| 1 |
/* @(#)xpmP.h 17.1 (ESO-IPG) 01/25/02 17:26:07 */ |
| 2 |
/*--------------------------------------------------------------------- |
| 3 |
* $Date: 2003-06-04 14:49:18 $ $Revision: 1.1.1.1 $ |
| 4 |
*--------------------------------------------------------------------- |
| 5 |
* |
| 6 |
* |
| 7 |
* Copyright (c) 1992, Visual Edge Software Ltd. |
| 8 |
* |
| 9 |
* ALL RIGHTS RESERVED. Permission to use, copy, modify, and |
| 10 |
* distribute this software and its documentation for any purpose |
| 11 |
* and without fee is hereby granted, provided that the above |
| 12 |
* copyright notice appear in all copies and that both that |
| 13 |
* copyright notice and this permission notice appear in supporting |
| 14 |
* documentation, and that the name of Visual Edge Software not be |
| 15 |
* used in advertising or publicity pertaining to distribution of |
| 16 |
* the software without specific, written prior permission. The year |
| 17 |
* included in the notice is the year of the creation of the work. |
| 18 |
*-------------------------------------------------------------------*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* Copyright 1990, 1991 GROUPE BULL |
| 22 |
* |
| 23 |
* Permission to use, copy, modify, and distribute this software and its |
| 24 |
* documentation for any purpose and without fee is hereby granted, provided |
| 25 |
* that the above copyright notice appear in all copies and that both that |
| 26 |
* copyright notice and this permission notice appear in supporting |
| 27 |
* documentation, and that the name of GROUPE BULL not be used in advertising |
| 28 |
* or publicity pertaining to distribution of the software without specific, |
| 29 |
* written prior permission. GROUPE BULL makes no representations about the |
| 30 |
* suitability of this software for any purpose. It is provided "as is" |
| 31 |
* without express or implied warranty. |
| 32 |
* |
| 33 |
* GROUPE BULL disclaims all warranties with regard to this software, |
| 34 |
* including all implied warranties of merchantability and fitness, |
| 35 |
* in no event shall GROUPE BULL be liable for any special, |
| 36 |
* indirect or consequential damages or any damages |
| 37 |
* whatsoever resulting from loss of use, data or profits, |
| 38 |
* whether in an action of contract, negligence or other tortious |
| 39 |
* action, arising out of or in connection with the use |
| 40 |
* or performance of this software. |
| 41 |
* |
| 42 |
*/ |
| 43 |
|
| 44 |
/*****************************************************************************\ |
| 45 |
* xpmP.h: * |
| 46 |
* * |
| 47 |
* XPM library * |
| 48 |
* Private Include file * |
| 49 |
* * |
| 50 |
* Developed by Arnaud Le Hors * |
| 51 |
\*****************************************************************************/ |
| 52 |
|
| 53 |
#ifndef XPMP_h |
| 54 |
#define XPMP_h |
| 55 |
|
| 56 |
#ifdef Debug |
| 57 |
/* memory leak control tool */ |
| 58 |
#include <mnemosyne.h> |
| 59 |
#endif |
| 60 |
|
| 61 |
#ifdef VMS |
| 62 |
#include "decw$include:Xlib.h" |
| 63 |
#include "decw$include:Intrinsic.h" |
| 64 |
#include "sys$library:stdio.h" |
| 65 |
#else |
| 66 |
#include <X11/Xlib.h> |
| 67 |
#include <X11/Intrinsic.h> |
| 68 |
#include <stdio.h> |
| 69 |
/* stdio.h doesn't declare popen on a Sequent DYNIX OS */ |
| 70 |
#ifdef sequent |
| 71 |
extern FILE *popen(); |
| 72 |
#endif |
| 73 |
#endif |
| 74 |
|
| 75 |
#include "xpm.h" |
| 76 |
|
| 77 |
/* we keep the same codes as for Bitmap management */ |
| 78 |
#ifndef _XUTIL_H_ |
| 79 |
#ifdef VMS |
| 80 |
#include "decw$include:Xutil.h" |
| 81 |
#else |
| 82 |
#include <X11/Xutil.h> |
| 83 |
#endif |
| 84 |
#endif |
| 85 |
|
| 86 |
#ifdef SYSV |
| 87 |
#define bcopy(source, dest, count) memcpy(dest, source, count) |
| 88 |
#endif |
| 89 |
|
| 90 |
typedef struct { |
| 91 |
unsigned int type; |
| 92 |
union { |
| 93 |
FILE *file; |
| 94 |
char **data; |
| 95 |
} stream; |
| 96 |
char *cptr; |
| 97 |
unsigned int line; |
| 98 |
int CommentLength; |
| 99 |
char Comment[BUFSIZ]; |
| 100 |
char *Bcmt, *Ecmt, Bos, Eos; |
| 101 |
} xpmData; |
| 102 |
|
| 103 |
#define XPMARRAY 0 |
| 104 |
#define XPMFILE 1 |
| 105 |
#define XPMPIPE 2 |
| 106 |
|
| 107 |
typedef unsigned char byte; |
| 108 |
|
| 109 |
#define EOL '\n' |
| 110 |
#define TAB '\t' |
| 111 |
#define SPC ' ' |
| 112 |
|
| 113 |
typedef struct { |
| 114 |
char *type; /* key word */ |
| 115 |
char *Bcmt; /* string beginning comments */ |
| 116 |
char *Ecmt; /* string ending comments */ |
| 117 |
char Bos; /* character beginning strings */ |
| 118 |
char Eos; /* character ending strings */ |
| 119 |
char *Strs; /* strings separator */ |
| 120 |
char *Dec; /* data declaration string */ |
| 121 |
char *Boa; /* string beginning assignment */ |
| 122 |
char *Eoa; /* string ending assignment */ |
| 123 |
} xpmDataType; |
| 124 |
|
| 125 |
extern xpmDataType xpmDataTypes[]; |
| 126 |
|
| 127 |
/* |
| 128 |
* rgb values and ascii names (from rgb text file) rgb values, |
| 129 |
* range of 0 -> 65535 color mnemonic of rgb value |
| 130 |
*/ |
| 131 |
typedef struct { |
| 132 |
int r, g, b; |
| 133 |
char *name; |
| 134 |
} xpmRgbName; |
| 135 |
|
| 136 |
/* Maximum number of rgb mnemonics allowed in rgb text file. */ |
| 137 |
#define MAX_RGBNAMES 1024 |
| 138 |
|
| 139 |
extern char *xpmColorKeys[]; |
| 140 |
|
| 141 |
#define TRANSPARENT_COLOR "None" /* this must be a string! */ |
| 142 |
|
| 143 |
/* number of xpmColorKeys */ |
| 144 |
#define NKEYS 5 |
| 145 |
|
| 146 |
/* |
| 147 |
* key numbers for visual type, they must fit along with the number key of |
| 148 |
* each corresponding element in xpmColorKeys[] defined in xpm.h |
| 149 |
*/ |
| 150 |
#define MONO 2 |
| 151 |
#define GRAY4 3 |
| 152 |
#define GRAY 4 |
| 153 |
#define COLOR 5 |
| 154 |
|
| 155 |
/* structure containing data related to an Xpm pixmap */ |
| 156 |
typedef struct { |
| 157 |
char *name; |
| 158 |
unsigned int width; |
| 159 |
unsigned int height; |
| 160 |
unsigned int cpp; |
| 161 |
unsigned int ncolors; |
| 162 |
char ***colorTable; |
| 163 |
unsigned int *pixelindex; |
| 164 |
XColor *xcolors; |
| 165 |
char **colorStrings; |
| 166 |
unsigned int mask_pixel; /* mask pixel's colorTable index */ |
| 167 |
} xpmInternAttrib; |
| 168 |
|
| 169 |
#define UNDEF_PIXEL 0x80000000 |
| 170 |
|
| 171 |
/* XPM private routines */ |
| 172 |
|
| 173 |
#ifdef NOT_NEEDED |
| 174 |
FUNC(xpmParseDataAndCreateImage, int, (xpmData * data, |
| 175 |
Display * display, |
| 176 |
XImage ** image_return, |
| 177 |
XImage ** shapeimage_return, |
| 178 |
xpmInternAttrib * attrib_return, |
| 179 |
XpmAttributes * attributes)); |
| 180 |
#endif |
| 181 |
|
| 182 |
FUNC(xpmCreateImage, int, (Display * display, |
| 183 |
xpmInternAttrib * attrib, |
| 184 |
XImage ** image_return, |
| 185 |
XImage ** shapeimage_return, |
| 186 |
XpmAttributes * attributes)); |
| 187 |
|
| 188 |
FUNC(xpmParseData, int, (xpmData * data, |
| 189 |
xpmInternAttrib * attrib_return, |
| 190 |
XpmAttributes * attributes)); |
| 191 |
|
| 192 |
#ifdef NOT_NEEDED |
| 193 |
FUNC(xpmScanImage, int, (Display * display, |
| 194 |
XImage * image, |
| 195 |
XImage * shapeimage, |
| 196 |
XpmAttributes * attributes, |
| 197 |
xpmInternAttrib * attrib)); |
| 198 |
#endif |
| 199 |
|
| 200 |
FUNC(xpmFreeColorTable, int, (char ***colorTable, int ncolors)); |
| 201 |
|
| 202 |
FUNC(xpmInitInternAttrib, int, (xpmInternAttrib * xmpdata)); |
| 203 |
|
| 204 |
FUNC(xpmFreeInternAttrib, int, (xpmInternAttrib * xmpdata)); |
| 205 |
|
| 206 |
FUNC(xpmSetAttributes, int, (xpmInternAttrib * attrib, |
| 207 |
XpmAttributes * attributes)); |
| 208 |
|
| 209 |
#ifdef NOT_NEEDED |
| 210 |
FUNC(xpmGetAttributes, int, (XpmAttributes * attributes, |
| 211 |
xpmInternAttrib * attrib)); |
| 212 |
#endif |
| 213 |
|
| 214 |
/* I/O utility */ |
| 215 |
|
| 216 |
FUNC(xpmNextString, int, (xpmData * mdata)); |
| 217 |
FUNC(xpmNextUI, int, (xpmData * mdata, unsigned int *ui_return)); |
| 218 |
|
| 219 |
#define xpmGetC(mdata) \ |
| 220 |
(mdata->type ? (getc(mdata->stream.file)) : (*mdata->cptr++)) |
| 221 |
|
| 222 |
FUNC(xpmNextWord, unsigned int, (xpmData * mdata, char *buf)); |
| 223 |
FUNC(xpmGetCmt, int, (xpmData * mdata, char **cmt)); |
| 224 |
FUNC(xpmReadFile, int, (char *filename, xpmData * mdata)); |
| 225 |
FUNC(xpmWriteFile, int, (char *filename, xpmData * mdata)); |
| 226 |
FUNC(xpmOpenArray, int, (char **data, xpmData * mdata)); |
| 227 |
FUNC(XpmDataClose, int, (xpmData * mdata)); |
| 228 |
|
| 229 |
/* RGB utility */ |
| 230 |
|
| 231 |
#ifdef NOT_NEEDED |
| 232 |
FUNC(xpmReadRgbNames, int, (char *rgb_fname, xpmRgbName * rgbn)); |
| 233 |
FUNC(xpmGetRgbName, char *, (xpmRgbName * rgbn, int rgbn_max, |
| 234 |
int red, int green, int blue)); |
| 235 |
FUNC(xpmFreeRgbNames, void, (xpmRgbName * rgbn, int rgbn_max)); |
| 236 |
#endif |
| 237 |
|
| 238 |
FUNC(xpm_xynormalizeimagebits, int, (register unsigned char *bp, |
| 239 |
register XImage * img)); |
| 240 |
FUNC(xpm_znormalizeimagebits, int, (register unsigned char *bp, |
| 241 |
register XImage * img)); |
| 242 |
|
| 243 |
/* |
| 244 |
* Macros |
| 245 |
* |
| 246 |
* The XYNORMALIZE macro determines whether XY format data requires |
| 247 |
* normalization and calls a routine to do so if needed. The logic in |
| 248 |
* this module is designed for LSBFirst byte and bit order, so |
| 249 |
* normalization is done as required to present the data in this order. |
| 250 |
* |
| 251 |
* The ZNORMALIZE macro performs byte and nibble order normalization if |
| 252 |
* required for Z format data. |
| 253 |
* |
| 254 |
* The XYINDEX macro computes the index to the starting byte (char) boundary |
| 255 |
* for a bitmap_unit containing a pixel with coordinates x and y for image |
| 256 |
* data in XY format. |
| 257 |
* |
| 258 |
* The ZINDEX* macros compute the index to the starting byte (char) boundary |
| 259 |
* for a pixel with coordinates x and y for image data in ZPixmap format. |
| 260 |
* |
| 261 |
*/ |
| 262 |
|
| 263 |
#define XYNORMALIZE(bp, img) \ |
| 264 |
if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \ |
| 265 |
xpm_xynormalizeimagebits((unsigned char *)(bp), img) |
| 266 |
|
| 267 |
#define ZNORMALIZE(bp, img) \ |
| 268 |
if (img->byte_order == MSBFirst) \ |
| 269 |
xpm_znormalizeimagebits((unsigned char *)(bp), img) |
| 270 |
|
| 271 |
#define XYINDEX(x, y, img) \ |
| 272 |
((y) * img->bytes_per_line) + \ |
| 273 |
(((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3) |
| 274 |
|
| 275 |
#define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \ |
| 276 |
(((x) * img->bits_per_pixel) >> 3) |
| 277 |
|
| 278 |
#define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2) |
| 279 |
|
| 280 |
#define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1) |
| 281 |
|
| 282 |
#define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x) |
| 283 |
|
| 284 |
#define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3) |
| 285 |
|
| 286 |
#if __STDC__ |
| 287 |
#define Const const |
| 288 |
#else |
| 289 |
#define Const /**/ |
| 290 |
#endif |
| 291 |
|
| 292 |
/* |
| 293 |
* there are structures and functions related to hastable code |
| 294 |
*/ |
| 295 |
|
| 296 |
typedef struct _xpmHashAtom { |
| 297 |
char *name; |
| 298 |
void *data; |
| 299 |
} *xpmHashAtom; |
| 300 |
|
| 301 |
typedef struct { |
| 302 |
int size; |
| 303 |
int limit; |
| 304 |
int used; |
| 305 |
xpmHashAtom *atomTable; |
| 306 |
} xpmHashTable; |
| 307 |
|
| 308 |
FUNC(xpmHashTableInit, int, (xpmHashTable *table)); |
| 309 |
FUNC(xpmHashTableFree, int, (xpmHashTable *table)); |
| 310 |
FUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s)); |
| 311 |
FUNC(xpmHashIntern, xpmHashAtom, (xpmHashTable *table, char *tag, void *data)); |
| 312 |
|
| 313 |
#define HashAtomData(i) ((void *)i) |
| 314 |
#define HashColorIndex(slot) ((unsigned int)((*slot)->data)) |
| 315 |
#define USE_HASHTABLE (ncolors > 4) |
| 316 |
|
| 317 |
#endif |