rnd-19981112-1
[rocksndiamonds.git] / src / image.h
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  (c) 1995-98 Artsoft Entertainment                       *
5 *              Holger Schemel                              *
6 *              Oststrasse 11a                              *
7 *              33604 Bielefeld                             *
8 *              phone: ++49 +521 290471                     *
9 *              email: aeglos@valinor.owl.de                *
10 *----------------------------------------------------------*
11 *  image.h                                                 *
12 ***********************************************************/
13
14 #ifndef IMAGE_H
15 #define IMAGE_H
16
17 #include "main.h"
18
19 #define MAX_COLORS      256     /* maximal number of colors for each image */
20
21 typedef unsigned short Intensity; /* what X thinks an RGB intensity is */
22
23 typedef struct
24 {
25   Display  *display;    /* destination display                              */
26   int       screen;     /* destination screen                               */
27   int       depth;      /* depth of drawable we want/have                   */
28   Drawable  drawable;   /* drawable to send image to                        */
29   Pixel    *index;      /* array of pixel values allocated                  */
30   int       no;         /* number of pixels in the array                    */
31   int       rootimage;  /* True if is a root image - eg, retain colors      */
32   Pixel     foreground; /* foreground and background pixels for mono images */
33   Pixel     background;
34   Colormap  cmap;       /* colormap used for image                          */
35   GC        gc;         /* cached gc for sending image                      */
36   GC        gc_mask;    /* cached gc for sending image mask                 */
37   XImage   *ximage;     /* ximage structure                                 */
38   XImage   *ximage_mask;/* ximage structure of mask                         */
39   Pixmap   pixmap;      /* final pixmap                                     */
40   Pixmap   pixmap_mask; /* final pixmap of mask                             */
41 } XImageInfo;
42
43 struct RGBMap
44 {
45   unsigned int used;                    /* number of colors used in RGB map */
46   Intensity    red[MAX_COLORS];         /* color values in X style          */
47   Intensity    green[MAX_COLORS];
48   Intensity    blue[MAX_COLORS];
49   boolean      color_used[MAX_COLORS];  /* flag if color cell is used       */
50 };
51
52 typedef struct
53 {
54   struct RGBMap rgb;            /* RGB map of image if IRGB type       */
55   unsigned int  width;          /* width of image in pixels            */
56   unsigned int  height;         /* height of image in pixels           */
57   unsigned int  depth;          /* depth of image in bits if IRGB type */
58   byte         *data;           /* image data                          */
59   byte         *data_mask;      /* clip mask data                      */
60 } Image;
61
62 /*
63  * architecture independent memory-to-value conversions
64  * note: the internal format is big endian
65  */
66
67 #define memToVal(PTR,LEN) (                                   \
68 (LEN) == 1 ? (unsigned long)(                 *( (byte *)(PTR))         ) :    \
69 (LEN) == 2 ? (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<< 8)      \
70                           + (                 *(((byte *)(PTR))+1)      ) :    \
71 (LEN) == 3 ? (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<<16)      \
72                           + (((unsigned long)(*(((byte *)(PTR))+1)))<< 8)      \
73                                                   + (                 *(((byte *)(PTR))+2)      ) :    \
74              (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<<24)      \
75                                                   + (((unsigned long)(*(((byte *)(PTR))+1)))<<16)      \
76                                                   + (((unsigned long)(*(((byte *)(PTR))+2)))<< 8)      \
77                                                   + (                 *(((byte *)(PTR))+3)      ) )
78
79 #define valToMem(VAL,PTR,LEN)  (                                          \
80 (LEN) == 1 ? (*( (byte *)(PTR)   ) = ( VAL     ) ) : \
81 (LEN) == 2 ? (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>> 8),        \
82               *(((byte *)(PTR))+1) = ( VAL     ) ) : \
83 (LEN) == 3 ? (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>>16),        \
84               *(((byte *)(PTR))+1) = (((unsigned long)(VAL))>> 8),        \
85               *(((byte *)(PTR))+2) = ( VAL     ) ) : \
86              (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>>24),        \
87               *(((byte *)(PTR))+1) = (((unsigned long)(VAL))>>16),        \
88               *(((byte *)(PTR))+2) = (((unsigned long)(VAL))>> 8),        \
89               *(((byte *)(PTR))+3) = ( VAL     ) ))
90
91 #define PCX_Success              0
92 #define PCX_OpenFailed          -1
93 #define PCX_ReadFailed          -2
94 #define PCX_FileInvalid         -3
95 #define PCX_NoMemory            -4
96 #define PCX_ColorFailed         -5
97
98 int Read_PCX_to_Pixmaps(Display *, Window, char *, Pixmap *, Pixmap *);
99
100 Image *Read_PCX_to_Image();
101 Image *newImage();
102 void freeImage();
103 void freeXImage();
104
105 #endif  /* IMAGE_H */