- changing MaxInstructions to 100 for cthulhain (crazy nut) =:)
[bbkeys.git] / src / Image.hh
blob4b85acc7aa81b9533e90102386607ca5c2b7ecd2
1 // Image.hh for Blackbox - an X11 Window manager
2 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
22 // $Id$
24 #ifndef __Image_hh
25 #define __Image_hh
27 #include <X11/Xlib.h>
28 #include <X11/Xutil.h>
30 #include "Timer.hh"
32 class BImage;
33 class BImageControl;
36 class BColor {
37 private:
38 int allocated;
39 unsigned char red, green, blue;
40 unsigned long pixel;
42 public:
43 BColor(char r = 0, char g = 0, char b = 0)
44 { red = r; green = g; blue = b; pixel = 0; allocated = 0; }
46 inline const int &isAllocated(void) const { return allocated; }
48 inline const unsigned char &getRed(void) const { return red; }
49 inline const unsigned char &getGreen(void) const { return green; }
50 inline const unsigned char &getBlue(void) const { return blue; }
52 inline const unsigned long &getPixel(void) const { return pixel; }
54 inline void setAllocated(int a) { allocated = a; }
55 inline void setRGB(char r, char g, char b) { red = r; green = g; blue = b; }
56 inline void setPixel(unsigned long p) { pixel = p; }
60 class BTexture {
61 private:
62 BColor color, colorTo, hiColor, loColor;
63 unsigned long texture;
65 public:
66 BTexture(void) { texture = 0; }
68 inline BColor *getColor(void) { return &color; }
69 inline BColor *getColorTo(void) { return &colorTo; }
70 inline BColor *getHiColor(void) { return &hiColor; }
71 inline BColor *getLoColor(void) { return &loColor; }
73 inline const unsigned long &getTexture(void) const { return texture; }
75 inline void setTexture(unsigned long t) { texture = t; }
76 inline void addTexture(unsigned long t) { texture |= t; }
80 // bevel options
81 #define BImage_Flat (1l<<1)
82 #define BImage_Sunken (1l<<2)
83 #define BImage_Raised (1l<<3)
85 // textures
86 #define BImage_Solid (1l<<4)
87 #define BImage_Gradient (1l<<5)
89 // gradients
90 #define BImage_Horizontal (1l<<6)
91 #define BImage_Vertical (1l<<7)
92 #define BImage_Diagonal (1l<<8)
93 #define BImage_CrossDiagonal (1l<<9)
94 #define BImage_Rectangle (1l<<10)
95 #define BImage_Pyramid (1l<<11)
96 #define BImage_PipeCross (1l<<12)
97 #define BImage_Elliptic (1l<<13)
99 // bevel types
100 #define BImage_Bevel1 (1l<<14)
101 #define BImage_Bevel2 (1l<<15)
103 // inverted image
104 #define BImage_Invert (1l<<16)
106 // parent relative image
107 #define BImage_ParentRelative (1l<<17)
109 #ifdef INTERLACE
110 // fake interlaced image
111 # define BImage_Interlaced (1l<<18)
112 #endif // INTERLACE
114 #include "BaseDisplay.hh"
115 #include "LinkedList.hh"
118 class BImage {
119 private:
120 BImageControl *control;
122 #ifdef INTERLACE
123 Bool interlaced;
124 #endif // INTERLACE
126 XColor *colors;
128 BColor *from, *to;
129 int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits,
130 ncolors, cpc, cpccpc;
131 unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table;
132 unsigned int width, height, *xtable, *ytable;
135 protected:
136 Pixmap renderPixmap(void);
138 XImage *renderXImage(void);
140 void invert(void);
141 void bevel1(void);
142 void bevel2(void);
143 void dgradient(void);
144 void egradient(void);
145 void hgradient(void);
146 void pgradient(void);
147 void rgradient(void);
148 void vgradient(void);
149 void cdgradient(void);
150 void pcgradient(void);
153 public:
154 BImage(BImageControl *, unsigned int, unsigned int);
155 ~BImage(void);
157 Pixmap render(BTexture *);
158 Pixmap render_solid(BTexture *);
159 Pixmap render_gradient(BTexture *);
163 class BImageControl : public TimeoutHandler {
164 private:
165 Bool dither;
166 BaseDisplay *basedisplay;
167 ScreenInfo *screeninfo;
168 #ifdef TIMEDCACHE
169 BTimer *timer;
170 #endif // TIMEDCACHE
172 Colormap root_colormap;
173 Window window;
174 XColor *colors;
175 int colors_per_channel, ncolors, screen_number, screen_depth,
176 bits_per_pixel, red_offset, green_offset, blue_offset,
177 red_bits, green_bits, blue_bits;
178 unsigned char red_color_table[256], green_color_table[256],
179 blue_color_table[256];
180 unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width,
181 grad_buffer_height;
182 unsigned long *sqrt_table, cache_max;
184 typedef struct Cache {
185 Pixmap pixmap;
187 unsigned int count, width, height;
188 unsigned long pixel1, pixel2, texture;
189 } Cache;
191 LinkedList<Cache> *cache;
194 protected:
195 Pixmap searchCache(unsigned int, unsigned int, unsigned long, BColor *,
196 BColor *);
199 public:
200 BImageControl(BaseDisplay *, ScreenInfo *, Bool = False, int = 4,
201 unsigned long = 300000l, unsigned long = 200l);
202 virtual ~BImageControl(void);
204 inline BaseDisplay *getBaseDisplay(void) { return basedisplay; }
206 inline const Bool &doDither(void) { return dither; }
208 inline const Colormap &getColormap(void) const { return root_colormap; }
210 inline ScreenInfo *getScreenInfo(void) { return screeninfo; }
212 inline const Window &getDrawable(void) const { return window; }
214 inline Visual *getVisual(void) { return screeninfo->getVisual(); }
216 inline const int &getBitsPerPixel(void) const { return bits_per_pixel; }
217 inline const int &getDepth(void) const { return screen_depth; }
218 inline const int &getColorsPerChannel(void) const
219 { return colors_per_channel; }
221 unsigned long getColor(const char *);
222 unsigned long getColor(const char *, unsigned char *, unsigned char *,
223 unsigned char *);
224 unsigned long getSqrt(unsigned int);
226 Pixmap renderImage(unsigned int, unsigned int, BTexture *);
228 void installRootColormap(void);
229 void removeImage(Pixmap);
230 void getColorTables(unsigned char **, unsigned char **, unsigned char **,
231 int *, int *, int *, int *, int *, int *);
232 void getXColorTable(XColor **, int *);
233 void getGradientBuffers(unsigned int, unsigned int,
234 unsigned int **, unsigned int **);
235 void setDither(Bool d) { dither = d; }
236 void setColorsPerChannel(int);
237 void parseTexture(BTexture *, char *);
238 void parseColor(BColor *, char * = 0);
240 virtual void timeout(void);
244 #endif // __Image_hh