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: # README # FORMATS # Makefile # cbmtopbm.c # cbmtopbm.man # icontopbm.c # icontopbm.man # macpainttopbm.c # macpainttopbm.man # rastertopbm.c # rastertopbm.man # This archive created: Wed Feb 10 03:53:51 1988 # By: Jef Poskanzer export PATH; PATH=/bin:$PATH echo shar: extracting "'README'" '(2014 characters)' if test -f 'README' then echo shar: will not over-write existing file "'README'" else sed 's/^X//' << \SHAR_EOF > 'README' X Portable Bitmap Toolkit X Distribution of 09feb88 X X XIncluded are a number of programs for converting various bitmap formats Xto and from a portable format; plus some tools for manipulating the Xportable bitmaps. X X XFiles in this distribution: X X README this X FORMATS descriptions of the various bitmap formats X Makefile guess X X cbmtopbm.c convert from compact bitmap to portable bitmap X icontopbm.c convert from Sun icon to portable bitmap X macpainttopbm.c convert from Macintosh MacPaint to portable bitmap X rastertopbm.c convert from Sun raster to portable bitmap X xbmtopbm.c convert from X10 or X11 bitmap to portable bitmap X X pbmtocbm.c convert from portable bitmap to compact bitmap X pbmtoicon.c convert from portable bitmap to Sun icon X pbmtoraster.c convert from portable bitmap to Sun raster X pbmtoxbm.c convert from portable bitmap to X11 bitmap X pbmtox10bm.c convert from portable bitmap to X10 bitmap X pbmtops.c convert from portable bitmap to PostScript X pbmtoptx.c convert from portable bitmap to Printronix X pbmtoascii.c convert from portable bitmap to ASCII graphic form X X pbminvert.c invert a portable bitmap X pbmcrop.c crop a portable bitmap X pbmcatlr.c concatenate portable bitmaps left to right X pbmcattb.c concatenate portable bitmaps top to bottom X pbmfliplr.c flip a portable bitmap left for right X pbmfliptb.c flip a portable bitmap top for bottom X X libpbm.c a few utility routines X pbm.h header file for libpbm X bmaliases csh script to make aliases for converting formats X *.man manual entries for all of the tools X X XUnpack the files, edit Makefile and change the options to suit, Xmake, and enjoy! I've tested this stuff under 4.2 BSD, 4.3 BSD, Xand System V rel 2. Nevertheless, I'm sure bugs remain. Feedback Xis welcome - send bug reports, enhancements, checks, money orders, Xetc. to the addresses below. X X X Jef Poskanzer X jef@lbl-rtsg.arpa SHAR_EOF if test 2014 -ne "`wc -c < 'README'`" then echo shar: error transmitting "'README'" '(should have been 2014 characters)' fi fi # end of overwriting check echo shar: extracting "'FORMATS'" '(2967 characters)' if test -f 'FORMATS' then echo shar: will not over-write existing file "'FORMATS'" else sed 's/^X//' << \SHAR_EOF > 'FORMATS' XFormats currently supported are: X X X11 and X10 bitmaps X Sun icons X Sun raster files. X Macintosh MacPaint files X PostScript X Printronix printer graphics X "portable bitmap format" X "compact bitmap format" X X XThe portable bitmap format is something I came up with while I was Xat Xerox. It is a lowest common denominator, designed to make it Xreasonable to mail bitmaps between different types machines using the Xtypical stupid network mailers we have today. The definition is as Xfollows: X X - a width, formatted as ASCII characters in decimal; X X - whitespace (blanks, TABs, CRs, LFs); X X - a height, again in ASCII decimal; X X - whitespace; X X - width * height bits, each either '1' or '0', starting at the top-left X corner of the bitmap, proceding in normal English reading order; X X - '1' means black, '0' means white; X X - whitespace in the bits section is ignored; X X - characters from a "#" to the next end-of-line are ignored (comments); X X - no line may be longer than 70 characters. X XHere is an example of a small bitmap in this format: X X # feep.pbm X 24 7 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 X 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 X 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0 X 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 X 0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X XPrograms that read this format should be as lenient as possible, Xaccepting anything that looks remotely like a bitmap. For instance, Xthe above example does not actually conform to the standard, since Xit has whitespace before the width; neverthless, it should be accepted. X X XThe compact bitmap format is the same basic idea as the portable Xformat, but it assumes the underlying filesystem can reliably store X8-bit bytes. If you have the compress and zcat programs, you should Xnot bother with compact bitmaps -- all formats are about the same size Xafter being compressed. Otherwise, compact bitmaps are probably the Xmost space-efficient format. The definition: X X - Two bytes of "magic number", which are always 0x2A 0x17. X X - Two bytes representing the width. The bytes are in "big-endian" X order, i.e. the formula for the width is firstbyte * 256 + secondbyte. X X - Two bytes representing the height, same order as above. X X - The bits, in the same order as in the portable format: starting X at the top-left, proceeding in normal English reading order. X Within each byte, the most significant bit is used first, and so X on down to the least significant bit. X X - Nothing special happens at the end of a row -- no padding, not even X to the end of the current byte. X X - A 1 bit means black, a 0 bit means white; X X - All eight bits of each byte are used, except of course for the X last byte, where there may be some extra bits. These are ignored. SHAR_EOF if test 2967 -ne "`wc -c < 'FORMATS'`" then echo shar: error transmitting "'FORMATS'" '(should have been 2967 characters)' fi fi # end of overwriting check echo shar: extracting "'Makefile'" '(4510 characters)' if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else sed 's/^X//' << \SHAR_EOF > 'Makefile' X# Makefile for pbm tools. X X X# Valid options: X# OS_BSD Set this if your system is BSD 4.2 or later. X# OS_SYSV Set this if your system is System V. XOPTIONS = -DOS_BSD X X XCC = cc XCFLAGS = -O $(OPTIONS) X X.SUFFIXES: .man .cat X.man.cat: X nroff -h -man $< > $@ X X Xall: cbmtopbm cbmtopbm.cat icontopbm icontopbm.cat macpainttopbm \ X macpainttopbm.cat rastertopbm rastertopbm.cat xbmtopbm \ X xbmtopbm.cat pbmtocbm pbmtocbm.cat pbmtoicon pbmtoicon.cat \ X pbmtops pbmtops.cat pbmtoptx pbmtoptx.cat pbmtoraster \ X pbmtoraster.cat pbmtoxbm pbmtoxbm.cat pbmtox10bm \ X pbmtox10bm.cat pbmtoascii pbmtoascii.cat pbmcatlr \ X pbmcatlr.cat pbmcattb pbmcattb.cat pbmfliplr pbmfliplr.cat \ X pbminvert pbminvert.cat pbmcrop pbmcrop.man X X Xcbmtopbm: cbmtopbm.o libpbm.a X $(CC) -s -o cbmtopbm cbmtopbm.o libpbm.a X Xcbmtopbm.o: cbmtopbm.c pbm.h X X Xicontopbm: icontopbm.o libpbm.a X $(CC) -s -o icontopbm icontopbm.o libpbm.a X Xicontopbm.o: icontopbm.c pbm.h X X Xmacpainttopbm: macpainttopbm.o libpbm.a X $(CC) -s -o macpainttopbm macpainttopbm.o libpbm.a X Xmacpainttopbm.o: macpainttopbm.c pbm.h X X Xrastertopbm: rastertopbm.o libpbm.a X $(CC) -s -o rastertopbm rastertopbm.o libpbm.a -lpixrect X Xrastertopbm.o: rastertopbm.c pbm.h X X Xpbmcatlr: pbmcatlr.o libpbm.a X $(CC) -s -o pbmcatlr pbmcatlr.o libpbm.a X Xpbmcatlr.o: pbmcatlr.c pbm.h X X Xpbmcattb: pbmcattb.o libpbm.a X $(CC) -s -o pbmcattb pbmcattb.o libpbm.a X Xpbmcattb.o: pbmcattb.c pbm.h X X Xpbmfliplr: pbmfliplr.o libpbm.a X $(CC) -s -o pbmfliplr pbmfliplr.o libpbm.a X Xpbmfliplr.o: pbmfliplr.c pbm.h X X Xpbmfliptb: pbmfliptb.o libpbm.a X $(CC) -s -o pbmfliptb pbmfliptb.o libpbm.a X Xpbmfliptb.o: pbmfliptb.c pbm.h X X Xpbminvert: pbminvert.o libpbm.a X $(CC) -s -o pbminvert pbminvert.o libpbm.a X Xpbminvert.o: pbminvert.c pbm.h X X Xpbmcrop: pbmcrop.o libpbm.a X $(CC) -s -o pbmcrop pbmcrop.o libpbm.a X Xpbmcrop.o: pbmcrop.c pbm.h X X Xpbmtocbm: pbmtocbm.o libpbm.a X $(CC) -s -o pbmtocbm pbmtocbm.o libpbm.a X Xpbmtocbm.o: pbmtocbm.c pbm.h X X Xpbmtoicon: pbmtoicon.o libpbm.a X $(CC) -s -o pbmtoicon pbmtoicon.o libpbm.a X Xpbmtoicon.o: pbmtoicon.c pbm.h X X Xpbmtops: pbmtops.o libpbm.a X $(CC) -s -o pbmtops pbmtops.o libpbm.a X Xpbmtops.o: pbmtops.c pbm.h X X Xpbmtoptx: pbmtoptx.o libpbm.a X $(CC) -s -o pbmtoptx pbmtoptx.o libpbm.a X Xpbmtoptx.o: pbmtoptx.c pbm.h X X Xpbmtoraster: pbmtoraster.o libpbm.a X $(CC) -s -o pbmtoraster pbmtoraster.o libpbm.a -lpixrect X Xpbmtoraster.o: pbmtoraster.c pbm.h X X Xpbmtoxbm: pbmtoxbm.o libpbm.a X $(CC) -s -o pbmtoxbm pbmtoxbm.o libpbm.a X Xpbmtoxbm.o: pbmtoxbm.c pbm.h X X Xpbmtox10bm: pbmtox10bm.o libpbm.a X $(CC) -s -o pbmtox10bm pbmtox10bm.o libpbm.a X Xpbmtox10bm.o: pbmtox10bm.c pbm.h X X Xpbmtoascii: pbmtoascii.o libpbm.a X $(CC) -s -o pbmtoascii pbmtoascii.o libpbm.a X Xpbmtoascii.o: pbmtoascii.c pbm.h X X Xxbmtopbm: xbmtopbm.o libpbm.a X $(CC) -s -o xbmtopbm xbmtopbm.o libpbm.a X Xxbmtopbm.o: xbmtopbm.c pbm.h X X Xlibpbm.a: libpbm.o X ar r libpbm.a libpbm.o X -ranlib libpbm.a X Xlibpbm.o: libpbm.c pbm.h X X Xclean: X -rm -f *.o libpbm.a *.cat pbm.shar* core icontopbm X -rm -f macpainttopbm rastertopbm pbmcatlr pbmcattb pbmcrop X -rm -f pbmfliplr pbmfliptb pbminvert pbmtoicon pbmtops X -rm -f pvmtoptx pbmtoraster pbmtoxbm pbmtox10bm xbmtopbm X -rm -f pbmtoascii pbmtocbm cbmtopbm X X Xshar: pbm.shar1 pbm.shar2 pbm.shar3 X Xpbm.shar1: README FORMATS Makefile cbmtopbm.c cbmtopbm.man icontopbm.c \ X icontopbm.man macpainttopbm.c macpainttopbm.man rastertopbm.c \ X rastertopbm.man X shar -v -c -p X README FORMATS Makefile cbmtopbm.c cbmtopbm.man icontopbm.c icontopbm.man macpainttopbm.c macpainttopbm.man rastertopbm.c rastertopbm.man > pbm.shar1 X Xpbm.shar2: xbmtopbm.c xbmtopbm.man pbmtocbm.c pbmtocbm.man pbmtoicon.c \ X pbmtoicon.man pbmtops.c pbmtops.man pbmtoptx.c pbmtoptx.man \ X pbmtoraster.c pbmtoraster.man pbmtoxbm.c pbmtoxbm.man \ X pbmtox10bm.c pbmtox10bm.man X shar -v -c -p X xbmtopbm.c xbmtopbm.man pbmtocbm.c pbmtocbm.man pbmtoicon.c pbmtoicon.man pbmtops.c pbmtops.man pbmtoptx.c pbmtoptx.man pbmtoraster.c pbmtoraster.man pbmtoxbm.c pbmtoxbm.man pbmtox10bm.c pbmtox10bm.man > pbm.shar2 X Xpbm.shar3: pbmtoascii.c pbmtoascii.man pbmcatlr.c pbmcatlr.man \ X pbmcattb.c pbmcattb.man pbmfliplr.c pbmfliplr.man pbmfliptb.c \ X pbmfliptb.man pbminvert.c pbminvert.man pbmcrop.c pbmcrop.man \ X libpbm.c pbm.h bmaliases X shar -v -c -p X 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 > pbm.shar3 SHAR_EOF if test 4510 -ne "`wc -c < 'Makefile'`" then echo shar: error transmitting "'Makefile'" '(should have been 4510 characters)' fi fi # end of overwriting check echo shar: extracting "'cbmtopbm.c'" '(1483 characters)' if test -f 'cbmtopbm.c' then echo shar: will not over-write existing file "'cbmtopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'cbmtopbm.c' X/* cbmtopbm.c - read a compact bitmap and write 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, getbit(); X int rows, cols, row, col; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [cbmfile]\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 for ( row = 0; row < rows; row++ ) X for ( col = 0; col < cols; col++ ) X bits[row][col] = getbit( ifd ); 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 if ( getc( file ) != 42 ) X { X fprintf( stderr, "Bad magic number." ); X exit( 1 ); X } X if ( getc( file ) != 23 ) X { X fprintf( stderr, "Bad magic number." ); X exit( 1 ); X } X *colp = getc( file ) << 8; X *colp += getc( file ); X *rowp = getc( file ) << 8; X *rowp += getc( file ); X bitsperitem = 8; 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 1483 -ne "`wc -c < 'cbmtopbm.c'`" then echo shar: error transmitting "'cbmtopbm.c'" '(should have been 1483 characters)' fi fi # end of overwriting check echo shar: extracting "'cbmtopbm.man'" '(537 characters)' if test -f 'cbmtopbm.man' then echo shar: will not over-write existing file "'cbmtopbm.man'" else sed 's/^X//' << \SHAR_EOF > 'cbmtopbm.man' X.TH cbmtopbm 1 "08 February 1988" "PBM" X.SH NAME Xcbmtopbm \- convert compact bitmaps into portable bitmaps X.SH SYNOPSIS Xcbmtopbm \%[cbmfile] X.SH DESCRIPTION XReads a compact bitmap as input. XProduces 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 537 -ne "`wc -c < 'cbmtopbm.man'`" then echo shar: error transmitting "'cbmtopbm.man'" '(should have been 537 characters)' fi fi # end of overwriting check echo shar: extracting "'icontopbm.c'" '(4092 characters)' if test -f 'icontopbm.c' then echo shar: will not over-write existing file "'icontopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'icontopbm.c' X/* icontopbm.c - read a Sun icon file and produce a portable bitmap X*/ X X#include <stdio.h> X#include <sys/types.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, shortcount, mask; X short *data; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [iconfile]\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 if ( ReadIconFile( ifd, &cols, &rows, &data ) < 0 ) X { X fprintf( stderr, "%s: can't load.\n", argv[1] ); X exit( 1 ); X } X X if ( ifd != stdin ) X fclose( ifd ); X X bits = pbm_allocarray( cols, rows ); X X for ( row = 0; row < rows; row++ ) X { X shortcount = 0; X mask = 0x8000; X for ( col = 0; col < cols; col++ ) X { X if ( shortcount >= 16 ) X { X data++; X shortcount = 0; X mask = 0x8000; X } X bits[row][col] = ( ( *data & mask ) ? 1 : 0 ); X shortcount++; X mask = mask >> 1; X } X data++; X } X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } X X X/* size in bytes of a bitmap */ X#define BitmapSize(width, height) (((((width) + 15) >> 3) &~ 1) * (height)) X Xint XReadIconFile( file, width, height, data ) XFILE *file; Xint *width, *height; Xshort **data; X { X char variable[81], ch; X int status, firsttime, value, i, data_length; X X if ( file == NULL ) X return ( -1 ); X X if ( getc( file ) != '/' ) X { X fprintf( stderr, "Error 1 scanning beginning of initial section.\n" ); X return ( -1 ); X } X if ( getc( file ) != '*' ) X { X fprintf( stderr, "Error 2 scanning beginning of initial section.\n" ); X return ( -1 ); X } X if ( getc( file ) != ' ' ) X { X fprintf( stderr, "Error 3 scanning beginning of initial section.\n" ); X return ( -1 ); X } X *width = *height = -1; X firsttime = -1; X for ( ; ; ) X { X if ( firsttime ) X firsttime = 0; X else X if ( getc( file ) != ',' ) X break; X while ( ( ch = getc( file ) ) == '\n' | ch == '\t' | ch == ' ' ) X ; X X for ( i = 0; ch != '='; i++ ) X { X variable[i] = ch; X ch = getc( file ); X } X variable[i] = '\0'; X X if ( fscanf( file, "%d", &value ) != 1 ) X break; X X if ( strcmp( variable, "Width" ) == 0 ) X *width = value; X else if ( strcmp( variable, "Height" ) == 0 ) X *height = value; X else if ( strcmp( variable, "Depth" ) == 0 ) X { X if ( value != 1 ) X { X fprintf( stderr, "Invalid depth.\n" ); X return ( -1 ); X } X } X else if ( strcmp( variable, "Format_version" ) == 0 ) X { X if ( value != 1 ) X { X fprintf( stderr, "Invalid Format_version.\n" ); X return ( -1 ); X } X } X else if ( strcmp( variable, "Valid_bits_per_item" ) == 0 ) X { X if ( value != 16 ) X { X fprintf( stderr, "Invalid Valid_bits_per_item.\n" ); X return ( -1 ); X } X } X } X X if ( getc( file ) != ' ' ) X { X fprintf( stderr, "Error 1 scanning end of initial section.\n" ); X return ( -1 ); X } X if ( getc( file ) != '*' ) X { X fprintf( stderr, "Error 2 scanning end of initial section.\n" ); X return ( -1 ); X } X if ( getc( file ) != '/' ) X { X fprintf( stderr, "Error 3 scanning end of initial section.\n" ); X return ( -1 ); X } X if ( getc( file ) != '\n' ) X { X fprintf( stderr, "Error 4 scanning end of initial section.\n" ); X return ( -1 ); X } X X if ( *width <= 0 ) X { X fprintf( stderr, "Invalid width: %d.\n", *width ); X return ( -1 ); X } X X if ( *height <= 0 ) X { X fprintf( stderr, "Invalid height: %d.\n", *height ); X return ( -1 ); X } X X data_length = BitmapSize( *width, *height ); X *data = (short *) malloc( data_length ); X data_length /= sizeof( short ); X if ( *data == NULL ) X { X return ( -1 ); X } X X for ( i = 0 ; i < data_length; i++ ) X { X if ( i == 0 ) X status = fscanf( file, " 0x%4hx", *data ); X else X status = fscanf( file, ", 0x%4hx", *data + i ); X if ( status != 1 ) X { X free( *data ); X fprintf( stderr, "Error scanning bits item.\n" ); X return ( -1 ); X } X } X X return ( 0 ); X } SHAR_EOF if test 4092 -ne "`wc -c < 'icontopbm.c'`" then echo shar: error transmitting "'icontopbm.c'" '(should have been 4092 characters)' fi fi # end of overwriting check echo shar: extracting "'icontopbm.man'" '(529 characters)' if test -f 'icontopbm.man' then echo shar: will not over-write existing file "'icontopbm.man'" else sed 's/^X//' << \SHAR_EOF > 'icontopbm.man' X.TH icontopbm 1 "08 February 1988" "PBM" X.SH NAME Xicontopbm \- convert Sun icons into portable bitmaps X.SH SYNOPSIS Xicontopbm \%[iconfile] X.SH DESCRIPTION XReads a Sun icon as input. XProduces 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 529 -ne "`wc -c < 'icontopbm.man'`" then echo shar: error transmitting "'icontopbm.man'" '(should have been 529 characters)' fi fi # end of overwriting check echo shar: extracting "'macpainttopbm.c'" '(2670 characters)' if test -f 'macpainttopbm.c' then echo shar: will not over-write existing file "'macpainttopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'macpainttopbm.c' X/* macpainttopbm.c - read a Macintosh MacPaint file and produce a portable X** bitmap X*/ X X#include <stdio.h> X#include <sys/types.h> X#include "pbm.h" X X#define BORDER_WIDTH 3 X#define HEADER_LENGTH 0x280 X#define MAX_LINES 720 X#define BYTES_WIDE 72 X#define MAX_NAME 64 X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X unsigned char Pic[MAX_LINES][BYTES_WIDE]; X bit **bits; X int scanLine, rows, cols, row, bcol, i; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [macpaintfile]\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 if ( ReadMacPaintFile( ifd, &scanLine, Pic ) < 0 ) X { X fprintf( stderr, "%s: can't load.\n", argv[1] ); X exit( 1 ); X } X X if ( ifd != stdin ) X fclose( ifd ); X X cols = BYTES_WIDE * 8; X rows = scanLine; X bits = pbm_allocarray( cols, rows ); X X for ( row = 0; row < rows; row++ ) X for ( bcol = 0; bcol < BYTES_WIDE; bcol++ ) X for ( i = 0; i < 8; i++ ) X bits[row][bcol * 8 + i] = ( (Pic[row][bcol] >> (7 - i)) & 1); X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } X X/* X** Some of the following routine is: X** X** Copyright 1987 by Patrick J. Naughton X** All Rights Reserved X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, X** provided that the above copyright notice appear in all copies and that X** both that copyright notice and this permission notice appear in X** supporting documentation. X*/ X Xint XReadMacPaintFile( file, scanLineP, Pic ) XFILE *file; Xint *scanLineP; Xunsigned char Pic[MAX_LINES][BYTES_WIDE]; X { X unsigned int i, j, k; X unsigned char ch; X X /* Skip over the header. */ X for ( i = 0; i < HEADER_LENGTH; i++ ) X getc( file ); X X *scanLineP = 0; X k = 0; X X while ( *scanLineP < MAX_LINES ) X { X ch = (unsigned char) getc( file ); /* Count byte */ X i = (unsigned int) ch; X if ( ch < 0x80 ) X { /* Unpack next (I+1) chars as is */ X for ( j = 0; j <= i; j++ ) X if ( *scanLineP < MAX_LINES ) X { X Pic[*scanLineP][k++] = (unsigned char) getc( file ); X if ( ! (k %= BYTES_WIDE) ) X *scanLineP += 1; X } X } X else X { /* Repeat next char (2's comp I) times */ X ch = getc( file ); X for ( j = 0; j <= 256 - i; j++ ) X if ( *scanLineP < MAX_LINES ) X { X Pic[*scanLineP][k++] = (unsigned char) ch; X if ( ! (k %= BYTES_WIDE) ) X *scanLineP += 1; X } X } X } X X return(0); X } SHAR_EOF if test 2670 -ne "`wc -c < 'macpainttopbm.c'`" then echo shar: error transmitting "'macpainttopbm.c'" '(should have been 2670 characters)' fi fi # end of overwriting check echo shar: extracting "'macpainttopbm.man'" '(985 characters)' if test -f 'macpainttopbm.man' then echo shar: will not over-write existing file "'macpainttopbm.man'" else sed 's/^X//' << \SHAR_EOF > 'macpainttopbm.man' X.TH macpainttopbm 1 "08 February 1988" "PBM" X.SH NAME Xmacpainttopbm \- convert Macintosh MacPaint files into portable bitmaps X.SH SYNOPSIS Xmacpainttopbm \%[macpaintfile] X.SH DESCRIPTION XReads a Macintosh MacPaint file as input. XProduces 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 X XThe MacPaint-reading code is X Copyright (c) 1987 by Patrick J. Naughton, X (naughton@sun.soe.clarkson.edu) X X Permission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that Xboth that copyright notice and this permission notice appear in Xsupporting documentation. SHAR_EOF if test 985 -ne "`wc -c < 'macpainttopbm.man'`" then echo shar: error transmitting "'macpainttopbm.man'" '(should have been 985 characters)' fi fi # end of overwriting check echo shar: extracting "'rastertopbm.c'" '(2750 characters)' if test -f 'rastertopbm.c' then echo shar: will not over-write existing file "'rastertopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'rastertopbm.c' X/* rastertopbm.c - read a Sun raster file and produce a portable bitmap X*/ X X#include <pixrect/pixrect_hs.h> 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, shortcount, mask; X int linesize; X short *data; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [rasterfile]\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 if ( ReadRasterFile( ifd, &cols, &rows, &linesize, &data ) < 0 ) X { X fprintf( stderr, "%s: can't load.\n", argv[1] ); X exit( 1 ); X } X X if ( ifd != stdin ) X fclose( ifd ); X X bits = pbm_allocarray( cols, rows ); X X for ( row = 0; row < rows; row++ ) X { X shortcount = 0; X mask = 0x8000; X for ( col = 0; col < cols; col++ ) X { X if ( mask == 0 ) X { X shortcount++; X mask = 0x8000; X } X bits[row][col] = ( *(data + shortcount) & mask ) ? 1 : 0; X mask = mask >> 1; X } X data += linesize / sizeof(short); X } X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } X X Xint XReadRasterFile( file, width, height, linebytes, data ) XFILE *file; Xint *width, *height; Xint *linebytes; Xshort **data; X { X struct rasterfile header; X struct pixrect *pr, *pr_load_image(); X int status, firsttime, value, i, data_length; X X if ( file == NULL ) X return ( -1 ); X X *width = *height = -1; X X X /* Get the raster file's header. */ X if ( pr_load_header( file, &header ) != 0 ) X { X fprintf( stderr, "Unable to read in raster file header.\n"); X return ( -1 ); X } X X /* PBM can only handle monochrome bitmaps. */ X if ( header.ras_depth != 1 ) X { X fprintf( stderr, "Invalid depth.\n" ); X return ( -1 ); X } X X *width = header.ras_width; X *height = header.ras_height; X if ( *width <= 0 ) X { X fprintf( stderr, "Invalid width: %d.\n", *width ); X return ( -1 ); X } X X if ( *height <= 0 ) X { X fprintf( stderr, "Invalid height: %d.\n", *height ); X return ( -1 ); X } X X /* If there is a color map, skip over it. */ X if ( header.ras_maptype != RMT_NONE && header.ras_maplength != 0 ) X { X if (pr_load_colormap(file, &header, NULL) != 0) X { X fprintf( stderr, "Unable to skip colormap data.\n"); X return ( -1 ); X } X } X X /* Now load the data. The pixrect returned is a memory pixrect. */ X if ( (pr = pr_load_image(file, &header, NULL)) == NULL ) X { X fprintf( X stderr, "Unable to read in the image from the raster file.\n"); X return ( -1 ); X } X X *linebytes = ((struct mpr_data *)pr->pr_data)->md_linebytes; X *data = ((struct mpr_data *)pr->pr_data)->md_image; X X return ( 0 ); X } SHAR_EOF if test 2750 -ne "`wc -c < 'rastertopbm.c'`" then echo shar: error transmitting "'rastertopbm.c'" '(should have been 2750 characters)' fi fi # end of overwriting check echo shar: extracting "'rastertopbm.man'" '(541 characters)' if test -f 'rastertopbm.man' then echo shar: will not over-write existing file "'rastertopbm.man'" else sed 's/^X//' << \SHAR_EOF > 'rastertopbm.man' X.TH rastertopbm 1 "08 February 1988" "PBM" X.SH NAME Xrastertopbm \- convert Sun rasters into portable bitmaps X.SH SYNOPSIS Xrastertopbm \%[rasterfile] X.SH DESCRIPTION XReads a Sun raster as input. XProduces 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 XBarry Klawans SHAR_EOF if test 541 -ne "`wc -c < 'rastertopbm.man'`" then echo shar: error transmitting "'rastertopbm.man'" '(should have been 541 characters)' fi fi # end of overwriting check # End of shell archive exit 0