b6c6dfbdd9c355ceb2ad670504f77a91c280ebf0
[rocksndiamonds.git] / src / image.h
1
2 /* image.h */
3
4 #include "main.h"
5
6 typedef unsigned short Intensity; /* what X thinks an RGB intensity is */
7
8 /* This struct holds the X-client side bits for a rendered image. */
9 typedef struct
10 {
11   Display  *disp;       /* destination display */
12   int       scrn;       /* destination screen */
13   int       depth;      /* depth of drawable we want/have */
14   Drawable  drawable;   /* drawable to send image to */
15   Pixel    *index;      /* array of pixel values allocated */
16   int       no;         /* number of pixels in the array */
17   int       rootimage;  /* True if is a root image - eg, retain colors */
18   Pixel     foreground; /* foreground and background pixels for mono images */
19   Pixel     background;
20   Colormap  cmap;       /* colormap used for image */
21   GC        gc;         /* cached gc for sending image */
22   XImage   *ximage;     /* ximage structure */
23 } XImageInfo;
24
25 /* Function declarations */
26 void        sendXImage(); /* send.c */
27 XImageInfo *imageToXImage();
28 Pixmap      ximageToPixmap();
29 void        freeXImage();
30
31
32 typedef struct rgbmap
33 {
34   unsigned int  size;       /* size of RGB map */
35   unsigned int  used;       /* number of colors used in RGB map */
36   int           compressed; /* image uses colormap fully */
37   Intensity    *red;        /* color values in X style */
38   Intensity    *green;
39   Intensity    *blue;
40 } RGBMap;
41
42 /* image structure
43  */
44
45 typedef struct {
46   unsigned int  type;   /* type of image */
47   RGBMap        rgb;    /* RGB map of image if IRGB type */
48   unsigned int  width;  /* width of image in pixels */
49   unsigned int  height; /* height of image in pixels */
50   unsigned int  depth;  /* depth of image in bits if IRGB type */
51   unsigned int  pixlen; /* length of pixel if IRGB type */
52   byte         *data;   /* data rounded to full byte for each row */
53   float         gamma;  /* gamma of display the image is adjusted for */
54 } Image;
55
56 #define IBITMAP 0 /* image is a bitmap */
57 #define IRGB    1 /* image is RGB */
58
59 #define BITMAPP(IMAGE) ((IMAGE)->type == IBITMAP)
60 #define RGBP(IMAGE)    ((IMAGE)->type == IRGB)
61
62 #define depthToColors(n) DepthToColorsTable[((n) < 24 ? (n) : 24)]
63
64 /*
65  * Architecture independent memory to value conversions.
66  * Note the "Normal" internal format is big endian.
67  */
68
69 #define memToVal(PTR,LEN) (                                   \
70 (LEN) == 1 ? (unsigned long)(                 *( (byte *)(PTR))         ) :    \
71 (LEN) == 2 ? (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<< 8)      \
72                           + (                 *(((byte *)(PTR))+1)      ) :    \
73 (LEN) == 3 ? (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<<16)      \
74                           + (((unsigned long)(*(((byte *)(PTR))+1)))<< 8)      \
75                                                   + (                 *(((byte *)(PTR))+2)      ) :    \
76              (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<<24)      \
77                                                   + (((unsigned long)(*(((byte *)(PTR))+1)))<<16)      \
78                                                   + (((unsigned long)(*(((byte *)(PTR))+2)))<< 8)      \
79                                                   + (                 *(((byte *)(PTR))+3)      ) )
80
81 #define valToMem(VAL,PTR,LEN)  (                                          \
82 (LEN) == 1 ? (*( (byte *)(PTR)   ) = ( VAL     ) ) : \
83 (LEN) == 2 ? (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>> 8),        \
84               *(((byte *)(PTR))+1) = ( VAL     ) ) : \
85 (LEN) == 3 ? (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>>16),        \
86               *(((byte *)(PTR))+1) = (((unsigned long)(VAL))>> 8),        \
87               *(((byte *)(PTR))+2) = ( VAL     ) ) : \
88              (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>>24),        \
89               *(((byte *)(PTR))+1) = (((unsigned long)(VAL))>>16),        \
90               *(((byte *)(PTR))+2) = (((unsigned long)(VAL))>> 8),        \
91               *(((byte *)(PTR))+3) = ( VAL     ) ))
92
93
94 /* functions */
95
96 extern unsigned long DepthToColorsTable[];
97 Image *newBitImage();
98 Image *newRGBImage();
99 void   freeImage();
100 void   freeImageData();
101 void   newRGBMapData();
102 void   freeRGBMapData();
103 byte  *lcalloc();
104 byte  *lmalloc();
105
106 Image *Read_GIF_to_Image();
107 Image *monochrome();
108 Image *zoom();
109
110 void compress();