PBMPLUS, part 17 of 18

Jef Poskanzer pokey at well.UUCP
Thu Sep 14 21:26:23 AEST 1989


#! /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/Makefile
#	pnm/Imakefile
#	pnm/pnm.5
#	pnm/libpnm1.c
#	pnm/libpnm2.c
#	pnm/libpnm3.c
#	pnm/pnm.h
#	pnm/pnmcat.c
#	pnm/pnmcat.1
#	pnm/pnmcrop.c
#	pnm/pnmcrop.1
#	pnm/pnmcut.c
#	pnm/pnmcut.1
#	pnm/pnmenlarge.c
#	pnm/pnmenlarge.1
# This archive created: Thu Sep 14 03:43:53 1989
# By:	Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
export PATH; PATH=/bin:$PATH
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/Makefile'" '(3632 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 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 -fstrength-reduce -fcombine-regs
X# CFLAGS =	-O
XCFLAGS =	-g
X# CFLAGS =	
X# LDFLAGS =	-s
XLDFLAGS =	
XINSTALLBINARIES =	/usr/new/pbm
XINSTALLMANUALS =	n
X
X# CONFIGURE: You can compile PNM without PPM.  If you don't want PPM,
X# comment out the next five lines.  This will make the PNM programs use
X# less memory.
XPPMOPT =	-DPPM
XPPMDIR =	../ppm
XINCLUDEPPM =	-I$(PPMDIR)
XLIBPPM =	$(PPMDIR)/libppm.a
XDEFPPM =	$(PPMDIR)/ppm.h ../pbmplus.h
XDEFLIBPPM =	$(PPMDIR)/libppm.h
X
X# CONFIGURE: Likewise here: if you don't have PGM, comment these lines out.
XPGMOPT =	-DPGM
XPGMDIR =	../pgm
XINCLUDEPGM =	-I$(PGMDIR)
XLIBPGM =	$(PGMDIR)/libpgm.a
XDEFPGM =	$(PGMDIR)/pgm.h
XDEFLIBPGM =	$(PGMDIR)/libpgm.h
X
X# PBM is required, don't comment these lines out.
XPBMOPT =	-DPBM
XPBMDIR =	../pbm
XINCLUDEPBM =	-I$(PBMDIR)
XLIBPBM =	$(PBMDIR)/libpbm.a
XDEFPBM =	$(PBMDIR)/pbm.h
XDEFLIBPBM =	$(PBMDIR)/libpbm.h
X
XINCLUDE =	$(INCLUDEPPM) $(INCLUDEPGM) $(INCLUDEPBM)
XALLCFLAGS =	$(CFLAGS) $(PPMOPT) $(PGMOPT) $(PBMOPT) $(INCLUDE)
XLIBPNM =	libpnm.a
X
XPORTBINARIES =	pnmcat pnmcrop pnmcut pnmenlarge pnmflip pnminvert pnmpaste \
X		pnmtile
X
XPORTMANUALS =	pnm.5 pnmcat.1 pnmcrop.1 pnmcut.1 pnmenlarge.1 pnmflip.1 \
X		pnminvert.1 pnmpaste.1 pnmtile.1
X
XBINARIES =	$(PORTBINARIES)
X
Xall:		binaries
Xinstall:	installbinaries
X
Xbinaries:	$(BINARIES)
X
Xinstallbinaries:	binaries
X	cp $(BINARIES) $(INSTALLBINARIES)
X
Xinstallmanuals:
X	cp $(PORTMANUALS) /usr/man/man$(INSTALLMANUALS)
X
X# Rule for plain programs.
X$(PORTBINARIES):	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) $(LIBPNM) \
X			$(LIBPPM) $(LIBPGM) $(LIBPBM)
X	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM)
X
X# And library.
X$(LIBPNM):	libpnm1.o libpnm2.o libpnm3.o
X	-rm $(LIBPNM)
X	ar rc $(LIBPNM) libpnm1.o libpnm2.o libpnm3.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
X
X# Other dependencies.
Xpnmcat:		pnmcat.c
Xpnmcrop:	pnmcrop.c
Xpnmcut:		pnmcut.c
Xpnmenlarge:	pnmenlarge.c
Xpnmflip:	pnmflip.c
Xpnminvert:	pnminvert.c
Xpnmpaste:	pnmpaste.c
Xpnmtile:	pnmtile.c
X
Xclean:
X	-rm -f *.o *.a *.cat core $(BINARIES)
X
X
X# Imakefile stuff.  Ignore if you're not an X11 type.
X
X            TOP = ../../../../../../usr/src/new/X11
X
X             RM = rm -f
X             MV = mv
X        UTILSRC = $(TOP)/util
X       IMAKESRC = $(UTILSRC)/imake
X       IRULESRC = $(UTILSRC)/imake.includes
X          IMAKE = $(IMAKESRC)/imake
X  IMAKE_DEFINES =
X      IMAKE_CMD = $(NEWTOP)$(IMAKE) -TImake.tmpl -I$(NEWTOP)$(IRULESRC) \
X			-s Makefile $(IMAKE_DEFINES)
XMakefile: Imakefile \
X	$(IRULESRC)/Imake.tmpl \
X	$(IRULESRC)/Imake.rules \
X	$(IRULESRC)/site.def \
X	$(IRULESRC)/$(MACROFILE)
X	- at if [ -f Makefile ]; then \
X	echo "$(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
X	$(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
X	else exit 0; fi
X	$(IMAKE_CMD) -DTOPDIR=$(TOP)
X
XMakefiles:
SHAR_EOF
if test 3632 -ne "`wc -c < 'pnm/Makefile'`"
then
	echo shar: error transmitting "'pnm/Makefile'" '(should have been 3632 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/Imakefile'" '(2423 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 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# CONFIGURE: You can compile PNM without PPM.  If you don't want PPM,
X# comment out the next five lines.  This will make the PNM programs use
X# less memory.
XPPMOPT =	-DPPM
XPPMDIR =	../ppm
XINCLUDEPPM =	-I$(PPMDIR)
XLIBPPM =	$(PPMDIR)/libppm.a
XDEFPPM =	$(PPMDIR)/ppm.h ../pbmplus.h
XDEFLIBPPM =	$(PPMDIR)/libppm.h
X
X# CONFIGURE: Likewise here: if you don't have PGM, comment these lines out.
XPGMOPT =	-DPGM
XPGMDIR =	../pgm
XINCLUDEPGM =	-I$(PGMDIR)
XLIBPGM =	$(PGMDIR)/libpgm.a
XDEFPGM =	$(PGMDIR)/pgm.h
XDEFLIBPGM =	$(PGMDIR)/libpgm.h
X
X# PBM is required, don't comment these lines out.
XPBMOPT =	-DPBM
XPBMDIR =	../pbm
XINCLUDEPBM =	-I$(PBMDIR)
XLIBPBM =	$(PBMDIR)/libpbm.a
XDEFPBM =	$(PBMDIR)/pbm.h
XDEFLIBPBM =	$(PBMDIR)/libpbm.h
X
XINCLUDE =	$(INCLUDEPPM) $(INCLUDEPGM) $(INCLUDEPBM)
XALLCFLAGS =	$(CFLAGS) $(PPMOPT) $(PGMOPT) $(PBMOPT) $(INCLUDE)
XLIBPNM =	libpnm.a
X
XPORTBINARIES =	pnmcat pnmcrop pnmcut pnmenlarge pnmflip pnminvert pnmpaste \
X		pnmtile
X
XPORTMANUALS =	pnm.5 pnmcat.1 pnmcrop.1 pnmcut.1 pnmenlarge.1 pnmflip.1 \
X		pnminvert.1 pnmpaste.1 pnmtile.1
X
XBINARIES =	$(PORTBINARIES)
X
Xall:		binaries
Xinstall:	installbinaries
X
Xbinaries:	$(BINARIES)
X
Xinstallbinaries:	binaries
X	cp $(BINARIES) $(INSTALLBINARIES)
X
Xinstallmanuals:
X	cp $(PORTMANUALS) /usr/man/man$(INSTALLMANUALS)
X
X# Rule for plain programs.
X$(PORTBINARIES):	pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) $(LIBPNM) \
X			$(LIBPPM) $(LIBPGM) $(LIBPBM)
X	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM)
X
X# And library.
X$(LIBPNM):	libpnm1.o libpnm2.o libpnm3.o
X	-rm $(LIBPNM)
X	ar rc $(LIBPNM) libpnm1.o libpnm2.o libpnm3.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
SHAR_EOF
if test 2423 -ne "`wc -c < 'pnm/Imakefile'`"
then
	echo shar: error transmitting "'pnm/Imakefile'" '(should have been 2423 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'" '(820 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 "08 August 1989"
