Newsgroups: comp.sources.misc From: jef@well.sf.ca.us (Jef Poskanzer) Subject: REPOST: v23i037: pbmplus - Extended Portable Bitmap Toolkit, Part02/24 Message-ID: <1991Oct15.020017.16699@sparky.imd.sterling.com> X-Md4-Signature: f6917c1cf91769815ffcd7ad259f3e8d Date: Tue, 15 Oct 1991 02:00:17 GMT Approved: kent@sparky.imd.sterling.com Submitted-by: jef@well.sf.ca.us (Jef Poskanzer) Posting-number: Volume 23, Issue 37 Archive-name: pbmplus/part02 Environment: UNIX #! /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: # pbm/Imakefile # pbm/Makefile # pbm/pbm.h # pbm/icontopbm.c # pbm/icontopbm.1 # pbm/macptopbm.c # pbm/macptopbm.1 # pbm/xbmtopbm.c # pbm/xbmtopbm.1 # pbm/pbmtoptx.c # pbm/pbmtoptx.1 # pbm/pbmtoicon.c # pbm/pbmtoicon.1 # pbm/pbmtoxbm.c # pbm/pbmtoxbm.1 # pbm/pbmtox10bm.c # pbm/pbmtox10bm.1 # This archive created: Fri Sep 27 17:50:03 1991 # By: Jef Poskanzer (Acme Software) export PATH; PATH=/bin:$PATH if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/Imakefile'" '(2357 characters)' if test -f 'pbm/Imakefile' then echo shar: will not over-write existing file "'pbm/Imakefile'" else sed 's/^X//' << \SHAR_EOF > 'pbm/Imakefile' X# Imakefile for pbm tools. X# X# Copyright (C) 1989, 1991 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 XRGBDEF = -DRGB_DB=\"DefaultRGBDatabase\" XTIFFDEF = -DLIBTIFF XINCLUDE = -I.. XALLCFLAGS = $(CFLAGS) $(RGBDEF) $(TIFFDEF) $(INCLUDE) XLIBPBM = libpbm.a X XBINARIES = atktopbm brushtopbm cmuwmtopbm g3topbm \ X icontopbm gemtopbm macptopbm mgrtopbm \ X pbmlife pbmmake pbmmask pbmreduce \ X pbmtext pbmto10x pbmtoascii pbmtoatk \ X pbmtobbnbg pbmtocmuwm pbmtoepson pbmtog3 \ X pbmtogem pbmtogo pbmtoicon pbmtolj pbmtomacp \ X pbmtomgr pbmtopi3 pbmtoplot pbmtoptx \ X pbmtox10bm pbmtoxbm pbmtoybm pbmtozinc \ X pbmupc pi3topbm xbmtopbm \ X ybmtopbm X XMANUALS1 = atktopbm.1 brushtopbm.1 cmuwmtopbm.1 g3topbm.1 \ X icontopbm.1 gemtopbm.1 macptopbm.1 mgrtopbm.1 \ X pbmlife.1 pbmmake.1 pbmmask.1 pbmreduce.1 \ X pbmtext.1 pbmto10x.1 pbmtoascii.1 pbmtoatk.1 \ X pbmtobbnbg.1 pbmtocmuwm.1 pbmtoepson.1 pbmtog3.1 \ X pbmtogem.1 pbmtogo.1 pbmtoicon.1 pbmtolj.1 pbmtomacp.1 \ X pbmtomgr.1 pbmtopi3.1 pbmtoplot.1 pbmtoptx.1 \ X pbmtox10bm.1 pbmtoxbm.1 pbmtoybm.1 pbmtozinc.1 \ X pbmupc.1 pi3topbm.1 xbmtopbm.1 \ X ybmtopbm.1 XMANUALS3 = libpbm.3 XMANUALS5 = pbm.5 X Xall: $(BINARIES) X Xinstall:: all X cp $(BINARIES) $(BINDIR) X Xinstall.man:: X cp $(MANUALS1) $(MANUALS3) $(MANUALS5) $(MANDIR) X X# Rule for plain programs. X$(BINARIES): pbm.h ../pbmplus.h $(LIBPBM) X $(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPBM) X X# And library. X$(LIBPBM): libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.o X -rm $(LIBPBM) X $(AR) $(LIBPBM) libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.o X -$(RANLIB) $(LIBPBM) X Xlibpbm1.o: pbm.h ../pbmplus.h libpbm.h libpbm1.c X $(CC) $(ALLCFLAGS) -c libpbm1.c Xlibpbm2.o: pbm.h ../pbmplus.h libpbm.h libpbm2.c X $(CC) $(ALLCFLAGS) -c libpbm2.c Xlibpbm3.o: pbm.h ../pbmplus.h libpbm.h libpbm3.c X $(CC) $(ALLCFLAGS) -c libpbm3.c Xlibpbm4.o: pbm.h ../pbmplus.h libpbm.h libpbm4.c X $(CC) $(ALLCFLAGS) -c libpbm4.c Xlibpbm5.o: pbm.h ../pbmplus.h pbmfont.h libpbm5.c X $(CC) $(ALLCFLAGS) -c libpbm5.c X XDependTarget() SHAR_EOF if test 2357 -ne "`wc -c < 'pbm/Imakefile'`" then echo shar: error transmitting "'pbm/Imakefile'" '(should have been 2357 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/Makefile'" '(5165 characters)' if test -f 'pbm/Makefile' then echo shar: will not over-write existing file "'pbm/Makefile'" else sed 's/^X//' << \SHAR_EOF > 'pbm/Makefile' X# Makefile for pbm tools. X# X# Copyright (C) 1989, 1991 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# Default values, usually overridden by top-level Makefile. X#CC = cc XCC = gcc -ansi -pedantic -fcombine-regs -fpcc-struct-return X#CFLAGS = -O XCFLAGS = -g X#CFLAGS = -g -O XRGBDEF = -DRGB_DB=\"/usr/lib/X11/rgb.txt\" XTIFFDEF = -DLIBTIFF X#LDFLAGS = -s XLDFLAGS = XINSTALLBINARIES = /usr/new/pbm XINSTALLMANUALS1 = /usr/man/man1 XSUFFIXMANUALS1 = 1 XINSTALLMANUALS3 = /usr/man/man3 XSUFFIXMANUALS3 = 3 XINSTALLMANUALS5 = /usr/man/man5 XSUFFIXMANUALS5 = 5 XMANCP = cp X XSHELL = /bin/sh XINCLUDE = -I.. XALLCFLAGS = $(CFLAGS) $(RGBDEF) $(TIFFDEF) $(INCLUDE) XLIBPBM = libpbm.a XDEFPBM = pbm.h ../pbmplus.h X XBINARIES = atktopbm brushtopbm cmuwmtopbm g3topbm \ X icontopbm gemtopbm macptopbm mgrtopbm \ X pbmlife pbmmake pbmmask pbmreduce \ X pbmtext pbmto10x pbmtoascii pbmtoatk \ X pbmtobbnbg pbmtocmuwm pbmtoepson pbmtog3 \ X pbmtogem pbmtogo pbmtoicon pbmtolj pbmtomacp \ X pbmtomgr pbmtopi3 pbmtoplot pbmtoptx \ X pbmtox10bm pbmtoxbm pbmtoybm pbmtozinc \ X pbmupc pi3topbm xbmtopbm \ X ybmtopbm X XOBJECTS = atktopbm.o brushtopbm.o cmuwmtopbm.o g3topbm.o \ X icontopbm.o gemtopbm.o macptopbm.o mgrtopbm.o \ X pbmlife.o pbmmake.o pbmmask.o pbmreduce.o \ X pbmtext.o pbmto10x.o pbmtoascii.o pbmtoatk.o \ X pbmtobbnbg.o pbmtocmuwm.o pbmtoepson.o pbmtog3.o \ X pbmtogem.o pbmtogo.o pbmtoicon.o pbmtolj.o pbmtomacp.o \ X pbmtomgr.o pbmtopi3.o pbmtoplot.o pbmtoptx.o \ X pbmtox10bm.o pbmtoxbm.o pbmtoybm.o pbmtozinc.o \ X pbmupc.o pi3topbm.o xbmtopbm.o \ X ybmtopbm.o X XMANUALS1 = $(BINARIES) XMANUALS3 = libpbm XMANUALS5 = pbm X X X#all: binaries Xall: merge X#install: install.bin Xinstall: install.merge X X Xbinaries: $(BINARIES) X Xinstall.bin: binaries X cd $(INSTALLBINARIES) ; rm -f $(BINARIES) X cp $(BINARIES) $(INSTALLBINARIES) X X Xmerge: pbmmerge Xpbmmerge: pbmmerge.c $(OBJECTS) $(LIBPBM) X $(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(OBJECTS) $(LIBPBM) X Xinstall.merge: install.pbmmerge Xinstall.pbmmerge: pbmmerge X cd $(INSTALLBINARIES) ; rm -f $(BINARIES) X cp pbmmerge $(INSTALLBINARIES) X cd $(INSTALLBINARIES) ; for i in $(BINARIES) ; do ln pbmmerge $$i ; done X rm $(INSTALLBINARIES)/pbmmerge X X Xinstall.man: X for i in $(MANUALS1) ; do \ X rm -f $(INSTALLMANUALS1)/$$i.$(SUFFIXMANUALS1) ; \ X $(MANCP) $$i.1 $(INSTALLMANUALS1)/$$i.$(SUFFIXMANUALS1) ; \ X done X for i in $(MANUALS3) ; do \ X rm -f $(INSTALLMANUALS3)/$$i.$(SUFFIXMANUALS3) ; \ X $(MANCP) $$i.3 $(INSTALLMANUALS3)/$$i.$(SUFFIXMANUALS3) ; \ X done X for i in $(MANUALS5) ; do \ X rm -f $(INSTALLMANUALS5)/$$i.$(SUFFIXMANUALS5) ; \ X $(MANCP) $$i.5 $(INSTALLMANUALS5)/$$i.$(SUFFIXMANUALS5) ; \ X done X X X# Rules for plain programs. X$(BINARIES): $(DEFPBM) $(LIBPBM) X $(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPBM) X$(OBJECTS): $(DEFPBM) X $(CC) $(ALLCFLAGS) "-Dmain=$*_main" -c $*.c X X# And library. Xlib: $(LIBPBM) X$(LIBPBM): libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.o X -rm $(LIBPBM) X ar rc $(LIBPBM) libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.o X -ranlib $(LIBPBM) X Xlibpbm1.o: $(DEFPBM) ../version.h libpbm.h libpbm1.c X $(CC) $(ALLCFLAGS) -c libpbm1.c Xlibpbm2.o: $(DEFPBM) libpbm.h libpbm2.c X $(CC) $(ALLCFLAGS) -c libpbm2.c Xlibpbm3.o: $(DEFPBM) libpbm.h libpbm3.c X $(CC) $(ALLCFLAGS) -c libpbm3.c Xlibpbm4.o: $(DEFPBM) libpbm.h libpbm4.c X $(CC) $(ALLCFLAGS) -c libpbm4.c Xlibpbm5.o: $(DEFPBM) pbmfont.h libpbm5.c X $(CC) $(ALLCFLAGS) -c libpbm5.c X X# Other dependencies. Xatktopbm atktopbm.o: atktopbm.c Xbrushtopbm brushtopbm.o: brushtopbm.c Xcmuwmtopbm cmuwmtopbm.o: cmuwmtopbm.c cmuwm.h Xg3topbm g3topbm.o: g3topbm.c g3.h Xicontopbm icontopbm.o: icontopbm.c Xgemtopbm gemtopbm.o: gemtopbm.c Xmacptopbm macptopbm.o: macptopbm.c macp.h Xmgrtopbm mgrtopbm.o: mgrtopbm.c mgr.h Xpbmlife pbmlife.o: pbmlife.c Xpbmmake pbmmake.o: pbmmake.c Xpbmmask pbmmask.o: pbmmask.c Xpbmreduce pbmreduce.o: pbmreduce.c Xpbmtext pbmtext.o: pbmtext.c pbmfont.h Xpbmto10x pbmto10x.o: pbmto10x.c Xpbmtoascii pbmtoascii.o: pbmtoascii.c Xpbmtoatk pbmtoatk.o: pbmtoatk.c Xpbmtobbnbg pbmtobbnbg.o: pbmtobbnbg.c Xpbmtocmuwm pbmtocmuwm.o: pbmtocmuwm.c cmuwm.h Xpbmtoepson pbmtoepson.o: pbmtoepson.c Xpbmtog3 pbmtog3.o: pbmtog3.c g3.h Xpbmtogem pbmtogem.o: pbmtogem.c Xpbmtogo pbmtogo.o: pbmtogo.c Xpbmtoicon pbmtoicon.o: pbmtoicon.c Xpbmtolj pbmtolj.o: pbmtolj.c Xpbmtomacp pbmtomacp.o: pbmtomacp.c macp.h Xpbmtomgr pbmtomgr.o: pbmtomgr.c mgr.h Xpbmtopi3 pbmtopi3.o: pbmtopi3.c Xpbmtoplot pbmtoplot.o: pbmtoplot.c Xpbmtoptx pbmtoptx.o: pbmtoptx.c Xpbmtox10bm pbmtox10bm.o: pbmtox10bm.c Xpbmtoxbm pbmtoxbm.o: pbmtoxbm.c Xpbmtoybm pbmtoybm.o: pbmtoybm.c Xpbmtozinc pbmtozinc.o: pbmtozinc.c Xpbmupc pbmupc.o: pbmupc.c Xpi3topbm pi3topbm.o: pi3topbm.c Xxbmtopbm xbmtopbm.o: xbmtopbm.c Xybmtopbm ybmtopbm.o: ybmtopbm.c X Xclean: X -rm -f *.o *.a *.cat core $(BINARIES) pbmmerge SHAR_EOF if test 5165 -ne "`wc -c < 'pbm/Makefile'`" then echo shar: error transmitting "'pbm/Makefile'" '(should have been 5165 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/pbm.h'" '(1430 characters)' if test -f 'pbm/pbm.h' then echo shar: will not over-write existing file "'pbm/pbm.h'" else sed 's/^X//' << \SHAR_EOF > 'pbm/pbm.h' X/* pbm.h - header file for libpbm portable bitmap library X*/ X X#ifndef _PBM_H_ X#define _PBM_H_ X X#include "pbmplus.h" X Xtypedef unsigned char bit; X#define PBM_WHITE 0 X#define PBM_BLACK 1 X X X/* Magic constants. */ X X#define PBM_MAGIC1 'P' X#define PBM_MAGIC2 '1' X#define RPBM_MAGIC2 '4' X#define PBM_FORMAT (PBM_MAGIC1 * 256 + PBM_MAGIC2) X#define RPBM_FORMAT (PBM_MAGIC1 * 256 + RPBM_MAGIC2) X#define PBM_TYPE PBM_FORMAT X X X/* Macro for turning a format number into a type number. */ X X#define PBM_FORMAT_TYPE(f) ((f) == PBM_FORMAT || (f) == RPBM_FORMAT ? PBM_TYPE : -1) X X X/* Declarations of routines. */ X Xvoid pbm_init ARGS(( int* argcP, char* argv[] )); X X#define pbm_allocarray( cols, rows ) ((bit**) pm_allocarray( cols, rows, sizeof(bit) )) X#define pbm_allocrow( cols ) ((bit*) pm_allocrow( cols, sizeof(bit) )) X#define pbm_freearray( bits, rows ) pm_freearray( (char**) bits, rows ) X#define pbm_freerow( bitrow ) pm_freerow( (char*) bitrow ) X Xbit** pbm_readpbm ARGS(( FILE* file, int* colsP, int* rowsP )); Xvoid pbm_readpbminit ARGS(( FILE* file, int* colsP, int* rowsP, int* formatP )); Xvoid pbm_readpbmrow ARGS(( FILE* file, bit* bitrow, int cols, int format )); X Xvoid pbm_writepbm ARGS(( FILE* file, bit** bits, int cols, int rows, int forceplain )); Xvoid pbm_writepbminit ARGS(( FILE* file, int cols, int rows, int forceplain )); Xvoid pbm_writepbmrow ARGS(( FILE* file, bit* bitrow, int cols, int forceplain )); X X#endif /*_PBM_H_*/ SHAR_EOF if test 1430 -ne "`wc -c < 'pbm/pbm.h'`" then echo shar: error transmitting "'pbm/pbm.h'" '(should have been 1430 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/icontopbm.c'" '(3493 characters)' if test -f 'pbm/icontopbm.c' then echo shar: will not over-write existing file "'pbm/icontopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'pbm/icontopbm.c' X/* icontopbm.c - read a Sun icon file and produce 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 "pbm.h" X Xstatic void ReadIconFile ARGS(( FILE* file, int* width, int* height, short** data )); X Xvoid Xmain( argc, argv ) X int argc; X char* argv[]; X { X FILE* ifp; X bit* bitrow; X register bit* bP; X int rows, cols, row, col, shortcount, mask; X short* data; X X pbm_init( &argc, argv ); X X if ( argc > 2 ) X pm_usage( "[iconfile]" ); X X if ( argc == 2 ) X ifp = pm_openr( argv[1] ); X else X ifp = stdin; X X ReadIconFile( ifp, &cols, &rows, &data ); X X pm_close( ifp ); X X pbm_writepbminit( stdout, cols, rows, 0 ); X bitrow = pbm_allocrow( cols ); X X for ( row = 0; row < rows; row++ ) X { X shortcount = 0; X mask = 0x8000; X for ( col = 0, bP = bitrow; col < cols; col++, bP++ ) X { X if ( shortcount >= 16 ) X { X data++; X shortcount = 0; X mask = 0x8000; X } X *bP = ( *data & mask ) ? PBM_BLACK : PBM_WHITE; X shortcount++; X mask = mask >> 1; X } X data++; X pbm_writepbmrow( stdout, bitrow, cols, 0 ); X } X X exit( 0 ); X } X X/* size in bytes of a bitmap */ X#define BitmapSize(width, height) (((((width) + 15) >> 3) &~ 1) * (height)) X Xstatic void XReadIconFile( file, width, height, data ) X FILE* file; X int* width; X int* height; X short** data; X { X char variable[81], ch; X int status, value, i, data_length, gotsome; X X gotsome = 0; X *width = *height = -1; X for ( ; ; ) X { X while ( ( ch = getc( file ) ) == ',' || ch == '\n' || ch == '\t' || X ch == ' ' ) X ; X for ( i = 0; X ch != '=' && ch != ',' && ch != '\n' && ch != '\t' && ch != ' '; X i++ ) X { X variable[i] = ch; X ch = getc( file ); X } X variable[i] = '\0'; X X if ( strcmp( variable, "*/" ) == 0 && gotsome ) X break; X X if ( fscanf( file, "%d", &value ) != 1 ) X continue; X X if ( strcmp( variable, "Width" ) == 0 ) X { X *width = value; X gotsome = 1; X } X else if ( strcmp( variable, "Height" ) == 0 ) X { X *height = value; X gotsome = 1; X } X else if ( strcmp( variable, "Depth" ) == 0 ) X { X if ( value != 1 ) X pm_error( "invalid depth" ); X gotsome = 1; X } X else if ( strcmp( variable, "Format_version" ) == 0 ) X { X if ( value != 1 ) X pm_error( "invalid Format_version" ); X gotsome = 1; X } X else if ( strcmp( variable, "Valid_bits_per_item" ) == 0 ) X { X if ( value != 16 ) X pm_error( "invalid Valid_bits_per_item" ); X gotsome = 1; X } X } X X if ( *width <= 0 ) X pm_error( "invalid width: %d", *width ); X if ( *height <= 0 ) X pm_error( "invalid height: %d", *height ); X X data_length = BitmapSize( *width, *height ); X *data = (short*) malloc( data_length ); X if ( *data == NULL ) X pm_error( "out of memory" ); X data_length /= sizeof( short ); 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 pm_error( "error 4 scanning bits item" ); X } X } SHAR_EOF if test 3493 -ne "`wc -c < 'pbm/icontopbm.c'`" then echo shar: error transmitting "'pbm/icontopbm.c'" '(should have been 3493 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/icontopbm.1'" '(740 characters)' if test -f 'pbm/icontopbm.1' then echo shar: will not over-write existing file "'pbm/icontopbm.1'" else sed 's/^X//' << \SHAR_EOF > 'pbm/icontopbm.1' X.TH icontopbm 1 "31 August 1988" X.IX icontopbm X.SH NAME Xicontopbm - convert a Sun icon into a portable bitmap X.SH SYNOPSIS X.B icontopbm X.RI [ iconfile ] X.SH DESCRIPTION XReads a Sun icon as input. X.IX Sun X.IX "Sun icon format" XProduces a portable bitmap as output. X.SH "SEE ALSO" Xpbmtoicon(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer. 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. SHAR_EOF if test 740 -ne "`wc -c < 'pbm/icontopbm.1'`" then echo shar: error transmitting "'pbm/icontopbm.1'" '(should have been 740 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/macptopbm.c'" '(3439 characters)' if test -f 'pbm/macptopbm.c' then echo shar: will not over-write existing file "'pbm/macptopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'pbm/macptopbm.c' X/* macptopbm.c - read a MacPaint file and produce 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 "pbm.h" X#include "macp.h" X Xstatic void ReadMacPaintFile ARGS(( FILE* file, int extraskip, int* scanLineP, unsigned char Pic[MAX_LINES][BYTES_WIDE] )); X Xvoid Xmain( argc, argv ) X int argc; X char* argv[]; X { X FILE* ifp; X unsigned char Pic[MAX_LINES][BYTES_WIDE]; X bit* bitrow; X int argn, extraskip, scanLine, rows, cols, row, bcol, i; X char* usage = "[-extraskip N] [macpfile]"; X X pbm_init( &argc, argv ); X X argn = 1; X extraskip = 0; X X /* Check for flags. */ X if ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' ) X { X if ( pm_keymatch( argv[argn], "-extraskip", 2 ) ) X { X argn++; X if ( argn == argc || sscanf( argv[argn], "%d", &extraskip ) != 1 ) X pm_usage( usage ); X } X else X pm_usage( usage ); X argn++; X } X X if ( argn < argc ) X { X ifp = pm_openr( argv[argn] ); X argn++; X } X else X ifp = stdin; X X if ( argn != argc ) X pm_usage( usage ); X X ReadMacPaintFile( ifp, extraskip, &scanLine, Pic ); X X pm_close( ifp ); X X cols = BYTES_WIDE * 8; X rows = scanLine; X pbm_writepbminit( stdout, cols, rows, 0 ); X bitrow = pbm_allocrow( cols ); X X for ( row = 0; row < rows; row++ ) X { X for ( bcol = 0; bcol < BYTES_WIDE; bcol++ ) X for ( i = 0; i < 8; i++ ) X bitrow[bcol * 8 + i] = X ( (Pic[row][bcol] >> (7 - i)) & 1 ) ? PBM_BLACK : PBM_WHITE; X pbm_writepbmrow( stdout, bitrow, cols, 0 ); X } 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 Xstatic void XReadMacPaintFile( file, extraskip, scanLineP, Pic ) X FILE* file; X int extraskip; X int* scanLineP; X unsigned 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 < extraskip; i++ ) X getc( file ); 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 } SHAR_EOF if test 3439 -ne "`wc -c < 'pbm/macptopbm.c'`" then echo shar: error transmitting "'pbm/macptopbm.c'" '(should have been 3439 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/macptopbm.1'" '(1780 characters)' if test -f 'pbm/macptopbm.1' then echo shar: will not over-write existing file "'pbm/macptopbm.1'" else sed 's/^X//' << \SHAR_EOF > 'pbm/macptopbm.1' X.TH macptopbm 1 "29 March 1989" X.IX macptopbm X.SH NAME Xmacptopbm - convert a MacPaint file into a portable bitmap X.SH SYNOPSIS X.B macptopbm X.RB [ -extraskip X.IR N ] X.RI [ macpfile ] X.SH DESCRIPTION XReads a MacPaint file as input. X.IX MacPaint X.IX Macintosh XProduces a portable bitmap as output. X.SH OPTIONS X.TP X.B -extraskip XThis flag is to get around a problem with some methods Xof transferring files from the Mac world to the Unix world. XMost of these methods leave the Mac files alone, but a few of Xthem add the "finderinfo" data onto the front of the Unix file. XThis means an extra 128 bytes to skip over when reading the file. XThe symptom to watch for is that the resulting PBM file looks shifted Xto one side. XIf you get this, try X.B -extraskip X128, and if that still doesn't look right try another value. X.PP XAll flags can be abbreviated to their shortest unique prefix. X.SH "SEE ALSO" Xpicttoppm(1), pbmtomacp(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer. 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. XThe MacPaint-reading code is copyright (c) 1987 by Patrick J. Naughton X(naughton@wind.sun.com). 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. SHAR_EOF if test 1780 -ne "`wc -c < 'pbm/macptopbm.1'`" then echo shar: error transmitting "'pbm/macptopbm.1'" '(should have been 1780 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/xbmtopbm.c'" '(5263 characters)' if test -f 'pbm/xbmtopbm.c' then echo shar: will not over-write existing file "'pbm/xbmtopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'pbm/xbmtopbm.c' X/* xbmtopbm.c - read an X bitmap file and produce 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 "pbm.h" X Xstatic void ReadBitmapFile ARGS(( FILE* stream, int* widthP, int* heightP, char** dataP )); X Xvoid Xmain( argc, argv ) X int argc; X char* argv[]; X { X FILE* ifp; X bit* bitrow; X register bit* bP; X int rows, cols, row, col, charcount; X char* data; X char mask; X X pbm_init( &argc, argv ); X X if ( argc > 2 ) X pm_usage( "[bitmapfile]" ); X X if ( argc == 2 ) X ifp = pm_openr( argv[1] ); X else X ifp = stdin; X X ReadBitmapFile( ifp, &cols, &rows, &data ); X X pm_close( ifp ); X X pbm_writepbminit( stdout, cols, rows, 0 ); X bitrow = pbm_allocrow( cols ); X X for ( row = 0; row < rows; ++row ) X { X charcount = 0; X mask = 1; X for ( col = 0, bP = bitrow; col < cols; ++col, ++bP ) X { X if ( charcount >= 8 ) X { X ++data; X charcount = 0; X mask = 1; X } X *bP = ( *data & mask ) ? PBM_BLACK : PBM_WHITE; X ++charcount; X mask = mask << 1; X } X ++data; X pbm_writepbmrow( stdout, bitrow, cols, 0 ); X } X X exit( 0 ); X } X X#define MAX_LINE 500 X Xstatic void XReadBitmapFile( stream, widthP, heightP, dataP ) X FILE* stream; X int* widthP; X int* heightP; X char** dataP; X { X char line[MAX_LINE], name_and_type[MAX_LINE]; X char* ptr; X char* t; X int version10, raster_length, v; X register int bytes, bytes_per_line, padding; X register int c1, c2, value1, value2; X int hex_table[256]; X X *widthP = *heightP = -1; X X for ( ; ; ) X { X if ( fgets( line, MAX_LINE, stream ) == NULL ) X pm_error( "EOF / read error" ); X if ( strlen( line ) == MAX_LINE - 1 ) X pm_error( "line too long" ); X X if ( sscanf( line, "#define %s %d", name_and_type, &v ) == 2 ) X { X if ( ( t = rindex( name_and_type, '_' ) ) == NULL ) X t = name_and_type; X else X ++t; X if ( ! strcmp( "width", t ) ) X *widthP = v; X else if ( ! strcmp( "height", t ) ) X *heightP = v; X continue; X } X X if ( sscanf( line, "static short %s = {", name_and_type ) == 1 ) /* } */ X { X version10 = 1; X break; X } X if ( sscanf( line, "static char %s = {", name_and_type ) == 1 ) /* } */ X { X version10 = 0; X break; X } X } X X if ( *widthP == -1 ) X pm_error( "invalid width" ); X if ( *heightP == -1 ) X pm_error( "invalid height" ); X X padding = 0; X if ( ((*widthP % 16) >= 1) && ((*widthP % 16) <= 8) && version10 ) X padding = 1; X X bytes_per_line = (*widthP+7)/8 + padding; X X raster_length = bytes_per_line * *heightP; X *dataP = (char*) malloc( raster_length ); X if ( *dataP == (char*) 0 ) X pm_error( "out of memory" ); X X /* Initialize hex_table. */ X for ( c1 = 0; c1 < 256; ++c1 ) X hex_table[c1] = 256; X hex_table['0'] = 0; X hex_table['1'] = 1; X hex_table['2'] = 2; X hex_table['3'] = 3; X hex_table['4'] = 4; X hex_table['5'] = 5; X hex_table['6'] = 6; X hex_table['7'] = 7; X hex_table['8'] = 8; X hex_table['9'] = 9; X hex_table['A'] = 10; X hex_table['B'] = 11; X hex_table['C'] = 12; X hex_table['D'] = 13; X hex_table['E'] = 14; X hex_table['F'] = 15; X hex_table['a'] = 10; X hex_table['b'] = 11; X hex_table['c'] = 12; X hex_table['d'] = 13; X hex_table['e'] = 14; X hex_table['f'] = 15; X X if ( version10 ) X for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes += 2 ) X { X while ( ( c1 = getc( stream ) ) != 'x' ) X if ( c1 == EOF ) X pm_error( "EOF / read error" ); X c1 = getc( stream ); X c2 = getc( stream ); X if ( c1 == EOF || c2 == EOF ) X pm_error( "EOF / read error" ); X value1 = ( hex_table[c1] << 4 ) + hex_table[c2]; X if ( value1 >= 256 ) X pm_error( "syntax error" ); X c1 = getc( stream ); X c2 = getc( stream ); X if ( c1 == EOF || c2 == EOF ) X pm_error( "EOF / read error" ); X value2 = ( hex_table[c1] << 4 ) + hex_table[c2]; X if ( value2 >= 256 ) X pm_error( "syntax error" ); X *ptr++ = value2; X if ( ( ! padding ) || ( ( bytes + 2 ) % bytes_per_line ) ) X *ptr++ = value1; X } X else X for ( bytes = 0, ptr = *dataP; bytes < raster_length; ++bytes ) X { X /* X ** Skip until digit is found. X */ X for ( ; ; ) X { X c1 = getc( stream ); X if ( c1 == EOF ) X pm_error( "EOF / read error" ); X value1 = hex_table[c1]; X if ( value1 != 256 ) X break; X } X /* X ** Loop on digits. X */ X for ( ; ; ) X { X c2 = getc( stream ); X if ( c2 == EOF ) X pm_error( "EOF / read error" ); X value2 = hex_table[c2]; X if ( value2 != 256 ) X { X value1 = (value1 << 4) | value2; X if ( value1 >= 256 ) X pm_error( "syntax error" ); X } X else if ( c2 == 'x' || c2 == 'X' ) X if ( value1 == 0 ) X continue; X else pm_error( "syntax error" ); X else break; X } X *ptr++ = value1; X } X } SHAR_EOF if test 5263 -ne "`wc -c < 'pbm/xbmtopbm.c'`" then echo shar: error transmitting "'pbm/xbmtopbm.c'" '(should have been 5263 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/xbmtopbm.1'" '(779 characters)' if test -f 'pbm/xbmtopbm.1' then echo shar: will not over-write existing file "'pbm/xbmtopbm.1'" else sed 's/^X//' << \SHAR_EOF > 'pbm/xbmtopbm.1' X.TH xbmtopbm 1 "31 August 1988" X.IX xbmtopbm X.SH NAME Xxbmtopbm - convert an X11 or X10 bitmap into a portable bitmap X.SH SYNOPSIS X.B xbmtopbm X.RI [ bitmapfile ] X.SH DESCRIPTION XReads an X11 or X10 bitmap as input. XProduces a portable bitmap as output. X.IX "X bitmap" X.IX "X window system" X.SH "SEE ALSO" Xpbmtoxbm(1), pbmtox10bm(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer. 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. SHAR_EOF if test 779 -ne "`wc -c < 'pbm/xbmtopbm.1'`" then echo shar: error transmitting "'pbm/xbmtopbm.1'" '(should have been 779 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/pbmtoptx.c'" '(1951 characters)' if test -f 'pbm/pbmtoptx.c' then echo shar: will not over-write existing file "'pbm/pbmtoptx.c'" else sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoptx.c' X/* pbmtoptx.c - read a portable bitmap and produce a Printronix printer file 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 "pbm.h" X Xstatic void putinit ARGS(( void )); Xstatic void putbit ARGS(( bit b )); Xstatic void putrest ARGS(( void )); Xstatic void putitem ARGS(( void )); X Xvoid main( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifp; X register bit *bitrow, *bP; X int rows, cols, format, row, col; X char *usage = "[pbmfile]"; X X pbm_init( &argc, argv ); X X if ( argc > 2 ) X pm_usage( usage ); X X if ( argc == 2 ) X ifp = pm_openr( argv[1] ); X else X ifp = stdin; X X pbm_readpbminit( ifp, &cols, &rows, &format ); X bitrow = pbm_allocrow( cols ); X X putinit( ); X for ( row = 0; row < rows; row++ ) X { X pbm_readpbmrow( ifp, bitrow, cols, format ); X for ( col = 0, bP = bitrow; col < cols; col++, bP++ ) X putbit( *bP ); X putrest( ); X putchar( 5 ); X putchar( '\n' ); X } X X pm_close( ifp ); X X exit( 0 ); X } X Xstatic char item; Xstatic int bitsperitem, bitshift; X Xstatic void Xputinit( ) X { X bitsperitem = 0; X item = 64; X bitshift = 0; X } X X#if __STDC__ Xstatic void Xputbit( bit b ) X#else /*__STDC__*/ Xstatic void Xputbit( b ) X bit b; X#endif /*__STDC__*/ X { X if ( bitsperitem == 6 ) X putitem( ); X if ( b == PBM_BLACK ) X item += 1 << bitshift; X bitsperitem++; X bitshift++; X } X Xstatic void Xputrest( ) X { X if ( bitsperitem > 0 ) X putitem( ); X } X Xstatic void Xputitem( ) X { X putchar( item ); X bitsperitem = 0; X item = 64; X bitshift = 0; X } SHAR_EOF if test 1951 -ne "`wc -c < 'pbm/pbmtoptx.c'`" then echo shar: error transmitting "'pbm/pbmtoptx.c'" '(should have been 1951 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/pbmtoptx.1'" '(824 characters)' if test -f 'pbm/pbmtoptx.1' then echo shar: will not over-write existing file "'pbm/pbmtoptx.1'" else sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoptx.1' X.TH pbmtoptx 1 "31 August 1988" X.IX pbmtoptx X.SH NAME Xpbmtoptx - convert a portable bitmap into Printronix printer graphics X.SH SYNOPSIS X.B pbmtoptx X.RI [ pbmfile ] X.SH DESCRIPTION XReads a portable bitmap as input. XProduces a file of Printronix printer graphics as output. X.IX Printronix X.PP XNote that there is no ptxtopbm tool - this transformation is one way. X.SH "SEE ALSO" Xpbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer. 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. SHAR_EOF if test 824 -ne "`wc -c < 'pbm/pbmtoptx.1'`" then echo shar: error transmitting "'pbm/pbmtoptx.1'" '(should have been 824 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/pbmtoicon.c'" '(2821 characters)' if test -f 'pbm/pbmtoicon.c' then echo shar: will not over-write existing file "'pbm/pbmtoicon.c'" else sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoicon.c' X/* pbmtoicon.c - read a portable bitmap and produce a Sun icon file 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 "pbm.h" X Xstatic void putinit ARGS(( void )); Xstatic void putbit ARGS(( bit b )); Xstatic void putrest ARGS(( void )); Xstatic void putitem ARGS(( void )); X Xvoid Xmain( argc, argv ) X int argc; X char* argv[]; X { X FILE* ifp; X bit* bitrow; X register bit* bP; X int rows, cols, format, pad, padleft, padright, row, col; X X pbm_init( &argc, argv ); X X if ( argc > 2 ) X pm_usage( "[pbmfile]" ); X X if ( argc == 2 ) X ifp = pm_openr( argv[1] ); X else X ifp = stdin; X X pbm_readpbminit( ifp, &cols, &rows, &format ); X bitrow = pbm_allocrow( cols ); X X /* Round cols up to the nearest multiple of 16. */ X pad = ( ( cols + 15 ) / 16 ) * 16 - cols; X padleft = pad / 2; X padright = pad - padleft; X X printf( "/* Format_version=1, Width=%d, Height=%d", cols + pad, rows ); X printf( ", Depth=1, Valid_bits_per_item=16\n */\n" ); X X putinit( ); X for ( row = 0; row < rows; ++row ) X { X pbm_readpbmrow( ifp, bitrow, cols, format ); X for ( col = 0; col < padleft; ++col ) X putbit( 0 ); X for ( col = 0, bP = bitrow; col < cols; ++col, ++bP ) X putbit( *bP ); X for ( col = 0; col < padright; ++col ) X putbit( 0 ); X } X X pm_close( ifp ); X X putrest( ); X X exit( 0 ); X } X Xstatic int item, bitsperitem, bitshift, itemsperline, firstitem; X Xstatic void Xputinit( ) X { X itemsperline = 0; X bitsperitem = 0; X item = 0; X bitshift = 15; X firstitem = 1; X } X X#if __STDC__ Xstatic void Xputbit( bit b ) X#else /*__STDC__*/ Xstatic void Xputbit( b ) Xbit b; X#endif /*__STDC__*/ X { X if ( bitsperitem == 16 ) X putitem( ); X ++bitsperitem; X if ( b == PBM_BLACK ) X item += 1 << bitshift; X --bitshift; X } X Xstatic void Xputrest( ) X { X if ( bitsperitem > 0 ) X putitem( ); X putchar( '\n' ); X } X Xstatic void Xputitem( ) X { X char* hexits = "0123456789abcdef"; X X if ( firstitem ) X firstitem = 0; X else X putchar( ',' ); X if ( itemsperline == 8 ) X { X putchar( '\n' ); X itemsperline = 0; X } X if ( itemsperline == 0 ) X putchar( '\t' ); X putchar( '0' ); X putchar( 'x' ); X putchar( hexits[item >> 12] ); X putchar( hexits[( item >> 8 ) & 15] ); X putchar( hexits[( item >> 4 ) & 15] ); X putchar( hexits[item & 15] ); X ++itemsperline; X bitsperitem = 0; X item = 0; X bitshift = 15; X } SHAR_EOF if test 2821 -ne "`wc -c < 'pbm/pbmtoicon.c'`" then echo shar: error transmitting "'pbm/pbmtoicon.c'" '(should have been 2821 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/pbmtoicon.1'" '(739 characters)' if test -f 'pbm/pbmtoicon.1' then echo shar: will not over-write existing file "'pbm/pbmtoicon.1'" else sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoicon.1' X.TH pbmtoicon 1 "31 August 1988" X.IX pbmtoicon X.SH NAME Xpbmtoicon - convert a portable bitmap into a Sun icon X.SH SYNOPSIS X.B pbmtoicon X.RI [ pbmfile ] X.SH DESCRIPTION XReads a portable bitmap as input. XProduces a Sun icon as output. X.IX Sun X.IX "Sun icon format" X.SH "SEE ALSO" Xicontopbm(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer. 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. SHAR_EOF if test 739 -ne "`wc -c < 'pbm/pbmtoicon.1'`" then echo shar: error transmitting "'pbm/pbmtoicon.1'" '(should have been 739 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/pbmtoxbm.c'" '(2579 characters)' if test -f 'pbm/pbmtoxbm.c' then echo shar: will not over-write existing file "'pbm/pbmtoxbm.c'" else sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoxbm.c' X/* pbmtoxbm.c - read a portable bitmap and produce an X11 bitmap file 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 "pbm.h" X Xvoid Xmain( argc, argv ) X int argc; X char* argv[]; X { X FILE* ifp; X bit* bitrow; X register bit* bP; X int rows, cols, format, padright, row; X register int col; X char name[100]; X char* cp; X int itemsperline; X register int bitsperitem; X register int item; X int firstitem; X char* hexchar = "0123456789abcdef"; X X pbm_init( &argc, argv ); X X if ( argc > 2 ) X pm_usage( "[pbmfile]" ); X X if ( argc == 2 ) X { X ifp = pm_openr( argv[1] ); X strcpy( name, argv[1] ); X if ( strcmp( name, "-" ) == 0 ) X strcpy( name, "noname" ); X X if ( ( cp = index( name, '.' ) ) != 0 ) X *cp = '\0'; X } X else X { X ifp = stdin; X strcpy( name, "noname" ); X } X X pbm_readpbminit( ifp, &cols, &rows, &format ); X bitrow = pbm_allocrow( cols ); X X /* Compute padding to round cols up to the nearest multiple of 8. */ X padright = ( ( cols + 7 ) / 8 ) * 8 - cols; X X printf( "#define %s_width %d\n", name, cols ); X printf( "#define %s_height %d\n", name, rows ); X printf( "static char %s_bits[] = {\n", name ); X X itemsperline = 0; X bitsperitem = 0; X item = 0; X firstitem = 1; X X#define PUTITEM \ X { \ X if ( firstitem ) \ X firstitem = 0; \ X else \ X putchar( ',' ); \ X if ( itemsperline == 15 ) \ X { \ X putchar( '\n' ); \ X itemsperline = 0; \ X } \ X if ( itemsperline == 0 ) \ X putchar( ' ' ); \ X ++itemsperline; \ X putchar('0'); \ X putchar('x'); \ X putchar(hexchar[item >> 4]); \ X putchar(hexchar[item & 15]); \ X bitsperitem = 0; \ X item = 0; \ X } X X#define PUTBIT(b) \ X { \ X if ( bitsperitem == 8 ) \ X PUTITEM; \ X if ( (b) == PBM_BLACK ) \ X item += 1 << bitsperitem; \ X ++bitsperitem; \ X } X X for ( row = 0; row < rows; ++row ) X { X pbm_readpbmrow( ifp, bitrow, cols, format ); X for ( col = 0, bP = bitrow; col < cols; ++col, ++bP ) X PUTBIT(*bP); X for ( col = 0; col < padright; ++col ) X PUTBIT(0); X } X X if ( ifp != stdin ) X fclose( ifp ); X X if ( bitsperitem > 0 ) X PUTITEM; X printf( "};\n" ); X X exit( 0 ); X } SHAR_EOF if test 2579 -ne "`wc -c < 'pbm/pbmtoxbm.c'`" then echo shar: error transmitting "'pbm/pbmtoxbm.c'" '(should have been 2579 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/pbmtoxbm.1'" '(762 characters)' if test -f 'pbm/pbmtoxbm.1' then echo shar: will not over-write existing file "'pbm/pbmtoxbm.1'" else sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoxbm.1' X.TH pbmtoxbm 1 "31 August 1988" X.IX pbmtoxbm X.SH NAME Xpbmtoxbm - convert a portable bitmap into an X11 bitmap X.SH SYNOPSIS X.B pbmtoxbm X.RI [ pbmfile ] X.SH DESCRIPTION XReads a portable bitmap as input. XProduces an X11 bitmap as output. X.IX "X bitmap" X.IX "X window system" X.SH "SEE ALSO" Xpbmtox10bm(1), xbmtopbm(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer. 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. SHAR_EOF if test 762 -ne "`wc -c < 'pbm/pbmtoxbm.1'`" then echo shar: error transmitting "'pbm/pbmtoxbm.1'" '(should have been 762 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/pbmtox10bm.c'" '(2653 characters)' if test -f 'pbm/pbmtox10bm.c' then echo shar: will not over-write existing file "'pbm/pbmtox10bm.c'" else sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtox10bm.c' X/* pbmtox10bm.c - read a portable bitmap and produce an X10 bitmap file 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 "pbm.h" X Xvoid Xmain( argc, argv ) X int argc; X char* argv[]; X { X FILE* ifp; X bit* bitrow; X register bit* bP; X int rows, cols, format, padright, row; X register int col; X char name[100]; X char* cp; X int itemsperline; X register int bitsperitem; X register int item; X int firstitem; X char* hexchar = "0123456789abcdef"; X X pbm_init( &argc, argv ); X X if ( argc > 2 ) X pm_usage( "[pbmfile]" ); X X if ( argc == 2 ) X { X ifp = pm_openr( argv[1] ); X strcpy( name, argv[1] ); X if ( strcmp( name, "-" ) == 0 ) X strcpy( name, "noname" ); X X if ( ( cp = index( name, '.' ) ) != 0 ) X *cp = '\0'; X } X else X { X ifp = stdin; X strcpy( name, "noname" ); X } X X pbm_readpbminit( ifp, &cols, &rows, &format ); X bitrow = pbm_allocrow( cols ); X X /* Compute padding to round cols up to the nearest multiple of 16. */ X padright = ( ( cols + 15 ) / 16 ) * 16 - cols; X X printf( "#define %s_width %d\n", name, cols ); X printf( "#define %s_height %d\n", name, rows ); X printf( "static short %s_bits[] = {\n", name ); X X itemsperline = 0; X bitsperitem = 0; X item = 0; X firstitem = 1; X X#define PUTITEM \ X { \ X if ( firstitem ) \ X firstitem = 0; \ X else \ X putchar( ',' ); \ X if ( itemsperline == 11 ) \ X { \ X putchar( '\n' ); \ X itemsperline = 0; \ X } \ X if ( itemsperline == 0 ) \ X putchar( ' ' ); \ X ++itemsperline; \ X putchar('0'); \ X putchar('x'); \ X putchar(hexchar[item >> 12]); \ X putchar(hexchar[(item >> 8) & 15]); \ X putchar(hexchar[(item >> 4) & 15]); \ X putchar(hexchar[item & 15]); \ X bitsperitem = 0; \ X item = 0; \ X } X X#define PUTBIT(b) \ X { \ X if ( bitsperitem == 16 ) \ X PUTITEM; \ X if ( (b) == PBM_BLACK ) \ X item += 1 << bitsperitem; \ X ++bitsperitem; \ X } X X for ( row = 0; row < rows; ++row ) X { X pbm_readpbmrow( ifp, bitrow, cols, format ); X for ( col = 0, bP = bitrow; col < cols; ++col, ++bP ) X PUTBIT(*bP); X for ( col = 0; col < padright; ++col ) X PUTBIT(0); X } X X pm_close( ifp ); X X if ( bitsperitem > 0 ) X PUTITEM; X printf( "};\n" ); X X exit( 0 ); X } SHAR_EOF if test 2653 -ne "`wc -c < 'pbm/pbmtox10bm.c'`" then echo shar: error transmitting "'pbm/pbmtox10bm.c'" '(should have been 2653 characters)' fi fi # end of overwriting check if test ! -d 'pbm' then echo shar: creating directory "'pbm'" mkdir 'pbm' fi echo shar: extracting "'pbm/pbmtox10bm.1'" '(917 characters)' if test -f 'pbm/pbmtox10bm.1' then echo shar: will not over-write existing file "'pbm/pbmtox10bm.1'" else sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtox10bm.1' X.TH pbmtox10bm 1 "31 August 1988" X.IX pbmtox10bm X.SH NAME Xpbmtox10bm - convert a portable bitmap into an X10 bitmap X.SH SYNOPSIS X.B pbmtox10bm X.RI [ pbmfile ] X.SH DESCRIPTION XReads a portable bitmap as input. XProduces an X10 bitmap as output. XThis older format is maintained for compatibility. X.IX "X bitmap" X.IX "X window system" X.PP XNote that there is no x10bmtopbm tool, because X.I xbmtopbm Xcan read both X11 and X10 bitmaps. X.SH "SEE ALSO" Xpbmtoxbm(1), xbmtopbm(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer. 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. SHAR_EOF if test 917 -ne "`wc -c < 'pbm/pbmtox10bm.1'`" then echo shar: error transmitting "'pbm/pbmtox10bm.1'" '(should have been 917 characters)' fi fi # end of overwriting check # End of shell archive exit 0 exit 0 # Just in case... -- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM Sterling Software, IMD UUCP: uunet!sparky!kent Phone: (402) 291-8300 FAX: (402) 291-4362 Please send comp.sources.misc-related mail to kent@uunet.uu.net.