Newsgroups: comp.sources.misc
From: jef@well.sf.ca.us (Jef Poskanzer)
Subject:  REPOST: v23i055:  pbmplus - Extended Portable Bitmap Toolkit, Part20/24
Message-ID: <1991Oct17.041453.15044@sparky.imd.sterling.com>
X-Md4-Signature: 9eb59d6e61247925eac1cd64af05bfbe
Date: Thu, 17 Oct 1991 04:14:53 GMT
Approved: kent@sparky.imd.sterling.com

Submitted-by: jef@well.sf.ca.us (Jef Poskanzer)
Posting-number: Volume 23, Issue 55
Archive-name: pbmplus/part20
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:
#	pnm/Imakefile
#	pnm/Makefile
#	pnm/pnm.5
#	pnm/libpnm.3
#	pnm/libpnm1.c
#	pnm/libpnm2.c
#	pnm/libpnm3.c
#	pnm/libpnm4.c
#	pnm/pnmcat.c
#	pnm/pnmcat.1
#	pnm/x11wd.h
# This archive created: Fri Sep 27 17:50:46 1991
# By:	Jef Poskanzer (Acme Software)
export PATH; PATH=/bin:$PATH
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/Imakefile'" '(3108 characters)'
if test -f 'pnm/Imakefile'
then
	echo shar: will not over-write existing file "'pnm/Imakefile'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/Imakefile'
X# Imakefile for pnm 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
XTIFFDEF =	-DLIBTIFF
XTIFFINC =	-I../libtiff
XTIFFLIB =	../libtiff/libtiff.a
XTIFFBINARIES =	tifftopnm pnmtotiff
XTIFFMANUALS =	tifftopnm.1 pnmtotiff.1
X
XPPMDIR =	../ppm
XINCLUDEPPM =	-I$(PPMDIR)
XLIBPPM =	$(PPMDIR)/libppm.a
XDEFPPM =	$(PPMDIR)/ppm.h ../pbmplus.h
XDEFLIBPPM =	$(PPMDIR)/libppm.h
X
XPGMDIR =	../pgm
XINCLUDEPGM =	-I$(PGMDIR)
XLIBPGM =	$(PGMDIR)/libpgm.a
XDEFPGM =	$(PGMDIR)/pgm.h
XDEFLIBPGM =	$(PGMDIR)/libpgm.h
X
XPBMDIR =	../pbm
XINCLUDEPBM =	-I$(PBMDIR)
XLIBPBM =	$(PBMDIR)/libpbm.a
XDEFPBM =	$(PBMDIR)/pbm.h
XDEFLIBPBM =	$(PBMDIR)/libpbm.h
X
XINCLUDE =	-I.. $(INCLUDEPPM) $(INCLUDEPGM) $(INCLUDEPBM)
XALLCFLAGS =	$(CFLAGS) $(TIFFDEF) $(INCLUDE) $(TIFFINC)
XLIBPNM =	libpnm.a
X
XPORTBINARIES =	pnmarith pnmcat pnmconvol pnmcrop pnmcut \
X		pnmdepth pnmenlarge pnmfile pnmflip pnminvert \
X		pnmnoraw pnmpaste pnmscale pnmtile pnmtops \
X		pnmtorast pnmtoxwd rasttopnm xwdtopnm
XMATHBINARIES =	pnmgamma pnmrotate pnmshear
XBINARIES =	$(PORTBINARIES) $(MATHBINARIES) $(TIFFBINARIES)
XSCRIPTS =	anytopnm pnmindex pnmmargin pnmsmooth
X
XMANUALS1 =	pnmarith.1 pnmcat.1 pnmconvol.1 pnmcrop.1 pnmcut.1 \
X		pnmdepth.1 pnmenlarge.1 pnmfile.1 pnmflip.1 pnminvert.1 \
X		pnmnoraw.1 pnmpaste.1 pnmscale.1 pnmtile.1 pnmtops.1 \
X		pnmtorast.1 pnmtoxwd.1 rasttopnm.1 xwdtopnm.1 \
X		pnmgamma.1 pnmrotate.1 pnmshear.1 \
X		anytopnm.1 pnmindex.1 pnmmargin.1 pnmsmooth.1 $(TIFFMANUALS)
XMANUALS3 =	libpnm.3
XMANUALS5 =	pnm.5
X
Xall:		$(BINARIES)
X
Xinstall::	all
X	cp $(BINARIES) $(BINDIR)
X	cp $(SCRIPTS) $(BINDIR)
X	cd $(BINDIR) ; chmod +x $(SCRIPTS)
X
Xinstall.man::
X	cp $(MANUALS1) $(MANUALS3) $(MANUALS5) $(MANDIR)
X
X# Rule for plain programs.
X$(PORTBINARIES) $(TIFFBINARIES):	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM) $(TIFFLIB)
X	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM) $(TIFFLIB)
X
X# Rule for math-dependent programs.
X$(MATHBINARIES):	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM)
X	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c -lm $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM)
X
X# And library.
X$(LIBPNM):	libpnm1.o libpnm2.o libpnm3.o libpnm4.o
X	-rm $(LIBPNM)
X	$(AR) $(LIBPNM) libpnm1.o libpnm2.o libpnm3.o libpnm4.o
X	-$(RANLIB) $(LIBPNM)
X
Xlibpnm1.o:	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm1.c
X	$(CC) $(ALLCFLAGS) -c libpnm1.c
Xlibpnm2.o:	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm2.c $(DEFLIBPPM) $(DEFLIBPGM) $(DEFLIBPBM)
X	$(CC) $(ALLCFLAGS) -c libpnm2.c
Xlibpnm3.o:	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm3.c $(DEFLIBPPM) $(DEFLIBPGM) $(DEFLIBPBM)
X	$(CC) $(ALLCFLAGS) -c libpnm3.c
Xlibpnm4.o:	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) rast.h libpnm4.c
X	$(CC) $(ALLCFLAGS) -c libpnm4.c
X
XDependTarget()
SHAR_EOF
if test 3108 -ne "`wc -c < 'pnm/Imakefile'`"
then
	echo shar: error transmitting "'pnm/Imakefile'" '(should have been 3108 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/Makefile'" '(5937 characters)'
if test -f 'pnm/Makefile'
then
	echo shar: will not over-write existing file "'pnm/Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/Makefile'
