XpmI.h revision edce3322
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
26a966c04fSmrg/*****************************************************************************\
27a966c04fSmrg* XpmI.h:                                                                     *
28a966c04fSmrg*                                                                             *
29a966c04fSmrg*  XPM library                                                                *
30a966c04fSmrg*  Internal Include file                                                      *
31a966c04fSmrg*                                                                             *
32a966c04fSmrg*  ** Everything defined here is subject to changes any time. **              *
33a966c04fSmrg*                                                                             *
34a966c04fSmrg*  Developed by Arnaud Le Hors                                                *
35a966c04fSmrg\*****************************************************************************/
36a966c04fSmrg
37a966c04fSmrg/*
38a966c04fSmrg * The code related to FOR_MSW has been added by
39a966c04fSmrg * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
40a966c04fSmrg */
41a966c04fSmrg
42a966c04fSmrg#ifndef XPMI_h
43a966c04fSmrg#define XPMI_h
44a966c04fSmrg
45a966c04fSmrg#include "xpm.h"
46a966c04fSmrg
47a966c04fSmrg/*
48a966c04fSmrg * lets try to solve include files
49a966c04fSmrg */
50a966c04fSmrg
51a966c04fSmrg#include <sys/types.h>
52a966c04fSmrg#include <stdio.h>
53a966c04fSmrg#include <stdlib.h>
54a966c04fSmrg#include <limits.h>
55a966c04fSmrg/* stdio.h doesn't declare popen on a Sequent DYNIX OS */
56a966c04fSmrg#ifdef sequent
57a966c04fSmrgextern FILE *popen();
58a966c04fSmrg#endif
59a966c04fSmrg
60a966c04fSmrg#ifdef FOR_MSW
61a966c04fSmrg#include "simx.h"
62a966c04fSmrg#else
63a966c04fSmrg#include <X11/Xos.h>
64a966c04fSmrg#include <X11/Xfuncs.h>
65a966c04fSmrg#include <X11/Xmd.h>
66a966c04fSmrg#endif
67a966c04fSmrg
68a966c04fSmrg#ifdef VMS
69a966c04fSmrg#include <unixio.h>
70a966c04fSmrg#include <file.h>
71a966c04fSmrg#endif
72a966c04fSmrg
73a966c04fSmrg/* The following should help people wanting to use their own memory allocation
74a966c04fSmrg * functions. To avoid the overhead of a function call when the standard
75a966c04fSmrg * functions are used these are all macros, even the XpmFree function which
76a966c04fSmrg * needs to be a real function for the outside world though.
77a966c04fSmrg * So if change these be sure to change the XpmFree function in misc.c
78a966c04fSmrg * accordingly.
79a966c04fSmrg */
80a966c04fSmrg#define XpmFree(ptr) free(ptr)
81a966c04fSmrg
82a966c04fSmrg#ifndef FOR_MSW
83a966c04fSmrg#define XpmMalloc(size) malloc((size))
84a966c04fSmrg#define XpmRealloc(ptr, size) realloc((ptr), (size))
85a966c04fSmrg#define XpmCalloc(nelem, elsize) calloc((nelem), (elsize))
86a966c04fSmrg#else
87a966c04fSmrg/* checks for mallocs bigger than 64K */
88a966c04fSmrg#define XpmMalloc(size) boundCheckingMalloc((long)(size))/* in simx.[ch] */
89a966c04fSmrg#define XpmRealloc(ptr, size) boundCheckingRealloc((ptr),(long)(size))
90a966c04fSmrg#define XpmCalloc(nelem, elsize) \
91a966c04fSmrg		boundCheckingCalloc((long)(nelem),(long) (elsize))
92a966c04fSmrg#endif
93a966c04fSmrg
94a966c04fSmrg#if defined(SCO) || defined(__USLC__)
95a966c04fSmrg#include <stdint.h>	/* For SIZE_MAX */
96a966c04fSmrg#endif
97a966c04fSmrg#include <limits.h>
98a966c04fSmrg#ifndef SIZE_MAX
99a966c04fSmrg# ifdef ULONG_MAX
100a966c04fSmrg#  define SIZE_MAX ULONG_MAX
10197cf2ee2Smrg# else
102a966c04fSmrg#  define SIZE_MAX UINT_MAX
103a966c04fSmrg# endif
104a966c04fSmrg#endif
105a966c04fSmrg
106a966c04fSmrg#define XPMMAXCMTLEN BUFSIZ
107a966c04fSmrgtypedef struct {
108a966c04fSmrg    unsigned int type;
109a966c04fSmrg    union {
110a966c04fSmrg	FILE *file;
111a966c04fSmrg	char **data;
112a966c04fSmrg    }     stream;
113a966c04fSmrg    char *cptr;
114a966c04fSmrg    unsigned int line;
115a966c04fSmrg    int CommentLength;
116a966c04fSmrg    char Comment[XPMMAXCMTLEN];
11797cf2ee2Smrg    const char *Bcmt, *Ecmt;
11897cf2ee2Smrg    char 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 {
13697cf2ee2Smrg    const char *type;		/* key word */
13797cf2ee2Smrg    const char *Bcmt;		/* string beginning comments */
13897cf2ee2Smrg    const char *Ecmt;		/* string ending comments */
139a966c04fSmrg    char Bos;			/* character beginning strings */
140a966c04fSmrg    char Eos;			/* character ending strings */
14197cf2ee2Smrg    const char *Strs;		/* strings separator */
14297cf2ee2Smrg    const char *Dec;		/* data declaration string */
14397cf2ee2Smrg    const char *Boa;		/* string beginning assignment */
14497cf2ee2Smrg    const 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
16197cf2ee2Smrgextern const 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
219edce3322Smrg#if defined(_MSC_VER) && defined(_M_X64)
220edce3322Smrg#define HashAtomData(i) ((void *)(long long)i)
221edce3322Smrg#define HashColorIndex(slot) ((unsigned long long)((*slot)->data))
222edce3322Smrg#else
223a966c04fSmrg#define HashAtomData(i) ((void *)(long)i)
224a966c04fSmrg#define HashColorIndex(slot) ((unsigned long)((*slot)->data))
225edce3322Smrg#endif
226a966c04fSmrg#define USE_HASHTABLE (cpp > 2 && ncolors > 4)
227a966c04fSmrg
228a966c04fSmrg/* I/O utility */
229a966c04fSmrg
230a966c04fSmrgFUNC(xpmNextString, int, (xpmData *mdata));
231a966c04fSmrgFUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return));
232a966c04fSmrgFUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l));
233a966c04fSmrg
234a966c04fSmrg#define xpmGetC(mdata) \
235a966c04fSmrg	((!mdata->type || mdata->type == XPMBUFFER) ? \
236a966c04fSmrg	 (*mdata->cptr++) : (getc(mdata->stream.file)))
237a966c04fSmrg
238a966c04fSmrgFUNC(xpmNextWord, unsigned int,
239a966c04fSmrg     (xpmData *mdata, char *buf, unsigned int buflen));
240a966c04fSmrgFUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt));
241a966c04fSmrgFUNC(xpmParseHeader, int, (xpmData *mdata));
242a966c04fSmrgFUNC(xpmParseValues, int, (xpmData *data, unsigned int *width,
243a966c04fSmrg			   unsigned int *height, unsigned int *ncolors,
244a966c04fSmrg			   unsigned int *cpp, unsigned int *x_hotspot,
245a966c04fSmrg			   unsigned int *y_hotspot, unsigned int *hotspot,
246a966c04fSmrg			   unsigned int *extensions));
247a966c04fSmrg
248a966c04fSmrgFUNC(xpmParseColors, int, (xpmData *data, unsigned int ncolors,
249a966c04fSmrg			   unsigned int cpp, XpmColor **colorTablePtr,
250a966c04fSmrg			   xpmHashTable *hashtable));
251a966c04fSmrg
252a966c04fSmrgFUNC(xpmParseExtensions, int, (xpmData *data, XpmExtension **extensions,
253a966c04fSmrg			       unsigned int *nextensions));
254a966c04fSmrg
255a966c04fSmrg/* RGB utility */
256a966c04fSmrg
257a966c04fSmrgFUNC(xpmReadRgbNames, int, (char *rgb_fname, xpmRgbName *rgbn));
258a966c04fSmrgFUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max,
259a966c04fSmrg			     int red, int green, int blue));
260a966c04fSmrgFUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max));
261a966c04fSmrg#ifdef FOR_MSW
262a966c04fSmrgFUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b));
263a966c04fSmrg#endif
264a966c04fSmrg
265a966c04fSmrg#ifndef AMIGA
266a966c04fSmrgFUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp,
267a966c04fSmrg				      register XImage *img));
268a966c04fSmrgFUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
269a966c04fSmrg				     register XImage *img));
270a966c04fSmrg
271a966c04fSmrg/*
272a966c04fSmrg * Macros
273a966c04fSmrg *
274a966c04fSmrg * The XYNORMALIZE macro determines whether XY format data requires
275a966c04fSmrg * normalization and calls a routine to do so if needed. The logic in
276a966c04fSmrg * this module is designed for LSBFirst byte and bit order, so
277a966c04fSmrg * normalization is done as required to present the data in this order.
278a966c04fSmrg *
279a966c04fSmrg * The ZNORMALIZE macro performs byte and nibble order normalization if
280a966c04fSmrg * required for Z format data.
281a966c04fSmrg *
282a966c04fSmrg * The XYINDEX macro computes the index to the starting byte (char) boundary
283a966c04fSmrg * for a bitmap_unit containing a pixel with coordinates x and y for image
284a966c04fSmrg * data in XY format.
285a966c04fSmrg *
286a966c04fSmrg * The ZINDEX* macros compute the index to the starting byte (char) boundary
287a966c04fSmrg * for a pixel with coordinates x and y for image data in ZPixmap format.
288a966c04fSmrg *
289a966c04fSmrg */
290a966c04fSmrg
291a966c04fSmrg#define XYNORMALIZE(bp, img) \
292a966c04fSmrg    if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \
293a966c04fSmrg	xpm_xynormalizeimagebits((unsigned char *)(bp), img)
294a966c04fSmrg
295a966c04fSmrg#define ZNORMALIZE(bp, img) \
296a966c04fSmrg    if (img->byte_order == MSBFirst) \
297a966c04fSmrg	xpm_znormalizeimagebits((unsigned char *)(bp), img)
298a966c04fSmrg
299a966c04fSmrg#define XYINDEX(x, y, img) \
300a966c04fSmrg    ((y) * img->bytes_per_line) + \
301a966c04fSmrg    (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3)
302a966c04fSmrg
303a966c04fSmrg#define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \
304a966c04fSmrg    (((x) * img->bits_per_pixel) >> 3)
305a966c04fSmrg
306a966c04fSmrg#define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2)
307a966c04fSmrg
308a966c04fSmrg#define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1)
309a966c04fSmrg
310a966c04fSmrg#define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x)
311a966c04fSmrg
312a966c04fSmrg#define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3)
313a966c04fSmrg#endif /* not AMIGA */
314a966c04fSmrg
315a966c04fSmrg#ifdef NEED_STRDUP
316a966c04fSmrgFUNC(xpmstrdup, char *, (char *s1));
317a966c04fSmrg#else
318a966c04fSmrg#undef xpmstrdup
319a966c04fSmrg#define xpmstrdup strdup
32097cf2ee2Smrg#include <string.h>
321a966c04fSmrg#endif
322a966c04fSmrg
32397cf2ee2Smrg#ifdef NEED_STRCASECMP
324a966c04fSmrgFUNC(xpmstrcasecmp, int, (char *s1, char *s2));
325a966c04fSmrg#else
326a966c04fSmrg#undef xpmstrcasecmp
327a966c04fSmrg#define xpmstrcasecmp strcasecmp
32897cf2ee2Smrg#include <strings.h>
329a966c04fSmrg#endif
330a966c04fSmrg
331a966c04fSmrgFUNC(xpmatoui, unsigned int,
332a966c04fSmrg     (char *p, unsigned int l, unsigned int *ui_return));
333a966c04fSmrg
334a966c04fSmrg#endif
335