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