X# Makefile for pnm 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
XTIFFDEF =	-DLIBTIFF
XTIFFINC =       -I../libtiff
XTIFFLIB =       ../libtiff/libtiff.a
XTIFFBINARIES =  tifftopnm pnmtotiff
XTIFFOBJECTS =   tifftopnm.o pnmtotiff.o
X#LDFLAGS =	-s
XLDFLAGS =	
XINSTALLBINARIES =	/usr/new/pbm
XINSTALLSCRIPTS =	$(INSTALLBINARIES)
XINSTALLMANUALS1 =	/usr/man/man1
XSUFFIXMANUALS1 =	1
XINSTALLMANUALS3 =	/usr/man/man3
XSUFFIXMANUALS3 =	3
XINSTALLMANUALS5 =	/usr/man/man5
XSUFFIXMANUALS5 =	5
XMANCP =			cp
X
XPPMDIR =	../ppm
XINCLUDEPPM =	-I$(PPMDIR)
XLIBPPM =	$(PPMDIR)/libppm.a
XDEFPPM =	$(PPMDIR)/ppm.h
XDEFLIBPPM =	$(PPMDIR)/libppm.h
X
XPGMDIR =	../pgm
XINCLUDEPGM =	-I$(PGMDIR)
XLIBPGM =	$(PGMDIR)/libpgm.a
XDEFPGM =	$(PGMDIR)/pgm.h
XDEFLIBPGM =	$(PGMDIR)/libpgm.h
X
XPBMDIR =	../pbm
XINCLUDEPBM =	-I$(PBMDIR)
XLIBPBM =	$(PBMDIR)/libpbm.a
XDEFPBM =	$(PBMDIR)/pbm.h ../pbmplus.h
XDEFLIBPBM =	$(PBMDIR)/libpbm.h
X
XSHELL =		/bin/sh
XINCLUDE =	-I.. $(INCLUDEPPM) $(INCLUDEPGM) $(INCLUDEPBM)
XALLCFLAGS =	$(CFLAGS) $(INCLUDE) $(TIFFDEF) $(TIFFINC)
XLIBPNM =	libpnm.a
X
XPORTBINARIES =	pnmarith pnmcat pnmconvol pnmcrop pnmcut \
X		pnmdepth pnmenlarge pnmfile pnmflip pnminvert \
X		pnmnoraw pnmpaste pnmscale pnmtile pnmtops \
X		pnmtorast pnmtoxwd rasttopnm xwdtopnm
XMATHBINARIES =	pnmgamma pnmrotate pnmshear
XBINARIES =      $(PORTBINARIES) $(MATHBINARIES) $(TIFFBINARIES)
XSCRIPTS =	anytopnm pnmindex pnmmargin pnmsmooth
X
XPORTOBJECTS =	pnmarith.o pnmcat.o pnmconvol.o pnmcrop.o pnmcut.o \
X		pnmdepth.o pnmenlarge.o pnmfile.o pnmflip.o pnminvert.o \
X		pnmnoraw.o pnmpaste.o pnmscale.o pnmtile.o pnmtops.o \
X		pnmtorast.o pnmtoxwd.o rasttopnm.o xwdtopnm.o \
X		pnmgamma.o pnmrotate.o pnmshear.o
XOBJECTS =	$(PORTOBJECTS) $(TIFFOBJECTS)
X
XMANUALS1 =	$(BINARIES) $(SCRIPTS)
XMANUALS3 =	libpnm
XMANUALS5 =	pnm
X
X
X#all:		binaries
Xall:		merge
X#install:	install.bin
Xinstall:	install.merge
X
X
Xbinaries:	$(BINARIES)
X
Xinstall.bin:	binaries $(SCRIPTS)
X	cd $(INSTALLBINARIES) ; rm -f $(BINARIES)
X	cp $(BINARIES) $(INSTALLBINARIES)
X	cd $(INSTALLSCRIPTS) ; rm -f $(SCRIPTS)
X	cp $(SCRIPTS) $(INSTALLSCRIPTS)
X	cd $(INSTALLSCRIPTS) ; chmod +x $(SCRIPTS)
X
X
Xmerge:		pnmmerge
Xpnmmerge:	pnmmerge.c $(OBJECTS) $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM)
X	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(OBJECTS) -lm $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM) $(TIFFLIB)
X
Xinstall.merge:	install.pnmmerge $(SCRIPTS)
Xinstall.pnmmerge:	pnmmerge
X	cd $(INSTALLBINARIES) ; rm -f $(BINARIES)
X	cp pnmmerge $(INSTALLBINARIES)
X	cd $(INSTALLBINARIES) ; for i in $(BINARIES) ; do ln pnmmerge $$i ; done
X	rm $(INSTALLBINARIES)/pnmmerge
X	cd $(INSTALLSCRIPTS) ; rm -f $(SCRIPTS)
X	cp $(SCRIPTS) $(INSTALLSCRIPTS)
X	cd $(INSTALLSCRIPTS) ; chmod +x $(SCRIPTS)
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$(PORTBINARIES) $(TIFFBINARIES):	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM) $(TIFFLIB)
X	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM) $(TIFFLIB)
X
X# Rule for math-dependent programs.
X$(MATHBINARIES):        pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) $(LIBPNM) \
X			$(LIBPPM) $(LIBPGM) $(LIBPBM)
X	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c -lm $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM)
X
X# Rule for objects.
X$(OBJECTS):	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM)
X	$(CC) $(ALLCFLAGS) "-Dmain=$*_main" -c $*.c
X
X# And libraries.
X$(LIBPBM):
X	cd $(PBMDIR) ; make lib
X$(LIBPGM) FOO:
X	cd $(PGMDIR) ; make lib
X$(LIBPPM) BAR:
X	cd $(PPMDIR) ; make lib
Xlib:		$(LIBPNM)
X$(LIBPNM):	libpnm1.o libpnm2.o libpnm3.o libpnm4.o
X	-rm $(LIBPNM)
X	ar rc $(LIBPNM) libpnm1.o libpnm2.o libpnm3.o libpnm4.o
X	-ranlib $(LIBPNM)
X
Xlibpnm1.o:	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm1.c
X	$(CC) $(ALLCFLAGS) -c libpnm1.c
Xlibpnm2.o:	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm2.c $(DEFLIBPPM) \
X		$(DEFLIBPGM) $(DEFLIBPBM)
X	$(CC) $(ALLCFLAGS) -c libpnm2.c
Xlibpnm3.o:	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm3.c $(DEFLIBPPM) \
X		$(DEFLIBPGM) $(DEFLIBPBM)
X	$(CC) $(ALLCFLAGS) -c libpnm3.c
Xlibpnm4.o:	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) rast.h libpnm4.c
X	$(CC) $(ALLCFLAGS) -c libpnm4.c
X
X# Other dependencies.
Xpnmarith pnmarith.o:		pnmarith.c
Xpnmcat pnmcat.o:		pnmcat.c
Xpnmconvol pnmconvol.o:		pnmconvol.c
Xpnmcrop pnmcrop.o:		pnmcrop.c
Xpnmcut pnmcut.o:		pnmcut.c
Xpnmdepth pnmdepth.o:		pnmdepth.c
Xpnmenlarge pnmenlarge.o:	pnmenlarge.c
Xpnmfile pnmfile.o:		pnmfile.c
Xpnmflip pnmflip.o:		pnmflip.c
Xpnmgamma pnmgamma.o:		pnmgamma.c
Xpnminvert pnminvert.o:		pnminvert.c
Xpnmnoraw pnmnoraw.o:		pnmnoraw.c
Xpnmpaste pnmpaste.o:		pnmpaste.c
Xpnmrotate pnmrotate.o:		pnmrotate.c
Xpnmscale pnmscale.o:		pnmscale.c
Xpnmshear pnmshear.o:		pnmshear.c
Xpnmtile pnmtile.o:		pnmtile.c
Xpnmtops pnmtops.o:		pnmtops.c
Xpnmtorast pnmtorast.o:		pnmtorast.c rast.h
Xpnmtotiff pnmtotiff.o:		pnmtotiff.c
Xpnmtoxwd pnmtoxwd.o:		pnmtoxwd.c x11wd.h
Xrasttopnm rasttopnm.o:		rasttopnm.c rast.h
Xtifftopnm tifftopnm.o:		tifftopnm.c
Xxwdtopnm xwdtopnm.o:		xwdtopnm.c x10wd.h x11wd.h
X
Xclean:
X	-rm -f *.o *.a *.cat core $(BINARIES) pnmmerge
SHAR_EOF
if test 5937 -ne "`wc -c < 'pnm/Makefile'`"
then
	echo shar: error transmitting "'pnm/Makefile'" '(should have been 5937 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/pnm.5'" '(1117 characters)'
if test -f 'pnm/pnm.5'
then
	echo shar: will not over-write existing file "'pnm/pnm.5'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/pnm.5'
X.TH pnm 5 "27 September 1991"
X.SH NAME
Xpnm - portable anymap file format
X.SH DESCRIPTION
XThe
X.I pnm
Xprograms operate on portable bitmaps, graymaps, and pixmaps, produced by the
X.I pbm, pgm,
Xand
X.I ppm
Xsegments.  There is no file format associated with
X.I pnm
Xitself.
X.SH "SEE ALSO"
Xanytopnm(1), rasttopnm(1), tifftopnm(1), xwdtopnm(1),
Xpnmtops(1), pnmtorast(1), pnmtotiff(1), pnmtoxwd(1),
Xpnmarith(1), pnmcat(1), pnmconvol(1), pnmcrop(1), pnmcut(1),
Xpnmdepth(1), pnmenlarge(1), pnmfile(1), pnmflip(1), pnmgamma(1),
Xpnmindex(1), pnminvert(1), pnmmargin(1), pnmnoraw(1), pnmpaste(1),
Xpnmrotate(1), pnmscale(1), pnmshear(1), pnmsmooth(1), pnmtile(1),
Xppm(5), pgm(5), pbm(5)
X.SH AUTHOR
XCopyright (C) 1989, 1991 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 1117 -ne "`wc -c < 'pnm/pnm.5'`"
then
	echo shar: error transmitting "'pnm/pnm.5'" '(should have been 1117 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/libpnm.3'" '(4891 characters)'
if test -f 'pnm/libpnm.3'
then
	echo shar: will not over-write existing file "'pnm/libpnm.3'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/libpnm.3'
