home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libcnv / ppm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.6 KB  |  106 lines

  1. /* ppm.h -
  2. **
  3. ** Header File
  4. **
  5. ** Copyright (C) 1989, 1991 by Jef Poskanzer.
  6. **
  7. ** Permission to use, copy, modify, and distribute this software and its
  8. ** documentation for any purpose and without fee is hereby granted, provided
  9. ** that the above copyright notice appear in all copies and that both that
  10. ** copyright notice and this permission notice appear in supporting
  11. ** documentation.  This software is provided "as is" without express or
  12. ** implied warranty.
  13. */
  14.  
  15. /*modified by Netscape*/
  16.  
  17. #ifndef _PPM_H_
  18. #define _PPM_H_
  19.  
  20. /*#include "pgm.h" JUDGE*/
  21. typedef unsigned char gray;
  22.  
  23. typedef gray pixval;
  24.  
  25. #ifdef PPM_PACKCOLORS
  26.  
  27. #define PPM_MAXMAXVAL 1023
  28. typedef uint32 pixel;
  29. #define PPM_GETR(p) (((p) & 0x3ff00000) >> 20)
  30. #define PPM_GETG(p) (((p) & 0xffc00) >> 10)
  31. #define PPM_GETB(p) ((p) & 0x3ff)
  32. #define PPM_ASSIGN(p,red,grn,blu) (p) = ((pixel) (red) << 20) | ((pixel) (grn) << 10) | (pixel) (blu)
  33. #define PPM_EQUAL(p,q) ((p) == (q))
  34.  
  35. #else /*PPM_PACKCOLORS*/
  36.  
  37. #define PPM_MAXMAXVAL PGM_MAXMAXVAL
  38. typedef struct
  39.     {
  40.     pixval r, g, b;
  41.     } pixel;
  42. #define PPM_GETR(p) ((p).r)
  43. #define PPM_GETG(p) ((p).g)
  44. #define PPM_GETB(p) ((p).b)
  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.  
  66. /* Declarations of routines. */
  67.  
  68. void ppm_init ARGS(( int16* argcP, char* argv[] ));
  69.  
  70. #define ppm_allocarray( cols, rows ) ((pixel**) pm_allocarray( cols, rows, sizeof(pixel) ))
  71. #define ppm_allocrow( cols ) ((pixel*) pm_allocrow( cols, sizeof(pixel) ))
  72. #define ppm_freearray( pixels, rows ) pm_freearray( (char**) pixels, rows )
  73. #define ppm_freerow( pixelrow ) pm_freerow( (char*) pixelrow )
  74.  
  75. pixel** ppm_readppm ARGS(( FILE* file, int16* colsP, int16* rowsP, pixval* maxvalP ));
  76. void ppm_readppminit ARGS(( FILE* file, int16* colsP, int16* rowsP, pixval* maxvalP, int16* formatP ));
  77. void ppm_readppmrow ARGS(( FILE* file, pixel* pixelrow, int16 cols, pixval maxval, int16 format ));
  78.  
  79. void ppm_writeppm ARGS(( FILE* file, pixel** pixels, int16 cols, int16 rows, pixval maxval, int16 forceplain ));
  80. void ppm_writeppminit ARGS(( FILE* file, int16 cols, int16 rows, pixval maxval, int16 forceplain ));
  81. void ppm_writeppmrow ARGS(( FILE* file, pixel* pixelrow, int16 cols, pixval maxval, int16 forceplain ));
  82.  
  83. pixel ppm_parsecolor ARGS(( char* colorname, pixval maxval ));
  84. char* ppm_colorname ARGS(( pixel* colorP, pixval maxval, int16 hexok ));
  85.  
  86. extern pixval ppm_pbmmaxval;
  87. /* This is the maxval used when a PPM program reads a PBM file.  Normally
  88. ** it is 1; however, for some programs, a larger value gives better results
  89. */
  90.  
  91.  
  92. /* Color scaling macro -- to make writing ppmtowhatever easier. */
  93.  
  94. #define PPM_DEPTH(newp,p,oldmaxval,newmaxval) \
  95.     PPM_ASSIGN( (newp), \
  96.     ( (int16) PPM_GETR(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
  97.     ( (int16) PPM_GETG(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
  98.     ( (int16) PPM_GETB(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) )
  99.  
  100.  
  101. /* Luminance macro. */
  102.  
  103. #define PPM_LUMIN(p) ( 0.299 * PPM_GETR(p) + 0.587 * PPM_GETG(p) + 0.114 * PPM_GETB(p) )
  104.  
  105. #endif /*_PPM_H_*/
  106.