1 #ifndef PBM_H_INCLUDED
2 #define PBM_H_INCLUDED
3 
4 #include <netpbm/pm.h>
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 #if 0
10 } /* to fake out automatic code indenters */
11 #endif
12 
13 typedef unsigned char bit;
14 #define PBM_WHITE 0
15 #define PBM_BLACK 1
16 
17 
18 /* Magic constants. */
19 
20 #define PBM_MAGIC1 'P'
21 #define PBM_MAGIC2 '1'
22 #define RPBM_MAGIC2 '4'
23 #define PBM_FORMAT (PBM_MAGIC1 * 256 + PBM_MAGIC2)
24 #define RPBM_FORMAT (PBM_MAGIC1 * 256 + RPBM_MAGIC2)
25 #define PBM_TYPE PBM_FORMAT
26 
27 
28 /* Macro for turning a format number into a type number. */
29 
30 #define PBM_FORMAT_TYPE(f) \
31   ((f) == PBM_FORMAT || (f) == RPBM_FORMAT ? PBM_TYPE : -1)
32 
33 
34 /* Declarations of routines. */
35 
36 void
37 pbm_init(int *   const argcP,
38          char ** const argv);
39 
40 void
41 pbm_nextimage(FILE *file, int * const eofP);
42 
43 bit *
44 pbm_allocrow(unsigned int const cols);
45 
46 #define pbm_allocarray(cols, rows) \
47   ((bit**) pm_allocarray(cols, rows, sizeof(bit)))
48 #define pbm_freearray(bits, rows) pm_freearray((char**) bits, rows)
49 #define pbm_freerow(bitrow) pm_freerow((char*) bitrow)
50 #define pbm_packed_bytes(cols) (((cols)+7)/8)
51 #define pbm_allocrow_packed(cols) \
52     ((unsigned char *) pm_allocrow(pbm_packed_bytes(cols), \
53                                    sizeof(unsigned char)))
54 #define pbm_freerow_packed(packed_bits) \
55     pm_freerow((char *) packed_bits)
56 #define pbm_allocarray_packed(cols, rows) ((unsigned char **) \
57     pm_allocarray(pbm_packed_bytes(cols), rows, sizeof(unsigned char)))
58 #define pbm_freearray_packed(packed_bits, rows) \
59     pm_freearray((char **) packed_bits, rows)
60 
61 bit**
62 pbm_readpbm(FILE * const file,
63             int  * const colsP,
64             int  * const rowsP);
65 
66 void
67 pbm_readpbminit(FILE * const file,
68                 int  * const colsP,
69                 int  * const rowsP, int * const formatP);
70 
71 void
72 pbm_readpbmrow(FILE * const file,
73                bit  * const bitrow,
74                int    const cols,
75                int    const format);
76 
77 void
78 pbm_readpbmrow_packed(FILE *          const file,
79                       unsigned char * const packedBits,
80                       int             const cols,
81                       int             const format);
82 
83 void
84 pbm_readpbmrow_bitoffset(FILE *          const fileP,
85                          unsigned char * const packedBits,
86                          int             const cols,
87                          int             const format,
88                          unsigned int    const offset);
89 
90 void
91 pbm_cleanrowend_packed(unsigned char * const packedBits,
92                        unsigned int    const cols);
93 
94 void
95 pbm_writepbminit(FILE * const fileP,
96                  int    const cols,
97                  int    const rows,
98                  int    const forceplain);
99 
100 void
101 pbm_writepbm(FILE * const fileP,
102              bit ** const bits,
103              int    const cols,
104              int    const rows,
105              int    const forceplain);
106 
107 void
108 pbm_writepbmrow(FILE *      const fileP,
109                 const bit * const bitrow,
110                 int         const cols,
111                 int         const forceplain);
112 
113 void
114 pbm_writepbmrow_packed(FILE *                const fileP,
115                        const unsigned char * const packed_bits,
116                        int                   const cols,
117                        int                   const forceplain);
118 
119 void
120 pbm_writepbmrow_bitoffset(FILE *          const ifP,
121                           unsigned char * const packedBits,
122                           unsigned int    const cols,
123                           int             const format,
124                           unsigned int    const offset);
125 
126 void
127 pbm_check(FILE * file, const enum pm_check_type check_type,
128           const int format, const int cols, const int rows,
129           enum pm_check_code * const retval_p);
130 
131 bit
132 pbm_backgroundbitrow(const unsigned char * const packedBits,
133                      unsigned int          const cols,
134                      unsigned int          const offset);
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif
141