aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/ImageControl.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/ImageControl.hh')
-rw-r--r--src/FbTk/ImageControl.hh139
1 files changed, 139 insertions, 0 deletions
diff --git a/src/FbTk/ImageControl.hh b/src/FbTk/ImageControl.hh
new file mode 100644
index 0000000..087cd69
--- /dev/null
+++ b/src/FbTk/ImageControl.hh
@@ -0,0 +1,139 @@
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.8 2004/01/02 22:19:39 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#include <set>
38
39namespace FbTk {
40
41/// Holds screen info, color tables and caches textures
42class ImageControl: private NotCopyable {
43public:
44 ImageControl(int screen_num, bool dither = false, int colors_per_channel = 4,
45 unsigned long cache_timeout = 300000l, unsigned long cache_max = 200l);
46 virtual ~ImageControl();
47
48 inline bool doDither() const { return m_dither; }
49 inline int bitsPerPixel() const { return bits_per_pixel; }
50 inline int depth() const { return m_screen_depth; }
51 inline int colorsPerChannel() const { return m_colors_per_channel; }
52 int screenNum() const { return m_screen_num; }
53 Visual *visual() const { return m_visual; }
54 unsigned long getSqrt(unsigned int val) const;
55
56 /**
57 Render to pixmap
58 @param width width of pixmap
59 @param height height of pixmap
60 @param src_texture texture type to render
61 @return pixmap of the rendered image, on failure None
62 */
63 Pixmap renderImage(unsigned int width, unsigned int height,
64 const FbTk::Texture &src_texture);
65
66 void installRootColormap();
67 void removeImage(Pixmap thepix);
68 void colorTables(const unsigned char **, const unsigned char **, const unsigned char **,
69 int *, int *, int *, int *, int *, int *) const;
70 void getXColorTable(XColor **, int *);
71 void getGradientBuffers(unsigned int, unsigned int,
72 unsigned int **, unsigned int **);
73 void setDither(bool d) { m_dither = d; }
74 void setColorsPerChannel(int cpc);
75
76 void cleanCache();
77private:
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, const Texture &text) const;
83
84 void createColorTable();
85 bool m_dither;
86 Timer m_timer;
87
88 Colormap m_colormap;
89
90 Window m_root_window;
91
92 XColor *m_colors; ///< color table
93 unsigned int m_num_colors; ///< number of colors in color table
94
95 Visual *m_visual;
96
97 int bits_per_pixel, red_offset, green_offset, blue_offset,
98 red_bits, green_bits, blue_bits;
99 int m_colors_per_channel; ///< number of colors per channel
100 int m_screen_depth; ///< bit depth of screen
101 int m_screen_num; ///< screen number
102 unsigned char red_color_table[256], green_color_table[256],
103 blue_color_table[256];
104 unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width,
105 grad_buffer_height;
106
107 static unsigned long *sqrt_table; /// sqrt lookup table
108
109 typedef struct Cache {
110 Pixmap pixmap;
111 Pixmap texture_pixmap;
112 unsigned int count, width, height;
113 unsigned long pixel1, pixel2, texture;
114 } Cache;
115
116 struct ltCacheEntry {
117 bool operator()(const Cache* s1, const Cache* s2) const {
118 return (s1->width < s2->width || s1->width == s2->width &&
119 (s1->height < s2->height || s1->height == s2->height &&
120 (s1->texture < s2->texture || s1->texture == s2->texture &&
121 s1->pixel1 < s2->pixel1 || s1->pixel1 == s2->pixel1 &&
122 (s1->texture & FbTk::Texture::GRADIENT) &&
123 s1->pixel2 < s2->pixel2)
124 ));
125 }
126 };
127
128
129 unsigned long cache_max;
130 typedef std::set<Cache *, ltCacheEntry> CacheList;
131
132 mutable CacheList cache;
133 static bool s_timed_cache;
134};
135
136} // end namespace FbTk
137
138#endif // FBTK_IMAGECONTROL_HH
139