prt2ppm pixel map converter

Brian Litzinger brian at apt.bungi.com
Fri Dec 7 19:47:40 AEST 1990


It didn't seem obvious to me how to convert output files of
the prt raytracer to ppm format so I adopted one of the existing
ppmtoXXX programs to do the job.

Hope you find this helpful.  If on the other hand you know of
some straight forward way to do the same thing with less work
I don't really care.

-brian
<>  Brian Litzinger @ APT Technology Inc., San Jose, CA
<>  brian at apt.bungi.com      {apple,sun,pyramid}!daver!apt!brian

#!/bin/sh
# This is a shell archive (shar 3.47)
# made 12/07/1990 08:45 UTC by brian at apt
# Source directory /ust/brian/src/pbmplus/ppm
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   1302 -rw-r----- prt2ppm.c
#
# ============= prt2ppm.c ==============
if test -f 'prt2ppm.c' -a X"$1" != X"-c"; then
	echo 'x - skipping prt2ppm.c (File already exists)'
else
echo 'x - extracting prt2ppm.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'prt2ppm.c' &&
/* prt2ppmm.c - convert a prt pixmap to a portable pixmap
**
** Copyright (C) 1989 by Jef Poskanzer.
** Copyright (C) 1990 By Brian E. Litzinger
**
** Permission to use, copy, modify, and distribute this software and its
** documentation for any purpose and without fee is hereby granted, provided
** that the above copyright notice appear in all copies and that both that
** copyright notice and this permission notice appear in supporting
** documentation.  This software is provided "as is" without express or
** implied warranty.
*/
X
#include <stdio.h>
#include "ppm.h"
X
#define PRT_MAXVAL 255
X
main( argc, argv )
int argc;
char *argv[];
{
X    FILE *ifd;
X    pixel *pixelrow;
X    register pixel *pP;
X    int rows, cols, row;
X    register int col;
X    pixval maxval;
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[prtfile]" );
X
X    if ( argc == 2 )
X	ifd = pm_openr( argv[1] );
X    else
X	ifd = stdin;
X
X    fscanf(ifd,"%d %d\n",&cols, &rows);
X    ppm_writeppminit( stdout, cols, rows, PRT_MAXVAL );
X
X    pixelrow = ppm_allocrow( cols );
X
X    for ( row = 0; row < rows; row++ ) {
X	for ( col=0, pP = pixelrow; col<cols; col++, pP++ )
X	    PPM_ASSIGN(*pP,getc(ifd),getc(ifd),getc(ifd));
X	ppm_writeppmrow( stdout, pixelrow, cols, PRT_MAXVAL );
X    }
X
X    pm_close( ifd );
X
X    exit( 0 );
}
SHAR_EOF
chmod 0640 prt2ppm.c ||
echo 'restore of prt2ppm.c failed'
Wc_c="`wc -c < 'prt2ppm.c'`"
test 1302 -eq "$Wc_c" ||
	echo 'prt2ppm.c: original size 1302, current size' "$Wc_c"
fi
exit 0



More information about the Alt.sources mailing list