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