X.TH libpnm 3
X.SH NAME
Xlibpnm - functions to support portable anymap programs
X.SH SYNOPSIS
X.de Ss
X.sp
X.ft CW
X.nf
X..
X.de Se
X.fi
X.ft P
X.sp
X..
X.Ss
X#include <pnm.h>
Xcc ... libpnm.a libppm.a libpgm.a libpbm.a
X.Se
X.SH DESCRIPTION
X.SS TYPES AND CONSTANTS
X.Ss
Xtypedef ... xel;
Xtypedef ... xelval;
X#define PNM_MAXMAXVAL ...
Xextern xelval pnm_pbmmaxval;
X.Se
XEach
X.BR xel
Xcontains three
X.BR xelval s,
Xeach of which should contain only the values between
X.BR 0
Xand
X.BR PNM_MAXMAXVAL .
X.BR pnm_pbmmaxval
Xis the maxval used when a PNM program reads a PBM file.
XNormally it is 1; however, for some programs, a larger value gives better
Xresults.
X.SS XEL MANIPULATIONS
X.Ss
Xxelval PNM_GET1( xel x )
X.Se
XThis macro extracts a single value from an xel, when you know it's
Xfrom a PBM or PGM file.
XWhen it's from a PPM file, use
X.BR PPM_GETR() ,
X.BR PPM_GETG() ,
Xand
X.BR PPM_GETB() .
X.Ss
Xvoid PNM_ASSIGN1( xel x, xelval v )
X.Se
XThis macro assigns a single value to an xel, when you know it's
Xfrom a PBM or PGM file.
XWhen it's from a PPM file, use
X.BR PPM_ASSIGN() .
X.Ss
Xint PNM_EQUAL( xel x, xel y )
X.Se
XThis macro checks two xels for equality.
X.Ss
Xint PNM_FORMAT_TYPE( int format )
X.Se
XFor distinguishing different file types.
X.SS INITIALIZATION
X.Ss
Xvoid pnm_init( int* argcP, char* argv[] )
X.Se
XAll PNM programs must call this routine.
X.SS MEMORY MANAGEMENT
X.Ss
Xxel** pnm_allocarray( int cols, int rows )
X.Se
XAllocate an array of xels.
X.Ss
Xxel* pnm_allocrow( int cols )
X.Se
XAllocate a row of the given number of xels.
X.Ss
Xvoid pnm_freearray( xel** xels, int rows )
X.Se
XFree the array allocated with
X.BR pnm_allocarray()
Xcontaining the given number
Xof rows.
X.Ss
Xvoid pnm_freerow( xel* xelrow )
X.Se
XFree a row of xels.
X.SS READING FILES
X.Ss
Xvoid pnm_readpnminit( FILE* fp, int* colsP, int* rowsP, xelval* maxvalP, int* formatP )
X.Se
XRead the header from a PNM file, filling in the rows, cols, maxval and format
Xvariables.
X.Ss
Xvoid pnm_readpnmrow( FILE* fp, xel* xelrow, int cols, xelval maxval, int format )
X.Se
XRead a row of xels into the xelrow array.
XFormat, cols, and maxval were filled in by
X.BR pnm_readpnminit() .
X.Ss
Xxel** pnm_readpnm( FILE* fp, int* colsP, int* rowsP, xelval* maxvalP, int* formatP )
X.Se
XRead an entire anymap file into memory, returning the allocated array and
Xfilling in the rows, cols, maxval, and format variables.
XThis function combines
X.BR pnm_readpnminit() ,
X.BR pnm_allocarray()
Xand
X.BR pnm_readpnmrow() .
XUnlike the equivalent functions in PBM, PGM, and PPM, it returns the format
Xso you can tell what type the file is.
X.SS WRITING FILES
X.Ss
Xvoid pnm_writepnminit( FILE* fp, int cols, int rows, xelval maxval, int format, int forceplain )
X.Se
XWrite the header for a portable anymap file.
XUnlike the equivalent functions in PBM, PGM, and PPM, you have to specify
Xthe output type.
XThe forceplain flag forces a plain-format file to be written, as opposed
Xto a raw-format one.
X.Ss
Xvoid pnm_writepnmrow( FILE* fp, xel* xelrow, int cols, xelval maxval, int format, int forceplain )
X.Se
XWrite a row from a portable anymap.
X.Ss
Xvoid pnm_writepnm( FILE* fp, xel** xels, int cols, int rows, xelval maxval, int format, int forceplain )
X.Se
XWrite the header and all data for a portable anymap.
XThis function combines
X.BR pnm_writepnminit()
Xand
X.BR pnm_writepnmrow() .
X.SS FORMAT PROMOTION
X.Ss
Xvoid pnm_promoteformatrow( xel* xelrow, int cols, xelval maxval, int format, xelval newmaxval, int newformat )
X.Se
XPromote a row of xels from one maxval and format to a new set.
XUsed when combining multiple anymaps of different types - just
Xtake the max of the maxvals and the max of the formats, and
Xpromote them all to that.
X.Ss
Xvoid pnm_promoteformat( xel** xels, int cols, int rows, xelval maxval, int format, xelval newmaxval, int newformat )
X.Se
XPromote an entire anymap.
X.SS XEL MANIPULATION
X.Ss
Xxel pnm_whitexel( xelval maxval, int format )
Xxel pnm_blackxel( xelval maxval, int format )
X.Se
XReturn a white or black xel for the given maxval and format.
X.Ss
Xvoid pnm_invertxel( xel* x, xelval maxval, int format )
X.Se
XInvert an xel.
X.Ss
Xxel pnm_backgroundxelrow( xel* xelrow, int cols, xelval maxval, int format )
X.Se
XFigure out an appropriate background xel based on this row.
X.Ss
Xxel pnm_backgroundxel( xel** xels, int cols, int rows, xelval maxval, int format )
X.Se
XFigure out a background xel based on an entire anymap.
XThis can do a slightly better job than
X.BR pnm_backgroundxelrow() .
X.SH "SEE ALSO"
Xpbm(3), pgm(3), ppm(3)
X.SH AUTHOR
XCopyright (C) 1989, 1991 by Tony Hansen and 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 4891 -ne "`wc -c < 'pnm/libpnm.3'`"
then
	echo shar: error transmitting "'pnm/libpnm.3'" '(should have been 4891 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/libpnm1.c'" '(2931 characters)'
if test -f 'pnm/libpnm1.c'
then
	echo shar: will not over-write existing file "'pnm/libpnm1.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/libpnm1.c'
X/* libpnm1.c - pnm utility library part 1
X**
X** Copyright (C) 1989 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include "pnm.h"
X
X#include "ppm.h"
X#include "libppm.h"
X
X#include "pgm.h"
X#include "libpgm.h"
X
X#include "pbm.h"
X#include "libpbm.h"
X
Xvoid
Xpnm_init( argcP, argv )
X    int* argcP;
X    char* argv[];
X    {
X    ppm_init( argcP, argv );
X    }
X
Xxelval pnm_pbmmaxval = 1;
X
Xvoid
Xpnm_readpnminit( file, colsP, rowsP, maxvalP, formatP )
X    FILE* file;
X    int* colsP;
X    int* rowsP;
X    int* formatP;
X    xelval* maxvalP;
X    {
X    gray gmaxval;
X
X    /* Check magic number. */
X    *formatP = pbm_readmagicnumber( file );
X    switch ( PNM_FORMAT_TYPE(*formatP) )
X	{
X	case PPM_TYPE:
X	ppm_readppminitrest( file, colsP, rowsP, (pixval*) maxvalP );
X	break;
X
X	case PGM_TYPE:
X	pgm_readpgminitrest( file, colsP, rowsP, &gmaxval );
X	*maxvalP = (xelval) gmaxval;
X	break;
X
X	case PBM_TYPE:
X	pbm_readpbminitrest( file, colsP, rowsP );
X	*maxvalP = pnm_pbmmaxval;
X	break;
X
X	default:
X	pm_error( "bad magic number - not a ppm, pgm, or pbm file" );
X	}
X    }
X
X#if __STDC__
Xvoid
Xpnm_readpnmrow( FILE* file, xel* xelrow, int cols, xelval maxval, int format )
X#else /*__STDC__*/
Xvoid
Xpnm_readpnmrow( file, xelrow, cols, maxval, format )
X    FILE* file;
X    xel* xelrow;
X    xelval maxval;
X    int cols, format;
X#endif /*__STDC__*/
X    {
X    register int col;
X    register xel* xP;
X    gray* grayrow;
X    register gray* gP;
X    bit* bitrow;
X    register bit* bP;
X
X    switch ( PNM_FORMAT_TYPE(format) )
X	{
X	case PPM_TYPE:
X	ppm_readppmrow( file, (pixel*) xelrow, cols, (pixval) maxval, format );
X	break;
X
X	case PGM_TYPE:
X	grayrow = pgm_allocrow( cols );
X	pgm_readpgmrow( file, grayrow, cols, (gray) maxval, format );
X	for ( col = 0, xP = xelrow, gP = grayrow; col < cols; ++col, ++xP, ++gP )
X	    PNM_ASSIGN1( *xP, *gP );
X	pgm_freerow( grayrow );
X	break;
X
X	case PBM_TYPE:
X	bitrow = pbm_allocrow( cols );
X	pbm_readpbmrow( file, bitrow, cols, format );
X	for ( col = 0, xP = xelrow, bP = bitrow; col < cols; ++col, ++xP, ++bP )
X	    PNM_ASSIGN1( *xP, *bP == PBM_BLACK ? 0: pnm_pbmmaxval );
X	pbm_freerow( bitrow );
X	break;
X
X	default:
X	pm_error( "can't happen" );
X	}
X    }
X
Xxel**
Xpnm_readpnm( file, colsP, rowsP, maxvalP, formatP )
X    FILE* file;
X    int* colsP;
X    int* rowsP;
X    int* formatP;
X    xelval* maxvalP;
X    {
X    xel** xels;
X    int row;
X
X    pnm_readpnminit( file, colsP, rowsP, maxvalP, formatP );
X
X    xels = pnm_allocarray( *colsP, *rowsP );
X
X    for ( row = 0; row < *rowsP; ++row )
X	pnm_readpnmrow( file, xels[row], *colsP, *maxvalP, *formatP );
X
X    return xels;
X    }
SHAR_EOF
if test 2931 -ne "`wc -c < 'pnm/libpnm1.c'`"
then
	echo shar: error transmitting "'pnm/libpnm1.c'" '(should have been 2931 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/libpnm2.c'" '(2970 characters)'
