home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 309.lha / PBM_PLUS / ppm / qrttoppm.c < prev    next >
C/C++ Source or Header  |  1980-12-04  |  2KB  |  68 lines

  1. /* qrttoppm.c - read a QRT ray-tracer output file and produce a portable pixmap
  2. **
  3. ** Copyright (C) 1989 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include <stdio.h>
  14. #include "ppm.h"
  15.  
  16. main( argc, argv )
  17. int argc;
  18. char *argv[];
  19.     {
  20.     FILE *ifd;
  21.     register pixel *pixelrow;
  22.     int rows, cols, row, col;
  23.     pixval maxval;
  24.     unsigned char *buf;
  25.  
  26.     pm_progname = argv[0];
  27.  
  28.     if ( argc > 2 )
  29.     pm_usage( "[qrtfile]" );
  30.  
  31.     if ( argc == 2 )
  32.     ifd = pm_openr( argv[1] );
  33.     else
  34.     ifd = stdin;
  35.  
  36.     /* Read in the QRT file.  First the header. */
  37.     cols = getc( ifd );
  38.     cols += getc( ifd ) << 8;
  39.     rows = getc( ifd );
  40.     rows += getc( ifd ) << 8;
  41.  
  42.     if ( cols <= 0 || rows <= 0 )
  43.     pm_error( "invalid size: %d %d", cols, rows, 0,0,0 );
  44.     maxval = 255;
  45.  
  46.     ppm_writeppminit( stdout, cols, rows, maxval );
  47.     pixelrow = ppm_allocrow( cols );
  48.     buf = (unsigned char *) malloc( 3 * cols );
  49.     if ( buf == (unsigned char *) 0 )
  50.     pm_error( "out of memory", 0,0,0,0,0 );
  51.  
  52.     for ( row = 0; row < rows; row++ )
  53.     {
  54.         (void) getc( ifd );    /* discard */
  55.         (void) getc( ifd );    /* linenum */
  56.     if ( fread( buf, 3 * cols, 1, ifd ) != 1 )
  57.         pm_error( "premature EOF", 0,0,0,0,0 );
  58.     for ( col = 0; col < cols; col++ )
  59.         PPM_ASSIGN(
  60.         pixelrow[col], buf[col], buf[cols + col], buf[2 * cols + col] );
  61.     ppm_writeppmrow( stdout, pixelrow, cols, maxval );
  62.     }
  63.  
  64.     pm_close( ifd );
  65.  
  66.     exit( 0 );
  67.     }
  68.