home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / xpaint-247 / xpm.h < prev   
C/C++ Source or Header  |  1995-03-01  |  16KB  |  445 lines

  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. * xpm.h:                                                                      *
  28. *                                                                             *
  29. *  XPM library                                                                *
  30. *  Include file                                                               *
  31. *                                                                             *
  32. *  Developed by Arnaud Le Hors                                                *
  33. \*****************************************************************************/
  34.  
  35. /*
  36.  * The code related to FOR_MSW has been added by
  37.  * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
  38.  */
  39.  
  40. #ifndef XPM_h
  41. #define XPM_h
  42.  
  43. /*
  44.  * first some identification numbers:
  45.  * the version and revision numbers are determined with the following rule:
  46.  * SO Major number = LIB minor version number.
  47.  * SO Minor number = LIB sub-minor version number.
  48.  * e.g: Xpm version 3.2f
  49.  *      we forget the 3 which is the format number, 2 gives 2, and f gives 6.
  50.  *      thus we have XpmVersion = 2 and XpmRevision = 6
  51.  *      which gives  SOXPMLIBREV = 2.6
  52.  *
  53.  * Then the XpmIncludeVersion number is built from these numbers.
  54.  */
  55. #define XpmFormat 3
  56. #define XpmVersion 4
  57. #define XpmRevision 5
  58. #define XpmIncludeVersion ((XpmFormat * 100 + XpmVersion) * 100 + XpmRevision)
  59.  
  60. #ifndef XPM_NUMBERS
  61.  
  62. #ifdef VMS
  63. #include "decw$include:Xlib.h"
  64. #include "decw$include:Xutil.h"
  65. #else /* VMS */
  66. #ifdef FOR_MSW
  67. #define SYSV            /* uses memcpy string.h etc. */
  68. #include <malloc.h>
  69. #include "simx.h"        /* defines some X stuff using MSW types */
  70. #define NEED_STRCASECMP        /* at least for MSVC++ */
  71. #else /* FOR_MSW */
  72. #include <X11/Xlib.h>
  73. #include <X11/Xutil.h>
  74. #endif /* FOR_MSW */
  75. #endif /* VMS */
  76.  
  77. /* let's define Pixel if it is not done yet */
  78. #if ! defined(_XtIntrinsic_h) && ! defined(PIXEL_ALREADY_TYPEDEFED)
  79. typedef unsigned long Pixel;    /* Index into colormap */
  80. #define PIXEL_ALREADY_TYPEDEFED
  81. #endif
  82.  
  83. /* Return ErrorStatus codes:
  84.  * null     if full success
  85.  * positive if partial success
  86.  * negative if failure
  87.  */
  88.  
  89. #define XpmColorError    1
  90. #define XpmSuccess       0
  91. #define XpmOpenFailed   -1
  92. #define XpmFileInvalid  -2
  93. #define XpmNoMemory     -3
  94. #define XpmColorFailed  -4
  95.  
  96. /* the following should help people wanting to use their own functions */
  97. #define XpmFree(ptr) free(ptr)
  98.  
  99. typedef struct {
  100.     char *name;            /* Symbolic color name */
  101.     char *value;        /* Color value */
  102.     Pixel pixel;        /* Color pixel */
  103. }      XpmColorSymbol;
  104.  
  105. typedef struct {
  106.     char *name;            /* name of the extension */
  107.     unsigned int nlines;    /* number of lines in this extension */
  108.     char **lines;        /* pointer to the extension array of strings */
  109. }      XpmExtension;
  110.  
  111. typedef struct {
  112.     char *string;        /* characters string */
  113.     char *symbolic;        /* symbolic name */
  114.     char *m_color;        /* monochrom default */
  115.     char *g4_color;        /* 4 level grayscale default */
  116.     char *g_color;        /* other level grayscale default */
  117.     char *c_color;        /* color default */
  118. }      XpmColor;
  119.  
  120. typedef struct {
  121.     unsigned int width;        /* image width */
  122.     unsigned int height;    /* image height */
  123.     unsigned int cpp;        /* number of characters per pixel */
  124.     unsigned int ncolors;    /* number of colors */
  125.     XpmColor *colorTable;    /* list of related colors */
  126.     unsigned int *data;        /* image data */
  127. }      XpmImage;
  128.  
  129. typedef struct {
  130.     unsigned long valuemask;    /* Specifies which attributes are defined */
  131.     char *hints_cmt;        /* Comment of the hints section */
  132.     char *colors_cmt;        /* Comment of the colors section */
  133.     char *pixels_cmt;        /* Comment of the pixels section */
  134.     unsigned int x_hotspot;    /* Returns the x hotspot's coordinate */
  135.     unsigned int y_hotspot;    /* Returns the y hotspot's coordinate */
  136.     unsigned int nextensions;    /* number of extensions */
  137.     XpmExtension *extensions;    /* pointer to array of extensions */
  138. }      XpmInfo;
  139.  
  140. typedef struct {
  141.     unsigned long valuemask;        /* Specifies which attributes are
  142.                      * defined */
  143.  
  144.     Visual *visual;            /* Specifies the visual to use */
  145.     Colormap colormap;            /* Specifies the colormap to use */
  146.     unsigned int depth;            /* Specifies the depth */
  147.     unsigned int width;            /* Returns the width of the created
  148.                      * pixmap */
  149.     unsigned int height;        /* Returns the height of the created
  150.                      * pixmap */
  151.     unsigned int x_hotspot;        /* Returns the x hotspot's
  152.                      * coordinate */
  153.     unsigned int y_hotspot;        /* Returns the y hotspot's
  154.                      * coordinate */
  155.     unsigned int cpp;            /* Specifies the number of char per
  156.                      * pixel */
  157.     Pixel *pixels;            /* List of used color pixels */
  158.     unsigned int npixels;        /* Number of pixels */
  159.     XpmColorSymbol *colorsymbols;    /* Array of color symbols to
  160.                      * override */
  161.     unsigned int numsymbols;        /* Number of symbols */
  162.     char *rgb_fname;            /* RGB text file name */
  163.     unsigned int nextensions;        /* number of extensions */
  164.     XpmExtension *extensions;        /* pointer to array of extensions */
  165.  
  166.     unsigned int ncolors;               /* Number of colors */
  167.     XpmColor *colorTable;               /* Color table pointer */
  168. /* 3.2 backward compatibility code */
  169.     char *hints_cmt;                    /* Comment of the hints section */
  170.     char *colors_cmt;                   /* Comment of the colors section */
  171.     char *pixels_cmt;                   /* Comment of the pixels section */
  172. /* end 3.2 bc */
  173.     unsigned int mask_pixel;            /* Transparent pixel's color table
  174.                                          * index */
  175.  
  176.     /* Color Allocation Directives */
  177.     unsigned int exactColors;        /* Only use exact colors for visual */
  178.     unsigned int closeness;        /* Allowable RGB deviation */
  179.     unsigned int red_closeness;        /* Allowable red deviation */
  180.     unsigned int green_closeness;    /* Allowable green deviation */
  181.     unsigned int blue_closeness;    /* Allowable blue deviation */
  182.     int color_key;            /* Use colors from this color set */
  183.  
  184. }      XpmAttributes;
  185.  
  186. /* XpmAttributes value masks bits */
  187. #define XpmVisual       (1L<<0)
  188. #define XpmColormap       (1L<<1)
  189. #define XpmDepth       (1L<<2)
  190. #define XpmSize           (1L<<3)    /* width & height */
  191. #define XpmHotspot       (1L<<4)    /* x_hotspot & y_hotspot */
  192. #define XpmCharsPerPixel   (1L<<5)
  193. #define XpmColorSymbols       (1L<<6)
  194. #define XpmRgbFilename       (1L<<7)
  195. /* 3.2 backward compatibility code */
  196. #define XpmInfos       (1L<<8)
  197. #define XpmReturnInfos       XpmInfos
  198. /* end 3.2 bc */
  199. #define XpmReturnPixels       (1L<<9)
  200. #define XpmExtensions      (1L<<10)
  201. #define XpmReturnExtensions XpmExtensions
  202.  
  203. #define XpmExactColors     (1L<<11)
  204. #define XpmCloseness       (1L<<12)
  205. #define XpmRGBCloseness       (1L<<13)
  206. #define XpmColorKey       (1L<<14)
  207.  
  208. #define XpmColorTable      (1L<<15)
  209. #define XpmReturnColorTable XpmColorTable
  210.  
  211. /* XpmInfo value masks bits */
  212. #define XpmComments        XpmInfos
  213. #define XpmReturnComments  XpmComments
  214.  
  215. /* XpmAttributes mask_pixel value when there is no mask */
  216. #ifndef FOR_MSW
  217. #define XpmUndefPixel 0x80000000
  218. #else
  219. /* int is only 16 bit for MSW */
  220. #define XpmUndefPixel 0x8000
  221. #endif
  222.  
  223. /*
  224.  * color keys for visual type, they must fit along with the number key of
  225.  * each related element in xpmColorKeys[] defined in xpmP.h
  226.  */
  227. #define XPM_MONO    2
  228. #define XPM_GREY4    3
  229. #define XPM_GRAY4    3
  230. #define XPM_GREY     4
  231. #define XPM_GRAY     4
  232. #define XPM_COLOR    5
  233.  
  234.  
  235. /*
  236.  * minimal portability layer between ansi and KR C
  237.  */
  238.  
  239. /* forward declaration of functions with prototypes */
  240.  
  241. #if __STDC__ || defined(__cplusplus) || defined(c_plusplus)
  242.  /* ANSI || C++ */
  243. #define FUNC(f, t, p) extern t f p
  244. #define LFUNC(f, t, p) static t f p
  245. #else  /* K&R */
  246. #define FUNC(f, t, p) extern t f()
  247. #define LFUNC(f, t, p) static t f()
  248. #endif /* end of K&R */
  249.  
  250.  
  251. /*
  252.  * functions declarations
  253.  */
  254.  
  255. #ifdef __cplusplus
  256. extern "C" {
  257. #endif
  258.  
  259. /* FOR_MSW, all ..Pixmap.. are excluded, only the ..XImage.. are used */
  260.  
  261. #ifndef FOR_MSW
  262.     FUNC(XpmCreatePixmapFromData, int, (Display *display,
  263.                     Drawable d,
  264.                     char **data,
  265.                     Pixmap *pixmap_return,
  266.                     Pixmap *shapemask_return,
  267.                     XpmAttributes *attributes));
  268.  
  269.     FUNC(XpmCreateDataFromPixmap, int, (Display *display,
  270.                     char ***data_return,
  271.                     Pixmap pixmap,
  272.                     Pixmap shapemask,
  273.                     XpmAttributes *attributes));
  274.  
  275.     FUNC(XpmReadFileToPixmap, int, (Display *display,
  276.                     Drawable d,
  277.                     char *filename,
  278.                     Pixmap *pixmap_return,
  279.                     Pixmap *shapemask_return,
  280.                     XpmAttributes *attributes));
  281.  
  282.     FUNC(XpmWriteFileFromPixmap, int, (Display *display,
  283.                        char *filename,
  284.                        Pixmap pixmap,
  285.                        Pixmap shapemask,
  286.                        XpmAttributes *attributes));
  287. #endif  /* ndef FOR_MSW */
  288.  
  289.     FUNC(XpmCreateImageFromData, int, (Display *display,
  290.                        char **data,
  291.                        XImage **image_return,
  292.                        XImage **shapemask_return,
  293.                        XpmAttributes *attributes));
  294.  
  295.     FUNC(XpmCreateDataFromImage, int, (Display *display,
  296.                        char ***data_return,
  297.                        XImage *image,
  298.                        XImage *shapeimage,
  299.                        XpmAttributes *attributes));
  300.  
  301.     FUNC(XpmReadFileToImage, int, (Display *display,
  302.                    char *filename,
  303.                    XImage **image_return,
  304.                    XImage **shapeimage_return,
  305.                    XpmAttributes *attributes));
  306.  
  307.     FUNC(XpmWriteFileFromImage, int, (Display *display,
  308.                       char *filename,
  309.                       XImage *image,
  310.                       XImage *shapeimage,
  311.                       XpmAttributes *attributes));
  312.  
  313.     FUNC(XpmCreateImageFromBuffer, int, (Display *display,
  314.                      char *buffer,
  315.                      XImage **image_return,
  316.                      XImage **shapemask_return,
  317.                      XpmAttributes *attributes));
  318. #ifndef FOR_MSW
  319.     FUNC(XpmCreatePixmapFromBuffer, int, (Display *display,
  320.                       Drawable d,
  321.                       char *buffer,
  322.                       Pixmap *pixmap_return,
  323.                       Pixmap *shapemask_return,
  324.                       XpmAttributes *attributes));
  325.  
  326.     FUNC(XpmCreateBufferFromImage, int, (Display *display,
  327.                      char **buffer_return,
  328.                      XImage *image,
  329.                      XImage *shapeimage,
  330.                      XpmAttributes *attributes));
  331.  
  332.     FUNC(XpmCreateBufferFromPixmap, int, (Display *display,
  333.                       char **buffer_return,
  334.                       Pixmap pixmap,
  335.                       Pixmap shapemask,
  336.                       XpmAttributes *attributes));
  337. #endif  /* ndef FOR_MSW */
  338.     FUNC(XpmReadFileToBuffer, int, (char *filename, char **buffer_return));
  339.     FUNC(XpmWriteFileFromBuffer, int, (char *filename, char *buffer));
  340.  
  341.     FUNC(XpmReadFileToData, int, (char *filename, char ***data_return));
  342.     FUNC(XpmWriteFileFromData, int, (char *filename, char **data));
  343.  
  344.     FUNC(XpmAttributesSize, int, ());
  345.     FUNC(XpmFreeAttributes, void, (XpmAttributes *attributes));
  346.     FUNC(XpmFreeExtensions, void, (XpmExtension *extensions,
  347.                    int nextensions));
  348.  
  349.     FUNC(XpmFreeXpmImage, void, (XpmImage *image));
  350.     FUNC(XpmFreeXpmInfo, void, (XpmInfo *info));
  351.     FUNC(XpmGetErrorString, char *, (int errcode));
  352.     FUNC(XpmLibraryVersion, int, ());
  353.  
  354.     /* XpmImage functions */
  355.     FUNC(XpmReadFileToXpmImage, int, (char *filename,
  356.                       XpmImage *image,
  357.                       XpmInfo *info));
  358.  
  359.     FUNC(XpmWriteFileFromXpmImage, int, (char *filename,
  360.                      XpmImage *image,
  361.                      XpmInfo *info));
  362. #ifndef FOR_MSW
  363.     FUNC(XpmCreatePixmapFromXpmImage, int, (Display *display,
  364.                         Drawable d,
  365.                         XpmImage *image,
  366.                         Pixmap *pixmap_return,
  367.                         Pixmap *shapemask_return,
  368.                         XpmAttributes *attributes));
  369. #endif
  370.     FUNC(XpmCreateImageFromXpmImage, int, (Display *display,
  371.                        XpmImage *image,
  372.                        XImage **image_return,
  373.                        XImage **shapeimage_return,
  374.                        XpmAttributes *attributes));
  375.  
  376.     FUNC(XpmCreateXpmImageFromImage, int, (Display *display,
  377.                        XImage *image,
  378.                        XImage *shapeimage,
  379.                        XpmImage *xpmimage,
  380.                        XpmAttributes *attributes));
  381. #ifndef FOR_MSW
  382.     FUNC(XpmCreateXpmImageFromPixmap, int, (Display *display,
  383.                         Pixmap pixmap,
  384.                         Pixmap shapemask,
  385.                         XpmImage *xpmimage,
  386.                         XpmAttributes *attributes));
  387. #endif
  388.     FUNC(XpmCreateDataFromXpmImage, int, (char ***data_return,
  389.                       XpmImage *image,
  390.                       XpmInfo *info));
  391.  
  392.     FUNC(XpmCreateXpmImageFromData, int, (char **data,
  393.                       XpmImage *image,
  394.                       XpmInfo *info));
  395.  
  396.     FUNC(XpmCreateXpmImageFromBuffer, int, (char *buffer,
  397.                         XpmImage *image,
  398.                         XpmInfo *info));
  399.  
  400.     FUNC(XpmCreateBufferFromXpmImage, int, (char **buffer_return,
  401.                         XpmImage *image,
  402.                         XpmInfo *info));
  403.  
  404. #ifdef __cplusplus
  405. } /* for C++ V2.0 */
  406. #endif
  407.  
  408.  
  409. /* backward compatibility */
  410.  
  411. /* for version 3.0c */
  412. #define XpmPixmapColorError  XpmColorError
  413. #define XpmPixmapSuccess     XpmSuccess
  414. #define XpmPixmapOpenFailed  XpmOpenFailed
  415. #define XpmPixmapFileInvalid XpmFileInvalid
  416. #define XpmPixmapNoMemory    XpmNoMemory
  417. #define XpmPixmapColorFailed XpmColorFailed
  418.  
  419. #define XpmReadPixmapFile(dpy, d, file, pix, mask, att) \
  420.     XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
  421. #define XpmWritePixmapFile(dpy, file, pix, mask, att) \
  422.     XpmWriteFileFromPixmap(dpy, file, pix, mask, att)
  423.  
  424. /* for version 3.0b */
  425. #define PixmapColorError  XpmColorError
  426. #define PixmapSuccess     XpmSuccess
  427. #define PixmapOpenFailed  XpmOpenFailed
  428. #define PixmapFileInvalid XpmFileInvalid
  429. #define PixmapNoMemory    XpmNoMemory
  430. #define PixmapColorFailed XpmColorFailed
  431.  
  432. #define ColorSymbol XpmColorSymbol
  433.  
  434. #define XReadPixmapFile(dpy, d, file, pix, mask, att) \
  435.     XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
  436. #define XWritePixmapFile(dpy, file, pix, mask, att) \
  437.     XpmWriteFileFromPixmap(dpy, file, pix, mask, att)
  438. #define XCreatePixmapFromData(dpy, d, data, pix, mask, att) \
  439.     XpmCreatePixmapFromData(dpy, d, data, pix, mask, att)
  440. #define XCreateDataFromPixmap(dpy, data, pix, mask, att) \
  441.     XpmCreateDataFromPixmap(dpy, data, pix, mask, att)
  442.  
  443. #endif /* XPM_NUMBERS */
  444. #endif
  445. e