home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / xpm / xpmP.h < prev    next >
C/C++ Source or Header  |  2000-07-29  |  8KB  |  280 lines

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