X.SH NAME
Xpnm - portable anymap file format
X.SH DESCRIPTION
XThe pnm programs operate on portable bitmaps, graymaps, and pixmaps,
Xproduced by the PBM, PGM, and PPM toolkits.
XThere is no file format associated with pnm itself.
X.SH "SEE ALSO"
Xpnmcatlr(1), pnmcattb(1), pnmcrop(1), pnmcut(1), pnmenlarge(1), pnmflip(1),
Xpnminvert(1), pnmpaste(1), pnmtile(1)
Xppm(5), pgm(5), pbm(5)
X.SH AUTHOR
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 820 -ne "`wc -c < 'pnm/pnm.5'`"
then
	echo shar: error transmitting "'pnm/pnm.5'" '(should have been 820 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'" '(2882 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 <stdio.h>
X#include "pnm.h"
X
X#ifdef PPM
X#include "ppm.h"
X#include "libppm.h"
X#endif PPM
X
X#ifdef PGM
X#include "pgm.h"
X#include "libpgm.h"
Xstatic gray *grayrow;
X#endif PGM
X
X#ifdef PBM
X#include "pbm.h"
X#include "libpbm.h"
Xstatic bit *bitrow;
X#endif PBM
X
Xvoid
Xpnm_readpnminit( file, colsP, rowsP, maxvalP, formatP )
XFILE *file;
Xint *colsP, *rowsP, *formatP;
Xxelval *maxvalP;
X    {
X#ifdef PGM
X    gray gmaxval;
X#endif PGM
X
X    /* Check magic number. */
X    *formatP = pbm_readmagicnumber( file );
X    switch ( *formatP )
X	{
X#ifdef PPM
X	case PPM_FORMAT:
X	case RPPM_FORMAT:
X	ppm_readppminitrest( file, colsP, rowsP, maxvalP );
X	break;
X#endif PPM
X
X#ifdef PGM
X	case PGM_FORMAT:
X	case RPGM_FORMAT:
X	pgm_readpgminitrest( file, colsP, rowsP, &gmaxval );
X	*maxvalP = (xelval) gmaxval;
X	grayrow = pgm_allocrow( *colsP );
X	break;
X#endif PGM
X
X#ifdef PBM
X	case PBM_FORMAT:
X	case RPBM_FORMAT:
X	pbm_readpbminitrest( file, colsP, rowsP );
X	bitrow = pbm_allocrow( *colsP );
X	break;
X#endif PVM
X
X	default:
X	pm_error( "bad magic number - not a ppm, pgm, or pbm file", 0,0,0,0,0 );
X	}
X    }
X
Xvoid
Xpnm_readpnmrow( file, xelrow, cols, maxval, format )
XFILE *file;
Xxel *xelrow;
Xxelval maxval;
Xint cols, format;
X    {
X    register int col;
X    register xel *xP;
X#ifdef PGM
X    register gray *gP;
X#endif PGM
X#ifdef PBM
X    register bit *bP;
X#endif PBM
X
X    switch ( format )
X	{
X#ifdef PPM
X	case PPM_FORMAT:
X	case RPPM_FORMAT:
X	ppm_readppmrow( file, (pixel *) xelrow, cols, (pixval) maxval, format );
X	break;
X#endif PPM
X
X#ifdef PGM
X	case PGM_FORMAT:
X	case RPGM_FORMAT:
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	break;
X#endif PGM
X
X#ifdef PBM
X	case PBM_FORMAT:
X	case RPBM_FORMAT:
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 );
X	break;
X#endif PBM
X
X	default:
X	pm_error( "can't happen", 0,0,0,0,0 );
X	}
X    }
X
Xxel **
Xpnm_readpnm( file, colsP, rowsP, maxvalP, formatP )
XFILE *file;
Xint *colsP, *rowsP, *formatP;
Xxelval *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 2882 -ne "`wc -c < 'pnm/libpnm1.c'`"
then
	echo shar: error transmitting "'pnm/libpnm1.c'" '(should have been 2882 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'" '(2575 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 <stdio.h>
