jef@helios.ee.lbl.gov (Jef Poskanzer) (11/09/88)
Posting-number: Volume 5, Issue 43 Submitted-by: "Jef Poskanzer" <jef@helios.ee.lbl.gov> Archive-name: pbm3/Part3 [Yuck. I'd prefer real subject lines. ++bsa] #! /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: # pbmfliptb.c # pbmfliptb.1 # pbminvert.c # pbminvert.1 # pbmcrop.c # pbmcrop.1 # pbmtrnspos.c # pbmtrnspos.1 # pbmcut.c # pbmcut.1 # pbmpaste.c # pbmpaste.1 # xxxtopbm.c # xxxtopbm.1 # pbmenlarge.c # pbmenlarge.1 # pbmmake.c # pbmmake.1 # pbmtolj.c # pbmtolj.1 # pbmtomacp.c # This archive created: Mon Oct 31 18:33:35 1988 # By: Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal) export PATH; PATH=/bin:$PATH echo shar: extracting "'pbmfliptb.c'" '(1305 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** Copyright (C) 1988 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 <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 1305 -ne "`wc -c < 'pbmfliptb.c'`" then echo shar: error transmitting "'pbmfliptb.c'" '(should have been 1305 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmfliptb.1'" '(709 characters)' if test -f 'pbmfliptb.1' then echo shar: will not over-write existing file "'pbmfliptb.1'" else sed 's/^X//' << \SHAR_EOF > 'pbmfliptb.1' X.TH pbmfliptb 1 "31 August 1988" 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" Xpbmfliplr(1), pbmtrnspos(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 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 709 -ne "`wc -c < 'pbmfliptb.1'`" then echo shar: error transmitting "'pbmfliptb.1'" '(should have been 709 characters)' fi fi # end of overwriting check echo shar: extracting "'pbminvert.c'" '(1224 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** Copyright (C) 1988 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 <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 1224 -ne "`wc -c < 'pbminvert.c'`" then echo shar: error transmitting "'pbminvert.c'" '(should have been 1224 characters)' fi fi # end of overwriting check echo shar: extracting "'pbminvert.1'" '(672 characters)' if test -f 'pbminvert.1' then echo shar: will not over-write existing file "'pbminvert.1'" else sed 's/^X//' << \SHAR_EOF > 'pbminvert.1' X.TH pbminvert 1 "13 February 1988" 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" Xpbm(5) X.SH AUTHOR XCopyright (C) 1988 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 672 -ne "`wc -c < 'pbminvert.1'`" then echo shar: error transmitting "'pbminvert.1'" '(should have been 672 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmcrop.c'" '(4241 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** Copyright (C) 1988 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 <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]/[-w]/[-1]/[-b] [pbmfile]\n"; X X argn = 1; X backdefault = 1; X X /* Check for flags. */ X if ( argn < argc ) X { X if ( argv[argn][0] == '-' ) X { X if ( ( argv[argn][1] == '0' || argv[argn][1] == 'w' || X argv[argn][1] == 'W' ) && argv[argn][2] == '\0' ) X { X backdefault = 0; X background = 0; X } X else if ( ( argv[argn][1] == '1' || argv[argn][1] == 'b' || X argv[argn][1] == 'B' ) && argv[argn][2] == '\0' ) X { X backdefault = 0; X background = 1; X } X else X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X argn++; X } X } X X if ( argn == argc ) X ifd = stdin; X else 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 argn++; X } X bits = pbm_readpbm( ifd, &cols, &rows ); X if ( ifd != stdin ) X fclose( ifd ); X X if ( argn != argc ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X X if ( backdefault ) X { X /* Guess what the background is by looking for an edge of X ** all one color. X */ X c = 0; X for ( col = 0; col < cols; col++ ) X c += bits[0][col]; X if ( c == 0 ) X background = 0; X else if ( c == cols ) X background = 1; X else X { X c = 0; X for ( col = 0; col < cols; col++ ) X c += bits[rows - 1][col]; X if ( c == 0 ) X background = 0; X else if ( c == cols ) X background = 1; X else X { X c = 0; X for ( row = 0; row < rows; row++ ) X c += bits[row][0]; X if ( c == 0 ) X background = 0; X else if ( c == rows ) X background = 1; X else X { X c = 0; X for ( row = 0; row < rows; row++ ) X c += bits[row][cols - 1]; X if ( c == 0 ) X background = 0; X else if ( c == rows ) X background = 1; X else X { X fprintf( stderr, "(nothing to crop, continuing)\n" ); X background = 0; /* arbitrary */ X } X } X } X } 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 if ( top > 0 ) X fprintf( stderr, "(cropping %d %d-rows off the top)\n", X top, background ); X if ( bottom < rows - 1 ) X fprintf( stderr, "(cropping %d %d-rows off the bottom)\n", X rows - 1 - bottom, background ); X if ( left > 0 ) X fprintf( stderr, "(cropping %d %d-cols off the left)\n", X left, background ); X if ( right < cols - 1 ) X fprintf( stderr, "(cropping %d %d-cols off the right)\n", X cols - 1 - right, background ); 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 4241 -ne "`wc -c < 'pbmcrop.c'`" then echo shar: error transmitting "'pbmcrop.c'" '(should have been 4241 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmcrop.1'" '(837 characters)' if test -f 'pbmcrop.1' then echo shar: will not over-write existing file "'pbmcrop.1'" else sed 's/^X//' << \SHAR_EOF > 'pbmcrop.1' X.TH pbmcrop 1 "31 August 1988" X.SH NAME Xpbmcrop - crop a portable bitmap X.SH SYNOPSIS Xpbmcrop [-0]/[-w]/[-1]/[-b] [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/-w and -1/-b flags. X.SH "SEE ALSO" Xpbmcut(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 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 837 -ne "`wc -c < 'pbmcrop.1'`" then echo shar: error transmitting "'pbmcrop.1'" '(should have been 837 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmtrnspos.c'" '(1332 characters)' if test -f 'pbmtrnspos.c' then echo shar: will not over-write existing file "'pbmtrnspos.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmtrnspos.c' X/* pbmtrnspos.c - read a portable bitmap and transpose it x for y X** X** Copyright (C) 1988 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 <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits, **newbits; 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 newbits = pbm_allocarray( rows, cols ); /* note parameter reversal */ X X for ( row = 0; row < rows; row++ ) X for ( col = 0; col < cols; col++ ) X newbits[col][row] = bits[row][col]; X X pbm_writepbm( stdout, newbits, rows, cols ); /* reversed again */ X X exit( 0 ); X } SHAR_EOF if test 1332 -ne "`wc -c < 'pbmtrnspos.c'`" then echo shar: error transmitting "'pbmtrnspos.c'" '(should have been 1332 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmtrnspos.1'" '(1035 characters)' if test -f 'pbmtrnspos.1' then echo shar: will not over-write existing file "'pbmtrnspos.1'" else sed 's/^X//' << \SHAR_EOF > 'pbmtrnspos.1' X.TH pbmtrnspos 1 "31 August 1988" X.SH NAME Xpbmtrnspos - transpose a portable bitmap x for y X.SH SYNOPSIS Xpbmtrnspos [pbmfile] X.SH DESCRIPTION XReads a portable bitmap as input. XTransposes it x for y and produces a portable bitmap as output. X.PP XNote that transposition is not rotation, but can be used to produce it. XFor example, if you wanted a 90 degree clockwise rotation, perhaps for Xprinting a landscape bitmap on a laser printer, you could Xdo 'pbmtrnspos | pbmfliplr' or 'pbmfliptb | pbmtrnspos'. XFor counter-clockwise rotation, you would use the opposite flips. X.SH "SEE ALSO" Xpbmfliplr(1), pbmfliptb(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 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 1035 -ne "`wc -c < 'pbmtrnspos.1'`" then echo shar: error transmitting "'pbmtrnspos.1'" '(should have been 1035 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmcut.c'" '(2606 characters)' if test -f 'pbmcut.c' then echo shar: will not over-write existing file "'pbmcut.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmcut.c' X/* pbmcut.c - cut a rectangle out of a portable bitmap X** X** Copyright (C) 1988 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 <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits, **newbits; X int rows, cols, x, y, width, height, row, col; X char *usage = "usage: %s x y width height [pbmfile]\n"; X X X if ( argc < 5 || argc > 6 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X X if ( sscanf( argv[1], "%d", &x ) != 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X if ( sscanf( argv[2], "%d", &y ) != 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X if ( sscanf( argv[3], "%d", &width ) != 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X if ( sscanf( argv[4], "%d", &height ) != 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X X if ( x < 0 ) X { X fprintf( stderr, "x is less than 0\n" ); X exit( 1 ); X } X if ( y < 0 ) X { X fprintf( stderr, "y is less than 0\n" ); X exit( 1 ); X } X if ( width < 1 ) X { X fprintf( stderr, "width is less than 1\n" ); X exit( 1 ); X } X if ( height < 1 ) X { X fprintf( stderr, "height is less than 1\n" ); X exit( 1 ); X } X X if ( argc == 6 ) X { X ifd = fopen( argv[5], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[5] ); 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 ( x >= cols ) X { X fprintf( X stderr, "x is too large -- the bitmap has only %d cols\n", cols ); X exit( 1 ); X } X if ( y >= rows ) X { X fprintf( X stderr, "y is too large -- the bitmap has only %d rows\n", rows ); X exit( 1 ); X } X if ( x + width > cols ) X { X fprintf( X stderr, "x + width is too large by %d pixels\n", x + width - cols ); X exit( 1 ); X } X if ( y + height > rows ) X { X fprintf( X stderr, "y + height is too large by %d pixels\n", X y + height - rows ); X exit( 1 ); X } X X newbits = pbm_allocarray( width, height ); X for ( row = y; row < y + height; row++ ) X for ( col = x; col < x + width; col++ ) X newbits[row-y][col-x] = bits[row][col]; X X pbm_writepbm( stdout, newbits, width, height ); X X exit( 0 ); X } SHAR_EOF if test 2606 -ne "`wc -c < 'pbmcut.c'`" then echo shar: error transmitting "'pbmcut.c'" '(should have been 2606 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmcut.1'" '(726 characters)' if test -f 'pbmcut.1' then echo shar: will not over-write existing file "'pbmcut.1'" else sed 's/^X//' << \SHAR_EOF > 'pbmcut.1' X.TH pbmcut 1 "31 August 1988" X.SH NAME Xpbmcut - cut a rectangle out of a portable bitmap X.SH SYNOPSIS Xpbmcut x y width height [pbmfile] X.SH DESCRIPTION XReads a portable bitmap as input. XExtracts the specified rectangle, Xand produces a portable bitmap as output. X.SH "SEE ALSO" Xpbmcrop(1), pbmpaste(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 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 726 -ne "`wc -c < 'pbmcut.1'`" then echo shar: error transmitting "'pbmcut.1'" '(should have been 726 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmpaste.c'" '(3521 characters)' if test -f 'pbmpaste.c' then echo shar: will not over-write existing file "'pbmpaste.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmpaste.c' X/* pbmpaste.c - paste a rectangle into a portable bitmap X** X** Copyright (C) 1988 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 <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits1, **bits2; X int argn, rows1, cols1, x, y, rows2, cols2, row, col; X char function; X char *usage = "usage: %s [-r]/[-o]/[-a]/[-x] frompbmfile x y [intopbmfile]\n"; X X argn = 1; X function = 'r'; X X /* Check for flags. */ X if ( argn < argc ) X { X if ( argv[argn][0] == '-' ) X { X if ( ( argv[argn][1] == 'r' || argv[argn][1] == 'R' || X argv[argn][1] == 'o' || argv[argn][1] == 'O' || X argv[argn][1] == 'a' || argv[argn][1] == 'A' || X argv[argn][1] == 'x' || argv[argn][1] == 'X' ) && X argv[argn][2] == '\0' ) X function = argv[argn][1]; X else X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X argn++; X } X } X X if ( argn == argc ) X { X fprintf( stderr, usage, argv[0] ); X exit( 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 bits1 = pbm_readpbm( ifd, &cols1, &rows1 ); X fclose( ifd ); X argn++; X X if ( argn == argc ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X if ( sscanf( argv[argn], "%d", &x ) != 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X argn++; X if ( argn == argc ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X if ( sscanf( argv[argn], "%d", &y ) != 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X argn++; X X if ( x < 0 ) X { X fprintf( stderr, "x is less than 0\n" ); X exit( 1 ); X } X if ( y < 0 ) X { X fprintf( stderr, "y is less than 0\n" ); X exit( 1 ); X } X X if ( argn == argc ) X ifd = stdin; X else 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 argn++; X } X bits2 = pbm_readpbm( ifd, &cols2, &rows2 ); X if ( ifd != stdin ) X fclose( ifd ); X X if ( x >= cols2 ) X { X fprintf( X stderr, "x is too large -- the second bitmap has only %d cols\n", X cols2 ); X exit( 1 ); X } X if ( y >= rows2 ) X { X fprintf( X stderr, "y is too large -- the second bitmap has only %d rows\n", X rows2 ); X exit( 1 ); X } X if ( x + cols1 > cols2 ) X { X fprintf( X stderr, "x + width is too large by %d pixels\n", X x + cols1 - cols2 ); X exit( 1 ); X } X if ( y + rows1 > rows2 ) X { X fprintf( X stderr, "y + height is too large by %d pixels\n", X y + rows1 - rows2 ); X exit( 1 ); X } X X if ( argn != argc ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X X for ( row = 0; row < rows1; row++ ) X for ( col = 0; col < cols1; col++ ) X switch ( function ) X { X case 'r': X case 'R': X bits2[row+y][col+x] = bits1[row][col]; X break; X X case 'o': X case 'O': X bits2[row+y][col+x] |= bits1[row][col]; X break; X X case 'a': X case 'A': X bits2[row+y][col+x] &= bits1[row][col]; X break; X X case 'x': X case 'X': X bits2[row+y][col+x] ^= bits1[row][col]; X break; X } X X pbm_writepbm( stdout, bits2, cols2, rows2 ); X X exit( 0 ); X } SHAR_EOF if test 3521 -ne "`wc -c < 'pbmpaste.c'`" then echo shar: error transmitting "'pbmpaste.c'" '(should have been 3521 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmpaste.1'" '(1311 characters)' if test -f 'pbmpaste.1' then echo shar: will not over-write existing file "'pbmpaste.1'" else sed 's/^X//' << \SHAR_EOF > 'pbmpaste.1' X.TH pbmpaste 1 "06 April 1988" X.SH NAME Xpbmpaste - paste a rectangle into a portable bitmap X.SH SYNOPSIS Xpbmpaste [-r]/[-o]/[-a]/[-x] frompbmfile x y [intopbmfile] X.SH DESCRIPTION XReads two portable bitmaps as input. XInserts the first bitmap into the second at the specified location, Xand produces a portable bitmap the same size as the second as output. XIf the second bitmap is not specified, it is read from stdin. X.PP XThe -r/-o/-a/-x flags specify the logical operation to use when doing Xthe paste. XThey stand for Replace, Or, And, and Xor, respectively. XThe default is replace. X.PP XThis tool is most useful in combination with pbmcut(1). XFor instance, if you want to edit a small segment of a large Xbitmap, and your bitmap editor is TOO STUPID to edit the Xlarge bitmap, you can cut out the segment you are interested in, Xedit it, and then paste it back in. X.SH "SEE ALSO" Xpbmcut(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 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 1311 -ne "`wc -c < 'pbmpaste.1'`" then echo shar: error transmitting "'pbmpaste.1'" '(should have been 1311 characters)' fi fi # end of overwriting check echo shar: extracting "'xxxtopbm.c'" '(2375 characters)' if test -f 'xxxtopbm.c' then echo shar: will not over-write existing file "'xxxtopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'xxxtopbm.c' X/* xxxtopbm.c - read an xxx bitmap and write a portable bitmap X** X** Copyright (C) 1988 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 <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits, getbit(); X int rows, cols, padright, row, col, subcol; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [xxxfile]\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 getinit( ifd, &cols, &rows ); X X bits = pbm_allocarray( cols, rows ); X X /* Compute padding to round cols up to the next multiple of 16. */ X padright = ( ( cols + 15 ) / 16 ) * 16 - cols; X X for ( row = 0; row < rows; row++ ) X { X /* Get data, bit-reversed within each byte. */ X for ( col = 0; col < cols; col += 8 ) X for ( subcol = col + 7; subcol >= col; subcol-- ) X bits[row][subcol] = getbit( ifd ); X /* Discard line padding */ X for ( col = 0; col < padright; col ++ ) X (void) getbit( ifd ); X } X X if ( ifd != stdin ) X fclose( ifd ); X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } X X Xint item, bitsperitem, bitshift; X Xgetinit( file, colp, rowp ) XFILE *file; Xint *colp, *rowp; X { X int i; X X if ( getc( file ) != 109 ) X { X fprintf( stderr, "Bad magic number 1.\n" ); X exit( 1 ); X } X if ( getc( file ) != 1 ) X { X fprintf( stderr, "Bad magic number 2.\n" ); X exit( 1 ); X } X *colp = getc( file ); X *colp += getc( file ) << 8; X *rowp = getc( file ); X *rowp += getc( file ) << 8; X bitsperitem = 8; X X /* Junk rest of header. */ X for ( i = 0; i < 2; i++ ) X (void) getc( file ); X } X Xbit Xgetbit( file ) XFILE *file; X { X bit b; X X if ( bitsperitem == 8 ) X { X item = getc( file ); X bitsperitem = 0; X bitshift = 7; X } X bitsperitem++; X b = ( item >> bitshift) & 1; X bitshift--; X return b; X } SHAR_EOF if test 2375 -ne "`wc -c < 'xxxtopbm.c'`" then echo shar: error transmitting "'xxxtopbm.c'" '(should have been 2375 characters)' fi fi # end of overwriting check echo shar: extracting "'xxxtopbm.1'" '(922 characters)' if test -f 'xxxtopbm.1' then echo shar: will not over-write existing file "'xxxtopbm.1'" else sed 's/^X//' << \SHAR_EOF > 'xxxtopbm.1' X.TH xxxtopbm 1 "28 August 1988" X.SH NAME Xxxxtopbm - convert "xxx" bitmaps into portable bitmaps X.SH SYNOPSIS Xxxxtopbm [xxxfile] X.SH DESCRIPTION XReads an "xxx" bitmap as input. XProduces a portable bitmap as output. X.LP X"xxx" bitmaps are the unknown and undocumented format found on Xucbvax.Berkeley.Edu in the directory pub/xbackgrounds. XThe arrangement of the bits is the same as for Sun rasterfiles, but Xthe headers are completely different. X.LP XNote that there is no pbmtoxxx tool. X.SH "SEE ALSO" Xpbm(5) X.SH AUTHOR XCopyright (C) 1988 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 922 -ne "`wc -c < 'xxxtopbm.1'`" then echo shar: error transmitting "'xxxtopbm.1'" '(should have been 922 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmenlarge.c'" '(1776 characters)' if test -f 'pbmenlarge.c' then echo shar: will not over-write existing file "'pbmenlarge.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmenlarge.c' X/* pbmenlarge.c - read a portable bitmap and enlarge it N times X** X** Copyright (C) 1988 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 <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits, **newbits; X int argn, n, rows, cols, row, col, subrow, subcol; X char *usage = "usage: %s [-N] [pbmfile]\n"; X X argn = 1; X n = 2; X X if ( argn < argc ) X { X if ( argv[argn][0] == '-' ) X { X if ( sscanf( &(argv[argn][1]), "%d", &n ) != 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X if ( n < 2 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X argn++; X } X } X X if ( argn == argc ) X ifd = stdin; X else 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 argn++; X } X X if ( argn != argc ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X X bits = pbm_readpbm( ifd, &cols, &rows ); X if ( ifd != stdin ) X fclose( ifd ); X X newbits = pbm_allocarray( cols * n, rows * n ); X X for ( row = 0; row < rows; row++ ) X for ( col = 0; col < cols; col++ ) X for ( subrow = 0; subrow < n; subrow++ ) X for ( subcol = 0; subcol < n; subcol++ ) X newbits[row * n + subrow][col * n + subcol] = X bits[row][col]; X X pbm_writepbm( stdout, newbits, cols * n, rows * n ); X X exit( 0 ); X } SHAR_EOF if test 1776 -ne "`wc -c < 'pbmenlarge.c'`" then echo shar: error transmitting "'pbmenlarge.c'" '(should have been 1776 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmenlarge.1'" '(735 characters)' if test -f 'pbmenlarge.1' then echo shar: will not over-write existing file "'pbmenlarge.1'" else sed 's/^X//' << \SHAR_EOF > 'pbmenlarge.1' X.TH pbmenlarge 1 "29 February 1988" X.SH NAME Xpbmenlarge - read a portable bitmap and enlarge it N times X.SH SYNOPSIS Xpbmenlarge [-N] [pbmfile] X.SH DESCRIPTION XReads a portable bitmap as input. XReplicates its bits N times, and produces a portable bitmap as output. XThe default enlargement is two. X.SH "SEE ALSO" Xpbm(5) X.SH AUTHOR XCopyright (C) 1988 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 735 -ne "`wc -c < 'pbmenlarge.1'`" then echo shar: error transmitting "'pbmenlarge.1'" '(should have been 735 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmmake.c'" '(2226 characters)' if test -f 'pbmmake.c' then echo shar: will not over-write existing file "'pbmmake.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmmake.c' X/* pbmmake.c - create a blank bitmap of a specified size X** X** Copyright (C) 1988 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 <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X bit color, gray, rowcolor, **bits; X int argn, rows, cols, row, col; X char *usage = "usage: %s [-0]/[-w]/[-1]/[-b]/[-g] <width> <height>\n"; X X argn = 1; X color = 0; X gray = 0; X X /* Check for flags. */ X if ( argn < argc ) X { X if ( argv[argn][0] == '-' ) X { X if ( ( argv[argn][1] == '0' || argv[argn][1] == 'w' || X argv[argn][1] == 'W' ) && argv[argn][2] == '\0' ) X color = 0; X else if ( ( argv[argn][1] == '1' || argv[argn][1] == 'b' || X argv[argn][1] == 'B' ) && argv[argn][2] == '\0' ) X color = 1; X else if ( ( argv[argn][1] == 'g' || argv[argn][1] == 'G' ) && X argv[argn][2] == '\0' ) X gray = 1; X else X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X argn++; X } X } X X if ( argn == argc ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X if ( sscanf( argv[argn], "%d", &cols ) != 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X argn++; X if ( argn == argc ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X if ( sscanf( argv[argn], "%d", &rows ) != 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X argn++; X X if ( argn != argc ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X X bits = pbm_allocarray( cols, rows ); X X if ( gray ) X rowcolor = 0; /* arbitrarily make the corner white */ X for ( row = 0; row < rows; row++ ) X { X if ( gray ) X { X color = rowcolor; X rowcolor = 1 - rowcolor; X } X for ( col = 0; col < cols; col++ ) X { X bits[row][col] = color; X if ( gray ) X color = 1 - color; X } X } X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } SHAR_EOF if test 2226 -ne "`wc -c < 'pbmmake.c'`" then echo shar: error transmitting "'pbmmake.c'" '(should have been 2226 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmmake.1'" '(870 characters)' if test -f 'pbmmake.1' then echo shar: will not over-write existing file "'pbmmake.1'" else sed 's/^X//' << \SHAR_EOF > 'pbmmake.1' X.TH pbmmake 1 "16 May 1988" X.SH NAME Xpbmmake - create a blank bitmap of a specified size X.SH SYNOPSIS Xpbmmake [-0]/[-w]/[-1]/[-b]/[-g] <width> <height> X.SH DESCRIPTION XProduces a portable bitmap of the specified width and height. XThe color defaults to 0/white. X.LP XIn addition to the usual -w/-0 for white and -b/-1 for black, this program Ximplements -g for gray. XThis gives a simple 50% gray pattern with 1's and 0's alternating. X.SH "SEE ALSO" Xpbm(5) X.SH AUTHOR XCopyright (C) 1988 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 870 -ne "`wc -c < 'pbmmake.1'`" then echo shar: error transmitting "'pbmmake.1'" '(should have been 870 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmtolj.c'" '(3054 characters)' if test -f 'pbmtolj.c' then echo shar: will not over-write existing file "'pbmtolj.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmtolj.c' X/* pbmtolj.c - read a portable bitmap and produce a LaserJet bitmap file X** X** based on pbmtops.c X** X** Michael Haberler HP Vienna mah@hpuviea.uucp X** mcvax!tuvie!mah X** misfeatures: X** no positioning X** X** Copyright (C) 1988 by Jef Poskanzer and Michael Haberler. 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 <stdio.h> X#ifdef OS_SYSV X#include <string.h> X#else OS_SYSV X#include <strings.h> X#endif OS_SYSV X#include "pbm.h" X Xint dpi = 75; X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits; X int argn, rows, cols, rucols, padright, row, col; X char ch; X char *usage = X"usage: %s [-r resolution] [pbmfile]\n\t\ Xresolution = [75|100|150|300] (dpi)\n"; X X argn = 1; X X /* Check for flags. */ X if ( argc > argn ) X { X if ( argv[argn][0] == '-' ) X { X if ( strcmp( argv[argn], "-r" ) == 0 ) X { X if ( argc == argn + 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X if ( sscanf( argv[argn+1], "%d", &dpi ) != 1 ) X { X fprintf( stderr, usage, argv[0] ); X exit( 1 ); X } X argn += 2; 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 /* Round cols up to the nearest multiple of 8. */ X rucols = ( cols + 7 ) / 8; X rucols = rucols * 8; X padright = rucols - cols; X X putinit( ); X for ( row = 0; row < rows; row++ ) X { X /* Transfer raster graphics */ X printf("\033*b%dW",rucols/8); X for ( col = 0; col < cols; col++ ) X putbit( bits[row][col] ); X for ( col = 0; col < padright; col++ ) X putbit( 0 ); X } X putrest( ); X X exit( 0 ); X } X X Xint item, bitsperitem, bitshift, itemsperline, firstitem; X Xputinit( ) X { X /* Set raster graphics resolution */ X printf("\033*t%dR",dpi); X X /* Start raster graphics, relative adressing */ X printf("\033*r1A"); X X itemsperline = 0; X bitsperitem = 1; X item = 0; X bitshift = 7; X firstitem = 1; X } X Xputbit( b ) Xbit b; X { X if ( bitsperitem == 8 ) { X putitem( ); X bitshift = 7; X } X if ( b ) X item += 1 << bitshift; X bitsperitem++; X bitshift--; X } X Xputrest( ) X { X if ( bitsperitem > 1 ) X putitem( ); X X /* end raster graphics */ X printf( "\033*rB" ); X } X Xputitem( ) X { X putchar( item ); X bitsperitem = 0; X item = 0; X } SHAR_EOF if test 3054 -ne "`wc -c < 'pbmtolj.c'`" then echo shar: error transmitting "'pbmtolj.c'" '(should have been 3054 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmtolj.1'" '(862 characters)' if test -f 'pbmtolj.1' then echo shar: will not over-write existing file "'pbmtolj.1'" else sed 's/^X//' << \SHAR_EOF > 'pbmtolj.1' X.TH pbmtolj 1 "29 August 1988" X.SH NAME Xpbmtolj - convert portable bitmaps into HP LaserJet X.SH SYNOPSIS Xpbmtolj [ -r <resolution> ] [ <pbmfile> ] X.SH DESCRIPTION XReads a portable bitmap as input. XProduces HP LaserJet data as output. X.LP XThe -r flag specifies the resolution of the output device, in dpi. XTypical values are 75, 100, 150, 300. XThe default is 75. X.LP XNote that there is no ljtopbm tool. X.SH "SEE ALSO" Xpbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer and Michael Haberler. 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 862 -ne "`wc -c < 'pbmtolj.1'`" then echo shar: error transmitting "'pbmtolj.1'" '(should have been 862 characters)' fi fi # end of overwriting check echo shar: extracting "'pbmtomacp.c'" '(6598 characters)' if test -f 'pbmtomacp.c' then echo shar: will not over-write existing file "'pbmtomacp.c'" else sed 's/^X//' << \SHAR_EOF > 'pbmtomacp.c' X/* pbmtomacp.c - read a portable bitmap and produce a MacPaint bitmap file X** X** Copyright (C) 1988 by Douwe vand der Schaaf. 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 <stdio.h> X#include "pbm.h" X#include "macp.h" X X#define TRUE 1 X#define FALSE 0 X#define EQUAL 1 X#define UNEQUAL 0 X XFILE *fdout; Xchar *Program; Xchar *usage = X "usage: %s [-l left] [-r right] [-b bottom] [-t top] [pbmfile]\n"; X Xextern int optind; Xextern char *optarg; X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ int c; X FILE *ifd; X bit **bits, **bitsr; X int rows, cols; X int left,bottom,right,top; X int lflg, rflg, tflg, bflg, errflg; X char name[100]; Xint i,j; X X fdout = stdout; X Program = argv[0]; X errflg = lflg = rflg = tflg = bflg = 0; X if( argc > 1 ) X { while( ( c = getopt( argc, argv, "l:r:t:b:" ) ) != EOF ) X switch(c) X { Xcase 'l': X lflg++; X left = atoi( optarg ); X break; X Xcase 'r': X rflg++; X right = atoi( optarg ); X break; X Xcase 't': X tflg++; X top = atoi( optarg ); X break; X Xcase 'b': X bflg++; X bottom = atoi( optarg ); X break; X Xcase '?': Xdefault: X errflg++; X } X if (errflg) X { fprintf( stderr, "%s: ERROR. incorrect flag\n", Program ); X fprintf( stderr, usage, Program ); X exit(1); X } } X X if ( argc - optind > 1 ) X { fprintf( stderr, "%s: ERROR. more than 1 inputfile given.\n", Program ); X fprintf( stderr, usage, Program ); X exit( 2 ); X } X X if ( optind == argc - 1 ) X { ifd = fopen( argv[optind], "r" ); X if ( ifd == NULL ) X { fprintf( stderr, "%s: can't open.\n", argv[optind] ); X exit( 3 ); X } X strcpy( name, argv[optind] ); X } X else X { ifd = stdin; X strcpy( name, "noname" ); X } X X bitsr = pbm_readpbm( ifd, &cols, &rows ); X X if ( ifd != stdin ) X fclose( ifd ); X X bits = pbm_allocarray( MAX_COLS, MAX_LINES ); X X if( !lflg ) X left = 0; X X if( rflg ) X { if( right - left >= MAX_COLS ) X right = left + MAX_COLS - 1; X } X else X right = ( left + MAX_COLS > cols ) ? ( cols - 1 ) : ( left + MAX_COLS - 1 ); X X if( !tflg ) X top = 0; X X if( bflg ) X { if( bottom - top >= MAX_LINES ) X bottom = top + MAX_LINES - 1; X } X else X bottom = ( top + MAX_LINES > rows ) ? X ( rows - 1 ) : ( top + MAX_LINES - 1 ); X X if( !checkborders( top, left, bottom, right ) ) X exit( 4 ); X X fillbits( bits, bitsr, top, left, bottom, right ); X X writemacp( bits ); X X} /* main */ X X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */ X Xcheckborders( top, left, bottom, right ) Xint top, left, bottom, right; X{ if( right <= left || left < 0 || right - left + 1 > MAX_COLS ) X { fprintf(stderr,"%s: error in right (= %d) and/or left (=%d)\n", X Program,right,left ); X return( FALSE ); X } X if( bottom <= top || top < 0 || bottom - top + 1 > MAX_LINES ) X { fprintf(stderr,"%s: error in bottom (= %d) and/or top (=%d)\n", X Program,bottom,top ); X return( FALSE ); X } X return( TRUE ); X} /* checkborders */ X X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */ X X/* centreer het over te zenden plaatje in het MacPaint document X * X * Het plaatje wordt vanaf al of niet opgegeven (left, bottom) X * in een pbm bitmap van de juist macpaint afmetingen gezet, X * en eventueel afgekapt. X */ Xfillbits( bits, bitsr, top, left, bottom, right ) Xbit **bits, **bitsr; Xint top, left, bottom, right; X{ register bit *bi, *bir; X register int i, j; X register int bottomr, leftr, topr, rightr; X int width, height; X X width = right - left + 1; X leftr = (MAX_COLS - width) / 2; X rightr = leftr + width - 1; X X height = bottom - top + 1; X topr = ( MAX_LINES - height ) / 2; X bottomr = topr + height - 1; X X for( i = 0; i < topr; i++ ) X { bi = bits[i]; X for( j = 0; j < MAX_COLS; j++ ) X *bi++ = 0; X } X X for( i = topr; i <= bottomr; i++ ) X { bi = bits[i]; X { for( j = 0; j < leftr; j++ ) X *bi++ = 0; X bir = bitsr[ i - topr + top ]; X for( j = leftr; j <= rightr; j++ ) X *bi++ = bir[j - leftr + left]; X for( j = rightr + 1; j < MAX_COLS; j++ ) X *bi++ = 0; X } } X X for( i = bottomr + 1; i < MAX_LINES; i++ ) X { bi = bits[i]; X for( j = 0; j < MAX_COLS; j++ ) X *bi++ = 0; X } X} /* fillbits */ X X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */ X Xwritemacp( bits ) Xbit **bits; X{ register int i; X bit pb[MAX_COLS * 2]; X int npb; X X header(); X for( i=0; i < MAX_LINES; i++ ) X { npb = packit( pb, bits[i] ); X sendbytes( pb, npb ); X } X} /* writemacp */ X X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */ X X/* pack regel van MacPaint doc in Apple's format X * return value = # of bytes in pb X */ Xint Xpackit( pb, bits ) Xbit *pb, *bits; X{ register int i, charcount, npb, newcount, flg; X bit temp[72]; X bit *count, *srcb, *destb, save; X X srcb = bits; destb = temp; X filltemp( destb, srcb ); X srcb = temp; X destb = pb; X npb = 0; X charcount = BYTES_WIDE; X flg = EQUAL; X while( charcount ) X { save = *srcb++; X charcount--; X newcount = 1; X while( (*srcb == save) && charcount ) X { srcb++; X newcount++; X charcount--; X } X if( newcount > 2 ) X { count = destb++; X *count = 257 - newcount; X *destb++ = save; X npb += 2; X flg = EQUAL; X } X else X { if( flg == EQUAL ) X { count = destb++; X *count = newcount - 1; X npb++; X } X else X *count += newcount; X while( newcount-- ) X { *destb++ = save; X npb++; X } X flg = UNEQUAL; X } } X return npb; X} /* packit */ X X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */ X Xfilltemp( dest, src ) Xbit *src, *dest; X{ register unsigned char ch, zero, acht; X register int i, j; X X zero = '\0'; X acht = 8; X i = BYTES_WIDE; X while( i-- ) X { ch = zero; X j = acht; X while( j-- ) X { ch <<= 1; X if( *src++ ) X ch++; X } X *dest++ = ch; X } X} /* filltemp */ X X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */ X Xsendbytes( pb, npb ) Xbit *pb; Xregister int npb; X{ register bit *b; X X b = pb; X while( npb-- ) X putc( *b++, fdout ); X} /* sendbytes */ X X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */ X Xheader() X{ register int i; X register char ch; X X /* header contains nothing ... */ X ch = '\0'; X for(i = 0; i < HEADER_LENGTH; i++ ) X putc( ch, fdout ); X} /* header */ SHAR_EOF if test 6598 -ne "`wc -c < 'pbmtomacp.c'`" then echo shar: error transmitting "'pbmtomacp.c'" '(should have been 6598 characters)' fi fi # end of overwriting check # End of shell archive exit 0