diff options
Diffstat (limited to 'src/Image.hh')
-rw-r--r-- | src/Image.hh | 295 |
1 files changed, 145 insertions, 150 deletions
diff --git a/src/Image.hh b/src/Image.hh index 3811e69..677acbb 100644 --- a/src/Image.hh +++ b/src/Image.hh | |||
@@ -1,3 +1,6 @@ | |||
1 | // Image.hh for Fluxbox Window Manager | ||
2 | // Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxbox@linuxmail.org) | ||
3 | // | ||
1 | // Image.hh for Blackbox - an X11 Window manager | 4 | // Image.hh for Blackbox - an X11 Window manager |
2 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) | 5 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) |
3 | // | 6 | // |
@@ -13,19 +16,24 @@ | |||
13 | // | 16 | // |
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 20 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 23 | // DEALINGS IN THE SOFTWARE. |
21 | 24 | ||
22 | #ifndef _IMAGE_HH_ | 25 | // $Id: Image.hh,v 1.7 2002/05/17 10:59:30 fluxgen Exp $ |
23 | #define _IMAGE_HH_ | 26 | |
27 | #ifndef IMAGE_HH | ||
28 | #define IMAGE_HH | ||
24 | 29 | ||
25 | #include <X11/Xlib.h> | 30 | #include <X11/Xlib.h> |
26 | #include <X11/Xutil.h> | 31 | #include <X11/Xutil.h> |
27 | 32 | ||
28 | #include "Timer.hh" | 33 | #include "Timer.hh" |
34 | #include "BaseDisplay.hh" | ||
35 | |||
36 | #include <list> | ||
29 | 37 | ||
30 | class BImage; | 38 | class BImage; |
31 | class BImageControl; | 39 | class BImageControl; |
@@ -33,208 +41,195 @@ class BImageControl; | |||
33 | 41 | ||
34 | class BColor { | 42 | class BColor { |
35 | private: | 43 | private: |
36 | int allocated; | 44 | int allocated; |
37 | unsigned char red, green, blue; | 45 | unsigned char red, green, blue; |
38 | unsigned long pixel; | 46 | unsigned long pixel; |
39 | 47 | ||
40 | public: | 48 | public: |
41 | BColor(char r = 0, char g = 0, char b = 0) | 49 | BColor(char r = 0, char g = 0, char b = 0) |
42 | { red = r; green = g; blue = b; pixel = 0; allocated = 0; } | 50 | { red = r; green = g; blue = b; pixel = 0; allocated = 0; } |
43 | 51 | ||
44 | inline const int &isAllocated(void) const { return allocated; } | 52 | inline int isAllocated(void) const { return allocated; } |
45 | 53 | ||
46 | inline const unsigned char &getRed(void) const { return red; } | 54 | inline unsigned char getRed(void) const { return red; } |
47 | inline const unsigned char &getGreen(void) const { return green; } | 55 | inline unsigned char getGreen(void) const { return green; } |
48 | inline const unsigned char &getBlue(void) const { return blue; } | 56 | inline unsigned char getBlue(void) const { return blue; } |
49 | 57 | ||
50 | inline const unsigned long &getPixel(void) const { return pixel; } | 58 | inline unsigned long getPixel(void) const { return pixel; } |
51 | 59 | ||
52 | inline void setAllocated(int a) { allocated = a; } | 60 | inline void setAllocated(int a) { allocated = a; } |
53 | inline void setRGB(char r, char g, char b) { red = r; green = g; blue = b; } | 61 | inline void setRGB(char r, char g, char b) { red = r; green = g; blue = b; } |
54 | inline void setPixel(unsigned long p) { pixel = p; } | 62 | inline void setPixel(unsigned long p) { pixel = p; } |
55 | }; | 63 | }; |
56 | 64 | ||
57 | 65 | ||
58 | class BTexture { | 66 | class BTexture { |
59 | private: | 67 | private: |
60 | BColor color, colorTo, hiColor, loColor; | 68 | BColor color, colorTo, hiColor, loColor; |
61 | unsigned long texture; | 69 | unsigned long texture; |
62 | 70 | ||
63 | public: | 71 | public: |
64 | BTexture(void) { texture = 0; } | 72 | BTexture(void):texture(0) { } |
65 | 73 | ||
66 | inline BColor *getColor(void) { return &color; } | 74 | inline const BColor *getColor(void) const { return &color; } |
67 | inline BColor *getColorTo(void) { return &colorTo; } | 75 | inline const BColor *getColorTo(void) const { return &colorTo; } |
68 | inline BColor *getHiColor(void) { return &hiColor; } | 76 | inline const BColor *getHiColor(void) const { return &hiColor; } |
69 | inline BColor *getLoColor(void) { return &loColor; } | 77 | inline const BColor *getLoColor(void) const { return &loColor; } |
70 | |||
71 | inline const unsigned long &getTexture(void) const { return texture; } | ||
72 | |||
73 | inline void setTexture(unsigned long t) { texture = t; } | ||
74 | inline void addTexture(unsigned long t) { texture |= t; } | ||
75 | }; | ||
76 | 78 | ||
79 | inline BColor *getColor(void) { return &color; } | ||
80 | inline BColor *getColorTo(void) { return &colorTo; } | ||
81 | inline BColor *getHiColor(void) { return &hiColor; } | ||
82 | inline BColor *getLoColor(void) { return &loColor; } | ||
77 | 83 | ||
78 | // bevel options | 84 | inline unsigned long getTexture(void) const { return texture; } |
79 | #define BImage_Flat (1l<<1) | ||
80 | #define BImage_Sunken (1l<<2) | ||
81 | #define BImage_Raised (1l<<3) | ||
82 | 85 | ||
83 | // textures | 86 | inline void setTexture(unsigned long t) { texture = t; } |
84 | #define BImage_Solid (1l<<4) | 87 | inline void addTexture(unsigned long t) { texture |= t; } |
85 | #define BImage_Gradient (1l<<5) | 88 | }; |
86 | |||
87 | // gradients | ||
88 | #define BImage_Horizontal (1l<<6) | ||
89 | #define BImage_Vertical (1l<<7) | ||
90 | #define BImage_Diagonal (1l<<8) | ||
91 | #define BImage_CrossDiagonal (1l<<9) | ||
92 | #define BImage_Rectangle (1l<<10) | ||
93 | #define BImage_Pyramid (1l<<11) | ||
94 | #define BImage_PipeCross (1l<<12) | ||
95 | #define BImage_Elliptic (1l<<13) | ||
96 | |||
97 | // bevel types | ||
98 | #define BImage_Bevel1 (1l<<14) | ||
99 | #define BImage_Bevel2 (1l<<15) | ||
100 | |||
101 | // inverted image | ||
102 | #define BImage_Invert (1l<<16) | ||
103 | |||
104 | // parent relative image | ||
105 | #define BImage_ParentRelative (1l<<17) | ||
106 | |||
107 | #ifdef INTERLACE | ||
108 | // fake interlaced image | ||
109 | # define BImage_Interlaced (1l<<18) | ||
110 | #endif // INTERLACE | ||
111 | 89 | ||
112 | #include "BaseDisplay.hh" | ||
113 | #include "LinkedList.hh" | ||
114 | 90 | ||
115 | 91 | ||
116 | class BImage { | 92 | class BImage { |
117 | private: | 93 | private: |
118 | BImageControl *control; | 94 | BImageControl *control; |
119 | 95 | ||
120 | #ifdef INTERLACE | 96 | #ifdef INTERLACE |
121 | Bool interlaced; | 97 | Bool interlaced; |
122 | #endif // INTERLACE | 98 | #endif // INTERLACE |
123 | 99 | ||
124 | XColor *colors; | 100 | XColor *colors; |
125 | 101 | ||
126 | BColor *from, *to; | 102 | BColor *from, *to; |
127 | int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits, | 103 | int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits, |
128 | ncolors, cpc, cpccpc; | 104 | ncolors, cpc, cpccpc; |
129 | unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table; | 105 | unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table; |
130 | unsigned int width, height, *xtable, *ytable; | 106 | unsigned int width, height, *xtable, *ytable; |
131 | 107 | ||
132 | 108 | ||
133 | protected: | 109 | protected: |
134 | Pixmap renderPixmap(void); | 110 | Pixmap renderPixmap(void); |
135 | 111 | ||
136 | XImage *renderXImage(void); | 112 | XImage *renderXImage(void); |
137 | 113 | ||
138 | void invert(void); | 114 | void invert(void); |
139 | void bevel1(void); | 115 | void bevel1(void); |
140 | void bevel2(void); | 116 | void bevel2(void); |
141 | void dgradient(void); | 117 | void dgradient(void); |
142 | void egradient(void); | 118 | void egradient(void); |
143 | void hgradient(void); | 119 | void hgradient(void); |
144 | void pgradient(void); | 120 | void pgradient(void); |
145 | void rgradient(void); | 121 | void rgradient(void); |
146 | void vgradient(void); | 122 | void vgradient(void); |
147 | void cdgradient(void); | 123 | void cdgradient(void); |
148 | void pcgradient(void); | 124 | void pcgradient(void); |
149 | 125 | ||
150 | 126 | ||
151 | public: | 127 | public: |
152 | BImage(BImageControl *, unsigned int, unsigned int); | 128 | enum Bevel{FLAT=0x00002, SUNKEN=0x00004, RAISED=0x00008}; |
153 | ~BImage(void); | 129 | enum Textures{SOLID=0x00010, GRADIENT=0x00020}; |
154 | 130 | enum Gradients{ | |
155 | Pixmap render(BTexture *); | 131 | HORIZONTAL=0x00040, |
156 | Pixmap render_solid(BTexture *); | 132 | VERTICAL=0x00080, |
157 | Pixmap render_gradient(BTexture *); | 133 | DIAGONAL=0x00100, |
134 | CROSSDIAGONAL=0x00200, | ||
135 | RECTANGLE=0x00400, | ||
136 | PYRAMID=0x00800, | ||
137 | PIPECROSS=0x01000, | ||
138 | ELLIPTIC=0x02000 | ||
139 | }; | ||
140 | |||
141 | enum { | ||
142 | BEVEL1=0x04000, BEVEL2=0x08000, // bevel types | ||
143 | INVERT=0x010000, //inverted image | ||
144 | PARENTRELATIVE=0x20000, | ||
145 | INTERLACED=0x40000 | ||
146 | }; | ||
147 | |||
148 | BImage(BImageControl *, unsigned int, unsigned int); | ||
149 | ~BImage(void); | ||
150 | |||
151 | Pixmap render(BTexture *); | ||
152 | Pixmap render_solid(BTexture *); | ||
153 | Pixmap render_gradient(BTexture *); | ||
158 | }; | 154 | }; |
159 | 155 | ||
160 | 156 | ||
161 | class BImageControl : public TimeoutHandler { | 157 | class BImageControl : public TimeoutHandler { |
162 | private: | 158 | public: |
163 | Bool dither; | 159 | BImageControl(BaseDisplay *, ScreenInfo *, Bool = False, int = 4, |
164 | BaseDisplay *basedisplay; | 160 | unsigned long = 300000l, unsigned long = 200l); |
165 | ScreenInfo *screeninfo; | 161 | virtual ~BImageControl(); |
166 | #ifdef TIMEDCACHE | ||
167 | BTimer *timer; | ||
168 | #endif // TIMEDCACHE | ||
169 | |||
170 | Colormap colormap; | ||
171 | 162 | ||
172 | Window window; | 163 | inline BaseDisplay *getBaseDisplay(void) { return basedisplay; } |
173 | XColor *colors; | ||
174 | int colors_per_channel, ncolors, screen_number, screen_depth, | ||
175 | bits_per_pixel, red_offset, green_offset, blue_offset, | ||
176 | red_bits, green_bits, blue_bits; | ||
177 | unsigned char red_color_table[256], green_color_table[256], | ||
178 | blue_color_table[256]; | ||
179 | unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width, | ||
180 | grad_buffer_height; | ||
181 | unsigned long *sqrt_table, cache_max; | ||
182 | 164 | ||
183 | typedef struct Cache { | 165 | inline bool doDither(void) { return dither; } |
184 | Pixmap pixmap; | 166 | inline const Colormap &getColormap(void) const { return colormap; } |
167 | inline ScreenInfo *getScreenInfo(void) { return screeninfo; } | ||
185 | 168 | ||
186 | unsigned int count, width, height; | 169 | inline const Window &getDrawable(void) const { return window; } |
187 | unsigned long pixel1, pixel2, texture; | ||
188 | } Cache; | ||
189 | 170 | ||
190 | LinkedList<Cache> *cache; | 171 | inline Visual *getVisual(void) { return screeninfo->getVisual(); } |
191 | 172 | ||
173 | inline int getBitsPerPixel(void) const { return bits_per_pixel; } | ||
174 | inline int getDepth(void) const { return screen_depth; } | ||
175 | inline int getColorsPerChannel(void) const | ||
176 | { return colors_per_channel; } | ||
192 | 177 | ||
193 | protected: | 178 | unsigned long getColor(const char *); |
194 | Pixmap searchCache(unsigned int, unsigned int, unsigned long, BColor *, | 179 | unsigned long getColor(const char *, unsigned char *, unsigned char *, |
195 | BColor *); | 180 | unsigned char *); |
181 | unsigned long getSqrt(unsigned int); | ||
196 | 182 | ||
183 | Pixmap renderImage(unsigned int, unsigned int, BTexture *); | ||
197 | 184 | ||
198 | public: | 185 | void installRootColormap(void); |
199 | BImageControl(BaseDisplay *, ScreenInfo *, Bool = False, int = 4, | 186 | void removeImage(Pixmap); |
200 | unsigned long = 300000l, unsigned long = 200l); | 187 | void getColorTables(unsigned char **, unsigned char **, unsigned char **, |
201 | virtual ~BImageControl(void); | 188 | int *, int *, int *, int *, int *, int *); |
189 | void getXColorTable(XColor **, int *); | ||
190 | void getGradientBuffers(unsigned int, unsigned int, | ||
191 | unsigned int **, unsigned int **); | ||
192 | void setDither(Bool d) { dither = d; } | ||
193 | void setColorsPerChannel(int); | ||
194 | void parseTexture(BTexture *, char *); | ||
195 | void parseColor(BColor *, char * = 0); | ||
202 | 196 | ||
203 | inline BaseDisplay *getBaseDisplay(void) { return basedisplay; } | 197 | virtual void timeout(void); |
204 | 198 | ||
205 | inline const Bool &doDither(void) { return dither; } | 199 | private: |
206 | inline const Colormap &getColormap(void) const { return colormap; } | 200 | Bool dither; |
207 | inline ScreenInfo *getScreenInfo(void) { return screeninfo; } | 201 | BaseDisplay *basedisplay; |
202 | ScreenInfo *screeninfo; | ||
203 | #ifdef TIMEDCACHE | ||
204 | BTimer timer; | ||
205 | #endif // TIMEDCACHE | ||
208 | 206 | ||
209 | inline const Window &getDrawable(void) const { return window; } | 207 | Colormap colormap; |
210 | 208 | ||
211 | inline Visual *getVisual(void) { return screeninfo->getVisual(); } | 209 | Window window; |
210 | XColor *colors; | ||
211 | int colors_per_channel, ncolors, screen_number, screen_depth, | ||
212 | bits_per_pixel, red_offset, green_offset, blue_offset, | ||
213 | red_bits, green_bits, blue_bits; | ||
214 | unsigned char red_color_table[256], green_color_table[256], | ||
215 | blue_color_table[256]; | ||
216 | unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width, | ||
217 | grad_buffer_height; | ||
218 | unsigned long *sqrt_table, cache_max; | ||
212 | 219 | ||
213 | inline const int &getBitsPerPixel(void) const { return bits_per_pixel; } | 220 | typedef struct Cache { |
214 | inline const int &getDepth(void) const { return screen_depth; } | 221 | Pixmap pixmap; |
215 | inline const int &getColorsPerChannel(void) const | ||
216 | { return colors_per_channel; } | ||
217 | 222 | ||
218 | unsigned long getColor(const char *); | 223 | unsigned int count, width, height; |
219 | unsigned long getColor(const char *, unsigned char *, unsigned char *, | 224 | unsigned long pixel1, pixel2, texture; |
220 | unsigned char *); | 225 | } Cache; |
221 | unsigned long getSqrt(unsigned int); | ||
222 | 226 | ||
223 | Pixmap renderImage(unsigned int, unsigned int, BTexture *); | 227 | typedef std::list<Cache *> CacheList; |
224 | 228 | ||
225 | void installRootColormap(void); | 229 | CacheList cache; |
226 | void removeImage(Pixmap); | ||
227 | void getColorTables(unsigned char **, unsigned char **, unsigned char **, | ||
228 | int *, int *, int *, int *, int *, int *); | ||
229 | void getXColorTable(XColor **, int *); | ||
230 | void getGradientBuffers(unsigned int, unsigned int, | ||
231 | unsigned int **, unsigned int **); | ||
232 | void setDither(Bool d) { dither = d; } | ||
233 | void setColorsPerChannel(int); | ||
234 | void parseTexture(BTexture *, char *); | ||
235 | void parseColor(BColor *, char * = 0); | ||
236 | 230 | ||
237 | virtual void timeout(void); | 231 | protected: |
232 | Pixmap searchCache(unsigned int, unsigned int, unsigned long, BColor *, BColor *); | ||
238 | }; | 233 | }; |
239 | 234 | ||
240 | 235 | ||