1 #include <X11/Xlib.h>
2 #include <X11/Xutil.h>
3 #include <X11/Xatom.h>
4 #include <X11/Xos.h>
5 #ifdef HAVE_X11_EXTENSIONS_XSHM_H
6 #include <X11/extensions/XShm.h>
7 #endif
8 #include <X11/extensions/shape.h>
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <math.h>
13 #include <ctype.h>
14 #include <time.h>
15 #include <netinet/in.h>
16 #ifdef HAVE_SYS_IPC_H
17 #include <sys/ipc.h>
18 #endif
19 #ifdef HAVE_SYS_SHM_H
20 #include <sys/shm.h>
21 #endif
22 #include <sys/time.h>
23 #include <sys/types.h>
24 
25 #ifdef _HAVE_STRING_H
26 #include <string.h>
27 #elif _HAVE_STRINGS_H
28 #include <strings.h>
29 #endif
30 
31 #ifndef SYSTEM_IMRC
32 #define SYSTEM_IMRC "/etc/imrc"
33 #endif /* endef SYSTEM_IMRC */
34 
35 typedef struct _ImlibBorder ImlibBorder;
36 typedef struct _ImlibColor ImlibColor;
37 typedef struct _ImlibColorModifier ImlibColorModifier;
38 typedef struct _ImlibImage ImlibImage;
39 typedef struct _xdata Xdata;
40 typedef struct _ImlibData ImlibData;
41 typedef struct _ImlibSaveInfo ImlibSaveInfo;
42 typedef struct _ImlibInitParams ImlibInitParams;
43 
44 struct _ImlibBorder
45   {
46     int                 left, right;
47     int                 top, bottom;
48   };
49 
50 struct _ImlibColor
51   {
52     int                 r, g, b;
53     int                 pixel;
54   };
55 
56 struct _ImlibColorModifier
57   {
58     int                 gamma;
59     int                 brightness;
60     int                 contrast;
61   };
62 
63 struct _ImlibImage
64   {
65     int                 rgb_width, rgb_height;
66     unsigned char      *rgb_data;
67     unsigned char      *alpha_data;
68     char               *filename;
69 /* the below information is private */
70     int                 width, height;
71     ImlibColor          shape_color;
72     ImlibBorder         border;
73     Pixmap              pixmap;
74     Pixmap              shape_mask;
75     char                cache;
76     ImlibColorModifier  mod, rmod, gmod, bmod;
77     unsigned char       rmap[256], gmap[256], bmap[256];
78   };
79 
80 struct _xdata
81   {
82     Display            *disp;
83     void              (*x_lock_display) (Display *display);
84     void              (*x_unlock_display) (Display *display);
85     int                 screen;
86     Window              root;
87     Visual             *visual;
88     int                 depth;
89     int                 render_depth;
90     Colormap            root_cmap;
91     char                shm;
92     char                shmp;
93     int                 shm_event;
94     XImage             *last_xim;
95     XImage             *last_sxim;
96 #ifdef HAVE_X11_EXTENSIONS_XSHM_H
97     XShmSegmentInfo     last_shminfo;
98     XShmSegmentInfo     last_sshminfo;
99 #endif
100     Window              base_window;
101     int                 byte_order, bit_order;
102   };
103 
104 struct _ImlibData
105   {
106     int                 num_colors;
107     ImlibColor         *palette;
108     ImlibColor         *palette_orig;
109     unsigned char      *fast_rgb;
110     int                *fast_err;
111     int                *fast_erg;
112     int                *fast_erb;
113     int                 render_type;
114     int                 max_shm;
115     Xdata               x;
116     int                 byte_order;
117     struct _cache
118       {
119 	char                on_image;
120 	int                 size_image;
121 	int                 num_image;
122 	int                 used_image;
123 	struct image_cache *image;
124 	char                on_pixmap;
125 	int                 size_pixmap;
126 	int                 num_pixmap;
127 	int                 used_pixmap;
128 	struct pixmap_cache *pixmap;
129       }
130     cache;
131     char                fastrend;
132     char                hiq;
133     ImlibColorModifier  mod, rmod, gmod, bmod;
134     unsigned char       rmap[256], gmap[256], bmap[256];
135     char                fallback;
136     char                ordered_dither;
137   };
138 
139 struct _ImlibSaveInfo
140   {
141     int                 quality;
142     int                 scaling;
143     int                 xjustification;
144     int                 yjustification;
145     int                 page_size;
146     char                color;
147   };
148 
149 struct _ImlibInitParams
150   {
151     int                 flags;
152     int                 visualid;
153     char               *palettefile;
154     char                sharedmem;
155     char                sharedpixmaps;
156     char                paletteoverride;
157     char                remap;
158     char                fastrender;
159     char                hiquality;
160     char                dither;
161     int                 imagecachesize;
162     int                 pixmapcachesize;
163     Colormap            cmap;
164   };
165 
166 #define PARAMS_VISUALID        1<<0
167 #define PARAMS_PALETTEFILE     1<<1
168 #define PARAMS_SHAREDMEM       1<<2
169 #define PARAMS_SHAREDPIXMAPS   1<<3
170 #define PARAMS_PALETTEOVERRIDE 1<<4
171 #define PARAMS_REMAP           1<<5
172 #define PARAMS_FASTRENDER      1<<6
173 #define PARAMS_HIQUALITY       1<<7
174 #define PARAMS_DITHER          1<<8
175 #define PARAMS_IMAGECACHESIZE  1<<9
176 #define PARAMS_PIXMAPCACHESIZE 1<<10
177 #define PARAMS_COLORMAP        1<<11
178 
179 #define PAGE_SIZE_EXECUTIVE    0
180 #define PAGE_SIZE_LETTER       1
181 #define PAGE_SIZE_LEGAL        2
182 #define PAGE_SIZE_A4           3
183 #define PAGE_SIZE_A3           4
184 #define PAGE_SIZE_A5           5
185 #define PAGE_SIZE_FOLIO        6
186 
187 #define RT_PLAIN_PALETTE       0
188 #define RT_PLAIN_PALETTE_FAST  1
189 #define RT_DITHER_PALETTE      2
190 #define RT_DITHER_PALETTE_FAST 3
191 #define RT_PLAIN_TRUECOL       4
192 /* a special high-quality renderer for people with 15 and 16bpp that dithers */
193 #define RT_DITHER_TRUECOL      5
194