1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
// Image.hh for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 1999 by Brad Hughes, bhughes@tcac.net
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// (See the included file COPYING / GPL-2.0)
//
#ifndef __Image_hh
#define __Image_hh
#include <X11/Xlib.h>
#include <X11/Xutil.h>
class BaseDisplay;
class ScreenInfo;
class BImage;
class BImageControl;
class BColor {
private:
int allocated;
unsigned char red, green, blue;
unsigned long pixel;
public:
BColor(char r = 0, char g = 0, char b = 0)
{ red = r; green = g; blue = b; pixel = 0; allocated = 0; }
int isAllocated(void) { return allocated; }
unsigned char getRed(void) { return red; }
unsigned char getGreen(void) { return green; }
unsigned char getBlue(void) { return blue; }
unsigned long getPixel(void) { return pixel; }
void setAllocated(int a)
{ allocated = a; }
void setRGB(char r, char g, char b)
{ red = r; green = g; blue = b; }
void setPixel(unsigned long p)
{ pixel = p; }
};
class BTexture {
private:
BColor color, colorTo, hiColor, loColor;
unsigned long texture;
public:
BTexture(void) { texture = 0; }
BColor *getColor(void) { return &color; }
BColor *getColorTo(void) { return &colorTo; }
BColor *getHiColor(void) { return &hiColor; }
BColor *getLoColor(void) { return &loColor; }
unsigned long getTexture(void) { return texture; }
void setTexture(unsigned long t) { texture = t; }
void addTexture(unsigned long t) { texture |= t; }
};
#include "LinkedList.hh"
// bevel options
#define BImage_Flat (1l<<1)
#define BImage_Sunken (1l<<2)
#define BImage_Raised (1l<<3)
// textures
#define BImage_Solid (1l<<4)
#define BImage_Gradient (1l<<5)
// gradients
#define BImage_Horizontal (1l<<6)
#define BImage_Vertical (1l<<7)
#define BImage_Diagonal (1l<<8)
#define BImage_CrossDiagonal (1l<<9)
#define BImage_Rectangle (1l<<10)
#define BImage_Pyramid (1l<<11)
#define BImage_PipeCross (1l<<12)
#define BImage_Elliptic (1l<<13)
// bevel types
#define BImage_Bevel1 (1l<<14)
#define BImage_Bevel2 (1l<<15)
// inverted image
#define BImage_Invert (1l<<16)
#ifdef INTERLACE
// fake interlaced image
# define BImage_Interlaced (1l<<17)
#endif // INTERLACE
class BImage {
private:
BImageControl *control;
#ifdef INTERLACE
Bool interlaced;
#endif // INTERLACE
XColor *colors;
BColor *from, *to;
int red_offset, green_offset, blue_offset, ncolors, cpc, cpccpc;
unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table;
unsigned int width, height, *xtable, *ytable;
protected:
Pixmap renderPixmap(void);
XImage *renderXImage(void);
void invert(void);
void bevel1(void);
void bevel2(void);
void dgradient(void);
void egradient(void);
void hgradient(void);
void pgradient(void);
void rgradient(void);
void vgradient(void);
void cdgradient(void);
void pcgradient(void);
public:
BImage(BImageControl *, unsigned int, unsigned int);
~BImage(void);
Pixmap render(BTexture *);
Pixmap render_solid(BTexture *);
Pixmap render_gradient(BTexture *);
};
class BImageControl {
private:
Bool dither;
BaseDisplay *display;
ScreenInfo *screeninfo;
Colormap root_colormap;
Window window;
XColor *colors;
int colors_per_channel, ncolors, screen_number, screen_depth,
bits_per_pixel, red_offset, green_offset, blue_offset;
unsigned char red_color_table[256], green_color_table[256],
blue_color_table[256], red_error_table[256], green_error_table[256],
blue_error_table[256], red_error38_table[256], green_error38_table[256],
blue_error38_table[256];
unsigned long *sqrt_table;
short *red_buffer, *green_buffer, *blue_buffer, *next_red_buffer,
*next_green_buffer, *next_blue_buffer;
unsigned int dither_buffer_width;
typedef struct Cache {
Pixmap pixmap;
unsigned int count, width, height;
unsigned long pixel1, pixel2, texture;
} Cache;
LinkedList<Cache> *cache;
protected:
Pixmap searchCache(unsigned int, unsigned int, unsigned long, BColor *,
BColor *);
public:
BImageControl(BaseDisplay *, ScreenInfo *, Bool = False, int = 4);
~BImageControl(void);
Bool doDither(void) { return dither; }
ScreenInfo *getScreenInfo(void) { return screeninfo; }
Colormap getColormap(void) { return root_colormap; }
BaseDisplay *getDisplay(void) { return display; }
Pixmap renderImage(unsigned int, unsigned int, BTexture *);
Visual *getVisual(void);
Window getDrawable(void) { return window; }
int getBitsPerPixel(void) { return bits_per_pixel; }
int getDepth(void) { return screen_depth; }
int getColorsPerChannel(void) { return colors_per_channel; }
unsigned long getColor(const char *);
unsigned long getColor(const char *, unsigned char *, unsigned char *,
unsigned char *);
unsigned long getSqrt(unsigned int);
void installRootColormap(void);
void removeImage(Pixmap);
void getDitherBuffers(unsigned int,
short **, short **, short **,
short **, short **, short **,
unsigned char **, unsigned char **, unsigned char **,
unsigned char **, unsigned char **, unsigned char **);
void getColorTables(unsigned char **, unsigned char **, unsigned char **,
int *, int *, int *);
void getXColorTable(XColor **, int *);
void setDither(Bool d) { dither = d; }
void setColorsPerChannel(int);
void parseTexture(BTexture *, char *);
void parseColor(BColor *, char * = 0);
};
#endif // __Image_hh
|