home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2234 / prt2ppm.c
C/C++ Source or Header  |  1990-12-28  |  1KB  |  55 lines

  1. /* prt2ppmm.c - convert a prt pixmap to a portable pixmap
  2. **
  3. ** Copyright (C) 1989 by Jef Poskanzer.
  4. ** Copyright (C) 1990 By Brian E. Litzinger
  5. **
  6. ** Permission to use, copy, modify, and distribute this software and its
  7. ** documentation for any purpose and without fee is hereby granted, provided
  8. ** that the above copyright notice appear in all copies and that both that
  9. ** copyright notice and this permission notice appear in supporting
  10. ** documentation.  This software is provided "as is" without express or
  11. ** implied warranty.
  12. */
  13.  
  14. #include <stdio.h>
  15. #include "ppm.h"
  16.  
  17. #define PRT_MAXVAL 255
  18.  
  19. main( argc, argv )
  20. int argc;
  21. char *argv[];
  22. {
  23.     FILE *ifd;
  24.     pixel *pixelrow;
  25.     register pixel *pP;
  26.     int rows, cols, row;
  27.     register int col;
  28.     pixval maxval;
  29.  
  30.     pm_progname = argv[0];
  31.  
  32.     if ( argc > 2 )
  33.     pm_usage( "[prtfile]" );
  34.  
  35.     if ( argc == 2 )
  36.     ifd = pm_openr( argv[1] );
  37.     else
  38.     ifd = stdin;
  39.  
  40.     fscanf(ifd,"%d %d\n",&cols, &rows);
  41.     ppm_writeppminit( stdout, cols, rows, PRT_MAXVAL );
  42.  
  43.     pixelrow = ppm_allocrow( cols );
  44.  
  45.     for ( row = 0; row < rows; row++ ) {
  46.     for ( col=0, pP = pixelrow; col<cols; col++, pP++ )
  47.         PPM_ASSIGN(*pP,getc(ifd),getc(ifd),getc(ifd));
  48.     ppm_writeppmrow( stdout, pixelrow, cols, PRT_MAXVAL );
  49.     }
  50.  
  51.     pm_close( ifd );
  52.  
  53.     exit( 0 );
  54. }
  55.