diff options
Diffstat (limited to 'src/FbTk/ImageControl.hh')
-rw-r--r-- | src/FbTk/ImageControl.hh | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/FbTk/ImageControl.hh b/src/FbTk/ImageControl.hh new file mode 100644 index 0000000..850e814 --- /dev/null +++ b/src/FbTk/ImageControl.hh | |||
@@ -0,0 +1,127 @@ | |||
1 | // ImageControl.hh for FbTk - Fluxbox Toolkit | ||
2 | // Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxbox at users.sourceforge.net) | ||
3 | // | ||
4 | // from Image.hh for Blackbox - an X11 Window manager | ||
5 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net) | ||
6 | // | ||
7 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
8 | // copy of this software and associated documentation files (the "Software"), | ||
9 | // to deal in the Software without restriction, including without limitation | ||
10 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
11 | // and/or sell copies of the Software, and to permit persons to whom the | ||
12 | // Software is furnished to do so, subject to the following conditions: | ||
13 | // | ||
14 | // The above copyright notice and this permission notice shall be included in | ||
15 | // all copies or substantial portions of the Software. | ||
16 | // | ||
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
20 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
23 | // DEALINGS IN THE SOFTWARE. | ||
24 | |||
25 | // $Id: ImageControl.hh,v 1.2 2003/05/16 00:19:51 fluxgen Exp $ | ||
26 | |||
27 | #ifndef FBTK_IMAGECONTROL_HH | ||
28 | #define FBTK_IMAGECONTROL_HH | ||
29 | |||
30 | #include "Texture.hh" | ||
31 | #include "Timer.hh" | ||
32 | #include "NotCopyable.hh" | ||
33 | |||
34 | #include <X11/Xlib.h> | ||
35 | #include <X11/Xutil.h> | ||
36 | #include <list> | ||
37 | |||
38 | namespace FbTk { | ||
39 | |||
40 | /// Holds screen info, color tables and caches textures | ||
41 | class ImageControl : public TimeoutHandler, private NotCopyable { | ||
42 | public: | ||
43 | ImageControl(int screen_num, bool dither = false, int colors_per_channel = 4, | ||
44 | unsigned long cache_timeout = 300000l, unsigned long cache_max = 200l); | ||
45 | virtual ~ImageControl(); | ||
46 | |||
47 | inline bool doDither() const { return m_dither; } | ||
48 | inline int bitsPerPixel() const { return bits_per_pixel; } | ||
49 | inline int depth() const { return m_screen_depth; } | ||
50 | inline int colorsPerChannel() const { return m_colors_per_channel; } | ||
51 | int screenNum() const { return m_screen_num; } | ||
52 | Visual *visual() const { return m_visual; } | ||
53 | unsigned long getSqrt(unsigned int val) const; | ||
54 | |||
55 | /** | ||
56 | Render to pixmap | ||
57 | @param width width of pixmap | ||
58 | @param height height of pixmap | ||
59 | @param src_texture texture type to render | ||
60 | @return pixmap of the rendered image, on failure None | ||
61 | */ | ||
62 | Pixmap renderImage(unsigned int width, unsigned int height, | ||
63 | const FbTk::Texture &src_texture); | ||
64 | |||
65 | void installRootColormap(); | ||
66 | void removeImage(Pixmap thepix); | ||
67 | void colorTables(const unsigned char **, const unsigned char **, const unsigned char **, | ||
68 | int *, int *, int *, int *, int *, int *) const; | ||
69 | void getXColorTable(XColor **, int *); | ||
70 | void getGradientBuffers(unsigned int, unsigned int, | ||
71 | unsigned int **, unsigned int **); | ||
72 | void setDither(bool d) { m_dither = d; } | ||
73 | void setColorsPerChannel(int cpc); | ||
74 | |||
75 | virtual void timeout(); | ||
76 | |||
77 | private: | ||
78 | /** | ||
79 | Search cache for a specific pixmap | ||
80 | @return None if no cache was found | ||
81 | */ | ||
82 | Pixmap searchCache(unsigned int width, unsigned int height, unsigned long texture_type, | ||
83 | const FbTk::Color &color, const FbTk::Color &color_to) const; | ||
84 | |||
85 | void createColorTable(); | ||
86 | bool m_dither; | ||
87 | |||
88 | Timer m_timer; | ||
89 | |||
90 | Colormap m_colormap; | ||
91 | |||
92 | Window m_root_window; | ||
93 | |||
94 | XColor *m_colors; ///< color table | ||
95 | unsigned int m_num_colors; ///< number of colors in color table | ||
96 | |||
97 | Visual *m_visual; | ||
98 | |||
99 | int bits_per_pixel, red_offset, green_offset, blue_offset, | ||
100 | red_bits, green_bits, blue_bits; | ||
101 | int m_colors_per_channel; ///< number of colors per channel | ||
102 | int m_screen_depth; ///< bit depth of screen | ||
103 | int m_screen_num; ///< screen number | ||
104 | unsigned char red_color_table[256], green_color_table[256], | ||
105 | blue_color_table[256]; | ||
106 | unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width, | ||
107 | grad_buffer_height; | ||
108 | |||
109 | static unsigned long *sqrt_table; /// sqrt lookup table | ||
110 | |||
111 | typedef struct Cache { | ||
112 | Pixmap pixmap; | ||
113 | |||
114 | unsigned int count, width, height; | ||
115 | unsigned long pixel1, pixel2, texture; | ||
116 | } Cache; | ||
117 | |||
118 | unsigned long cache_max; | ||
119 | typedef std::list<Cache *> CacheList; | ||
120 | |||
121 | mutable CacheList cache; | ||
122 | }; | ||
123 | |||
124 | }; // end namespace FbTk | ||
125 | |||
126 | #endif // FBTK_IMAGECONTROL_HH | ||
127 | |||