rnd-19981111-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 typedef unsigned short Intensity; /* what X thinks an RGB intensity is */
20
21 /* This struct holds the X-client side bits for a rendered image. */
22 typedef struct
23 {
24   Display  *display;    /* destination display */
25   int       screen;     /* destination screen */
26   int       depth;      /* depth of drawable we want/have */
27   Drawable  drawable;   /* drawable to send image to */
28   Pixel    *index;      /* array of pixel values allocated */
29   int       no;         /* number of pixels in the array */
30   int       rootimage;  /* True if is a root image - eg, retain colors */
31   Pixel     foreground; /* foreground and background pixels for mono images */
32   Pixel     background;
33   Colormap  cmap;       /* colormap used for image */
34   GC        gc;         /* cached gc for sending image */
35   XImage   *ximage;     /* ximage structure */
36 } XImageInfo;
37
38 /* Function declarations */
39 void        sendXImage(); /* send.c */
40 XImageInfo *imageToXImage();
41 Pixmap      ximageToPixmap();
42 void        freeXImage();
43
44
45 typedef struct rgbmap
46 {
47   unsigned int  size;       /* size of RGB map */
48   unsigned int  used;       /* number of colors used in RGB map */
49   int           compressed; /* image uses colormap fully */
50   Intensity    *red;        /* color values in X style */
51   Intensity    *green;
52   Intensity    *blue;
53 } RGBMap;
54
55 /* image structure
56  */
57
58 typedef struct {
59   unsigned int  type;   /* type of image */
60   RGBMap        rgb;    /* RGB map of image if IRGB type */
61   unsigned int  width;  /* width of image in pixels */
62   unsigned int  height; /* height of image in pixels */
63   unsigned int  depth;  /* depth of image in bits if IRGB type */
64   unsigned int  pixlen; /* length of pixel if IRGB type */
65   byte         *data;   /* data rounded to full byte for each row */
66   float         gamma;  /* gamma of display the image is adjusted for */
67 } Image;
68
69 #define IBITMAP 0 /* image is a bitmap */
70 #define IRGB    1 /* image is RGB */
71
72 #define BITMAPP(IMAGE) ((IMAGE)->type == IBITMAP)
73 #define RGBP(IMAGE)    ((IMAGE)->type == IRGB)
74
75 #define depthToColors(n) DepthToColorsTable[((n) < 24 ? (n) : 24)]
76
77 /*
78  * Architecture independent memory to value conversions.
79  * Note the "Normal" internal format is big endian.
80  */
81
82 #define memToVal(PTR,LEN) (                                   \
83 (LEN) == 1 ? (unsigned long)(                 *( (byte *)(PTR))         ) :    \
84 (LEN) == 2 ? (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<< 8)      \
85                           + (                 *(((byte *)(PTR))+1)      ) :    \
86 (LEN) == 3 ? (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<<16)      \
87                           + (((unsigned long)(*(((byte *)(PTR))+1)))<< 8)      \
88                                                   + (                 *(((byte *)(PTR))+2)      ) :    \
89              (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<<24)      \
90                                                   + (((unsigned long)(*(((byte *)(PTR))+1)))<<16)      \
91                                                   + (((unsigned long)(*(((byte *)(PTR))+2)))<< 8)      \
92                                                   + (                 *(((byte *)(PTR))+3)      ) )
93
94 #define valToMem(VAL,PTR,LEN)  (                                          \
95 (LEN) == 1 ? (*( (byte *)(PTR)   ) = ( VAL     ) ) : \
96 (LEN) == 2 ? (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>> 8),        \
97               *(((byte *)(PTR))+1) = ( VAL     ) ) : \
98 (LEN) == 3 ? (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>>16),        \
99               *(((byte *)(PTR))+1) = (((unsigned long)(VAL))>> 8),        \
100               *(((byte *)(PTR))+2) = ( VAL     ) ) : \
101              (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>>24),        \
102               *(((byte *)(PTR))+1) = (((unsigned long)(VAL))>>16),        \
103               *(((byte *)(PTR))+2) = (((unsigned long)(VAL))>> 8),        \
104               *(((byte *)(PTR))+3) = ( VAL     ) ))
105
106
107 /* return values */
108
109 #define GIF_Success              0
110 #define GIF_OpenFailed          -1
111 #define GIF_ReadFailed          -2
112 #define GIF_FileInvalid         -3
113 #define GIF_NoMemory            -4
114 #define GIF_ColorFailed         -5
115
116 #define PCX_Success              0
117 #define PCX_OpenFailed          -1
118 #define PCX_ReadFailed          -2
119 #define PCX_FileInvalid         -3
120 #define PCX_NoMemory            -4
121 #define PCX_ColorFailed         -5
122
123 /* functions */
124
125 extern unsigned long DepthToColorsTable[];
126 Image *newBitImage();
127 Image *newRGBImage();
128 void   freeImage();
129 void   freeImageData();
130 void   newRGBMapData();
131 void   freeRGBMapData();
132 byte  *lcalloc();
133 byte  *lmalloc();
134
135 Image *Read_GIF_to_Image();
136 Image *Read_PCX_to_Image();
137
138 int Read_GIF_to_Pixmaps(Display *, Window, char *, Pixmap *, Pixmap *);
139 int Read_PCX_to_Pixmaps(Display *, Window, char *, Pixmap *, Pixmap *);
140
141 Image *monochrome();
142 Image *zoom();
143
144 void compress();
145
146 Pixmap XImage_to_Pixmap(Display *, Window, XImageInfo *);
147 XImageInfo *Image_to_XImage(Display *, int, Visual *, unsigned int, Image *);
148 void XImage_to_Drawable(XImageInfo *, int, int, int, int,
149                         unsigned int, unsigned int);
150
151 #endif  /* IMAGE_H */