~ubuntu-branches/ubuntu/warty/fluxbox/warty

« back to all changes in this revision

Viewing changes to src/Image.hh

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2002-04-12 22:08:52 UTC
  • Revision ID: james.westby@ubuntu.com-20020412220852-0gbqxr57mgu63qdh
Tags: upstream-0.1.7
ImportĀ upstreamĀ versionĀ 0.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Image.hh for Fluxbox Window Manager
 
2
// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxbox@linuxmail.org)
 
3
//
 
4
// Image.hh for Blackbox - an X11 Window manager
 
5
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
 
6
//
 
7
// Permission is hereby granted, free of charge, to any person obtaining a
 
8
// copy of this software and associated documentation files (the "Software"),
 
9
// to deal in the Software without restriction, including without limitation
 
10
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
11
// and/or sell copies of the Software, and to permit persons to whom the
 
12
// Software is furnished to do so, subject to the following conditions:
 
13
//
 
14
// The above copyright notice and this permission notice shall be included in
 
15
// all copies or substantial portions of the Software.
 
16
//
 
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
18
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
19
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
20
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
21
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
22
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
23
// DEALINGS IN THE SOFTWARE.
 
24
 
 
25
// $Id: Image.hh,v 1.5 2002/02/17 18:57:47 fluxgen Exp $
 
26
 
 
27
#ifndef   IMAGE_HH
 
28
#define   IMAGE_HH
 
29
 
 
30
#include <X11/Xlib.h>
 
31
#include <X11/Xutil.h>
 
32
 
 
33
#include "Timer.hh"
 
34
#include "BaseDisplay.hh"
 
35
 
 
36
#include <list>
 
37
 
 
38
class BImage;
 
39
class BImageControl;
 
40
 
 
41
 
 
42
class BColor {
 
43
private:
 
44
  int allocated;
 
45
  unsigned char red, green, blue;
 
46
  unsigned long pixel;
 
47
 
 
48
public:
 
49
  BColor(char r = 0, char g = 0, char b = 0)
 
50
    { red = r; green = g; blue = b; pixel = 0; allocated = 0; }
 
51
 
 
52
  inline const int &isAllocated(void) const { return allocated; }
 
53
 
 
54
  inline const unsigned char &getRed(void) const { return red; }
 
55
  inline const unsigned char &getGreen(void) const { return green; }
 
56
  inline const unsigned char &getBlue(void) const { return blue; }
 
57
 
 
58
  inline const unsigned long &getPixel(void) const { return pixel; }
 
59
 
 
60
  inline void setAllocated(int a) { allocated = a; }
 
61
  inline void setRGB(char r, char g, char b) { red = r; green = g; blue = b; }
 
62
  inline void setPixel(unsigned long p) { pixel = p; }
 
63
};
 
64
 
 
65
 
 
66
class BTexture {
 
67
private:
 
68
  BColor color, colorTo, hiColor, loColor;
 
69
  unsigned long texture;
 
70
 
 
71
public:
 
72
  BTexture(void) { texture = 0; }
 
73
 
 
74
  inline BColor *getColor(void) { return &color; }
 
75
  inline BColor *getColorTo(void) { return &colorTo; }
 
76
  inline BColor *getHiColor(void) { return &hiColor; }
 
77
  inline BColor *getLoColor(void) { return &loColor; }
 
78
 
 
79
  inline const unsigned long &getTexture(void) const { return texture; }
 
80
 
 
81
  inline void setTexture(unsigned long t) { texture = t; }
 
82
  inline void addTexture(unsigned long t) { texture |= t; }
 
83
};
 
84
 
 
85
 
 
86
 
 
87
class BImage {
 
88
private:
 
89
  BImageControl *control;
 
90
 
 
91
#ifdef    INTERLACE
 
92
  Bool interlaced;
 
93
#endif // INTERLACE
 
94
 
 
95
  XColor *colors;
 
96
 
 
97
  BColor *from, *to;
 
98
  int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits,
 
99
    ncolors, cpc, cpccpc;
 
100
  unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table;
 
101
  unsigned int width, height, *xtable, *ytable;
 
102
 
 
103
 
 
104
protected:
 
105
  Pixmap renderPixmap(void);
 
106
 
 
107
  XImage *renderXImage(void);
 
108
 
 
109
  void invert(void);
 
110
  void bevel1(void);
 
111
  void bevel2(void);
 
112
  void dgradient(void);
 
113
  void egradient(void);
 
114
  void hgradient(void);
 
115
  void pgradient(void);
 
116
  void rgradient(void);
 
117
  void vgradient(void);
 
118
  void cdgradient(void);
 
119
  void pcgradient(void);
 
120
 
 
121
 
 
122
public:
 
123
  enum Bevel{FLAT=0x00002, SUNKEN=0x00004, RAISED=0x00008};
 
124
        enum Textures{SOLID=0x00010, GRADIENT=0x00020};
 
125
        enum Gradients{
 
126
                HORIZONTAL=0x00040,
 
127
                VERTICAL=0x00080,
 
128
                DIAGONAL=0x00100,
 
129
                CROSSDIAGONAL=0x00200,
 
130
                RECTANGLE=0x00400,
 
131
                PYRAMID=0x00800,
 
132
                PIPECROSS=0x01000,
 
133
                ELLIPTIC=0x02000                
 
134
        };
 
135
        
 
136
        enum {
 
137
                BEVEL1=0x04000, BEVEL2=0x08000, // bevel types
 
138
                INVERT=0x010000, //inverted image
 
139
                PARENTRELATIVE=0x20000,
 
140
                INTERLACED=0x40000
 
141
        };
 
142
        
 
143
        BImage(BImageControl *, unsigned int, unsigned int);
 
144
  ~BImage(void);
 
145
 
 
146
  Pixmap render(BTexture *);
 
147
  Pixmap render_solid(BTexture *);
 
148
  Pixmap render_gradient(BTexture *);
 
149
};
 