if test -f 'pnm/libpnm2.c'
then
	echo shar: will not over-write existing file "'pnm/libpnm2.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/libpnm2.c'
X/* libpnm2.c - pnm utility library part 2
X**
X** Copyright (C) 1989 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include "pnm.h"
X
X#include "ppm.h"
X#include "libppm.h"
X
X#include "pgm.h"
X#include "libpgm.h"
X
X#include "pbm.h"
X#include "libpbm.h"
X
X#if __STDC__
Xvoid
Xpnm_writepnminit( FILE* file, int cols, int rows, xelval maxval, int format, int forceplain )
X#else /*__STDC__*/
Xvoid
Xpnm_writepnminit( file, cols, rows, maxval, format, forceplain )
X    FILE* file;
X    int cols, rows, format;
X    xelval maxval;
X    int forceplain;
X#endif /*__STDC__*/
X    {
X    switch ( PNM_FORMAT_TYPE(format) )
X	{
X	case PPM_TYPE:
X	ppm_writeppminit( file, cols, rows, (pixval) maxval, forceplain );
X	break;
X
X	case PGM_TYPE:
X	pgm_writepgminit( file, cols, rows, (gray) maxval, forceplain );
X	break;
X
X	case PBM_TYPE:
X	pbm_writepbminit( file, cols, rows, forceplain );
X	break;
X
X	default:
X	pm_error( "can't happen" );
X	}
X    }
X
X#if __STDC__
Xvoid
Xpnm_writepnmrow( FILE* file, xel* xelrow, int cols, xelval maxval, int format, int forceplain )
X#else /*__STDC__*/
Xvoid
Xpnm_writepnmrow( file, xelrow, cols, maxval, format, forceplain )
X    FILE* file;
X    xel* xelrow;
X    int cols, format;
X    xelval maxval;
X    int forceplain;
X#endif /*__STDC__*/
X    {
X    register int col;
X    register xel* xP;
X    gray* grayrow;
X    register gray* gP;
X    bit* bitrow;
X    register bit* bP;
X
X    switch ( PNM_FORMAT_TYPE(format) )
X	{
X	case PPM_TYPE:
X	ppm_writeppmrow( file, (pixel*) xelrow, cols, (pixval) maxval, forceplain );
X	break;
X
X	case PGM_TYPE:
X	grayrow = pgm_allocrow( cols );
X	for ( col = 0, gP = grayrow, xP = xelrow; col < cols; ++col, ++gP, ++xP )
X	    *gP = PNM_GET1( *xP );
X	pgm_writepgmrow( file, grayrow, cols, (gray) maxval, forceplain );
X	pgm_freerow( grayrow );
X	break;
X
X	case PBM_TYPE:
X	bitrow = pbm_allocrow( cols );
X	for ( col = 0, bP = bitrow, xP = xelrow; col < cols; ++col, ++bP, ++xP )
X	    *bP = PNM_GET1( *xP ) == 0 ? PBM_BLACK : PBM_WHITE;
X	pbm_writepbmrow( file, bitrow, cols, forceplain );
X	pbm_freerow( bitrow );
X	break;
X
X	default:
X	pm_error( "can't happen" );
X	}
X    }
X
X#if __STDC__
Xvoid
Xpnm_writepnm( FILE* file, xel** xels, int cols, int rows, xelval maxval, int format, int forceplain )
X#else /*__STDC__*/
Xvoid
Xpnm_writepnm( file, xels, cols, rows, maxval, format, forceplain )
X    FILE* file;
X    xel** xels;
X    xelval maxval;
X    int cols, rows, format;
X    int forceplain;
X#endif /*__STDC__*/
X    {
X    int row;
X
X    pnm_writepnminit( file, cols, rows, maxval, format, forceplain );
X
X    for ( row = 0; row < rows; ++row )
X	pnm_writepnmrow( file, xels[row], cols, maxval, format, forceplain );
X    }
SHAR_EOF
if test 2970 -ne "`wc -c < 'pnm/libpnm2.c'`"
then
	echo shar: error transmitting "'pnm/libpnm2.c'" '(should have been 2970 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/libpnm3.c'" '(8773 characters)'
if test -f 'pnm/libpnm3.c'
then
	echo shar: will not over-write existing file "'pnm/libpnm3.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/libpnm3.c'
