home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netpbma.zip / ppm / ppm.h < prev    next >
C/C++ Source or Header  |  1996-11-10  |  4KB  |  110 lines

  1. /* ppm.h - header file for libppm portable pixmap library
  2. */
  3.  
  4. #ifndef _PPM_H_
  5. #define _PPM_H_
  6.  
  7. #include "pgm.h"
  8.  
  9. typedef gray pixval;
  10.  
  11. #ifdef PPM_PACKCOLORS
  12.  
  13. #define PPM_MAXMAXVAL 1023
  14. typedef unsigned long pixel;
  15. #define PPM_GETR(p) (((p) & 0x3ff00000) >> 20)
  16. #define PPM_GETG(p) (((p) & 0xffc00) >> 10)
  17. #define PPM_GETB(p) ((p) & 0x3ff)
  18.  
  19. /************* added definitions *****************/
  20. #define PPM_PUTR(p, red) ((p) |= (((red) & 0x3ff) << 20))
  21. #define PPM_PUTG(p, grn) ((p) |= (((grn) & 0x3ff) << 10))
  22. #define PPM_PUTB(p, blu) ((p) |= ( (blu) & 0x3ff))
  23. /**************************************************/
  24.  
  25. #define PPM_ASSIGN(p,red,grn,blu) (p) = ((pixel) (red) << 20) | ((pixel) (grn) << 10) | (pixel) (blu)
  26. #define PPM_EQUAL(p,q) ((p) == (q))
  27.  
  28. #else /*PPM_PACKCOLORS*/
  29.  
  30. #define PPM_MAXMAXVAL PGM_MAXMAXVAL
  31. typedef struct
  32.     {
  33.     pixval r, g, b;
  34.     } pixel;
  35. #define PPM_GETR(p) ((p).r)
  36. #define PPM_GETG(p) ((p).g)
  37. #define PPM_GETB(p) ((p).b)
  38.  
  39. /************* added definitions *****************/
  40. #define PPM_PUTR(p,red) ((p).r = (red))
  41. #define PPM_PUTG(p,grn) ((p).g = (grn))
  42. #define PPM_PUTB(p,blu) ((p).b = (blu))
  43. /**************************************************/
  44.  
  45. #define PPM_ASSIGN(p,red,grn,blu) do { (p).r = (red); (p).g = (grn); (p).b = (blu); } while ( 0 )
  46. #define PPM_EQUAL(p,q) ( (p).r == (q).r && (p).g == (q).g && (p).b == (q).b )
  47.  
  48. #endif /*PPM_PACKCOLORS*/
  49.  
  50.  
  51. /* Magic constants. */
  52.  
  53. #define PPM_MAGIC1 'P'
  54. #define PPM_MAGIC2 '3'
  55. #define RPPM_MAGIC2 '6'
  56. #define PPM_FORMAT (PPM_MAGIC1 * 256 + PPM_MAGIC2)
  57. #define RPPM_FORMAT (PPM_MAGIC1 * 256 + RPPM_MAGIC2)
  58. #define PPM_TYPE PPM_FORMAT
  59.  
  60.  
  61. /* Macro for turning a format number into a type number. */
  62.  
  63. #define PPM_FORMAT_TYPE(f) ((f) == PPM_FORMAT || (f) == RPPM_FORMAT ? PPM_TYPE : PGM_FORMAT_TYPE(f))
  64.  
  65. #ifdef __EMX__
  66. #define srandom srand
  67. #define random rand
  68. #endif
  69.  
  70. /* Declarations of routines. */
  71.  
  72. void ppm_init ARGS(( int* argcP, char* argv[] ));
  73.  
  74. #define ppm_allocarray( cols, rows ) ((pixel**) pm_allocarray( cols, rows, sizeof(pixel) ))
  75. #define ppm_allocrow( cols ) ((pixel*) pm_allocrow( cols, sizeof(pixel) ))
  76. #define ppm_freearray( pixels, rows ) pm_freearray( (char**) pixels, rows )
  77. #define ppm_freerow( pixelrow ) pm_freerow( (char*) pixelrow )
  78.  
  79. pixel** ppm_readppm ARGS(( FILE* file, int* colsP, int* rowsP, pixval* maxvalP ));
  80. void ppm_readppminit ARGS(( FILE* file, int* colsP, int* rowsP, pixval* maxvalP, int* formatP ));
  81. void ppm_readppmrow ARGS(( FILE* file, pixel* pixelrow, int cols, pixval maxval, int format ));
  82.  
  83. void ppm_writeppm ARGS(( FILE* file, pixel** pixels, int cols, int rows, pixval maxval, int forceplain ));
  84. void ppm_writeppminit ARGS(( FILE* file, int cols, int rows, pixval maxval, int forceplain ));
  85. void ppm_writeppmrow ARGS(( FILE* file, pixel* pixelrow, int cols, pixval maxval, int forceplain ));
  86.  
  87. pixel ppm_parsecolor ARGS(( char* colorname, pixval maxval ));
  88. char* ppm_colorname ARGS(( pixel* colorP, pixval maxval, int hexok ));
  89.  
  90. extern pixval ppm_pbmmaxval;
  91. /* This is the maxval used when a PPM program reads a PBM file.  Normally
  92. ** it is 1; however, for some programs, a larger value gives better results
  93. */
  94.  
  95.  
  96. /* Color scaling macro -- to make writing ppmtowhatever easier. */
  97.  
  98. #define PPM_DEPTH(newp,p,oldmaxval,newmaxval) \
  99.     PPM_ASSIGN( (newp), \
  100.         ( (int) PPM_GETR(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
  101.         ( (int) PPM_GETG(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
  102.         ( (int) PPM_GETB(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) )
  103.  
  104.  
  105. /* Luminance macro. */
  106.  
  107. #define PPM_LUMIN(p) ( 0.299 * PPM_GETR(p) + 0.587 * PPM_GETG(p) + 0.114 * PPM_GETB(p) )
  108.  
  109. #endif /*_PPM_H_*/
  110.