home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / NETWORK / netpbm_src.lzh / NETPBM / PPM / ppm.h < prev    next >
Text File  |  1997-04-14  |  4KB  |  109 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. #ifdef OSK
  35.    pixval dummy;
  36. #endif    
  37.     } pixel;
  38. #define PPM_GETR(p) ((p).r)
  39. #define PPM_GETG(p) ((p).g)
  40. #define PPM_GETB(p) ((p).b)
  41.  
  42. /************* added definitions *****************/
  43. #define PPM_PUTR(p,red) ((p).r = (red))
  44. #define PPM_PUTG(p,grn) ((p).g = (grn))
  45. #define PPM_PUTB(p,blu) ((p).b = (blu))
  46. /**************************************************/
  47.  
  48. #define PPM_ASSIGN(p,red,grn,blu) do { (p).r = (red); (p).g = (grn); (p).b = (blu); } while ( 0 )
  49. #define PPM_EQUAL(p,q) ( (p).r == (q).r && (p).g == (q).g && (p).b == (q).b )
  50.  
  51. #endif /*PPM_PACKCOLORS*/
  52.  
  53.  
  54. /* Magic constants. */
  55.  
  56. #define PPM_MAGIC1 'P'
  57. #define PPM_MAGIC2 '3'
  58. #define RPPM_MAGIC2 '6'
  59. #define PPM_FORMAT (PPM_MAGIC1 * 256 + PPM_MAGIC2)
  60. #define RPPM_FORMAT (PPM_MAGIC1 * 256 + RPPM_MAGIC2)
  61. #define PPM_TYPE PPM_FORMAT
  62.  
  63.  
  64. /* Macro for turning a format number into a type number. */
  65.  
  66. #define PPM_FORMAT_TYPE(f) ((f) == PPM_FORMAT || (f) == RPPM_FORMAT ? PPM_TYPE : PGM_FORMAT_TYPE(f))
  67.  
  68.  
  69. /* Declarations of routines. */
  70.  
  71. void ppm_init ARGS(( int* argcP, char* argv[] ));
  72.  
  73. #define ppm_allocarray( cols, rows ) ((pixel**) pm_allocarray( cols, rows, sizeof(pixel) ))
  74. #define ppm_allocrow( cols ) ((pixel*) pm_allocrow( cols, sizeof(pixel) ))
  75. #define ppm_freearray( pixels, rows ) pm_freearray( (char**) pixels, rows )
  76. #define ppm_freerow( pixelrow ) pm_freerow( (char*) pixelrow )
  77.  
  78. pixel** ppm_readppm ARGS(( FILE* file, int* colsP, int* rowsP, pixval* maxvalP ));
  79. void ppm_readppminit ARGS(( FILE* file, int* colsP, int* rowsP, pixval* maxvalP, int* formatP ));
  80. void ppm_readppmrow ARGS(( FILE* file, pixel* pixelrow, int cols, pixval maxval, int format ));
  81.  
  82. void ppm_writeppm ARGS(( FILE* file, pixel** pixels, int cols, int rows, pixval maxval, int forceplain ));
  83. void ppm_writeppminit ARGS(( FILE* file, int cols, int rows, pixval maxval, int forceplain ));
  84. void ppm_writeppmrow ARGS(( FILE* file, pixel* pixelrow, int cols, pixval maxval, int forceplain ));
  85.  
  86. pixel ppm_parsecolor ARGS(( char* colorname, pixval maxval ));
  87. char* ppm_colorname ARGS(( pixel* colorP, pixval maxval, int hexok ));
  88.  
  89. extern pixval ppm_pbmmaxval;
  90. /* This is the maxval used when a PPM program reads a PBM file.  Normally
  91. ** it is 1; however, for some programs, a larger value gives better results
  92. */
  93.  
  94.  
  95. /* Color scaling macro -- to make writing ppmtowhatever easier. */
  96.  
  97. #define PPM_DEPTH(newp,p,oldmaxval,newmaxval) \
  98.     PPM_ASSIGN( (newp), \
  99.     ( (int) PPM_GETR(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
  100.     ( (int) PPM_GETG(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
  101.     ( (int) PPM_GETB(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) )
  102.  
  103.  
  104. /* Luminance macro. */
  105.  
  106. #define PPM_LUMIN(p) ( 0.299 * PPM_GETR(p) + 0.587 * PPM_GETG(p) + 0.114 * PPM_GETB(p) )
  107.  
  108. #endif /*_PPM_H_*/
  109.