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