From: burns@chem.psu.edu (Michael C. Burns)
Newsgroups: alt.sources
Subject: ANNOUNCE: pnmsmooth.c Version 2.0 [1/1]
Followup-To: alt.sources.d
Date: 7 Dec 1994 23:23:38 GMT
Organization: Penn State Chemistry
Lines: 456
Message-ID: <3c5g5q$1792@hearst.cac.psu.edu>
Keywords: smooth, convolution, pbmplus, netpbm


Archive-name: pnmsmooth.c_2.0
Submitted-by: burns@chem.psu.edu

README for pnmsmooth.c 2.0

This is a replacement for the pnmsmooth script that is distributed with
pbmplus/netpbm.  This version of pnmsmooth is written as a C program rather
than a shell script.  It accepts command line arguments to specify a size 
other than 3x3 for the convolution matrix and an argument for dumping the 
resultant convolution matrix as a PGM file.  By default it uses the same 3x3
matrix size as the pnmsmooth script and can be used as a direct replacement.

Also included are an updated man page and a patch file to update the Imakefile
in the pnm directory.  You may want to apply the patches by hand if you have
already modified the Imakefile to add other new programs.   You will then
have to remake the Makefiles and then type 'make all' in the pnm directory.

- Mike

----------------------------------------------------------------------------
Mike Burns                                              System Administrator
burns@chem.psu.edu                                   Department of Chemistry
(814) 863-2123                             The Pennsylvania State University

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  pnmsmooth.1 pnmsmooth.Imakefile.patch pnmsmooth.README
#   pnmsmooth.c
# Wrapped by burns@portal on Wed Dec  7 18:08:37 1994
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'pnmsmooth.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pnmsmooth.1'\"
else
echo shar: Extracting \"'pnmsmooth.1'\" \(1448 characters\)
sed "s/^X//" >'pnmsmooth.1' <<'END_OF_FILE'
X.TH pnmsmooth 1 "4 December 1994"
X.IX pnmsmooth
X.SH NAME
Xpnmsmooth - smooth out an image
X.SH SYNOPSIS
X.B pnmsmooth
X.RB [ -size
X.IR width
X.IR height ]
X.RB [ -dump
X.IR dumpfile ]
X.RI [ pnmfile ]
X.SH DESCRIPTION
XSmooths out an image by replacing each pixel with the
Xaverage of its width X height neighbors.
X.IX smoothing
X.IX anti-aliasing
XIt is implemented as a C progam that generates a PGM convolution matrix
Xand then invokes
X.IR pnmconvol .
X.IX pnmconvol
X.SH OPTIONS
X.TP
X.B -size width height
XSpecifies the size of the convolution matrix.  
XDefault size is a 3x3 matrix.
XWidth and height sizes must be odd.  
XMaximum size of convolution matrix is limited by the maximum value for a 
Xpixel such that (width * height * 2) must not exceed the maximum pixel value.
X.TP
X.B -dump dumpfile
XGenerates and saves the convolution file only.
XUse of this option does not invoke pnmconvol.
X.SH "SEE ALSO"
Xpnmconvol(1), pnm(5)
X.SH AUTHORS
XCopyright (C) 1989, 1991 by Jef Poskanzer.
X.br
XConverted from script to C program December 1994 by Mike Burns (burns@chem.psu.edu).
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.
END_OF_FILE
if test 1448 -ne `wc -c <'pnmsmooth.1'`; then
    echo shar: \"'pnmsmooth.1'\" unpacked with wrong size!
