]> Dogcows Code - chaz/openbox/blob - src/Image.hh
caps
[chaz/openbox] / src / Image.hh
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // Image.hh for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 #ifndef __Image_hh
25 #define __Image_hh
26
27 extern "C" {
28 #include <X11/Xlib.h>
29 #include <X11/Xutil.h>
30 }
31
32 #include <list>
33
34 #include "Timer.hh"
35 #include "BaseDisplay.hh"
36 #include "Color.hh"
37
38 class BImageControl;
39 class BTexture;
40
41 class BImage {
42 private:
43 BImageControl *control;
44 bool interlaced;
45 XColor *colors;
46
47 BColor from, to;
48 int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits,
49 ncolors, cpc, cpccpc;
50 unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table;
51 unsigned int width, height, *xtable, *ytable;
52
53 void TrueColorDither(unsigned int bit_depth, int bytes_per_line,
54 unsigned char *pixel_data);
55 void PseudoColorDither(int bytes_per_line, unsigned char *pixel_data);
56 #ifdef ORDEREDPSEUDO
57 void OrderedPseudoColorDither(int bytes_per_line, unsigned char *pixel_data);
58 #endif
59
60 Pixmap renderPixmap(void);
61 Pixmap render_solid(const BTexture &texture);
62 Pixmap render_gradient(const BTexture &texture);
63
64 XImage *renderXImage(void);
65
66 void invert(void);
67 void bevel1(void);
68 void bevel2(void);
69 void dgradient(void);
70 void egradient(void);
71 void hgradient(void);
72 void pgradient(void);
73 void rgradient(void);
74 void vgradient(void);
75 void cdgradient(void);
76 void pcgradient(void);
77
78
79 public:
80 BImage(BImageControl *c, int w, int h);
81 ~BImage(void);
82
83 Pixmap render(const BTexture &texture);
84 };
85
86
87 class BImageControl : public TimeoutHandler {
88 public:
89 struct CachedImage {
90 Pixmap pixmap;
91
92 unsigned int count, width, height;
93 unsigned long pixel1, pixel2, texture;
94 };
95
96 BImageControl(BaseDisplay *dpy, const ScreenInfo *scrn,
97 bool _dither= False, int _cpc = 4,
98 unsigned long cache_timeout = 300000l,
99 unsigned long cmax = 200l);
100 virtual ~BImageControl(void);
101
102 inline BaseDisplay *getBaseDisplay(void) const { return basedisplay; }
103
104 inline bool doDither(void) { return dither; }
105
106 inline const ScreenInfo *getScreenInfo(void) { return screeninfo; }
107
108 inline Window getDrawable(void) const { return window; }
109
110 inline Visual *getVisual(void) { return screeninfo->getVisual(); }
111
112 inline int getBitsPerPixel(void) const { return bits_per_pixel; }
113 inline int getDepth(void) const { return screen_depth; }
114 inline int getColorsPerChannel(void) const
115 { return colors_per_channel; }
116
117 unsigned long getSqrt(unsigned int x);
118
119 Pixmap renderImage(unsigned int width, unsigned int height,
120 const BTexture &texture);
121
122 void installRootColormap(void);
123 void removeImage(Pixmap pixmap);
124 void getColorTables(unsigned char **rmt, unsigned char **gmt,
125 unsigned char **bmt,
126 int *roff, int *goff, int *boff,
127 int *rbit, int *gbit, int *bbit);
128 void getXColorTable(XColor **c, int *n);
129 void getGradientBuffers(unsigned int w, unsigned int h,
130 unsigned int **xbuf, unsigned int **ybuf);
131 void setDither(bool d) { dither = d; }
132 void setColorsPerChannel(int cpc);
133
134 virtual void timeout(void);
135
136 private:
137 bool dither;
138 BaseDisplay *basedisplay;
139 const ScreenInfo *screeninfo;
140 #ifdef TIMEDCACHE
141 BTimer *timer;
142 #endif // TIMEDCACHE
143
144 Colormap colormap;
145
146 Window window;
147 XColor *colors;
148 int colors_per_channel, ncolors, screen_number, screen_depth,
149 bits_per_pixel, red_offset, green_offset, blue_offset,
150 red_bits, green_bits, blue_bits;
151 unsigned char red_color_table[256], green_color_table[256],
152 blue_color_table[256];
153 unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width,
154 grad_buffer_height;
155 unsigned long *sqrt_table, cache_max;
156
157 typedef std::list<CachedImage> CacheContainer;
158 CacheContainer cache;
159
160 Pixmap searchCache(const unsigned int width, const unsigned int height,
161 const unsigned long texture,
162 const BColor &c1, const BColor &c2);
163 };
164
165
166 #endif // __Image_hh
167
This page took 0.040952 seconds and 4 git commands to generate.