]> Dogcows Code - chaz/openbox/blob - src/Image.h
took bsetroot from Blackbox moving_target.. "bsetroot now sets xrootpmap_id, pseudo...
[chaz/openbox] / src / Image.h
1 // Image.h for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 #ifndef __Image_hh
24 #define __Image_hh
25
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28
29 #include "LinkedList.h"
30 #include "Timer.h"
31
32 class ScreenInfo;
33 class BImage;
34 class BImageControl;
35
36
37 // bevel options
38 #define BImage_Flat (1l<<1)
39 #define BImage_Sunken (1l<<2)
40 #define BImage_Raised (1l<<3)
41
42 // textures
43 #define BImage_Solid (1l<<4)
44 #define BImage_Gradient (1l<<5)
45
46 // gradients
47 #define BImage_Horizontal (1l<<6)
48 #define BImage_Vertical (1l<<7)
49 #define BImage_Diagonal (1l<<8)
50 #define BImage_CrossDiagonal (1l<<9)
51 #define BImage_Rectangle (1l<<10)
52 #define BImage_Pyramid (1l<<11)
53 #define BImage_PipeCross (1l<<12)
54 #define BImage_Elliptic (1l<<13)
55
56 // bevel types
57 #define BImage_Bevel1 (1l<<14)
58 #define BImage_Bevel2 (1l<<15)
59
60 // inverted image
61 #define BImage_Invert (1l<<16)
62
63 // parent relative image
64 #define BImage_ParentRelative (1l<<17)
65
66 #ifdef INTERLACE
67 // fake interlaced image
68 # define BImage_Interlaced (1l<<18)
69 #endif // INTERLACE
70
71 class BColor {
72 private:
73 int allocated;
74 unsigned char red, green, blue;
75 unsigned long pixel;
76
77 public:
78 BColor(char r = 0, char g = 0, char b = 0)
79 { red = r; green = g; blue = b; pixel = 0; allocated = 0; }
80
81 inline const int &isAllocated(void) const { return allocated; }
82
83 inline const unsigned char &getRed(void) const { return red; }
84 inline const unsigned char &getGreen(void) const { return green; }
85 inline const unsigned char &getBlue(void) const { return blue; }
86
87 inline const unsigned long &getPixel(void) const { return pixel; }
88
89 inline void setAllocated(int a) { allocated = a; }
90 inline void setRGB(char r, char g, char b) { red = r; green = g; blue = b; }
91 inline void setPixel(unsigned long p) { pixel = p; }
92 };
93
94
95 class BTexture {
96 private:
97 BColor color, colorTo, hiColor, loColor;
98 unsigned long texture;
99
100 public:
101 BTexture(void) { texture = 0; }
102
103 inline BColor *getColor(void) { return &color; }
104 inline BColor *getColorTo(void) { return &colorTo; }
105 inline BColor *getHiColor(void) { return &hiColor; }
106 inline BColor *getLoColor(void) { return &loColor; }
107
108 inline const unsigned long &getTexture(void) const { return texture; }
109
110 inline void setTexture(unsigned long t) { texture = t; }
111 inline void addTexture(unsigned long t) { texture |= t; }
112 };
113
114
115 class BImage {
116 private:
117 BImageControl &control;
118
119 #ifdef INTERLACE
120 Bool interlaced;
121 #endif // INTERLACE
122
123 XColor *colors;
124
125 BColor *from, *to;
126 int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits,
127 ncolors, cpc, cpccpc;
128 unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table;
129 unsigned int width, height, *xtable, *ytable;
130
131
132 protected:
133 Pixmap renderPixmap(void);
134
135 XImage *renderXImage(void);
136
137 void invert(void);
138 void bevel1(void);
139 void bevel2(void);
140 void dgradient(void);
141 void egradient(void);
142 void hgradient(void);
143 void pgradient(void);
144 void rgradient(void);
145 void vgradient(void);
146 void cdgradient(void);
147 void pcgradient(void);
148
149
150 public:
151 BImage(BImageControl &, unsigned int, unsigned int);
152 ~BImage(void);
153
154 Pixmap render(BTexture *);
155 Pixmap render_solid(BTexture *);
156 Pixmap render_gradient(BTexture *);
157 };
158
159
160 class BImageControl : public TimeoutHandler {
161 private:
162 Bool dither;
163 BaseDisplay &basedisplay;
164 ScreenInfo &screeninfo;
165 #ifdef TIMEDCACHE
166 BTimer *timer;
167 #endif // TIMEDCACHE
168
169 Colormap colormap;
170
171 Window window;
172 XColor *colors;
173 int colors_per_channel, ncolors, screen_number, screen_depth,
174 bits_per_pixel, red_offset, green_offset, blue_offset,
175 red_bits, green_bits, blue_bits;
176 unsigned char red_color_table[256], green_color_table[256],
177 blue_color_table[256];
178 unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width,
179 grad_buffer_height;
180 unsigned long *sqrt_table, cache_max;
181
182 typedef struct Cache {
183 Pixmap pixmap;
184
185 unsigned int count, width, height;
186 unsigned long pixel1, pixel2, texture;
187 } Cache;
188
189 LinkedList<Cache> *cache;
190
191
192 protected:
193 Pixmap searchCache(unsigned int, unsigned int, unsigned long, BColor *,
194 BColor *);
195
196
197 public:
198 BImageControl(BaseDisplay &, ScreenInfo &, Bool = False, int = 4,
199 unsigned long = 300000l, unsigned long = 200l);
200 virtual ~BImageControl(void);
201
202 inline BaseDisplay &getBaseDisplay(void) { return basedisplay; }
203
204 inline const Bool &doDither(void) { return dither; }
205
206 inline ScreenInfo &getScreenInfo(void) { return screeninfo; }
207
208 inline const Window &getDrawable(void) const { return window; }
209
210 inline Visual *getVisual(void) { return screeninfo.getVisual(); }
211
212 inline const int &getBitsPerPixel(void) const { return bits_per_pixel; }
213 inline const int &getDepth(void) const { return screen_depth; }
214 inline const int &getColorsPerChannel(void) const
215 { return colors_per_channel; }
216
217 unsigned long getColor(const char *);
218 unsigned long getColor(const char *, unsigned char *, unsigned char *,
219 unsigned char *);
220 unsigned long getSqrt(unsigned int);
221
222 Pixmap renderImage(unsigned int, unsigned int, BTexture *);
223
224 void installRootColormap(void);
225 void removeImage(Pixmap);
226 void getColorTables(unsigned char **, unsigned char **, unsigned char **,
227 int *, int *, int *, int *, int *, int *);
228 void getXColorTable(XColor **, int *);
229 void getGradientBuffers(unsigned int, unsigned int,
230 unsigned int **, unsigned int **);
231 void setDither(Bool d) { dither = d; }
232 void setColorsPerChannel(int);
233 void parseTexture(BTexture *, const char *);
234 void parseColor(BColor *, const char * = 0);
235
236 virtual void timeout(void);
237 };
238
239
240 #endif // __Image_hh
241
This page took 0.044693 seconds and 4 git commands to generate.