fi
# end of 'pnmsmooth.1'
fi
if test -f 'pnmsmooth.Imakefile.patch' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pnmsmooth.Imakefile.patch'\"
else
echo shar: Extracting \"'pnmsmooth.Imakefile.patch'\" \(5092 characters\)
sed "s/^X//" >'pnmsmooth.Imakefile.patch' <<'END_OF_FILE'
X*** Imakefile.orig	Mon Dec  5 20:31:46 1994
X--- Imakefile	Mon Dec  5 20:33:10 1994
X***************
X*** 42,53 ****
X  		 pnmalias.1 pnmarith.1 pnmcat.1 pnmcomp.1 pnmconvol.1 \
X                   pnmcrop.1 pnmcut.1 pnmdepth.1 pnmenlarge.1 pnmfile.1 \
X                   pnmflip.1 pnmhistmap.1 pnminvert.1 pnmnlfilt.1 \
X! 		 pnmnoraw.1 pnmpad.1 pnmpaste.1 pnmscale.1 pnmtile.1 \
X! 		 pnmtoddif.1 pnmtofits.1 pnmtops.1 pnmtorast.1 pnmtosgi.1 \
X! 		 pnmtosir.1 pnmtoxwd.1 \
X  		 rasttopnm.1 sgitopnm.1 sirtopnm.1 xwdtopnm.1 zeisstopnm.1 \
X  		 pnmgamma.1 pnmrotate.1 pnmshear.1 \
X! 		 anytopnm.1 pnmindex.1 pnmmargin.1 pnmsmooth.1 \
X  		 $(TIFFMAN1)
X            MAN3 = libpnm.3
X            MAN5 = pnm.5
X--- 42,53 ----
X  		 pnmalias.1 pnmarith.1 pnmcat.1 pnmcomp.1 pnmconvol.1 \
X                   pnmcrop.1 pnmcut.1 pnmdepth.1 pnmenlarge.1 pnmfile.1 \
X                   pnmflip.1 pnmhistmap.1 pnminvert.1 pnmnlfilt.1 \
X! 		 pnmnoraw.1 pnmpad.1 pnmpaste.1 pnmscale.1 pnmsmooth.1 \
X! 		 pnmtile.1 pnmtoddif.1 pnmtofits.1 pnmtops.1 pnmtorast.1 \
X! 		 pnmtosgi.1 pnmtosir.1 pnmtoxwd.1 \
X  		 rasttopnm.1 sgitopnm.1 sirtopnm.1 xwdtopnm.1 zeisstopnm.1 \
X  		 pnmgamma.1 pnmrotate.1 pnmshear.1 \
X! 		 anytopnm.1 pnmindex.1 pnmmargin.1 \
X  		 $(TIFFMAN1)
X            MAN3 = libpnm.3
X            MAN5 = pnm.5
X***************
X*** 56,64 ****
X  		 pnmalias.c pnmarith.c pnmcat.c pnmcomp.c pnmconvol.c \
X                   pnmcrop.c pnmcut.c pnmdepth.c pnmenlarge.c pnmfile.c \
X                   pnmflip.c pnmhistmap.c pnminvert.c pnmnlfilt.c \
X! 		 pnmnoraw.c pnmpad.c pnmpaste.c pnmscale.c pnmtile.c \
X! 		 pnmtoddif.c pnmtofits.c pnmtops.c pnmtorast.c pnmtosgi.c \
X! 		 pnmtosir.c pnmtoxwd.c \
X  		 rasttopnm.c sgitopnm.c sirtopnm.c xwdtopnm.c zeisstopnm.c \
X  		 $(TIFFSRCS)
X  
X--- 56,64 ----
X  		 pnmalias.c pnmarith.c pnmcat.c pnmcomp.c pnmconvol.c \
X                   pnmcrop.c pnmcut.c pnmdepth.c pnmenlarge.c pnmfile.c \
X                   pnmflip.c pnmhistmap.c pnminvert.c pnmnlfilt.c \
X! 		 pnmnoraw.c pnmpad.c pnmpaste.c pnmscale.c pnmsmooth.c \
X! 		 pnmtile.c pnmtoddif.c pnmtofits.c pnmtops.c pnmtorast.c \
X! 		 pnmtosgi.c pnmtosir.c pnmtoxwd.c \
X  		 rasttopnm.c sgitopnm.c sirtopnm.c xwdtopnm.c zeisstopnm.c \
X  		 $(TIFFSRCS)
X  
X***************
X*** 66,74 ****
X  		 pnmalias.o pnmarith.o pnmcat.o pnmcomp.o pnmconvol.o \
X                   pnmcrop.o pnmcut.o pnmdepth.o pnmenlarge.o pnmfile.o \
X                   pnmflip.o pnmhistmap.o pnminvert.o pnmnlfilt.o \
X! 		 pnmnoraw.o pnmpad.o pnmpaste.o pnmscale.o pnmtile.o \
X! 		 pnmtoddif.o pnmtofits.o pnmtops.o pnmtorast.o pnmtosgi.o \
X! 		 pnmtosir.o pnmtoxwd.o \
X  		 rasttopnm.o sgitopnm.o sirtopnm.o xwdtopnm.o zeisstopnm.o \
X  		 $(TIFFOBJS)
X  
X--- 66,74 ----
X  		 pnmalias.o pnmarith.o pnmcat.o pnmcomp.o pnmconvol.o \
X                   pnmcrop.o pnmcut.o pnmdepth.o pnmenlarge.o pnmfile.o \
X                   pnmflip.o pnmhistmap.o pnminvert.o pnmnlfilt.o \
X! 		 pnmnoraw.o pnmpad.o pnmpaste.o pnmscale.o pnmsmooth.o \
X! 		 pnmtile.o pnmtoddif.o pnmtofits.o pnmtops.o pnmtorast.o \
X! 		 pnmtosgi.o pnmtosir.o pnmtoxwd.o \
X  		 rasttopnm.o sgitopnm.o sirtopnm.o xwdtopnm.o zeisstopnm.o \
X  		 $(TIFFOBJS)
X  
X***************
X*** 76,88 ****
X  		 pnmalias pnmarith pnmcat pnmcomp pnmconvol \
X                   pnmcrop pnmcut pnmdepth pnmenlarge pnmfile \
X                   pnmflip pnmhistmap pnminvert pnmnlfilt \
X! 		 pnmnoraw pnmpad pnmpaste pnmscale pnmtile \
X  		 pnmtoddif pnmtofits pnmtops pnmtorast pnmtosgi \
X  		 pnmtosir pnmtoxwd \
X  		 rasttopnm sgitopnm sirtopnm xwdtopnm zeisstopnm \
X  		 $(TIFFBINS)
X  
X! includes:: anytopnm.script pnmindex.script pnmmargin.script pnmsmooth.script \
X  	   pstopnm.script
X  
X  anytopnm.script:
X--- 76,88 ----
X  		 pnmalias pnmarith pnmcat pnmcomp pnmconvol \
X                   pnmcrop pnmcut pnmdepth pnmenlarge pnmfile \
X                   pnmflip pnmhistmap pnminvert pnmnlfilt \
X! 		 pnmnoraw pnmpad pnmpaste pnmscale pnmsmooth pnmtile \
X  		 pnmtoddif pnmtofits pnmtops pnmtorast pnmtosgi \
X  		 pnmtosir pnmtoxwd \
X  		 rasttopnm sgitopnm sirtopnm xwdtopnm zeisstopnm \
X  		 $(TIFFBINS)
X  
X! includes:: anytopnm.script pnmindex.script pnmmargin.script \
X  	   pstopnm.script
X  
X  anytopnm.script:
X***************
X*** 94,102 ****
X  pnmmargin.script:
X  	$(LN) pnmmargin pnmmargin.script
X  
X- pnmsmooth.script:
X- 	$(LN) pnmsmooth pnmsmooth.script
X- 
X  pstopnm.script:
X  	$(LN) pstopnm pstopnm.script
X  
X--- 94,99 ----
X***************
X*** 122,127 ****
X--- 119,125 ----
X  NormalPbmplusProgramTarget(pnmnoraw)
X  NormalPbmplusProgramTarget(pnmpad)
X  NormalPbmplusProgramTarget(pnmpaste)
X+ NormalPbmplusProgramTarget(pnmsmooth)
X  NormalPbmplusProgramTarget(pnmtile)
X  NormalPbmplusProgramTarget(pnmtoddif)
X  NormalPbmplusProgramTarget(pnmtofits)
X***************
X*** 160,166 ****
X  InstallScript(anytopnm,$(PBMPLUSDIR)$(PBMPLUSBINDIR))
X  InstallScript(pnmindex,$(PBMPLUSDIR)$(PBMPLUSBINDIR))
X  InstallScript(pnmmargin,$(PBMPLUSDIR)$(PBMPLUSBINDIR))
X- InstallScript(pnmsmooth,$(PBMPLUSDIR)$(PBMPLUSBINDIR))
X  InstallScript(pstopnm,$(PBMPLUSDIR)$(PBMPLUSBINDIR))
X  #endif
X  
X--- 158,163 ----
END_OF_FILE
if test 5092 -ne `wc -c <'pnmsmooth.Imakefile.patch'`; then
    echo shar: \"'pnmsmooth.Imakefile.patch'\" unpacked with wrong size!
