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