X#include "pnm.h"
X
X#ifdef PPM
X#include "ppm.h"
X#include "libppm.h"
X#endif PPM
X
X#ifdef PGM
X#include "pgm.h"
X#include "libpgm.h"
Xstatic gray *grayrow;
X#endif PGM
X
X#ifdef PBM
X#include "pbm.h"
X#include "libpbm.h"
Xstatic bit *bitrow;
X#endif PBM
X
Xvoid
Xpnm_writepnminit( file, cols, rows, maxval, format )
XFILE *file;
Xint cols, rows, format;
Xxelval maxval;
X    {
X    switch ( format )
X	{
X#ifdef PPM
X	case PPM_FORMAT:
X	case RPPM_FORMAT:
X	ppm_writeppminit( file, cols, rows, (pixval) maxval );
X	break;
X#endif PPM
X
X#ifdef PGM
X	case PGM_FORMAT:
X	case RPGM_FORMAT:
X	pgm_writepgminit( file, cols, rows, (gray) maxval );
X	grayrow = pgm_allocrow( cols );
X	break;
X#endif PGM
X
X#ifdef PBM
X	case PBM_FORMAT:
X	case RPBM_FORMAT:
X	pbm_writepbminit( file, cols, rows );
X	bitrow = pbm_allocrow( cols );
X	break;
X#endif PBM
X
X	default:
X	pm_error( "can't happen", 0,0,0,0,0 );
X	}
X    }
X
Xvoid
Xpnm_writepnmrow( file, xelrow, cols, maxval, format )
XFILE *file;
Xxel *xelrow;
Xxelval maxval;
Xint cols, format;
X    {
X    register int col;
X    register xel *xP;
X#ifdef PGM
X    register gray *gP;
X#endif PGM
X#ifdef PBM
X    register bit *bP;
X#endif PBM
X
X    switch ( format )
X	{
X#ifdef PPM
X	case PPM_FORMAT:
X	case RPPM_FORMAT:
X	ppm_writeppmrow( file, (pixel *) xelrow, cols, (pixval) maxval );
X	break;
X#endif PPM
X
X#ifdef PGM
X	case PGM_FORMAT:
X	case RPGM_FORMAT:
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 );
X	break;
X#endif PGM
X
X#ifdef PBM
X	case PBM_FORMAT:
X	case RPBM_FORMAT:
X	for ( col = 0, bP = bitrow, xP = xelrow; col < cols; col++, bP++, xP++ )
X	    *bP = PNM_GET1( *xP );
X	pbm_writepbmrow( file, bitrow, cols );
X	break;
X#endif PBM
X
X	default:
X	pm_error( "can't happen", 0,0,0,0,0 );
X	}
X    }
X
Xvoid
Xpnm_writepnm( file, xels, cols, rows, maxval, format )
XFILE *file;
Xxel **xels;
Xxelval maxval;
Xint cols, rows, format;
X    {
X    int row;
X
X    pnm_writepnminit( file, cols, rows, maxval, format );
X
X    for ( row = 0; row < rows; row++ )
X	pnm_writepnmrow( file, xels[row], cols, maxval, format );
X    }
SHAR_EOF
if test 2575 -ne "`wc -c < 'pnm/libpnm2.c'`"
then
	echo shar: error transmitting "'pnm/libpnm2.c'" '(should have been 2575 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'" '(8709 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 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include "pnm.h"
