2 * Copyright (C) 1989-94 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
43 #if (defined(_WINDOWS) || defined(__WXMSW__) || defined(WIN32)) && !defined(FOR_MSW)
46 /* Piggyback on MSW for now */
47 #if (defined(__OS2__) || defined(__WXPM__) || defined(OS232)) && !defined(FOR_MSW)
52 * first some identification numbers:
53 * the following revision numbers is determined with the following rule:
54 * SO Major number = LIB minor version number.
55 * SO Minor number = LIB sub-minor version number.
56 * e.g: Xpm version 3.2f
57 * we forget the 3 which is the format number, 2 gives 2, and f gives 6.
58 * thus we have XpmVersion = 2 and XpmRevision = 6
59 * which gives SOXPMLIBREV = 2.6
61 * Then the XpmIncludeVersion number is built with the following rule:
62 * (XpmFormat*100 + XpmVersion)*100 + XpmRevision
68 #define XpmIncludeVersion 30402
73 #include "decw$include:Xlib.h"
74 #include "decw$include:Xutil.h"
77 #define SYSV /* uses memcpy string.h etc. */
79 #include "simx.h" /* defines some X stuff using MSW types */
81 #define NEED_STRCASECMP /* at least for MSVC++ */
85 #include <X11/Xutil.h>
86 #include <stdlib.h> /* HEDU */
90 /* let's define Pixel if it is not done yet */
91 #if ! defined(_XtIntrinsic_h) && ! defined(PIXEL_ALREADY_TYPEDEFED)
92 typedef unsigned long Pixel
; /* Index into colormap */
93 #define PIXEL_ALREADY_TYPEDEFED
96 /* Return ErrorStatus codes:
97 * null if full success
98 * positive if partial success
102 #define XpmColorError 1
104 #define XpmOpenFailed -1
105 #define XpmFileInvalid -2
106 #define XpmNoMemory -3
107 #define XpmColorFailed -4
109 /* the following should help people wanting to use their own functions */
110 #define XpmFree(ptr) free(ptr)
113 char *name
; /* Symbolic color name */
114 char *value
; /* Color value */
115 Pixel pixel
; /* Color pixel */
119 char *name
; /* name of the extension */
120 unsigned int nlines
; /* number of lines in this extension */
121 char **lines
; /* pointer to the extension array of strings */
125 char *string
; /* characters string */
126 char *symbolic
; /* symbolic name */
127 char *m_color
; /* monochrom default */
128 char *g4_color
; /* 4 level grayscale default */
129 char *g_color
; /* other level grayscale default */
130 char *c_color
; /* color default */
134 unsigned int width
; /* image width */
135 unsigned int height
; /* image height */
136 unsigned int cpp
; /* number of characters per pixel */
137 unsigned int ncolors
; /* number of colors */
138 XpmColor
*colorTable
; /* list of related colors */
139 unsigned int *data
; /* image data */
143 unsigned long valuemask
; /* Specifies which attributes are defined */
144 char *hints_cmt
; /* Comment of the hints section */
145 char *colors_cmt
; /* Comment of the colors section */
146 char *pixels_cmt
; /* Comment of the pixels section */
147 unsigned int x_hotspot
; /* Returns the x hotspot's coordinate */
148 unsigned int y_hotspot
; /* Returns the y hotspot's coordinate */
149 unsigned int nextensions
; /* number of extensions */
150 XpmExtension
*extensions
; /* pointer to array of extensions */
154 unsigned long valuemask
; /* Specifies which attributes are
157 Visual
*visual
; /* Specifies the visual to use */
158 Colormap colormap
; /* Specifies the colormap to use */
159 unsigned int depth
; /* Specifies the depth */
160 unsigned int width
; /* Returns the width of the created
162 unsigned int height
; /* Returns the height of the created
164 unsigned int x_hotspot
; /* Returns the x hotspot's
166 unsigned int y_hotspot
; /* Returns the y hotspot's
168 unsigned int cpp
; /* Specifies the number of char per
170 Pixel
*pixels
; /* List of used color pixels */
171 unsigned int npixels
; /* Number of pixels */
172 XpmColorSymbol
*colorsymbols
; /* Array of color symbols to
174 unsigned int numsymbols
; /* Number of symbols */
175 char *rgb_fname
; /* RGB text file name */
176 unsigned int nextensions
; /* number of extensions */
177 XpmExtension
*extensions
; /* pointer to array of extensions */
179 unsigned int ncolors
; /* Number of colors */
180 XpmColor
*colorTable
; /* Color table pointer */
181 /* 3.2 backward compatibility code */
182 char *hints_cmt
; /* Comment of the hints section */
183 char *colors_cmt
; /* Comment of the colors section */
184 char *pixels_cmt
; /* Comment of the pixels section */
186 unsigned int mask_pixel
; /* Transparent pixel's color table
189 /* Color Allocation Directives */
190 unsigned int exactColors
; /* Only use exact colors for visual */
191 unsigned int closeness
; /* Allowable RGB deviation */
192 unsigned int red_closeness
; /* Allowable red deviation */
193 unsigned int green_closeness
; /* Allowable green deviation */
194 unsigned int blue_closeness
; /* Allowable blue deviation */
195 int color_key
; /* Use colors from this color set */
199 /* XpmAttributes value masks bits */
200 #define XpmVisual (1L<<0)
201 #define XpmColormap (1L<<1)
202 #define XpmDepth (1L<<2)
203 #define XpmSize (1L<<3) /* width & height */
204 #define XpmHotspot (1L<<4) /* x_hotspot & y_hotspot */
205 #define XpmCharsPerPixel (1L<<5)
206 #define XpmColorSymbols (1L<<6)
207 #define XpmRgbFilename (1L<<7)
208 /* 3.2 backward compatibility code */
209 #define XpmInfos (1L<<8)
210 #define XpmReturnInfos XpmInfos
212 #define XpmReturnPixels (1L<<9)
213 #define XpmExtensions (1L<<10)
214 #define XpmReturnExtensions XpmExtensions
216 #define XpmExactColors (1L<<11)
217 #define XpmCloseness (1L<<12)
218 #define XpmRGBCloseness (1L<<13)
219 #define XpmColorKey (1L<<14)
221 #define XpmColorTable (1L<<15)
222 #define XpmReturnColorTable XpmColorTable
224 /* XpmInfo value masks bits */
225 #define XpmComments XpmInfos
226 #define XpmReturnComments XpmComments
228 /* XpmAttributes mask_pixel value when there is no mask */
230 #define XpmUndefPixel 0x80000000
232 /* int is only 16 bit for MSW */
233 #define XpmUndefPixel 0x8000
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
249 * minimal portability layer between ansi and KR C
252 /* forward declaration of functions with prototypes */
254 #if __STDC__ || defined(__cplusplus) || defined(c_plusplus)
256 #define FUNC(f, t, p) extern t f p
257 #define LFUNC(f, t, p) static t f p
258 /* #define LFUNC(f, t, p) t f p */
260 #define FUNC(f, t, p) extern t f()
261 #define LFUNC(f, t, p) static t f()
262 /* #define LFUNC(f, t, p) t f() */
263 #endif /* end of K&R */
267 * functions declarations
274 /* For Microsoft C++ at any rate, the FUNC macro just doesn't work: it causes
275 * arguments to be corrupted espec. in XpmWriteFileFromXpmImage.
276 * So, define all prototypes explicitly.
278 #if defined(_MSC_VER) || defined(__OS2__)
280 /* FOR_MSW, all ..Pixmap.. are excluded, only the ..XImage.. are used */
282 int XpmCreateImageFromData(Display
*display
,
284 XImage
**image_return
,
285 XImage
**shapemask_return
,
286 XpmAttributes
*attributes
);
288 int XpmCreateDataFromImage(Display
*display
,
292 XpmAttributes
*attributes
);
294 int XpmReadFileToImage(Display
*display
,
296 XImage
**image_return
,
297 XImage
**shapeimage_return
,
298 XpmAttributes
*attributes
);
300 int XpmWriteFileFromImage(Display
*display
,
304 XpmAttributes
*attributes
);
306 int XpmCreateImageFromBuffer(Display
*display
,
308 XImage
**image_return
,
309 XImage
**shapemask_return
,
310 XpmAttributes
*attributes
);
312 int XpmReadFileToBuffer(char *filename
, char **buffer_return
);
313 int XpmWriteFileFromBuffer(char *filename
, char *buffer
);
315 int XpmReadFileToData(char *filename
, char ***data_return
);
316 int XpmWriteFileFromData(char *filename
, char **data
);
318 int XpmAttributesSize();
319 void XpmFreeAttributes(XpmAttributes
*attributes
);
320 void XpmFreeExtensions(XpmExtension
*extensions
,
323 void XpmFreeXpmImage(XpmImage
*image
);
324 void XpmFreeXpmInfo(XpmInfo
*info
);
325 char *XpmGetErrorString(int errcode
);
326 int XpmLibraryVersion();
328 /* XpmImage functions */
329 int XpmReadFileToXpmImage(char *filename
,
333 int XpmWriteFileFromXpmImage(char *filename
,
337 int XpmWriteFileFromXpmImage(char *filename
, XpmImage
*image
, XpmInfo
*info
);
339 int XpmCreateImageFromXpmImage(Display
*display
,
341 XImage
**image_return
,
342 XImage
**shapeimage_return
,
343 XpmAttributes
*attributes
);
345 int XpmCreateXpmImageFromImage(Display
*display
,
349 XpmAttributes
*attributes
);
350 int XpmCreateDataFromXpmImage(char ***data_return
,
354 int XpmCreateXpmImageFromData(char **data
,
358 int XpmCreateXpmImageFromBuffer(char *buffer
,
362 int XpmCreateBufferFromXpmImage(char **buffer_return
,
368 /* FOR_MSW, all ..Pixmap.. are excluded, only the ..XImage.. are used */
371 FUNC(XpmCreatePixmapFromData
, int, (Display
*display
,
374 Pixmap
*pixmap_return
,
375 Pixmap
*shapemask_return
,
376 XpmAttributes
*attributes
));
378 FUNC(XpmCreateDataFromPixmap
, int, (Display
*display
,
382 XpmAttributes
*attributes
));
384 FUNC(XpmReadFileToPixmap
, int, (Display
*display
,
387 Pixmap
*pixmap_return
,
388 Pixmap
*shapemask_return
,
389 XpmAttributes
*attributes
));
391 FUNC(XpmWriteFileFromPixmap
, int, (Display
*display
,
395 XpmAttributes
*attributes
));
396 #endif /* ndef FOR_MSW */
398 FUNC(XpmCreateImageFromData
, int, (Display
*display
,
400 XImage
**image_return
,
401 XImage
**shapemask_return
,
402 XpmAttributes
*attributes
));
404 FUNC(XpmCreateDataFromImage
, int, (Display
*display
,
408 XpmAttributes
*attributes
));
410 FUNC(XpmReadFileToImage
, int, (Display
*display
,
412 XImage
**image_return
,
413 XImage
**shapeimage_return
,
414 XpmAttributes
*attributes
));
416 FUNC(XpmWriteFileFromImage
, int, (Display
*display
,
420 XpmAttributes
*attributes
));
422 FUNC(XpmCreateImageFromBuffer
, int, (Display
*display
,
424 XImage
**image_return
,
425 XImage
**shapemask_return
,
426 XpmAttributes
*attributes
));
428 FUNC(XpmCreatePixmapFromBuffer
, int, (Display
*display
,
431 Pixmap
*pixmap_return
,
432 Pixmap
*shapemask_return
,
433 XpmAttributes
*attributes
));
435 FUNC(XpmCreateBufferFromImage
, int, (Display
*display
,
436 char **buffer_return
,
439 XpmAttributes
*attributes
));
441 FUNC(XpmCreateBufferFromPixmap
, int, (Display
*display
,
442 char **buffer_return
,
445 XpmAttributes
*attributes
));
446 #endif /* ndef FOR_MSW */
447 FUNC(XpmReadFileToBuffer
, int, (char *filename
, char **buffer_return
));
448 FUNC(XpmWriteFileFromBuffer
, int, (char *filename
, char *buffer
));
450 FUNC(XpmReadFileToData
, int, (char *filename
, char ***data_return
));
451 FUNC(XpmWriteFileFromData
, int, (char *filename
, char **data
));
453 FUNC(XpmAttributesSize
, int, ());
454 FUNC(XpmFreeAttributes
, void, (XpmAttributes
*attributes
));
455 FUNC(XpmFreeExtensions
, void, (XpmExtension
*extensions
,
458 FUNC(XpmFreeXpmImage
, void, (XpmImage
*image
));
459 FUNC(XpmFreeXpmInfo
, void, (XpmInfo
*info
));
460 FUNC(XpmGetErrorString
, char *, (int errcode
));
461 FUNC(XpmLibraryVersion
, int, ());
463 /* XpmImage functions */
464 FUNC(XpmReadFileToXpmImage
, int, (char *filename
,
468 FUNC(XpmWriteFileFromXpmImage
, int, (char *filename
,
472 FUNC(XpmWriteFileFromXpmImage
, int, (char *filename
, XpmImage
*image
, XpmInfo
*info
));
473 /* extern int XpmWriteFileFromXpmImage(char *filename, XpmImage *image, XpmInfo *info); */
476 FUNC(XpmCreatePixmapFromXpmImage
, int, (Display
*display
,
479 Pixmap
*pixmap_return
,
480 Pixmap
*shapemask_return
,
481 XpmAttributes
*attributes
));
483 FUNC(XpmCreateImageFromXpmImage
, int, (Display
*display
,
485 XImage
**image_return
,
486 XImage
**shapeimage_return
,
487 XpmAttributes
*attributes
));
489 FUNC(XpmCreateXpmImageFromImage
, int, (Display
*display
,
493 XpmAttributes
*attributes
));
495 FUNC(XpmCreateXpmImageFromPixmap
, int, (Display
*display
,
499 XpmAttributes
*attributes
));
501 FUNC(XpmCreateDataFromXpmImage
, int, (char ***data_return
,
505 FUNC(XpmCreateXpmImageFromData
, int, (char **data
,
509 FUNC(XpmCreateXpmImageFromBuffer
, int, (char *buffer
,
513 FUNC(XpmCreateBufferFromXpmImage
, int, (char **buffer_return
,
524 /* backward compatibility */
526 /* for version 3.0c */
527 #define XpmPixmapColorError XpmColorError
528 #define XpmPixmapSuccess XpmSuccess
529 #define XpmPixmapOpenFailed XpmOpenFailed
530 #define XpmPixmapFileInvalid XpmFileInvalid
531 #define XpmPixmapNoMemory XpmNoMemory
532 #define XpmPixmapColorFailed XpmColorFailed
534 #define XpmReadPixmapFile(dpy, d, file, pix, mask, att) \
535 XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
536 #define XpmWritePixmapFile(dpy, file, pix, mask, att) \
537 XpmWriteFileFromPixmap(dpy, file, pix, mask, att)
539 /* for version 3.0b */
540 #define PixmapColorError XpmColorError
541 #define PixmapSuccess XpmSuccess
542 #define PixmapOpenFailed XpmOpenFailed
543 #define PixmapFileInvalid XpmFileInvalid
544 #define PixmapNoMemory XpmNoMemory
545 #define PixmapColorFailed XpmColorFailed
547 #define ColorSymbol XpmColorSymbol
549 #define XReadPixmapFile(dpy, d, file, pix, mask, att) \
550 XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
551 #define XWritePixmapFile(dpy, file, pix, mask, att) \
552 XpmWriteFileFromPixmap(dpy, file, pix, mask, att)
553 #define XCreatePixmapFromData(dpy, d, data, pix, mask, att) \
554 XpmCreatePixmapFromData(dpy, d, data, pix, mask, att)
555 #define XCreateDataFromPixmap(dpy, data, pix, mask, att) \
556 XpmCreateDataFromPixmap(dpy, data, pix, mask, att)
558 #endif /* XPM_NUMBERS */