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