diff options
Diffstat (limited to 'src/Image.hh')
-rw-r--r-- | src/Image.hh | 172 |
1 files changed, 59 insertions, 113 deletions
diff --git a/src/Image.hh b/src/Image.hh index 94aa6b0..c43e50b 100644 --- a/src/Image.hh +++ b/src/Image.hh | |||
@@ -22,7 +22,7 @@ | |||
22 | // 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 |
23 | // DEALINGS IN THE SOFTWARE. | 23 | // DEALINGS IN THE SOFTWARE. |
24 | 24 | ||
25 | // $Id: Image.hh,v 1.9 2002/07/22 22:33:45 fluxgen Exp $ | 25 | // $Id: Image.hh,v 1.10 2002/07/23 17:11:59 fluxgen Exp $ |
26 | 26 | ||
27 | #ifndef IMAGE_HH | 27 | #ifndef IMAGE_HH |
28 | #define IMAGE_HH | 28 | #define IMAGE_HH |
@@ -33,124 +33,62 @@ | |||
33 | #include "Timer.hh" | 33 | #include "Timer.hh" |
34 | #include "BaseDisplay.hh" | 34 | #include "BaseDisplay.hh" |
35 | 35 | ||
36 | #include "Color.hh" | ||
37 | #include "Texture.hh" | ||
38 | |||
36 | #include <list> | 39 | #include <list> |
37 | 40 | ||
38 | class BImage; | ||
39 | class BImageControl; | 41 | class BImageControl; |
40 | 42 | ||
41 | 43 | class BImage { | |
42 | class BColor { | ||
43 | public: | ||
44 | BColor(unsigned char red = 0, unsigned char green = 0, unsigned char blue = 0): | ||
45 | m_red(red), m_green(green), m_blue(blue), m_pixel(0), m_allocated(false) { } | ||
46 | |||
47 | inline int isAllocated() const { return m_allocated; } | ||
48 | |||
49 | inline unsigned char red() const { return m_red; } | ||
50 | inline unsigned char green() const { return m_green; } | ||
51 | inline unsigned char blue() const { return m_blue; } | ||
52 | |||
53 | inline unsigned long pixel() const { return m_pixel; } | ||
54 | |||
55 | inline void setAllocated(bool a) { m_allocated = a; } | ||
56 | inline void setRGB(char red, char green, char blue) { m_red = red; m_green = green; m_blue = blue; } | ||
57 | inline void setPixel(unsigned long pixel) { m_pixel = pixel; } | ||
58 | |||
59 | private: | ||
60 | unsigned char m_red, m_green, m_blue; | ||
61 | unsigned long m_pixel; | ||
62 | bool m_allocated; | ||
63 | }; | ||
64 | |||
65 | |||
66 | class BTexture { | ||
67 | public: | 44 | public: |
68 | BTexture():m_texture(0) { } | 45 | BImage(BImageControl *ic, unsigned int, unsigned int); |
69 | 46 | ~BImage(); | |
70 | inline const BColor &color() const { return m_color; } | 47 | /// render to pixmap |
71 | inline const BColor &colorTo() const { return m_color_to; } | 48 | Pixmap render(const FbTk::Texture *src_texture); |
72 | inline const BColor &hiColor() const { return m_hicolor; } | 49 | /// render solid texture to pixmap |
73 | inline const BColor &loColor() const { return m_locolor; } | 50 | Pixmap renderSolid(const FbTk::Texture *src_texture); |
74 | 51 | /// render gradient texture to pixmap | |
75 | inline BColor &color() { return m_color; } | 52 | Pixmap renderGradient(const FbTk::Texture *src_texture); |
76 | inline BColor &colorTo() { return m_color_to; } | ||
77 | inline BColor &hiColor() { return m_hicolor; } | ||
78 | inline BColor &loColor() { return m_locolor; } | ||
79 | |||
80 | inline unsigned long getTexture() const { return m_texture; } | ||
81 | |||
82 | inline void setTexture(unsigned long t) { m_texture = t; } | ||
83 | inline void addTexture(unsigned long t) { m_texture |= t; } | ||
84 | |||
85 | private: | ||
86 | BColor m_color, m_color_to, m_hicolor, m_locolor; | ||
87 | unsigned long m_texture; | ||
88 | }; | ||
89 | |||
90 | 53 | ||
54 | protected: | ||
55 | /** | ||
56 | Render to pixmap | ||
57 | @return rendered pixmap | ||
58 | */ | ||
59 | Pixmap renderPixmap(); | ||
60 | /** | ||
61 | Render to XImage | ||
62 | @returns allocated and rendered XImage, user is responsible to deallocate | ||
63 | */ | ||
64 | XImage *renderXImage(); | ||
65 | |||
66 | void invert(); | ||
67 | void bevel1(); | ||
68 | void bevel2(); | ||
69 | void dgradient(); | ||
70 | void egradient(); | ||
71 | void hgradient(); | ||
72 | void pgradient(); | ||
73 | void rgradient(); | ||
74 | void vgradient(); | ||
75 | void cdgradient(); | ||
76 | void pcgradient(); | ||
91 | 77 | ||
92 | class BImage { | ||
93 | private: | 78 | private: |
94 | BImageControl *control; | 79 | BImageControl *control; |
95 | 80 | ||
96 | #ifdef INTERLACE | 81 | #ifdef INTERLACE |
97 | Bool interlaced; | 82 | bool interlaced; |
98 | #endif // INTERLACE | 83 | #endif // INTERLACE |
99 | 84 | ||
100 | XColor *colors; | 85 | XColor *colors; // color table |
101 | 86 | ||
102 | BColor *from, *to; | 87 | const FbTk::Color *from, *to; |
103 | int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits, | 88 | int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits, |
104 | ncolors, cpc, cpccpc; | 89 | ncolors, cpc, cpccpc; |
105 | unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table; | 90 | unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table; |
106 | unsigned int width, height, *xtable, *ytable; | 91 | unsigned int width, height, *xtable, *ytable; |
107 | |||
108 | |||
109 | protected: | ||
110 | Pixmap renderPixmap(void); | ||
111 | |||
112 | XImage *renderXImage(void); | ||
113 | |||
114 | void invert(void); | ||
115 | void bevel1(void); | ||
116 | void bevel2(void); | ||
117 | void dgradient(void); | ||
118 | void egradient(void); | ||
119 | void hgradient(void); | ||
120 | void pgradient(void); | ||
121 | void rgradient(void); | ||
122 | void vgradient(void); | ||
123 | void cdgradient(void); | ||
124 | void pcgradient(void); | ||
125 | |||
126 | |||
127 | public: | ||
128 | enum Bevel{FLAT=0x00002, SUNKEN=0x00004, RAISED=0x00008}; | ||
129 | enum Textures{SOLID=0x00010, GRADIENT=0x00020}; | ||
130 | enum Gradients{ | ||
131 | HORIZONTAL=0x00040, | ||
132 | VERTICAL=0x00080, | ||
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 *); | ||
154 | }; | 92 | }; |
155 | 93 | ||
156 | 94 | ||
@@ -166,20 +104,21 @@ public: | |||
166 | inline const Colormap &colormap() const { return m_colormap; } | 104 | inline const Colormap &colormap() const { return m_colormap; } |
167 | inline ScreenInfo *getScreenInfo() { return screeninfo; } | 105 | inline ScreenInfo *getScreenInfo() { return screeninfo; } |
168 | 106 | ||
169 | inline const Window &drawable() const { return window; } | 107 | inline Window drawable() const { return window; } |
170 | 108 | ||
171 | inline Visual *visual() { return screeninfo->getVisual(); } | 109 | inline Visual *visual() { return screeninfo->getVisual(); } |
172 | 110 | ||
173 | inline int bitsPerPixel() const { return bits_per_pixel; } | 111 | inline int bitsPerPixel() const { return bits_per_pixel; } |
174 | inline int depth() const { return screen_depth; } | 112 | inline int depth() const { return screen_depth; } |
175 | inline int colorsPerChannel(void) const { return colors_per_channel; } | 113 | inline int colorsPerChannel() const { return colors_per_channel; } |
176 | 114 | ||
177 | unsigned long color(const char *colorname); | 115 | unsigned long color(const char *colorname); |
178 | unsigned long color(const char *, unsigned char *, unsigned char *, | 116 | unsigned long color(const char *, unsigned char *, unsigned char *, |
179 | unsigned char *); | 117 | unsigned char *); |
180 | unsigned long getSqrt(unsigned int val); | 118 | unsigned long getSqrt(unsigned int val); |
181 | 119 | ||
182 | Pixmap renderImage(unsigned int, unsigned int, BTexture *); | 120 | Pixmap renderImage(unsigned int width, unsigned int height, |
121 | const FbTk::Texture *src_texture); | ||
183 | 122 | ||
184 | void installRootColormap(); | 123 | void installRootColormap(); |
185 | void removeImage(Pixmap thepix); | 124 | void removeImage(Pixmap thepix); |
@@ -190,11 +129,19 @@ public: | |||
190 | unsigned int **, unsigned int **); | 129 | unsigned int **, unsigned int **); |
191 | void setDither(bool d) { dither = d; } | 130 | void setDither(bool d) { dither = d; } |
192 | void setColorsPerChannel(int cpc); | 131 | void setColorsPerChannel(int cpc); |
193 | void parseTexture(BTexture *ret_texture, char *sval); | 132 | void parseTexture(FbTk::Texture *ret_texture, const char *sval); |
194 | void parseColor(BColor *ret_color, char *sval = 0); | 133 | void parseColor(FbTk::Color *ret_color, const char *sval = 0); |
195 | 134 | ||
196 | virtual void timeout(); | 135 | virtual void timeout(); |
197 | 136 | ||
137 | protected: | ||
138 | /** | ||
139 | Search cache for a specific pixmap | ||
140 | @return None if no cache was found | ||
141 | */ | ||
142 | Pixmap searchCache(unsigned int width, unsigned int height, unsigned long texture_type, | ||
143 | const FbTk::Color &color, const FbTk::Color &color_to); | ||
144 | |||
198 | private: | 145 | private: |
199 | bool dither; | 146 | bool dither; |
200 | BaseDisplay *basedisplay; | 147 | BaseDisplay *basedisplay; |
@@ -206,16 +153,17 @@ private: | |||
206 | Colormap m_colormap; | 153 | Colormap m_colormap; |
207 | 154 | ||
208 | Window window; | 155 | Window window; |
209 | XColor *colors; | 156 | XColor *colors; // color table |
210 | int colors_per_channel, ncolors, screen_number, screen_depth, | 157 | int colors_per_channel, ncolors, screen_number, screen_depth, |
211 | bits_per_pixel, red_offset, green_offset, blue_offset, | 158 | bits_per_pixel, red_offset, green_offset, blue_offset, |
212 | red_bits, green_bits, blue_bits; | 159 | red_bits, green_bits, blue_bits; |
160 | |||
213 | unsigned char red_color_table[256], green_color_table[256], | 161 | unsigned char red_color_table[256], green_color_table[256], |
214 | blue_color_table[256]; | 162 | blue_color_table[256]; |
215 | unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width, | 163 | unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width, |
216 | grad_buffer_height; | 164 | grad_buffer_height; |
217 | static unsigned long *sqrt_table; | 165 | |
218 | unsigned long cache_max; | 166 | static unsigned long *sqrt_table; /// sqrt lookup table |
219 | 167 | ||
220 | typedef struct Cache { | 168 | typedef struct Cache { |
221 | Pixmap pixmap; | 169 | Pixmap pixmap; |
@@ -223,13 +171,11 @@ private: | |||
223 | unsigned int count, width, height; | 171 | unsigned int count, width, height; |
224 | unsigned long pixel1, pixel2, texture; | 172 | unsigned long pixel1, pixel2, texture; |
225 | } Cache; | 173 | } Cache; |
226 | 174 | ||
175 | unsigned long cache_max; | ||
227 | typedef std::list<Cache *> CacheList; | 176 | typedef std::list<Cache *> CacheList; |
228 | 177 | ||
229 | CacheList cache; | 178 | CacheList cache; |
230 | |||
231 | protected: | ||
232 | Pixmap searchCache(unsigned int, unsigned int, unsigned long, BColor *, BColor *); | ||
233 | }; | 179 | }; |
234 | 180 | ||
235 | 181 | ||