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 * xpm.h:                                                                      *
28 *                                                                             *
29 *  XPM library                                                                *
30 *  Include file                                                               *
31 *                                                                             *
32 *  Developed by Arnaud Le Hors                                                *
33 \*****************************************************************************/
34 
35 /*
36  * The code related to FOR_MSW has been added by
37  * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
38  */
39 
40 /*
41  * The code related to AMIGA has been added by
42  * Lorens Younes (d93-hyo@nada.kth.se) 4/96
43  */
44 
45 #ifndef XPM_h
46 #define XPM_h
47 
48 /*
49  * first some identification numbers:
50  * the version and revision numbers are determined with the following rule:
51  * SO Major number = LIB minor version number.
52  * SO Minor number = LIB sub-minor version number.
53  * e.g: Xpm version 3.2f
54  *      we forget the 3 which is the format number, 2 gives 2, and f gives 6.
55  *      thus we have XpmVersion = 2 and XpmRevision = 6
56  *      which gives  SOXPMLIBREV = 2.6
57  *
58  * Then the XpmIncludeVersion number is built from these numbers.
59  */
60 #define XpmFormat 3
61 #define XpmVersion 4
62 #define XpmRevision 11
63 #define XpmIncludeVersion ((XpmFormat * 100 + XpmVersion) * 100 + XpmRevision)
64 
65 #ifndef XPM_NUMBERS
66 
67 #ifdef FOR_MSW
68 # define SYSV			/* uses memcpy string.h etc. */
69 # include <malloc.h>
70 # include "simx.h"		/* defines some X stuff using MSW types */
71 #define NEED_STRCASECMP		/* at least for MSVC++ */
72 #else /* FOR_MSW */
73 # ifdef AMIGA
74 #  include "amigax.h"
75 # else /* not AMIGA */
76 #  include <X11/Xlib.h>
77 #  include <X11/Xutil.h>
78 # endif /* not AMIGA */
79 #endif /* FOR_MSW */
80 
81 /* let's define Pixel if it is not done yet */
82 #if ! defined(_XtIntrinsic_h) && ! defined(PIXEL_ALREADY_TYPEDEFED)
83 typedef unsigned long Pixel;	/* Index into colormap */
84 # define PIXEL_ALREADY_TYPEDEFED
85 #endif
86 
87 /* Return ErrorStatus codes:
88  * null     if full success
89  * positive if partial success
90  * negative if failure
91  */
92 
93 #define XpmColorError    1
94 #define XpmSuccess       0
95 #define XpmOpenFailed   -1
96 #define XpmFileInvalid  -2
97 #define XpmNoMemory     -3
98 #define XpmColorFailed  -4
99 
100 typedef struct {
101     char *name;			/* Symbolic color name */
102     char *value;		/* Color value */
103     Pixel pixel;		/* Color pixel */
104 }      XpmColorSymbol;
105 
106 typedef struct {
107     char *name;			/* name of the extension */
108     unsigned int nlines;	/* number of lines in this extension */
109     char **lines;		/* pointer to the extension array of strings */
110 }      XpmExtension;
111 
112 typedef struct {
113     char *string;		/* characters string */
114     char *symbolic;		/* symbolic name */
115     char *m_color;		/* monochrom default */
116     char *g4_color;		/* 4 level grayscale default */
117     char *g_color;		/* other level grayscale default */
118     char *c_color;		/* color default */
119 }      XpmColor;
120 
121 typedef struct {
122     unsigned int width;		/* image width */
123     unsigned int height;	/* image height */
124     unsigned int cpp;		/* number of characters per pixel */
125     unsigned int ncolors;	/* number of colors */
126     XpmColor *colorTable;	/* list of related colors */
127     unsigned int *data;		/* image data */
128 }      XpmImage;
129 
130 typedef struct {
131     unsigned long valuemask;	/* Specifies which attributes are defined */
132     char *hints_cmt;		/* Comment of the hints section */
133     char *colors_cmt;		/* Comment of the colors section */
134     char *pixels_cmt;		/* Comment of the pixels section */
135     unsigned int x_hotspot;	/* Returns the x hotspot's coordinate */
136     unsigned int y_hotspot;	/* Returns the y hotspot's coordinate */
137     unsigned int nextensions;	/* number of extensions */
138     XpmExtension *extensions;	/* pointer to array of extensions */
139 }      XpmInfo;
140 
141 typedef int (*XpmAllocColorFunc)(
142     Display*			/* display */,
143     Colormap			/* colormap */,
144     char*			/* colorname */,
145     XColor*			/* xcolor */,
146     void*			/* closure */
147 );
148 
149 typedef int (*XpmFreeColorsFunc)(
150     Display*			/* display */,
151     Colormap			/* colormap */,
152     Pixel*			/* pixels */,
153     int				/* npixels */,
154     void*			/* closure */
155 );
156 
157 typedef struct {
158     unsigned long valuemask;		/* Specifies which attributes are
159 					   defined */
160 
161     Visual *visual;			/* Specifies the visual to use */
162     Colormap colormap;			/* Specifies the colormap to use */
163     unsigned int depth;			/* Specifies the depth */
164     unsigned int width;			/* Returns the width of the created
165 					   pixmap */
166     unsigned int height;		/* Returns the height of the created
167 					   pixmap */
168     unsigned int x_hotspot;		/* Returns the x hotspot's
169 					   coordinate */
170     unsigned int y_hotspot;		/* Returns the y hotspot's
171 					   coordinate */
172     unsigned int cpp;			/* Specifies the number of char per
173 					   pixel */
174     Pixel *pixels;			/* List of used color pixels */
175     unsigned int npixels;		/* Number of used pixels */
176     XpmColorSymbol *colorsymbols;	/* List of color symbols to override */
177     unsigned int numsymbols;		/* Number of symbols */
178     char *rgb_fname;			/* RGB text file name */
179     unsigned int nextensions;		/* Number of extensions */
180     XpmExtension *extensions;		/* List of extensions */
181 
182     unsigned int ncolors;               /* Number of colors */
183     XpmColor *colorTable;               /* List of colors */
184 /* 3.2 backward compatibility code */
185     char *hints_cmt;                    /* Comment of the hints section */
186     char *colors_cmt;                   /* Comment of the colors section */
187     char *pixels_cmt;                   /* Comment of the pixels section */
188 /* end 3.2 bc */
189     unsigned int mask_pixel;            /* Color table index of transparent
190                                            color */
191 
192     /* Color Allocation Directives */
193     Bool exactColors;			/* Only use exact colors for visual */
194     unsigned int closeness;		/* Allowable RGB deviation */
195     unsigned int red_closeness;		/* Allowable red deviation */
196     unsigned int green_closeness;	/* Allowable green deviation */
197     unsigned int blue_closeness;	/* Allowable blue deviation */
198     int color_key;			/* Use colors from this color set */
199 
200     Pixel *alloc_pixels;		/* Returns the list of alloc'ed color
201 					   pixels */
202     int nalloc_pixels;			/* Returns the number of alloc'ed
203 					   color pixels */
204 
205     Bool alloc_close_colors;    	/* Specify whether close colors should
206 					   be allocated using XAllocColor
207 					   or not */
208     int bitmap_format;			/* Specify the format of 1bit depth
209 					   images: ZPixmap or XYBitmap */
210 
211     /* Color functions */
212     XpmAllocColorFunc alloc_color;	/* Application color allocator */
213     XpmFreeColorsFunc free_colors;	/* Application color de-allocator */
214     void *color_closure;		/* Application private data to pass to
215 					   alloc_color and free_colors */
216 
217 }      XpmAttributes;
218 
219 /* XpmAttributes value masks bits */
220 #define XpmVisual	   (1L<<0)
221 #define XpmColormap	   (1L<<1)
222 #define XpmDepth	   (1L<<2)
223 #define XpmSize		   (1L<<3)	/* width & height */
224 #define XpmHotspot	   (1L<<4)	/* x_hotspot & y_hotspot */
225 #define XpmCharsPerPixel   (1L<<5)
226 #define XpmColorSymbols	   (1L<<6)
227 #define XpmRgbFilename	   (1L<<7)
228 /* 3.2 backward compatibility code */
229 #define XpmInfos	   (1L<<8)
230 #define XpmReturnInfos	   XpmInfos
231 /* end 3.2 bc */
232 #define XpmReturnPixels	   (1L<<9)
233 #define XpmExtensions      (1L<<10)
234 #define XpmReturnExtensions XpmExtensions
235 
236 #define XpmExactColors     (1L<<11)
237 #define XpmCloseness	   (1L<<12)
238 #define XpmRGBCloseness	   (1L<<13)
239 #define XpmColorKey	   (1L<<14)
240 
241 #define XpmColorTable      (1L<<15)
242 #define XpmReturnColorTable XpmColorTable
243 
244 #define XpmReturnAllocPixels (1L<<16)
245 #define XpmAllocCloseColors (1L<<17)
246 #define XpmBitmapFormat    (1L<<18)
247 
248 #define XpmAllocColor      (1L<<19)
249 #define XpmFreeColors      (1L<<20)
250 #define XpmColorClosure    (1L<<21)
251 
252 
253 /* XpmInfo value masks bits */
254 #define XpmComments        XpmInfos
255 #define XpmReturnComments  XpmComments
256 
257 /* XpmAttributes mask_pixel value when there is no mask */
258 #ifndef FOR_MSW
259 #define XpmUndefPixel 0x80000000
260 #else
261 /* int is only 16 bit for MSW */
262 #define XpmUndefPixel 0x8000
263 #endif
264 
265 /*
266  * color keys for visual type, they must fit along with the number key of
267  * each related element in xpmColorKeys[] defined in XpmI.h
268  */
269 #define XPM_MONO	2
270 #define XPM_GREY4	3
271 #define XPM_GRAY4	3
272 #define XPM_GREY 	4
273 #define XPM_GRAY 	4
274 #define XPM_COLOR	5
275 
276 
277 /* macros for forward declarations of functions with prototypes */
278 #define FUNC(f, t, p) extern t f p
279 #define LFUNC(f, t, p) static t f p
280 
281 
282 /*
283  * functions declarations
284  */
285 
286 _XFUNCPROTOBEGIN
287 
288 /* FOR_MSW, all ..Pixmap.. are excluded, only the ..XImage.. are used */
289 /* Same for Amiga! */
290 
291 #if !defined(FOR_MSW) && !defined(AMIGA)
292     FUNC(XpmCreatePixmapFromData, int, (Display *display,
293 					Drawable d,
294 					char **data,
295 					Pixmap *pixmap_return,
296 					Pixmap *shapemask_return,
297 					XpmAttributes *attributes));
298 
299     FUNC(XpmCreateDataFromPixmap, int, (Display *display,
300 					char ***data_return,
301 					Pixmap pixmap,
302 					Pixmap shapemask,
303 					XpmAttributes *attributes));
304 
305     FUNC(XpmReadFileToPixmap, int, (Display *display,
306 				    Drawable d,
307 				    const char *filename,
308 				    Pixmap *pixmap_return,
309 				    Pixmap *shapemask_return,
310 				    XpmAttributes *attributes));
311 
312     FUNC(XpmWriteFileFromPixmap, int, (Display *display,
313 				       const char *filename,
314 				       Pixmap pixmap,
315 				       Pixmap shapemask,
316 				       XpmAttributes *attributes));
317 #endif
318 
319     FUNC(XpmCreateImageFromData, int, (Display *display,
320 				       char **data,
321 				       XImage **image_return,
322 				       XImage **shapemask_return,
323 				       XpmAttributes *attributes));
324 
325     FUNC(XpmCreateDataFromImage, int, (Display *display,
326 				       char ***data_return,
327 				       XImage *image,
328 				       XImage *shapeimage,
329 				       XpmAttributes *attributes));
330 
331     FUNC(XpmReadFileToImage, int, (Display *display,
332 				   const char *filename,
333 				   XImage **image_return,
334 				   XImage **shapeimage_return,
335 				   XpmAttributes *attributes));
336 
337     FUNC(XpmWriteFileFromImage, int, (Display *display,
338 				      const char *filename,
339 				      XImage *image,
340 				      XImage *shapeimage,
341 				      XpmAttributes *attributes));
342 
343     FUNC(XpmCreateImageFromBuffer, int, (Display *display,
344 					 char *buffer,
345 					 XImage **image_return,
346 					 XImage **shapemask_return,
347 					 XpmAttributes *attributes));
348 #if !defined(FOR_MSW) && !defined(AMIGA)
349     FUNC(XpmCreatePixmapFromBuffer, int, (Display *display,
350 					  Drawable d,
351 					  char *buffer,
352 					  Pixmap *pixmap_return,
353 					  Pixmap *shapemask_return,
354 					  XpmAttributes *attributes));
355 
356     FUNC(XpmCreateBufferFromImage, int, (Display *display,
357 					 char **buffer_return,
358 					 XImage *image,
359 					 XImage *shapeimage,
360 					 XpmAttributes *attributes));
361 
362     FUNC(XpmCreateBufferFromPixmap, int, (Display *display,
363 					  char **buffer_return,
364 					  Pixmap pixmap,
365 					  Pixmap shapemask,
366 					  XpmAttributes *attributes));
367 #endif
368     FUNC(XpmReadFileToBuffer, int, (const char *filename, char **buffer_return));
369     FUNC(XpmWriteFileFromBuffer, int, (const char *filename, char *buffer));
370 
371     FUNC(XpmReadFileToData, int, (const char *filename, char ***data_return));
372     FUNC(XpmWriteFileFromData, int, (const char *filename, char **data));
373 
374     FUNC(XpmAttributesSize, int, (void));
375     FUNC(XpmFreeAttributes, void, (XpmAttributes *attributes));
376     FUNC(XpmFreeExtensions, void, (XpmExtension *extensions,
377 				   int nextensions));
378 
379     FUNC(XpmFreeXpmImage, void, (XpmImage *image));
380     FUNC(XpmFreeXpmInfo, void, (XpmInfo *info));
381     FUNC(XpmGetErrorString, char *, (int errcode));
382     FUNC(XpmLibraryVersion, int, (void));
383 
384     /* XpmImage functions */
385     FUNC(XpmReadFileToXpmImage, int, (const char *filename,
386 				      XpmImage *image,
387 				      XpmInfo *info));
388 
389     FUNC(XpmWriteFileFromXpmImage, int, (const char *filename,
390 					 XpmImage *image,
391 					 XpmInfo *info));
392 #if !defined(FOR_MSW) && !defined(AMIGA)
393     FUNC(XpmCreatePixmapFromXpmImage, int, (Display *display,
394 					    Drawable d,
395 					    XpmImage *image,
396 					    Pixmap *pixmap_return,
397 					    Pixmap *shapemask_return,
398 					    XpmAttributes *attributes));
399 #endif
400     FUNC(XpmCreateImageFromXpmImage, int, (Display *display,
401 					   XpmImage *image,
402 					   XImage **image_return,
403 					   XImage **shapeimage_return,
404 					   XpmAttributes *attributes));
405 
406     FUNC(XpmCreateXpmImageFromImage, int, (Display *display,
407 					   XImage *image,
408 					   XImage *shapeimage,
409 					   XpmImage *xpmimage,
410 					   XpmAttributes *attributes));
411 #if !defined(FOR_MSW) && !defined(AMIGA)
412     FUNC(XpmCreateXpmImageFromPixmap, int, (Display *display,
413 					    Pixmap pixmap,
414 					    Pixmap shapemask,
415 					    XpmImage *xpmimage,
416 					    XpmAttributes *attributes));
417 #endif
418     FUNC(XpmCreateDataFromXpmImage, int, (char ***data_return,
419 					  XpmImage *image,
420 					  XpmInfo *info));
421 
422     FUNC(XpmCreateXpmImageFromData, int, (char **data,
423 					  XpmImage *image,
424 					  XpmInfo *info));
425 
426     FUNC(XpmCreateXpmImageFromBuffer, int, (char *buffer,
427 					    XpmImage *image,
428 					    XpmInfo *info));
429 
430     FUNC(XpmCreateBufferFromXpmImage, int, (char **buffer_return,
431 					    XpmImage *image,
432 					    XpmInfo *info));
433 
434     FUNC(XpmGetParseError, int, (char *filename,
435 				 int *linenum_return,
436 				 int *charnum_return));
437 
438     FUNC(XpmFree, void, (void *ptr));
439 
440 _XFUNCPROTOEND
441 
442 /* backward compatibility */
443 
444 /* for version 3.0c */
445 #define XpmPixmapColorError  XpmColorError
446 #define XpmPixmapSuccess     XpmSuccess
447 #define XpmPixmapOpenFailed  XpmOpenFailed
448 #define XpmPixmapFileInvalid XpmFileInvalid
449 #define XpmPixmapNoMemory    XpmNoMemory
450 #define XpmPixmapColorFailed XpmColorFailed
451 
452 #define XpmReadPixmapFile(dpy, d, file, pix, mask, att) \
453     XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
454 #define XpmWritePixmapFile(dpy, file, pix, mask, att) \
455     XpmWriteFileFromPixmap(dpy, file, pix, mask, att)
456 
457 /* for version 3.0b */
458 #define PixmapColorError  XpmColorError
459 #define PixmapSuccess     XpmSuccess
460 #define PixmapOpenFailed  XpmOpenFailed
461 #define PixmapFileInvalid XpmFileInvalid
462 #define PixmapNoMemory    XpmNoMemory
463 #define PixmapColorFailed XpmColorFailed
464 
465 #define ColorSymbol XpmColorSymbol
466 
467 #define XReadPixmapFile(dpy, d, file, pix, mask, att) \
468     XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
469 #define XWritePixmapFile(dpy, file, pix, mask, att) \
470     XpmWriteFileFromPixmap(dpy, file, pix, mask, att)
471 #define XCreatePixmapFromData(dpy, d, data, pix, mask, att) \
472     XpmCreatePixmapFromData(dpy, d, data, pix, mask, att)
473 #define XCreateDataFromPixmap(dpy, data, pix, mask, att) \
474     XpmCreateDataFromPixmap(dpy, data, pix, mask, att)
475 
476 #endif /* XPM_NUMBERS */
477 #endif
478