X
X#ifdef PPM
X#include "ppm.h"
X#include "libppm.h"
X#endif PPM
X
X#ifdef PGM
X#include "pgm.h"
X#include "libpgm.h"
X#endif PGM
X
X#ifdef PBM
X#include "pbm.h"
X#include "libpbm.h"
X#endif PBM
X
Xxel
Xpnm_backgroundxel( xels, cols, rows, maxval, format )
Xxel **xels;
Xxelval maxval;
Xint cols, rows, format;
X    {
X    xel bgxel, ul, ur, ll, lr;
X#ifdef PGM
X    gray gul, gur, gll, glr;
X#endif PGM
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( ul,  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 ( format )
X	    {
X#ifdef PPM
X	    case PPM_FORMAT:
X	    case RPPM_FORMAT:
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#endif PPM
X
X#ifdef PGM
X	    case PGM_FORMAT:
X	    case RPGM_FORMAT:
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#endif PGM
X
X#ifdef PBM
X	    case PBM_FORMAT:
X	    case RPBM_FORMAT:
X	    pm_error(
X		"pnm_backgroundxel: four bits no two of which equal each other??",
X		0,0,0,0,0 );
X#endif PBM
X
X	    default:
X	    pm_error( "can't happen", 0,0,0,0,0 );
X	    }
X	}
X
X    return bgxel;
X    }
X
Xxel
Xpnm_whitexel( maxval, format )
Xxelval maxval;
Xint format;
X    {
X    xel x;
X
X    switch ( format )
X	{
X#ifdef PPM
X	case PPM_FORMAT:
X	case RPPM_FORMAT:
X	PPM_ASSIGN( x, maxval, maxval, maxval );
X	break;
X#endif PPM
X
X#ifdef PGM
X	case PGM_FORMAT:
X	case RPGM_FORMAT:
X	PNM_ASSIGN1( x, maxval );
X	break;
X#endif PGM
X
X#ifdef PBM
X	case PBM_FORMAT:
X	case RPBM_FORMAT:
X	PNM_ASSIGN1( x, (xelval) PBM_WHITE );
X	break;
X#endif PBM
X
X	default:
X	pm_error( "can't happen", 0,0,0,0,0 );
X	}
X
X    return x;
X    }
X
Xxel
Xpnm_blackxel( maxval, format )
Xxelval maxval;
Xint format;
X    {
X    xel x;
X
X    switch ( format )
X	{
X#ifdef PPM
X	case PPM_FORMAT:
X	case RPPM_FORMAT:
X	PPM_ASSIGN( x, 0, 0, 0 );
X	break;
X#endif PPM
X
X#ifdef PGM
X	case PGM_FORMAT:
X	case RPGM_FORMAT:
X	PNM_ASSIGN1( x, (xelval) 0 );
X	break;
X#endif PGM
X
X#ifdef PBM
X	case PBM_FORMAT:
X	case RPBM_FORMAT:
X	PNM_ASSIGN1( x, (xelval) PBM_BLACK );
X	break;
X#endif PBM
X
X	default:
X	pm_error( "can't happen", 0,0,0,0,0 );
X	}
X
X    return x;
X    }
X
Xxel
Xpnm_invertxel( x, maxval, format )
Xxel x;
Xxelval maxval;
Xint format;
X    {
X    switch ( format )
X	{
X#ifdef PPM
X	case PPM_FORMAT:
X	case RPPM_FORMAT:
X	PPM_ASSIGN(
X	    x, maxval - PPM_GETR( x ),
X	    maxval - PPM_GETG( x ), maxval - PPM_GETB( x ) );
X	break;
X#endif PPM
X
X#ifdef PGM
X	case PGM_FORMAT:
X	case RPGM_FORMAT:
X	PNM_ASSIGN1( x, (gray) maxval - (gray) PNM_GET1( x ) );
X	break;
X#endif PGM
X
X#ifdef PBM
X	case PBM_FORMAT:
X	case RPBM_FORMAT:
X	PNM_ASSIGN1(
X	    x, ( (bit) PNM_GET1( x ) == PBM_WHITE ) ? PBM_BLACK : PBM_WHITE );
X	break;
X#endif PBM
X
X	default:
X	pm_error( "can't happen", 0,0,0,0,0 );
X	}
X    return x;
X    }
X
Xvoid
Xpnm_promoteformat( xels, cols, rows, maxval, format, newmaxval, newformat )
Xxel **xels;
Xxelval maxval, newmaxval;
Xint cols, rows, format, newformat;
X    {
X    int row;
X    register int col;
X    register xel *xP;
X
X#ifdef PPM
X    if ( ( ( format == PPM_FORMAT || format == RPPM_FORMAT ) &&
X	   ( newformat == PGM_FORMAT || newformat == RPGM_FORMAT ||
X	     newformat == PBM_FORMAT || newformat == RPBM_FORMAT ) ) ||
X	 ( ( format == PGM_FORMAT || format == RPGM_FORMAT ) &&
X	   ( newformat == PBM_FORMAT || newformat == RPBM_FORMAT ) ) )
X	pm_error( "pnm_promoteformat: can't promote downwards!", 0,0,0,0,0 );
X#else PPM
X# ifdef PGM
X    if ( ( ( format == PGM_FORMAT || format == RPGM_FORMAT ) &&
X	   ( newformat == PBM_FORMAT || newformat == RPBM_FORMAT ) ) )
X	pm_error( "pnm_promoteformat: can't promote downwards!", 0,0,0,0,0 );
X# else PGM
X#  ifdef PBM
X    /* If only PBM is defined, we can just return. */
X    return;
X#  endif PBM
X# endif PGM
X#endif PPM
X
X#ifdef PPM
X    if ( ( ( format == PPM_FORMAT || format == RPPM_FORMAT ) &&
X           ( newformat == PPM_FORMAT || newformat == RPPM_FORMAT ) ) ||
X         ( ( format == PGM_FORMAT || format == RPGM_FORMAT ) &&
X           ( newformat == PGM_FORMAT || newformat == RPGM_FORMAT ) ) ||
X         ( ( format == PBM_FORMAT || format == RPBM_FORMAT ) &&
X           ( newformat == PBM_FORMAT || newformat == RPBM_FORMAT ) ) )
X#else PPM
X# ifdef PGM
X    if ( ( ( format == PGM_FORMAT || format == RPGM_FORMAT ) &&
X           ( newformat == PGM_FORMAT || newformat == RPGM_FORMAT ) ) ||
X         ( ( format == PBM_FORMAT || format == RPBM_FORMAT ) &&
X           ( newformat == PBM_FORMAT || newformat == RPBM_FORMAT ) ) )
X# else PGM
X#  ifdef PBM
X    if ( ( ( format == PBM_FORMAT || format == RPBM_FORMAT ) &&
X           ( newformat == PBM_FORMAT || newformat == RPBM_FORMAT ) ) )
X#  endif PBM
X# endif PGM
X#endif PPM
X	{
X#ifdef PBM
X	if ( format == PBM_FORMAT || format == RPBM_FORMAT )
X	    return;
X#endif PBM
X	if ( newmaxval < maxval )
X	    pm_error(
X		"pnm_promoteformat: can't decrease maxval -- try using ppmcscale",
X		0,0,0,0,0 );
X	if ( newmaxval == maxval )
X	    return;
X	/* Increase maxval. */
X	switch ( format )
X	    {
X#ifdef PGM
X	    case PGM_FORMAT:
X	    case RPGM_FORMAT:
X	    for ( row = 0; row < rows; row++ )
X		for ( col = 0, xP = xels[row]; col < cols; col++, xP++ )
X		    PNM_ASSIGN1(
X			*xP, (int) PNM_GET1(*xP) * newmaxval / maxval );
X	    break;
X#endif PGM
X
X#ifdef PPM
X	    case PPM_FORMAT:
X	    case RPPM_FORMAT:
X	    for ( row = 0; row < rows; row++ )
X		for ( col = 0, xP = xels[row]; col < cols; col++, xP++ )
X		    PPM_CSCALE( *xP, *xP, maxval, newmaxval );
X	    break;
X#endif PPM
X
X	    default:
X	    pm_error( "shouldn't happen", 0,0,0,0,0 );
X	    }
X	return;
X	}
X
X    switch ( format )
X	{
X#ifdef PBM
X	case PBM_FORMAT:
X	case RPBM_FORMAT:
X	switch ( newformat )
X	    {
X#ifdef PGM
X	    case PGM_FORMAT:
X	    case RPGM_FORMAT:
X	    for ( row = 0; row < rows; row++ )
X		for ( col = 0, xP = xels[row]; col < cols; col++, xP++ )
X		    PNM_ASSIGN1(
X			*xP, ( PNM_GET1(*xP) == PBM_WHITE ) ? newmaxval : (xelval) 0 );
X	    break;
X#endif PGM
X
X#ifdef PPM
X	    case PPM_FORMAT:
X	    case RPPM_FORMAT:
X	    for ( row = 0; row < rows; row++ )
X		for ( col = 0, xP = xels[row]; col < cols; col++, xP++ )
X		    if ( PNM_GET1(*xP) == PBM_WHITE )
X			PPM_ASSIGN( *xP, newmaxval, newmaxval, newmaxval );
X		    else
X			PPM_ASSIGN( *xP, 0, 0, 0 );
X	    break;
X#endif PPM
X
X	    default:
X	    pm_error( "can't happen", 0,0,0,0,0 );
X	    }
X	break;
X#endif PBM
X
X#ifdef PGM
X	case PGM_FORMAT:
X	case RPGM_FORMAT:
X	switch ( newformat )
X	    {
X#ifdef PPM
X	    case PPM_FORMAT:
X	    case RPPM_FORMAT:
X	    if ( newmaxval < maxval )
X		pm_error(
X		    "pnm_promoteformat: can't decrease maxval -- try using ppmcscale",
X		    0,0,0,0,0 );
X	    if ( newmaxval == maxval )
X		{
X		for ( row = 0; row < rows; row++ )
X		    for ( col = 0, xP = xels[row]; 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 ( row = 0; row < rows; row++ )
X		    for ( col = 0, xP = xels[row]; 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#endif PPM
X
X	    default:
X	    pm_error( "can't happen", 0,0,0,0,0 );
X	    }
X	break;
X#endif PGM
X
X	default:
X	pm_error( "can't happen", 0,0,0,0,0 );
X	}
X    }
SHAR_EOF
if test 8709 -ne "`wc -c < 'pnm/libpnm3.c'`"
then
	echo shar: error transmitting "'pnm/libpnm3.c'" '(should have been 8709 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.h'" '(1948 characters)'
if test -f 'pnm/pnm.h'
then
	echo shar: will not over-write existing file "'pnm/pnm.h'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/pnm.h'
X/* pnm.h - header file for libpnm portable anymap library
X*/
X
X#ifndef _PNM_H_
X#define _PNM_H_
X
X#ifdef PPM
X
X#include "ppm.h"
Xtypedef pixel xel;
Xtypedef pixval xelval;
X
X#define PNM_GET1(p) PPM_GETB(p)
X#define PNM_ASSIGN1(p,v) PPM_ASSIGN(p,0,0,v)
X#define PNM_EQUAL(p,q) PPM_EQUAL(p,q)
X
X#else PPM
X# ifdef PGM
X
X#include "pgm.h"
Xtypedef gray xel;
Xtypedef gray xelval;
X#define PNM_GET1(p) (p)
X#define PNM_ASSIGN1(p,v) (p) = (v)
X#define PNM_EQUAL(p,q) ( (p) == (q) )
X
X# else PGM
X#  ifdef PBM
X
X#include "pbm.h"
Xtypedef bit xel;
Xtypedef bit xelval;
X#define PNM_GET1(p) (p)
X#define PNM_ASSIGN1(p,v) (p) = (v)
X#define PNM_EQUAL(p,q) ( (p) == (q) )
X
X#  endif PBM
X# endif PGM
X#endif PPM
X
X/* Declarations of routines. */
X
X#define pnm_allocarray( cols, rows ) ((xel **) pm_allocarray( cols, rows, sizeof(xel) ))
X#define pnm_allocrow( cols ) ((xel *) pm_allocrow( cols, sizeof(xel) ))
X#define pnm_freearray( xelrow, rows ) pm_freearray( xelrow, rows )
X#define pnm_freerow( xelrow ) pm_freerow( xelrow )
X
Xxel **pnm_readpnm( /* FILE *file, int *colsP, int *rowsP, xelval *maxvalP, int *formatP */ );
Xvoid pnm_readpnminit( /* FILE *file, int *colsP, int *rowsP, xelval *maxvalP, int *formatP */ );
Xvoid pnm_readpnmrow( /* FILE *file, xel *xelrow, int cols, xelval maxval, int format */ );
X
Xvoid pnm_writepnm( /* FILE *file, xel **xels, int cols, int rows, xelval maxval, int format */ );
Xvoid pnm_writepnminit( /* FILE *file, int cols, int rows, xelval maxval, int format */ );
Xvoid pnm_writepnmrow( /* FILE *file, xel *xelrow, int cols, xelval maxval, int format */ );
X
Xxel pnm_backgroundxel( /* xel **xels, int cols, int rows, xelval maxval, int format */ );
Xxel pnm_whitexel( /* xelval maxval, int format */ );
Xxel pnm_blackxel( /* xelval maxval, int format */ );
Xxel pnm_invertxel( /* xel x, xelval maxval, int format */ );
Xvoid pnm_promoteformat( /* xel **xels, int cols, int rows, xelval maxval, int format, xelval newmaxval, int newformat */ );
X
X#endif _PNM_H_
SHAR_EOF
if test 1948 -ne "`wc -c < 'pnm/pnm.h'`"
then
	echo shar: error transmitting "'pnm/pnm.h'" '(should have been 1948 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'" '(4262 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/* pnmcatlr.c - concatenate portable anymaps left to right
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 <stdio.h>
X#ifdef	SYSV
X#include <string.h>
X#else	SYSV
X#include <strings.h>
X#endif	SYSV
X#include "pnm.h"
X
X#define MAXFILES 100
X#define max(a,b) ((a) > (b) ? (a) : (b))
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd[MAXFILES];
X    xel **xels[MAXFILES], background;
X    register xel **newxels;
X    xelval maxval[MAXFILES], newmaxval;
X    int argn, backdefault, backblack, lrflag, tbflag, nfiles, i;
X    int rows[MAXFILES], cols[MAXFILES], format[MAXFILES], newformat, row, col;
X    int newrows, newcols, new, pad;
X    char *usage = "[-white|-black] pnmfile pnmfile ...";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X    backdefault = 1;
X    lrflag = tbflag = 0;
X
X    /* Check for flags. */
X    while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' )
X	{
X	if ( strncmp(argv[argn],"-white",max(strlen(argv[argn]),2)) == 0 )
X	    {
X	    backdefault = 0;
X	    backblack = 0;
X	    }
X	else if ( strncmp(argv[argn],"-black",max(strlen(argv[argn]),2)) == 0 )
X	    {
X	    backdefault = 0;
X	    backblack = 1;
X	    }
X	else if ( strncmp(argv[argn],"-lr",max(strlen(argv[argn]),2)) == 0 ||
X	          strncmp(argv[argn],"-leftright",max(strlen(argv[argn]),2)) == 0 )
X	    lrflag = 1;
X	else if ( strncmp(argv[argn],"-tb",max(strlen(argv[argn]),2)) == 0 ||
X	          strncmp(argv[argn],"-topbottom",max(strlen(argv[argn]),2)) == 0 )
X	    tbflag = 1;
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", 0,0,0,0,0 );
X    if ( ! ( lrflag || tbflag ) )
X	pm_error( "one of -lr or -tb must be specified", 0,0,0,0,0 );
X
X    if ( argn < argc )
X	{
X	nfiles = argc - argn;
X	for ( i = 0; i < nfiles; i++ )
X	    ifd[i] = pm_openr( argv[argn+i] );
X	}
X    else
X	{
X	nfiles = 1;
X	ifd[0] = stdin;
X	}
X
X    newcols = 0;
X    newrows = 0;
X    for ( i = 0; i < nfiles; i++ )
X	{
X	xels[i] =
X	    pnm_readpnm( ifd[i], &cols[i], &rows[i], &maxval[i], &format[i] );
X	pm_close( ifd[i] );
X	if ( i == 0 )
X	    {
X	    newmaxval = maxval[i];
X	    newformat = format[i];
X	    }
X	else if ( format[i] > newformat )
X	    {
X	    newmaxval = maxval[i];
X	    newformat = format[i];
X	    }
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
X    for ( i = 0; i < nfiles; i++ )
X	pnm_promoteformat(
X	    xels[i], cols[i], rows[i], maxval[i], format[i], newmaxval,
X	    newformat );
X
X    if ( ! backdefault )
X	if ( backblack )
X	    background = pnm_blackxel( newmaxval, newformat );
X	else
X	    background = pnm_whitexel( newmaxval, newformat );
X
X    newxels = pnm_allocarray( newcols, newrows );
X
X    new = 0;
X
X    for ( i = 0; i < nfiles; i++ )
X	{
X	if ( backdefault )
X	    background =
X		pnm_backgroundxel(
X		    xels[i], cols[i], rows[i], newmaxval, newformat );
X
X	if ( lrflag )
X	    {
X	    pad = (newrows - rows[i]) / 2;
X	    for ( col = 0; col < cols[i]; col++ )
X		{
X		for ( row = 0; row < pad; row++ )
X		    newxels[row][new+col] = background;
X		for ( row = 0; row < rows[i]; row++ )
X		    newxels[pad+row][new+col] = xels[i][row][col];
X		for ( row = pad+rows[i]; row < newrows; row++ )
X		    newxels[row][new+col] = background;
X		}
X
X	    new += cols[i];
X	    }
X	else
X	    {
X	    pad = (newcols - cols[i]) / 2;
X	    for ( row = 0; row < rows[i]; row++ )
X		{
X		for ( col = 0; col < pad; col++ )
X		    newxels[new+row][col] = background;
X		for ( col = 0; col < cols[i]; col++ )
X		    newxels[new+row][pad+col] = xels[i][row][col];
X		for ( col = pad+cols[i]; col < newcols; col++ )
X		    newxels[new+row][col] = background;
X		}
X
X	    new += rows[i];
X	    }
X
X	}
X
X    pnm_writepnm( stdout, newxels, newcols, newrows, newmaxval, newformat );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 4262 -ne "`wc -c < 'pnm/pnmcat.c'`"
then
	echo shar: error transmitting "'pnm/pnmcat.c'" '(should have been 4262 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'" '(1073 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.SH NAME
Xpnmcat - concatenate portable anymaps
X.SH SYNOPSIS
Xpnmcat [-white|-black] -leftright|-lr|-topbottom|-tb pnmfile pnmfile ...
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.
XIf the anymaps are not all the same height (left-right) or width (top-bottom),
Xthe smaller ones are centered with the edges filled in.
XThe -white and -black flags specify what color to use for this fill -- if
Xneither 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
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 1073 -ne "`wc -c < 'pnm/pnmcat.1'`"
then
	echo shar: error transmitting "'pnm/pnmcat.1'" '(should have been 1073 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/pnmcrop.c'" '(3820 characters)'
if test -f 'pnm/pnmcrop.c'
then
	echo shar: will not over-write existing file "'pnm/pnmcrop.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/pnmcrop.c'
X/* pnmcrop.c - crop a portable anymap
X**
X** Copyright (C) 1988 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#ifdef	SYSV
X#include <string.h>
X#else	SYSV
X#include <strings.h>
X#endif	SYSV
X#include "pnm.h"
X
X#define max(a,b) ((a) > (b) ? (a) : (b))
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register xel **xels, *newxelrow, *xP, *nxP;
X    xel background;
X    xelval maxval;
X    int argn, format, backdefault, backblack;
X    int rows, cols, row, col, newrows, newcols;
X    int top, bottom, left, right;
X    char *usage = "[-white|-black] [pnmfile]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X    backdefault = 1;
X
X    /* Check for flags. */
X    if ( argn < argc && argv[argn][0] == '-' )
X	{
X	if ( strncmp(argv[argn],"-white",max(strlen(argv[argn]),2)) == 0 )
X	    {
X	    backdefault = 0;
X	    backblack = 0;
X	    }
X	else if ( strncmp(argv[argn],"-black",max(strlen(argv[argn]),2)) == 0 )
X	    {
X	    backdefault = 0;
X	    backblack = 1;
X	    }
X	else
X	    pm_usage( usage );
X	argn++;
X	}
X
X    if ( argn != argc )
X	{
X	ifd = pm_openr( argv[argn] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X    xels = pnm_readpnm( ifd, &cols, &rows, &maxval, &format );
X    pm_close( ifd );
X
X    if ( backdefault )
X	background = pnm_backgroundxel( xels, cols, rows, maxval, format );
X    else
X	if ( backblack )
X	    background = pnm_blackxel( maxval, format );
X	else
X	    background = pnm_whitexel( maxval, format );
X
X    /* Find first non-background line. */
X    for ( top = 0; top < rows; top++ )
X	for ( col = 0, xP = xels[top]; col < cols; col++, xP++ )
X	    if ( ! PNM_EQUAL( *xP, background ) )
X		goto gottop;
Xgottop:
X
X    /* Find last non-background line. */
X    for ( bottom = rows - 1; bottom >= top; bottom-- )
X	for ( col = 0, xP = xels[bottom]; col < cols; col++, xP++ )
X	    if ( ! PNM_EQUAL( *xP, background ) )
X		goto gotbottom;
Xgotbottom:
X
X    /* Find first non-background column.  To avoid massive paging on
X    ** large anymaps, we use a different loop than the above two cases. */
X    left = cols - 1;
X    for ( row = top; row <= bottom; row++ )
X	{
X	int thisleft;
X
X	for ( thisleft = 0; thisleft < left; thisleft++ )
X	    if ( ! PNM_EQUAL( xels[row][thisleft], background ) )
X		{
X		left = thisleft;
X		break;
X		}
X	}
X
X    /* Find last non-background column.  Again, use row-major loop. */
X    right = left + 1;
X    for ( row = top; row <= bottom; row++ )
X	{
X	int thisright;
X
X	for ( thisright = cols - 1; thisright > right; thisright-- )
X	    if ( ! PNM_EQUAL( xels[row][thisright], background ) )
X		{
X		right = thisright;
X		break;
X		}
X	}
X
X    if ( top > 0 )
X	fprintf( stderr, "(cropping %d rows off the top)\n", top );
X    if ( bottom < rows - 1 )
X	fprintf( stderr, "(cropping %d rows off the bottom)\n", rows - 1 - bottom );
X    if ( left > 0 )
X	fprintf( stderr, "(cropping %d cols off the left)\n", left );
X    if ( right < cols - 1 )
X	fprintf( stderr, "(cropping %d cols off the right)\n", cols - 1 - right );
X
X    /* Now write out the new anymap. */
X    newcols = right - left + 1;
X    newrows = bottom - top + 1;
X    pnm_writepnminit( stdout, newcols, newrows, maxval, format );
X    newxelrow = pnm_allocrow( newcols );
X    for ( row = top; row <= bottom; row++ )
X	{
X        for ( col = left, xP = &(xels[row][left]), nxP = newxelrow; col <= right; col++, xP++, nxP++ )
X	    *nxP = *xP;
X	pnm_writepnmrow( stdout, newxelrow, newcols, maxval, format );
X	}
X
X    exit( 0 );
X    }
SHAR_EOF
if test 3820 -ne "`wc -c < 'pnm/pnmcrop.c'`"
then
	echo shar: error transmitting "'pnm/pnmcrop.c'" '(should have been 3820 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/pnmcrop.1'" '(903 characters)'
if test -f 'pnm/pnmcrop.1'
then
	echo shar: will not over-write existing file "'pnm/pnmcrop.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/pnmcrop.1'
X.TH pnmcrop 1 "25 February 1989"
X.SH NAME
Xpnmcrop - crop a portable anymap
X.SH SYNOPSIS
Xpnmcrop [-white|-black] [pnmfile]
X.SH DESCRIPTION
XReads a portable anymap as input.
XRemoves edges that are the background color,
Xand produces a portable anymap as output.
XBy default, it makes a guess as to what the background
Xcolor is.
XYou can override the default with the -white and -black flags.
X.PP
XAll flags can be abbreviated to their shortest unique prefix.
X.SH "SEE ALSO"
Xpnmcut(1), pnm(5)
X.SH AUTHOR
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 903 -ne "`wc -c < 'pnm/pnmcrop.1'`"
then
	echo shar: error transmitting "'pnm/pnmcrop.1'" '(should have been 903 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/pnmcut.c'" '(2247 characters)'
if test -f 'pnm/pnmcut.c'
then
	echo shar: will not over-write existing file "'pnm/pnmcut.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/pnmcut.c'
X/* pnmcut.c - cut a rectangle out of a portable anymap
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 <stdio.h>
X#include "pnm.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register xel *xelrow;
X    xelval maxval;
X    int rows, cols, format, x, y, width, height, row;
X    char *usage = "x y width height [pnmfile]";
X
X    pm_progname = argv[0];
X
X    if ( argc < 5 || argc > 6 )
X	pm_usage( usage );
X
X    if ( sscanf( argv[1], "%d", &x ) != 1 )
X	pm_usage( usage );
X    if ( sscanf( argv[2], "%d", &y ) != 1 )
X	pm_usage( usage );
X    if ( sscanf( argv[3], "%d", &width ) != 1 )
X	pm_usage( usage );
X    if ( sscanf( argv[4], "%d", &height ) != 1 )
X	pm_usage( usage );
X
X    if ( x < 0 )
X	pm_error( "x is less than 0", 0,0,0,0,0 );
X    if ( y < 0 )
X	pm_error( "y is less than 0", 0,0,0,0,0 );
X    if ( width < 1 )
X	pm_error( "width is less than 1", 0,0,0,0,0 );
X    if ( height < 1 )
X	pm_error( "height is less than 1", 0,0,0,0,0 );
X
X    if ( argc == 6 )
X	ifd = pm_openr( argv[5] );
X    else
X	ifd = stdin;
X
X    pnm_readpnminit( ifd, &cols, &rows, &maxval, &format );
X    xelrow = pnm_allocrow( cols );
X
X    if ( x >= cols )
X	pm_error(
X	    "x is too large -- the anymap has only %d cols", cols, 0,0,0,0 );
X    if ( y >= rows )
X	pm_error(
X	    "y is too large -- the anymap has only %d rows", rows, 0,0,0,0 );
X    if ( x + width > cols )
X	pm_error(
X	    "x + width is too large by %d xels", x + width - cols, 0,0,0,0 );
X    if ( y + height > rows )
X	pm_error(
X	    "y + height is too large by %d xels", y + height - rows, 0,0,0,0 );
X
X    pnm_writepnminit( stdout, width, height, maxval, format );
X    for ( row = 0; row < y + height; row++ )
X	{
X	pnm_readpnmrow( ifd, xelrow, cols, maxval, format );
X	if ( row >= y )
X	    pnm_writepnmrow( stdout, &(xelrow[x]), width, maxval, format );
X	}
X
X    pm_close( ifd );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 2247 -ne "`wc -c < 'pnm/pnmcut.c'`"
then
	echo shar: error transmitting "'pnm/pnmcut.c'" '(should have been 2247 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/pnmcut.1'" '(703 characters)'
if test -f 'pnm/pnmcut.1'
then
	echo shar: will not over-write existing file "'pnm/pnmcut.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/pnmcut.1'
X.TH pnmcut 1 "21 February 1989"
X.SH NAME
Xpnmcut - cut a rectangle out of a portable anymap
X.SH SYNOPSIS
Xpnmcut x y width height [pnmfile]
X.SH DESCRIPTION
XReads a portable anymap as input.
XExtracts the specified rectangle,
Xand produces a portable anymap as output.
X.SH "SEE ALSO"
Xpnm(5)
X.SH AUTHOR
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 703 -ne "`wc -c < 'pnm/pnmcut.1'`"
then
	echo shar: error transmitting "'pnm/pnmcut.1'" '(should have been 703 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/pnmenlarge.c'" '(1760 characters)'
if test -f 'pnm/pnmenlarge.c'
then
	echo shar: will not over-write existing file "'pnm/pnmenlarge.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/pnmenlarge.c'
X/* pnmenlarge.c - read a portable anymap and enlarge it N times
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 <stdio.h>
X#include "pnm.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register xel *xelrow, *newxelrow, *xP;
X    int argn, n, rows, cols, format, row, col, subrow, subcol;
X    xelval maxval;
X    char *usage = "N [pnmfile]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X
X    if ( argn == argc )
X	pm_usage( usage );
X    if ( sscanf( argv[argn], "%d", &n ) != 1 )
X	pm_usage( usage );
X    if ( n < 2 )
X	pm_error( "N must be greater than 1", 0,0,0,0,0 );
X    argn++;
X
X    if ( argn != argc )
X	{
X	ifd = pm_openr( argv[argn] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X    pnm_readpnminit( ifd, &cols, &rows, &maxval, &format );
X    xelrow = pnm_allocrow( cols );
X    pnm_writepnminit( stdout, cols * n, rows * n, maxval, format );
X    newxelrow = pnm_allocrow( cols * n );
X
X    for ( row = 0; row < rows; row++ )
X	{
X	pnm_readpnmrow( ifd, xelrow, cols, maxval, format );
X	for ( subrow = 0; subrow < n; subrow++ )
X	    {
X	    for ( col = 0, xP = xelrow; col < cols; col++, xP++ )
X		{
X		for ( subcol = 0; subcol < n; subcol++ )
X		    newxelrow[col * n + subcol] = *xP;
X		}
X	    pnm_writepnmrow( stdout, newxelrow, cols * n, maxval, format );
X	    }
X	}
X
X    pm_close( ifd );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 1760 -ne "`wc -c < 'pnm/pnmenlarge.c'`"
then
	echo shar: error transmitting "'pnm/pnmenlarge.c'" '(should have been 1760 characters)'
fi
fi # end of overwriting check
if test ! -d 'pnm'
then
	echo shar: creating directory "'pnm'"
	mkdir 'pnm'
fi
echo shar: extracting "'pnm/pnmenlarge.1'" '(929 characters)'
if test -f 'pnm/pnmenlarge.1'
then
	echo shar: will not over-write existing file "'pnm/pnmenlarge.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pnm/pnmenlarge.1'
X.TH pnmenlarge 1 "26 February 1989"
X.SH NAME
Xpnmenlarge - read a portable anymap and enlarge it N times
X.SH SYNOPSIS
Xpnmenlarge N [pnmfile]
X.SH DESCRIPTION
XReads a portable anymap as input.
XReplicates its pixels N times, and produces a portable anymap as output.
X.PP
Xpnmenlarge can only enlarge by integer factors.
XThe slower but more general ppmscale can enlarge or reduce by arbitrary
Xfactors, and pbmreduce can reduce by integer factors, but only for
Xbitmaps.
X.SH "SEE ALSO"
Xpbmreduce(1), ppmscale(1), pnm(5)
X.SH AUTHOR
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 929 -ne "`wc -c < 'pnm/pnmenlarge.1'`"
then
	echo shar: error transmitting "'pnm/pnmenlarge.1'" '(should have been 929 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0



More information about the Alt.sources mailing list