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.
28 #include <X11/Xutil.h>
39 unsigned char red
, green
, blue
;
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
; }
62 BColor color
, colorTo
, hiColor
, loColor
;
63 unsigned long texture
;
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
; }
81 #define BImage_Flat (1l<<1)
82 #define BImage_Sunken (1l<<2)
83 #define BImage_Raised (1l<<3)
86 #define BImage_Solid (1l<<4)
87 #define BImage_Gradient (1l<<5)
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)
100 #define BImage_Bevel1 (1l<<14)
101 #define BImage_Bevel2 (1l<<15)
104 #define BImage_Invert (1l<<16)
106 // parent relative image
107 #define BImage_ParentRelative (1l<<17)
110 // fake interlaced image
111 # define BImage_Interlaced (1l<<18)
114 #include "BaseDisplay.hh"
115 #include "LinkedList.hh"
120 BImageControl
*control
;
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
;
136 Pixmap
renderPixmap(void);
138 XImage
*renderXImage(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);
154 BImage(BImageControl
*, unsigned int, unsigned int);
157 Pixmap
render(BTexture
*);
158 Pixmap
render_solid(BTexture
*);
159 Pixmap
render_gradient(BTexture
*);
163 class BImageControl
: public TimeoutHandler
{
166 BaseDisplay
*basedisplay
;
167 ScreenInfo
*screeninfo
;
172 Colormap root_colormap
;
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
,
182 unsigned long *sqrt_table
, cache_max
;
184 typedef struct Cache
{
187 unsigned int count
, width
, height
;
188 unsigned long pixel1
, pixel2
, texture
;
191 LinkedList
<Cache
> *cache
;
195 Pixmap
searchCache(unsigned int, unsigned int, unsigned long, BColor
*,
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 *,
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);