XpmI.h revision 52dc082b
1a966c04fSmrg/* 2a966c04fSmrg * Copyright (C) 1989-95 GROUPE BULL 3a966c04fSmrg * 4a966c04fSmrg * Permission is hereby granted, free of charge, to any person obtaining a copy 5a966c04fSmrg * of this software and associated documentation files (the "Software"), to 6a966c04fSmrg * deal in the Software without restriction, including without limitation the 7a966c04fSmrg * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8a966c04fSmrg * sell copies of the Software, and to permit persons to whom the Software is 9a966c04fSmrg * furnished to do so, subject to the following conditions: 10a966c04fSmrg * 11a966c04fSmrg * The above copyright notice and this permission notice shall be included in 12a966c04fSmrg * all copies or substantial portions of the Software. 13a966c04fSmrg * 14a966c04fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15a966c04fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16a966c04fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17a966c04fSmrg * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18a966c04fSmrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19a966c04fSmrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20a966c04fSmrg * 21a966c04fSmrg * Except as contained in this notice, the name of GROUPE BULL shall not be 22a966c04fSmrg * used in advertising or otherwise to promote the sale, use or other dealings 23a966c04fSmrg * in this Software without prior written authorization from GROUPE BULL. 24a966c04fSmrg */ 25a966c04fSmrg 26a966c04fSmrg/*****************************************************************************\ 27a966c04fSmrg* XpmI.h: * 28a966c04fSmrg* * 29a966c04fSmrg* XPM library * 30a966c04fSmrg* Internal Include file * 31a966c04fSmrg* * 32a966c04fSmrg* ** Everything defined here is subject to changes any time. ** * 33a966c04fSmrg* * 34a966c04fSmrg* Developed by Arnaud Le Hors * 35a966c04fSmrg\*****************************************************************************/ 36a966c04fSmrg 37a966c04fSmrg/* 38a966c04fSmrg * The code related to FOR_MSW has been added by 39a966c04fSmrg * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94 40a966c04fSmrg */ 41a966c04fSmrg 42a966c04fSmrg#ifndef XPMI_h 43a966c04fSmrg#define XPMI_h 44a966c04fSmrg 45a966c04fSmrg#include "xpm.h" 46a966c04fSmrg 47a966c04fSmrg/* 48a966c04fSmrg * lets try to solve include files 49a966c04fSmrg */ 50a966c04fSmrg 51a966c04fSmrg#include <sys/types.h> 52a966c04fSmrg#include <stdio.h> 53a966c04fSmrg#include <stdlib.h> 54a966c04fSmrg#include <limits.h> 55a966c04fSmrg/* stdio.h doesn't declare popen on a Sequent DYNIX OS */ 56a966c04fSmrg#ifdef sequent 57a966c04fSmrgextern FILE *popen(); 58a966c04fSmrg#endif 59a966c04fSmrg 60a966c04fSmrg#ifdef FOR_MSW 61a966c04fSmrg#include "simx.h" 62a966c04fSmrg#else 63a966c04fSmrg#include <X11/Xos.h> 64a966c04fSmrg#include <X11/Xfuncs.h> 65a966c04fSmrg#include <X11/Xmd.h> 66a966c04fSmrg#endif 67a966c04fSmrg 68a966c04fSmrg#ifdef VMS 69a966c04fSmrg#include <unixio.h> 70a966c04fSmrg#include <file.h> 71a966c04fSmrg#endif 72a966c04fSmrg 73a966c04fSmrg/* The following should help people wanting to use their own memory allocation 74a966c04fSmrg * functions. To avoid the overhead of a function call when the standard 75a966c04fSmrg * functions are used these are all macros, even the XpmFree function which 76a966c04fSmrg * needs to be a real function for the outside world though. 77a966c04fSmrg * So if change these be sure to change the XpmFree function in misc.c 78a966c04fSmrg * accordingly. 79a966c04fSmrg */ 80a966c04fSmrg#define XpmFree(ptr) free(ptr) 81a966c04fSmrg 82a966c04fSmrg#ifndef FOR_MSW 83a966c04fSmrg#define XpmMalloc(size) malloc((size)) 84a966c04fSmrg#define XpmRealloc(ptr, size) realloc((ptr), (size)) 85a966c04fSmrg#define XpmCalloc(nelem, elsize) calloc((nelem), (elsize)) 86a966c04fSmrg#else 87a966c04fSmrg/* checks for mallocs bigger than 64K */ 88a966c04fSmrg#define XpmMalloc(size) boundCheckingMalloc((long)(size))/* in simx.[ch] */ 89a966c04fSmrg#define XpmRealloc(ptr, size) boundCheckingRealloc((ptr),(long)(size)) 90a966c04fSmrg#define XpmCalloc(nelem, elsize) \ 91a966c04fSmrg boundCheckingCalloc((long)(nelem),(long) (elsize)) 92a966c04fSmrg#endif 93a966c04fSmrg 94a966c04fSmrg#if defined(SCO) || defined(__USLC__) 95a966c04fSmrg#include <stdint.h> /* For SIZE_MAX */ 96a966c04fSmrg#endif 97a966c04fSmrg#include <limits.h> 98a966c04fSmrg#ifndef SIZE_MAX 99a966c04fSmrg# ifdef ULONG_MAX 100a966c04fSmrg# define SIZE_MAX ULONG_MAX 10197cf2ee2Smrg# else 102a966c04fSmrg# define SIZE_MAX UINT_MAX 103a966c04fSmrg# endif 104a966c04fSmrg#endif 105a966c04fSmrg 10652dc082bSmrg#ifdef O_CLOEXEC 10752dc082bSmrg# define FOPEN_CLOEXEC "e" 10852dc082bSmrg#else 10952dc082bSmrg# define FOPEN_CLOEXEC "" 11052dc082bSmrg# define O_CLOEXEC 0 11152dc082bSmrg#endif 11252dc082bSmrg 113a966c04fSmrg#define XPMMAXCMTLEN BUFSIZ 114a966c04fSmrgtypedef struct { 115a966c04fSmrg unsigned int type; 116a966c04fSmrg union { 117a966c04fSmrg FILE *file; 118a966c04fSmrg char **data; 119a966c04fSmrg } stream; 120a966c04fSmrg char *cptr; 121a966c04fSmrg unsigned int line; 122a966c04fSmrg int CommentLength; 123a966c04fSmrg char Comment[XPMMAXCMTLEN]; 12497cf2ee2Smrg const char *Bcmt, *Ecmt; 12597cf2ee2Smrg char Bos, Eos; 126a966c04fSmrg int format; /* 1 if XPM1, 0 otherwise */ 127a966c04fSmrg#ifdef CXPMPROG 128a966c04fSmrg int lineNum; 129a966c04fSmrg int charNum; 130a966c04fSmrg#endif 131a966c04fSmrg} xpmData; 132a966c04fSmrg 133a966c04fSmrg#define XPMARRAY 0 134a966c04fSmrg#define XPMFILE 1 135a966c04fSmrg#define XPMPIPE 2 136a966c04fSmrg#define XPMBUFFER 3 137a966c04fSmrg 138a966c04fSmrg#define EOL '\n' 139a966c04fSmrg#define TAB '\t' 140a966c04fSmrg#define SPC ' ' 141a966c04fSmrg 142a966c04fSmrgtypedef struct { 14397cf2ee2Smrg const char *type; /* key word */ 14497cf2ee2Smrg const char *Bcmt; /* string beginning comments */ 14597cf2ee2Smrg const char *Ecmt; /* string ending comments */ 146a966c04fSmrg char Bos; /* character beginning strings */ 147a966c04fSmrg char Eos; /* character ending strings */ 14897cf2ee2Smrg const char *Strs; /* strings separator */ 14997cf2ee2Smrg const char *Dec; /* data declaration string */ 15097cf2ee2Smrg const char *Boa; /* string beginning assignment */ 15197cf2ee2Smrg const char *Eoa; /* string ending assignment */ 152a966c04fSmrg} xpmDataType; 153a966c04fSmrg 15452dc082bSmrgextern _X_HIDDEN xpmDataType xpmDataTypes[]; 155a966c04fSmrg 156a966c04fSmrg/* 157a966c04fSmrg * rgb values and ascii names (from rgb text file) rgb values, 158a966c04fSmrg * range of 0 -> 65535 color mnemonic of rgb value 159a966c04fSmrg */ 160a966c04fSmrgtypedef struct { 161a966c04fSmrg int r, g, b; 162a966c04fSmrg char *name; 163a966c04fSmrg} xpmRgbName; 164a966c04fSmrg 165a966c04fSmrg/* Maximum number of rgb mnemonics allowed in rgb text file. */ 166a966c04fSmrg#define MAX_RGBNAMES 1024 167a966c04fSmrg 16852dc082bSmrgextern _X_HIDDEN const char *xpmColorKeys[]; 169a966c04fSmrg 170a966c04fSmrg#define TRANSPARENT_COLOR "None" /* this must be a string! */ 171a966c04fSmrg 172a966c04fSmrg/* number of xpmColorKeys */ 173a966c04fSmrg#define NKEYS 5 174a966c04fSmrg 175a966c04fSmrg/* XPM internal routines */ 176a966c04fSmrg 17752dc082bSmrgHFUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info)); 17852dc082bSmrgHFUNC(xpmParseDataAndCreate, int, (Display *display, xpmData *data, 179a966c04fSmrg XImage **image_return, 180a966c04fSmrg XImage **shapeimage_return, 181a966c04fSmrg XpmImage *image, XpmInfo *info, 182a966c04fSmrg XpmAttributes *attributes)); 183a966c04fSmrg 18452dc082bSmrgHFUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors)); 185a966c04fSmrg 18652dc082bSmrgHFUNC(xpmInitAttributes, void, (XpmAttributes *attributes)); 187a966c04fSmrg 18852dc082bSmrgHFUNC(xpmInitXpmImage, void, (XpmImage *image)); 189a966c04fSmrg 19052dc082bSmrgHFUNC(xpmInitXpmInfo, void, (XpmInfo *info)); 191a966c04fSmrg 19252dc082bSmrgHFUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes)); 19352dc082bSmrgHFUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes)); 19452dc082bSmrgHFUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image, 195a966c04fSmrg XpmInfo *info)); 196a966c04fSmrg 197a966c04fSmrg#if !defined(FOR_MSW) && !defined(AMIGA) 19852dc082bSmrgHFUNC(xpmCreatePixmapFromImage, int, (Display *display, Drawable d, 199a966c04fSmrg XImage *ximage, Pixmap *pixmap_return)); 200a966c04fSmrg 20152dc082bSmrgHFUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap, 202a966c04fSmrg XImage **ximage_return, 203a966c04fSmrg unsigned int *width, 204a966c04fSmrg unsigned int *height)); 205a966c04fSmrg#endif 206a966c04fSmrg 207a966c04fSmrg/* structures and functions related to hastable code */ 208a966c04fSmrg 209a966c04fSmrgtypedef struct _xpmHashAtom { 210a966c04fSmrg char *name; 211a966c04fSmrg void *data; 212a966c04fSmrg} *xpmHashAtom; 213a966c04fSmrg 214a966c04fSmrgtypedef struct { 215a966c04fSmrg unsigned int size; 216a966c04fSmrg unsigned int limit; 217a966c04fSmrg unsigned int used; 218a966c04fSmrg xpmHashAtom *atomTable; 219a966c04fSmrg} xpmHashTable; 220a966c04fSmrg 22152dc082bSmrgHFUNC(xpmHashTableInit, int, (xpmHashTable *table)); 22252dc082bSmrgHFUNC(xpmHashTableFree, void, (xpmHashTable *table)); 22352dc082bSmrgHFUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s)); 22452dc082bSmrgHFUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data)); 225a966c04fSmrg 226edce3322Smrg#if defined(_MSC_VER) && defined(_M_X64) 227edce3322Smrg#define HashAtomData(i) ((void *)(long long)i) 228edce3322Smrg#define HashColorIndex(slot) ((unsigned long long)((*slot)->data)) 229edce3322Smrg#else 230a966c04fSmrg#define HashAtomData(i) ((void *)(long)i) 231a966c04fSmrg#define HashColorIndex(slot) ((unsigned long)((*slot)->data)) 232edce3322Smrg#endif 233a966c04fSmrg#define USE_HASHTABLE (cpp > 2 && ncolors > 4) 234a966c04fSmrg 235a966c04fSmrg/* I/O utility */ 236a966c04fSmrg 23752dc082bSmrgHFUNC(xpmNextString, int, (xpmData *mdata)); 23852dc082bSmrgHFUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return)); 23952dc082bSmrgHFUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l)); 240a966c04fSmrg 241a966c04fSmrg#define xpmGetC(mdata) \ 242a966c04fSmrg ((!mdata->type || mdata->type == XPMBUFFER) ? \ 243a966c04fSmrg (*mdata->cptr++) : (getc(mdata->stream.file))) 244a966c04fSmrg 24552dc082bSmrgHFUNC(xpmNextWord, unsigned int, 246a966c04fSmrg (xpmData *mdata, char *buf, unsigned int buflen)); 24752dc082bSmrgHFUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt)); 24852dc082bSmrgHFUNC(xpmParseHeader, int, (xpmData *mdata)); 24952dc082bSmrgHFUNC(xpmParseValues, int, (xpmData *data, unsigned int *width, 250a966c04fSmrg unsigned int *height, unsigned int *ncolors, 251a966c04fSmrg unsigned int *cpp, unsigned int *x_hotspot, 252a966c04fSmrg unsigned int *y_hotspot, unsigned int *hotspot, 253a966c04fSmrg unsigned int *extensions)); 254a966c04fSmrg 25552dc082bSmrgHFUNC(xpmParseColors, int, (xpmData *data, unsigned int ncolors, 256a966c04fSmrg unsigned int cpp, XpmColor **colorTablePtr, 257a966c04fSmrg xpmHashTable *hashtable)); 258a966c04fSmrg 25952dc082bSmrgHFUNC(xpmParseExtensions, int, (xpmData *data, XpmExtension **extensions, 260a966c04fSmrg unsigned int *nextensions)); 261a966c04fSmrg 262a966c04fSmrg/* RGB utility */ 263a966c04fSmrg 26452dc082bSmrgHFUNC(xpmReadRgbNames, int, (const char *rgb_fname, xpmRgbName *rgbn)); 26552dc082bSmrgHFUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max, 266a966c04fSmrg int red, int green, int blue)); 26752dc082bSmrgHFUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max)); 268a966c04fSmrg#ifdef FOR_MSW 26952dc082bSmrgHFUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b)); 270a966c04fSmrg#endif 271a966c04fSmrg 272a966c04fSmrg#ifndef AMIGA 27352dc082bSmrgHFUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp, 274a966c04fSmrg register XImage *img)); 27552dc082bSmrgHFUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp, 276a966c04fSmrg register XImage *img)); 277a966c04fSmrg 278a966c04fSmrg/* 279a966c04fSmrg * Macros 280a966c04fSmrg * 281a966c04fSmrg * The XYNORMALIZE macro determines whether XY format data requires 282a966c04fSmrg * normalization and calls a routine to do so if needed. The logic in 283a966c04fSmrg * this module is designed for LSBFirst byte and bit order, so 284a966c04fSmrg * normalization is done as required to present the data in this order. 285a966c04fSmrg * 286a966c04fSmrg * The ZNORMALIZE macro performs byte and nibble order normalization if 287a966c04fSmrg * required for Z format data. 288a966c04fSmrg * 289a966c04fSmrg * The XYINDEX macro computes the index to the starting byte (char) boundary 290a966c04fSmrg * for a bitmap_unit containing a pixel with coordinates x and y for image 291a966c04fSmrg * data in XY format. 292a966c04fSmrg * 293a966c04fSmrg * The ZINDEX* macros compute the index to the starting byte (char) boundary 294a966c04fSmrg * for a pixel with coordinates x and y for image data in ZPixmap format. 295a966c04fSmrg * 296a966c04fSmrg */ 297a966c04fSmrg 298a966c04fSmrg#define XYNORMALIZE(bp, img) \ 299a966c04fSmrg if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \ 300a966c04fSmrg xpm_xynormalizeimagebits((unsigned char *)(bp), img) 301a966c04fSmrg 302a966c04fSmrg#define ZNORMALIZE(bp, img) \ 303a966c04fSmrg if (img->byte_order == MSBFirst) \ 304a966c04fSmrg xpm_znormalizeimagebits((unsigned char *)(bp), img) 305a966c04fSmrg 306a966c04fSmrg#define XYINDEX(x, y, img) \ 307a966c04fSmrg ((y) * img->bytes_per_line) + \ 308a966c04fSmrg (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3) 309a966c04fSmrg 310a966c04fSmrg#define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \ 311a966c04fSmrg (((x) * img->bits_per_pixel) >> 3) 312a966c04fSmrg 313a966c04fSmrg#define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2) 314a966c04fSmrg 315a966c04fSmrg#define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1) 316a966c04fSmrg 317a966c04fSmrg#define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x) 318a966c04fSmrg 319a966c04fSmrg#define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3) 320a966c04fSmrg#endif /* not AMIGA */ 321a966c04fSmrg 322a966c04fSmrg#ifdef NEED_STRDUP 32352dc082bSmrgHFUNC(xpmstrdup, char *, (char *s1)); 324a966c04fSmrg#else 325a966c04fSmrg#undef xpmstrdup 326a966c04fSmrg#define xpmstrdup strdup 32797cf2ee2Smrg#include <string.h> 328a966c04fSmrg#endif 329a966c04fSmrg 33097cf2ee2Smrg#ifdef NEED_STRCASECMP 33152dc082bSmrgHFUNC(xpmstrcasecmp, int, (char *s1, char *s2)); 332a966c04fSmrg#else 333a966c04fSmrg#undef xpmstrcasecmp 334a966c04fSmrg#define xpmstrcasecmp strcasecmp 33597cf2ee2Smrg#include <strings.h> 336a966c04fSmrg#endif 337a966c04fSmrg 33852dc082bSmrgHFUNC(xpmatoui, unsigned int, 339a966c04fSmrg (char *p, unsigned int l, unsigned int *ui_return)); 340a966c04fSmrg 341a966c04fSmrg#endif 342