150
 
 
151
 
 
152
class BImageControl : public TimeoutHandler {
 
153
private:
 
154
  Bool dither;
 
155
  BaseDisplay *basedisplay;
 
156
  ScreenInfo *screeninfo;
 
157
#ifdef    TIMEDCACHE
 
158
  BTimer *timer;
 
159
#endif // TIMEDCACHE
 
160
 
 
161
  Colormap colormap;
 
162
 
 
163
  Window window;
 
164
  XColor *colors;
 
165
  int colors_per_channel, ncolors, screen_number, screen_depth,
 
166
    bits_per_pixel, red_offset, green_offset, blue_offset,
 
167
    red_bits, green_bits, blue_bits;
 
168
  unsigned char red_color_table[256], green_color_table[256],
 
169
    blue_color_table[256];
 
170
  unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width,
 
171
    grad_buffer_height;
 
172
  unsigned long *sqrt_table, cache_max;
 
173
 
 
174
  typedef struct Cache {
 
175
    Pixmap pixmap;
 
176
 
 
177
    unsigned int count, width, height;
 
178
    unsigned long pixel1, pixel2, texture;
 
179
  } Cache;
 
180
 
 
181
  typedef std::list<Cache *> CacheList;
 
182
 
 
183
  CacheList cache;
 
184
 
 
185
 
 
186
protected:
 
187
  Pixmap searchCache(unsigned int, unsigned int, unsigned long, BColor *,
 
188
                     BColor *);
 
189
 
 
190
 
 
191
public:
 
192
  BImageControl(BaseDisplay *, ScreenInfo *, Bool = False, int = 4,
 
193
                unsigned long = 300000l, unsigned long = 200l);
 
194
  virtual ~BImageControl(void);
 
195
 
 
196
  inline BaseDisplay *getBaseDisplay(void) { return basedisplay; }
 
197
 
 
198
  inline const Bool &doDither(void) { return dither; }
 
199
  inline const Colormap &getColormap(void) const { return colormap; }
 
200
  inline ScreenInfo *getScreenInfo(void) { return screeninfo; }
 
201
 
 
202
  inline const Window &getDrawable(void) const { return window; }
 
203
 
 
204
  inline Visual *getVisual(void) { return screeninfo->getVisual(); }
 
205
 
 
206
  inline const int &getBitsPerPixel(void) const { return bits_per_pixel; }
 
207
  inline const int &getDepth(void) const { return screen_depth; }
 
208
  inline const int &getColorsPerChannel(void) const
 
209
    { return colors_per_channel; }
 
210
 
 
211
  unsigned long getColor(const char *);
 
212
  unsigned long getColor(const char *, unsigned char *, unsigned char *,
 
213
                         unsigned char *);
 
214
  unsigned long getSqrt(unsigned int);
 
215
 
 
216
  Pixmap renderImage(unsigned int, unsigned int, BTexture *);
 
217
 
 
218
  void installRootColormap(void);
 
219
  void removeImage(Pixmap);
 
220
  void getColorTables(unsigned char **, unsigned char **, unsigned char **,
 
221
                      int *, int *, int *, int *, int *, int *);
 
222
  void getXColorTable(XColor **, int *);
 
223
  void getGradientBuffers(unsigned int, unsigned int,
 
224
                          unsigned int **, unsigned int **);
 
225
  void setDither(Bool d) { dither = d; }
 
226
  void setColorsPerChannel(int);
 
227
  void parseTexture(BTexture *, char *);
 
228
  void parseColor(BColor *, char * = 0);
 
229
 
 
230
  virtual void timeout(void);
 
231
};
 
232
 
 
233
 
 
234
#endif // __Image_hh
 
235