XpmI.h revision 52dc082b
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* XpmI.h: * 28* * 29* XPM library * 30* Internal Include file * 31* * 32* ** Everything defined here is subject to changes any time. ** * 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#ifndef XPMI_h 43#define XPMI_h 44 45#include "xpm.h" 46 47/* 48 * lets try to solve include files 49 */ 50 51#include <sys/types.h> 52#include <stdio.h> 53#include <stdlib.h> 54#include <limits.h> 55/* stdio.h doesn't declare popen on a Sequent DYNIX OS */ 56#ifdef sequent 57extern FILE *popen(); 58#endif 59 60#ifdef FOR_MSW 61#include "simx.h" 62#else 63#include <X11/Xos.h> 64#include <X11/Xfuncs.h> 65#include <X11/Xmd.h> 66#endif 67 68#ifdef VMS 69#include <unixio.h> 70#include <file.h> 71#endif 72 73/* The following should help people wanting to use their own memory allocation 74 * functions. To avoid the overhead of a function call when the standard 75 * functions are used these are all macros, even the XpmFree function which 76 * needs to be a real function for the outside world though. 77 * So if change these be sure to change the XpmFree function in misc.c 78 * accordingly. 79 */ 80#define XpmFree(ptr) free(ptr) 81 82#ifndef FOR_MSW 83#define XpmMalloc(size) malloc((size)) 84#define XpmRealloc(ptr, size) realloc((ptr), (size)) 85#define XpmCalloc(nelem, elsize) calloc((nelem), (elsize)) 86#else 87/* checks for mallocs bigger than 64K */ 88#define XpmMalloc(size) boundCheckingMalloc((long)(size))/* in simx.[ch] */ 89#define XpmRealloc(ptr, size) boundCheckingRealloc((ptr),(long)(size)) 90#define XpmCalloc(nelem, elsize) \ 91 boundCheckingCalloc((long)(nelem),(long) (elsize)) 92#endif 93 94#if defined(SCO) || defined(__USLC__) 95#include <stdint.h> /* For SIZE_MAX */ 96#endif 97#include <limits.h> 98#ifndef SIZE_MAX 99# ifdef ULONG_MAX 100# define SIZE_MAX ULONG_MAX 101# else 102# define SIZE_MAX UINT_MAX 103# endif 104#endif 105 106#ifdef O_CLOEXEC 107# define FOPEN_CLOEXEC "e" 108#else 109# define FOPEN_CLOEXEC "" 110# define O_CLOEXEC 0 111#endif 112 113#define XPMMAXCMTLEN BUFSIZ 114typedef struct { 115 unsigned int type; 116 union { 117 FILE *file; 118 char **data; 119 } stream; 120 char *cptr; 121 unsigned int line; 122 int CommentLength; 123 char Comment[XPMMAXCMTLEN]; 124 const char *Bcmt, *Ecmt; 125 char Bos, Eos; 126 int format; /* 1 if XPM1, 0 otherwise */ 127#ifdef CXPMPROG 128 int lineNum; 129 int charNum; 130#endif 131} xpmData; 132 133#define XPMARRAY 0 134#define XPMFILE 1 135#define XPMPIPE 2 136#define XPMBUFFER 3 137 138#define EOL '\n' 139#define TAB '\t' 140#define SPC ' ' 141 142typedef struct { 143 const char *type; /* key word */ 144 const char *Bcmt; /* string beginning comments */ 145 const char *Ecmt; /* string ending comments */ 146 char Bos; /* character beginning strings */ 147 char Eos; /* character ending strings */ 148 const char *Strs; /* strings separator */ 149 const char *Dec; /* data declaration string */ 150 const char *Boa; /* string beginning assignment */ 151 const char *Eoa; /* string ending assignment */ 152} xpmDataType; 153 154extern _X_HIDDEN xpmDataType xpmDataTypes[]; 155 156/* 157 * rgb values and ascii names (from rgb text file) rgb values, 158 * range of 0 -> 65535 color mnemonic of rgb value 159 */ 160typedef struct { 161 int r, g, b; 162 char *name; 163} xpmRgbName; 164 165/* Maximum number of rgb mnemonics allowed in rgb text file. */ 166#define MAX_RGBNAMES 1024 167 168extern _X_HIDDEN const char *xpmColorKeys[]; 169 170#define TRANSPARENT_COLOR "None" /* this must be a string! */ 171 172/* number of xpmColorKeys */ 173#define NKEYS 5 174 175/* XPM internal routines */ 176 177HFUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info)); 178HFUNC(xpmParseDataAndCreate, int, (Display *display, xpmData *data, 179 XImage **image_return, 180 XImage **shapeimage_return, 181 XpmImage *image, XpmInfo *info, 182 XpmAttributes *attributes)); 183 184HFUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors)); 185 186HFUNC(xpmInitAttributes, void, (XpmAttributes *attributes)); 187 188HFUNC(xpmInitXpmImage, void, (XpmImage *image)); 189 190HFUNC(xpmInitXpmInfo, void, (XpmInfo *info)); 191 192HFUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes)); 193HFUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes)); 194HFUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image, 195 XpmInfo *info)); 196 197#if !defined(FOR_MSW) && !defined(AMIGA) 198HFUNC(xpmCreatePixmapFromImage, int, (Display *display, Drawable d, 199 XImage *ximage, Pixmap *pixmap_return)); 200 201HFUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap, 202 XImage **ximage_return, 203 unsigned int *width, 204 unsigned int *height)); 205#endif 206 207/* structures and functions related to hastable code */ 208 209typedef struct _xpmHashAtom { 210 char *name; 211 void *data; 212} *xpmHashAtom; 213 214typedef struct { 215 unsigned int size; 216 unsigned int limit; 217 unsigned int used; 218 xpmHashAtom *atomTable; 219} xpmHashTable; 220 221HFUNC(xpmHashTableInit, int, (xpmHashTable *table)); 222HFUNC(xpmHashTableFree, void, (xpmHashTable *table)); 223HFUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s)); 224HFUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data)); 225 226#if defined(_MSC_VER) && defined(_M_X64) 227#define HashAtomData(i) ((void *)(long long)i) 228#define HashColorIndex(slot) ((unsigned long long)((*slot)->data)) 229#else 230#define HashAtomData(i) ((void *)(long)i) 231#define HashColorIndex(slot) ((unsigned long)((*slot)->data)) 232#endif 233#define USE_HASHTABLE (cpp > 2 && ncolors > 4) 234 235/* I/O utility */ 236 237HFUNC(xpmNextString, int, (xpmData *mdata)); 238HFUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return)); 239HFUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l)); 240 241#define xpmGetC(mdata) \ 242 ((!mdata->type || mdata->type == XPMBUFFER) ? \ 243 (*mdata->cptr++) : (getc(mdata->stream.file))) 244 245HFUNC(xpmNextWord, unsigned int, 246 (xpmData *mdata, char *buf, unsigned int buflen)); 247HFUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt)); 248HFUNC(xpmParseHeader, int, (xpmData *mdata)); 249HFUNC(xpmParseValues, int, (xpmData *data, unsigned int *width, 250 unsigned int *height, unsigned int *ncolors, 251 unsigned int *cpp, unsigned int *x_hotspot, 252 unsigned int *y_hotspot, unsigned int *hotspot, 253 unsigned int *extensions)); 254 255HFUNC(xpmParseColors, int, (xpmData *data, unsigned int ncolors, 256 unsigned int cpp, XpmColor **colorTablePtr, 257 xpmHashTable *hashtable)); 258 259HFUNC(xpmParseExtensions, int, (xpmData *data, XpmExtension **extensions, 260 unsigned int *nextensions)); 261 262/* RGB utility */ 263 264HFUNC(xpmReadRgbNames, int, (const char *rgb_fname, xpmRgbName *rgbn)); 265HFUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max, 266 int red, int green, int blue)); 267HFUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max)); 268#ifdef FOR_MSW 269HFUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b)); 270#endif 271 272#ifndef AMIGA 273HFUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp, 274 register XImage *img)); 275HFUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp, 276 register XImage *img)); 277 278/* 279 * Macros 280 * 281 * The XYNORMALIZE macro determines whether XY format data requires 282 * normalization and calls a routine to do so if needed. The logic in 283 * this module is designed for LSBFirst byte and bit order, so 284 * normalization is done as required to present the data in this order. 285 * 286 * The ZNORMALIZE macro performs byte and nibble order normalization if 287 * required for Z format data. 288 * 289 * The XYINDEX macro computes the index to the starting byte (char) boundary 290 * for a bitmap_unit containing a pixel with coordinates x and y for image 291 * data in XY format. 292 * 293 * The ZINDEX* macros compute the index to the starting byte (char) boundary 294 * for a pixel with coordinates x and y for image data in ZPixmap format. 295 * 296 */ 297 298#define XYNORMALIZE(bp, img) \ 299 if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \ 300 xpm_xynormalizeimagebits((unsigned char *)(bp), img) 301 302#define ZNORMALIZE(bp, img) \ 303 if (img->byte_order == MSBFirst) \ 304 xpm_znormalizeimagebits((unsigned char *)(bp), img) 305 306#define XYINDEX(x, y, img) \ 307 ((y) * img->bytes_per_line) + \ 308 (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3) 309 310#define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \ 311 (((x) * img->bits_per_pixel) >> 3) 312 313#define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2) 314 315#define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1) 316 317#define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x) 318 319#define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3) 320#endif /* not AMIGA */ 321 322#ifdef NEED_STRDUP 323HFUNC(xpmstrdup, char *, (char *s1)); 324#else 325#undef xpmstrdup 326#define xpmstrdup strdup 327#include <string.h> 328#endif 329 330#ifdef NEED_STRCASECMP 331HFUNC(xpmstrcasecmp, int, (char *s1, char *s2)); 332#else 333#undef xpmstrcasecmp 334#define xpmstrcasecmp strcasecmp 335#include <strings.h> 336#endif 337 338HFUNC(xpmatoui, unsigned int, 339 (char *p, unsigned int l, unsigned int *ui_return)); 340 341#endif 342