aboutsummaryrefslogtreecommitdiff
path: root/src/Image.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-07-23 17:11:59 (GMT)
committerfluxgen <fluxgen>2002-07-23 17:11:59 (GMT)
commit35c55cdc8dc0771a07c2276d3190782b89d8a715 (patch)
tree4d0ccaaaf6165453bfe46af0bcc20ed82846041b /src/Image.cc
parent8b560ddf76a0b0256a1c2ffd0cb97d91153e8192 (diff)
downloadfluxbox_pavel-35c55cdc8dc0771a07c2276d3190782b89d8a715.zip
fluxbox_pavel-35c55cdc8dc0771a07c2276d3190782b89d8a715.tar.bz2
moved Texture and Color into new files, fixed some const and pointers
Diffstat (limited to 'src/Image.cc')
-rw-r--r--src/Image.cc198
1 files changed, 113 insertions, 85 deletions
diff --git a/src/Image.cc b/src/Image.cc
index 9db3ee3..4052c10 100644
--- a/src/Image.cc
+++ b/src/Image.cc
@@ -22,10 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// stupid macros needed to access some functions in version 2 of the GNU C 25// $Id: Image.cc,v 1.12 2002/07/23 17:11:58 fluxgen Exp $
26// library
27
28// $Id: Image.cc,v 1.11 2002/07/22 22:33:45 fluxgen Exp $
29 26
30//use GNU extensions 27//use GNU extensions
31#ifndef _GNU_SOURCE 28#ifndef _GNU_SOURCE
@@ -69,9 +66,16 @@ typedef unsigned int u_int32_t;
69# include <ctype.h> 66# include <ctype.h>
70#endif // HAVE_CTYPE_H 67#endif // HAVE_CTYPE_H
71 68
69#include <iostream>
70
71using namespace std;
72
73// lookup table for texture
72unsigned long *BImageControl::sqrt_table = 0; 74unsigned long *BImageControl::sqrt_table = 0;
73 75
74static unsigned long bsqrt(unsigned long x) { 76namespace { // anonymous
77
78unsigned long bsqrt(unsigned long x) {
75 if (x <= 0) return 0; 79 if (x <= 0) return 0;
76 if (x == 1) return 1; 80 if (x == 1) return 1;
77 81
@@ -85,6 +89,7 @@ static unsigned long bsqrt(unsigned long x) {
85 } 89 }
86} 90}
87 91
92};
88 93
89BImage::BImage(BImageControl *c, unsigned int w, unsigned int h) { 94BImage::BImage(BImageControl *c, unsigned int w, unsigned int h) {
90 control = c; 95 control = c;
@@ -117,19 +122,20 @@ BImage::~BImage(void) {
117} 122}
118 123
119 124
120Pixmap BImage::render(BTexture *texture) { 125Pixmap BImage::render(const FbTk::Texture *texture) {
121 if (texture->getTexture() & BImage::PARENTRELATIVE) 126 using namespace FbTk;
127 if (texture->type() & Texture::PARENTRELATIVE)
122 return ParentRelative; 128 return ParentRelative;
123 else if (texture->getTexture() & BImage::SOLID) 129 else if (texture->type() & Texture::SOLID)
124 return render_solid(texture); 130 return renderSolid(texture);
125 else if (texture->getTexture() & BImage::GRADIENT) 131 else if (texture->type() & Texture::GRADIENT)
126 return render_gradient(texture); 132 return renderGradient(texture);
127 133
128 return None; 134 return None;
129} 135}
130 136
131 137
132Pixmap BImage::render_solid(BTexture *texture) { 138Pixmap BImage::renderSolid(const FbTk::Texture *texture) {
133 Pixmap pixmap = XCreatePixmap(control->baseDisplay()->getXDisplay(), 139 Pixmap pixmap = XCreatePixmap(control->baseDisplay()->getXDisplay(),
134 control->drawable(), width, 140 control->drawable(), width,
135 height, control->depth()); 141 height, control->depth());
@@ -160,8 +166,9 @@ Pixmap BImage::render_solid(BTexture *texture) {
160 XFillRectangle(control->baseDisplay()->getXDisplay(), pixmap, gc, 0, 0, 166 XFillRectangle(control->baseDisplay()->getXDisplay(), pixmap, gc, 0, 0,
161 width, height); 167 width, height);
162 168
163#ifdef INTERLACE 169 using namespace FbTk;
164 if (texture->getTexture() & BImage::INTERLACED) { 170#ifdef INTERLACE
171 if (texture->type() & Texture::INTERLACED) {
165 gcv.foreground = texture->colorTo().pixel(); 172 gcv.foreground = texture->colorTo().pixel();
166 GC igc = XCreateGC(control->baseDisplay()->getXDisplay(), pixmap, 173 GC igc = XCreateGC(control->baseDisplay()->getXDisplay(), pixmap,
167 GCForeground, &gcv); 174 GCForeground, &gcv);
@@ -176,8 +183,8 @@ Pixmap BImage::render_solid(BTexture *texture) {
176#endif // INTERLACE 183#endif // INTERLACE
177 184
178 185
179 if (texture->getTexture() & BImage::BEVEL1) { 186 if (texture->type() & Texture::BEVEL1) {
180 if (texture->getTexture() & BImage::RAISED) { 187 if (texture->type() & Texture::RAISED) {
181 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, lgc, 188 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, lgc,
182 0, height - 1, width - 1, height - 1); 189 0, height - 1, width - 1, height - 1);
183 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, lgc, 190 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, lgc,
@@ -187,7 +194,7 @@ Pixmap BImage::render_solid(BTexture *texture) {
187 0, 0, width - 1, 0); 194 0, 0, width - 1, 0);
188 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc, 195 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc,
189 0, height - 1, 0, 0); 196 0, height - 1, 0, 0);
190 } else if (texture->getTexture() & BImage::SUNKEN) { 197 } else if (texture->type() & Texture::SUNKEN) {
191 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc, 198 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc,
192 0, height - 1, width - 1, height - 1); 199 0, height - 1, width - 1, height - 1);
193 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc, 200 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc,
@@ -198,8 +205,8 @@ Pixmap BImage::render_solid(BTexture *texture) {
198 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, lgc, 205 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, lgc,
199 0, height - 1, 0, 0); 206 0, height - 1, 0, 0);
200 } 207 }
201 } else if (texture->getTexture() & BImage::BEVEL2) { 208 } else if (texture->type() & Texture::BEVEL2) {
202 if (texture->getTexture() & BImage::RAISED) { 209 if (texture->type() & Texture::RAISED) {
203 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, lgc, 210 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, lgc,
204 1, height - 3, width - 3, height - 3); 211 1, height - 3, width - 3, height - 3);
205 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, lgc, 212 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, lgc,
@@ -209,7 +216,7 @@ Pixmap BImage::render_solid(BTexture *texture) {
209 1, 1, width - 3, 1); 216 1, 1, width - 3, 1);
210 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc, 217 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc,
211 1, height - 3, 1, 1); 218 1, height - 3, 1, 1);
212 } else if (texture->getTexture() & BImage::SUNKEN) { 219 } else if (texture->type() & Texture::SUNKEN) {
213 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc, 220 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc,
214 1, height - 3, width - 3, height - 3); 221 1, height - 3, width - 3, height - 3);
215 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc, 222 XDrawLine(control->baseDisplay()->getXDisplay(), pixmap, hgc,
@@ -230,38 +237,53 @@ Pixmap BImage::render_solid(BTexture *texture) {
230} 237}
231 238
232 239
233Pixmap BImage::render_gradient(BTexture *texture) { 240Pixmap BImage::renderGradient(const FbTk::Texture *texture) {
234 int inverted = 0;
235 241
236#ifdef INTERLACE 242 bool inverted = false;
237 interlaced = texture->getTexture() & BImage::INTERLACED; 243
244 using namespace FbTk;
245
246#ifdef INTERLACE
247 interlaced = texture->type() & Texture::INTERLACED;
238#endif // INTERLACE 248#endif // INTERLACE
239 249
240 if (texture->getTexture() & BImage::SUNKEN) { 250 if (texture->type() & Texture::SUNKEN) {
241 from = &(texture->colorTo()); 251 from = &(texture->colorTo());
242 to = &(texture->color()); 252 to = &(texture->color());
243 253
244 if (! (texture->getTexture() & BImage::INVERT)) inverted = 1; 254 if (! (texture->type() & Texture::INVERT))
255 inverted = true;
245 } else { 256 } else {
246 from = &(texture->color()); 257 from = &(texture->color());
247 to = &(texture->colorTo()); 258 to = &(texture->colorTo());
248 259
249 if (texture->getTexture() & BImage::INVERT) inverted = 1; 260 if (texture->type() & Texture::INVERT)
261 inverted = true;
250 } 262 }
251 263
252 control->getGradientBuffers(width, height, &xtable, &ytable); 264 control->getGradientBuffers(width, height, &xtable, &ytable);
253 265
254 if (texture->getTexture() & BImage::DIAGONAL) dgradient(); 266 if (texture->type() & Texture::DIAGONAL)
255 else if (texture->getTexture() & BImage::ELLIPTIC) egradient(); 267 dgradient();
256 else if (texture->getTexture() & BImage::HORIZONTAL) hgradient(); 268 else if (texture->type() & Texture::ELLIPTIC)
257 else if (texture->getTexture() & BImage::PYRAMID) pgradient(); 269 egradient();
258 else if (texture->getTexture() & BImage::RECTANGLE) rgradient(); 270 else if (texture->type() & Texture::HORIZONTAL)
259 else if (texture->getTexture() & BImage::VERTICAL) vgradient(); 271 hgradient();
260 else if (texture->getTexture() & BImage::CROSSDIAGONAL) cdgradient(); 272 else if (texture->type() & Texture::PYRAMID)
261 else if (texture->getTexture() & BImage::PIPECROSS) pcgradient(); 273 pgradient();
262 274 else if (texture->type() & Texture::RECTANGLE)
263 if (texture->getTexture() & BImage::BEVEL1) bevel1(); 275 rgradient();
264 else if (texture->getTexture() & BImage::BEVEL2) bevel2(); 276 else if (texture->type() & Texture::VERTICAL)
277 vgradient();
278 else if (texture->type() & Texture::CROSSDIAGONAL)
279 cdgradient();
280 else if (texture->type() & Texture::PIPECROSS)
281 pcgradient();
282
283 if (texture->type() & Texture::BEVEL1)
284 bevel1();
285 else if (texture->type() & Texture::BEVEL2)
286 bevel2();
265 287
266 if (inverted) 288 if (inverted)
267 invert(); 289 invert();
@@ -2163,9 +2185,8 @@ BImageControl::~BImageControl(void) {
2163 if (colors) { 2185 if (colors) {
2164 unsigned long *pixels = new unsigned long [ncolors]; 2186 unsigned long *pixels = new unsigned long [ncolors];
2165 2187
2166 int i; 2188 for (int color = 0; color < ncolors; color++)
2167 for (i = 0; i < ncolors; i++) 2189 *(pixels + color) = (*(colors + color)).pixel;
2168 *(pixels + i) = (*(colors + i)).pixel;
2169 2190
2170 XFreeColors(basedisplay->getXDisplay(), colormap(), pixels, ncolors, 0); 2191 XFreeColors(basedisplay->getXDisplay(), colormap(), pixels, ncolors, 0);
2171 2192
@@ -2192,17 +2213,17 @@ BImageControl::~BImageControl(void) {
2192 2213
2193 2214
2194Pixmap BImageControl::searchCache(unsigned int width, unsigned int height, 2215Pixmap BImageControl::searchCache(unsigned int width, unsigned int height,
2195 unsigned long texture, 2216 unsigned long texture_type,
2196 BColor *c1, BColor *c2) { 2217 const FbTk::Color &color, const FbTk::Color &color_to) {
2197 CacheList::iterator it = cache.begin(); 2218 CacheList::iterator it = cache.begin();
2198 CacheList::iterator it_end = cache.end(); 2219 CacheList::iterator it_end = cache.end();
2199 for (; it != it_end; ++it) { 2220 for (; it != it_end; ++it) {
2200 if (((*it)->width == width) && 2221 if (((*it)->width == width) &&
2201 ((*it)->height == height) && 2222 ((*it)->height == height) &&
2202 ((*it)->texture == texture) && 2223 ((*it)->texture == texture_type) &&
2203 ((*it)->pixel1 == c1->pixel())) { 2224 ((*it)->pixel1 == color.pixel())) {
2204 if (texture & BImage::GRADIENT) { 2225 if (texture_type & FbTk::Texture::GRADIENT) {
2205 if ((*it)->pixel2 == c2->pixel()) { 2226 if ((*it)->pixel2 == color_to.pixel()) {
2206 (*it)->count++; 2227 (*it)->count++;
2207 return (*it)->pixmap; 2228 return (*it)->pixmap;
2208 } 2229 }
@@ -2218,11 +2239,12 @@ Pixmap BImageControl::searchCache(unsigned int width, unsigned int height,
2218 2239
2219 2240
2220Pixmap BImageControl::renderImage(unsigned int width, unsigned int height, 2241Pixmap BImageControl::renderImage(unsigned int width, unsigned int height,
2221 BTexture *texture) { 2242 const FbTk::Texture *texture) {
2222 if (texture->getTexture() & BImage::PARENTRELATIVE) return ParentRelative; 2243 if (texture->type() & FbTk::Texture::PARENTRELATIVE)
2244 return ParentRelative;
2223 2245
2224 Pixmap pixmap = searchCache(width, height, texture->getTexture(), 2246 Pixmap pixmap = searchCache(width, height, texture->type(),
2225 &texture->color(), &texture->colorTo()); 2247 texture->color(), texture->colorTo());
2226 if (pixmap) return pixmap; 2248 if (pixmap) return pixmap;
2227 2249
2228 BImage image(this, width, height); 2250 BImage image(this, width, height);
@@ -2235,10 +2257,10 @@ Pixmap BImageControl::renderImage(unsigned int width, unsigned int height,
2235 tmp->width = width; 2257 tmp->width = width;
2236 tmp->height = height; 2258 tmp->height = height;
2237 tmp->count = 1; 2259 tmp->count = 1;
2238 tmp->texture = texture->getTexture(); 2260 tmp->texture = texture->type();
2239 tmp->pixel1 = texture->color().pixel(); 2261 tmp->pixel1 = texture->color().pixel();
2240 2262
2241 if (texture->getTexture() & BImage::GRADIENT) 2263 if (texture->type() & FbTk::Texture::GRADIENT)
2242 tmp->pixel2 = texture->colorTo().pixel(); 2264 tmp->pixel2 = texture->colorTo().pixel();
2243 else 2265 else
2244 tmp->pixel2 = 0l; 2266 tmp->pixel2 = 0l;
@@ -2431,65 +2453,71 @@ unsigned long BImageControl::getSqrt(unsigned int x) {
2431} 2453}
2432 2454
2433 2455
2434void BImageControl::parseTexture(BTexture *texture, char *t) { 2456void BImageControl::parseTexture(FbTk::Texture *texture, const char *texture_string) {
2435 if ((! texture) || (! t)) return; 2457 if ((! texture) || (! texture_string))
2458 return;
2436 2459
2437 int t_len = strlen(t) + 1, i; 2460 int t_len = strlen(texture_string) + 1;
2438 char *ts = new char[t_len]; 2461 char *ts = new char[t_len];
2439 if (! ts) return; 2462 if (! ts) return;
2440 2463
2441 // convert to lower case 2464 // convert to lower case
2442 for (i = 0; i < t_len; i++) 2465 for (int byte_pos = 0; byte_pos < t_len; byte_pos++)
2443 *(ts + i) = tolower(*(t + i)); 2466 *(ts + byte_pos) = tolower(*(texture_string + byte_pos));
2467
2468 using namespace FbTk;
2469#ifdef DEBUG
2470 cerr<<__FILE__<<"("<<__LINE__<<"): texture_string = "<<texture_string<<endl;
2471#endif // DEBUG
2444 2472
2445 if (strstr(ts, "parentrelative")) { 2473 if (strstr(ts, "parentrelative")) {
2446 texture->setTexture(BImage::PARENTRELATIVE); 2474 texture->setType(Texture::PARENTRELATIVE);
2447 } else { 2475 } else {
2448 texture->setTexture(0); 2476 texture->setType(Texture::NONE);
2449 2477
2450 if (strstr(ts, "solid")) 2478 if (strstr(ts, "solid"))
2451 texture->addTexture(BImage::SOLID); 2479 texture->addType(Texture::SOLID);
2452 else if (strstr(ts, "gradient")) { 2480 else if (strstr(ts, "gradient")) {
2453 texture->addTexture(BImage::GRADIENT); 2481 texture->addType(Texture::GRADIENT);
2454 if (strstr(ts, "crossdiagonal")) 2482 if (strstr(ts, "crossdiagonal"))
2455 texture->addTexture(BImage::CROSSDIAGONAL); 2483 texture->addType(Texture::CROSSDIAGONAL);
2456 else if (strstr(ts, "rectangle")) 2484 else if (strstr(ts, "rectangle"))
2457 texture->addTexture(BImage::RECTANGLE); 2485 texture->addType(Texture::RECTANGLE);
2458 else if (strstr(ts, "pyramid")) 2486 else if (strstr(ts, "pyramid"))
2459 texture->addTexture(BImage::PYRAMID); 2487 texture->addType(Texture::PYRAMID);
2460 else if (strstr(ts, "pipecross")) 2488 else if (strstr(ts, "pipecross"))
2461 texture->addTexture(BImage::PIPECROSS); 2489 texture->addType(Texture::PIPECROSS);
2462 else if (strstr(ts, "elliptic")) 2490 else if (strstr(ts, "elliptic"))
2463 texture->addTexture(BImage::ELLIPTIC); 2491 texture->addType(Texture::ELLIPTIC);
2464 else if (strstr(ts, "diagonal")) 2492 else if (strstr(ts, "diagonal"))
2465 texture->addTexture(BImage::DIAGONAL); 2493 texture->addType(Texture::DIAGONAL);
2466 else if (strstr(ts, "horizontal")) 2494 else if (strstr(ts, "horizontal"))
2467 texture->addTexture(BImage::HORIZONTAL); 2495 texture->addType(Texture::HORIZONTAL);
2468 else if (strstr(ts, "vertical")) 2496 else if (strstr(ts, "vertical"))
2469 texture->addTexture(BImage::VERTICAL); 2497 texture->addType(Texture::VERTICAL);
2470 else 2498 else
2471 texture->addTexture(BImage::DIAGONAL); 2499 texture->addType(Texture::DIAGONAL);
2472 } else 2500 } else
2473 texture->addTexture(BImage::SOLID); 2501 texture->addType(Texture::SOLID);
2474 2502
2475 if (strstr(ts, "raised")) 2503 if (strstr(ts, "raised"))
2476 texture->addTexture(BImage::RAISED); 2504 texture->addType(Texture::RAISED);
2477 else if (strstr(ts, "sunken")) 2505 else if (strstr(ts, "sunken"))
2478 texture->addTexture(BImage::SUNKEN); 2506 texture->addType(Texture::SUNKEN);
2479 else if (strstr(ts, "flat")) 2507 else if (strstr(ts, "flat"))
2480 texture->addTexture(BImage::FLAT); 2508 texture->addType(Texture::FLAT);
2481 else 2509 else
2482 texture->addTexture(BImage::RAISED); 2510 texture->addType(Texture::RAISED);
2483 2511
2484 if (! (texture->getTexture() & BImage::FLAT)) 2512 if (! (texture->type() & Texture::FLAT))
2485 if (strstr(ts, "bevel2")) 2513 if (strstr(ts, "bevel2"))
2486 texture->addTexture(BImage::BEVEL2); 2514 texture->addType(Texture::BEVEL2);
2487 else 2515 else
2488 texture->addTexture(BImage::BEVEL1); 2516 texture->addType(Texture::BEVEL1);
2489 2517
2490#ifdef INTERLACE 2518#ifdef INTERLACE
2491 if (strstr(ts, "interlaced")) 2519 if (strstr(ts, "interlaced"))
2492 texture->addTexture(BImage::INTERLACED); 2520 texture->addType(Texture::INTERLACED);
2493#endif // INTERLACE 2521#endif // INTERLACE
2494 } 2522 }
2495 2523
@@ -2497,7 +2525,7 @@ void BImageControl::parseTexture(BTexture *texture, char *t) {
2497} 2525}
2498 2526
2499 2527
2500void BImageControl::parseColor(BColor *col, char *c) { 2528void BImageControl::parseColor(FbTk::Color *col, const char *color_string) {
2501 if (!col) return; 2529 if (!col) return;
2502 2530
2503 if (col->isAllocated()) { 2531 if (col->isAllocated()) {
@@ -2507,13 +2535,13 @@ void BImageControl::parseColor(BColor *col, char *c) {
2507 2535
2508 col->setPixel(0l); 2536 col->setPixel(0l);
2509 col->setRGB(0, 0, 0); 2537 col->setRGB(0, 0, 0);
2510 col->setAllocated(False); 2538 col->setAllocated(false);
2511 } 2539 }
2512 2540
2513 if (c) { 2541 if (color_string != 0) {
2514 unsigned char r, g, b; 2542 unsigned char r, g, b;
2515 2543
2516 col->setPixel(color(c, &r, &g, &b)); 2544 col->setPixel(color(color_string, &r, &g, &b));
2517 col->setRGB(r, g, b); 2545 col->setRGB(r, g, b);
2518 col->setAllocated(true); 2546 col->setAllocated(true);
2519 } 2547 }