]> git.saurik.com Git - wxWidgets.git/blob - src/xpm/xpm34p.h
If we used 10% less inline functions in useless occasions,
[wxWidgets.git] / src / xpm / xpm34p.h
1 /*
2 * Copyright (C) 1989-94 GROUPE BULL
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 *
21 * Except as contained in this notice, the name of GROUPE BULL shall not be
22 * used in advertising or otherwise to promote the sale, use or other dealings
23 * in this Software without prior written authorization from GROUPE BULL.
24 */
25
26 /*****************************************************************************\
27 * xpmP.h: *
28 * *
29 * XPM library *
30 * Private Include file *
31 * *
32 * Developed by Arnaud Le Hors *
33 \*****************************************************************************/
34
35 /*
36 * The code related to FOR_MSW has been added by
37 * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
38 */
39
40 #ifndef XPMP_h
41 #define XPMP_h
42
43 #include "xpm34.h"
44
45 /*
46 * lets try to solve include files
47 */
48 #ifdef VMS
49
50 #include "sys$library:stdio.h"
51 #include "sys$library:string.h"
52
53 #else /* VMS */
54
55 #include <stdio.h>
56 /* stdio.h doesn't declare popen on a Sequent DYNIX OS */
57 #ifdef sequent
58 extern FILE *popen();
59 #endif
60
61 #if defined(SYSV) || defined(SVR4)
62 #include <string.h>
63
64 #ifndef index
65 #define index strchr
66 #endif
67
68 #ifndef rindex
69 #define rindex strrchr
70 #endif
71
72 #else /* defined(SYSV) || defined(SVR4) */
73 #include <strings.h>
74 #endif
75
76 #endif /* VMS */
77
78
79 #if (defined(SYSV) || defined(SVR4) || defined(VMS)) && !defined(__sgi)
80 #define bcopy(source, dest, count) memcpy(dest, source, count)
81 #define bzero(b, len) memset(b, 0, len)
82 #endif
83
84
85 /* the following should help people wanting to use their own functions */
86 #ifndef FOR_MSW
87 #define XpmMalloc(size) malloc((size))
88 #define XpmRealloc(ptr, size) realloc((ptr), (size))
89 #define XpmCalloc(nelem, elsize) calloc((nelem), (elsize))
90 #else
91 /* checks for mallocs bigger than 64K */
92 #define XpmMalloc(size) boundCheckingMalloc((long)(size))/* in simx.[ch] */
93 #define XpmRealloc(ptr, size) boundCheckingRealloc((ptr),(long)(size))
94 #define XpmCalloc(nelem, elsize) \
95 boundCheckingCalloc((long)(nelem),(long) (elsize))
96 #endif
97
98
99 typedef struct {
100 unsigned int type;
101 union {
102 FILE *file;
103 char **data;
104 } stream;
105 char *cptr;
106 unsigned int line;
107 int CommentLength;
108 char Comment[BUFSIZ];
109 char *Bcmt, *Ecmt, Bos, Eos;
110 int format; /* 1 if XPM1, 0 otherwise */
111 } xpmData;
112
113 #define XPMARRAY 0
114 #define XPMFILE 1
115 #define XPMPIPE 2
116 #define XPMBUFFER 3
117
118 #define EOL '\n'
119 #define TAB '\t'
120 #define SPC ' '
121
122 typedef struct {
123 char *type; /* key word */
124 char *Bcmt; /* string beginning comments */
125 char *Ecmt; /* string ending comments */
126 char Bos; /* character beginning strings */
127 char Eos; /* character ending strings */
128 char *Strs; /* strings separator */
129 char *Dec; /* data declaration string */
130 char *Boa; /* string beginning assignment */
131 char *Eoa; /* string ending assignment */
132 } xpmDataType;
133
134 extern xpmDataType xpmDataTypes[];
135
136 /*
137 * rgb values and ascii names (from rgb text file) rgb values,
138 * range of 0 -> 65535 color mnemonic of rgb value
139 */
140 typedef struct {
141 int r, g, b;
142 char *name;
143 } xpmRgbName;
144
145 /* Maximum number of rgb mnemonics allowed in rgb text file. */
146 #define MAX_RGBNAMES 1024
147
148 extern char *xpmColorKeys[];
149
150 #define TRANSPARENT_COLOR "None" /* this must be a string! */
151
152 /* number of xpmColorKeys */
153 #define NKEYS 5
154
155 /* XPM private routines */
156
157 FUNC(xpmWriteData, int, (xpmData *mdata, XpmImage *image, char *name,
158 XpmInfo *info));
159
160 FUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info));
161
162 FUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors));
163
164 FUNC(xpmInitAttributes, void, (XpmAttributes *attributes));
165
166 FUNC(xpmInitXpmImage, void, (XpmImage *image));
167
168 FUNC(xpmInitXpmInfo, void, (XpmInfo *info));
169
170 FUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes));
171 FUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes));
172 FUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image,
173 XpmInfo *info));
174
175 #ifndef FOR_MSW
176 FUNC(xpmCreatePixmapFromImage, void, (Display *display, Drawable d,
177 XImage *ximage, Pixmap *pixmap_return));
178
179 FUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap,
180 XImage **ximage_return,
181 unsigned int *width,
182 unsigned int *height));
183 #endif
184
185 /* I/O utility */
186
187 FUNC(xpmNextString, int, (xpmData *mdata));
188 FUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return));
189 FUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l));
190
191 #define xpmGetC(mdata) \
192 ((!mdata->type || mdata->type == XPMBUFFER) ? \
193 (*mdata->cptr++) : (getc(mdata->stream.file)))
194
195 FUNC(xpmNextWord, unsigned int,
196 (xpmData *mdata, char *buf, unsigned int buflen));
197 FUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt));
198 FUNC(xpmReadFile, int, (char *filename, xpmData *mdata));
199 FUNC(xpmWriteFile, int, (char *filename, xpmData *mdata));
200 FUNC(xpmOpenArray, void, (char **data, xpmData *mdata));
201 FUNC(xpmDataClose, int, (xpmData *mdata));
202 FUNC(xpmParseHeader, int, (xpmData *mdata));
203 FUNC(xpmOpenBuffer, void, (char *buffer, xpmData *mdata));
204
205 /* RGB utility */
206
207 FUNC(xpmReadRgbNames, int, (char *rgb_fname, xpmRgbName *rgbn));
208 FUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max,
209 int red, int green, int blue));
210 FUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max));
211 #ifdef FOR_MSW
212 FUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b));
213 #endif
214
215 FUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp,
216 register XImage *img));
217 FUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
218 register XImage *img));
219
220 /*
221 * Macros
222 *
223 * The XYNORMALIZE macro determines whether XY format data requires
224 * normalization and calls a routine to do so if needed. The logic in
225 * this module is designed for LSBFirst byte and bit order, so
226 * normalization is done as required to present the data in this order.
227 *
228 * The ZNORMALIZE macro performs byte and nibble order normalization if
229 * required for Z format data.
230 *
231 * The XYINDEX macro computes the index to the starting byte (char) boundary
232 * for a bitmap_unit containing a pixel with coordinates x and y for image
233 * data in XY format.
234 *
235 * The ZINDEX* macros compute the index to the starting byte (char) boundary
236 * for a pixel with coordinates x and y for image data in ZPixmap format.
237 *
238 */
239
240 #define XYNORMALIZE(bp, img) \
241 if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \
242 xpm_xynormalizeimagebits((unsigned char *)(bp), img)
243
244 #define ZNORMALIZE(bp, img) \
245 if (img->byte_order == MSBFirst) \
246 xpm_znormalizeimagebits((unsigned char *)(bp), img)
247
248 #define XYINDEX(x, y, img) \
249 ((y) * img->bytes_per_line) + \
250 (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3)
251
252 #define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \
253 (((x) * img->bits_per_pixel) >> 3)
254
255 #define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2)
256
257 #define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1)
258
259 #define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x)
260
261 #define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3)
262
263 #if __STDC__
264 #define Const const
265 #else
266 #define Const /**/
267 #endif
268
269 /*
270 * there are structures and functions related to hastable code
271 */
272
273 typedef struct _xpmHashAtom {
274 char *name;
275 void *data;
276 } *xpmHashAtom;
277
278 typedef struct {
279 int size;
280 int limit;
281 int used;
282 xpmHashAtom *atomTable;
283 } xpmHashTable;
284
285 FUNC(xpmHashTableInit, int, (xpmHashTable *table));
286 FUNC(xpmHashTableFree, void, (xpmHashTable *table));
287 FUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s));
288 FUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data));
289
290 #define HashAtomData(i) ((void *)i)
291 #define HashColorIndex(slot) ((unsigned int)(unsigned long)((*slot)->data))
292 #define USE_HASHTABLE (cpp > 2 && ncolors > 4)
293
294 #ifdef NEED_STRDUP
295 FUNC(strdup, char *, (char *s1));
296 #endif
297
298 #ifdef NEED_STRCASECMP
299 FUNC(strcasecmp, int, (char *s1, char *s2));
300 #endif
301
302 FUNC(atoui, unsigned int, (char *p, unsigned int l, unsigned int *ui_return));
303
304 #endif