|
Packit |
78deda |
/* qrttoppm.c - read a QRT ray-tracer output file and produce a portable pixmap
|
|
Packit |
78deda |
**
|
|
Packit |
78deda |
** Copyright (C) 1989 by Jef Poskanzer.
|
|
Packit |
78deda |
**
|
|
Packit |
78deda |
** Permission to use, copy, modify, and distribute this software and its
|
|
Packit |
78deda |
** documentation for any purpose and without fee is hereby granted, provided
|
|
Packit |
78deda |
** that the above copyright notice appear in all copies and that both that
|
|
Packit |
78deda |
** copyright notice and this permission notice appear in supporting
|
|
Packit |
78deda |
** documentation. This software is provided "as is" without express or
|
|
Packit |
78deda |
** implied warranty.
|
|
Packit |
78deda |
*/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
#include "ppm.h"
|
|
Packit |
78deda |
|
|
Packit |
78deda |
int
|
|
Packit |
78deda |
main( argc, argv )
|
|
Packit |
78deda |
int argc;
|
|
Packit |
78deda |
char* argv[];
|
|
Packit |
78deda |
{
|
|
Packit |
78deda |
FILE* ifp;
|
|
Packit |
78deda |
register pixel* pixelrow;
|
|
Packit |
78deda |
int rows, cols, row, col;
|
|
Packit |
78deda |
pixval maxval;
|
|
Packit |
78deda |
unsigned char* buf;
|
|
Packit |
78deda |
|
|
Packit |
78deda |
|
|
Packit |
78deda |
ppm_init( &argc, argv );
|
|
Packit |
78deda |
|
|
Packit |
78deda |
if ( argc > 2 )
|
|
Packit |
78deda |
pm_usage( "[qrtfile]" );
|
|
Packit |
78deda |
|
|
Packit |
78deda |
if ( argc == 2 )
|
|
Packit |
78deda |
ifp = pm_openr( argv[1] );
|
|
Packit |
78deda |
else
|
|
Packit |
78deda |
ifp = stdin;
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Read in the QRT file. First the header. */
|
|
Packit |
78deda |
cols = getc( ifp );
|
|
Packit |
78deda |
cols += getc( ifp ) << 8;
|
|
Packit |
78deda |
rows = getc( ifp );
|
|
Packit |
78deda |
rows += getc( ifp ) << 8;
|
|
Packit |
78deda |
|
|
Packit |
78deda |
if ( cols <= 0 || rows <= 0 )
|
|
Packit |
78deda |
pm_error( "invalid size: %d %d", cols, rows );
|
|
Packit |
78deda |
maxval = 255;
|
|
Packit |
78deda |
|
|
Packit |
78deda |
ppm_writeppminit( stdout, cols, rows, maxval, 0 );
|
|
Packit |
78deda |
pixelrow = ppm_allocrow( cols );
|
|
Packit |
38c941 |
buf = (unsigned char *) malloc2( 3 , cols );
|
|
Packit |
78deda |
if ( buf == (unsigned char *) 0 )
|
|
Packit |
78deda |
pm_error( "out of memory" );
|
|
Packit |
78deda |
|
|
Packit |
78deda |
for ( row = 0; row < rows; row++ )
|
|
Packit |
78deda |
{
|
|
Packit |
78deda |
(void) getc( ifp ); /* discard */
|
|
Packit |
78deda |
(void) getc( ifp ); /* linenum */
|
|
Packit |
78deda |
if ( fread( buf, 3 * cols, 1, ifp ) != 1 )
|
|
Packit |
78deda |
pm_error( "EOF / read error" );
|
|
Packit |
78deda |
for ( col = 0; col < cols; col++ )
|
|
Packit |
78deda |
PPM_ASSIGN(
|
|
Packit |
78deda |
pixelrow[col], buf[col], buf[cols + col], buf[2 * cols + col] );
|
|
Packit |
78deda |
ppm_writeppmrow( stdout, pixelrow, cols, maxval, 0 );
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
pm_close( ifp );
|
|
Packit |
78deda |
pm_close( stdout );
|
|
Packit |
78deda |
|
|
Packit |
78deda |
exit( 0 );
|
|
Packit |
78deda |
}
|