1 // Image.hh for Blackbox - an X11 Window manager
2 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
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.
29 #include <X11/Xutil.h>
41 unsigned char red
, green
, blue
;
45 BColor(char r
= 0, char g
= 0, char b
= 0)
46 { red
= r
; green
= g
; blue
= b
; pixel
= 0; allocated
= 0; }
48 inline const int &isAllocated(void) const { return allocated
; }
50 inline const unsigned char &getRed(void) const { return red
; }
51 inline const unsigned char &getGreen(void) const { return green
; }
52 inline const unsigned char &getBlue(void) const { return blue
; }
54 inline const unsigned long &getPixel(void) const { return pixel
; }
56 inline void setAllocated(int a
) { allocated
= a
; }
57 inline void setRGB(char r
, char g
, char b
) { red
= r
; green
= g
; blue
= b
; }
58 inline void setPixel(unsigned long p
) { pixel
= p
; }
64 BColor color
, colorTo
, hiColor
, loColor
;
65 unsigned long texture
;
68 BTexture(void) { texture
= 0; }
70 inline BColor
*getColor(void) { return &color
; }
71 inline BColor
*getColorTo(void) { return &colorTo
; }
72 inline BColor
*getHiColor(void) { return &hiColor
; }
73 inline BColor
*getLoColor(void) { return &loColor
; }
75 inline const unsigned long &getTexture(void) const { return texture
; }
77 inline void setTexture(unsigned long t
) { texture
= t
; }
78 inline void addTexture(unsigned long t
) { texture
|= t
; }
83 #define BImage_Flat (1l<<1)
84 #define BImage_Sunken (1l<<2)
85 #define BImage_Raised (1l<<3)
88 #define BImage_Solid (1l<<4)
89 #define BImage_Gradient (1l<<5)
92 #define BImage_Horizontal (1l<<6)
93 #define BImage_Vertical (1l<<7)
94 #define BImage_Diagonal (1l<<8)
95 #define BImage_CrossDiagonal (1l<<9)
96 #define BImage_Rectangle (1l<<10)
97 #define BImage_Pyramid (1l<<11)
98 #define BImage_PipeCross (1l<<12)
99 #define BImage_Elliptic (1l<<13)
102 #define BImage_Bevel1 (1l<<14)
103 #define BImage_Bevel2 (1l<<15)
106 #define BImage_Invert (1l<<16)
108 // parent relative image
109 #define BImage_ParentRelative (1l<<17)
112 // fake interlaced image
113 # define BImage_Interlaced (1l<<18)
116 #include "BaseDisplay.hh"
117 #include "LinkedList.hh"
122 BImageControl
*control
;
131 int red_offset
, green_offset
, blue_offset
, red_bits
, green_bits
, blue_bits
,
132 ncolors
, cpc
, cpccpc
;
133 unsigned char *red
, *green
, *blue
, *red_table
, *green_table
, *blue_table
;
134 unsigned int width
, height
, *xtable
, *ytable
;
138 Pixmap
renderPixmap(void);
140 XImage
*renderXImage(void);
145 void dgradient(void);
146 void egradient(void);
147 void hgradient(void);
148 void pgradient(void);
149 void rgradient(void);
150 void vgradient(void);
151 void cdgradient(void);
152 void pcgradient(void);
156 BImage(BImageControl
*, unsigned int, unsigned int);
159 Pixmap
render(BTexture
*);
160 Pixmap
render_solid(BTexture
*);
161 Pixmap
render_gradient(BTexture
*);
165 class BImageControl
: public TimeoutHandler
{
168 BaseDisplay
*basedisplay
;
169 ScreenInfo
*screeninfo
;
174 Colormap root_colormap
;
177 int colors_per_channel
, ncolors
, screen_number
, screen_depth
,
178 bits_per_pixel
, red_offset
, green_offset
, blue_offset
,
179 red_bits
, green_bits
, blue_bits
;
180 unsigned char red_color_table
[256], green_color_table
[256],
181 blue_color_table
[256];
182 unsigned int *grad_xbuffer
, *grad_ybuffer
, grad_buffer_width
,
184 unsigned long *sqrt_table
, cache_max
;
186 typedef struct Cache
{
189 unsigned int count
, width
, height
;
190 unsigned long pixel1
, pixel2
, texture
;
193 LinkedList
<Cache
> *cache
;
197 Pixmap
searchCache(unsigned int, unsigned int, unsigned long, BColor
*,
202 BImageControl(BaseDisplay
*, ScreenInfo
*, Bool
= False
, int = 4,
203 unsigned long = 300000l, unsigned long = 200l);
204 virtual ~BImageControl(void);
206 inline BaseDisplay
*getBaseDisplay(void) { return basedisplay
; }
208 inline const Bool
&doDither(void) { return dither
; }
210 inline const Colormap
&getColormap(void) const { return root_colormap
; }
212 inline ScreenInfo
*getScreenInfo(void) { return screeninfo
; }
214 inline const Window
&getDrawable(void) const { return window
; }
216 inline Visual
*getVisual(void) { return screeninfo
->getVisual(); }
218 inline const int &getBitsPerPixel(void) const { return bits_per_pixel
; }
219 inline const int &getDepth(void) const { return screen_depth
; }
220 inline const int &getColorsPerChannel(void) const
221 { return colors_per_channel
; }
223 unsigned long getColor(const char *);
224 unsigned long getColor(const char *, unsigned char *, unsigned char *,
226 unsigned long getSqrt(unsigned int);
228 Pixmap
renderImage(unsigned int, unsigned int, BTexture
*);
230 void installRootColormap(void);
231 void removeImage(Pixmap
);
232 void getColorTables(unsigned char **, unsigned char **, unsigned char **,
233 int *, int *, int *, int *, int *, int *);
234 void getXColorTable(XColor
**, int *);
235 void getGradientBuffers(unsigned int, unsigned int,
236 unsigned int **, unsigned int **);
237 void setDither(Bool d
) { dither
= d
; }
238 void setColorsPerChannel(int);
239 void parseTexture(BTexture
*, const char *);
240 void parseColor(BColor
*, const char * = 0);
242 virtual void timeout(void);