fi
# end of 'pnmsmooth.Imakefile.patch'
fi
if test -f 'pnmsmooth.README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pnmsmooth.README'\"
else
echo shar: Extracting \"'pnmsmooth.README'\" \(1105 characters\)
sed "s/^X//" >'pnmsmooth.README' <<'END_OF_FILE'
XREADME for pnmsmooth.c 2.0
X
XThis is a replacement for the pnmsmooth script that is distributed with
Xpbmplus/netpbm.  This version of pnmsmooth is written as a C program rather
Xthan a shell script.  It accepts command line arguments to specify a size 
Xother than 3x3 for the convolution matrix and an argument for dumping the 
Xresultant convolution matrix as a PGM file.  By default it uses the same 3x3
Xmatrix size as the pnmsmooth script and can be used as a direct replacement.
X
XAlso included are an updated man page and a patch file to update the Imakefile
Xin the pnm directory.  You may want to apply the patches by hand if you have
Xalready modified the Imakefile to add other new programs.   You will then
Xhave to remake the Makefiles and then type 'make all' in the pnm directory.
X
X- Mike
X
X----------------------------------------------------------------------------
XMike Burns                                              System Administrator
Xburns@chem.psu.edu                                   Department of Chemistry
X(814) 863-2123                             The Pennsylvania State University
X
END_OF_FILE
if test 1105 -ne `wc -c <'pnmsmooth.README'`; then
    echo shar: \"'pnmsmooth.README'\" unpacked with wrong size!
