]> icculus.org git repositories - mikachu/openbox.git/blob - otk/image.hh
add an OBDisplay class and the old ScreenInfo class to the toolkit.
[mikachu/openbox.git] / otk / image.hh
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 #ifndef   __Image_hh
3 #define   __Image_hh
4
5 extern "C" {
6 #include <X11/Xlib.h>
7 #include <X11/Xutil.h>
8 }
9
10 #include <list>
11
12 #include "timer.hh"
13 #include "color.hh"
14 #include "screeninfo.hh"
15
16 namespace otk {
17
18 class BImageControl;
19 class BTexture;
20 class ScreenInfo;
21
22 class BImage {
23 private:
24   BImageControl *control;
25   bool interlaced;
26   XColor *colors;
27
28   BColor from, to;
29   int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits,
30     ncolors, cpc, cpccpc;
31   unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table;
32   unsigned int width, height, *xtable, *ytable;
33
34   void TrueColorDither(unsigned int bit_depth, int bytes_per_line,
35                        unsigned char *pixel_data);
36   void PseudoColorDither(int bytes_per_line, unsigned char *pixel_data);
37 #ifdef ORDEREDPSEUDO
38   void OrderedPseudoColorDither(int bytes_per_line, unsigned char *pixel_data);
39 #endif
40
41   Pixmap renderPixmap(void);
42   Pixmap render_solid(const BTexture &texture);
43   Pixmap render_gradient(const BTexture &texture);
44
45   XImage *renderXImage(void);
46
47   void invert(void);
48   void bevel1(void);
49   void bevel2(void);
50   void border(const BTexture &texture);
51   void dgradient(void);
52   void egradient(void);
53   void hgradient(void);
54   void pgradient(void);
55   void rgradient(void);
56   void vgradient(void);
57   void cdgradient(void);
58   void pcgradient(void);
59
60
61 public:
62   BImage(BImageControl *c, int w, int h);
63   ~BImage(void);
64
65   Pixmap render(const BTexture &texture);
66 };
67
68
69 class BImageControl : public TimeoutHandler {
70 public:
71   struct CachedImage {
72     Pixmap pixmap;
73
74     unsigned int count, width, height;
75     unsigned long pixel1, pixel2, texture;
76   };
77
78   BImageControl(const ScreenInfo *scrn,
79                 bool _dither= False, int _cpc = 4,
80                 unsigned long cache_timeout = 300000l,
81                 unsigned long cmax = 200l);
82   virtual ~BImageControl(void);
83
84   inline bool doDither(void) { return dither; }
85
86   inline const ScreenInfo* getScreenInfo() const { return screeninfo; }
87
88   inline Window getDrawable(void) const { return window; }
89
90   inline Visual *getVisual(void) { return screeninfo->getVisual(); }
91
92   inline int getBitsPerPixel(void) const { return bits_per_pixel; }
93   inline int getDepth(void) const { return screen_depth; }
94   inline int getColorsPerChannel(void) const
95     { return colors_per_channel; }
96
97   unsigned long getSqrt(unsigned int x);
98
99   Pixmap renderImage(unsigned int width, unsigned int height,
100                      const BTexture &texture);
101
102   void installRootColormap(void);
103   void removeImage(Pixmap pixmap);
104   void getColorTables(unsigned char **rmt, unsigned char **gmt,
105                       unsigned char **bmt,
106                       int *roff, int *goff, int *boff,
107                       int *rbit, int *gbit, int *bbit);
108   void getXColorTable(XColor **c, int *n);
109   void getGradientBuffers(unsigned int w, unsigned int h,
110                           unsigned int **xbuf, unsigned int **ybuf);
111   void setDither(bool d) { dither = d; }
112   void setColorsPerChannel(int cpc);
113
114   virtual void timeout(void);
115
116 private:
117   bool dither;
118   const ScreenInfo *screeninfo;
119   BTimer *timer;
120
121   Colormap colormap;
122
123   Window window;
124   XColor *colors;
125   int colors_per_channel, ncolors, screen_number, screen_depth,
126     bits_per_pixel, red_offset, green_offset, blue_offset,
127     red_bits, green_bits, blue_bits;
128   unsigned char red_color_table[256], green_color_table[256],
129     blue_color_table[256];
130   unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width,
131     grad_buffer_height;
132   unsigned long *sqrt_table, cache_max;
133
134   typedef std::list<CachedImage> CacheContainer;
135   CacheContainer cache;
136
137   Pixmap searchCache(const unsigned int width, const unsigned int height,
138                      const unsigned long texture,
139                      const BColor &c1, const BColor &c2);
140 };
141
142 }
143
144 #endif // __Image_hh
145