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

  1. /* libpnm2.c - pnm utility library part 2
  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. #include "ppm.h"
  16. #include "libppm.h"
  17.  
  18. #include "pgm.h"
  19. #include "libpgm.h"
  20.  
  21. #include "pbm.h"
  22. #include "libpbm.h"
  23.  
  24. #if __STDC__
  25. void
  26. pnm_writepnminit( FILE* file, int cols, int rows, xelval maxval, int format, int forceplain )
  27. #else /*__STDC__*/
  28. void
  29. pnm_writepnminit( file, cols, rows, maxval, format, forceplain )
  30.     FILE* file;
  31.     int cols, rows, format;
  32.     xelval maxval;
  33.     int forceplain;
  34. #endif /*__STDC__*/
  35.     {
  36.     switch ( PNM_FORMAT_TYPE(format) )
  37.     {
  38.     case PPM_TYPE:
  39.     ppm_writeppminit( file, cols, rows, (pixval) maxval, forceplain );
  40.     break;
  41.  
  42.     case PGM_TYPE:
  43.     pgm_writepgminit( file, cols, rows, (gray) maxval, forceplain );
  44.     break;
  45.  
  46.     case PBM_TYPE:
  47.     pbm_writepbminit( file, cols, rows, forceplain );
  48.     break;
  49.  
  50.     default:
  51.     pm_error( "can't happen" );
  52.     }
  53.     }
  54.  
  55. #if __STDC__
  56. void
  57. pnm_writepnmrow( FILE* file, xel* xelrow, int cols, xelval maxval, int format, int forceplain )
  58. #else /*__STDC__*/
  59. void
  60. pnm_writepnmrow( file, xelrow, cols, maxval, format, forceplain )
  61.     FILE* file;
  62.     xel* xelrow;
  63.     int cols, format;
  64.     xelval maxval;
  65.     int forceplain;
  66. #endif /*__STDC__*/
  67.     {
  68.     register int col;
  69.     register xel* xP;
  70.     gray* grayrow;
  71.     register gray* gP;
  72.     bit* bitrow;
  73.     register bit* bP;
  74.  
  75.     switch ( PNM_FORMAT_TYPE(format) )
  76.     {
  77.     case PPM_TYPE:
  78.     ppm_writeppmrow( file, (pixel*) xelrow, cols, (pixval) maxval, forceplain );
  79.     break;
  80.  
  81.     case PGM_TYPE:
  82.     grayrow = pgm_allocrow( cols );
  83.     for ( col = 0, gP = grayrow, xP = xelrow; col < cols; ++col, ++gP, ++xP )
  84.         *gP = PNM_GET1( *xP );
  85.     pgm_writepgmrow( file, grayrow, cols, (gray) maxval, forceplain );
  86.     pgm_freerow( grayrow );
  87.     break;
  88.  
  89.     case PBM_TYPE:
  90.     bitrow = pbm_allocrow( cols );
  91.     for ( col = 0, bP = bitrow, xP = xelrow; col < cols; ++col, ++bP, ++xP )
  92.         *bP = PNM_GET1( *xP ) == 0 ? PBM_BLACK : PBM_WHITE;
  93.     pbm_writepbmrow( file, bitrow, cols, forceplain );
  94.     pbm_freerow( bitrow );
  95.     break;
  96.  
  97.     default:
  98.     pm_error( "can't happen" );
  99.     }
  100.     }
  101.  
  102. #if __STDC__
  103. void
  104. pnm_writepnm( FILE* file, xel** xels, int cols, int rows, xelval maxval, int format, int forceplain )
  105. #else /*__STDC__*/
  106. void
  107. pnm_writepnm( file, xels, cols, rows, maxval, format, forceplain )
  108.     FILE* file;
  109.     xel** xels;
  110.     xelval maxval;
  111.     int cols, rows, format;
  112.     int forceplain;
  113. #endif /*__STDC__*/
  114.     {
  115.     int row;
  116.  
  117.     pnm_writepnminit( file, cols, rows, maxval, format, forceplain );
  118.  
  119.     for ( row = 0; row < rows; ++row )
  120.     pnm_writepnmrow( file, xels[row], cols, maxval, format, forceplain );
  121.     }
  122.