rnd-19980906
[rocksndiamonds.git] / src / xli.h
1
2 /* xli.h:
3  *
4  * jim frost 06.21.89
5  *
6  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
7  * copyright information.
8  */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <math.h>
14 #include <malloc.h>
15
16 #include <X11/X.h>
17 #include <X11/Xlib.h>
18 #include <X11/Xutil.h>
19 #include <X11/Xatom.h>
20 #include <X11/cursorfont.h>
21
22 typedef unsigned long  Pixel;     /* what X thinks a pixel is */
23 typedef unsigned short Intensity; /* what X thinks an RGB intensity is */
24 typedef unsigned char  byte;      /* unsigned byte type */
25
26 #define FALSE 0
27 #define TRUE (!FALSE)
28
29 /* Display device dependent Information structure */
30 typedef struct
31 {
32   int  width;           /* Display width and height */
33   int  height;
34
35   Display      *disp;
36   int           scrn;
37   Colormap      colormap;
38 } DisplayInfo;
39
40 /* This struct holds the X-client side bits for a rendered image. */
41 typedef struct
42 {
43   Display  *disp;       /* destination display */
44   int       scrn;       /* destination screen */
45   int       depth;      /* depth of drawable we want/have */
46   Drawable  drawable;   /* drawable to send image to */
47   Pixel    *index;      /* array of pixel values allocated */
48   int       no;         /* number of pixels in the array */
49   int       rootimage;  /* True if is a root image - eg, retain colors */
50   Pixel     foreground; /* foreground and background pixels for mono images */
51   Pixel     background;
52   Colormap  cmap;       /* colormap used for image */
53   GC        gc;         /* cached gc for sending image */
54   XImage   *ximage;     /* ximage structure */
55 } XImageInfo;
56
57 /* Function declarations */
58 void        sendXImage(); /* send.c */
59 XImageInfo *imageToXImage();
60 Pixmap      ximageToPixmap();
61 void        freeXImage();
62
63
64 typedef struct rgbmap {
65   unsigned int  size;       /* size of RGB map */
66   unsigned int  used;       /* number of colors used in RGB map */
67   int           compressed; /* image uses colormap fully */
68   Intensity    *red;        /* color values in X style */
69   Intensity    *green;
70   Intensity    *blue;
71 } RGBMap;
72
73 /* image structure
74  */
75
76 typedef struct {
77   char         *title;  /* name of image */
78   unsigned int  type;   /* type of image */
79   RGBMap        rgb;    /* RGB map of image if IRGB type */
80   unsigned int  width;  /* width of image in pixels */
81   unsigned int  height; /* height of image in pixels */
82   unsigned int  depth;  /* depth of image in bits if IRGB type */
83   unsigned int  pixlen; /* length of pixel if IRGB type */
84   byte         *data;   /* data rounded to full byte for each row */
85   float         gamma;  /* gamma of display the image is adjusted for */
86 } Image;
87
88 #define IBITMAP 0 /* image is a bitmap */
89 #define IRGB    1 /* image is RGB */
90
91 #define BITMAPP(IMAGE) ((IMAGE)->type == IBITMAP)
92 #define RGBP(IMAGE)    ((IMAGE)->type == IRGB)
93
94 #define depthToColors(n) DepthToColorsTable[((n) < 24 ? (n) : 24)]
95
96 /*
97  * Architecture independent memory to value conversions.
98  * Note the "Normal" internal format is big endian.
99  */
100
101 #define memToVal(PTR,LEN) (                                   \
102 (LEN) == 1 ? (unsigned long)(                 *( (byte *)(PTR))         ) :    \
103 (LEN) == 2 ? (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<< 8)      \
104                           + (                 *(((byte *)(PTR))+1)      ) :    \
105 (LEN) == 3 ? (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<<16)      \
106                           + (((unsigned long)(*(((byte *)(PTR))+1)))<< 8)      \
107                                                   + (                 *(((byte *)(PTR))+2)      ) :    \
108              (unsigned long)(((unsigned long)(*( (byte *)(PTR))   ))<<24)      \
109                                                   + (((unsigned long)(*(((byte *)(PTR))+1)))<<16)      \
110                                                   + (((unsigned long)(*(((byte *)(PTR))+2)))<< 8)      \
111                                                   + (                 *(((byte *)(PTR))+3)      ) )
112
113 #define valToMem(VAL,PTR,LEN)  (                                          \
114 (LEN) == 1 ? (*( (byte *)(PTR)   ) = ( VAL     ) ) : \
115 (LEN) == 2 ? (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>> 8),        \
116               *(((byte *)(PTR))+1) = ( VAL     ) ) : \
117 (LEN) == 3 ? (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>>16),        \
118               *(((byte *)(PTR))+1) = (((unsigned long)(VAL))>> 8),        \
119               *(((byte *)(PTR))+2) = ( VAL     ) ) : \
120              (*( (byte *)(PTR)   ) = (((unsigned long)(VAL))>>24),        \
121               *(((byte *)(PTR))+1) = (((unsigned long)(VAL))>>16),        \
122               *(((byte *)(PTR))+2) = (((unsigned long)(VAL))>> 8),        \
123               *(((byte *)(PTR))+3) = ( VAL     ) ))
124
125
126 /* functions */
127
128 void cleanUpWindow();   /* window.c */
129 char imageInWindow();
130
131 int   visualClassFromName();
132 char *nameOfVisualClass();
133
134 extern unsigned long DepthToColorsTable[]; /* new.c */
135 char  *dupString();
136 Image *newBitImage();
137 Image *newRGBImage();
138 void   freeImage();
139 void   freeImageData();
140 void   newRGBMapData();
141 void   freeRGBMapData();
142 byte  *lcalloc();
143 byte  *lmalloc();
144 void   lfree();
145
146 Image *gifLoad();
147 Image *monochrome();
148 Image *zoom();
149
150 void compress(); /* compress.c */
151
152 int xliOpenDisplay();
153 void tellAboutDisplay(DisplayInfo *);
154 void xliCloseDisplay(DisplayInfo *);