w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ppm.h
Go to the documentation of this file.
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_OVERALLMAXVAL PGM_OVERALLMAXVAL
31 #define PPM_MAXMAXVAL PGM_MAXMAXVAL
32 typedef struct
33  {
34  pixval r, g, b;
35  } pixel;
36 #define PPM_GETR(p) ((p).r)
37 #define PPM_GETG(p) ((p).g)
38 #define PPM_GETB(p) ((p).b)
39 
40 /************* added definitions *****************/
41 #define PPM_PUTR(p,red) ((p).r = (red))
42 #define PPM_PUTG(p,grn) ((p).g = (grn))
43 #define PPM_PUTB(p,blu) ((p).b = (blu))
44 /**************************************************/
45 
46 #define PPM_ASSIGN(p,red,grn,blu) do { (p).r = (red); (p).g = (grn); (p).b = (blu); } while ( 0 )
47 #define PPM_EQUAL(p,q) ( (p).r == (q).r && (p).g == (q).g && (p).b == (q).b )
48 
49 #endif /*PPM_PACKCOLORS*/
50 
51 
52 /* Magic constants. */
53 
54 #define PPM_MAGIC1 'P'
55 #define PPM_MAGIC2 '3'
56 #define RPPM_MAGIC2 '6'
57 #define PPM_FORMAT (PPM_MAGIC1 * 256 + PPM_MAGIC2)
58 #define RPPM_FORMAT (PPM_MAGIC1 * 256 + RPPM_MAGIC2)
59 #define PPM_TYPE PPM_FORMAT
60 
61 
62 /* Macro for turning a format number into a type number. */
63 
64 #define PPM_FORMAT_TYPE(f) ((f) == PPM_FORMAT || (f) == RPPM_FORMAT ? PPM_TYPE : PGM_FORMAT_TYPE(f))
65 
66 
67 /* Declarations of routines. */
68 
69 void ppm_init ARGS(( int* argcP, char* argv[] ));
70 
71 #define ppm_allocarray( cols, rows ) ((pixel**) pm_allocarray( cols, rows, sizeof(pixel) ))
72 #define ppm_allocrow( cols ) ((pixel*) pm_allocrow( cols, sizeof(pixel) ))
73 #define ppm_freearray( pixels, rows ) pm_freearray( (char**) pixels, rows )
74 #define ppm_freerow( pixelrow ) pm_freerow( (char*) pixelrow )
75 
76 pixel** ppm_readppm ARGS(( FILE* file, int* colsP, int* rowsP, pixval* maxvalP ));
77 void ppm_readppminit ARGS(( FILE* file, int* colsP, int* rowsP, pixval* maxvalP, int* formatP ));
79 
80 void ppm_writeppm ARGS(( FILE* file, pixel** pixels, int cols, int rows, pixval maxval, int forceplain ));
81 void ppm_writeppminit ARGS(( FILE* file, int cols, int rows, pixval maxval, int forceplain ));
82 void ppm_writeppmrow ARGS(( FILE* file, pixel* pixelrow, int cols, pixval maxval, int forceplain ));
83 
85 char* ppm_colorname ARGS(( pixel* colorP, pixval maxval, int hexok ));
86 
87 extern pixval ppm_pbmmaxval;
88 /* This is the maxval used when a PPM program reads a PBM file. Normally
89 ** it is 1; however, for some programs, a larger value gives better results
90 */
91 
92 
93 /* Color scaling macro -- to make writing ppmtowhatever easier. */
94 
95 #define PPM_DEPTH(newp,p,oldmaxval,newmaxval) \
96  PPM_ASSIGN( (newp), \
97  ( (int) PPM_GETR(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
98  ( (int) PPM_GETG(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
99  ( (int) PPM_GETB(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) )
100 
101 
102 /* Luminance macro. */
103 
104 #define PPM_LUMIN(p) ( 0.299 * PPM_GETR(p) + 0.587 * PPM_GETG(p) + 0.114 * PPM_GETB(p) )
105 
106 #endif /*_PPM_H_*/
static gray maxval
Definition: asciitopgm.c:38
int pixels
Definition: dvipng.h:106
unsigned char pixelrow[1023]
Definition: hbf2gf.c:377
static int rows
Definition: pbmclean.c:15
static int format
Definition: pbmclean.c:15
static int cols
Definition: pbmmask.c:21
#define ARGS(alist)
Definition: pbmplus.h:235
unsigned int gray
Definition: pgm.h:10
unsigned long pixel
Definition: png22pnm.c:123
void ppm_init()
void ppm_readppminit()
gray pixval
Definition: ppm.h:9
pixel ** ppm_readppm()
void ppm_writeppminit()
char * ppm_colorname()
pixel ppm_parsecolor()
void ppm_writeppm()
pixval ppm_pbmmaxval
Definition: libppm1.c:50
void ppm_readppmrow()
void ppm_writeppmrow()
int g
Definition: ppmqvga.c:68
int r
Definition: ppmqvga.c:68
Definition: filedef.h:30
Definition: ppm.h:33
pixval b
Definition: ppm.h:34
#define FILE
Definition: t1stdio.h:34
#define argv
Definition: xmain.c:270