diff options
author | fluxgen <fluxgen> | 2003-01-09 21:09:49 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-01-09 21:09:49 (GMT) |
commit | 7dd4823340ae5f710a08ff3a8fbe4276defc6b85 (patch) | |
tree | f4b6623ecf435a643fcf247d3075aaf79d6e82f3 /src/FbTk/ImageControl.hh | |
parent | 7a74a56fe48b319fecf56cede8e16f9c03dfaa96 (diff) | |
download | fluxbox-7dd4823340ae5f710a08ff3a8fbe4276defc6b85.zip fluxbox-7dd4823340ae5f710a08ff3a8fbe4276defc6b85.tar.bz2 |
moved from fluxbox to fbtk
Diffstat (limited to 'src/FbTk/ImageControl.hh')
-rw-r--r-- | src/FbTk/ImageControl.hh | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/src/FbTk/ImageControl.hh b/src/FbTk/ImageControl.hh new file mode 100644 index 0000000..81d792c --- /dev/null +++ b/src/FbTk/ImageControl.hh | |||
@@ -0,0 +1,126 @@ | |||
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.1 2003/01/09 21:09:49 fluxgen Exp $ | ||
26 | |||
27 | #ifndef FBTK_IMAGECONTROL_HH | ||
28 | #define FBTK_IMAGECONTROL_HH | ||
29 | |||
30 | #include "Texture.hh" | ||
31 | #include "Timer.hh" | ||
32 | |||
33 | #include <X11/Xlib.h> | ||
34 | #include <X11/Xutil.h> | ||
35 | #include <list> | ||
36 | |||
37 | namespace FbTk { | ||
38 | |||
39 | /// Holds screen info, color tables and caches textures | ||
40 | class ImageControl : public TimeoutHandler { | ||
41 | public: | ||
42 | ImageControl(int screen_num, bool dither = false, int colors_per_channel = 4, | ||
43 | unsigned long cache_timeout = 300000l, unsigned long cache_max = 200l); | ||
44 | virtual ~ImageControl(); | ||
45 | |||
46 | inline bool doDither() const { return m_dither; } | ||
47 | inline int bitsPerPixel() const { return bits_per_pixel; } | ||
48 | inline int depth() const { return m_screen_depth; } | ||
49 | inline int colorsPerChannel() const { return m_colors_per_channel; } | ||
50 | int screenNum() const { return m_screen_num; } | ||
51 | Visual *visual() const { return m_visual; } | ||
52 | unsigned long getSqrt(unsigned int val) const; | ||
53 | |||
54 | /** | ||
55 | Render to pixmap | ||
56 | @param width width of pixmap | ||
57 | @param height height of pixmap | ||
58 | @param src_texture texture type to render | ||
59 | @return pixmap of the rendered image, on failure None | ||
60 | */ | ||
61 | Pixmap renderImage(unsigned int width, unsigned int height, | ||
62 | const FbTk::Texture &src_texture); | ||
63 | |||
64 | void installRootColormap(); | ||
65 | void removeImage(Pixmap thepix); | ||
66 | void colorTables(const unsigned char **, const unsigned char **, const unsigned char **, | ||
67 | int *, int *, int *, int *, int *, int *) const; | ||
68 | void getXColorTable(XColor **, int *); | ||
69 | void getGradientBuffers(unsigned int, unsigned int, | ||
70 | unsigned int **, unsigned int **); | ||
71 | void setDither(bool d) { m_dither = d; } | ||
72 | void setColorsPerChannel(int cpc); | ||
73 | |||
74 | virtual void timeout(); | ||
75 | |||
76 | private: | ||
77 | /** | ||
78 | Search cache for a specific pixmap | ||
79 | @return None if no cache was found | ||
80 | */ | ||
81 | Pixmap searchCache(unsigned int width, unsigned int height, unsigned long texture_type, | ||
82 | const FbTk::Color &color, const FbTk::Color &color_to) const; | ||
83 | |||
84 | void createColorTable(); | ||
85 | bool m_dither; | ||
86 | |||
87 | Timer m_timer; | ||
88 | |||
89 | Colormap m_colormap; | ||
90 | |||
91 | Window m_root_window; | ||
92 | |||
93 | XColor *m_colors; ///< color table | ||
94 | unsigned int m_num_colors; ///< number of colors in color table | ||
95 | |||
96 | Visual *m_visual; | ||
97 | |||
98 | int bits_per_pixel, red_offset, green_offset, blue_offset, | ||
99 | red_bits, green_bits, blue_bits; | ||
100 | int m_colors_per_channel; ///< number of colors per channel | ||
101 | int m_screen_depth; ///< bit depth of screen | ||
102 | int m_screen_num; ///< screen number | ||
103 | unsigned char red_color_table[256], green_color_table[256], | ||
104 | blue_color_table[256]; | ||
105 | unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width, | ||
106 | grad_buffer_height; | ||
107 | |||
108 | static unsigned long *sqrt_table; /// sqrt lookup table | ||
109 | |||
110 | typedef struct Cache { | ||
111 | Pixmap pixmap; | ||
112 | |||
113 | unsigned int count, width, height; | ||
114 | unsigned long pixel1, pixel2, texture; | ||
115 | } Cache; | ||
116 | |||
117 | unsigned long cache_max; | ||
118 | typedef std::list<Cache *> CacheList; | ||
119 | |||
120 | mutable CacheList cache; | ||
121 | }; | ||
122 | |||
123 | }; // end namespace FbTk | ||
124 | |||
125 | #endif // FBTK_IMAGECONTROL_HH | ||
126 | |||