aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/TextureRender.cc
diff options
context:
space:
mode:
authormathias <mathias>2006-10-30 19:31:15 (GMT)
committermathias <mathias>2006-10-30 19:31:15 (GMT)
commite5e76e7761f52ba7c0deca75bcecae4fbd3e2ff5 (patch)
treec84838a84802805e9b1463045e86200b7cef917f /src/FbTk/TextureRender.cc
parent426c12c25c2ef095a882619ad7424684b88465b8 (diff)
downloadfluxbox-e5e76e7761f52ba7c0deca75bcecae4fbd3e2ff5.zip
fluxbox-e5e76e7761f52ba7c0deca75bcecae4fbd3e2ff5.tar.bz2
Cosmetic patch from Slava Semushin
Diffstat (limited to 'src/FbTk/TextureRender.cc')
-rw-r--r--src/FbTk/TextureRender.cc105
1 files changed, 55 insertions, 50 deletions
diff --git a/src/FbTk/TextureRender.cc b/src/FbTk/TextureRender.cc
index 7626c3b..e5271dc 100644
--- a/src/FbTk/TextureRender.cc
+++ b/src/FbTk/TextureRender.cc
@@ -39,7 +39,6 @@
39#else 39#else
40 #include <stdio.h> 40 #include <stdio.h>
41#endif 41#endif
42using namespace std;
43 42
44// mipspro has no new(nothrow) 43// mipspro has no new(nothrow)
45#if defined sgi && ! defined GCC 44#if defined sgi && ! defined GCC
@@ -48,10 +47,16 @@ using namespace std;
48#define FB_new_nothrow new(std::nothrow) 47#define FB_new_nothrow new(std::nothrow)
49#endif 48#endif
50 49
50using std::cerr;
51using std::endl;
52using std::string;
53using std::max;
54using std::min;
55
51namespace FbTk { 56namespace FbTk {
52 57
53TextureRender::TextureRender(ImageControl &imgctrl, 58TextureRender::TextureRender(ImageControl &imgctrl,
54 unsigned int w, unsigned int h, 59 unsigned int w, unsigned int h,
55 FbTk::Orientation orient, 60 FbTk::Orientation orient,
56 XColor *_colors, size_t num_colors): 61 XColor *_colors, size_t num_colors):
57 control(imgctrl), 62 control(imgctrl),
@@ -66,7 +71,7 @@ TextureRender::TextureRender(ImageControl &imgctrl,
66 71
67 unsigned int texture_max_width = WidthOfScreen(ScreenOfDisplay(FbTk::App::instance()->display(), imgctrl.screenNumber())) * 2; 72 unsigned int texture_max_width = WidthOfScreen(ScreenOfDisplay(FbTk::App::instance()->display(), imgctrl.screenNumber())) * 2;
68 unsigned int texture_max_height = HeightOfScreen(ScreenOfDisplay(FbTk::App::instance()->display(), imgctrl.screenNumber())) * 2; 73 unsigned int texture_max_height = HeightOfScreen(ScreenOfDisplay(FbTk::App::instance()->display(), imgctrl.screenNumber())) * 2;
69 74
70 _FB_USES_NLS; 75 _FB_USES_NLS;
71 // clamp to "normal" size 76 // clamp to "normal" size
72 if (width > texture_max_width) { 77 if (width > texture_max_width) {
@@ -83,14 +88,14 @@ TextureRender::TextureRender(ImageControl &imgctrl,
83 imgctrl.colorTables(&red_table, &green_table, &blue_table, 88 imgctrl.colorTables(&red_table, &green_table, &blue_table,
84 &red_offset, &green_offset, &blue_offset, 89 &red_offset, &green_offset, &blue_offset,
85 &red_bits, &green_bits, &blue_bits); 90 &red_bits, &green_bits, &blue_bits);
86 91
87} 92}
88 93
89 94
90TextureRender::~TextureRender() { 95TextureRender::~TextureRender() {
91 if (red != 0) delete [] red; 96 if (red != 0) delete [] red;
92 if (green != 0) delete [] green; 97 if (green != 0) delete [] green;
93 if (blue != 0) delete [] blue; 98 if (blue != 0) delete [] blue;
94} 99}
95 100
96 101
@@ -119,8 +124,8 @@ void TextureRender::allocateColorTables() {
119 if (red == 0) { 124 if (red == 0) {
120 char sbuf[128]; 125 char sbuf[128];
121 sprintf(sbuf, "%ld", (long int) size); 126 sprintf(sbuf, "%ld", (long int) size);
122 throw std::string("TextureRender::TextureRender(): " + 127 throw string("TextureRender::TextureRender(): " +
123 std::string(_FBTK_CONSOLETEXT(Error, OutOfMemoryRed, "Out of memory while allocating red buffer.", "")) + string(sbuf)); 128 string(_FBTK_CONSOLETEXT(Error, OutOfMemoryRed, "Out of memory while allocating red buffer.", "")) + string(sbuf));
124 } 129 }
125 130
126 131
@@ -128,16 +133,16 @@ void TextureRender::allocateColorTables() {
128 if (green == 0) { 133 if (green == 0) {
129 char sbuf[128]; 134 char sbuf[128];
130 sprintf(sbuf, "%ld", (long int) size); 135 sprintf(sbuf, "%ld", (long int) size);
131 throw std::string("TextureRender::TextureRender(): " + 136 throw string("TextureRender::TextureRender(): " +
132 std::string(_FBTK_CONSOLETEXT(Error, OutOfMemoryGreen, "Out of memory while allocating green buffer.", ""))+ string(sbuf)); 137 string(_FBTK_CONSOLETEXT(Error, OutOfMemoryGreen, "Out of memory while allocating green buffer.", ""))+ string(sbuf));
133 } 138 }
134 139
135 blue = FB_new_nothrow unsigned char[size]; 140 blue = FB_new_nothrow unsigned char[size];
136 if (blue == 0) { 141 if (blue == 0) {
137 char sbuf[128]; 142 char sbuf[128];
138 sprintf(sbuf, "%ld", (long int) size); 143 sprintf(sbuf, "%ld", (long int) size);
139 throw std::string("TextureRender::TextureRender(): " + 144 throw string("TextureRender::TextureRender(): " +
140 std::string(_FBTK_CONSOLETEXT(Error, OutOfMemoryBlue, "Out of memory while allocating blue buffer.", ""))+ string(sbuf)); 145 string(_FBTK_CONSOLETEXT(Error, OutOfMemoryBlue, "Out of memory while allocating blue buffer.", ""))+ string(sbuf));
141 } 146 }
142 147
143 148
@@ -146,7 +151,7 @@ void TextureRender::allocateColorTables() {
146Pixmap TextureRender::renderSolid(const FbTk::Texture &texture) { 151Pixmap TextureRender::renderSolid(const FbTk::Texture &texture) {
147 152
148 FbPixmap pixmap(RootWindow(FbTk::App::instance()->display(), 153 FbPixmap pixmap(RootWindow(FbTk::App::instance()->display(),
149 control.screenNumber()), 154 control.screenNumber()),
150 width, height, 155 width, height,
151 control.depth()); 156 control.depth());
152 157
@@ -157,7 +162,7 @@ Pixmap TextureRender::renderSolid(const FbTk::Texture &texture) {
157 } 162 }
158 163
159 164
160 FbTk::GContext gc(pixmap), 165 FbTk::GContext gc(pixmap),
161 hgc(pixmap), lgc(pixmap); 166 hgc(pixmap), lgc(pixmap);
162 167
163 gc.setForeground(texture.color()); 168 gc.setForeground(texture.color());
@@ -166,9 +171,9 @@ Pixmap TextureRender::renderSolid(const FbTk::Texture &texture) {
166 hgc.setForeground(texture.hiColor()); 171 hgc.setForeground(texture.hiColor());
167 172
168 pixmap.fillRectangle(gc.gc(), 0, 0, width, height); 173 pixmap.fillRectangle(gc.gc(), 0, 0, width, height);
169 174
170 using namespace FbTk; 175 using namespace FbTk;
171 176
172 if (texture.type() & Texture::INTERLACED) { 177 if (texture.type() & Texture::INTERLACED) {
173 lgc.setForeground(texture.colorTo()); 178 lgc.setForeground(texture.colorTo());
174 register unsigned int i = 0; 179 register unsigned int i = 0;
@@ -181,7 +186,7 @@ Pixmap TextureRender::renderSolid(const FbTk::Texture &texture) {
181 186
182 if (texture.type() & Texture::BEVEL1) { 187 if (texture.type() & Texture::BEVEL1) {
183 if (texture.type() & Texture::RAISED) { 188 if (texture.type() & Texture::RAISED) {
184 pixmap.drawLine(lgc.gc(), 189 pixmap.drawLine(lgc.gc(),
185 0, height - 1, width - 1, height - 1); 190 0, height - 1, width - 1, height - 1);
186 pixmap.drawLine(lgc.gc(), 191 pixmap.drawLine(lgc.gc(),
187 width - 1, height - 1, width - 1, 0); 192 width - 1, height - 1, width - 1, 0);
@@ -244,33 +249,33 @@ Pixmap TextureRender::renderGradient(const FbTk::Texture &texture) {
244 from = &(texture.colorTo()); 249 from = &(texture.colorTo());
245 to = &(texture.color()); 250 to = &(texture.color());
246 251
247 if (! (texture.type() & Texture::INVERT)) 252 if (! (texture.type() & Texture::INVERT))
248 inverted = true; 253 inverted = true;
249 } else { 254 } else {
250 from = &(texture.color()); 255 from = &(texture.color());
251 to = &(texture.colorTo()); 256 to = &(texture.colorTo());
252 257
253 if (texture.type() & Texture::INVERT) 258 if (texture.type() & Texture::INVERT)
254 inverted = true; 259 inverted = true;
255 } 260 }
256 261
257 control.getGradientBuffers(width, height, &xtable, &ytable); 262 control.getGradientBuffers(width, height, &xtable, &ytable);
258 263
259 if (texture.type() & Texture::DIAGONAL) 264 if (texture.type() & Texture::DIAGONAL)
260 dgradient(); 265 dgradient();
261 else if (texture.type() & Texture::ELLIPTIC) 266 else if (texture.type() & Texture::ELLIPTIC)
262 egradient(); 267 egradient();
263 else if (texture.type() & Texture::HORIZONTAL) 268 else if (texture.type() & Texture::HORIZONTAL)
264 hgradient(); 269 hgradient();
265 else if (texture.type() & Texture::PYRAMID) 270 else if (texture.type() & Texture::PYRAMID)
266 pgradient(); 271 pgradient();
267 else if (texture.type() & Texture::RECTANGLE) 272 else if (texture.type() & Texture::RECTANGLE)
268 rgradient(); 273 rgradient();
269 else if (texture.type() & Texture::VERTICAL) 274 else if (texture.type() & Texture::VERTICAL)
270 vgradient(); 275 vgradient();
271 else if (texture.type() & Texture::CROSSDIAGONAL) 276 else if (texture.type() & Texture::CROSSDIAGONAL)
272 cdgradient(); 277 cdgradient();
273 else if (texture.type() & Texture::PIPECROSS) 278 else if (texture.type() & Texture::PIPECROSS)
274 pcgradient(); 279 pcgradient();
275 280
276 if (texture.type() & Texture::BEVEL1) 281 if (texture.type() & Texture::BEVEL1)
@@ -293,10 +298,10 @@ Pixmap TextureRender::renderPixmap(const FbTk::Texture &src_texture) {
293 if (tmpw != src_texture.pixmap().width() || 298 if (tmpw != src_texture.pixmap().width() ||
294 tmph != src_texture.pixmap().height()) { 299 tmph != src_texture.pixmap().height()) {
295 300
296 // copy src_texture's pixmap and 301 // copy src_texture's pixmap and
297 // scale/tile to fit our size 302 // scale/tile to fit our size
298 FbPixmap new_pm(src_texture.pixmap()); 303 FbPixmap new_pm(src_texture.pixmap());
299 304
300 if ((src_texture.type() & Texture::TILED)) { 305 if ((src_texture.type() & Texture::TILED)) {
301 new_pm.tile(tmpw,tmph); 306 new_pm.tile(tmpw,tmph);
302 } else { 307 } else {
@@ -336,14 +341,14 @@ XImage *TextureRender::renderXImage() {
336 o = image->bits_per_pixel + ((image->byte_order == MSBFirst) ? 1 : 0); 341 o = image->bits_per_pixel + ((image->byte_order == MSBFirst) ? 1 : 0);
337 342
338 if (control.doDither()) { 343 if (control.doDither()) {
339 unsigned char dither4[4][4] = { 344 unsigned char dither4[4][4] = {
340 {0, 4, 1, 5}, 345 {0, 4, 1, 5},
341 {6, 2, 7, 3}, 346 {6, 2, 7, 3},
342 {1, 5, 0, 4}, 347 {1, 5, 0, 4},
343 {7, 3, 6, 2} }; 348 {7, 3, 6, 2} };
344 349
345#ifdef ORDEREDPSEUDO 350#ifdef ORDEREDPSEUDO
346 unsigned char dither8[8][8] = { 351 unsigned char dither8[8][8] = {
347 { 0, 32, 8, 40, 2, 34, 10, 42 }, 352 { 0, 32, 8, 40, 2, 34, 10, 42 },
348 { 48, 16, 56, 24, 50, 18, 58, 26 }, 353 { 48, 16, 56, 24, 50, 18, 58, 26 },
349 { 12, 44, 4, 36, 14, 46, 6, 38 }, 354 { 12, 44, 4, 36, 14, 46, 6, 38 },
@@ -711,7 +716,7 @@ return image;
711 716
712Pixmap TextureRender::renderPixmap() { 717Pixmap TextureRender::renderPixmap() {
713 Display *disp = FbTk::App::instance()->display(); 718 Display *disp = FbTk::App::instance()->display();
714 FbPixmap pixmap(RootWindow(disp, control.screenNumber()), 719 FbPixmap pixmap(RootWindow(disp, control.screenNumber()),
715 width, height, control.depth()); 720 width, height, control.depth());
716 721
717 if (pixmap.drawable() == None) { 722 if (pixmap.drawable() == None) {
@@ -1441,9 +1446,9 @@ void TextureRender::rgradient() {
1441 // normal rgradient 1446 // normal rgradient
1442 for (yt = ytable, y = 0; y < height; y++, yt += 3) { 1447 for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1443 for (xt = xtable, x = 0; x < width; x++) { 1448 for (xt = xtable, x = 0; x < width; x++) {
1444 *(pr++) = (unsigned char) (tr - (rsign * std::max(*(xt++), *(yt)))); 1449 *(pr++) = (unsigned char) (tr - (rsign * max(*(xt++), *(yt))));
1445 *(pg++) = (unsigned char) (tg - (gsign * std::max(*(xt++), *(yt + 1)))); 1450 *(pg++) = (unsigned char) (tg - (gsign * max(*(xt++), *(yt + 1))));
1446 *(pb++) = (unsigned char) (tb - (bsign * std::max(*(xt++), *(yt + 2)))); 1451 *(pb++) = (unsigned char) (tb - (bsign * max(*(xt++), *(yt + 2))));
1447 } 1452 }
1448 } 1453 }
1449 1454
@@ -1454,32 +1459,32 @@ void TextureRender::rgradient() {
1454 for (yt = ytable, y = 0; y < height; y++, yt += 3) { 1459 for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1455 for (xt = xtable, x = 0; x < width; x++) { 1460 for (xt = xtable, x = 0; x < width; x++) {
1456 if (y & 1) { 1461 if (y & 1) {
1457 channel = (unsigned char) (tr - (rsign * std::max(*(xt++), *(yt)))); 1462 channel = (unsigned char) (tr - (rsign * max(*(xt++), *(yt))));
1458 channel2 = (channel >> 1) + (channel >> 2); 1463 channel2 = (channel >> 1) + (channel >> 2);
1459 if (channel2 > channel) channel2 = 0; 1464 if (channel2 > channel) channel2 = 0;
1460 *(pr++) = channel2; 1465 *(pr++) = channel2;
1461 1466
1462 channel = (unsigned char) (tg - (gsign * std::max(*(xt++), *(yt + 1)))); 1467 channel = (unsigned char) (tg - (gsign * max(*(xt++), *(yt + 1))));
1463 channel2 = (channel >> 1) + (channel >> 2); 1468 channel2 = (channel >> 1) + (channel >> 2);
1464 if (channel2 > channel) channel2 = 0; 1469 if (channel2 > channel) channel2 = 0;
1465 *(pg++) = channel2; 1470 *(pg++) = channel2;
1466 1471
1467 channel = (unsigned char) (tb - (bsign * std::max(*(xt++), *(yt + 2)))); 1472 channel = (unsigned char) (tb - (bsign * max(*(xt++), *(yt + 2))));
1468 channel2 = (channel >> 1) + (channel >> 2); 1473 channel2 = (channel >> 1) + (channel >> 2);
1469 if (channel2 > channel) channel2 = 0; 1474 if (channel2 > channel) channel2 = 0;
1470 *(pb++) = channel2; 1475 *(pb++) = channel2;
1471 } else { 1476 } else {
1472 channel = (unsigned char) (tr - (rsign * std::max(*(xt++), *(yt)))); 1477 channel = (unsigned char) (tr - (rsign * max(*(xt++), *(yt))));
1473 channel2 = channel + (channel >> 3); 1478 channel2 = channel + (channel >> 3);
1474 if (channel2 < channel) channel2 = ~0; 1479 if (channel2 < channel) channel2 = ~0;
1475 *(pr++) = channel2; 1480 *(pr++) = channel2;
1476 1481
1477 channel = (unsigned char) (tg - (gsign * std::max(*(xt++), *(yt + 1)))); 1482 channel = (unsigned char) (tg - (gsign * max(*(xt++), *(yt + 1))));
1478 channel2 = channel + (channel >> 3); 1483 channel2 = channel + (channel >> 3);
1479 if (channel2 < channel) channel2 = ~0; 1484 if (channel2 < channel) channel2 = ~0;
1480 *(pg++) = channel2; 1485 *(pg++) = channel2;
1481 1486
1482 channel = (unsigned char) (tb - (bsign * std::max(*(xt++), *(yt + 2)))); 1487 channel = (unsigned char) (tb - (bsign * max(*(xt++), *(yt + 2))));
1483 channel2 = channel + (channel >> 3); 1488 channel2 = channel + (channel >> 3);
1484 if (channel2 < channel) channel2 = ~0; 1489 if (channel2 < channel) channel2 = ~0;
1485 *(pb++) = channel2; 1490 *(pb++) = channel2;
@@ -1675,9 +1680,9 @@ void TextureRender::pcgradient() {
1675 // normal pcgradient 1680 // normal pcgradient
1676 for (yt = ytable, y = 0; y < height; y++, yt += 3) { 1681 for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1677 for (xt = xtable, x = 0; x < width; x++) { 1682 for (xt = xtable, x = 0; x < width; x++) {
1678 *(pr++) = (unsigned char) (tr - (rsign * std::min(*(xt++), *(yt)))); 1683 *(pr++) = (unsigned char) (tr - (rsign * min(*(xt++), *(yt))));
1679 *(pg++) = (unsigned char) (tg - (gsign * std::min(*(xt++), *(yt + 1)))); 1684 *(pg++) = (unsigned char) (tg - (gsign * min(*(xt++), *(yt + 1))));
1680 *(pb++) = (unsigned char) (tb - (bsign * std::min(*(xt++), *(yt + 2)))); 1685 *(pb++) = (unsigned char) (tb - (bsign * min(*(xt++), *(yt + 2))));
1681 } 1686 }
1682 } 1687 }
1683 1688
@@ -1688,32 +1693,32 @@ void TextureRender::pcgradient() {
1688 for (yt = ytable, y = 0; y < height; y++, yt += 3) { 1693 for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1689 for (xt = xtable, x = 0; x < width; x++) { 1694 for (xt = xtable, x = 0; x < width; x++) {
1690 if (y & 1) { 1695 if (y & 1) {
1691 channel = (unsigned char) (tr - (rsign * std::min(*(xt++), *(yt)))); 1696 channel = (unsigned char) (tr - (rsign * min(*(xt++), *(yt))));
1692 channel2 = (channel >> 1) + (channel >> 2); 1697 channel2 = (channel >> 1) + (channel >> 2);
1693 if (channel2 > channel) channel2 = 0; 1698 if (channel2 > channel) channel2 = 0;
1694 *(pr++) = channel2; 1699 *(pr++) = channel2;
1695 1700
1696 channel = (unsigned char) (tg - (bsign * std::min(*(xt++), *(yt + 1)))); 1701 channel = (unsigned char) (tg - (bsign * min(*(xt++), *(yt + 1))));
1697 channel2 = (channel >> 1) + (channel >> 2); 1702 channel2 = (channel >> 1) + (channel >> 2);
1698 if (channel2 > channel) channel2 = 0; 1703 if (channel2 > channel) channel2 = 0;
1699 *(pg++) = channel2; 1704 *(pg++) = channel2;
1700 1705
1701 channel = (unsigned char) (tb - (gsign * std::min(*(xt++), *(yt + 2)))); 1706 channel = (unsigned char) (tb - (gsign * min(*(xt++), *(yt + 2))));
1702 channel2 = (channel >> 1) + (channel >> 2); 1707 channel2 = (channel >> 1) + (channel >> 2);
1703 if (channel2 > channel) channel2 = 0; 1708 if (channel2 > channel) channel2 = 0;
1704 *(pb++) = channel2; 1709 *(pb++) = channel2;
1705 } else { 1710 } else {
1706 channel = (unsigned char) (tr - (rsign * std::min(*(xt++), *(yt)))); 1711 channel = (unsigned char) (tr - (rsign * min(*(xt++), *(yt))));
1707 channel2 = channel + (channel >> 3); 1712 channel2 = channel + (channel >> 3);
1708 if (channel2 < channel) channel2 = ~0; 1713 if (channel2 < channel) channel2 = ~0;
1709 *(pr++) = channel2; 1714 *(pr++) = channel2;
1710 1715
1711 channel = (unsigned char) (tg - (gsign * std::min(*(xt++), *(yt + 1)))); 1716 channel = (unsigned char) (tg - (gsign * min(*(xt++), *(yt + 1))));
1712 channel2 = channel + (channel >> 3); 1717 channel2 = channel + (channel >> 3);
1713 if (channel2 < channel) channel2 = ~0; 1718 if (channel2 < channel) channel2 = ~0;
1714 *(pg++) = channel2; 1719 *(pg++) = channel2;
1715 1720
1716 channel = (unsigned char) (tb - (bsign * std::min(*(xt++), *(yt + 2)))); 1721 channel = (unsigned char) (tb - (bsign * min(*(xt++), *(yt + 2))));
1717 channel2 = channel + (channel >> 3); 1722 channel2 = channel + (channel >> 3);
1718 if (channel2 < channel) channel2 = ~0; 1723 if (channel2 < channel) channel2 = ~0;
1719 *(pb++) = channel2; 1724 *(pb++) = channel2;