aboutsummaryrefslogtreecommitdiff
path: root/src/Image.hh
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2001-12-11 20:47:02 (GMT)
committerfluxgen <fluxgen>2001-12-11 20:47:02 (GMT)
commit18830ac9add80cbd3bf7369307d7e35a519dca9b (patch)
tree4759a5434a34ba317fe77bbf8b0ed9bb57bb6018 /src/Image.hh
parent1523b48bff07dead084af3064ad11c79a9b25df0 (diff)
downloadfluxbox_pavel-18830ac9add80cbd3bf7369307d7e35a519dca9b.zip
fluxbox_pavel-18830ac9add80cbd3bf7369307d7e35a519dca9b.tar.bz2
Initial revision
Diffstat (limited to 'src/Image.hh')
-rw-r--r--src/Image.hh242
1 files changed, 242 insertions, 0 deletions
diff --git a/src/Image.hh b/src/Image.hh
new file mode 100644
index 0000000..3811e69
--- /dev/null
+++ b/src/Image.hh
@@ -0,0 +1,242 @@
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:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
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.
21
22#ifndef _IMAGE_HH_
23#define _IMAGE_HH_
24
25#include <X11/Xlib.h>
26#include <X11/Xutil.h>
27
28#include "Timer.hh"
29
30class BImage;
31class BImageControl;
32
33
34class BColor {
35private:
36 int allocated;
37 unsigned char red, green, blue;
38 unsigned long pixel;
39
40public:
41 BColor(char r = 0, char g = 0, char b = 0)
42 { red = r; green = g; blue = b; pixel = 0; allocated = 0; }
43
44 inline const int &isAllocated(void) const { return allocated; }
45
46 inline const unsigned char &getRed(void) const { return red; }
47 inline const unsigned char &getGreen(void) const { return green; }
48 inline const unsigned char &getBlue(void) const { return blue; }
49
50 inline const unsigned long &getPixel(void) const { return pixel; }
51
52 inline void setAllocated(int a) { allocated = a; }
53 inline void setRGB(char r, char g, char b) { red = r; green = g; blue = b; }
54 inline void setPixel(unsigned long p) { pixel = p; }
55};
56
57
58class BTexture {
59private:
60 BColor color, colorTo, hiColor, loColor;
61 unsigned long texture;
62
63public:
64 BTexture(void) { texture = 0; }
65
66 inline BColor *getColor(void) { return &color; }
67 inline BColor *getColorTo(void) { return &colorTo; }
68 inline BColor *getHiColor(void) { return &hiColor; }
69 inline BColor *getLoColor(void) { return &loColor; }
70
71 inline const unsigned long &getTexture(void) const { return texture; }
72
73 inline void setTexture(unsigned long t) { texture = t; }
74 inline void addTexture(unsigned long t) { texture |= t; }
75};
76
77
78// bevel options
79#define BImage_Flat (1l<<1)
80#define BImage_Sunken (1l<<2)
81#define BImage_Raised (1l<<3)
82
83// textures
84#define BImage_Solid (1l<<4)
85#define BImage_Gradient (1l<<5)
86
87// gradients
88#define BImage_Horizontal (1l<<6)
89#define BImage_Vertical (1l<<7)
90#define BImage_Diagonal (1l<<8)
91#define BImage_CrossDiagonal (1l<<9)
92#define BImage_Rectangle (1l<<10)
93#define BImage_Pyramid (1l<<11)
94#define BImage_PipeCross (1l<<12)
95#define BImage_Elliptic (1l<<13)
96
97// bevel types
98#define BImage_Bevel1 (1l<<14)
99#define BImage_Bevel2 (1l<<15)
100
101// inverted image
102#define BImage_Invert (1l<<16)
103
104// parent relative image
105#define BImage_ParentRelative (1l<<17)
106
107#ifdef INTERLACE
108// fake interlaced image
109# define BImage_Interlaced (1l<<18)
110#endif // INTERLACE
111
112#include "BaseDisplay.hh"
113#include "LinkedList.hh"
114
115
116class BImage {
117private:
118 BImageControl *control;
119
120#ifdef INTERLACE
121 Bool interlaced;
122#endif // INTERLACE
123
124 XColor *colors;
125
126 BColor *from, *to;
127 int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits,
128 ncolors, cpc, cpccpc;
129 unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table;
130 unsigned int width, height, *xtable, *ytable;
131
132
133protected:
134 Pixmap renderPixmap(void);
135
136 XImage *renderXImage(void);
137
138 void invert(void);
139 void bevel1(void);
140 void bevel2(void);
141 void dgradient(void);
142 void egradient(void);
143 void hgradient(void);
144 void pgradient(void);
145 void rgradient(void);
146 void vgradient(void);
147 void cdgradient(void);
148 void pcgradient(void);
149
150
151public:
152 BImage(BImageControl *, unsigned int, unsigned int);
153 ~BImage(void);
154
155 Pixmap render(BTexture *);
156 Pixmap render_solid(BTexture *);
157 Pixmap render_gradient(BTexture *);
158};
159
160
161class BImageControl : public TimeoutHandler {
162private:
163 Bool dither;
164 BaseDisplay *basedisplay;
165 ScreenInfo *screeninfo;
166#ifdef TIMEDCACHE
167 BTimer *timer;
168#endif // TIMEDCACHE
169
170 Colormap colormap;
171
172 Window window;
173 XColor *colors;
174 int colors_per_channel, ncolors, screen_number, screen_depth,
175 bits_per_pixel, red_offset, green_offset, blue_offset,
176 red_bits, green_bits, blue_bits;
177 unsigned char red_color_table[256], green_color_table[256],
178 blue_color_table[256];
179 unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width,
180 grad_buffer_height;
181 unsigned long *sqrt_table, cache_max;
182
183 typedef struct Cache {
184 Pixmap pixmap;
185
186 unsigned int count, width, height;
187 unsigned long pixel1, pixel2, texture;
188 } Cache;
189
190 LinkedList<Cache> *cache;
191
192
193protected:
194 Pixmap searchCache(unsigned int, unsigned int, unsigned long, BColor *,
195 BColor *);
196
197
198public:
199 BImageControl(BaseDisplay *, ScreenInfo *, Bool = False, int = 4,
200 unsigned long = 300000l, unsigned long = 200l);
201 virtual ~BImageControl(void);
202
203 inline BaseDisplay *getBaseDisplay(void) { return basedisplay; }
204
205 inline const Bool &doDither(void) { return dither; }
206 inline const Colormap &getColormap(void) const { return colormap; }
207 inline ScreenInfo *getScreenInfo(void) { return screeninfo; }
208
209 inline const Window &getDrawable(void) const { return window; }
210
211 inline Visual *getVisual(void) { return screeninfo->getVisual(); }
212
213 inline const int &getBitsPerPixel(void) const { return bits_per_pixel; }
214 inline const int &getDepth(void) const { return screen_depth; }
215 inline const int &getColorsPerChannel(void) const
216 { return colors_per_channel; }
217
218 unsigned long getColor(const char *);
219 unsigned long getColor(const char *, unsigned char *, unsigned char *,
220 unsigned char *);
221 unsigned long getSqrt(unsigned int);
222
223 Pixmap renderImage(unsigned int, unsigned int, BTexture *);
224
225 void installRootColormap(void);
226 void removeImage(Pixmap);
227 void getColorTables(unsigned char **, unsigned char **, unsigned char **,
228 int *, int *, int *, int *, int *, int *);
229 void getXColorTable(XColor **, int *);
230 void getGradientBuffers(unsigned int, unsigned int,
231 unsigned int **, unsigned int **);
232 void setDither(Bool d) { dither = d; }
233 void setColorsPerChannel(int);
234 void parseTexture(BTexture *, char *);
235 void parseColor(BColor *, char * = 0);
236
237 virtual void timeout(void);
238};
239
240
241#endif // __Image_hh
242