summaryrefslogtreecommitdiff
path: root/include/pbmplus.h
blob: e9ebcdf283f83c9b952de54f978022cbe81d01ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* pbmplus.h - header file for PBM, PGM, PPM, and PNM

Copyright (C) 1988, 1989, 1991, 2011 Jef Poskanzer.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 

   Configuration options modified for GNU --karl.
*/

#ifndef _PBMPLUS_H_
#define _PBMPLUS_H_

#include <sys/types.h>
#include <stdio.h>

#include "config.h"


#if 0 /* karl */
#if ! ( defined(BSD) || defined(SYSV) || defined(MSDOS))
/* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
** System V site, set the SYSV option; and if you're IBM-compatible, set
** MSDOS.  If your compiler is ANSI C, you're probably better off setting
** SYSV.
*/
#define BSD
/* #define SYSV */
/* #define MSDOS */
#endif
#endif

/* CONFIGURE: If you want to enable writing "raw" files, set this option.
** "Raw" files are smaller, and much faster to read and write, but you
** must have a filesystem that allows all 256 ASCII characters to be read
** and written.  You will no longer be able to mail P?M files without 
** using uuencode or the equivalent, or running the files through pnmnoraw.
** Note that reading "raw" files works whether writing is enabled or not.
*/
#define PBMPLUS_RAWBITS

/* CONFIGURE: On some systems, the putc() macro is broken and will return
** EOF when you write out a 255.  For example, ULTRIX does this.  This
** only matters if you have defined RAWBITS.  To test whether your system
** is broken this way, go ahead and compile things with RAWBITS defined,
** and then try "pbmmake -b 8 1 > file".  If it works, fine.  If not,
** define BROKENPUTC1 and try again - if that works, good.  Otherwise,
** BROKENPUTC2 is guaranteed to work, although it's about twice as slow.
*/
/* #define PBMPLUS_BROKENPUTC1 */
/* #define PBMPLUS_BROKENPUTC2 */

#ifdef PBMPLUS_BROKENPUTC1
#undef putc
/* This is a fixed version of putc() that should work on most Unix systems. */
#define putc(x,p) (--(p)->_cnt>=0? ((int)(unsigned char)(*(p)->_ptr++=(unsigned char)(x))) : _flsbuf((unsigned char)(x),p))
#endif /*PBMPLUS_BROKENPUTC1*/
#ifdef PBMPLUS_BROKENPUTC2
#undef putc
/* For this one, putc() becomes a function, defined in pbm/libpbm1.c. */
#endif /*PBMPLUS_BROKENPUTC2*/

/* CONFIGURE: PGM can store gray values as either bytes or shorts.  For most
** applications, bytes will be big enough, and the memory savings can be
** substantial.  However, if you need more than 8 bits of resolution, then
** define this symbol.
**
** If you are not making PGM, you can ignore this.
*/
/* #define PGM_BIGGRAYS */

/* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
** It can also be configured to pack the three values into a single longword,
** 10 bits each.  If you have configured PGM with the PGM_BIGGRAYS option
** (store grays as shorts), AND you don't need more than 10 bits for each
** color component, AND you care more about memory use than speed, then
** this option might be a win.  Under these circumstances it will make
** some of the programs use 1.5 times less space,  but all of the programs
** will run about 1.4 times slower.
**
** If you are not using PGM_BIGGRAYS, then this option is useless -- it
** doesn't save any space, but it still slows things down.
**
** If you are not making PPM, you can ignore this.
*/
/* #define PPM_PACKCOLORS */

/* CONFIGURE: uncomment this to enable debugging checks. */
/* #define DEBUG */

#if 0 /* karl */
#ifdef SYSV
#include <string.h>
#define index strchr
#define rindex strrchr
#define srandom srand
#define random rand
#define bzero(dst,len) memset(dst, 0, len)
#define bcopy(src,dst,len) memcpy(dst, src, len)
#define bcmp memcmp
#else /*SYSV*/
#include <strings.h>
#endif /*SYSV*/
#endif /* 0 */

/* CONFIGURE: On some systems, malloc.h doesn't declare these, so we have
** to do it.  On other systems, for example HP/UX, it declares them
** incompatibly.  And some systems, for example Dynix, don't have a
** malloc.h at all.  A sad situation.  If you have compilation problems
** that point here, feel free to tweak or remove these declarations.
*/
/* Thank you, I did remove them:
#include <malloc.h>
extern char* malloc();
extern char* realloc();
extern char* calloc();
*/
/* End of configurable definitions. */


#undef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#undef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#undef abs
#define abs(a) ((a) >= 0 ? (a) : -(a))
#undef odd
#define odd(n) ((n) & 1)


/* Definitions to make PBMPLUS work with either ANSI C or C Classic. */

#if __STDC__
#define ARGS(alist) alist
#else /*__STDC__*/
#define ARGS(alist) ()
#define const
#endif /*__STDC__*/


/* Initialization. */

void pm_init ARGS(( int* argcP, char* argv[] ));


/* Variable-sized arrays definitions. */

char** pm_allocarray ARGS(( int cols, int rows, int size ));
char* pm_allocrow ARGS(( int cols, int size ));
void pm_freearray ARGS(( char** its, int rows ));
void pm_freerow ARGS(( char* itrow ));


/* Case-insensitive keyword matcher. */

int pm_keymatch ARGS(( char* str, char* keyword, int minchars ));


/* Log base two hacks. */

int pm_maxvaltobits ARGS(( int maxval ));
int pm_bitstomaxval ARGS(( int bits ));


/* Error handling definitions. */

void pm_message( /* char* fmt, char* v1, char* v2, char* v3, char* v4, char* v5 */ );	/* prototypes can't handle this */
void pm_error( /* char* fmt, char* v1, char* v2, char* v3, char* v4, char* v5 */ );	/* doesn't return */
void pm_perror ARGS(( char* reason ));			/* doesn't return */
void pm_usage ARGS(( char* usage ));			/* doesn't return */


/* File open/close that handles "-" as stdin and checks errors. */

FILE* pm_openr ARGS(( char* name ));
FILE* pm_openw ARGS(( char* name ));
void pm_close ARGS(( FILE* f ));


/* Endian I/O. */

int pm_readbigshort ARGS(( FILE* in, short* sP ));
int pm_writebigshort ARGS(( FILE* out, short s ));
int pm_readbiglong ARGS(( FILE* in, long* lP ));
int pm_writebiglong ARGS(( FILE* out, long l ));
int pm_readlittleshort ARGS(( FILE* in, short* sP ));
int pm_writelittleshort ARGS(( FILE* out, short s ));
int pm_readlittlelong ARGS(( FILE* in, long* lP ));
int pm_writelittlelong ARGS(( FILE* out, long l ));


#endif /*_PBMPLUS_H_*/