X/* libpnm3.c - pnm utility library part 3
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
X#include "pnm.h"
X
X#include "ppm.h"
X#include "libppm.h"
X
X#include "pgm.h"
X#include "libpgm.h"
X
X#include "pbm.h"
X#include "libpbm.h"
X
X#if __STDC__
Xxel
Xpnm_backgroundxel( xel** xels, int cols, int rows, xelval maxval, int format )
X#else /*__STDC__*/
Xxel
Xpnm_backgroundxel( xels, cols, rows, maxval, format )
X    xel** xels;
X    int cols, rows, format;
X    xelval maxval;
X#endif /*__STDC__*/
X    {
X    xel bgxel, ul, ur, ll, lr;
X
X    /* Guess a good background value. */
X    ul = xels[0][0];
X    ur = xels[0][cols-1];
X    ll = xels[rows-1][0];
X    lr = xels[rows-1][cols-1];
X
X    /* First check for three corners equal. */
X    if ( PNM_EQUAL( ul, ur ) && PNM_EQUAL( ur, ll ) )
X	bgxel = ul;
X    else if ( PNM_EQUAL( ul, ur ) && PNM_EQUAL( ur, lr ) )
X	bgxel = ul;
X    else if ( PNM_EQUAL( ul, ll ) && PNM_EQUAL( ll, lr ) )
X	bgxel = ul;
X    else if ( PNM_EQUAL( ur, ll ) && PNM_EQUAL( ll, lr ) )
X	bgxel = ur;
X    /* Nope, check for two corners equal. */
X    else if ( PNM_EQUAL( ul, ur ) || PNM_EQUAL( ul, ll ) ||
X	      PNM_EQUAL( ul, lr ) )
X	bgxel = ul;
X    else if ( PNM_EQUAL( ur, ll ) || PNM_EQUAL( ur, lr ) )
X	bgxel = ur;
X    else if ( PNM_EQUAL( ll, lr ) )
X	bgxel = ll;
X    else
X	{
X	/* Nope, we have to average the four corners.  This breaks the
X	** rules of pnm, but oh well.  Let's try to do it portably. */
X	switch ( PNM_FORMAT_TYPE(format) )
X	    {
X	    case PPM_TYPE:
X	    PPM_ASSIGN( bgxel,
X		PPM_GETR(ul) + PPM_GETR(ur) + PPM_GETR(ll) + PPM_GETR(lr) / 4,
X		PPM_GETG(ul) + PPM_GETG(ur) + PPM_GETG(ll) + PPM_GETG(lr) / 4,
X		PPM_GETB(ul) + PPM_GETB(ur) + PPM_GETB(ll) + PPM_GETB(lr) / 4 );
X	    break;
X
X	    case PGM_TYPE:
X	    {
X	    gray gul, gur, gll, glr;
X	    gul = (gray) PNM_GET1( ul );
X	    gur = (gray) PNM_GET1( ur );
X	    gll = (gray) PNM_GET1( ll );
X	    glr = (gray) PNM_GET1( lr );
X	    PNM_ASSIGN1( bgxel, ( ( gul + gur + gll + glr ) / 4 ) );
X	    break;
X	    }
X
X	    case PBM_TYPE:
X	    pm_error(
X	    "pnm_backgroundxel: four bits no two of which equal each other??" );
X
X	    default:
X	    pm_error( "can't happen" );
X	    }
X	}
X
X    return bgxel;
X    }
X
X#if __STDC__
Xxel
Xpnm_backgroundxelrow( xel* xelrow, int cols, xelval maxval, int format )
X#else /*__STDC__*/
Xxel
Xpnm_backgroundxelrow( xelrow, cols, maxval, format )
X    xel* xelrow;
X    int cols, format;
X    xelval maxval;
X#endif /*__STDC__*/
X    {
X    xel bgxel, l, r;
X
X    /* Guess a good background value. */
X    l = xelrow[0];
X    r = xelrow[cols-1];
X
X    /* First check for both corners equal. */
X    if ( PNM_EQUAL( l, r ) )
X	bgxel = l;
X    else
X	{
X	/* Nope, we have to average the two corners.  This breaks the
X	** rules of pnm, but oh well.  Let's try to do it portably. */
X	switch ( PNM_FORMAT_TYPE(format) )
X	    {
X	    case PPM_TYPE:
X	    PPM_ASSIGN( bgxel, PPM_GETR(l) + PPM_GETR(r) / 2,
X		PPM_GETG(l) + PPM_GETG(r) / 2, PPM_GETB(l) + PPM_GETB(r) / 2 );
X	    break;
X
X	    case PGM_TYPE:
X	    {
X	    gray gl, gr;
X	    gl = (gray) PNM_GET1( l );
X	    gr = (gray) PNM_GET1( r );
X	    PNM_ASSIGN1( bgxel, ( ( gl + gr ) / 2 ) );
X	    break;
X	    }
X
X	    case PBM_TYPE:
X	    {
X	    int col, blacks;
X
X	    /* One black, one white.  Gotta count. */
X	    for ( col = 0, blacks = 0; col < cols; ++col )
X		{
X		if ( PNM_GET1( xelrow[col] ) == 0 )
X		    ++blacks;
X		}
X	    if ( blacks >= cols / 2 )
X		PNM_ASSIGN1( bgxel, 0 );
X	    else
X		PNM_ASSIGN1( bgxel, pnm_pbmmaxval );
X	    break;
X	    }
X
X	    default:
X	    pm_error( "can't happen" );
X	    }
X	}
X
X    return bgxel;
X    }
X
X#if __STDC__
Xxel
Xpnm_whitexel( xelval maxval, int format )
X#else /*__STDC__*/
Xxel
Xpnm_whitexel( maxval, format )
X    xelval maxval;
X    int format;
X#endif /*__STDC__*/
X    {
X    xel x;
X
X    switch ( PNM_FORMAT_TYPE(format) )
X	{
X	case PPM_TYPE:
X	PPM_ASSIGN( x, maxval, maxval, maxval );
X	break;
X
X	case PGM_TYPE:
X	PNM_ASSIGN1( x, maxval );
X	break;
X
X	case PBM_TYPE:
X	PNM_ASSIGN1( x, pnm_pbmmaxval );
X	break;
X
X	default:
X	pm_error( "can't happen" );
X	}
X
X    return x;
X    }
X
X#if __STDC__
Xxel
Xpnm_blackxel( xelval maxval, int format )
X#else /*__STDC__*/
Xxel
Xpnm_blackxel( maxval, format )
X    xelval maxval;
X    int format;
X#endif /*__STDC__*/
X    {
X    xel x;
X
X    switch ( PNM_FORMAT_TYPE(format) )
X	{
X	case PPM_TYPE:
X	PPM_ASSIGN( x, 0, 0, 0 );
X	break;
X
X	case PGM_TYPE:
X	PNM_ASSIGN1( x, (xelval) 0 );
X	break;
X
X	case PBM_TYPE:
X	PNM_ASSIGN1( x, (xelval) 0 );
X	break;
X
X	default:
X	pm_error( "can't happen" );
X	}
X
X    return x;
X    }
X
X#if __STDC__
Xvoid
Xpnm_invertxel( xel* xP, xelval maxval, int format )
X#else /*__STDC__*/
Xvoid
Xpnm_invertxel( xP, maxval, format )
X    xel* xP;
X    xelval maxval;
X    int format;
X#endif /*__STDC__*/
X    {
X    switch ( PNM_FORMAT_TYPE(format) )
X	{
X	case PPM_TYPE:
X	PPM_ASSIGN(
X	    *xP, maxval - PPM_GETR( *xP ),
X	    maxval - PPM_GETG( *xP ), maxval - PPM_GETB( *xP ) );
X	break;
X
X	case PGM_TYPE:
X	PNM_ASSIGN1( *xP, (gray) maxval - (gray) PNM_GET1( *xP ) );
X	break;
X
X	case PBM_TYPE:
X	PNM_ASSIGN1( *xP, ( PNM_GET1( *xP ) == 0 ) ? pnm_pbmmaxval : 0 );
X	break;
X
X	default:
X	pm_error( "can't happen" );
X	}
X    }
X
X#if __STDC__
Xvoid
Xpnm_promoteformat( xel** xels, int cols, int rows, xelval maxval, int format, xelval newmaxval, int newformat )
X#else /*__STDC__*/
Xvoid
Xpnm_promoteformat( xels, cols, rows, maxval, format, newmaxval, newformat )
X    xel** xels;
X    xelval maxval, newmaxval;
X    int cols, rows, format, newformat;
X#endif /*__STDC__*/
X    {
X    int row;
X
X    for ( row = 0; row < rows; ++row )
X	pnm_promoteformatrow(
X	    xels[row], cols, maxval, format, newmaxval, newformat );
X    }
X
X#if __STDC__
Xvoid
Xpnm_promoteformatrow( xel* xelrow, int cols, xelval maxval, int format, xelval newmaxval, int newformat )
X#else /*__STDC__*/
Xvoid
Xpnm_promoteformatrow( xelrow, cols, maxval, format, newmaxval, newformat )
X    xel* xelrow;
X    xelval maxval, newmaxval;
X    int cols, format, newformat;
X#endif /*__STDC__*/
X    {
X    register int col;
X    register xel* xP;
X
X    if ( ( PNM_FORMAT_TYPE(format) == PPM_TYPE &&
X	   ( PNM_FORMAT_TYPE(newformat) == PGM_TYPE ||
X	     PNM_FORMAT_TYPE(newformat) == PBM_TYPE ) ) ||
X	 ( PNM_FORMAT_TYPE(format) == PGM_TYPE &&
X	   PNM_FORMAT_TYPE(newformat) == PBM_TYPE ) )
X	pm_error( "pnm_promoteformatrow: can't promote downwards!" );
X
X    /* Are we promoting to the same type? */
X    if ( PNM_FORMAT_TYPE(format) == PNM_FORMAT_TYPE(newformat) )
X	{
X	if ( PNM_FORMAT_TYPE(format) == PBM_TYPE )
X	    return;
X	if ( newmaxval < maxval )
X	    pm_error(
X	   "pnm_promoteformatrow: can't decrease maxval - try using pnmdepth" );
X	if ( newmaxval == maxval )
X	    return;
X	/* Increase maxval. */
X	switch ( PNM_FORMAT_TYPE(format) )
X	    {
X	    case PGM_TYPE:
X	    for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
X		PNM_ASSIGN1(
X		    *xP, (int) PNM_GET1(*xP) * newmaxval / maxval );
X	    break;
X
X	    case PPM_TYPE:
X	    for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
X		PPM_DEPTH( *xP, *xP, maxval, newmaxval );
X	    break;
X
X	    default:
X	    pm_error( "shouldn't happen" );
X	    }
X	return;
X	}
X
X    /* We must be promoting to a higher type. */
X    switch ( PNM_FORMAT_TYPE(format) )
X	{
X	case PBM_TYPE:
X	switch ( PNM_FORMAT_TYPE(newformat) )
X	    {
X	    case PGM_TYPE:
X	    for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
X		if ( PNM_GET1(*xP) == 0 )
X		    PNM_ASSIGN1( *xP, 0 );
X		else
X		    PNM_ASSIGN1( *xP, newmaxval );
X	    break;
X
X	    case PPM_TYPE:
X	    for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
X		if ( PNM_GET1(*xP) == 0 )
X		    PPM_ASSIGN( *xP, 0, 0, 0 );
X		else
X		    PPM_ASSIGN( *xP, newmaxval, newmaxval, newmaxval );
X	    break;
X
X	    default:
X	    pm_error( "can't happen" );
X	    }
X	break;
X
X	case PGM_TYPE:
X	switch ( PNM_FORMAT_TYPE(newformat) )
X	    {
X	    case PPM_TYPE:
X	    if ( newmaxval < maxval )
X		pm_error(
X	   "pnm_promoteformatrow: can't decrease maxval - try using pnmdepth" );
X	    if ( newmaxval == maxval )
X		{
X		for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
X		    PPM_ASSIGN(
X			*xP, PNM_GET1(*xP), PNM_GET1(*xP), PNM_GET1(*xP) );
X		}
X	    else
X		{ /* Increase maxval. */
X		for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
X		    PPM_ASSIGN(
X			*xP, (int) PNM_GET1(*xP) * newmaxval / maxval,
X			(int) PNM_GET1(*xP) * newmaxval / maxval,
X			(int) PNM_GET1(*xP) * newmaxval / maxval );
X		}
X	    break;
X
X	    default:
X	    pm_error( "can't happen" );
X	    }
X	break;
X
X	default:
X	pm_error( "can't happen" );
X	}
X    }
SHAR_EOF
if test 8773 -ne "`wc -c < 'pnm/libpnm3.c'`"
then
	echo shar: error transmitting "'pnm/libpnm3.c'" '(should have been 8773 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/libpnm4.c'" '(10085 characters)'
