2 * Copyright (C) 1989-95 GROUPE BULL
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
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.
26 /*****************************************************************************\
32 * Developed by Arnaud Le Hors *
33 \*****************************************************************************/
36 * The code related to FOR_MSW has been added by
37 * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
41 * The code related to AMIGA has been added by
42 * Lorens Younes (d93-hyo@nada.kth.se) 4/96
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
58 * Then the XpmIncludeVersion number is built from these numbers.
62 #define XpmRevision 11
63 #define XpmIncludeVersion ((XpmFormat * 100 + XpmVersion) * 100 + XpmRevision)
68 #define IS_EQUAL_PIXEL( a , b ) ( a == b )
69 #define IS_ZERO_PIXEL(a) (!(a) )
70 #define SET_ZERO_PIXEL(a) { (a) = 0 }
71 #define SET_WHITE_PIXEL(a) { (a) = 0 }
72 # define SYSV /* uses memcpy string.h etc. */
74 # include "simx.h" /* defines some X stuff using MSW types */
75 # define NEED_STRCASECMP /* at least for MSVC++ */
77 #define IS_EQUAL_PIXEL( a , b ) ( a == b )
78 #define IS_ZERO_PIXEL(a) (!(a) )
79 #define SET_ZERO_PIXEL(a) { (a) = 0 }
80 #define SET_WHITE_PIXEL(a) { (a) = 0 }
82 #elif defined(macintosh) || defined(__APPLE__)
83 #define IS_EQUAL_PIXEL( a , b ) ( (a).red == (b).red && (a).green == (b).green && (a).blue == (b).blue )
84 #define IS_ZERO_PIXEL(a) (!(a).red && !(a).green && !(a).blue )
85 #define SET_ZERO_PIXEL(a) { (a).red = 0 ; (a).green = 0 ;(a).blue = 0 ;}
86 #define SET_WHITE_PIXEL(a) { (a).red = 0xFFFF ; (a).green = 0xFFFF ;(a).blue = 0xFFFF ;}
88 # define NEED_STRCASECMP
91 #define IS_EQUAL_PIXEL( a , b ) ( a == b )
92 #define IS_ZERO_PIXEL(a) (!(a) )
93 #define SET_ZERO_PIXEL(a) { (a) = 0 }
94 #define SET_WHITE_PIXEL(a) { (a) = 0 }
95 # include <X11/Xlib.h>
96 # include <X11/Xutil.h>
99 /* let's define Pixel if it is not done yet */
100 #if ! defined(_XtIntrinsic_h) && ! defined(PIXEL_ALREADY_TYPEDEFED)
101 typedef unsigned long Pixel
; /* Index into colormap */
102 # define PIXEL_ALREADY_TYPEDEFED
105 /* make sure we know whether function prototypes are needed or not */
106 #ifndef NeedFunctionPrototypes
107 # if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
108 # define NeedFunctionPrototypes 1
110 # define NeedFunctionPrototypes 0
115 /* Return ErrorStatus codes:
116 * null if full success
117 * positive if partial success
118 * negative if failure
121 #define XpmColorError 1
123 #define XpmOpenFailed -1
124 #define XpmFileInvalid -2
125 #define XpmNoMemory -3
126 #define XpmColorFailed -4
129 char *name
; /* Symbolic color name */
130 char *value
; /* Color value */
131 Pixel pixel
; /* Color pixel */
135 char *name
; /* name of the extension */
136 unsigned int nlines
; /* number of lines in this extension */
137 char **lines
; /* pointer to the extension array of strings */
141 char *string
; /* characters string */
142 char *symbolic
; /* symbolic name */
143 char *m_color
; /* monochrom default */
144 char *g4_color
; /* 4 level grayscale default */
145 char *g_color
; /* other level grayscale default */
146 char *c_color
; /* color default */
150 unsigned int width
; /* image width */
151 unsigned int height
; /* image height */
152 unsigned int cpp
; /* number of characters per pixel */
153 unsigned int ncolors
; /* number of colors */
154 XpmColor
*colorTable
; /* list of related colors */
155 unsigned int *data
; /* image data */
159 unsigned long valuemask
; /* Specifies which attributes are defined */
160 char *hints_cmt
; /* Comment of the hints section */
161 char *colors_cmt
; /* Comment of the colors section */
162 char *pixels_cmt
; /* Comment of the pixels section */
163 unsigned int x_hotspot
; /* Returns the x hotspot's coordinate */
164 unsigned int y_hotspot
; /* Returns the y hotspot's coordinate */
165 unsigned int nextensions
; /* number of extensions */
166 XpmExtension
*extensions
; /* pointer to array of extensions */
169 typedef int (*XpmAllocColorFunc
)(
170 #if NeedFunctionPrototypes
171 Display
* /* display */,
172 Colormap
/* colormap */,
173 char* /* colorname */,
174 XColor
* /* xcolor */,
179 typedef int (*XpmFreeColorsFunc
)(
180 #if NeedFunctionPrototypes
181 Display
* /* display */,
182 Colormap
/* colormap */,
190 unsigned long valuemask
; /* Specifies which attributes are
193 Visual
*visual
; /* Specifies the visual to use */
194 Colormap colormap
; /* Specifies the colormap to use */
195 unsigned int depth
; /* Specifies the depth */
196 unsigned int width
; /* Returns the width of the created
198 unsigned int height
; /* Returns the height of the created
200 unsigned int x_hotspot
; /* Returns the x hotspot's
202 unsigned int y_hotspot
; /* Returns the y hotspot's
204 unsigned int cpp
; /* Specifies the number of char per
206 Pixel
*pixels
; /* List of used color pixels */
207 unsigned int npixels
; /* Number of used pixels */
208 XpmColorSymbol
*colorsymbols
; /* List of color symbols to override */
209 unsigned int numsymbols
; /* Number of symbols */
210 char *rgb_fname
; /* RGB text file name */
211 unsigned int nextensions
; /* Number of extensions */
212 XpmExtension
*extensions
; /* List of extensions */
214 unsigned int ncolors
; /* Number of colors */
215 XpmColor
*colorTable
; /* List of colors */
216 /* 3.2 backward compatibility code */
217 char *hints_cmt
; /* Comment of the hints section */
218 char *colors_cmt
; /* Comment of the colors section */
219 char *pixels_cmt
; /* Comment of the pixels section */
221 unsigned int mask_pixel
; /* Color table index of transparent
224 /* Color Allocation Directives */
225 Bool exactColors
; /* Only use exact colors for visual */
226 unsigned int closeness
; /* Allowable RGB deviation */
227 unsigned int red_closeness
; /* Allowable red deviation */
228 unsigned int green_closeness
; /* Allowable green deviation */
229 unsigned int blue_closeness
; /* Allowable blue deviation */
230 int color_key
; /* Use colors from this color set */
232 Pixel
*alloc_pixels
; /* Returns the list of alloc'ed color
234 int nalloc_pixels
; /* Returns the number of alloc'ed
237 Bool alloc_close_colors
; /* Specify whether close colors should
238 be allocated using XAllocColor
240 int bitmap_format
; /* Specify the format of 1bit depth
241 images: ZPixmap or XYBitmap */
243 /* Color functions */
244 XpmAllocColorFunc alloc_color
; /* Application color allocator */
245 XpmFreeColorsFunc free_colors
; /* Application color de-allocator */
246 void *color_closure
; /* Application private data to pass to
247 alloc_color and free_colors */
251 /* XpmAttributes value masks bits */
252 #define XpmVisual (1L<<0)
253 #define XpmColormap (1L<<1)
254 #define XpmDepth (1L<<2)
255 #define XpmSize (1L<<3) /* width & height */
256 #define XpmHotspot (1L<<4) /* x_hotspot & y_hotspot */
257 #define XpmCharsPerPixel (1L<<5)
258 #define XpmColorSymbols (1L<<6)
259 #define XpmRgbFilename (1L<<7)
260 /* 3.2 backward compatibility code */
261 #define XpmInfos (1L<<8)
262 #define XpmReturnInfos XpmInfos
264 #define XpmReturnPixels (1L<<9)
265 #define XpmExtensions (1L<<10)
266 #define XpmReturnExtensions XpmExtensions
268 #define XpmExactColors (1L<<11)
269 #define XpmCloseness (1L<<12)
270 #define XpmRGBCloseness (1L<<13)
271 #define XpmColorKey (1L<<14)
273 #define XpmColorTable (1L<<15)
274 #define XpmReturnColorTable XpmColorTable
276 #define XpmReturnAllocPixels (1L<<16)
277 #define XpmAllocCloseColors (1L<<17)
278 #define XpmBitmapFormat (1L<<18)
280 #define XpmAllocColor (1L<<19)
281 #define XpmFreeColors (1L<<20)
282 #define XpmColorClosure (1L<<21)
285 /* XpmInfo value masks bits */
286 #define XpmComments XpmInfos
287 #define XpmReturnComments XpmComments
289 /* XpmAttributes mask_pixel value when there is no mask */
291 #define XpmUndefPixel 0x80000000
293 /* int is only 16 bit for MSW */
294 #define XpmUndefPixel 0x8000
298 * color keys for visual type, they must fit along with the number key of
299 * each related element in xpmColorKeys[] defined in XpmI.h
309 /* macros for forward declarations of functions with prototypes */
310 #if NeedFunctionPrototypes
311 #define FUNC(f, t, p) extern t f p
312 #define LFUNC(f, t, p) static t f p
314 #define FUNC(f, t, p) extern t f()
315 #define LFUNC(f, t, p) static t f()
320 * functions declarations
328 FUNC(XpmCreateImageFromData
, int, (Display
*display
,
330 XImage
**image_return
,
331 XImage
**shapemask_return
,
332 XpmAttributes
*attributes
));
334 FUNC(XpmCreateDataFromImage
, int, (Display
*display
,
338 XpmAttributes
*attributes
));
340 FUNC(XpmReadFileToImage
, int, (Display
*display
,
342 XImage
**image_return
,
343 XImage
**shapeimage_return
,
344 XpmAttributes
*attributes
));
346 FUNC(XpmWriteFileFromImage
, int, (Display
*display
,
350 XpmAttributes
*attributes
));
352 FUNC(XpmCreateImageFromBuffer
, int, (Display
*display
,
354 XImage
**image_return
,
355 XImage
**shapemask_return
,
356 XpmAttributes
*attributes
));
358 FUNC(XpmReadFileToBuffer
, int, (char *filename
, char **buffer_return
));
359 FUNC(XpmWriteFileFromBuffer
, int, (char *filename
, char *buffer
));
361 FUNC(XpmReadFileToData
, int, (char *filename
, char ***data_return
));
362 FUNC(XpmWriteFileFromData
, int, (char *filename
, char **data
));
364 FUNC(XpmAttributesSize
, int, ());
365 FUNC(XpmFreeAttributes
, void, (XpmAttributes
*attributes
));
366 FUNC(XpmFreeExtensions
, void, (XpmExtension
*extensions
,
369 FUNC(XpmFreeXpmImage
, void, (XpmImage
*image
));
370 FUNC(XpmFreeXpmInfo
, void, (XpmInfo
*info
));
371 FUNC(XpmGetErrorString
, char *, (int errcode
));
372 FUNC(XpmLibraryVersion
, int, ());
374 /* XpmImage functions */
375 FUNC(XpmReadFileToXpmImage
, int, (char *filename
,
379 FUNC(XpmWriteFileFromXpmImage
, int, (char *filename
,
383 FUNC(XpmCreateImageFromXpmImage
, int, (Display
*display
,
385 XImage
**image_return
,
386 XImage
**shapeimage_return
,
387 XpmAttributes
*attributes
));
389 FUNC(XpmCreateXpmImageFromImage
, int, (Display
*display
,
393 XpmAttributes
*attributes
));
395 FUNC(XpmCreateDataFromXpmImage
, int, (char ***data_return
,
399 FUNC(XpmCreateXpmImageFromData
, int, (char **data
,
403 FUNC(XpmCreateXpmImageFromBuffer
, int, (char *buffer
,
407 FUNC(XpmCreateBufferFromXpmImage
, int, (char **buffer_return
,
411 FUNC(XpmGetParseError
, int, (char *filename
,
413 int *charnum_return
));
415 FUNC(XpmFree
, void, (void *ptr
));
422 /* backward compatibility */
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
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)
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
445 #define ColorSymbol XpmColorSymbol
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)
456 #endif /* XPM_NUMBERS */