00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef FBTK_IMAGECONTROL_HH
00028 #define FBTK_IMAGECONTROL_HH
00029
00030 #include "Texture.hh"
00031 #include "Timer.hh"
00032 #include "NotCopyable.hh"
00033
00034 #include <X11/Xlib.h>
00035 #include <X11/Xutil.h>
00036 #include <list>
00037 #include <set>
00038
00039 namespace FbTk {
00040
00042 class ImageControl: private NotCopyable {
00043 public:
00044 ImageControl(int screen_num, bool dither = false, int colors_per_channel = 4,
00045 unsigned long cache_timeout = 300000l, unsigned long cache_max = 200l);
00046 virtual ~ImageControl();
00047
00048 inline bool doDither() const { return m_dither; }
00049 inline int bitsPerPixel() const { return bits_per_pixel; }
00050 inline int depth() const { return m_screen_depth; }
00051 inline int colorsPerChannel() const { return m_colors_per_channel; }
00052 int screenNum() const { return m_screen_num; }
00053 Visual *visual() const { return m_visual; }
00054 unsigned long getSqrt(unsigned int val) const;
00055
00063 Pixmap renderImage(unsigned int width, unsigned int height,
00064 const FbTk::Texture &src_texture);
00065
00066 void installRootColormap();
00067 void removeImage(Pixmap thepix);
00068 void colorTables(const unsigned char **, const unsigned char **, const unsigned char **,
00069 int *, int *, int *, int *, int *, int *) const;
00070 void getXColorTable(XColor **, int *);
00071 void getGradientBuffers(unsigned int, unsigned int,
00072 unsigned int **, unsigned int **);
00073 void setDither(bool d) { m_dither = d; }
00074 void setColorsPerChannel(int cpc);
00075
00076 void cleanCache();
00077 private:
00082 Pixmap searchCache(unsigned int width, unsigned int height, const Texture &text) const;
00083
00084 void createColorTable();
00085 bool m_dither;
00086 Timer m_timer;
00087
00088 Colormap m_colormap;
00089
00090 Window m_root_window;
00091
00092 XColor *m_colors;
00093 unsigned int m_num_colors;
00094
00095 Visual *m_visual;
00096
00097 int bits_per_pixel, red_offset, green_offset, blue_offset,
00098 red_bits, green_bits, blue_bits;
00099 int m_colors_per_channel;
00100 int m_screen_depth;
00101 int m_screen_num;
00102 unsigned char red_color_table[256], green_color_table[256],
00103 blue_color_table[256];
00104 unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width,
00105 grad_buffer_height;
00106
00107 static unsigned long *sqrt_table;
00108
00109 typedef struct Cache {
00110 Pixmap pixmap;
00111 Pixmap texture_pixmap;
00112 unsigned int count, width, height;
00113 unsigned long pixel1, pixel2, texture;
00114 } Cache;
00115
00116 struct ltCacheEntry {
00117 bool operator()(const Cache* s1, const Cache* s2) const {
00118 return (s1->width < s2->width || s1->width == s2->width &&
00119 (s1->height < s2->height || s1->height == s2->height &&
00120 (s1->texture < s2->texture || s1->texture == s2->texture &&
00121 s1->pixel1 < s2->pixel1 || s1->pixel1 == s2->pixel1 &&
00122 (s1->texture & FbTk::Texture::GRADIENT) &&
00123 s1->pixel2 < s2->pixel2)
00124 ));
00125 }
00126 };
00127
00128
00129 unsigned long cache_max;
00130 typedef std::list<Cache *> CacheList;
00131
00132 mutable CacheList cache;
00133 static bool s_timed_cache;
00134 };
00135
00136 }
00137
00138 #endif // FBTK_IMAGECONTROL_HH
00139