if test -f 'pnm/libpnm4.c'
then
	echo shar: will not over-write existing file "'pnm/libpnm4.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/libpnm4.c'
X/* libpnm4.c - pnm utility library part 4
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 "pnm.h"
X#include "rast.h"
X
X/*
X** Semi-work-alike versions of some Sun pixrect routines.  Just enough
X** for rasterfile reading and writing to work.
X*/
X
Xstruct pixrect*
Xmem_create( w, h, depth )
X    int w, h, depth;
X    {
X    struct pixrect* p;
X    struct mpr_data* m;
X
X    p = (struct pixrect*) malloc( sizeof(struct pixrect) );
X    if ( p == NULL )
X	return NULL;
X    p->pr_ops = NULL;
X    p->pr_size.x = w;
X    p->pr_size.y = h;
X    p->pr_depth = depth;
X    m = p->pr_data = (struct mpr_data*) malloc( sizeof(struct mpr_data) );
X    if ( m == NULL )
X	{
X	free( p );
X	return NULL;
X	}
X    /* According to the documentation, linebytes is supposed to be rounded
X    ** up to a longword (except on 386 boxes).  However, this turns out
X    ** not to be the case.  In reality, all of Sun's code rounds up to
X    ** a short, not a long.
X    */
X    m->md_linebytes = ( w * depth + 15 ) / 16 * 2;
X    m->md_offset.x = 0;
X    m->md_offset.y = 0;
X    m->md_flags = 0;
X    m->md_image = (unsigned char*) malloc( m->md_linebytes * h );
X    if ( m->md_image == NULL )
X	{
X	free( m );
X	free( p );
X	return NULL;
X	}
X
X    return p;
X    }
X
Xvoid
Xmem_free( p )
X    struct pixrect* p;
X    {
X    free( p->pr_data->md_image );
X    free( p->pr_data );
X    free( p );
X    }
X
Xint
Xpr_dump( p, out, colormap, type, copy_flag )
X    struct pixrect* p;
X    FILE* out;
X    colormap_t* colormap;
X    int type, copy_flag;
X    {
X    struct rasterfile h;
X    int size, besize, count;
X    unsigned char* beimage;
X    unsigned char* bp;
X    unsigned char c, pc;
X    int i, j;
X
X    h.ras_magic = RAS_MAGIC;
X    h.ras_width = p->pr_size.x;
X    h.ras_height = p->pr_size.y;
X    h.ras_depth = p->pr_depth;
X
X    h.ras_type = type;
X    switch ( type )
X	{
X	case RT_OLD:
X	pm_error( "old rasterfile type is not supported" );
X
X	case RT_FORMAT_TIFF:
X	pm_error( "tiff rasterfile type is not supported" );
X
X	case RT_FORMAT_IFF:
X	pm_error( "iff rasterfile type is not supported" );
X
X	case RT_EXPERIMENTAL:
X	pm_error( "experimental rasterfile type is not supported" );
X
X	case RT_STANDARD:
X	case RT_FORMAT_RGB:
X	/* Ignore hP->ras_length. */
X	h.ras_length = p->pr_size.y * p->pr_data->md_linebytes;
X	break;
X
X	case RT_BYTE_ENCODED:
X	size = p->pr_size.y * p->pr_data->md_linebytes;
X	bp = p->pr_data->md_image;
X	beimage = (unsigned char*) malloc( size * 3 / 2 );	/* worst case */
X	if ( beimage == NULL )
X	    return PIX_ERR;
X	besize = 0;
X	count = 0;
X	for ( i = 0; i < size; ++i )
X	    {
X	    c = *bp++;
X	    if ( count > 0 )
X		{
X		if ( pc != c )
X		    {
X		    if ( count == 1 && pc == 128 )
X			{
X			beimage[besize++] = 128;
X			beimage[besize++] = 0;
X			count = 0;
X			}
X		    else if ( count > 2 || pc == 128 )
X			{
X			beimage[besize++] = 128;
X			beimage[besize++] = count - 1;
X			beimage[besize++] = pc;
X			count = 0;
X			}
X		    else
X			{
X			for ( j = 0; j < count; ++j )
X			    beimage[besize++] = pc;
X			count = 0;
X			}
X		    }
X		}
X	    pc = c;
X	    ++count;
X	    if ( count == 256 )
X		{
X		beimage[besize++] = 128;
X		beimage[besize++] = count - 1;
X		beimage[besize++] = c;
X		count = 0;
X		}
X	    }
X	if ( count > 0 )
X	    {
X	    if ( count == 1 && c == 128 )
X		{
X		beimage[besize++] = 128;
X		beimage[besize++] = 0;
X		}
X	    if ( count > 2 || c == 128 )
X		{
X		beimage[besize++] = 128;
X		beimage[besize++] = count - 1;
X		beimage[besize++] = c;
X		}
X	    else
X		{
X		for ( j = 0; j < count; ++j )
X		    beimage[besize++] = c;
X		}
X	    }
X	h.ras_length = besize;
X	break;
X
X	default:
X	pm_error( "unknown rasterfile type" );
X	}
X
X    if ( colormap == NULL )
X	{
X	h.ras_maptype = RMT_NONE;
X	h.ras_maplength = 0;
X	}
X    else
X	{
X	h.ras_maptype = colormap->type;
X	switch ( colormap->type )
X	    {
X	    case RMT_EQUAL_RGB:
X	    h.ras_maplength = colormap->length * 3;
X	    break;
X
X	    case RMT_RAW:
X	    h.ras_maplength = colormap->length;
X	    break;
X
X	    default:
X	    pm_error( "unknown colormap type" );
X	    }
X	}
X
X    if ( pm_writebiglong( out, h.ras_magic ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_width ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_height ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_depth ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_length ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_type ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_maptype ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_maplength ) == -1 )
X	return PIX_ERR;
X
X    if ( colormap != NULL )
X	{
X	switch ( colormap->type )
X	    {
X	    case RMT_EQUAL_RGB:
X	    if ( fwrite( colormap->map[0], 1, colormap->length, out ) !=
X		 colormap->length )
X		return PIX_ERR;
X	    if ( fwrite( colormap->map[1], 1, colormap->length, out ) !=
X		 colormap->length )
X		return PIX_ERR;
X	    if ( fwrite( colormap->map[2], 1, colormap->length, out ) !=
X		 colormap->length )
X		return PIX_ERR;
X	    break;
X
X	    case RMT_RAW:
X	    if ( fwrite( colormap->map[0], 1, colormap->length, out ) !=
X		 colormap->length )
X		return PIX_ERR;
X	    break;
X	    }
X	}
X
X    switch ( type )
X	{
X	case RT_STANDARD:
X	case RT_FORMAT_RGB:
X	if ( fwrite( p->pr_data->md_image, 1, h.ras_length, out ) !=
X	     h.ras_length )
X	    return PIX_ERR;
X	break;
X
X	case RT_BYTE_ENCODED:
X	if ( fwrite( beimage, 1, besize, out ) != besize )
X	    {
X	    free( beimage );
X	    return PIX_ERR;
X	    }
X	free( beimage );
X	break;
X	}
X
X    return 0;
X    }
X
Xint
Xpr_load_header( in, hP )
X    FILE* in;
X    struct rasterfile* hP;
X    {
X    if ( pm_readbiglong( in, &(hP->ras_magic) ) == -1 )
X	return PIX_ERR;
X    if ( hP->ras_magic != RAS_MAGIC )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_width) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_height) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_depth) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_length) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_type) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_maptype) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_maplength) ) == -1 )
X	return PIX_ERR;
X    return 0;
X    }
X
Xint
Xpr_load_colormap( in, hP, colormap )
X    FILE* in;
X    struct rasterfile* hP;
X    colormap_t* colormap;
X    {
X    if ( colormap == NULL || hP->ras_maptype == RMT_NONE )
X	{
X	int i;
X
X	for ( i = 0; i < hP->ras_maplength; ++i )
X	    if ( getc( in ) == EOF )
X		return PIX_ERR;
X	}
X    else
X	{
X	colormap->type = hP->ras_maptype;
X	switch ( hP->ras_maptype )
X	    {
X	    case RMT_EQUAL_RGB:
X	    colormap->length = hP->ras_maplength / 3;
X	    colormap->map[0] = (unsigned char*) malloc( colormap->length );
X	    if ( colormap->map[0] == NULL )
X		return PIX_ERR;
X	    colormap->map[1] = (unsigned char*) malloc( colormap->length );
X	    if ( colormap->map[1] == NULL )
X		{
X		free( colormap->map[0] );
X		return PIX_ERR;
X		}
X	    colormap->map[2] = (unsigned char*) malloc( colormap->length );
X	    if ( colormap->map[2] == NULL )
X		{
X		free( colormap->map[0] );
X		free( colormap->map[1] );
X		return PIX_ERR;
X		}
X	    if ( fread( colormap->map[0], 1, colormap->length, in ) != colormap->length ||
X	         fread( colormap->map[1], 1, colormap->length, in ) != colormap->length ||
X	         fread( colormap->map[2], 1, colormap->length, in ) != colormap->length )
X		{
X		free( colormap->map[0] );
X		free( colormap->map[1] );
X		free( colormap->map[2] );
X		return PIX_ERR;
X		}
X	    break;
X
X	    case RMT_RAW:
X	    colormap->length = hP->ras_maplength;
X	    colormap->map[0] = (unsigned char*) malloc( colormap->length );
X	    if ( colormap->map[0] == NULL )
X		return PIX_ERR;
X	    colormap->map[2] = colormap->map[1] = colormap->map[0];
X	    if ( fread( colormap->map[0], 1, hP->ras_maplength, in ) != hP->ras_maplength )
X		{
X		free( colormap->map[0] );
X		return PIX_ERR;
X		}
X	    break;
X
X	    default:
X	    pm_error( "unknown colormap type" );
X	    }
X	}
X    return 0;
X    }
X
Xstruct pixrect*
Xpr_load_image( in, hP, colormap )
X    FILE* in;
X    struct rasterfile* hP;
X    colormap_t* colormap;
X    {
X    struct pixrect* p;
X    unsigned char* beimage;
X    register unsigned char* bep;
X    register unsigned char* bp;
X    register unsigned char c;
X    int i;
X    register int j, count;
X
X    p = mem_create( hP->ras_width, hP->ras_height, hP->ras_depth );
X    if ( p == NULL )
X	return NULL;
X
X    switch ( hP->ras_type )
X	{
X	case RT_OLD:
X	pm_error( "old rasterfile type is not supported" );
X
X	case RT_FORMAT_TIFF:
X	pm_error( "tiff rasterfile type is not supported" );
X
X	case RT_FORMAT_IFF:
X	pm_error( "iff rasterfile type is not supported" );
X
X	case RT_EXPERIMENTAL:
X	pm_error( "experimental rasterfile type is not supported" );
X
X	case RT_STANDARD:
X	case RT_FORMAT_RGB:
X	/* Ignore hP->ras_length. */
X	i = p->pr_size.y * p->pr_data->md_linebytes;
X	if ( fread( p->pr_data->md_image, 1, i, in ) != i )
X	    {
X	    mem_free( p );
X	    return NULL;
X	    }
X	break;
X
X	case RT_BYTE_ENCODED:
X	beimage = (unsigned char*) malloc( hP->ras_length );
X	if ( beimage == NULL )
X	    {
X	    mem_free( p );
X	    return NULL;
X	    }
X	if ( fread( beimage, 1, hP->ras_length, in ) != hP->ras_length )
X	    {
X	    mem_free( p );
X	    free( beimage );
X	    return NULL;
X	    }
X	bep = beimage;
X	bp = p->pr_data->md_image;
X	for ( i = 0; i < hP->ras_length; )
X	    {
X	    c = *bep++;
X	    if ( c == 128 )
X		{
X		count = ( *bep++ ) + 1;
X		if ( count == 1 )
X		    {
X		    *bp++ = 128;
X		    i += 2;
X		    }
X		else
X		    {
X		    c = *bep++;
X		    for ( j = 0; j < count; ++j )
X			*bp++ = c;
X		    i += 3;
X		    }
X		}
X	    else
X		{
X		*bp++ = c;
X		++i;
X		}
X	    }
X	free( beimage );
X	break;
X
X	default:
X	pm_error( "unknown rasterfile type" );
X	}
X
X    return p;
X    }
SHAR_EOF
if test 10085 -ne "`wc -c < 'pnm/libpnm4.c'`"
then
	echo shar: error transmitting "'pnm/libpnm4.c'" '(should have been 10085 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/pnmcat.c'" '(6415 characters)'
