1 /* 2 * Motif 3 * 4 * Copyright (c) 1987-2012, The Open Group. All rights reserved. 5 * 6 * These libraries and programs are free software; you can 7 * redistribute them and/or modify them under the terms of the GNU 8 * Lesser General Public License as published by the Free Software 9 * Foundation; either version 2 of the License, or (at your option) 10 * any later version. 11 * 12 * These libraries and programs are distributed in the hope that 13 * they will be useful, but WITHOUT ANY WARRANTY; without even the 14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 * PURPOSE. See the GNU Lesser General Public License for more 16 * details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with these librararies and programs; if not, write 20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 21 * Floor, Boston, MA 02110-1301 USA 22 */ 23 24 #ifndef _XpmI_h 25 #define _XpmI_h 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /* Xpm internal symbols are prefixed with _Xm */ 32 33 #define xpmParseData _XmxpmParseData 34 #define xpmParseDataAndCreate _XmxpmParseDataAndCreate 35 #define xpmFreeColorTable _XmxpmFreeColorTable 36 #define xpmInitAttributes _XmxpmInitAttributes 37 #define xpmInitXpmImage _XmxpmInitXpmImage 38 #define xpmInitXpmInfo _XmxpmInitXpmInfo 39 #define xpmSetInfoMask _XmxpmSetInfoMask 40 #define xpmSetInfo _XmxpmSetInfo 41 #define xpmSetAttributes _XmxpmSetAttributes 42 #define xpmCreatePixmapFromImage _XmxpmCreatePixmapFromImage 43 #define xpmCreateImageFromPixmap _XmxpmCreateImageFromPixmap 44 #define xpmHashTableInit _XmxpmHashTableInit 45 #define xpmHashTableFree _XmxpmHashTableFree 46 #define xpmHashSlot _XmxpmHashSlot 47 #define xpmHashIntern _XmxpmHashIntern 48 #define xpmNextString _XmxpmNextString 49 #define xpmNextUI _XmxpmNextUI 50 #define xpmGetString _XmxpmGetString 51 #define xpmNextWord _XmxpmNextWord 52 #define xpmGetCmt _XmxpmGetCmt 53 #define xpmParseHeader _XmxpmParseHeader 54 #define xpmParseValues _XmxpmParseValues 55 #define xpmParseColors _XmxpmParseColors 56 #define xpmParseExtensions _XmxpmParseExtensions 57 #define xpmReadRgbNames _XmxpmReadRgbNames 58 #define xpmGetRgbName _XmxpmGetRgbName 59 #define xpmFreeRgbNames _XmxpmFreeRgbNames 60 #define xpmGetRGBfromName _XmxpmGetRGBfromName 61 #define xpm_xynormalizeimagebits _Xmxpm_xynormalizeimagebits 62 #define xpm_znormalizeimagebits _Xmxpm_znormalizeimagebits 63 #define xpmstrdup _Xmxpmstrdup 64 #define xpmstrcasecmp _Xmxpmstrcasecmp 65 #define xpmatoui _Xmxpmatoui 66 #define xpmDataTypes _XmxpmDataTypes 67 #define xpmColorKeys _XmxpmColorKeys 68 69 /* The following is the original XpmI.h header file, 70 except that it includes XpmP.h instead of xpm.h */ 71 72 /* 73 * Copyright (C) 1989-95 GROUPE BULL 74 * 75 * Permission is hereby granted, free of charge, to any person obtaining a copy 76 * of this software and associated documentation files (the "Software"), to 77 * deal in the Software without restriction, including without limitation the 78 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 79 * sell copies of the Software, and to permit persons to whom the Software is 80 * furnished to do so, subject to the following conditions: 81 * 82 * The above copyright notice and this permission notice shall be included in 83 * all copies or substantial portions of the Software. 84 * 85 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 86 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 87 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 88 * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 89 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 90 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 91 * 92 * Except as contained in this notice, the name of GROUPE BULL shall not be 93 * used in advertising or otherwise to promote the sale, use or other dealings 94 * in this Software without prior written authorization from GROUPE BULL. 95 */ 96 97 /*****************************************************************************\ 98 * XpmI.h: * 99 * * 100 * XPM library * 101 * Internal Include file * 102 * * 103 * ** Everything defined here is subject to changes any time. ** * 104 * * 105 * Developed by Arnaud Le Hors * 106 \*****************************************************************************/ 107 108 /* 109 * The code related to FOR_MSW has been added by 110 * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94 111 */ 112 113 #ifndef XPMI_h 114 #define XPMI_h 115 116 #include "XpmP.h" 117 118 /* 119 * lets try to solve include files 120 */ 121 122 #include <sys/types.h> 123 #include <stdio.h> 124 #include <stdlib.h> 125 #include <limits.h> 126 #include <X11/Xmd.h> 127 /* stdio.h doesn't declare popen on a Sequent DYNIX OS */ 128 #ifdef sequent 129 extern FILE *popen(); 130 #endif 131 132 #if defined(SYSV) || defined(SVR4) || defined(VMS) || defined(WIN32) || defined (_SVID_SOURCE) || defined(__DragonFly__) 133 #include <string.h> 134 135 #ifndef index 136 #define index strchr 137 #endif 138 139 #ifndef rindex 140 #define rindex strrchr 141 #endif 142 143 #else /* defined(SYSV) || defined(SVR4) || defined(VMS) */ 144 #include <strings.h> 145 #endif 146 147 148 149 #if defined(SYSV) || defined(SVR4) || defined(VMS) || defined(WIN32) 150 #ifndef bcopy 151 #define bcopy(source, dest, count) memcpy(dest, source, count) 152 #endif 153 #ifndef bzero 154 #define bzero(b, len) memset(b, 0, len) 155 #endif 156 #endif 157 158 /* the following is defined in X11R6 but not in previous versions */ 159 #ifdef __alpha 160 #ifndef LONG64 161 #define LONG64 162 #endif 163 #endif 164 165 #ifdef VMS 166 #include <unixio.h> 167 #include <file.h> 168 #endif 169 170 /* The following should help people wanting to use their own memory allocation 171 * functions. To avoid the overhead of a function call when the standard 172 * functions are used these are all macros, even the XpmFree function which 173 * needs to be a real function for the outside world though. 174 * So if change these be sure to change the XpmFree function in misc.c 175 * accordingly. 176 */ 177 #ifndef NO_XPMFREE_MACRO 178 #ifdef XpmFree 179 #undef XpmFree 180 #endif 181 #define XpmFree(ptr) free(ptr) 182 #endif 183 184 #ifndef FOR_MSW 185 #define XpmMalloc(size) malloc((size)) 186 #define XpmRealloc(ptr, size) realloc((ptr), (size)) 187 #define XpmCalloc(nelem, elsize) calloc((nelem), (elsize)) 188 #else 189 /* checks for mallocs bigger than 64K */ 190 #define XpmMalloc(size) boundCheckingMalloc((long)(size))/* in simx.[ch] */ 191 #define XpmRealloc(ptr, size) boundCheckingRealloc((ptr),(long)(size)) 192 #define XpmCalloc(nelem, elsize) \ 193 boundCheckingCalloc((long)(nelem),(long) (elsize)) 194 #endif 195 196 #define XPMMAXCMTLEN BUFSIZ 197 typedef struct { 198 unsigned int type; 199 union { 200 FILE *file; 201 char **data; 202 } stream; 203 char *cptr; 204 unsigned int line; 205 int CommentLength; 206 char Comment[XPMMAXCMTLEN]; 207 char *Bcmt, *Ecmt, Bos, Eos; 208 int format; /* 1 if XPM1, 0 otherwise */ 209 } xpmData; 210 211 #define XPMARRAY 0 212 #define XPMFILE 1 213 #define XPMPIPE 2 214 #define XPMBUFFER 3 215 216 #define EOL '\n' 217 #define TAB '\t' 218 #define SPC ' ' 219 220 typedef struct { 221 char *type; /* key word */ 222 char *Bcmt; /* string beginning comments */ 223 char *Ecmt; /* string ending comments */ 224 char Bos; /* character beginning strings */ 225 char Eos; /* character ending strings */ 226 char *Strs; /* strings separator */ 227 char *Dec; /* data declaration string */ 228 char *Boa; /* string beginning assignment */ 229 char *Eoa; /* string ending assignment */ 230 } xpmDataType; 231 232 extern xpmDataType xpmDataTypes[]; 233 234 /* 235 * rgb values and ascii names (from rgb text file) rgb values, 236 * range of 0 -> 65535 color mnemonic of rgb value 237 */ 238 typedef struct { 239 int r, g, b; 240 char *name; 241 } xpmRgbName; 242 243 /* Maximum number of rgb mnemonics allowed in rgb text file. */ 244 #define MAX_RGBNAMES 1024 245 246 extern char *xpmColorKeys[]; 247 248 #define TRANSPARENT_COLOR "None" /* this must be a string! */ 249 250 /* number of xpmColorKeys */ 251 #define NKEYS 5 252 253 /* XPM internal routines */ 254 255 FUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info)); 256 FUNC(xpmParseDataAndCreate, int, (Display *display, xpmData *data, 257 XImage **image_return, 258 XImage **shapeimage_return, 259 XpmImage *image, XpmInfo *info, 260 XpmAttributes *attributes)); 261 262 FUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors)); 263 264 FUNC(xpmInitAttributes, void, (XpmAttributes *attributes)); 265 266 FUNC(xpmInitXpmImage, void, (XpmImage *image)); 267 268 FUNC(xpmInitXpmInfo, void, (XpmInfo *info)); 269 270 FUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes)); 271 FUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes)); 272 FUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image, 273 XpmInfo *info)); 274 275 #ifndef FOR_MSW 276 FUNC(xpmCreatePixmapFromImage, void, (Display *display, Drawable d, 277 XImage *ximage, Pixmap *pixmap_return)); 278 279 FUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap, 280 XImage **ximage_return, 281 unsigned int *width, 282 unsigned int *height)); 283 #endif 284 285 /* structures and functions related to hastable code */ 286 287 typedef struct _xpmHashAtom { 288 char *name; 289 void *data; 290 } *xpmHashAtom; 291 292 typedef struct { 293 unsigned int size; 294 unsigned int limit; 295 unsigned int used; 296 xpmHashAtom *atomTable; 297 } xpmHashTable; 298 299 FUNC(xpmHashTableInit, int, (xpmHashTable *table)); 300 FUNC(xpmHashTableFree, void, (xpmHashTable *table)); 301 FUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s)); 302 FUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data)); 303 304 #define HashAtomData(i) ((void *)i) 305 #define HashColorIndex(slot) ((unsigned int)((*slot)->data)) 306 #define USE_HASHTABLE (cpp > 2 && ncolors > 4) 307 308 /* I/O utility */ 309 310 FUNC(xpmNextString, int, (xpmData *mdata)); 311 FUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return)); 312 FUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l)); 313 314 #define xpmGetC(mdata) \ 315 ((!mdata->type || mdata->type == XPMBUFFER) ? \ 316 (*mdata->cptr++) : (getc(mdata->stream.file))) 317 318 FUNC(xpmNextWord, unsigned int, 319 (xpmData *mdata, char *buf, unsigned int buflen)); 320 FUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt)); 321 FUNC(xpmParseHeader, int, (xpmData *mdata)); 322 FUNC(xpmParseValues, int, (xpmData *data, unsigned int *width, 323 unsigned int *height, unsigned int *ncolors, 324 unsigned int *cpp, unsigned int *x_hotspot, 325 unsigned int *y_hotspot, unsigned int *hotspot, 326 unsigned int *extensions)); 327 328 FUNC(xpmParseColors, int, (xpmData *data, unsigned int ncolors, 329 unsigned int cpp, XpmColor **colorTablePtr, 330 xpmHashTable *hashtable)); 331 332 FUNC(xpmParseExtensions, int, (xpmData *data, XpmExtension **extensions, 333 unsigned int *nextensions)); 334 335 /* RGB utility */ 336 337 FUNC(xpmReadRgbNames, int, (char *rgb_fname, xpmRgbName *rgbn)); 338 FUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max, 339 int red, int green, int blue)); 340 FUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max)); 341 #ifdef FOR_MSW 342 FUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b)); 343 #endif 344 345 FUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp, 346 register XImage *img)); 347 FUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp, 348 register XImage *img)); 349 350 /* 351 * Macros 352 * 353 * The XYNORMALIZE macro determines whether XY format data requires 354 * normalization and calls a routine to do so if needed. The logic in 355 * this module is designed for LSBFirst byte and bit order, so 356 * normalization is done as required to present the data in this order. 357 * 358 * The ZNORMALIZE macro performs byte and nibble order normalization if 359 * required for Z format data. 360 * 361 * The XYINDEX macro computes the index to the starting byte (char) boundary 362 * for a bitmap_unit containing a pixel with coordinates x and y for image 363 * data in XY format. 364 * 365 * The ZINDEX* macros compute the index to the starting byte (char) boundary 366 * for a pixel with coordinates x and y for image data in ZPixmap format. 367 * 368 */ 369 370 #define XYNORMALIZE(bp, img) \ 371 if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \ 372 xpm_xynormalizeimagebits((unsigned char *)(bp), img) 373 374 #define ZNORMALIZE(bp, img) \ 375 if (img->byte_order == MSBFirst) \ 376 xpm_znormalizeimagebits((unsigned char *)(bp), img) 377 378 #define XYINDEX(x, y, img) \ 379 ((y) * img->bytes_per_line) + \ 380 (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3) 381 382 #define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \ 383 (((x) * img->bits_per_pixel) >> 3) 384 385 #define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2) 386 387 #define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1) 388 389 #define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x) 390 391 #define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3) 392 393 #ifdef __STDC__ 394 #define Const const 395 #else 396 #define Const /**/ 397 #endif 398 399 #ifdef NEED_STRDUP 400 FUNC(xpmstrdup, char *, (char *s1)); 401 #else 402 #undef xpmstrdup 403 #define xpmstrdup strdup 404 #endif 405 406 #ifdef NEED_STRCASECMP 407 FUNC(xpmstrcasecmp, int, (char *s1, char *s2)); 408 #else 409 #undef xpmstrcasecmp 410 #define xpmstrcasecmp strcasecmp 411 #endif 412 413 FUNC(xpmatoui, unsigned int, 414 (char *p, unsigned int l, unsigned int *ui_return)); 415 416 #endif 417 418 #ifdef __cplusplus 419 } /* Close scope of 'extern "C"' declaration which encloses file. */ 420 #endif 421 422 #endif /* _XpmI_h */ 423