aboutsummaryrefslogtreecommitdiff
path: root/src/Image.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/Image.hh')
-rw-r--r--src/Image.hh336
1 files changed, 146 insertions, 190 deletions
diff --git a/src/Image.hh b/src/Image.hh
index 3811e69..7ae8b36 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,230 +16,183 @@
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.11 2002/08/04 15:55:13 fluxgen Exp $
23#define _IMAGE_HH_
24 26
25#include <X11/Xlib.h> 27#ifndef IMAGE_HH
26#include <X11/Xutil.h> 28#define IMAGE_HH
27 29
28#include "Timer.hh" 30#include "Timer.hh"
31#include "BaseDisplay.hh"
32#include "Color.hh"
33#include "Texture.hh"
29 34
30class BImage; 35#include <X11/Xlib.h>
31class BImageControl; 36#include <X11/Xutil.h>
32 37#include <list>
33
34class BColor {
35private:
36 int allocated;
37 unsigned char red, green, blue;
38 unsigned long pixel;
39
40public:
41 BColor(char r = 0, char g = 0, char b = 0)
42 { red = r; green = g; blue = b; pixel = 0; allocated = 0; }
43
44 inline const int &isAllocated(void) const { return allocated; }
45
46 inline const unsigned char &getRed(void) const { return red; }
47 inline const unsigned char &getGreen(void) const { return green; }
48 inline const unsigned char &getBlue(void) const { return blue; }
49
50 inline const unsigned long &getPixel(void) const { return pixel; }
51
52 inline void setAllocated(int a) { allocated = a; }
53 inline void setRGB(char r, char g, char b) { red = r; green = g; blue = b; }
54 inline void setPixel(unsigned long p) { pixel = p; }
55};
56
57 38
58class BTexture { 39class BImageControl;
59private:
60 BColor color, colorTo, hiColor, loColor;
61 unsigned long texture;
62 40
41/**
42 Renders to pixmap
43*/
44class BImage {
63public: 45public:
64 BTexture(void) { texture = 0; } 46 BImage(BImageControl *ic, unsigned int, unsigned int);
65 47 ~BImage();
66 inline BColor *getColor(void) { return &color; } 48 /// render to pixmap
67 inline BColor *getColorTo(void) { return &colorTo; } 49 Pixmap render(const FbTk::Texture *src_texture);
68 inline BColor *getHiColor(void) { return &hiColor; } 50 /// render solid texture to pixmap
69 inline BColor *getLoColor(void) { return &loColor; } 51 Pixmap renderSolid(const FbTk::Texture *src_texture);
70 52 /// render gradient texture to pixmap
71 inline const unsigned long &getTexture(void) const { return texture; } 53 Pixmap renderGradient(const FbTk::Texture *src_texture);
72
73 inline void setTexture(unsigned long t) { texture = t; }
74 inline void addTexture(unsigned long t) { texture |= t; }
75};
76
77
78// bevel options
79#define BImage_Flat (1l<<1)
80#define BImage_Sunken (1l<<2)
81#define BImage_Raised (1l<<3)
82
83// textures
84#define BImage_Solid (1l<<4)
85#define BImage_Gradient (1l<<5)
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
112#include "BaseDisplay.hh"
113#include "LinkedList.hh"
114 54
55protected:
56 /**
57 Render to pixmap
58 @return rendered pixmap
59 */
60 Pixmap renderPixmap();
61 /**
62 Render to XImage
63 @returns allocated and rendered XImage, user is responsible to deallocate
64 */
65 XImage *renderXImage();
66 /**
67 @name render functions
68 */
69 //@{
70 void invert();
71 void bevel1();
72 void bevel2();
73 void dgradient();
74 void egradient();
75 void hgradient();
76 void pgradient();
77 void rgradient();
78 void vgradient();
79 void cdgradient();
80 void pcgradient();
81 //@}
115 82
116class BImage {
117private: 83private:
118 BImageControl *control; 84 BImageControl *control;
119 85
120#ifdef INTERLACE 86#ifdef INTERLACE
121 Bool interlaced; 87 bool interlaced;
122#endif // INTERLACE 88#endif // INTERLACE
123 89
124 XColor *colors; 90 XColor *colors; // color table
125
126 BColor *from, *to;
127 int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits,
128 ncolors, cpc, cpccpc;
129 unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table;
130 unsigned int width, height, *xtable, *ytable;
131
132
133protected:
134 Pixmap renderPixmap(void);
135
136 XImage *renderXImage(void);
137
138 void invert(void);
139 void bevel1(void);
140 void bevel2(void);
141 void dgradient(void);
142 void egradient(void);
143 void hgradient(void);
144 void pgradient(void);
145 void rgradient(void);
146 void vgradient(void);
147 void cdgradient(void);
148 void pcgradient(void);
149
150
151public:
152 BImage(BImageControl *, unsigned int, unsigned int);
153 ~BImage(void);
154 91
155 Pixmap render(BTexture *); 92 const FbTk::Color *from, *to;
156 Pixmap render_solid(BTexture *); 93 int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits,
157 Pixmap render_gradient(BTexture *); 94 ncolors, cpc, cpccpc;
95 unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table;
96 unsigned int width, height, *xtable, *ytable;
158}; 97};
159 98
160 99/**
100 Holds screen info and color tables
101*/
161class BImageControl : public TimeoutHandler { 102class BImageControl : public TimeoutHandler {
162private: 103public:
163 Bool dither; 104 BImageControl(BaseDisplay *disp, ScreenInfo *screen, bool = False, int = 4,
164 BaseDisplay *basedisplay; 105 unsigned long = 300000l, unsigned long = 200l);
165 ScreenInfo *screeninfo; 106 virtual ~BImageControl();
166#ifdef TIMEDCACHE 107
167 BTimer *timer; 108 inline BaseDisplay *baseDisplay() { return basedisplay; }
168#endif // TIMEDCACHE 109
169 110 inline bool doDither() { return dither; }
170 Colormap colormap; 111 inline const Colormap &colormap() const { return m_colormap; }
171 112 inline const ScreenInfo *getScreenInfo() const { return screeninfo; }
172 Window window; 113 inline Window drawable() const { return window; }
173 XColor *colors; 114
174 int colors_per_channel, ncolors, screen_number, screen_depth, 115 /// @return visual of screen
175 bits_per_pixel, red_offset, green_offset, blue_offset, 116 inline Visual *visual() { return screeninfo->getVisual(); }
176 red_bits, green_bits, blue_bits; 117 /// @return Bits per pixel of screen
177 unsigned char red_color_table[256], green_color_table[256], 118 inline int bitsPerPixel() const { return bits_per_pixel; }
178 blue_color_table[256]; 119 /// @return depth of screen
179 unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width, 120 inline int depth() const { return screen_depth; }
180 grad_buffer_height; 121 inline int colorsPerChannel() const { return colors_per_channel; }
181 unsigned long *sqrt_table, cache_max; 122
182 123 unsigned long color(const char *colorname);
183 typedef struct Cache { 124 unsigned long color(const char *, unsigned char *, unsigned char *,
184 Pixmap pixmap; 125 unsigned char *);
185 126 unsigned long getSqrt(unsigned int val);
186 unsigned int count, width, height; 127 /**
187 unsigned long pixel1, pixel2, texture; 128 Render to pixmap
188 } Cache; 129 @param width width of pixmap
189 130 @param height height of pixmap
190 LinkedList<Cache> *cache; 131 @param src_texture texture type to render
191 132 @return pixmap of the rendered image, on failure None
133 */
134 Pixmap renderImage(unsigned int width, unsigned int height,
135 const FbTk::Texture *src_texture);
136
137 void installRootColormap();
138 void removeImage(Pixmap thepix);
139 void colorTables(unsigned char **, unsigned char **, unsigned char **,
140 int *, int *, int *, int *, int *, int *);
141 void getXColorTable(XColor **, int *);
142 void getGradientBuffers(unsigned int, unsigned int,
143 unsigned int **, unsigned int **);
144 void setDither(bool d) { dither = d; }
145 void setColorsPerChannel(int cpc);
146 void parseTexture(FbTk::Texture *ret_texture, const char *sval);
147 void parseColor(FbTk::Color *ret_color, const char *sval = 0);
148
149 virtual void timeout();
192 150
193protected: 151protected:
194 Pixmap searchCache(unsigned int, unsigned int, unsigned long, BColor *, 152 /**
195 BColor *); 153 Search cache for a specific pixmap
154 @return None if no cache was found
155 */
156 Pixmap searchCache(unsigned int width, unsigned int height, unsigned long texture_type,
157 const FbTk::Color &color, const FbTk::Color &color_to);
196 158
159private:
160 bool dither;
161 BaseDisplay *basedisplay;
162 ScreenInfo *screeninfo;
163#ifdef TIMEDCACHE
164 BTimer timer;
165#endif // TIMEDCACHE
197 166
198public: 167 Colormap m_colormap;
199 BImageControl(BaseDisplay *, ScreenInfo *, Bool = False, int = 4,
200 unsigned long = 300000l, unsigned long = 200l);
201 virtual ~BImageControl(void);
202
203 inline BaseDisplay *getBaseDisplay(void) { return basedisplay; }
204
205 inline const Bool &doDither(void) { return dither; }
206 inline const Colormap &getColormap(void) const { return colormap; }
207 inline ScreenInfo *getScreenInfo(void) { return screeninfo; }
208 168
209 inline const Window &getDrawable(void) const { return window; } 169 Window window;
170 XColor *colors; ///< color table
210 171
211 inline Visual *getVisual(void) { return screeninfo->getVisual(); } 172 int colors_per_channel, ncolors, screen_number, screen_depth,
173 bits_per_pixel, red_offset, green_offset, blue_offset,
174 red_bits, green_bits, blue_bits;
212 175
213 inline const int &getBitsPerPixel(void) const { return bits_per_pixel; } 176 unsigned char red_color_table[256], green_color_table[256],
214 inline const int &getDepth(void) const { return screen_depth; } 177 blue_color_table[256];
215 inline const int &getColorsPerChannel(void) const 178 unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width,
216 { return colors_per_channel; } 179 grad_buffer_height;
217 180
218 unsigned long getColor(const char *); 181 static unsigned long *sqrt_table; /// sqrt lookup table
219 unsigned long getColor(const char *, unsigned char *, unsigned char *,
220 unsigned char *);
221 unsigned long getSqrt(unsigned int);
222 182
223 Pixmap renderImage(unsigned int, unsigned int, BTexture *); 183 typedef struct Cache {
184 Pixmap pixmap;
224 185
225 void installRootColormap(void); 186 unsigned int count, width, height;
226 void removeImage(Pixmap); 187 unsigned long pixel1, pixel2, texture;
227 void getColorTables(unsigned char **, unsigned char **, unsigned char **, 188 } Cache;
228 int *, int *, int *, int *, int *, int *); 189
229 void getXColorTable(XColor **, int *); 190 unsigned long cache_max;
230 void getGradientBuffers(unsigned int, unsigned int, 191 typedef std::list<Cache *> CacheList;
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 192
237 virtual void timeout(void); 193 CacheList cache;
238}; 194};
239 195
240 196
241#endif // __Image_hh 197#endif // IMAGE_HH
242 198