Debian Codegraph @

src/XpmI.h

raw
1 /*
2 * Copyright (C) 1989-95 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 * XpmI.h: *
28 * *
29 * XPM library *
30 * Internal Include file *
31 * *
32 * ** Everything defined here is subject to changes any time. ** *
33 * *
34 * Developed by Arnaud Le Hors *
35 \*****************************************************************************/
36
37 #ifndef XPMI_h
38 #define XPMI_h
39
40 #include "xpm.h"
41
42 /*
43 * lets try to solve include files
44 */
45
46 #include <sys/types.h>
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <limits.h>
50 #include <string.h>
51 #if !defined(_MSC_VER)
52 #include <strings.h>
53 #endif
54
55 #include <X11/Xos.h>
56 #include <X11/Xfuncs.h>
57 #include <X11/Xmd.h>
58
59 #ifdef VMS
60 #include <unixio.h>
61 #include <file.h>
62 #endif
63
64 /* The following should help people wanting to use their own memory allocation
65 * functions. To avoid the overhead of a function call when the standard
66 * functions are used these are all macros, even the XpmFree function which
67 * needs to be a real function for the outside world though.
68 * So if change these be sure to change the XpmFree function in misc.c
69 * accordingly.
70 */
71 #define XpmFree(ptr) free(ptr)
72
73 #define XpmMalloc(size) malloc((size))
74 #define XpmRealloc(ptr, size) realloc((ptr), (size))
75 #define XpmCalloc(nelem, elsize) calloc((nelem), (elsize))
76
77 #include <stdint.h> /* For SIZE_MAX */
78 #include <limits.h>
79 #ifndef SIZE_MAX
80 # ifdef ULONG_MAX
81 # define SIZE_MAX ULONG_MAX
82 # else
83 # define SIZE_MAX UINT_MAX
84 # endif
85 #endif
86
87 #ifdef O_CLOEXEC
88 # define FOPEN_CLOEXEC "e"
89 #else
90 # define FOPEN_CLOEXEC ""
91 # define O_CLOEXEC 0
92 #endif
93
94 #define XPMMAXCMTLEN BUFSIZ
95 typedef struct {
96 unsigned int type;
97 union {
98 FILE *file;
99 char **data;
100 } stream;
101 char *cptr;
102 unsigned int line;
103 int CommentLength;
104 char Comment[XPMMAXCMTLEN];
105 const char *Bcmt, *Ecmt;
106 char Bos, Eos;
107 int format; /* 1 if XPM1, 0 otherwise */
108 #ifdef CXPMPROG
109 int lineNum;
110 int charNum;
111 #endif
112 } xpmData;
113
114 #define XPMARRAY 0
115 #define XPMFILE 1
116 #define XPMPIPE 2
117 #define XPMBUFFER 3
118
119 #define EOL '\n'
120 #define TAB '\t'
121 #define SPC ' '
122
123 typedef struct {
124 const char *type; /* key word */
125 const char *Bcmt; /* string beginning comments */
126 const char *Ecmt; /* string ending comments */
127 char Bos; /* character beginning strings */
128 char Eos; /* character ending strings */
129 const char *Strs; /* strings separator */
130 const char *Dec; /* data declaration string */
131 const char *Boa; /* string beginning assignment */
132 const char *Eoa; /* string ending assignment */
133 } xpmDataType;
134
135 extern _X_HIDDEN xpmDataType xpmDataTypes[];
136
137 /*
138 * rgb values and ascii names (from rgb text file) rgb values,
139 * range of 0 -> 65535 color mnemonic of rgb value
140 */
141 typedef struct {
142 int r, g, b;
143 char *name;
144 } xpmRgbName;
145
146 /* Maximum number of rgb mnemonics allowed in rgb text file. */
147 #define MAX_RGBNAMES 1024
148
149 extern _X_HIDDEN const char *xpmColorKeys[];
150
151 #define TRANSPARENT_COLOR "None" /* this must be a string! */
152
153 /* number of xpmColorKeys */
154 #define NKEYS 5
155
156 /* XPM internal routines */
157
158 HFUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info));
159 HFUNC(xpmParseDataAndCreate, int, (Display *display, xpmData *data,
160 XImage **image_return,
161 XImage **shapeimage_return,
162 XpmImage *image, XpmInfo *info,
163 XpmAttributes *attributes));
164
165 HFUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors));
166
167 HFUNC(xpmInitAttributes, void, (XpmAttributes *attributes));
168
169 HFUNC(xpmInitXpmImage, void, (XpmImage *image));
170
171 HFUNC(xpmInitXpmInfo, void, (XpmInfo *info));
172
173 HFUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes));
174 HFUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes));
175 HFUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image,
176 XpmInfo *info));
177
178 HFUNC(xpmCreatePixmapFromImage, int, (Display *display, Drawable d,
179 XImage *ximage, Pixmap *pixmap_return));
180
181 HFUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap,
182 XImage **ximage_return,
183 unsigned int *width,
184 unsigned int *height));
185
186 /* structures and functions related to hastable code */
187
188 typedef struct _xpmHashAtom {
189 char *name;
190 void *data;
191 } *xpmHashAtom;
192
193 typedef struct {
194 unsigned int size;
195 unsigned int limit;
196 unsigned int used;
197 xpmHashAtom *atomTable;
198 } xpmHashTable;
199
200 HFUNC(xpmHashTableInit, int, (xpmHashTable *table));
201 HFUNC(xpmHashTableFree, void, (xpmHashTable *table));
202 HFUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s));
203 HFUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data));
204
205 #if defined(_MSC_VER) && defined(_M_X64)
206 #define HashAtomData(i) ((void *)(long long)i)
207 #define HashColorIndex(slot) ((unsigned long long)((*slot)->data))
208 #else
209 #define HashAtomData(i) ((void *)(long)i)
210 #define HashColorIndex(slot) ((unsigned long)((*slot)->data))
211 #endif
212 #define USE_HASHTABLE (cpp > 2 && ncolors > 4)
213
214 /* I/O utility */
215
216 HFUNC(xpmNextString, int, (xpmData *mdata));
217 HFUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return));
218 HFUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l));
219
220 #define xpmGetC(mdata) \
221 ((!mdata->type || mdata->type == XPMBUFFER) ? \
222 (*mdata->cptr++) : (getc(mdata->stream.file)))
223
224 HFUNC(xpmNextWord, unsigned int,
225 (xpmData *mdata, char *buf, unsigned int buflen));
226 HFUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt));
227 HFUNC(xpmParseHeader, int, (xpmData *mdata));
228 HFUNC(xpmParseValues, int, (xpmData *data, unsigned int *width,
229 unsigned int *height, unsigned int *ncolors,
230 unsigned int *cpp, unsigned int *x_hotspot,
231 unsigned int *y_hotspot, unsigned int *hotspot,
232 unsigned int *extensions));
233
234 HFUNC(xpmParseColors, int, (xpmData *data, unsigned int ncolors,
235 unsigned int cpp, XpmColor **colorTablePtr,
236 xpmHashTable *hashtable));
237
238 HFUNC(xpmParseExtensions, int, (xpmData *data, XpmExtension **extensions,
239 unsigned int *nextensions));
240
241 /* RGB utility */
242
243 HFUNC(xpmReadRgbNames, int, (const char *rgb_fname, xpmRgbName *rgbn));
244 HFUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max,
245 int red, int green, int blue));
246 HFUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max));
247
248 HFUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp,
249 register XImage *img));
250 HFUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
251 register XImage *img));
252
253 /*
254 * Macros
255 *
256 * The XYNORMALIZE macro determines whether XY format data requires
257 * normalization and calls a routine to do so if needed. The logic in
258 * this module is designed for LSBFirst byte and bit order, so
259 * normalization is done as required to present the data in this order.
260 *
261 * The ZNORMALIZE macro performs byte and nibble order normalization if
262 * required for Z format data.
263 *
264 * The XYINDEX macro computes the index to the starting byte (char) boundary
265 * for a bitmap_unit containing a pixel with coordinates x and y for image
266 * data in XY format.
267 *
268 * The ZINDEX* macros compute the index to the starting byte (char) boundary
269 * for a pixel with coordinates x and y for image data in ZPixmap format.
270 *
271 */
272
273 #define XYNORMALIZE(bp, img) \
274 if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \
275 xpm_xynormalizeimagebits((unsigned char *)(bp), img)
276
277 #define ZNORMALIZE(bp, img) \
278 if (img->byte_order == MSBFirst) \
279 xpm_znormalizeimagebits((unsigned char *)(bp), img)
280
281 #define XYINDEX(x, y, img) \
282 ((y) * img->bytes_per_line) + \
283 (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3)
284
285 #define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \
286 (((x) * img->bits_per_pixel) >> 3)
287
288 #define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2)
289
290 #define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1)
291
292 #define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x)
293
294 #define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3)
295
296 HFUNC(xpmatoui, unsigned int,
297 (char *p, unsigned int l, unsigned int *ui_return));
298
299 #endif