Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!brutus.cs.uiuc.edu!usc!apple!well!pokey From: pokey@well.UUCP (Jef Poskanzer) Newsgroups: alt.sources Subject: PBMPLUS, part 18 of 18 Message-ID: <13624@well.UUCP> Date: 14 Sep 89 11:26:29 GMT Reply-To: Jef Poskanzer Organization: Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal Lines: 670 #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # pnm/pnmflip.c # pnm/pnmflip.1 # pnm/pnminvert.c # pnm/pnminvert.1 # pnm/pnmpaste.c # pnm/pnmpaste.1 # pnm/pnmtile.c # pnm/pnmtile.1 # This archive created: Thu Sep 14 03:43:55 1989 # By: Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal) export PATH; PATH=/bin:$PATH if test ! -d 'pnm' then echo shar: creating directory "'pnm'" mkdir 'pnm' fi echo shar: extracting "'pnm/pnmflip.c'" '(5425 characters)' if test -f 'pnm/pnmflip.c' then echo shar: will not over-write existing file "'pnm/pnmflip.c'" else sed 's/^X//' << \SHAR_EOF > 'pnm/pnmflip.c' X/* pnmflip.c - perform one or more flip operations on a portable anymap X** X** Copyright (C) 1989 by Jef Poskanzer. X** X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, provided X** that the above copyright notice appear in all copies and that both that X** copyright notice and this permission notice appear in supporting X** documentation. This software is provided "as is" without express or X** implied warranty. X*/ X X#include X#ifdef SYSV X#include X#else SYSV X#include X#endif SYSV X#include "pnm.h" X X#define max(a,b) ((a) > (b) ? (a) : (b)) X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X xel **xels, **transpose(); X void leftright(), topbottom(); X int argn, rows, cols, format; X xelval maxval; X char *usage = "[-leftright|-lr] [-topbottom|-tb] [-transpose|-xy]\n [-rotate90|-r90|-ccw] [-rotate270|r270|-cw]\n [-rotate180|-r180] [pnmfile]"; X X pm_progname = argv[0]; X X argn = 1; X X /* Just check the validity of arguments here. */ X while ( argn < argc && argv[argn][0] == '-' ) X { X if ( strncmp(argv[argn],"-lr",max(strlen(argv[argn]),2)) == 0 || X strncmp(argv[argn],"-leftright",max(strlen(argv[argn]),2)) == 0 ) X { } X else if ( strncmp(argv[argn],"-tb",max(strlen(argv[argn]),3)) == 0 || X strncmp(argv[argn],"-topbottom",max(strlen(argv[argn]),3)) == 0 ) X { } X else if ( strncmp(argv[argn],"-xy",max(strlen(argv[argn]),2)) == 0 || X strncmp(argv[argn],"-transpose",max(strlen(argv[argn]),3)) == 0 ) X { } X else if ( strncmp(argv[argn],"-r90",max(strlen(argv[argn]),3)) == 0 || X strncmp(argv[argn],"-rotate90",max(strlen(argv[argn]),8)) == 0 || X strncmp(argv[argn],"-ccw",max(strlen(argv[argn]),3)) == 0 ) X { } X else if ( strncmp(argv[argn],"-r270",max(strlen(argv[argn]),3)) == 0 || X strncmp(argv[argn],"-rotate270",max(strlen(argv[argn]),8)) == 0 || X strncmp(argv[argn],"-cw",max(strlen(argv[argn]),3)) == 0 ) X { } X else if ( strncmp(argv[argn],"-r180",max(strlen(argv[argn]),3)) == 0 || X strncmp(argv[argn],"-rotate180",max(strlen(argv[argn]),8)) == 0 ) X { } X else X pm_usage( usage ); X argn++; X } X X if ( argn != argc ) X { X ifd = pm_openr( argv[argn] ); X argn++; X } X else X ifd = stdin; X X if ( argn != argc ) X pm_usage( usage ); X X xels = pnm_readpnm( ifd, &cols, &rows, &maxval, &format ); X pm_close( ifd ); X X /* Now go through the flags again, this time executing them. */ X argn = 1; X while ( argn < argc && argv[argn][0] == '-' ) X { X if ( strncmp(argv[argn],"-lr",max(strlen(argv[argn]),2)) == 0 || X strncmp(argv[argn],"-leftright",max(strlen(argv[argn]),2)) == 0 ) X leftright( xels, rows, cols ); X else if ( strncmp(argv[argn],"-tb",max(strlen(argv[argn]),3)) == 0 || X strncmp(argv[argn],"-topbottom",max(strlen(argv[argn]),3)) == 0 ) X topbottom( xels, rows, cols ); X else if ( strncmp(argv[argn],"-xy",max(strlen(argv[argn]),2)) == 0 || X strncmp(argv[argn],"-transpose",max(strlen(argv[argn]),3)) == 0 ) X xels = transpose( xels, &rows, &cols ); X else if ( strncmp(argv[argn],"-r90",max(strlen(argv[argn]),3)) == 0 || X strncmp(argv[argn],"-rotate90",max(strlen(argv[argn]),8)) == 0 || X strncmp(argv[argn],"-ccw",max(strlen(argv[argn]),3)) == 0 ) X { X xels = transpose( xels, &rows, &cols ); X topbottom( xels, rows, cols ); X } X else if ( strncmp(argv[argn],"-r270",max(strlen(argv[argn]),3)) == 0 || X strncmp(argv[argn],"-rotate270",max(strlen(argv[argn]),8)) == 0 || X strncmp(argv[argn],"-cw",max(strlen(argv[argn]),3)) == 0 ) X { X xels = transpose( xels, &rows, &cols ); X leftright( xels, rows, cols ); X } X else if ( strncmp(argv[argn],"-r180",max(strlen(argv[argn]),3)) == 0 || X strncmp(argv[argn],"-rotate180",max(strlen(argv[argn]),8)) == 0 ) X { X leftright( xels, rows, cols ); X topbottom( xels, rows, cols ); X } X else X pm_error( "shouldn't happen!", 0,0,0,0,0 ); X argn++; X } X X /* All done. */ X pnm_writepnm( stdout, xels, cols, rows, maxval, format ); X X exit( 0 ); X } X Xvoid Xleftright( xels, rows, cols ) Xxel **xels; Xint rows, cols; X { X int row; X register int col; X register xel *x1P, *x2P; X xel p; X X for ( row = 0; row < rows; row++ ) X for ( col = 0, x1P = xels[row], x2P = &(xels[row][cols-1]); X col < cols / 2; X col++, x1P++, x2P-- ) X { X p = *x1P; X *x1P = *x2P; X *x2P = p; X } X } X Xvoid Xtopbottom( xels, rows, cols ) Xxel **xels; Xint rows, cols; X { X int row; X register int col; X register xel *x1P, *x2P; X xel p; X X for ( row = 0; row < rows / 2; row++ ) X for ( col = 0, x1P = xels[row], x2P = xels[rows - 1 - row]; X col < cols; X col++, x1P++, x2P++ ) X { X p = *x1P; X *x1P = *x2P; X *x2P = p; X } X } X Xxel ** Xtranspose( xels, rowsP, colsP ) Xxel **xels; Xint *rowsP, *colsP; X { X int row, t; X register int col; X register xel **newxels, *xP; X X newxels = pnm_allocarray( *rowsP, *colsP ); /* note parameter reversal */ X X for ( row = 0; row < *rowsP; row++ ) X for ( col = 0, xP = xels[row]; col < *colsP; col++, xP++ ) X newxels[col][row] = *xP; /* reversal here too */ X X pnm_freearray( xels, *rowsP ); X t = *rowsP; X *rowsP = *colsP; X *colsP = t; X X return newxels; X } SHAR_EOF if test 5425 -ne "`wc -c < 'pnm/pnmflip.c'`" then echo shar: error transmitting "'pnm/pnmflip.c'" '(should have been 5425 characters)' fi fi # end of overwriting check if test ! -d 'pnm' then echo shar: creating directory "'pnm'" mkdir 'pnm' fi echo shar: extracting "'pnm/pnmflip.1'" '(1300 characters)' if test -f 'pnm/pnmflip.1' then echo shar: will not over-write existing file "'pnm/pnmflip.1'" else sed 's/^X//' << \SHAR_EOF > 'pnm/pnmflip.1' X.TH pnmflip 1 "25 July 1989" X.SH NAME Xpnmflip - perform one or more flip operations on a portable anymap X.SH SYNOPSIS Xpnmflip [-leftright|-lr] [-topbottom|-tb] [-transpose|-xy] X [-rotate90|-r90|-ccw] [-rotate270|-r270|-cw] X [-rotate180|-r180] [pnmfile] X.SH DESCRIPTION XReads a portable anymap as input. XPerforms one or more flip operations, in the order specified, and Xwrites out a portable anymap. X.PP XThe flip operations available are: left for right (-leftright or -lr); Xtop for bottom (-topbottom or -tb); and transposition (-transpose or -xy). XIn addition, some canned concatenations are available: -rotate90 or -ccw Xis equivalent to -transpose -topbottom; -rotate270 or -cw is equivalent Xto -transpose -leftright; and -rotate180 is equivalent to -leftright -topbottom. X.PP XAll flags can be abbreviated to their shortest unique prefix. X.SH "SEE ALSO" Xpnm(5), ppmrotate(1) X.SH AUTHOR XCopyright (C) 1989 by Jef Poskanzer. X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. This software is provided "as is" without express or Ximplied warranty. SHAR_EOF if test 1300 -ne "`wc -c < 'pnm/pnmflip.1'`" then echo shar: error transmitting "'pnm/pnmflip.1'" '(should have been 1300 characters)' fi fi # end of overwriting check if test ! -d 'pnm' then echo shar: creating directory "'pnm'" mkdir 'pnm' fi echo shar: extracting "'pnm/pnminvert.c'" '(1297 characters)' if test -f 'pnm/pnminvert.c' then echo shar: will not over-write existing file "'pnm/pnminvert.c'" else sed 's/^X//' << \SHAR_EOF > 'pnm/pnminvert.c' X/* pnminvert.c - read a portable anymap and invert it X** X** Copyright (C) 1989 by Jef Poskanzer. X** X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, provided X** that the above copyright notice appear in all copies and that both that X** copyright notice and this permission notice appear in supporting X** documentation. This software is provided "as is" without express or X** implied warranty. X*/ X X#include X#include "pnm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X xelval maxval; X register xel *xelrow, *xP; X int rows, cols, format, row, col; X X pm_progname = argv[0]; X X if ( argc > 2 ) X pm_usage( "[pnmfile]" ); X X if ( argc == 2 ) X ifd = pm_openr( argv[1] ); X else X ifd = stdin; X X pnm_readpnminit( ifd, &cols, &rows, &maxval, &format ); X pnm_writepnminit( stdout, cols, rows, maxval, format ); X xelrow = pnm_allocrow( cols ); X X for ( row = 0; row < rows; row++ ) X { X pnm_readpnmrow( ifd, xelrow, cols, maxval, format ); X for ( col = 0, xP = xelrow; col < cols; col++, xP++ ) X *xP = pnm_invertxel( *xP, maxval, format ); X X pnm_writepnmrow( stdout, xelrow, cols, maxval, format ); X } X X pm_close( ifd ); X X exit( 0 ); X } SHAR_EOF if test 1297 -ne "`wc -c < 'pnm/pnminvert.c'`" then echo shar: error transmitting "'pnm/pnminvert.c'" '(should have been 1297 characters)' fi fi # end of overwriting check if test ! -d 'pnm' then echo shar: creating directory "'pnm'" mkdir 'pnm' fi echo shar: extracting "'pnm/pnminvert.1'" '(670 characters)' if test -f 'pnm/pnminvert.1' then echo shar: will not over-write existing file "'pnm/pnminvert.1'" else sed 's/^X//' << \SHAR_EOF > 'pnm/pnminvert.1' X.TH pnminvert 1 "08 August 1989" X.SH NAME Xpnminvert - invert a portable anymap X.SH SYNOPSIS Xpnminvert [pnmfile] X.SH DESCRIPTION XReads a portable anymap as input. XInverts it black for white and produces a portable anymap as output. X.SH "SEE ALSO" Xpnm(5) X.SH AUTHOR XCopyright (C) 1989 by Jef Poskanzer. X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. This software is provided "as is" without express or Ximplied warranty. SHAR_EOF if test 670 -ne "`wc -c < 'pnm/pnminvert.1'`" then echo shar: error transmitting "'pnm/pnminvert.1'" '(should have been 670 characters)' fi fi # end of overwriting check if test ! -d 'pnm' then echo shar: creating directory "'pnm'" mkdir 'pnm' fi echo shar: extracting "'pnm/pnmpaste.c'" '(2914 characters)' if test -f 'pnm/pnmpaste.c' then echo shar: will not over-write existing file "'pnm/pnmpaste.c'" else sed 's/^X//' << \SHAR_EOF > 'pnm/pnmpaste.c' X/* pnmpaste.c - paste a rectangle into a portable anymap X** X** Copyright (C) 1989 by Jef Poskanzer. X** X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, provided X** that the above copyright notice appear in all copies and that both that X** copyright notice and this permission notice appear in supporting X** documentation. This software is provided "as is" without express or X** implied warranty. X*/ X X#include X#include "pnm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd1, *ifd2; X register xel **xels1, **xels2, *x1P, *x2P; X xelval maxval1, maxval2, newmaxval; X int argn, rows1, cols1, format1, x, y; X int rows2, cols2, format2, newformat, row; X register int col; X char *usage = "frompnmfile x y [intopnmfile]"; X X pm_progname = argv[0]; X X argn = 1; X X if ( argn == argc ) X pm_usage( usage ); X ifd1 = pm_openr( argv[argn] ); X argn++; X X if ( argn == argc ) X pm_usage( usage ); X if ( sscanf( argv[argn], "%d", &x ) != 1 ) X pm_usage( usage ); X argn++; X if ( argn == argc ) X pm_usage( usage ); X if ( sscanf( argv[argn], "%d", &y ) != 1 ) X pm_usage( usage ); X argn++; X X if ( argn != argc ) X { X ifd2 = pm_openr( argv[argn] ); X argn++; X } X else X ifd2 = stdin; X X if ( argn != argc ) X pm_usage( usage ); X X xels1 = pnm_readpnm( ifd1, &cols1, &rows1, &maxval1, &format1 ); X pm_close( ifd1 ); X X xels2 = pnm_readpnm( ifd2, &cols2, &rows2, &maxval2, &format2 ); X pm_close( ifd2 ); X X if ( format1 > format2 ) X { X newformat = format1; X newmaxval = maxval1; X } X else X { X newformat = format2; X newmaxval = maxval2; X } X pnm_promoteformat( xels1, cols2, rows1, maxval1, format1, newmaxval, newformat ); X pnm_promoteformat( xels2, cols2, rows2, maxval2, format2, newmaxval, newformat ); X X if ( x <= -cols2 ) X pm_error( X "x is too negative -- the second anymap has only %d cols", X cols2, 0,0,0,0 ); X if ( y <= -rows2 ) X pm_error( X "y is too negative -- the second anymap has only %d rows", X rows2, 0,0,0,0 ); X X if ( x < 0 ) X x = cols2 - x; X if ( y < 0 ) X y = rows2 - y; X X if ( x >= cols2 ) X pm_error( X "x is too large -- the second anymap has only %d cols", X cols2, 0,0,0,0 ); X if ( y >= rows2 ) X pm_error( X "y is too large -- the second anymap has only %d rows", X rows2, 0,0,0,0 ); X if ( x + cols1 > cols2 ) X pm_error( X "x + width is too large by %d pixels", x + cols1 - cols2, 0,0,0,0 ); X if ( y + rows1 > rows2 ) X pm_error( X "y + height is too large by %d pixels", y + rows1 - rows2, X 0,0,0,0 ); X X for ( row = 0; row < rows1; row++ ) X { X for ( col = 0, x1P = xels1[row], x2P = &(xels2[row+y][x]); col < cols1; col++, x1P++, x2P++ ) X *x2P = *x1P; X } X X pnm_writepnm( stdout, xels2, cols2, rows2, newmaxval, newformat ); X X exit( 0 ); X } SHAR_EOF if test 2914 -ne "`wc -c < 'pnm/pnmpaste.c'`" then echo shar: error transmitting "'pnm/pnmpaste.c'" '(should have been 2914 characters)' fi fi # end of overwriting check if test ! -d 'pnm' then echo shar: creating directory "'pnm'" mkdir 'pnm' fi echo shar: extracting "'pnm/pnmpaste.1'" '(1407 characters)' if test -f 'pnm/pnmpaste.1' then echo shar: will not over-write existing file "'pnm/pnmpaste.1'" else sed 's/^X//' << \SHAR_EOF > 'pnm/pnmpaste.1' X.TH pnmpaste 1 "07 April 1989" X.SH NAME Xpnmpaste - paste a rectangle into a portable anymap X.SH SYNOPSIS Xpnmpaste frompnmfile x y [intopnmfile] X.SH DESCRIPTION XReads two portable anymaps as input. XInserts the first anymap into the second at the specified location, Xand produces a portable anymap the same size as the second as output. XIf the second anymap is not specified, it is read from stdin. XThe x and y can be negative, in which case they are interpreted Xrelative to the right and bottom of the anymap, respectively. X.PP XThis tool is most useful in combination with pnmcut(1). XFor instance, if you want to edit a small segment of a large Xanymap, and your anymap editor is TOO STUPID to edit the Xlarge anymap, you can cut out the segment you are interested in, Xedit it, and then paste it back in. X.PP XThe pbmpaste(1) tool is like this one, except that since it only has to work Xwith bitmaps, it implements bitblt-style logical operations. X.SH "SEE ALSO" Xpbmpaste(1), pnmcut(1), pnm(5) X.SH AUTHOR XCopyright (C) 1989 by Jef Poskanzer. X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. This software is provided "as is" without express or Ximplied warranty. SHAR_EOF if test 1407 -ne "`wc -c < 'pnm/pnmpaste.1'`" then echo shar: error transmitting "'pnm/pnmpaste.1'" '(should have been 1407 characters)' fi fi # end of overwriting check if test ! -d 'pnm' then echo shar: creating directory "'pnm'" mkdir 'pnm' fi echo shar: extracting "'pnm/pnmtile.c'" '(1585 characters)' if test -f 'pnm/pnmtile.c' then echo shar: will not over-write existing file "'pnm/pnmtile.c'" else sed 's/^X//' << \SHAR_EOF > 'pnm/pnmtile.c' X/* pnmtile.c - replicate a portable anymap into a specified size X** X** Copyright (C) 1989 by Jef Poskanzer. X** X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, provided X** that the above copyright notice appear in all copies and that both that X** copyright notice and this permission notice appear in supporting X** documentation. This software is provided "as is" without express or X** implied warranty. X*/ X X#include X#include "pnm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X register xel **xels, *xelrow; X xelval maxval; X int rows, cols, format, width, height, row, col; X char *usage = "width height [pnmfile]"; X X pm_progname = argv[0]; X X if ( argc < 3 || argc > 4 ) X pm_usage( usage ); X X if ( sscanf( argv[1], "%d", &width ) != 1 ) X pm_usage( usage ); X if ( sscanf( argv[2], "%d", &height ) != 1 ) X pm_usage( usage ); X X if ( width < 1 ) X pm_error( "width is less than 1", 0,0,0,0,0 ); X if ( height < 1 ) X pm_error( "height is less than 1", 0,0,0,0,0 ); X X if ( argc == 4 ) X ifd = pm_openr( argv[3] ); X else X ifd = stdin; X X xels = pnm_readpnm( ifd, &cols, &rows, &maxval, &format ); X pm_close( ifd ); X X xelrow = pnm_allocrow( width ); X X pnm_writepnminit( stdout, width, height, maxval, format ); X for ( row = 0; row < height; row++ ) X { X for ( col = 0; col < width; col++ ) X xelrow[col] = xels[row % rows][col % cols]; X pnm_writepnmrow( stdout, xelrow, width, maxval, format ); X } X X exit( 0 ); X } SHAR_EOF if test 1585 -ne "`wc -c < 'pnm/pnmtile.c'`" then echo shar: error transmitting "'pnm/pnmtile.c'" '(should have been 1585 characters)' fi fi # end of overwriting check if test ! -d 'pnm' then echo shar: creating directory "'pnm'" mkdir 'pnm' fi echo shar: extracting "'pnm/pnmtile.1'" '(718 characters)' if test -f 'pnm/pnmtile.1' then echo shar: will not over-write existing file "'pnm/pnmtile.1'" else sed 's/^X//' << \SHAR_EOF > 'pnm/pnmtile.1' X.TH pnmtile 1 "13 May 1989" X.SH NAME Xpnmtile - replicate a portable anymap into a specified size X.SH SYNOPSIS Xpnmtile width height [pnmfile] X.SH DESCRIPTION XReads a portable anymap as input. XReplicates it until it is the specified size, Xand produces a portable anymap as output. X.SH "SEE ALSO" Xpnm(5) X.SH AUTHOR XCopyright (C) 1989 by Jef Poskanzer. X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. This software is provided "as is" without express or Ximplied warranty. SHAR_EOF if test 718 -ne "`wc -c < 'pnm/pnmtile.1'`" then echo shar: error transmitting "'pnm/pnmtile.1'" '(should have been 718 characters)' fi fi # end of overwriting check # End of shell archive exit 0