home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netpbma.zip / pnm / pnminvert.c < prev    next >
C/C++ Source or Header  |  1993-10-04  |  1KB  |  54 lines

  1. /* pnminvert.c - read a portable anymap and invert it
  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 "pnm.h"
  14.  
  15. int
  16. main( argc, argv )
  17.     int argc;
  18.     char* argv[];
  19.     {
  20.     FILE* ifp;
  21.     xelval maxval;
  22.     register xel* xelrow;
  23.     register xel* xP;
  24.     int rows, cols, format, row, col;
  25.  
  26.     pnm_init( &argc, argv );
  27.  
  28.     if ( argc > 2 )
  29.     pm_usage( "[pnmfile]" );
  30.  
  31.     if ( argc == 2 )
  32.     ifp = pm_openr( argv[1] );
  33.     else
  34.     ifp = stdin;
  35.  
  36.     pnm_readpnminit( ifp, &cols, &rows, &maxval, &format );
  37.     pnm_writepnminit( stdout, cols, rows, maxval, format, 0 );
  38.     xelrow = pnm_allocrow( cols );
  39.  
  40.     for ( row = 0; row < rows; ++row )
  41.     {
  42.     pnm_readpnmrow( ifp, xelrow, cols, maxval, format );
  43.         for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
  44.         pnm_invertxel( xP, maxval, format );
  45.  
  46.     pnm_writepnmrow( stdout, xelrow, cols, maxval, format, 0 );
  47.     }
  48.  
  49.     pm_close( ifp );
  50.     pm_close( stdout );
  51.  
  52.     exit( 0 );
  53.     }
  54.