fi
# end of 'pnmsmooth.README'
fi
if test -f 'pnmsmooth.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pnmsmooth.c'\"
else
echo shar: Extracting \"'pnmsmooth.c'\" \(4582 characters\)
sed "s/^X//" >'pnmsmooth.c' <<'END_OF_FILE'
X/* pnmsmooth.c - smooth out an image by replacing each pixel with the 
X**               average of its width x height neighbors.
X**
X** Version 2.0   December 5, 1994
X**
X** Copyright (C) 1994 by Mike Burns (burns@chem.psu.edu)
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/* Version 2.0 - December 5, 1994
X** ------------------------------
X** Rewrote as a C program that accepts a few options instead of a shell 
X** script with no options.
X**
X*/
X
X#include "pnm.h"
X#include <sys/wait.h>
X
X#define TRUE    1
X#define FALSE   0
X
Xint
Xmain( argc, argv )
X    int argc;
X    char* argv[];
X    {
X    FILE *cofp;
X    char *tempfn;
X    char *pnmfn;
X    int argn;
X    int col, row;
X    int format, forceplain;
X    int cols, rows;
X    int newmaxval;		/* normally xelval, but want int here */
X    xelval g;
X    xel *outputrow;
X    int pid, status;
X    int DUMPFLAG = FALSE;
X    char *usage = "[-size width height] [-dump dumpfile] [pnmfile]";
X
X    pnm_init( &argc, argv );
X
X    /* set up defaults */
X    cols = 3;
X    rows = 3;
X    format = PGM_FORMAT;
X    forceplain = 1;
X    pnmfn = (char *) 0;		/* initialize to NULL just in case */
X
X    argn = 1;
X    while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' )
X	{
X	if ( pm_keymatch( argv[argn], "-size", 2 ) )
X	    {
X	    ++argn;
X	    if ( argn+1 >= argc )
X		{
X		pm_message( "incorrect number of arguments for -size option" );
X		pm_usage( usage );
X		}
X	    else if ( argv[argn][0] == '-' || argv[argn+1][0] == '-' )
X		{
X		pm_message( "invalid arguments to -size option: %s %s", 
X		    argv[argn], argv[argn+1] );
X		pm_usage( usage );
X		}
X	    if ( (cols = atoi(argv[argn])) == 0 )
X		pm_error( "invalid width size specification: %s", argv[argn] );
X	    ++argn;
X	    if ( (rows = atoi(argv[argn])) == 0 )
X		pm_error( "invalid height size specification: %s",argv[argn] );
X	    if ( cols % 2 != 1 || rows % 2 != 1 )
X		pm_error( "the convolution matrix must have an odd number of rows and columns" );
X	    }
X	else if ( pm_keymatch( argv[argn], "-dump", 2 ) )
X	    {
X	    ++argn;
X	    if ( argn >= argc )
X		{
X		pm_message( "missing argument to -dump option" );
X		pm_usage( usage );
X		}
X	    else if ( argv[argn][0] == '-' )
X		{
X		pm_message( "invalid argument to -dump option: %s", 
X		    argv[argn] );
X		pm_usage( usage );
X		}
X	    cofp = pm_openw( argv[argn] );
X	    DUMPFLAG = TRUE;
X	    }
X	else
X	    pm_usage( usage );
X	++argn;
X	}
X
X    /* Only get file name if given on command line to pass through to 
X    ** pnmconvol.  If filename is coming from stdin, pnmconvol will read it.
X    */
X    if ( argn < argc )
X	{
X	pnmfn = argv[argn];
X	++argn;
X	}
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X
X    if ( !DUMPFLAG )
X	{
X	if ( (tempfn = tmpnam((char *) 0)) == NULL )
X	    pm_error( "could not create temporary file name" );
X	if ( (cofp = pm_openw(tempfn)) == NULL )
X	    pm_error( "could not create temporary convolution file" );
X	}
X
X    /* Generate mean value for all pixels in convolution matrix. */
X    g = rows * cols + 1;
X
X    /* Make sure newmaxval is not larger than PNM_MAXMAXVAL or else
X    ** newmaxval will overrun its defined data size and become garbage.
X    */
X    newmaxval = ( rows * cols ) * 2;
X    if ( newmaxval > PNM_MAXMAXVAL )
X	pm_error( "generated maxval is too large: %d", newmaxval );
X
X    pnm_writepnminit( cofp, cols, rows, newmaxval, format, forceplain );
X    outputrow = pnm_allocrow( cols );
X
X    for ( row = 0; row < rows; ++ row )
X	{
X	for ( col = 0; col < cols; ++col )
X	    PNM_ASSIGN1( outputrow[col], g );
X	pnm_writepnmrow( cofp, outputrow, cols, newmaxval, format, forceplain );
X	}
X    pm_close( cofp );
X    pnm_freerow( outputrow );
X
X    /* If we're only going to dump the file, now is the time to stop. */
X    if ( DUMPFLAG )
X	exit( 0 );
X
X    /* fork a child process */
X    if ( (pid = fork()) < 0 )
X	pm_error( "fork" );
X
X    /* child process executes following code */
X    if ( pid == 0 )
X	{
X	/* If pnmfile name is not given on command line, then pnmfn will be
X	** (char *) 0 and the arglist will terminate there.
X	*/
X	execlp( "pnmconvol", "pnmconvol", tempfn, pnmfn, (char *) 0 );
X	pm_error( "error executing pnmconvol command" );
X	}
X
X    /* wait for child to finish */
X    while ( wait(&status) != pid )
X	;
X
X    unlink( tempfn );
X    exit( 0 );
X    }
END_OF_FILE
if test 4582 -ne `wc -c <'pnmsmooth.c'`; then
    echo shar: \"'pnmsmooth.c'\" unpacked with wrong size!
fi
# end of 'pnmsmooth.c'
fi
echo shar: End of shell archive.
exit 0

----------------------------------------------------------------------------
Mike Burns                                              System Administrator
burns@chem.psu.edu                                   Department of Chemistry
(814) 863-2123                             The Pennsylvania State University