if test -f 'pnm/pnmcat.c'
then
	echo shar: will not over-write existing file "'pnm/pnmcat.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/pnmcat.c'
X/* pnmcat.c - concatenate portable anymaps
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
X#include "pnm.h"
X
Xvoid
Xmain( argc, argv )
X    int argc;
X    char* argv[];
X    {
X    FILE** ifp;
X    register xel* newxelrow;
X    xel** xelrow;
X    xel* background;
X    xelval* maxval;
X    xelval newmaxval;
X    int argn, backdefault, backblack, lrflag, tbflag, justify, nfiles;
X    int* rows;
X    int* cols;
X    int* format;
X    int newformat;
X    int i, row;
X    register int col;
X    int newrows, newcols, new;
X    char* usage = "[-white|-black] -leftright|-lr [-jtop|-jbottom] pnmfile ...\n               [-white|-black] -topbottom|-tb [-jleft|-jright] pnmfile ...";
X
X    pnm_init( &argc, argv );
X
X    argn = 1;
X    backdefault = 1;
X    lrflag = tbflag = 0;
X    justify = 0;
X
X    /* Check for flags. */
X    while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' )
X	{
X	if ( pm_keymatch( argv[argn], "-white", 2 ) )
X	    {
X	    backdefault = 0;
X	    backblack = 0;
X	    }
X	else if ( pm_keymatch( argv[argn], "-black", 2 ) )
X	    {
X	    backdefault = 0;
X	    backblack = 1;
X	    }
X	else if ( pm_keymatch( argv[argn], "-lr", 2 ) ||
X	          pm_keymatch( argv[argn], "-leftright", 2 ) )
X	    lrflag = 1;
X	else if ( pm_keymatch( argv[argn], "-tb", 2 ) ||
X	          pm_keymatch( argv[argn], "-topbottom", 2 ) )
X	    tbflag = 1;
X	else if ( pm_keymatch( argv[argn], "-jtop", 3 ) )
X	    justify = -1;
X	else if ( pm_keymatch( argv[argn], "-jbottom", 3 ) )
X	    justify = 1;
X	else if ( pm_keymatch( argv[argn], "-jleft", 3 ) )
X	    justify = -1;
X	else if ( pm_keymatch( argv[argn], "-jright", 3 ) )
X	    justify = 1;
X	else if ( pm_keymatch( argv[argn], "-jcenter", 3 ) )
X	    justify = 0;
X	else
X	    pm_usage( usage );
X	++argn;
X	}
X
X    if ( lrflag && tbflag )
X	pm_error( "only one of -lr and -tb may be specified" );
X    if ( ! ( lrflag || tbflag ) )
X	pm_error( "one of -lr or -tb must be specified" );
X
X    if ( argn < argc )
X	nfiles = argc - argn;
X    else
X	nfiles = 1;
X    ifp = (FILE**) malloc( nfiles * sizeof(FILE*) );
X    xelrow = (xel**) malloc( nfiles * sizeof(xel*) );
X    background = (xel*) malloc( nfiles * sizeof(xel) );
X    maxval = (xelval*) malloc( nfiles * sizeof(xelval) );
X    rows = (int*) malloc( nfiles * sizeof(int) );
X    cols = (int*) malloc( nfiles * sizeof(int) );
X    format = (int*) malloc( nfiles * sizeof(int) );
X    if ( ifp == (FILE**) 0 || xelrow == (xel**) 0 || background == (xel*) 0 ||
X	 maxval == (xelval*) 0 || rows == (int*) 0 || cols == (int*) 0 ||
X	 format == (int*) 0 )
X	pm_error( "out of memory" );
X    if ( argn < argc )
X	{
X	for ( i = 0; i < nfiles; ++i )
X	    ifp[i] = pm_openr( argv[argn+i] );
X	}
X    else
X	ifp[0] = stdin;
X
X    newcols = 0;
X    newrows = 0;
X    for ( i = 0; i < nfiles; ++i )
X	{
X	pnm_readpnminit( ifp[i], &cols[i], &rows[i], &maxval[i], &format[i] );
X	if ( i == 0 )
X	    {
X	    newmaxval = maxval[i];
X	    newformat = format[i];
X	    }
X	else
X	    {
X	    if ( PNM_FORMAT_TYPE(format[i]) > PNM_FORMAT_TYPE(newformat) )
X		newformat = format[i];
X	    if ( maxval[i] > newmaxval )
X		newmaxval = maxval[i];
X	    }
X	xelrow[i] = pnm_allocrow( cols[i] );
X	if ( lrflag )
X	    {
X	    newcols += cols[i];
X	    if ( rows[i] > newrows )
X		newrows = rows[i];
X	    }
X	else
X	    {
X	    newrows += rows[i];
X	    if ( cols[i] > newcols )
X		newcols = cols[i];
X	    }
X	}
X    for ( i = 0; i < nfiles; ++i )
X	{
X	/* Read first row just to get a good guess at the background. */
X	pnm_readpnmrow( ifp[i], xelrow[i], cols[i], maxval[i], format[i] );
X	pnm_promoteformatrow(
X	    xelrow[i], cols[i], maxval[i], format[i], newmaxval, newformat );
X	if (  backdefault )
X	    background[i] =
X		pnm_backgroundxelrow(
X		    xelrow[i], cols[i], newmaxval, newformat );
X	else
X	    if ( backblack )
X		background[i] = pnm_blackxel( newmaxval, newformat );
X	    else
X		background[i] = pnm_whitexel( newmaxval, newformat );
X	}
X
X    newxelrow = pnm_allocrow( newcols );
X
X    pnm_writepnminit( stdout, newcols, newrows, newmaxval, newformat, 0 );
X
X    if ( lrflag )
X	{
X	for ( row = 0; row < newrows; ++row )
X	    {
X	    new = 0;
X	    for ( i = 0; i < nfiles; ++i )
X		{
X		int padtop;
X
X		if ( justify == -1 )
X		    padtop = 0;
X		else if ( justify == 1 )
X		    padtop = newrows - rows[i];
X		else
X		    padtop = ( newrows - rows[i] ) / 2;
X		if ( row < padtop || row >= padtop + rows[i] )
X		    {
X		    for ( col = 0; col < cols[i]; ++col )
X			newxelrow[new+col] = background[i];
X		    }
X		else
X		    {
X		    if ( row != padtop )	/* first row already read */
X			{
X			pnm_readpnmrow(
X			    ifp[i], xelrow[i], cols[i], maxval[i], format[i] );
X			pnm_promoteformatrow(
X			    xelrow[i], cols[i], maxval[i], format[i],
X			    newmaxval, newformat );
X			}
X		    for ( col = 0; col < cols[i]; ++col )
X			newxelrow[new+col] = xelrow[i][col];
X		    }
X		new += cols[i];
X		}
X	    pnm_writepnmrow( stdout, newxelrow, newcols, newmaxval, newformat, 0 );
X	    }
X	}
X    else
X	{
X	int padleft;
X
X	new = 0;
X	i = 0;
X	if ( justify == -1 )
X	    padleft = 0;
X	else if ( justify == 1 )
X	    padleft = newcols - cols[i];
X	else
X	    padleft = ( newcols - cols[i] ) / 2;
X
X	for ( row = 0; row < newrows; ++row )
X	    {
X	    if ( row - new >= rows[i] )
X		{
X		new += rows[i];
X		++i;
X		if ( i >= nfiles )
X		    pm_error( "shouldn't happen" );
X		if ( justify == -1 )
X		    padleft = 0;
X		else if ( justify == 1 )
X		    padleft = newcols - cols[i];
X		else
X		    padleft = ( newcols - cols[i] ) / 2;
X		}
X	    if ( row - new > 0 )
X		{
X		pnm_readpnmrow(
X		    ifp[i], xelrow[i], cols[i], maxval[i], format[i] );
X		pnm_promoteformatrow(
X		    xelrow[i], cols[i], maxval[i], format[i],
X		    newmaxval, newformat );
X		}
X	    for ( col = 0; col < padleft; ++col )
X		newxelrow[col] = background[i];
X	    for ( col = 0; col < cols[i]; ++col )
X		newxelrow[padleft+col] = xelrow[i][col];
X	    for ( col = padleft + cols[i]; col < newcols; ++col )
X		newxelrow[col] = background[i];
X	    pnm_writepnmrow( stdout, newxelrow, newcols, newmaxval, newformat, 0 );
X	    }
X	}
X
X    for ( i = 0; i < nfiles; ++i )
X	pm_close( ifp[i] );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 6415 -ne "`wc -c < 'pnm/pnmcat.c'`"
then
	echo shar: error transmitting "'pnm/pnmcat.c'" '(should have been 6415 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/pnmcat.1'" '(1534 characters)'
