pokey@well.UUCP (Jef Poskanzer) (02/12/88)
#! /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: # pbmtoascii.c # pbmtoascii.man # pbmcatlr.c # pbmcatlr.man # pbmcattb.c # pbmcattb.man # pbmfliplr.c # pbmfliplr.man # pbmfliptb.c # pbmfliptb.man # pbminvert.c # pbminvert.man # pbmcrop.c # pbmcrop.man # libpbm.c # pbm.h # bmaliases # This archive created: Wed Feb 10 03:53:57 1988 # By: Jef Poskanzer export PATH; PATH=/bin:$PATH echo shar: extracting "'pbmtoascii.c'" '(1238 characters)' if test -f 'pbmtoascii.c' then echo shar: will not over-write existing file "'pbmtoascii.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmtoascii.c' X/* pbmtoascii.c - read a portable bitmap and produce ASCII graphics X*/ X X#include <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits; X int rows, cols, row, col, lastcol; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [pbmfile]\n", argv[0] ); X exit( 1 ); X } X X if ( argc == 2 ) X { X ifd = fopen( argv[1], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[1] ); X exit( 1 ); X } X } X else X ifd = stdin; X X bits = pbm_readpbm( ifd, &cols, &rows ); X X if ( ifd != stdin ) X fclose( ifd ); X X /* Write out rows by twos. */ X for ( row = 0; row < rows; row += 2 ) X { X /* Find end of lines. */ X for ( lastcol = cols-1; lastcol > 0; lastcol-- ) X { X if ( bits[row][lastcol] ) X break; X if ( row+1 < rows && bits[row+1][lastcol] ) X break; X } X for ( col = 0; col <= lastcol; col++ ) X { X if ( ! bits[row][col] ) X { X if ( row+1 >= rows || ! bits[row+1][col] ) X putchar( ' ' ); X else X putchar( 'o' ); X } X else X { X if ( row+1 >= rows || ! bits[row+1][col] ) X putchar( '"' ); X else X putchar( '$' ); X } X } X putchar( '\n' ); X } X X exit( 0 ); X } SHAR_EOF if test 1238 -ne "`wc -c < 'pbmtoascii.c'`" then echo shar: error transmitting "'pbmtoascii.c'" '(should have been 1238 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmtoascii.man'" '(626 characters)' if test -f 'pbmtoascii.man' then echo shar: will not over-write existing file "'pbmtoascii.man'" else sed 's/^X//' << \SHAR_EOF > 'pbmtoascii.man' X.TH pbmtoascii 1 "08 February 1988" "PBM" X.SH NAME Xpbmtoascii \- convert portable bitmaps into ASCII bitmaps X.SH SYNOPSIS Xpbmtoascii \%[pbmfile] X.SH DESCRIPTION XReads a portable bitmap as input. XProduces a somewhat crude ASCII bitmap as output. XNote that there is no Xasciitopbm Xtool - this transformation is one-way. X.SH "SEE\ ALSO" Xcbmtopbm(1), icontopbm(1), macpainttopbm(1), rastertopbm(1), xbmtopbm(1), Xpbmtocbm(1), pbmtomacpaint(1), pbmtops(1), pbmtoptx(1), pbmtoraster(1), Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1), Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1) X.SH AUTHOR XJef Poskanzer SHAR_EOF if test 626 -ne "`wc -c < 'pbmtoascii.man'`" then echo shar: error transmitting "'pbmtoascii.man'" '(should have been 626 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmcatlr.c'" '(2325 characters)' if test -f 'pbmcatlr.c' then echo shar: will not over-write existing file "'pbmcatlr.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmcatlr.c' X/* pbmcatlr.c - concatenate portable bitmaps left to right X*/ X X#include <stdio.h> X#include "pbm.h" X X#define MAXFILES 100 X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd[MAXFILES]; X bit **bits[MAXFILES], **newbits, background; X int argn, backdefault, nfiles, i, c; X int rows[MAXFILES], cols[MAXFILES], row, col; X int newrows, newcols, newcol, padtop; X char *usage = "usage: %s [-0] [-1] pbmfile pbmfile ...\n"; X X argn = 1; X backdefault = 1; X X /* Check for flags. */ X if ( argc > argn ) X { X if ( argv[argn][0] == '-' ) X { X if ( strcmp( argv[argn], "-0" ) == 0 ) X { X backdefault = 0; X background = 0; X argn++; X } X else if ( strcmp( argv[argn], "-1" ) == 0 ) X { X backdefault = 0; X background = 1; X argn++; X } X else X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X } X } X X if ( argc > argn ) X { X nfiles = argc - argn; X for ( i = 0; i < nfiles; i++ ) X { X if ( strcmp( argv[argn+i], "-" ) == 0 ) X ifd[i] = stdin; X else X { X ifd[i] = fopen( argv[argn+i], "r" ); X if ( ifd[i] == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[argn+i] ); X exit( 1 ); X } X } X } X } X else X { X nfiles = 1; X ifd[0] = stdin; X } X X newcols = 0; X newrows = 0; X for ( i = 0; i < nfiles; i++ ) X { X bits[i] = pbm_readpbm( ifd[i], &cols[i], &rows[i] ); X if ( ifd[i] != stdin ) X fclose( ifd[i] ); X newcols += cols[i]; X if ( rows[i] > newrows ) X newrows = rows[i]; X } X X newbits = pbm_allocarray( newcols, newrows ); X X newcol = 0; X X for ( i = 0; i < nfiles; i++ ) X { X if ( backdefault ) X { X /* Make a reasonable guess as to what the background is. */ X c = (int) bits[i][0][0] + (int) bits[i][0][cols[i]-1] + X (int) bits[i][rows[i]-1][0] + X (int) bits[i][rows[i]-1][cols[i]-1]; X background = ( c <= 2 ) ? 0 : 1; X } X X padtop = (newrows - rows[i]) / 2; X X for ( col = 0; col <= cols[i]; col++ ) X { X for ( row = 0; row < padtop; row++ ) X newbits[row][newcol+col] = background; X for ( row = 0; row < rows[i]; row++ ) X newbits[padtop+row][newcol+col] = bits[i][row][col]; X for ( row = padtop+rows[i]; row < newrows; row++ ) X newbits[row][newcol+col] = background; X } X X newcol += cols[i]; X } X X pbm_writepbm( stdout, newbits, newcols, newrows ); X X exit( 0 ); X } SHAR_EOF if test 2325 -ne "`wc -c < 'pbmcatlr.c'`" then echo shar: error transmitting "'pbmcatlr.c'" '(should have been 2325 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmcatlr.man'" '(848 characters)' if test -f 'pbmcatlr.man' then echo shar: will not over-write existing file "'pbmcatlr.man'" else sed 's/^X//' << \SHAR_EOF > 'pbmcatlr.man' X.TH pbmcatlr 1 "08 February 1988" "PBM" X.SH NAME Xpbmcatlr \- concatenate portable bitmaps left to right X.SH SYNOPSIS Xpbmcatlr \%[-0] \%[-1] pbmfile pbmfile ... X.SH DESCRIPTION XReads portable bitmaps as input. XConcatenates them left to right and produces a portable bitmap as output. XIf the bitmaps are not all the same height, the shorter ones are centered Xvertically with the edges filled in. XThe -0 and -1 flags specify what color to use for this fill -- if neither Xis specified, the program makes a guess as to which would look better. X.SH "SEE\ ALSO" Xcbmtopbm(1), icontopbm(1), macpainttopbm(1), rastertopbm(1), xbmtopbm(1), Xpbmtocbm(1), pbmtomacpaint(1), pbmtops(1), pbmtoptx(1), pbmtoraster(1), Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1), Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1) X.SH AUTHOR XJef Poskanzer SHAR_EOF if test 848 -ne "`wc -c < 'pbmcatlr.man'`" then echo shar: error transmitting "'pbmcatlr.man'" '(should have been 848 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmcattb.c'" '(2330 characters)' if test -f 'pbmcattb.c' then echo shar: will not over-write existing file "'pbmcattb.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmcattb.c' X/* pbmcattb.c - concatenate portable bitmaps top to bottom X*/ X X#include <stdio.h> X#include "pbm.h" X X#define MAXFILES 100 X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd[MAXFILES]; X bit **bits[MAXFILES], **newbits, background; X int argn, backdefault, nfiles, i, c; X int rows[MAXFILES], cols[MAXFILES], row, col; X int newrows, newcols, newrow, padleft; X char *usage = "usage: %s [-0] [-1] pbmfile pbmfile ...\n"; X X argn = 1; X backdefault = 1; X X /* Check for flags. */ X if ( argc > argn ) X { X if ( argv[argn][0] == '-' ) X { X if ( strcmp( argv[argn], "-0" ) == 0 ) X { X backdefault = 0; X background = 0; X argn++; X } X else if ( strcmp( argv[argn], "-1" ) == 0 ) X { X backdefault = 0; X background = 1; X argn++; X } X else X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X } X } X X if ( argc > argn ) X { X nfiles = argc - argn; X for ( i = 0; i < nfiles; i++ ) X { X if ( strcmp( argv[argn+i], "-" ) == 0 ) X ifd[i] = stdin; X else X { X ifd[i] = fopen( argv[argn+i], "r" ); X if ( ifd[i] == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[argn+i] ); X exit( 1 ); X } X } X } X } X else X { X nfiles = 1; X ifd[0] = stdin; X } X X newcols = 0; X newrows = 0; X for ( i = 0; i < nfiles; i++ ) X { X bits[i] = pbm_readpbm( ifd[i], &cols[i], &rows[i] ); X if ( ifd[i] != stdin ) X fclose( ifd[i] ); X if ( cols[i] > newcols ) X newcols = cols[i]; X newrows += rows[i]; X } X X newbits = pbm_allocarray( newcols, newrows ); X X newrow = 0; X X for ( i = 0; i < nfiles; i++ ) X { X if ( backdefault ) X { X /* Make a reasonable guess as to what the background is. */ X c = (int) bits[i][0][0] + (int) bits[i][0][cols[i]-1] + X (int) bits[i][rows[i]-1][0] + X (int) bits[i][rows[i]-1][cols[i]-1]; X background = ( c <= 2 ) ? 0 : 1; X } X X padleft = (newcols - cols[i]) / 2; X X for ( row = 0; row < rows[i]; row++ ) X { X for ( col = 0; col < padleft; col++ ) X newbits[newrow+row][col] = background; X for ( col = 0; col <= cols[i]; col++ ) X newbits[newrow+row][padleft+col] = bits[i][row][col]; X for ( col = padleft+cols[i]; col < newcols; col++ ) X newbits[newrow+row][col] = background; X } X X newrow += rows[i]; X } X X pbm_writepbm( stdout, newbits, newcols, newrows ); X X exit( 0 ); X } SHAR_EOF if test 2330 -ne "`wc -c < 'pbmcattb.c'`" then echo shar: error transmitting "'pbmcattb.c'" '(should have been 2330 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmcattb.man'" '(850 characters)' if test -f 'pbmcattb.man' then echo shar: will not over-write existing file "'pbmcattb.man'" else sed 's/^X//' << \SHAR_EOF > 'pbmcattb.man' X.TH pbmcattb 1 "08 February 1988" "PBM" X.SH NAME Xpbmcattb \- concatenate portable bitmaps top to bottom X.SH SYNOPSIS Xpbmcattb \%[-0] \%[-1] pbmfile pbmfile ... X.SH DESCRIPTION XReads portable bitmaps as input. XConcatenates them top to bottom and produces a portable bitmap as output. XIf the bitmaps are not all the same width, the narrower ones are centered Xhorizontally with the edges filled in. XThe -0 and -1 flags specify what color to use for this fill -- if neither Xis specified, the program makes a guess as to which would look better. X.SH "SEE\ ALSO" Xcbmtopbm(1), icontopbm(1), macpainttopbm(1), rastertopbm(1), xbmtopbm(1), Xpbmtocbm(1), pbmtomacpaint(1), pbmtops(1), pbmtoptx(1), pbmtoraster(1), Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1), Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1) X.SH AUTHOR XJef Poskanzer SHAR_EOF if test 850 -ne "`wc -c < 'pbmcattb.man'`" then echo shar: error transmitting "'pbmcattb.man'" '(should have been 850 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmfliplr.c'" '(873 characters)' if test -f 'pbmfliplr.c' then echo shar: will not over-write existing file "'pbmfliplr.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmfliplr.c' X/* pbmfliplr.c - read a portable bitmap and flip it left for right X*/ X X#include <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits, b; X int rows, cols, row, col; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [pbmfile]\n", argv[0] ); X exit( 1 ); X } X X if ( argc == 2 ) X { X ifd = fopen( argv[1], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[1] ); X exit( 1 ); X } X } X else X ifd = stdin; X X bits = pbm_readpbm( ifd, &cols, &rows ); X X if ( ifd != stdin ) X fclose( ifd ); X X for ( row = 0; row < rows; row++ ) X for ( col = 0; col < cols / 2; col++ ) X { X b = bits[row][col]; X bits[row][col] = bits[row][cols-col-1]; X bits[row][cols-col-1] = b; X } X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } SHAR_EOF if test 873 -ne "`wc -c < 'pbmfliplr.c'`" then echo shar: error transmitting "'pbmfliplr.c'" '(should have been 873 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmfliplr.man'" '(561 characters)' if test -f 'pbmfliplr.man' then echo shar: will not over-write existing file "'pbmfliplr.man'" else sed 's/^X//' << \SHAR_EOF > 'pbmfliplr.man' X.TH pbmfliplr 1 "08 February 1988" "PBM" X.SH NAME Xpbmfliplr \- flip a portable bitmap left for right X.SH SYNOPSIS Xpbmfliplr \%[pbmfile] X.SH DESCRIPTION XReads a portable bitmap as input. XFlips it left for right and produces a portable bitmap as output. X.SH "SEE\ ALSO" Xcbmtopbm(1), icontopbm(1), macpainttopbm(1), rastertopbm(1), xbmtopbm(1), Xpbmtocbm(1), pbmtomacpaint(1), pbmtops(1), pbmtoptx(1), pbmtoraster(1), Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1), Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1) X.SH AUTHOR XJef Poskanzer SHAR_EOF if test 561 -ne "`wc -c < 'pbmfliplr.man'`" then echo shar: error transmitting "'pbmfliplr.man'" '(should have been 561 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmfliptb.c'" '(873 characters)' if test -f 'pbmfliptb.c' then echo shar: will not over-write existing file "'pbmfliptb.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmfliptb.c' X/* pbmfliptb.c - read a portable bitmap and flip it top for bottom X*/ X X#include <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits, b; X int rows, cols, row, col; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [pbmfile]\n", argv[0] ); X exit( 1 ); X } X X if ( argc == 2 ) X { X ifd = fopen( argv[1], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[1] ); X exit( 1 ); X } X } X else X ifd = stdin; X X bits = pbm_readpbm( ifd, &cols, &rows ); X X if ( ifd != stdin ) X fclose( ifd ); X X for ( row = 0; row < rows / 2; row++ ) X for ( col = 0; col < cols; col++ ) X { X b = bits[row][col]; X bits[row][col] = bits[rows-row-1][col]; X bits[rows-row-1][col] = b; X } X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } SHAR_EOF if test 873 -ne "`wc -c < 'pbmfliptb.c'`" then echo shar: error transmitting "'pbmfliptb.c'" '(should have been 873 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmfliptb.man'" '(561 characters)' if test -f 'pbmfliptb.man' then echo shar: will not over-write existing file "'pbmfliptb.man'" else sed 's/^X//' << \SHAR_EOF > 'pbmfliptb.man' X.TH pbmfliptb 1 "08 February 1988" "PBM" X.SH NAME Xpbmfliptb \- flip a portable bitmap top for bottom X.SH SYNOPSIS Xpbmfliptb \%[pbmfile] X.SH DESCRIPTION XReads a portable bitmap as input. XFlips it top for bottom and produces a portable bitmap as output. X.SH "SEE\ ALSO" Xcbmtopbm(1), icontopbm(1), macpainttopbm(1), rastertopbm(1), xbmtopbm(1), Xpbmtocbm(1), pbmtomacpaint(1), pbmtops(1), pbmtoptx(1), pbmtoraster(1), Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1), Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1) X.SH AUTHOR XJef Poskanzer SHAR_EOF if test 561 -ne "`wc -c < 'pbmfliptb.man'`" then echo shar: error transmitting "'pbmfliptb.man'" '(should have been 561 characters)' fi fi # end of overwriting check echo shar: extracting "'pbminvert.c'" '(792 characters)' if test -f 'pbminvert.c' then echo shar: will not over-write existing file "'pbminvert.c'" else sed 's/^X//' << \SHAR_EOF > 'pbminvert.c' X/* pbminvert.c - read a portable bitmap and invert it X*/ X X#include <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits; X int rows, cols, row, col; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [pbmfile]\n", argv[0] ); X exit( 1 ); X } X X if ( argc == 2 ) X { X ifd = fopen( argv[1], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[1] ); X exit( 1 ); X } X } X else X ifd = stdin; X X bits = pbm_readpbm( ifd, &cols, &rows ); X X if ( ifd != stdin ) X fclose( ifd ); X X for ( row = 0; row < rows; row++ ) X for ( col = 0; col < cols; col++ ) X bits[row][col] = ( bits[row][col] == 0 ? 1 : 0 ); X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } SHAR_EOF if test 792 -ne "`wc -c < 'pbminvert.c'`" then echo shar: error transmitting "'pbminvert.c'" '(should have been 792 characters)' fi fi # end of overwriting check echo shar: extracting "'pbminvert.man'" '(551 characters)' if test -f 'pbminvert.man' then echo shar: will not over-write existing file "'pbminvert.man'" else sed 's/^X//' << \SHAR_EOF > 'pbminvert.man' X.TH pbminvert 1 "08 February 1988" "PBM" X.SH NAME Xpbminvert \- invert a portable bitmap X.SH SYNOPSIS Xpbminvert \%[pbmfile] X.SH DESCRIPTION XReads a portable bitmap as input. XInverts it black for white and produces a portable bitmap as output. X.SH "SEE\ ALSO" Xcbmtopbm(1), icontopbm(1), macpainttopbm(1), rastertopbm(1), xbmtopbm(1), Xpbmtocbm(1), pbmtomacpaint(1), pbmtops(1), pbmtoptx(1), pbmtoraster(1), Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1), Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1) X.SH AUTHOR XJef Poskanzer SHAR_EOF if test 551 -ne "`wc -c < 'pbminvert.man'`" then echo shar: error transmitting "'pbminvert.man'" '(should have been 551 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmcrop.c'" '(2523 characters)' if test -f 'pbmcrop.c' then echo shar: will not over-write existing file "'pbmcrop.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmcrop.c' X/* pbmcrop.c - crop a portable bitmap X*/ X X#include <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits, **newbits, background; X int argn, backdefault, c; X int rows, cols, row, col, newrows, newcols; X int top, bottom, left, right; X char *usage = "usage: %s [-0] [-1] [pbmfile]\n"; X X argn = 1; X backdefault = 1; X X /* Check for flags. */ X if ( argc > argn ) X { X if ( argv[argn][0] == '-' ) X { X if ( strcmp( argv[argn], "-0" ) == 0 ) X { X backdefault = 0; X background = 0; X argn++; X } X else if ( strcmp( argv[argn], "-1" ) == 0 ) X { X backdefault = 0; X background = 1; X argn++; X } X else X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X } X } X X if ( argc > argn + 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X X if ( argc == argn + 1 ) X { X ifd = fopen( argv[argn], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[argn] ); X exit( 1 ); X } X } X else X ifd = stdin; X X bits = pbm_readpbm( ifd, &cols, &rows ); X X if ( ifd != stdin ) X fclose( ifd ); X X if ( backdefault ) X { X /* Make a reasonable guess as to what the background is. */ X c = (int) bits[0][0] + (int) bits[0][cols-1] + X (int) bits[rows-1][0] + (int) bits[rows-1][cols-1]; X background = ( c <= 2 ) ? 0 : 1; X } X X /* Find first non-background line. */ X for ( top = 0; top < rows; top++ ) X for ( col = 0; col < cols; col++ ) X if ( bits[top][col] != background ) X goto gottop; Xgottop: X X /* Find last non-background line. */ X for ( bottom = rows-1; bottom >= top; bottom-- ) X for ( col = 0; col < cols; col++ ) X if ( bits[bottom][col] != background ) X goto gotbottom; Xgotbottom: X X /* Find first non-background column. */ X for ( left = 0; left < cols; left++ ) X for ( row = top; row < bottom; row++ ) X if ( bits[row][left] != background ) X goto gotleft; Xgotleft: X X /* Find last non-background column. */ X for ( right = cols-1; right > left; right-- ) X for ( row = top; row <= bottom; row++ ) X if ( bits[row][right] != background ) X goto gotright; Xgotright: X X /* Now copy into a new array. */ X newcols = right - left + 1; X newrows = bottom - top + 1; X newbits = pbm_allocarray( newcols, newrows ); X for ( row = top; row <= bottom; row++ ) X for ( col = left; col <= right; col++ ) X newbits[row-top][col-left] = bits[row][col]; X X pbm_writepbm( stdout, newbits, newcols, newrows ); X X exit( 0 ); X } SHAR_EOF if test 2523 -ne "`wc -c < 'pbmcrop.c'`" then echo shar: error transmitting "'pbmcrop.c'" '(should have been 2523 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmcrop.man'" '(695 characters)' if test -f 'pbmcrop.man' then echo shar: will not over-write existing file "'pbmcrop.man'" else sed 's/^X//' << \SHAR_EOF > 'pbmcrop.man' X.TH pbmcrop 1 "08 February 1988" "PBM" X.SH NAME Xpbmcrop \- crop a portable bitmap X.SH SYNOPSIS Xpbmcrop \%[-0] \%[-1] \%[pbmfile] X.SH DESCRIPTION XReads a portable bitmap as input. XRemoves edges that are the background color, Xand produces a portable bitmap as output. XBy default, it makes a guess as to what the background Xcolor is. XYou can override the default with the -0 and -1 flags. X.SH "SEE\ ALSO" Xcbmtopbm(1), icontopbm(1), macpainttopbm(1), rastertopbm(1), xbmtopbm(1), Xpbmtocbm(1), pbmtomacpaint(1), pbmtops(1), pbmtoptx(1), pbmtoraster(1), Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1), Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1) X.SH AUTHOR XJef Poskanzer SHAR_EOF if test 695 -ne "`wc -c < 'pbmcrop.man'`" then echo shar: error transmitting "'pbmcrop.man'" '(should have been 695 characters)' fi fi # end of overwriting check echo shar: extracting "'libpbm.c'" '(2317 characters)' if test -f 'libpbm.c' then echo shar: will not over-write existing file "'libpbm.c'" else sed 's/^X//' << \SHAR_EOF > 'libpbm.c' X/* libpbm.c - pbm utility library X*/ X X#include <stdio.h> X#include "pbm.h" X Xint Xpbm_getint( file ) XFILE *file; X { X char ch; X int i; X X do X { X ch = pbm_getc( file ); X } X while ( ch == ' ' || ch == '\t' || ch == '\n' ); X X if ( ch < '0' || ch > '9' ) X { X fprintf( stderr, "Junk in file where an integer should be!\n" ); X exit( 1 ); X } X X i = 0; X do X { X i = i * 10 + ch - '0'; X ch = pbm_getc( file ); X } X while ( ch >= '0' && ch <= '9' ); X X return ( i ); X } X X Xbit Xpbm_getbit( file ) XFILE *file; X { X char ch; X X do X { X ch = pbm_getc( file ); X } X while ( ch == ' ' || ch == '\t' || ch == '\n' ); X X if ( ch != '0' && ch != '1' ) X { X fprintf( stderr, "Junk in file where bits should be!\n" ); X exit( 1 ); X } X X return ( ( ch == '1' ) ? 1 : 0 ); X } X Xchar Xpbm_getc( file ) XFILE *file; X { X int ich; X char ch; X X ich = getc( file ); X if ( ich == NULL ) X { X fprintf( stderr, "Premature EOF.\n" ); X exit( 1 ); X } X ch = (char) ich; X X if ( ch == '#' ) X { X do X { X ich = getc( file ); X if ( ich == NULL ) X { X fprintf( stderr, "Premature EOF.\n" ); X exit( 1 ); X } X ch = (char) ich; X } X while ( ch != '\n' ); X } X X return ( ch ); X } X Xbit ** Xpbm_allocarray( cols, rows ) Xint cols, rows; X { X bit **bits; X int i; X X bits = (bit **) malloc( rows * sizeof( bit *) ); X for ( i = 0; i < rows; i++ ) X { X bits[i] = (bit *) malloc( cols * sizeof( bit ) ); X } X X return ( bits ); X } X X Xbit **pbm_readpbm( file, colsP, rowsP ) XFILE *file; Xint *colsP, *rowsP; X { X bit **bits; X int row, col; X X *colsP = pbm_getint( file ); X *rowsP = pbm_getint( file ); X X bits = pbm_allocarray( *colsP, *rowsP ); X X for ( row = 0; row < *rowsP; row++ ) X for ( col = 0; col < *colsP; col++ ) X bits[row][col] = pbm_getbit( file ); X X return ( bits ); X } X Xpbm_writepbm( file, bits, cols, rows ) XFILE *file; Xbit **bits; Xint cols, rows; X { X int row, col, linecount; X X fprintf( file, "%d %d\n", cols, rows ); X X for ( row = 0; row < rows; row++ ) X { X linecount = 0; X for ( col = 0; col < cols; col++ ) X { X if ( linecount >= 70 ) X { X putc( '\n', file ); X linecount = 0; X } X putc( bits[row][col] ? '1' : '0', file ); X linecount++; X } X putc( '\n', file ); X } X } SHAR_EOF if test 2317 -ne "`wc -c < 'libpbm.c'`" then echo shar: error transmitting "'libpbm.c'" '(should have been 2317 characters)' fi fi # end of overwriting check echo shar: extracting "'pbm.h'" '(490 characters)' if test -f 'pbm.h' then echo shar: will not over-write existing file "'pbm.h'" else sed 's/^X//' << \SHAR_EOF > 'pbm.h' X/* pbm.h - header file for libpbm portable bitmap library X*/ X Xtypedef unsigned char bit; X X/* Declarations of routines. */ X Xint pbm_getint( ); X /* i = pbm_getint( file ); */ Xbit pbm_getbit( ); X /* b = pbm_getbit( file ); */ Xchar pbm_getc( ); X /* c = pbm_getc( file ); */ Xbit **pbm_allocarray( ); X /* bits = pbm_allocarray( cols, rows ); bits[row][col]; */ Xbit **pbm_readpbm( ); X /* bits = pbm_readpbm( file, &cols, &rows ); */ Xpbm_writepbm( ); X /* pbm_writepbm( file, bits, cols, rows ); */ SHAR_EOF if test 490 -ne "`wc -c < 'pbm.h'`" then echo shar: error transmitting "'pbm.h'" '(should have been 490 characters)' fi fi # end of overwriting check echo shar: extracting "'bmaliases'" '(421 characters)' if test -f 'bmaliases' then echo shar: will not over-write existing file "'bmaliases'" else sed 's/^X//' << \SHAR_EOF > 'bmaliases' X# This script must be sourced - it will not work if you run it in a sub-shell. X Xset _bmtypes="ascii cbm icon macpaint ps ptx raster xbm x10bm" X Xforeach i ( $_bmtypes ) X if ( $i != ascii && $i != ps && $i != ptx && $i != x10bm ) then X foreach j ( $_bmtypes ) X if ( $i != macpaint ) then X if ( $i != $j ) then X alias ${i}to${j} "( ${i}topbm | pbmto${j} )" X endif X endif X end X endif Xend X Xunset _bmtypes SHAR_EOF if test 421 -ne "`wc -c < 'bmaliases'`" then echo shar: error transmitting "'bmaliases'" '(should have been 421 characters)' fi fi # end of overwriting check # End of shell archive exit 0