Back to index

plt-scheme  4.2.1
xpmP.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1989-95 GROUPE BULL
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to
00006  * deal in the Software without restriction, including without limitation the
00007  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00008  * sell copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00017  * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00018  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00019  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00020  *
00021  * Except as contained in this notice, the name of GROUPE BULL shall not be
00022  * used in advertising or otherwise to promote the sale, use or other dealings
00023  * in this Software without prior written authorization from GROUPE BULL.
00024  */
00025 
00026 /*****************************************************************************\
00027 * xpmP.h:                                                                     *
00028 *                                                                             *
00029 *  XPM library                                                                *
00030 *  Private Include file                                                       *
00031 *                                                                             *
00032 *  Developed by Arnaud Le Hors                                                *
00033 \*****************************************************************************/
00034 
00035 /*
00036  * The code related to FOR_MSW has been added by
00037  * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
00038  */
00039 
00040 #ifndef XPMP_h
00041 #define XPMP_h
00042 
00043 #include "xpm.h"
00044 
00045 /*
00046  * lets try to solve include files
00047  */
00048 
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 /* stdio.h doesn't declare popen on a Sequent DYNIX OS */
00052 #ifdef sequent
00053 extern FILE *popen();
00054 #endif
00055 
00056 #if defined(__FreeBSD__) || defined(SYSV) || defined(SVR4) || defined(VMS)
00057 #include <string.h>
00058 
00059 #ifndef index
00060 #define index strchr
00061 #endif
00062 
00063 #ifndef rindex
00064 #define rindex strrchr
00065 #endif
00066 
00067 #else  /* defined(SYSV) || defined(SVR4) || defined(VMS) */
00068 #include <strings.h>
00069 #endif
00070 
00071 
00072 
00073 #if defined(SYSV) || defined(SVR4) || defined(VMS)
00074 #define bcopy(source, dest, count) memcpy(dest, source, count)
00075 #define bzero(b, len) memset(b, 0, len)
00076 #endif
00077 
00078 /* PLTSCHEME hack: */
00079 #include "mzconfig.h"
00080 #ifdef SIZEOF_LONG
00081 # if SIZEOF_LONG == 8
00082 #  define LONG64
00083 # endif
00084 #endif
00085 
00086 /* the following is defined in X11R6 but not in previous versions */
00087 #ifdef __alpha
00088 #ifndef LONG64
00089 #define LONG64
00090 #endif
00091 #endif
00092 
00093 #ifdef VMS
00094 #include <unixio.h>
00095 #include <file.h>
00096 #endif
00097 
00098 /* the following should help people wanting to use their own functions */
00099 #ifndef FOR_MSW
00100 #define XpmMalloc(size) malloc((size))
00101 #define XpmRealloc(ptr, size) realloc((ptr), (size))
00102 #define XpmCalloc(nelem, elsize) calloc((nelem), (elsize))
00103 #else
00104 /* checks for mallocs bigger than 64K */
00105 #define XpmMalloc(size) boundCheckingMalloc((long)(size))/* in simx.[ch] */
00106 #define XpmRealloc(ptr, size) boundCheckingRealloc((ptr),(long)(size))
00107 #define XpmCalloc(nelem, elsize) \
00108               boundCheckingCalloc((long)(nelem),(long) (elsize))
00109 #endif
00110 
00111 #define XPMMAXCMTLEN BUFSIZ
00112 typedef struct {
00113     unsigned int type;
00114     union {
00115        FILE *file;
00116        char **data;
00117     }     stream;
00118     char *cptr;
00119     unsigned int line;
00120     int CommentLength;
00121     char Comment[XPMMAXCMTLEN];
00122     char *Bcmt, *Ecmt, Bos, Eos;
00123     int format;                    /* 1 if XPM1, 0 otherwise */
00124 }      xpmData;
00125 
00126 #define XPMARRAY 0
00127 #define XPMFILE  1
00128 #define XPMPIPE  2
00129 #define XPMBUFFER 3
00130 
00131 #define EOL '\n'
00132 #define TAB '\t'
00133 #define SPC ' '
00134 
00135 typedef struct {
00136     char *type;                    /* key word */
00137     char *Bcmt;                    /* string beginning comments */
00138     char *Ecmt;                    /* string ending comments */
00139     char Bos;               /* character beginning strings */
00140     char Eos;               /* character ending strings */
00141     char *Strs;                    /* strings separator */
00142     char *Dec;                     /* data declaration string */
00143     char *Boa;                     /* string beginning assignment */
00144     char *Eoa;                     /* string ending assignment */
00145 }      xpmDataType;
00146 
00147 extern xpmDataType xpmDataTypes[];
00148 
00149 /*
00150  * rgb values and ascii names (from rgb text file) rgb values,
00151  * range of 0 -> 65535 color mnemonic of rgb value
00152  */
00153 typedef struct {
00154     int r, g, b;
00155     char *name;
00156 }      xpmRgbName;
00157 
00158 /* Maximum number of rgb mnemonics allowed in rgb text file. */
00159 #define MAX_RGBNAMES 1024
00160 
00161 extern char *xpmColorKeys[];
00162 
00163 #define TRANSPARENT_COLOR "None"   /* this must be a string! */
00164 
00165 /* number of xpmColorKeys */
00166 #define NKEYS 5
00167 
00168 /* XPM private routines */
00169 
00170 FUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info));
00171 
00172 FUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors));
00173 
00174 FUNC(xpmInitAttributes, void, (XpmAttributes *attributes));
00175 
00176 FUNC(xpmInitXpmImage, void, (XpmImage *image));
00177 
00178 FUNC(xpmInitXpmInfo, void, (XpmInfo *info));
00179 
00180 FUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes));
00181 FUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes));
00182 FUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image,
00183                            XpmInfo *info));
00184 
00185 FUNC(xpmCreatePixmapFromImage, void, (Display *display, Drawable d,
00186                                   XImage *ximage, Pixmap *pixmap_return));
00187 
00188 FUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap,
00189                                   XImage **ximage_return,
00190                                   unsigned int *width,
00191                                   unsigned int *height));
00192 
00193 /* I/O utility */
00194 
00195 FUNC(xpmNextString, int, (xpmData *mdata));
00196 FUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return));
00197 FUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l));
00198 
00199 #define xpmGetC(mdata) \
00200        ((!mdata->type || mdata->type == XPMBUFFER) ? \
00201         (*mdata->cptr++) : (getc(mdata->stream.file)))
00202 
00203 FUNC(xpmNextWord, unsigned int,
00204      (xpmData *mdata, char *buf, unsigned int buflen));
00205 FUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt));
00206 FUNC(xpmParseHeader, int, (xpmData *mdata));
00207 
00208 /* RGB utility */
00209 
00210 FUNC(xpmReadRgbNames, int, (char *rgb_fname, xpmRgbName *rgbn));
00211 FUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max,
00212                           int red, int green, int blue));
00213 FUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max));
00214 #ifdef FOR_MSW
00215 FUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b));
00216 #endif
00217 
00218 FUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp,
00219                                   register XImage *img));
00220 FUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
00221                                  register XImage *img));
00222 
00223 /*
00224  * Macros
00225  *
00226  * The XYNORMALIZE macro determines whether XY format data requires
00227  * normalization and calls a routine to do so if needed. The logic in
00228  * this module is designed for LSBFirst byte and bit order, so
00229  * normalization is done as required to present the data in this order.
00230  *
00231  * The ZNORMALIZE macro performs byte and nibble order normalization if
00232  * required for Z format data.
00233  *
00234  * The XYINDEX macro computes the index to the starting byte (char) boundary
00235  * for a bitmap_unit containing a pixel with coordinates x and y for image
00236  * data in XY format.
00237  *
00238  * The ZINDEX* macros compute the index to the starting byte (char) boundary
00239  * for a pixel with coordinates x and y for image data in ZPixmap format.
00240  *
00241  */
00242 
00243 #define XYNORMALIZE(bp, img) \
00244     if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \
00245        xpm_xynormalizeimagebits((unsigned char *)(bp), img)
00246 
00247 #define ZNORMALIZE(bp, img) \
00248     if (img->byte_order == MSBFirst) \
00249        xpm_znormalizeimagebits((unsigned char *)(bp), img)
00250 
00251 #define XYINDEX(x, y, img) \
00252     ((y) * img->bytes_per_line) + \
00253     (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3)
00254 
00255 #define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \
00256     (((x) * img->bits_per_pixel) >> 3)
00257 
00258 #define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2)
00259 
00260 #define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1)
00261 
00262 #define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x)
00263 
00264 #define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3)
00265 
00266 #ifdef __STDC__
00267 #define Const const
00268 #else
00269 #define Const 
00270 #endif
00271 
00272 /*
00273  * there are structures and functions related to hastable code
00274  */
00275 
00276 typedef struct _xpmHashAtom {
00277     char *name;
00278     void *data;
00279 }      *xpmHashAtom;
00280 
00281 typedef struct {
00282     int size;
00283     int limit;
00284     int used;
00285     xpmHashAtom *atomTable;
00286 }      xpmHashTable;
00287 
00288 FUNC(xpmHashTableInit, int, (xpmHashTable *table));
00289 FUNC(xpmHashTableFree, void, (xpmHashTable *table));
00290 FUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s));
00291 FUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data));
00292 
00293 #define HashAtomData(i) ((void *)i)
00294 #define HashColorIndex(slot) ((unsigned int)((*slot)->data))
00295 #define USE_HASHTABLE (cpp > 2 && ncolors > 4)
00296 
00297 #ifdef NEED_STRDUP
00298 FUNC(strdup, char *, (char *s1));
00299 #endif
00300 
00301 #ifdef NEED_STRCASECMP                   
00302 FUNC(strcasecmp, int, (char *s1, char *s2));
00303 #endif
00304 
00305 FUNC(xpmatoui, unsigned int,
00306      (char *p, unsigned int l, unsigned int *ui_return));
00307 
00308 #endif