if test -f 'pnm/pnmcat.1'
then
	echo shar: will not over-write existing file "'pnm/pnmcat.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/pnmcat.1'
X.TH pnmcat 1 "12 March 1989"
X.IX pnmcat
X.SH NAME
Xpnmcat - concatenate portable anymaps
X.SH SYNOPSIS
X.B pnmcat
X.RB [ -white | -black ]
X.BR -leftright | -lr
X.RB [ -jtop | -jbottom ]
X.I pnmfile pnmfile
X.RI ...
X.br
X.B pnmcat
X.RB [ -white | -black ]
X.BR -topbottom | -tb
X.RB [ -jleft | -jright ]
X.I pnmfile pnmfile
X.RI ...
X.SH DESCRIPTION
XReads portable anymaps as input.
XConcatenates them either left to right or top to bottom, and produces a
Xportable anymap as output.
X.IX concatenation
X.SH OPTIONS
X.PP
XIf the anymaps are not all the same height (left-right) or width (top-bottom),
Xthe smaller ones have to be justified with the largest.
XBy default, they get centered, but you can specify one side or the other
Xwith one of the -j* flags.
XSo,
X.B -topbottom -jleft
Xwould stack the anymaps on top of each other, flush with the left edge.
X.PP
XThe
X.B -white
Xand
X.B -black
Xflags specify what color to use to fill in the extra space
Xwhen doing this justification.
XIf neither is specified, the program makes a guess.
X.PP
XAll flags can be abbreviated to their shortest unique prefix.
X.SH "SEE ALSO"
Xpnm(5)
X.SH AUTHOR
XCopyright (C) 1989 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 1534 -ne "`wc -c < 'pnm/pnmcat.1'`"
then
	echo shar: error transmitting "'pnm/pnmcat.1'" '(should have been 1534 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/x11wd.h'" '(1878 characters)'
if test -f 'pnm/x11wd.h'
then
	echo shar: will not over-write existing file "'pnm/x11wd.h'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/x11wd.h'
X/* x11wd.h - the following defs are taken from various X.V11R2 header files
X*/
X
X#ifndef _X11WD_H_
X#define _X11WD_H_
X
X#define LSBFirst	0
X#define MSBFirst	1
X
X#define XYBitmap	0
X#define XYPixmap	1
X#define ZPixmap		2
X
X#define StaticGray	0
X#define GrayScale	1
X#define StaticColor	2
X#define PseudoColor	3
X#define TrueColor	4
X#define DirectColor	5
X
Xtypedef unsigned long xwdval;
X#define X11WD_FILE_VERSION 7
Xtypedef struct {
X    xwdval header_size;		/* Size of the entire file header (bytes). */
X    xwdval file_version;	/* X11WD_FILE_VERSION */
X    xwdval pixmap_format;	/* Pixmap format */
X    xwdval pixmap_depth;	/* Pixmap depth */
X    xwdval pixmap_width;	/* Pixmap width */
X    xwdval pixmap_height;	/* Pixmap height */
X    xwdval xoffset;		/* Bitmap x offset */
X    xwdval byte_order;		/* MSBFirst, LSBFirst */
X    xwdval bitmap_unit;		/* Bitmap unit */
X    xwdval bitmap_bit_order;	/* MSBFirst, LSBFirst */
X    xwdval bitmap_pad;		/* Bitmap scanline pad */
X    xwdval bits_per_pixel;	/* Bits per pixel */
X    xwdval bytes_per_line;	/* Bytes per scanline */
X    xwdval visual_class;	/* Class of colormap */
X    xwdval red_mask;		/* Z red mask */
X    xwdval green_mask;		/* Z green mask */
X    xwdval blue_mask;		/* Z blue mask */
X    xwdval bits_per_rgb;	/* Log base 2 of distinct color values */
X    xwdval colormap_entries;	/* Number of entries in colormap */
X    xwdval ncolors;		/* Number of Color structures */
X    xwdval window_width;	/* Window width */
X    xwdval window_height;	/* Window height */
X    long window_x;		/* Window upper left X coordinate */
X    long window_y;		/* Window upper left Y coordinate */
X    xwdval window_bdrwidth;	/* Window border width */
X    } X11WDFileHeader;
X
Xtypedef struct {
X    unsigned long num;
X    unsigned short red, green, blue;
X    char flags;			/* do_red, do_green, do_blue */
X    char pad;
X    } X11XColor;
X
X#endif /*_X11WD_H_*/
SHAR_EOF
if test 1878 -ne "`wc -c < 'pnm/x11wd.h'`"
then
	echo shar: error transmitting "'pnm/x11wd.h'" '(should have been 1878 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.
