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