aboutsummaryrefslogtreecommitdiff
path: root/src/TextureRender.cc
diff options
context:
space:
mode:
authorrathnor <rathnor>2002-12-01 13:42:15 (GMT)
committerrathnor <rathnor>2002-12-01 13:42:15 (GMT)
commit28b5c604490094e187494dcc566bd3d7a05a2c25 (patch)
tree8f78f5714a5cd055c10b067a2656fe7b2338e71a /src/TextureRender.cc
parentb9134162f9633784d9097df18769a699a62650fe (diff)
downloadfluxbox-28b5c604490094e187494dcc566bd3d7a05a2c25.zip
fluxbox-28b5c604490094e187494dcc566bd3d7a05a2c25.tar.bz2
Indenting from tabs to emacs 4-space
Diffstat (limited to 'src/TextureRender.cc')
-rw-r--r--src/TextureRender.cc3046
1 files changed, 1523 insertions, 1523 deletions
diff --git a/src/TextureRender.cc b/src/TextureRender.cc
index b118eff..4a3b91e 100644
--- a/src/TextureRender.cc
+++ b/src/TextureRender.cc
@@ -22,7 +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// $Id: TextureRender.cc,v 1.2 2002/11/30 20:36:22 fluxgen Exp $ 25// $Id: TextureRender.cc,v 1.3 2002/12/01 13:42:00 rathnor Exp $
26 26
27#include "TextureRender.hh" 27#include "TextureRender.hh"
28 28
@@ -31,1724 +31,1724 @@
31#include "App.hh" 31#include "App.hh"
32 32
33TextureRender::TextureRender(BImageControl &imgctrl, unsigned int w, unsigned int h, 33TextureRender::TextureRender(BImageControl &imgctrl, unsigned int w, unsigned int h,
34 XColor *_colors, size_t num_colors): 34 XColor *_colors, size_t num_colors):
35control(imgctrl), 35 control(imgctrl),
36colors(_colors), 36 colors(_colors),
37ncolors(ncolors), 37 ncolors(ncolors),
38xtable(0), ytable(0) { 38 xtable(0), ytable(0) {
39 39
40 width = ((signed) w > 0) ? w : 1; 40 width = ((signed) w > 0) ? w : 1;
41 height = ((signed) h > 0) ? h : 1; 41 height = ((signed) h > 0) ? h : 1;
42 42
43 red = new unsigned char[width * height]; 43 red = new unsigned char[width * height];
44 green = new unsigned char[width * height]; 44 green = new unsigned char[width * height];
45 blue = new unsigned char[width * height]; 45 blue = new unsigned char[width * height];
46 46
47 cpc = imgctrl.colorsPerChannel(); 47 cpc = imgctrl.colorsPerChannel();
48 cpccpc = cpc * cpc; 48 cpccpc = cpc * cpc;
49 49
50 imgctrl.colorTables(&red_table, &green_table, &blue_table, 50 imgctrl.colorTables(&red_table, &green_table, &blue_table,
51 &red_offset, &green_offset, &blue_offset, 51 &red_offset, &green_offset, &blue_offset,
52 &red_bits, &green_bits, &blue_bits); 52 &red_bits, &green_bits, &blue_bits);
53 53
54} 54}
55 55
56 56
57TextureRender::~TextureRender() { 57TextureRender::~TextureRender() {
58 if (red) delete [] red; 58 if (red) delete [] red;
59 if (green) delete [] green; 59 if (green) delete [] green;
60 if (blue) delete [] blue; 60 if (blue) delete [] blue;
61} 61}
62 62
63 63
64Pixmap TextureRender::render(const FbTk::Texture &texture) { 64Pixmap TextureRender::render(const FbTk::Texture &texture) {
65 65
66 if (texture.type() & FbTk::Texture::PARENTRELATIVE) 66 if (texture.type() & FbTk::Texture::PARENTRELATIVE)
67 return ParentRelative; 67 return ParentRelative;
68 else if (texture.type() & FbTk::Texture::SOLID) 68 else if (texture.type() & FbTk::Texture::SOLID)
69 return renderSolid(texture); 69 return renderSolid(texture);
70 else if (texture.type() & FbTk::Texture::GRADIENT) 70 else if (texture.type() & FbTk::Texture::GRADIENT)
71 return renderGradient(texture); 71 return renderGradient(texture);
72 72
73 return None; 73 return None;
74} 74}
75 75
76 76
77Pixmap TextureRender::renderSolid(const FbTk::Texture &texture) { 77Pixmap TextureRender::renderSolid(const FbTk::Texture &texture) {
78 78
79 Display *disp = FbTk::App::instance()->display(); 79 Display *disp = FbTk::App::instance()->display();
80 80
81 Pixmap pixmap = XCreatePixmap(disp, 81 Pixmap pixmap = XCreatePixmap(disp,
82 RootWindow(disp, control.screenNum()), width, 82 RootWindow(disp, control.screenNum()), width,
83 height, control.depth()); 83 height, control.depth());
84 if (pixmap == None) { 84 if (pixmap == None) {
85 fprintf(stderr, 85 fprintf(stderr,
86 I18n::instance()->getMessage( 86 I18n::instance()->getMessage(
87 FBNLS::ImageSet, FBNLS::ImageErrorCreatingSolidPixmap, 87 FBNLS::ImageSet, FBNLS::ImageErrorCreatingSolidPixmap,
88 "BImage::render_solid: error creating pixmap\n")); 88 "BImage::render_solid: error creating pixmap\n"));
89 return None; 89 return None;
90 } 90 }
91 91
92 XGCValues gcv; 92 XGCValues gcv;
93 GC gc, hgc, lgc; 93 GC gc, hgc, lgc;
94 94
95 gcv.foreground = texture.color().pixel(); 95 gcv.foreground = texture.color().pixel();
96 gcv.fill_style = FillSolid; 96 gcv.fill_style = FillSolid;
97 gc = XCreateGC(disp, pixmap, GCForeground | GCFillStyle, &gcv); 97 gc = XCreateGC(disp, pixmap, GCForeground | GCFillStyle, &gcv);
98 98
99 gcv.foreground = texture.hiColor().pixel(); 99 gcv.foreground = texture.hiColor().pixel();
100 hgc = XCreateGC(disp, pixmap, GCForeground, &gcv); 100 hgc = XCreateGC(disp, pixmap, GCForeground, &gcv);
101 101
102 gcv.foreground = texture.loColor().pixel(); 102 gcv.foreground = texture.loColor().pixel();
103 lgc = XCreateGC(disp, pixmap, GCForeground, &gcv); 103 lgc = XCreateGC(disp, pixmap, GCForeground, &gcv);
104 104
105 XFillRectangle(disp, pixmap, gc, 0, 0, width, height); 105 XFillRectangle(disp, pixmap, gc, 0, 0, width, height);
106 106
107 using namespace FbTk; 107 using namespace FbTk;
108 108
109 if (texture.type() & Texture::INTERLACED) { 109 if (texture.type() & Texture::INTERLACED) {
110 gcv.foreground = texture.colorTo().pixel(); 110 gcv.foreground = texture.colorTo().pixel();
111 GC igc = XCreateGC(disp, pixmap, 111 GC igc = XCreateGC(disp, pixmap,
112 GCForeground, &gcv); 112 GCForeground, &gcv);
113 113
114 register unsigned int i = 0; 114 register unsigned int i = 0;
115 for (; i < height; i += 2) 115 for (; i < height; i += 2)
116 XDrawLine(disp, pixmap, igc, 0, i, width, i); 116 XDrawLine(disp, pixmap, igc, 0, i, width, i);
117 117
118 XFreeGC(disp, igc); 118 XFreeGC(disp, igc);
119 } 119 }
120 120
121 if (texture.type() & Texture::BEVEL1) { 121 if (texture.type() & Texture::BEVEL1) {
122 if (texture.type() & Texture::RAISED) { 122 if (texture.type() & Texture::RAISED) {
123 XDrawLine(disp, pixmap, lgc, 123 XDrawLine(disp, pixmap, lgc,
124 0, height - 1, width - 1, height - 1); 124 0, height - 1, width - 1, height - 1);
125 XDrawLine(disp, pixmap, lgc, 125 XDrawLine(disp, pixmap, lgc,
126 width - 1, height - 1, width - 1, 0); 126 width - 1, height - 1, width - 1, 0);
127 127
128 XDrawLine(disp, pixmap, hgc, 128 XDrawLine(disp, pixmap, hgc,
129 0, 0, width - 1, 0); 129 0, 0, width - 1, 0);
130 XDrawLine(disp, pixmap, hgc, 130 XDrawLine(disp, pixmap, hgc,
131 0, height - 1, 0, 0); 131 0, height - 1, 0, 0);
132 } else if (texture.type() & Texture::SUNKEN) { 132 } else if (texture.type() & Texture::SUNKEN) {
133 XDrawLine(disp, pixmap, hgc, 133 XDrawLine(disp, pixmap, hgc,
134 0, height - 1, width - 1, height - 1); 134 0, height - 1, width - 1, height - 1);
135 XDrawLine(disp, pixmap, hgc, 135 XDrawLine(disp, pixmap, hgc,
136 width - 1, height - 1, width - 1, 0); 136 width - 1, height - 1, width - 1, 0);
137 137
138 XDrawLine(disp, pixmap, lgc, 138 XDrawLine(disp, pixmap, lgc,
139 0, 0, width - 1, 0); 139 0, 0, width - 1, 0);
140 XDrawLine(disp, pixmap, lgc, 140 XDrawLine(disp, pixmap, lgc,
141 0, height - 1, 0, 0); 141 0, height - 1, 0, 0);
142 } 142 }
143 } else if (texture.type() & Texture::BEVEL2) { 143 } else if (texture.type() & Texture::BEVEL2) {
144 if (texture.type() & Texture::RAISED) { 144 if (texture.type() & Texture::RAISED) {
145 XDrawLine(disp, pixmap, lgc, 145 XDrawLine(disp, pixmap, lgc,
146 1, height - 3, width - 3, height - 3); 146 1, height - 3, width - 3, height - 3);
147 XDrawLine(disp, pixmap, lgc, 147 XDrawLine(disp, pixmap, lgc,
148 width - 3, height - 3, width - 3, 1); 148 width - 3, height - 3, width - 3, 1);
149 149
150 XDrawLine(disp, pixmap, hgc, 150 XDrawLine(disp, pixmap, hgc,
151 1, 1, width - 3, 1); 151 1, 1, width - 3, 1);
152 XDrawLine(disp, pixmap, hgc, 152 XDrawLine(disp, pixmap, hgc,
153 1, height - 3, 1, 1); 153 1, height - 3, 1, 1);
154 } else if (texture.type() & Texture::SUNKEN) { 154 } else if (texture.type() & Texture::SUNKEN) {
155 XDrawLine(disp, pixmap, hgc, 155 XDrawLine(disp, pixmap, hgc,
156 1, height - 3, width - 3, height - 3); 156 1, height - 3, width - 3, height - 3);
157 XDrawLine(disp, pixmap, hgc, 157 XDrawLine(disp, pixmap, hgc,
158 width - 3, height - 3, width - 3, 1); 158 width - 3, height - 3, width - 3, 1);
159 159
160 XDrawLine(disp, pixmap, lgc, 160 XDrawLine(disp, pixmap, lgc,
161 1, 1, width - 3, 1); 161 1, 1, width - 3, 1);
162 XDrawLine(disp, pixmap, lgc, 162 XDrawLine(disp, pixmap, lgc,
163 1, height - 3, 1, 1); 163 1, height - 3, 1, 1);
164 } 164 }
165 } 165 }
166 166
167 XFreeGC(disp, gc); 167 XFreeGC(disp, gc);
168 XFreeGC(disp, hgc); 168 XFreeGC(disp, hgc);
169 XFreeGC(disp, lgc); 169 XFreeGC(disp, lgc);
170 170
171 return pixmap; 171 return pixmap;
172} 172}
173 173
174 174
175Pixmap TextureRender::renderGradient(const FbTk::Texture &texture) { 175Pixmap TextureRender::renderGradient(const FbTk::Texture &texture) {
176 176
177 bool inverted = false; 177 bool inverted = false;
178 178
179 using namespace FbTk; 179 using namespace FbTk;
180 180
181 interlaced = texture.type() & Texture::INTERLACED; 181 interlaced = texture.type() & Texture::INTERLACED;
182 182
183 if (texture.type() & Texture::SUNKEN) { 183 if (texture.type() & Texture::SUNKEN) {
184 from = &(texture.colorTo()); 184 from = &(texture.colorTo());
185 to = &(texture.color()); 185 to = &(texture.color());
186 186
187 if (! (texture.type() & Texture::INVERT)) 187 if (! (texture.type() & Texture::INVERT))
188 inverted = true; 188 inverted = true;
189 } else { 189 } else {
190 from = &(texture.color()); 190 from = &(texture.color());
191 to = &(texture.colorTo()); 191 to = &(texture.colorTo());
192 192
193 if (texture.type() & Texture::INVERT) 193 if (texture.type() & Texture::INVERT)
194 inverted = true; 194 inverted = true;
195 } 195 }
196 196
197 control.getGradientBuffers(width, height, &xtable, &ytable); 197 control.getGradientBuffers(width, height, &xtable, &ytable);
198 198
199 if (texture.type() & Texture::DIAGONAL) 199 if (texture.type() & Texture::DIAGONAL)
200 dgradient(); 200 dgradient();
201 else if (texture.type() & Texture::ELLIPTIC) 201 else if (texture.type() & Texture::ELLIPTIC)
202 egradient(); 202 egradient();
203 else if (texture.type() & Texture::HORIZONTAL) 203 else if (texture.type() & Texture::HORIZONTAL)
204 hgradient(); 204 hgradient();
205 else if (texture.type() & Texture::PYRAMID) 205 else if (texture.type() & Texture::PYRAMID)
206 pgradient(); 206 pgradient();
207 else if (texture.type() & Texture::RECTANGLE) 207 else if (texture.type() & Texture::RECTANGLE)
208 rgradient(); 208 rgradient();
209 else if (texture.type() & Texture::VERTICAL) 209 else if (texture.type() & Texture::VERTICAL)
210 vgradient(); 210 vgradient();
211 else if (texture.type() & Texture::CROSSDIAGONAL) 211 else if (texture.type() & Texture::CROSSDIAGONAL)
212 cdgradient(); 212 cdgradient();
213 else if (texture.type() & Texture::PIPECROSS) 213 else if (texture.type() & Texture::PIPECROSS)
214 pcgradient(); 214 pcgradient();
215 215
216 if (texture.type() & Texture::BEVEL1) 216 if (texture.type() & Texture::BEVEL1)
217 bevel1(); 217 bevel1();
218 else if (texture.type() & Texture::BEVEL2) 218 else if (texture.type() & Texture::BEVEL2)
219 bevel2(); 219 bevel2();
220 220
221 if (inverted) 221 if (inverted)
222 invert(); 222 invert();
223 223
224 return renderPixmap(); 224 return renderPixmap();
225 225
226} 226}
227 227
228 228
229XImage *TextureRender::renderXImage() { 229XImage *TextureRender::renderXImage() {
230 I18n *i18n = I18n::instance(); 230 I18n *i18n = I18n::instance();
231 Display *disp = FbTk::App::instance()->display(); 231 Display *disp = FbTk::App::instance()->display();
232 XImage *image = 232 XImage *image =
233 XCreateImage(disp, 233 XCreateImage(disp,
234 DefaultVisual(disp, control.screenNum()), control.depth(), ZPixmap, 0, 0, 234 DefaultVisual(disp, control.screenNum()), control.depth(), ZPixmap, 0, 0,
235 width, height, 32, 0); 235 width, height, 32, 0);
236 236
237 if (! image) { 237 if (! image) {
238 fprintf(stderr, 238 fprintf(stderr,
239 i18n-> 239 i18n->
240 getMessage( 240 getMessage(
241 FBNLS::ImageSet, FBNLS::ImageErrorCreatingXImage, 241 FBNLS::ImageSet, FBNLS::ImageErrorCreatingXImage,
242 "BImage::renderXImage: error creating XImage\n")); 242 "BImage::renderXImage: error creating XImage\n"));
243 return 0; 243 return 0;
244 } 244 }
245 245
246 image->data = 0; 246 image->data = 0;
247 247
248 unsigned char *d = new unsigned char[image->bytes_per_line * (height + 1)]; 248 unsigned char *d = new unsigned char[image->bytes_per_line * (height + 1)];
249 register unsigned int x, y, dithx, dithy, r, g, b, o, er, eg, eb, offset; 249 register unsigned int x, y, dithx, dithy, r, g, b, o, er, eg, eb, offset;
250 250
251 unsigned char *pixel_data = d, *ppixel_data = d; 251 unsigned char *pixel_data = d, *ppixel_data = d;
252 unsigned long pixel; 252 unsigned long pixel;
253 253
254 o = image->bits_per_pixel + ((image->byte_order == MSBFirst) ? 1 : 0); 254 o = image->bits_per_pixel + ((image->byte_order == MSBFirst) ? 1 : 0);
255 255
256 if (control.doDither() && width > 1 && height > 1) { 256 if (control.doDither() && width > 1 && height > 1) {
257 unsigned char dither4[4][4] = { 257 unsigned char dither4[4][4] = {
258 {0, 4, 1, 5}, 258 {0, 4, 1, 5},
259 {6, 2, 7, 3}, 259 {6, 2, 7, 3},
260 {1, 5, 0, 4}, 260 {1, 5, 0, 4},
261 {7, 3, 6, 2} }; 261 {7, 3, 6, 2} };
262 262
263#ifdef ORDEREDPSEUDO 263#ifdef ORDEREDPSEUDO
264 unsigned char dither8[8][8] = { 264 unsigned char dither8[8][8] = {
265 { 0, 32, 8, 40, 2, 34, 10, 42 }, 265 { 0, 32, 8, 40, 2, 34, 10, 42 },
266 { 48, 16, 56, 24, 50, 18, 58, 26 }, 266 { 48, 16, 56, 24, 50, 18, 58, 26 },
267 { 12, 44, 4, 36, 14, 46, 6, 38 }, 267 { 12, 44, 4, 36, 14, 46, 6, 38 },
268 { 60, 28, 52, 20, 62, 30, 54, 22 }, 268 { 60, 28, 52, 20, 62, 30, 54, 22 },
269 { 3, 35, 11, 43, 1, 33, 9, 41 }, 269 { 3, 35, 11, 43, 1, 33, 9, 41 },
270 { 51, 19, 59, 27, 49, 17, 57, 25 }, 270 { 51, 19, 59, 27, 49, 17, 57, 25 },
271 { 15, 47, 7, 39, 13, 45, 5, 37 }, 271 { 15, 47, 7, 39, 13, 45, 5, 37 },
272 { 63, 31, 55, 23, 61, 29, 53, 21 } }; 272 { 63, 31, 55, 23, 61, 29, 53, 21 } };
273#endif // ORDEREDPSEUDO 273#endif // ORDEREDPSEUDO
274 274
275 switch (control.visual()->c_class) { 275 switch (control.visual()->c_class) {
276 case TrueColor: 276 case TrueColor:
277 // algorithm: ordered dithering... many many thanks to rasterman 277 // algorithm: ordered dithering... many many thanks to rasterman
278 // (raster@rasterman.com) for telling me about this... portions of this 278 // (raster@rasterman.com) for telling me about this... portions of this
279 // code is based off of his code in Imlib 279 // code is based off of his code in Imlib
280 for (y = 0, offset = 0; y < height; y++) { 280 for (y = 0, offset = 0; y < height; y++) {
281 dithy = y & 0x3; 281 dithy = y & 0x3;
282 282
283 for (x = 0; x < width; x++, offset++) { 283 for (x = 0; x < width; x++, offset++) {
284 dithx = x & 0x3; 284 dithx = x & 0x3;
285 r = red[offset]; 285 r = red[offset];
286 g = green[offset]; 286 g = green[offset];
287 b = blue[offset]; 287 b = blue[offset];
288 288
289 er = r & (red_bits - 1); 289 er = r & (red_bits - 1);
290 eg = g & (green_bits - 1); 290 eg = g & (green_bits - 1);
291 eb = b & (blue_bits - 1); 291 eb = b & (blue_bits - 1);
292 292
293 r = red_table[r]; 293 r = red_table[r];
294 g = green_table[g]; 294 g = green_table[g];
295 b = blue_table[b]; 295 b = blue_table[b];
296 296
297 if ((dither4[dithy][dithx] < er) && (r < red_table[255])) r++; 297 if ((dither4[dithy][dithx] < er) && (r < red_table[255])) r++;
298 if ((dither4[dithy][dithx] < eg) && (g < green_table[255])) g++; 298 if ((dither4[dithy][dithx] < eg) && (g < green_table[255])) g++;
299 if ((dither4[dithy][dithx] < eb) && (b < blue_table[255])) b++; 299 if ((dither4[dithy][dithx] < eb) && (b < blue_table[255])) b++;
300 300
301 pixel = (r << red_offset) | (g << green_offset) | (b << blue_offset); 301 pixel = (r << red_offset) | (g << green_offset) | (b << blue_offset);
302 302
303 switch (o) { 303 switch (o) {
304 case 8: // 8bpp 304 case 8: // 8bpp
305 *pixel_data++ = pixel; 305 *pixel_data++ = pixel;
306 break; 306 break;
307 307
308 case 16: // 16bpp LSB 308 case 16: // 16bpp LSB
309 *pixel_data++ = pixel; 309 *pixel_data++ = pixel;
310 *pixel_data++ = pixel >> 8; 310 *pixel_data++ = pixel >> 8;
311 break; 311 break;
312 312
313 case 17: // 16bpp MSB 313 case 17: // 16bpp MSB
314 *pixel_data++ = pixel >> 8; 314 *pixel_data++ = pixel >> 8;
315 *pixel_data++ = pixel; 315 *pixel_data++ = pixel;
316 break; 316 break;
317 317
318 case 24: // 24bpp LSB 318 case 24: // 24bpp LSB
319 *pixel_data++ = pixel; 319 *pixel_data++ = pixel;
320 *pixel_data++ = pixel >> 8; 320 *pixel_data++ = pixel >> 8;
321 *pixel_data++ = pixel >> 16; 321 *pixel_data++ = pixel >> 16;
322 break; 322 break;
323 323
324 case 25: // 24bpp MSB 324 case 25: // 24bpp MSB
325 *pixel_data++ = pixel >> 16; 325 *pixel_data++ = pixel >> 16;
326 *pixel_data++ = pixel >> 8; 326 *pixel_data++ = pixel >> 8;
327 *pixel_data++ = pixel; 327 *pixel_data++ = pixel;
328 break; 328 break;
329 329
330 case 32: // 32bpp LSB 330 case 32: // 32bpp LSB
331 *pixel_data++ = pixel; 331 *pixel_data++ = pixel;
332 *pixel_data++ = pixel >> 8; 332 *pixel_data++ = pixel >> 8;
333 *pixel_data++ = pixel >> 16; 333 *pixel_data++ = pixel >> 16;
334 *pixel_data++ = pixel >> 24; 334 *pixel_data++ = pixel >> 24;
335 break; 335 break;
336 336
337 case 33: // 32bpp MSB 337 case 33: // 32bpp MSB
338 *pixel_data++ = pixel >> 24; 338 *pixel_data++ = pixel >> 24;
339 *pixel_data++ = pixel >> 16; 339 *pixel_data++ = pixel >> 16;
340 *pixel_data++ = pixel >> 8; 340 *pixel_data++ = pixel >> 8;
341 *pixel_data++ = pixel; 341 *pixel_data++ = pixel;
342 break; 342 break;
343 } 343 }
344 } 344 }
345 345
346 pixel_data = (ppixel_data += image->bytes_per_line); 346 pixel_data = (ppixel_data += image->bytes_per_line);
347 } 347 }
348 348
349 break; 349 break;
350 350
351 case StaticColor: 351 case StaticColor:
352 case PseudoColor: { 352 case PseudoColor: {
353#ifndef ORDEREDPSEUDO 353#ifndef ORDEREDPSEUDO
354 short *terr, 354 short *terr,
355 *rerr = new short[width + 2], 355 *rerr = new short[width + 2],
356 *gerr = new short[width + 2], 356 *gerr = new short[width + 2],
357 *berr = new short[width + 2], 357 *berr = new short[width + 2],
358 *nrerr = new short[width + 2], 358 *nrerr = new short[width + 2],
359 *ngerr = new short[width + 2], 359 *ngerr = new short[width + 2],
360 *nberr = new short[width + 2]; 360 *nberr = new short[width + 2];
361 int rr, gg, bb, rer, ger, ber; 361 int rr, gg, bb, rer, ger, ber;
362 int dd = 255 / control.colorsPerChannel(); 362 int dd = 255 / control.colorsPerChannel();
363 363
364 for (x = 0; x < width; x++) { 364 for (x = 0; x < width; x++) {
365 *(rerr + x) = *(red + x); 365 *(rerr + x) = *(red + x);
366 *(gerr + x) = *(green + x); 366 *(gerr + x) = *(green + x);
367 *(berr + x) = *(blue + x); 367 *(berr + x) = *(blue + x);
368 } 368 }
369 369
370 *(rerr + x) = *(gerr + x) = *(berr + x) = 0; 370 *(rerr + x) = *(gerr + x) = *(berr + x) = 0;
371#endif // ORDEREDPSEUDO 371#endif // ORDEREDPSEUDO
372 372
373 for (y = 0, offset = 0; y < height; y++) { 373 for (y = 0, offset = 0; y < height; y++) {
374#ifdef ORDEREDPSEUDO 374#ifdef ORDEREDPSEUDO
375 dithy = y & 7; 375 dithy = y & 7;
376 376
377 for (x = 0; x < width; x++, offset++) { 377 for (x = 0; x < width; x++, offset++) {
378 dithx = x & 7; 378 dithx = x & 7;
379 379
380 r = red[offset]; 380 r = red[offset];
381 g = green[offset]; 381 g = green[offset];
382 b = blue[offset]; 382 b = blue[offset];
383 383
384 er = r & (red_bits - 1); 384 er = r & (red_bits - 1);
385 eg = g & (green_bits - 1); 385 eg = g & (green_bits - 1);
386 eb = b & (blue_bits - 1); 386 eb = b & (blue_bits - 1);
387 387
388 r = red_table[r]; 388 r = red_table[r];
389 g = green_table[g]; 389 g = green_table[g];
390 b = blue_table[b]; 390 b = blue_table[b];
391 391
392 if ((dither8[dithy][dithx] < er) && (r < red_table[255])) r++; 392 if ((dither8[dithy][dithx] < er) && (r < red_table[255])) r++;
393 if ((dither8[dithy][dithx] < eg) && (g < green_table[255])) g++; 393 if ((dither8[dithy][dithx] < eg) && (g < green_table[255])) g++;
394 if ((dither8[dithy][dithx] < eb) && (b < blue_table[255])) b++; 394 if ((dither8[dithy][dithx] < eb) && (b < blue_table[255])) b++;
395 395
396 pixel = (r * cpccpc) + (g * cpc) + b; 396 pixel = (r * cpccpc) + (g * cpc) + b;
397 *(pixel_data++) = colors[pixel].pixel; 397 *(pixel_data++) = colors[pixel].pixel;
398 } 398 }
399 399
400 pixel_data = (ppixel_data += image->bytes_per_line); 400 pixel_data = (ppixel_data += image->bytes_per_line);
401 } 401 }
402#else // !ORDEREDPSEUDO 402#else // !ORDEREDPSEUDO
403 if (y < (height - 1)) { 403 if (y < (height - 1)) {
404 int i = offset + width; 404 int i = offset + width;
405 for (x = 0; x < width; x++, i++) { 405 for (x = 0; x < width; x++, i++) {
406 *(nrerr + x) = *(red + i); 406 *(nrerr + x) = *(red + i);
407 *(ngerr + x) = *(green + i); 407 *(ngerr + x) = *(green + i);
408 *(nberr + x) = *(blue + i); 408 *(nberr + x) = *(blue + i);
409 } 409 }
410 410
411 *(nrerr + x) = *(red + (--i)); 411 *(nrerr + x) = *(red + (--i));
412 *(ngerr + x) = *(green + i); 412 *(ngerr + x) = *(green + i);
413 *(nberr + x) = *(blue + i); 413 *(nberr + x) = *(blue + i);
414 } 414 }
415 415
416 for (x = 0; x < width; x++) { 416 for (x = 0; x < width; x++) {
417 rr = rerr[x]; 417 rr = rerr[x];
418 gg = gerr[x]; 418 gg = gerr[x];
419 bb = berr[x]; 419 bb = berr[x];
420 420
421 if (rr > 255) rr = 255; else if (rr < 0) rr = 0; 421 if (rr > 255) rr = 255; else if (rr < 0) rr = 0;
422 if (gg > 255) gg = 255; else if (gg < 0) gg = 0; 422 if (gg > 255) gg = 255; else if (gg < 0) gg = 0;
423 if (bb > 255) bb = 255; else if (bb < 0) bb = 0; 423 if (bb > 255) bb = 255; else if (bb < 0) bb = 0;
424 424
425 r = red_table[rr]; 425 r = red_table[rr];
426 g = green_table[gg]; 426 g = green_table[gg];
427 b = blue_table[bb]; 427 b = blue_table[bb];
428 428
429 rer = rerr[x] - r*dd; 429 rer = rerr[x] - r*dd;
430 ger = gerr[x] - g*dd; 430 ger = gerr[x] - g*dd;
431 ber = berr[x] - b*dd; 431 ber = berr[x] - b*dd;
432 432
433 pixel = (r * cpccpc) + (g * cpc) + b; 433 pixel = (r * cpccpc) + (g * cpc) + b;
434 *pixel_data++ = colors[pixel].pixel; 434 *pixel_data++ = colors[pixel].pixel;
435 435
436 r = rer >> 1; 436 r = rer >> 1;
437 g = ger >> 1; 437 g = ger >> 1;
438 b = ber >> 1; 438 b = ber >> 1;
439 rerr[x+1] += r; 439 rerr[x+1] += r;
440 gerr[x+1] += g; 440 gerr[x+1] += g;
441 berr[x+1] += b; 441 berr[x+1] += b;
442 nrerr[x] += r; 442 nrerr[x] += r;
443 ngerr[x] += g; 443 ngerr[x] += g;
444 nberr[x] += b; 444 nberr[x] += b;
445 } 445 }
446 446
447 offset += width; 447 offset += width;
448 448
449 pixel_data = (ppixel_data += image->bytes_per_line); 449 pixel_data = (ppixel_data += image->bytes_per_line);
450 450
451 terr = rerr; 451 terr = rerr;
452 rerr = nrerr; 452 rerr = nrerr;
453 nrerr = terr; 453 nrerr = terr;
454 454
455 terr = gerr; 455 terr = gerr;
456 gerr = ngerr; 456 gerr = ngerr;
457 ngerr = terr; 457 ngerr = terr;
458 458
459 terr = berr; 459 terr = berr;
460 berr = nberr; 460 berr = nberr;
461 nberr = terr; 461 nberr = terr;
462 } 462 }
463 463
464 delete [] rerr; 464 delete [] rerr;
465 delete [] gerr; 465 delete [] gerr;
466 delete [] berr; 466 delete [] berr;
467 delete [] nrerr; 467 delete [] nrerr;
468 delete [] ngerr; 468 delete [] ngerr;
469 delete [] nberr; 469 delete [] nberr;
470#endif // ORDEREDPSUEDO 470#endif // ORDEREDPSUEDO
471 471
472 } break; 472 } break;
473 473
474 /* 474 /*
475 case StaticGray: 475 case StaticGray:
476 case GrayScale: 476 case GrayScale:
477 for (y = 0, offset = 0; y < height; y++) { 477 for (y = 0, offset = 0; y < height; y++) {
478 dithy = y & 0x3; 478 dithy = y & 0x3;
479 479
480 for (x = 0; x < width; x++, offset++) { 480 for (x = 0; x < width; x++, offset++) {
481 dithx = x & 0x3; 481 dithx = x & 0x3;
482 482
483 r = *(red + offset); 483 r = *(red + offset);
484 g = *(green + offset); 484 g = *(green + offset);
485 b = *(blue + offset); 485 b = *(blue + offset);
486 486
487 er = r & 0x7; 487 er = r & 0x7;
488 eg = g & 0x7; 488 eg = g & 0x7;
489 eb = b & 0x7; 489 eb = b & 0x7;
490 490
491 if ((dither[dithy][dithx] < er) && (r < (256 - 8))) 491 if ((dither[dithy][dithx] < er) && (r < (256 - 8)))
492 r += 8; 492 r += 8;
493 if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) 493 if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4)))
494 g += 4; 494 g += 4;
495 if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) 495 if ((dither[dithy][dithx] < eb) && (b < (256 - 8)))
496 b += 8; 496 b += 8;
497 497
498 r = *(red_table + r); 498 r = *(red_table + r);
499 g = *(green_table + g); 499 g = *(green_table + g);
500 b = *(blue_table + b); 500 b = *(blue_table + b);
501 501
502 g = ((r * 30) + (g * 59) + (b * 11)) / 100; 502 g = ((r * 30) + (g * 59) + (b * 11)) / 100;
503 *pixel_data++ = colors[g].pixel; 503 *pixel_data++ = colors[g].pixel;
504 } 504 }
505 505
506 pixel_data = (ppixel_data += image->bytes_per_line); 506 pixel_data = (ppixel_data += image->bytes_per_line);
507 } 507 }
508 508
509 break; 509 break;
510 */ 510 */
511 511
512 default: 512 default:
513 fprintf(stderr, 513 fprintf(stderr,
514 i18n-> 514 i18n->
515 getMessage( 515 getMessage(
516 FBNLS::ImageSet, FBNLS::ImageUnsupVisual, 516 FBNLS::ImageSet, FBNLS::ImageUnsupVisual,
517 "BImage::renderXImage: unsupported visual\n")); 517 "BImage::renderXImage: unsupported visual\n"));
518 delete [] d; 518 delete [] d;
519 XDestroyImage(image); 519 XDestroyImage(image);
520 return (XImage *) 0; 520 return (XImage *) 0;
521 } 521 }
522 } else { 522} else {
523 switch (control.visual()->c_class) { 523 switch (control.visual()->c_class) {
524 case StaticColor: 524 case StaticColor:
525 case PseudoColor: 525 case PseudoColor:
526 for (y = 0, offset = 0; y < height; y++) { 526 for (y = 0, offset = 0; y < height; y++) {
527 for (x = 0; x < width; x++, offset++) { 527 for (x = 0; x < width; x++, offset++) {
528 r = red_table[red[offset]]; 528 r = red_table[red[offset]];
529 g = green_table[green[offset]]; 529 g = green_table[green[offset]];
530 b = blue_table[blue[offset]]; 530 b = blue_table[blue[offset]];
531 531
532 pixel = (r * cpccpc) + (g * cpc) + b; 532 pixel = (r * cpccpc) + (g * cpc) + b;
533 *pixel_data++ = colors[pixel].pixel; 533 *pixel_data++ = colors[pixel].pixel;
534 } 534 }
535 535
536 pixel_data = (ppixel_data += image->bytes_per_line); 536 pixel_data = (ppixel_data += image->bytes_per_line);
537 } 537 }
538 538
539 break; 539 break;
540 540
541 case TrueColor: 541 case TrueColor:
542 for (y = 0, offset = 0; y < height; y++) { 542 for (y = 0, offset = 0; y < height; y++) {
543 for (x = 0; x < width; x++, offset++) { 543 for (x = 0; x < width; x++, offset++) {
544 r = red_table[red[offset]]; 544 r = red_table[red[offset]];
545 g = green_table[green[offset]]; 545 g = green_table[green[offset]];
546 b = blue_table[blue[offset]]; 546 b = blue_table[blue[offset]];
547 547
548 pixel = (r << red_offset) | (g << green_offset) | (b << blue_offset); 548 pixel = (r << red_offset) | (g << green_offset) | (b << blue_offset);
549 549
550 switch (o) { 550 switch (o) {
551 case 8: // 8bpp 551 case 8: // 8bpp
552 *pixel_data++ = pixel; 552 *pixel_data++ = pixel;
553 break; 553 break;
554 554
555 case 16: // 16bpp LSB 555 case 16: // 16bpp LSB
556 *pixel_data++ = pixel; 556 *pixel_data++ = pixel;
557 *pixel_data++ = pixel >> 8; 557 *pixel_data++ = pixel >> 8;
558 break; 558 break;
559 559
560 case 17: // 16bpp MSB 560 case 17: // 16bpp MSB
561 *pixel_data++ = pixel >> 8; 561 *pixel_data++ = pixel >> 8;
562 *pixel_data++ = pixel; 562 *pixel_data++ = pixel;
563 break; 563 break;
564 564
565 case 24: // 24bpp LSB 565 case 24: // 24bpp LSB
566 *pixel_data++ = pixel; 566 *pixel_data++ = pixel;
567 *pixel_data++ = pixel >> 8; 567 *pixel_data++ = pixel >> 8;
568 *pixel_data++ = pixel >> 16; 568 *pixel_data++ = pixel >> 16;
569 break; 569 break;
570 570
571 case 25: // 24bpp MSB 571 case 25: // 24bpp MSB
572 *pixel_data++ = pixel >> 16; 572 *pixel_data++ = pixel >> 16;
573 *pixel_data++ = pixel >> 8; 573 *pixel_data++ = pixel >> 8;
574 *pixel_data++ = pixel; 574 *pixel_data++ = pixel;
575 break; 575 break;
576 576
577 case 32: // 32bpp LSB 577 case 32: // 32bpp LSB
578 *pixel_data++ = pixel; 578 *pixel_data++ = pixel;
579 *pixel_data++ = pixel >> 8; 579 *pixel_data++ = pixel >> 8;
580 *pixel_data++ = pixel >> 16; 580 *pixel_data++ = pixel >> 16;
581 *pixel_data++ = pixel >> 24; 581 *pixel_data++ = pixel >> 24;
582 break; 582 break;
583 583
584 case 33: // 32bpp MSB 584 case 33: // 32bpp MSB
585 *pixel_data++ = pixel >> 24; 585 *pixel_data++ = pixel >> 24;
586 *pixel_data++ = pixel >> 16; 586 *pixel_data++ = pixel >> 16;
587 *pixel_data++ = pixel >> 8; 587 *pixel_data++ = pixel >> 8;
588 *pixel_data++ = pixel; 588 *pixel_data++ = pixel;
589 break; 589 break;
590 } 590 }
591 } 591 }
592 592
593 pixel_data = (ppixel_data += image->bytes_per_line); 593 pixel_data = (ppixel_data += image->bytes_per_line);
594 } 594 }
595 595
596 break; 596 break;
597 597
598 case StaticGray: 598 case StaticGray:
599 case GrayScale: 599 case GrayScale:
600 for (y = 0, offset = 0; y < height; y++) { 600 for (y = 0, offset = 0; y < height; y++) {
601 for (x = 0; x < width; x++, offset++) { 601 for (x = 0; x < width; x++, offset++) {
602 r = *(red_table + *(red + offset)); 602 r = *(red_table + *(red + offset));
603 g = *(green_table + *(green + offset)); 603 g = *(green_table + *(green + offset));
604 b = *(blue_table + *(blue + offset)); 604 b = *(blue_table + *(blue + offset));
605 605
606 g = ((r * 30) + (g * 59) + (b * 11)) / 100; 606 g = ((r * 30) + (g * 59) + (b * 11)) / 100;
607 *pixel_data++ = colors[g].pixel; 607 *pixel_data++ = colors[g].pixel;
608 } 608 }
609 609
610 pixel_data = (ppixel_data += image->bytes_per_line); 610 pixel_data = (ppixel_data += image->bytes_per_line);
611 } 611 }
612 612
613 break; 613 break;
614 614
615 default: 615 default:
616 fprintf(stderr, 616 fprintf(stderr,
617 i18n-> 617 i18n->
618 getMessage( 618 getMessage(
619 FBNLS::ImageSet, FBNLS::ImageUnsupVisual, 619 FBNLS::ImageSet, FBNLS::ImageUnsupVisual,
620 "BImage::renderXImage: unsupported visual\n")); 620 "BImage::renderXImage: unsupported visual\n"));
621 delete [] d; 621 delete [] d;
622 XDestroyImage(image); 622 XDestroyImage(image);
623 return (XImage *) 0; 623 return (XImage *) 0;
624 } 624 }
625} 625}
626 626
627 image->data = (char *) d; 627image->data = (char *) d;
628 return image; 628return image;
629} 629}
630 630
631 631
632Pixmap TextureRender::renderPixmap() { 632Pixmap TextureRender::renderPixmap() {
633 Display *disp = FbTk::App::instance()->display(); 633Display *disp = FbTk::App::instance()->display();
634 I18n *i18n = I18n::instance(); 634I18n *i18n = I18n::instance();
635 Pixmap pixmap = 635Pixmap pixmap =
636 XCreatePixmap(disp, 636XCreatePixmap(disp,
637 RootWindow(disp, control.screenNum()), width, height, control.depth()); 637 RootWindow(disp, control.screenNum()), width, height, control.depth());
638 638
639 if (pixmap == None) { 639if (pixmap == None) {
640 fprintf(stderr, 640fprintf(stderr,
641 i18n->getMessage( 641 i18n->getMessage(
642 FBNLS::ImageSet, FBNLS::ImageErrorCreatingPixmap, 642FBNLS::ImageSet, FBNLS::ImageErrorCreatingPixmap,
643 "BImage::renderPixmap: error creating pixmap\n")); 643 "BImage::renderPixmap: error creating pixmap\n"));
644 return None; 644return None;
645 } 645}
646 646
647 XImage *image = renderXImage(); 647XImage *image = renderXImage();
648 648
649 if (! image) { 649if (! image) {
650 XFreePixmap(disp, pixmap); 650XFreePixmap(disp, pixmap);
651 return None; 651return None;
652 } else if (! image->data) { 652} else if (! image->data) {
653 XDestroyImage(image); 653XDestroyImage(image);
654 XFreePixmap(disp, pixmap); 654XFreePixmap(disp, pixmap);
655 return None; 655return None;
656 } 656}
657 657
658 XPutImage(disp, pixmap, 658XPutImage(disp, pixmap,
659 DefaultGC(disp, control.screenNum()), 659 DefaultGC(disp, control.screenNum()),
660 image, 0, 0, 0, 0, width, height); 660 image, 0, 0, 0, 0, width, height);
661 661
662 if (image->data != 0) { 662if (image->data != 0) {
663 delete [] image->data; 663delete [] image->data;
664 image->data = 0; 664image->data = 0;
665 } 665}
666 666
667 XDestroyImage(image); 667XDestroyImage(image);
668 668
669 return pixmap; 669return pixmap;
670} 670}
671 671
672 672
673void TextureRender::bevel1() { 673void TextureRender::bevel1() {
674 if (! (width > 2 && height > 2)) 674if (! (width > 2 && height > 2))
675 return; 675 return;
676 676
677 unsigned char *pr = red, *pg = green, *pb = blue; 677unsigned char *pr = red, *pg = green, *pb = blue;
678 678
679 register unsigned char r, g, b, rr ,gg ,bb; 679register unsigned char r, g, b, rr ,gg ,bb;
680 register unsigned int w = width, h = height - 1, wh = w * h; 680register unsigned int w = width, h = height - 1, wh = w * h;
681 681
682 while (--w) { 682while (--w) {
683 r = *pr; 683r = *pr;
684 rr = r + (r >> 1); 684rr = r + (r >> 1);
685 if (rr < r) rr = ~0; 685if (rr < r) rr = ~0;
686 g = *pg; 686g = *pg;
687 gg = g + (g >> 1); 687gg = g + (g >> 1);
688 if (gg < g) gg = ~0; 688if (gg < g) gg = ~0;
689 b = *pb; 689b = *pb;
690 bb = b + (b >> 1); 690bb = b + (b >> 1);
691 if (bb < b) bb = ~0; 691if (bb < b) bb = ~0;
692 692
693 *pr = rr; 693*pr = rr;
694 *pg = gg; 694*pg = gg;
695 *pb = bb; 695*pb = bb;
696 696
697 r = *(pr + wh); 697r = *(pr + wh);
698 rr = (r >> 2) + (r >> 1); 698rr = (r >> 2) + (r >> 1);
699 if (rr > r) rr = 0; 699if (rr > r) rr = 0;
700 g = *(pg + wh); 700g = *(pg + wh);
701 gg = (g >> 2) + (g >> 1); 701gg = (g >> 2) + (g >> 1);
702 if (gg > g) gg = 0; 702if (gg > g) gg = 0;
703 b = *(pb + wh); 703b = *(pb + wh);
704 bb = (b >> 2) + (b >> 1); 704bb = (b >> 2) + (b >> 1);
705 if (bb > b) bb = 0; 705if (bb > b) bb = 0;
706 706
707 *((pr++) + wh) = rr; 707*((pr++) + wh) = rr;
708 *((pg++) + wh) = gg; 708*((pg++) + wh) = gg;
709 *((pb++) + wh) = bb; 709*((pb++) + wh) = bb;
710 }
711
712 r = *pr;
713 rr = r + (r >> 1);
714 if (rr < r) rr = ~0;
715 g = *pg;
716 gg = g + (g >> 1);
717 if (gg < g) gg = ~0;
718 b = *pb;
719 bb = b + (b >> 1);
720 if (bb < b) bb = ~0;
721
722 *pr = rr;
723 *pg = gg;
724 *pb = bb;
725
726 r = *(pr + wh);
727 rr = (r >> 2) + (r >> 1);
728 if (rr > r) rr = 0;
729 g = *(pg + wh);
730 gg = (g >> 2) + (g >> 1);
731 if (gg > g) gg = 0;
732 b = *(pb + wh);
733 bb = (b >> 2) + (b >> 1);
734 if (bb > b) bb = 0;
735
736 *(pr + wh) = rr;
737 *(pg + wh) = gg;
738 *(pb + wh) = bb;
739
740 pr = red + width;
741 pg = green + width;
742 pb = blue + width;
743
744 while (--h) {
745 r = *pr;
746 rr = r + (r >> 1);
747 if (rr < r) rr = ~0;
748 g = *pg;
749 gg = g + (g >> 1);
750 if (gg < g) gg = ~0;
751 b = *pb;
752 bb = b + (b >> 1);
753 if (bb < b) bb = ~0;
754
755 *pr = rr;
756 *pg = gg;
757 *pb = bb;
758
759 pr += width - 1;
760 pg += width - 1;
761 pb += width - 1;
762
763 r = *pr;
764 rr = (r >> 2) + (r >> 1);
765 if (rr > r) rr = 0;
766 g = *pg;
767 gg = (g >> 2) + (g >> 1);
768 if (gg > g) gg = 0;
769 b = *pb;
770 bb = (b >> 2) + (b >> 1);
771 if (bb > b) bb = 0;
772
773 *(pr++) = rr;
774 *(pg++) = gg;
775 *(pb++) = bb;
776 }
777
778 r = *pr;
779 rr = r + (r >> 1);
780 if (rr < r) rr = ~0;
781 g = *pg;
782 gg = g + (g >> 1);
783 if (gg < g) gg = ~0;
784 b = *pb;
785 bb = b + (b >> 1);
786 if (bb < b) bb = ~0;
787
788 *pr = rr;
789 *pg = gg;
790 *pb = bb;
791
792 pr += width - 1;
793 pg += width - 1;
794 pb += width - 1;
795
796 r = *pr;
797 rr = (r >> 2) + (r >> 1);
798 if (rr > r) rr = 0;
799 g = *pg;
800 gg = (g >> 2) + (g >> 1);
801 if (gg > g) gg = 0;
802 b = *pb;
803 bb = (b >> 2) + (b >> 1);
804 if (bb > b) bb = 0;
805
806 *pr = rr;
807 *pg = gg;
808 *pb = bb;
809} 710}
810 711
811 712r = *pr;
812void TextureRender::bevel2() { 713rr = r + (r >> 1);
813 if (! (width > 4 && height > 4)) 714if (rr < r) rr = ~0;
814 return; 715g = *pg;
815 716gg = g + (g >> 1);
816 unsigned char r, g, b, rr ,gg ,bb, *pr = red + width + 1, 717if (gg < g) gg = ~0;
817 *pg = green + width + 1, *pb = blue + width + 1; 718b = *pb;
818 unsigned int w = width - 2, h = height - 1, wh = width * (height - 3); 719bb = b + (b >> 1);
819 720if (bb < b) bb = ~0;
820 while (--w) { 721
821 r = *pr; 722*pr = rr;
822 rr = r + (r >> 1); 723*pg = gg;
823 if (rr < r) rr = ~0; 724*pb = bb;
824 g = *pg; 725
825 gg = g + (g >> 1); 726r = *(pr + wh);
826 if (gg < g) gg = ~0; 727rr = (r >> 2) + (r >> 1);
827 b = *pb; 728if (rr > r) rr = 0;
828 bb = b + (b >> 1); 729g = *(pg + wh);
829 if (bb < b) bb = ~0; 730gg = (g >> 2) + (g >> 1);
830 731if (gg > g) gg = 0;
831 *pr = rr; 732b = *(pb + wh);
832 *pg = gg; 733bb = (b >> 2) + (b >> 1);
833 *pb = bb; 734if (bb > b) bb = 0;
834 735
835 r = *(pr + wh); 736*(pr + wh) = rr;
836 rr = (r >> 2) + (r >> 1); 737*(pg + wh) = gg;
837 if (rr > r) rr = 0; 738*(pb + wh) = bb;
838 g = *(pg + wh); 739
839 gg = (g >> 2) + (g >> 1); 740pr = red + width;
840 if (gg > g) gg = 0; 741pg = green + width;
841 b = *(pb + wh); 742pb = blue + width;
842 bb = (b >> 2) + (b >> 1); 743
843 if (bb > b) bb = 0; 744while (--h) {
844 745r = *pr;
845 *((pr++) + wh) = rr; 746rr = r + (r >> 1);
846 *((pg++) + wh) = gg; 747if (rr < r) rr = ~0;
847 *((pb++) + wh) = bb; 748g = *pg;
848 } 749gg = g + (g >> 1);
849 750if (gg < g) gg = ~0;
850 pr = red + width; 751b = *pb;
851 pg = green + width; 752bb = b + (b >> 1);
852 pb = blue + width; 753if (bb < b) bb = ~0;
853 754
854 while (--h) { 755*pr = rr;
855 r = *pr; 756*pg = gg;
856 rr = r + (r >> 1); 757*pb = bb;
857 if (rr < r) rr = ~0; 758
858 g = *pg; 759pr += width - 1;
859 gg = g + (g >> 1); 760pg += width - 1;
860 if (gg < g) gg = ~0; 761pb += width - 1;
861 b = *pb; 762
862 bb = b + (b >> 1); 763r = *pr;
863 if (bb < b) bb = ~0; 764rr = (r >> 2) + (r >> 1);
864 765if (rr > r) rr = 0;
865 *(++pr) = rr; 766g = *pg;
866 *(++pg) = gg; 767gg = (g >> 2) + (g >> 1);
867 *(++pb) = bb; 768if (gg > g) gg = 0;
868 769b = *pb;
869 pr += width - 3; 770bb = (b >> 2) + (b >> 1);
870 pg += width - 3; 771if (bb > b) bb = 0;
871 pb += width - 3; 772
872 773*(pr++) = rr;
873 r = *pr; 774*(pg++) = gg;
874 rr = (r >> 2) + (r >> 1); 775*(pb++) = bb;
875 if (rr > r) rr = 0;
876 g = *pg;
877 gg = (g >> 2) + (g >> 1);
878 if (gg > g) gg = 0;
879 b = *pb;
880 bb = (b >> 2) + (b >> 1);
881 if (bb > b) bb = 0;
882
883 *(pr++) = rr;
884 *(pg++) = gg;
885 *(pb++) = bb;
886
887 pr++; pg++; pb++;
888 }
889} 776}
890 777
778r = *pr;
779rr = r + (r >> 1);
780if (rr < r) rr = ~0;
781g = *pg;
782gg = g + (g >> 1);
783if (gg < g) gg = ~0;
784b = *pb;
785bb = b + (b >> 1);
786if (bb < b) bb = ~0;
787
788*pr = rr;
789*pg = gg;
790*pb = bb;
791
792pr += width - 1;
793pg += width - 1;
794pb += width - 1;
795
796r = *pr;
797rr = (r >> 2) + (r >> 1);
798if (rr > r) rr = 0;
799g = *pg;
800gg = (g >> 2) + (g >> 1);
801if (gg > g) gg = 0;
802b = *pb;
803bb = (b >> 2) + (b >> 1);
804if (bb > b) bb = 0;
805
806*pr = rr;
807*pg = gg;
808*pb = bb;
809}
891 810
892void TextureRender::invert() {
893 register unsigned int i, j, wh = (width * height) - 1;
894 unsigned char tmp;
895
896 for (i = 0, j = wh; j > i; j--, i++) {
897 tmp = *(red + j);
898 *(red + j) = *(red + i);
899 *(red + i) = tmp;
900
901 tmp = *(green + j);
902 *(green + j) = *(green + i);
903 *(green + i) = tmp;
904 811
905 tmp = *(blue + j); 812void TextureRender::bevel2() {
906 *(blue + j) = *(blue + i); 813if (! (width > 4 && height > 4))
907 *(blue + i) = tmp; 814 return;
908 } 815
816unsigned char r, g, b, rr ,gg ,bb, *pr = red + width + 1,
817 *pg = green + width + 1, *pb = blue + width + 1;
818unsigned int w = width - 2, h = height - 1, wh = width * (height - 3);
819
820while (--w) {
821r = *pr;
822rr = r + (r >> 1);
823if (rr < r) rr = ~0;
824g = *pg;
825gg = g + (g >> 1);
826if (gg < g) gg = ~0;
827b = *pb;
828bb = b + (b >> 1);
829if (bb < b) bb = ~0;
830
831*pr = rr;
832*pg = gg;
833*pb = bb;
834
835r = *(pr + wh);
836rr = (r >> 2) + (r >> 1);
837if (rr > r) rr = 0;
838g = *(pg + wh);
839gg = (g >> 2) + (g >> 1);
840if (gg > g) gg = 0;
841b = *(pb + wh);
842bb = (b >> 2) + (b >> 1);
843if (bb > b) bb = 0;
844
845*((pr++) + wh) = rr;
846*((pg++) + wh) = gg;
847*((pb++) + wh) = bb;
909} 848}
910 849
850pr = red + width;
851pg = green + width;
852pb = blue + width;
853
854while (--h) {
855r = *pr;
856rr = r + (r >> 1);
857if (rr < r) rr = ~0;
858g = *pg;
859gg = g + (g >> 1);
860if (gg < g) gg = ~0;
861b = *pb;
862bb = b + (b >> 1);
863if (bb < b) bb = ~0;
864
865*(++pr) = rr;
866*(++pg) = gg;
867*(++pb) = bb;
868
869pr += width - 3;
870pg += width - 3;
871pb += width - 3;
872
873r = *pr;
874rr = (r >> 2) + (r >> 1);
875if (rr > r) rr = 0;
876g = *pg;
877gg = (g >> 2) + (g >> 1);
878if (gg > g) gg = 0;
879b = *pb;
880bb = (b >> 2) + (b >> 1);
881if (bb > b) bb = 0;
882
883*(pr++) = rr;
884*(pg++) = gg;
885*(pb++) = bb;
886
887pr++; pg++; pb++;
888}
889}
911 890
912void TextureRender::dgradient() {
913 // diagonal gradient code was written by Mike Cole <mike@mydot.com>
914 // modified for interlacing by Brad Hughes
915 891
916 float drx, dgx, dbx, dry, dgy, dby, yr = 0.0, yg = 0.0, yb = 0.0, 892void TextureRender::invert() {
917 xr = (float) from->red(), 893register unsigned int i, j, wh = (width * height) - 1;
918 xg = (float) from->green(), 894unsigned char tmp;
919 xb = (float) from->blue();
920 unsigned char *pr = red, *pg = green, *pb = blue;
921 unsigned int w = width * 2, h = height * 2;
922 unsigned int *xt = xtable, *yt = ytable;
923 895
924 register unsigned int x, y; 896for (i = 0, j = wh; j > i; j--, i++) {
897tmp = *(red + j);
898*(red + j) = *(red + i);
899*(red + i) = tmp;
925 900
926 dry = drx = (float) (to->red() - from->red()); 901tmp = *(green + j);
927 dgy = dgx = (float) (to->green() - from->green()); 902*(green + j) = *(green + i);
928 dby = dbx = (float) (to->blue() - from->blue()); 903*(green + i) = tmp;
929 904
930 // Create X table 905tmp = *(blue + j);
931 drx /= w; 906*(blue + j) = *(blue + i);
932 dgx /= w; 907*(blue + i) = tmp;
933 dbx /= w; 908}
934 909}
935 for (x = 0; x < width; x++) {
936 *(xt++) = (unsigned char) (xr);
937 *(xt++) = (unsigned char) (xg);
938 *(xt++) = (unsigned char) (xb);
939
940 xr += drx;
941 xg += dgx;
942 xb += dbx;
943 }
944
945 // Create Y table
946 dry /= h;
947 dgy /= h;
948 dby /= h;
949
950 for (y = 0; y < height; y++) {
951 *(yt++) = ((unsigned char) yr);
952 *(yt++) = ((unsigned char) yg);
953 *(yt++) = ((unsigned char) yb);
954
955 yr += dry;
956 yg += dgy;
957 yb += dby;
958 }
959
960 // Combine tables to create gradient
961
962
963 if (! interlaced) {
964
965
966 // normal dgradient
967 for (yt = ytable, y = 0; y < height; y++, yt += 3) {
968 for (xt = xtable, x = 0; x < width; x++) {
969 *(pr++) = *(xt++) + *(yt);
970 *(pg++) = *(xt++) + *(yt + 1);
971 *(pb++) = *(xt++) + *(yt + 2);
972 }
973 }
974
975 } else {
976 // faked interlacing effect
977 unsigned char channel, channel2;
978
979 for (yt = ytable, y = 0; y < height; y++, yt += 3) {
980 for (xt = xtable, x = 0; x < width; x++) {
981 if (y & 1) {
982 channel = *(xt++) + *(yt);
983 channel2 = (channel >> 1) + (channel >> 2);
984 if (channel2 > channel) channel2 = 0;
985 *(pr++) = channel2;
986
987 channel = *(xt++) + *(yt + 1);
988 channel2 = (channel >> 1) + (channel >> 2);
989 if (channel2 > channel) channel2 = 0;
990 *(pg++) = channel2;
991
992 channel = *(xt++) + *(yt + 2);
993 channel2 = (channel >> 1) + (channel >> 2);
994 if (channel2 > channel) channel2 = 0;
995 *(pb++) = channel2;
996 } else {
997 channel = *(xt++) + *(yt);
998 channel2 = channel + (channel >> 3);
999 if (channel2 < channel) channel2 = ~0;
1000 *(pr++) = channel2;
1001
1002 channel = *(xt++) + *(yt + 1);
1003 channel2 = channel + (channel >> 3);
1004 if (channel2 < channel) channel2 = ~0;
1005 *(pg++) = channel2;
1006
1007 channel = *(xt++) + *(yt + 2);
1008 channel2 = channel + (channel >> 3);
1009 if (channel2 < channel) channel2 = ~0;
1010 *(pb++) = channel2;
1011 }
1012 }
1013 }
1014 }
1015 910
1016 911
912void TextureRender::dgradient() {
913// diagonal gradient code was written by Mike Cole <mike@mydot.com>
914// modified for interlacing by Brad Hughes
915
916float drx, dgx, dbx, dry, dgy, dby, yr = 0.0, yg = 0.0, yb = 0.0,
917 xr = (float) from->red(),
918 xg = (float) from->green(),
919 xb = (float) from->blue();
920unsigned char *pr = red, *pg = green, *pb = blue;
921unsigned int w = width * 2, h = height * 2;
922unsigned int *xt = xtable, *yt = ytable;
923
924register unsigned int x, y;
925
926dry = drx = (float) (to->red() - from->red());
927dgy = dgx = (float) (to->green() - from->green());
928dby = dbx = (float) (to->blue() - from->blue());
929
930// Create X table
931drx /= w;
932dgx /= w;
933dbx /= w;
934
935for (x = 0; x < width; x++) {
936*(xt++) = (unsigned char) (xr);
937*(xt++) = (unsigned char) (xg);
938*(xt++) = (unsigned char) (xb);
939
940xr += drx;
941xg += dgx;
942xb += dbx;
1017} 943}
1018 944
945// Create Y table
946dry /= h;
947dgy /= h;
948dby /= h;
1019 949
1020void TextureRender::hgradient() { 950for (y = 0; y < height; y++) {
1021 float drx, dgx, dbx, 951*(yt++) = ((unsigned char) yr);
1022 xr = (float) from->red(), 952*(yt++) = ((unsigned char) yg);
1023 xg = (float) from->green(), 953*(yt++) = ((unsigned char) yb);
1024 xb = (float) from->blue();
1025 unsigned char *pr = red, *pg = green, *pb = blue;
1026 954
1027 register unsigned int x, y; 955yr += dry;
1028 956yg += dgy;
1029 drx = (float) (to->red() - from->red()); 957yb += dby;
1030 dgx = (float) (to->green() - from->green()); 958}
1031 dbx = (float) (to->blue() - from->blue());
1032 959
1033 drx /= width; 960// Combine tables to create gradient
1034 dgx /= width;
1035 dbx /= width;
1036 961
1037 if (interlaced && height > 2) {
1038 // faked interlacing effect
1039 unsigned char channel, channel2;
1040 962
1041 for (x = 0; x < width; x++, pr++, pg++, pb++) { 963if (! interlaced) {
1042 channel = (unsigned char) xr;
1043 channel2 = (channel >> 1) + (channel >> 2);
1044 if (channel2 > channel) channel2 = 0;
1045 *pr = channel2;
1046 964
1047 channel = (unsigned char) xg;
1048 channel2 = (channel >> 1) + (channel >> 2);
1049 if (channel2 > channel) channel2 = 0;
1050 *pg = channel2;
1051 965
1052 channel = (unsigned char) xb; 966// normal dgradient
1053 channel2 = (channel >> 1) + (channel >> 2); 967for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1054 if (channel2 > channel) channel2 = 0; 968for (xt = xtable, x = 0; x < width; x++) {
1055 *pb = channel2; 969*(pr++) = *(xt++) + *(yt);
970*(pg++) = *(xt++) + *(yt + 1);
971*(pb++) = *(xt++) + *(yt + 2);
972}
973}
1056 974
975} else {
976// faked interlacing effect
977unsigned char channel, channel2;
978
979for (yt = ytable, y = 0; y < height; y++, yt += 3) {
980for (xt = xtable, x = 0; x < width; x++) {
981if (y & 1) {
982channel = *(xt++) + *(yt);
983channel2 = (channel >> 1) + (channel >> 2);
984if (channel2 > channel) channel2 = 0;
985*(pr++) = channel2;
986
987channel = *(xt++) + *(yt + 1);
988channel2 = (channel >> 1) + (channel >> 2);
989if (channel2 > channel) channel2 = 0;
990*(pg++) = channel2;
991
992channel = *(xt++) + *(yt + 2);
993channel2 = (channel >> 1) + (channel >> 2);
994if (channel2 > channel) channel2 = 0;
995*(pb++) = channel2;
996} else {
997channel = *(xt++) + *(yt);
998channel2 = channel + (channel >> 3);
999if (channel2 < channel) channel2 = ~0;
1000*(pr++) = channel2;
1001
1002channel = *(xt++) + *(yt + 1);
1003channel2 = channel + (channel >> 3);
1004if (channel2 < channel) channel2 = ~0;
1005*(pg++) = channel2;
1006
1007channel = *(xt++) + *(yt + 2);
1008channel2 = channel + (channel >> 3);
1009if (channel2 < channel) channel2 = ~0;
1010*(pb++) = channel2;
1011}
1012}
1013}
1014}
1057 1015
1058 channel = (unsigned char) xr;
1059 channel2 = channel + (channel >> 3);
1060 if (channel2 < channel) channel2 = ~0;
1061 *(pr + width) = channel2;
1062 1016
1063 channel = (unsigned char) xg; 1017}
1064 channel2 = channel + (channel >> 3);
1065 if (channel2 < channel) channel2 = ~0;
1066 *(pg + width) = channel2;
1067 1018
1068 channel = (unsigned char) xb;
1069 channel2 = channel + (channel >> 3);
1070 if (channel2 < channel) channel2 = ~0;
1071 *(pb + width) = channel2;
1072 1019
1073 xr += drx; 1020void TextureRender::hgradient() {
1074 xg += dgx; 1021float drx, dgx, dbx,
1075 xb += dbx; 1022 xr = (float) from->red(),
1076 } 1023 xg = (float) from->green(),
1024 xb = (float) from->blue();
1025unsigned char *pr = red, *pg = green, *pb = blue;
1026
1027register unsigned int x, y;
1028
1029drx = (float) (to->red() - from->red());
1030dgx = (float) (to->green() - from->green());
1031dbx = (float) (to->blue() - from->blue());
1032
1033drx /= width;
1034dgx /= width;
1035dbx /= width;
1036
1037if (interlaced && height > 2) {
1038// faked interlacing effect
1039unsigned char channel, channel2;
1040
1041for (x = 0; x < width; x++, pr++, pg++, pb++) {
1042channel = (unsigned char) xr;
1043channel2 = (channel >> 1) + (channel >> 2);
1044if (channel2 > channel) channel2 = 0;
1045*pr = channel2;
1046
1047channel = (unsigned char) xg;
1048channel2 = (channel >> 1) + (channel >> 2);
1049if (channel2 > channel) channel2 = 0;
1050*pg = channel2;
1051
1052channel = (unsigned char) xb;
1053channel2 = (channel >> 1) + (channel >> 2);
1054if (channel2 > channel) channel2 = 0;
1055*pb = channel2;
1056
1057
1058channel = (unsigned char) xr;
1059channel2 = channel + (channel >> 3);
1060if (channel2 < channel) channel2 = ~0;
1061*(pr + width) = channel2;
1062
1063channel = (unsigned char) xg;
1064channel2 = channel + (channel >> 3);
1065if (channel2 < channel) channel2 = ~0;
1066*(pg + width) = channel2;
1067
1068channel = (unsigned char) xb;
1069channel2 = channel + (channel >> 3);
1070if (channel2 < channel) channel2 = ~0;
1071*(pb + width) = channel2;
1072
1073xr += drx;
1074xg += dgx;
1075xb += dbx;
1076}
1077 1077
1078 pr += width; 1078pr += width;
1079 pg += width; 1079pg += width;
1080 pb += width; 1080pb += width;
1081 1081
1082 int offset; 1082int offset;
1083 1083
1084 for (y = 2; y < height; y++, pr += width, pg += width, pb += width) { 1084for (y = 2; y < height; y++, pr += width, pg += width, pb += width) {
1085 if (y & 1) offset = width; else offset = 0; 1085if (y & 1) offset = width; else offset = 0;
1086 1086
1087 memcpy(pr, (red + offset), width); 1087memcpy(pr, (red + offset), width);
1088 memcpy(pg, (green + offset), width); 1088memcpy(pg, (green + offset), width);
1089 memcpy(pb, (blue + offset), width); 1089memcpy(pb, (blue + offset), width);
1090 } 1090}
1091 } else { 1091} else {
1092 1092
1093 // normal hgradient 1093// normal hgradient
1094 for (x = 0; x < width; x++) { 1094for (x = 0; x < width; x++) {
1095 *(pr++) = (unsigned char) (xr); 1095*(pr++) = (unsigned char) (xr);
1096 *(pg++) = (unsigned char) (xg); 1096*(pg++) = (unsigned char) (xg);
1097 *(pb++) = (unsigned char) (xb); 1097*(pb++) = (unsigned char) (xb);
1098 1098
1099 xr += drx; 1099xr += drx;
1100 xg += dgx; 1100xg += dgx;
1101 xb += dbx; 1101xb += dbx;
1102 } 1102}
1103 1103
1104 for (y = 1; y < height; y++, pr += width, pg += width, pb += width) { 1104for (y = 1; y < height; y++, pr += width, pg += width, pb += width) {
1105 memcpy(pr, red, width); 1105memcpy(pr, red, width);
1106 memcpy(pg, green, width); 1106memcpy(pg, green, width);
1107 memcpy(pb, blue, width); 1107memcpy(pb, blue, width);
1108 } 1108}
1109 1109
1110 } 1110}
1111 1111
1112} 1112}
1113 1113
1114 1114
1115void TextureRender::vgradient() { 1115void TextureRender::vgradient() {
1116 float dry, dgy, dby, 1116float dry, dgy, dby,
1117 yr = (float) from->red(), 1117 yr = (float) from->red(),
1118 yg = (float) from->green(), 1118 yg = (float) from->green(),
1119 yb = (float) from->blue(); 1119 yb = (float) from->blue();
1120 unsigned char *pr = red, *pg = green, *pb = blue; 1120unsigned char *pr = red, *pg = green, *pb = blue;
1121
1122register unsigned int y;
1123
1124dry = (float) (to->red() - from->red());
1125dgy = (float) (to->green() - from->green());
1126dby = (float) (to->blue() - from->blue());
1127
1128dry /= height;
1129dgy /= height;
1130dby /= height;
1131
1132if (interlaced) {
1133// faked interlacing effect
1134unsigned char channel, channel2;
1135
1136for (y = 0; y < height; y++, pr += width, pg += width, pb += width) {
1137if (y & 1) {
1138channel = (unsigned char) yr;
1139channel2 = (channel >> 1) + (channel >> 2);
1140if (channel2 > channel) channel2 = 0;
1141memset(pr, channel2, width);
1142
1143channel = (unsigned char) yg;
1144channel2 = (channel >> 1) + (channel >> 2);
1145if (channel2 > channel) channel2 = 0;
1146memset(pg, channel2, width);
1147
1148channel = (unsigned char) yb;
1149channel2 = (channel >> 1) + (channel >> 2);
1150if (channel2 > channel) channel2 = 0;
1151memset(pb, channel2, width);
1152} else {
1153channel = (unsigned char) yr;
1154channel2 = channel + (channel >> 3);
1155if (channel2 < channel) channel2 = ~0;
1156memset(pr, channel2, width);
1157
1158channel = (unsigned char) yg;
1159channel2 = channel + (channel >> 3);
1160if (channel2 < channel) channel2 = ~0;
1161memset(pg, channel2, width);
1162
1163channel = (unsigned char) yb;
1164channel2 = channel + (channel >> 3);
1165if (channel2 < channel) channel2 = ~0;
1166memset(pb, channel2, width);
1167}
1121 1168
1122 register unsigned int y; 1169yr += dry;
1170yg += dgy;
1171yb += dby;
1172}
1173} else {
1174
1175// normal vgradient
1176for (y = 0; y < height; y++, pr += width, pg += width, pb += width) {
1177memset(pr, (unsigned char) yr, width);
1178memset(pg, (unsigned char) yg, width);
1179memset(pb, (unsigned char) yb, width);
1123 1180
1124 dry = (float) (to->red() - from->red()); 1181yr += dry;
1125 dgy = (float) (to->green() - from->green()); 1182yg += dgy;
1126 dby = (float) (to->blue() - from->blue()); 1183yb += dby;
1184}
1185}
1127 1186
1128 dry /= height;
1129 dgy /= height;
1130 dby /= height;
1131 1187
1132 if (interlaced) { 1188}
1133 // faked interlacing effect
1134 unsigned char channel, channel2;
1135 1189
1136 for (y = 0; y < height; y++, pr += width, pg += width, pb += width) {
1137 if (y & 1) {
1138 channel = (unsigned char) yr;
1139 channel2 = (channel >> 1) + (channel >> 2);
1140 if (channel2 > channel) channel2 = 0;
1141 memset(pr, channel2, width);
1142 1190
1143 channel = (unsigned char) yg; 1191void TextureRender::pgradient() {
1144 channel2 = (channel >> 1) + (channel >> 2); 1192// pyramid gradient - based on original dgradient, written by
1145 if (channel2 > channel) channel2 = 0; 1193// Mosfet (mosfet@kde.org)
1146 memset(pg, channel2, width); 1194// adapted from kde sources for Blackbox by Brad Hughes
1147 1195
1148 channel = (unsigned char) yb; 1196float yr, yg, yb, drx, dgx, dbx, dry, dgy, dby,
1149 channel2 = (channel >> 1) + (channel >> 2); 1197 xr, xg, xb;
1150 if (channel2 > channel) channel2 = 0; 1198int rsign, gsign, bsign;
1151 memset(pb, channel2, width); 1199unsigned char *pr = red, *pg = green, *pb = blue;
1152 } else { 1200unsigned int tr = to->red(), tg = to->green(), tb = to->blue();
1153 channel = (unsigned char) yr; 1201unsigned int *xt = xtable, *yt = ytable;
1154 channel2 = channel + (channel >> 3); 1202
1155 if (channel2 < channel) channel2 = ~0; 1203register unsigned int x, y;
1156 memset(pr, channel2, width); 1204
1205dry = drx = (float) (to->red() - from->red());
1206dgy = dgx = (float) (to->green() - from->green());
1207dby = dbx = (float) (to->blue() - from->blue());
1208
1209rsign = (drx < 0) ? -1 : 1;
1210gsign = (dgx < 0) ? -1 : 1;
1211bsign = (dbx < 0) ? -1 : 1;
1212
1213xr = yr = (drx / 2);
1214xg = yg = (dgx / 2);
1215xb = yb = (dbx / 2);
1216
1217// Create X table
1218drx /= width;
1219dgx /= width;
1220dbx /= width;
1221
1222for (x = 0; x < width; x++) {
1223*(xt++) = (unsigned char) ((xr < 0) ? -xr : xr);
1224*(xt++) = (unsigned char) ((xg < 0) ? -xg : xg);
1225*(xt++) = (unsigned char) ((xb < 0) ? -xb : xb);
1226
1227xr -= drx;
1228xg -= dgx;
1229xb -= dbx;
1230}
1157 1231
1158 channel = (unsigned char) yg; 1232// Create Y table
1159 channel2 = channel + (channel >> 3); 1233dry /= height;
1160 if (channel2 < channel) channel2 = ~0; 1234dgy /= height;
1161 memset(pg, channel2, width); 1235dby /= height;
1162 1236
1163 channel = (unsigned char) yb; 1237for (y = 0; y < height; y++) {
1164 channel2 = channel + (channel >> 3); 1238*(yt++) = ((unsigned char) ((yr < 0) ? -yr : yr));
1165 if (channel2 < channel) channel2 = ~0; 1239*(yt++) = ((unsigned char) ((yg < 0) ? -yg : yg));
1166 memset(pb, channel2, width); 1240*(yt++) = ((unsigned char) ((yb < 0) ? -yb : yb));
1167 }
1168 1241
1169 yr += dry; 1242yr -= dry;
1170 yg += dgy; 1243yg -= dgy;
1171 yb += dby; 1244yb -= dby;
1172 } 1245}
1173 } else {
1174 1246
1175 // normal vgradient 1247// Combine tables to create gradient
1176 for (y = 0; y < height; y++, pr += width, pg += width, pb += width) {
1177 memset(pr, (unsigned char) yr, width);
1178 memset(pg, (unsigned char) yg, width);
1179 memset(pb, (unsigned char) yb, width);
1180 1248
1181 yr += dry;
1182 yg += dgy;
1183 yb += dby;
1184 }
1185 }
1186 1249
1250if (! interlaced) {
1187 1251
1252// normal pgradient
1253for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1254for (xt = xtable, x = 0; x < width; x++) {
1255*(pr++) = (unsigned char) (tr - (rsign * (*(xt++) + *(yt))));
1256*(pg++) = (unsigned char) (tg - (gsign * (*(xt++) + *(yt + 1))));
1257*(pb++) = (unsigned char) (tb - (bsign * (*(xt++) + *(yt + 2))));
1258}
1188} 1259}
1189 1260
1261} else {
1262// faked interlacing effect
1263unsigned char channel, channel2;
1264
1265for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1266for (xt = xtable, x = 0; x < width; x++) {
1267if (y & 1) {
1268channel = (unsigned char) (tr - (rsign * (*(xt++) + *(yt))));
1269channel2 = (channel >> 1) + (channel >> 2);
1270if (channel2 > channel) channel2 = 0;
1271*(pr++) = channel2;
1272
1273channel = (unsigned char) (tg - (gsign * (*(xt++) + *(yt + 1))));
1274channel2 = (channel >> 1) + (channel >> 2);
1275if (channel2 > channel) channel2 = 0;
1276*(pg++) = channel2;
1277
1278channel = (unsigned char) (tb - (bsign * (*(xt++) + *(yt + 2))));
1279channel2 = (channel >> 1) + (channel >> 2);
1280if (channel2 > channel) channel2 = 0;
1281*(pb++) = channel2;
1282} else {
1283channel = (unsigned char) (tr - (rsign * (*(xt++) + *(yt))));
1284channel2 = channel + (channel >> 3);
1285if (channel2 < channel) channel2 = ~0;
1286*(pr++) = channel2;
1287
1288channel = (unsigned char) (tg - (gsign * (*(xt++) + *(yt + 1))));
1289channel2 = channel + (channel >> 3);
1290if (channel2 < channel) channel2 = ~0;
1291*(pg++) = channel2;
1292
1293channel = (unsigned char) (tb - (bsign * (*(xt++) + *(yt + 2))));
1294channel2 = channel + (channel >> 3);
1295if (channel2 < channel) channel2 = ~0;
1296*(pb++) = channel2;
1297}
1298}
1299}
1300}
1190 1301
1191void TextureRender::pgradient() { 1302}
1192 // pyramid gradient - based on original dgradient, written by
1193 // Mosfet (mosfet@kde.org)
1194 // adapted from kde sources for Blackbox by Brad Hughes
1195 1303
1196 float yr, yg, yb, drx, dgx, dbx, dry, dgy, dby,
1197 xr, xg, xb;
1198 int rsign, gsign, bsign;
1199 unsigned char *pr = red, *pg = green, *pb = blue;
1200 unsigned int tr = to->red(), tg = to->green(), tb = to->blue();
1201 unsigned int *xt = xtable, *yt = ytable;
1202 1304
1203 register unsigned int x, y; 1305void TextureRender::rgradient() {
1306// rectangle gradient - based on original dgradient, written by
1307// Mosfet (mosfet@kde.org)
1308// adapted from kde sources for Blackbox by Brad Hughes
1309
1310float drx, dgx, dbx, dry, dgy, dby, xr, xg, xb, yr, yg, yb;
1311int rsign, gsign, bsign;
1312unsigned char *pr = red, *pg = green, *pb = blue;
1313unsigned int tr = to->red(), tg = to->green(), tb = to->blue();
1314unsigned int *xt = xtable, *yt = ytable;
1204 1315
1205 dry = drx = (float) (to->red() - from->red()); 1316register unsigned int x, y;
1206 dgy = dgx = (float) (to->green() - from->green());
1207 dby = dbx = (float) (to->blue() - from->blue());
1208 1317
1209 rsign = (drx < 0) ? -1 : 1; 1318dry = drx = (float) (to->red() - from->red());
1210 gsign = (dgx < 0) ? -1 : 1; 1319dgy = dgx = (float) (to->green() - from->green());
1211 bsign = (dbx < 0) ? -1 : 1; 1320dby = dbx = (float) (to->blue() - from->blue());
1212 1321
1213 xr = yr = (drx / 2); 1322rsign = (drx < 0) ? -2 : 2;
1214 xg = yg = (dgx / 2); 1323gsign = (dgx < 0) ? -2 : 2;
1215 xb = yb = (dbx / 2); 1324bsign = (dbx < 0) ? -2 : 2;
1216 1325
1217 // Create X table 1326xr = yr = (drx / 2);
1218 drx /= width; 1327xg = yg = (dgx / 2);
1219 dgx /= width; 1328xb = yb = (dbx / 2);
1220 dbx /= width;
1221
1222 for (x = 0; x < width; x++) {
1223 *(xt++) = (unsigned char) ((xr < 0) ? -xr : xr);
1224 *(xt++) = (unsigned char) ((xg < 0) ? -xg : xg);
1225 *(xt++) = (unsigned char) ((xb < 0) ? -xb : xb);
1226
1227 xr -= drx;
1228 xg -= dgx;
1229 xb -= dbx;
1230 }
1231
1232 // Create Y table
1233 dry /= height;
1234 dgy /= height;
1235 dby /= height;
1236
1237 for (y = 0; y < height; y++) {
1238 *(yt++) = ((unsigned char) ((yr < 0) ? -yr : yr));
1239 *(yt++) = ((unsigned char) ((yg < 0) ? -yg : yg));
1240 *(yt++) = ((unsigned char) ((yb < 0) ? -yb : yb));
1241
1242 yr -= dry;
1243 yg -= dgy;
1244 yb -= dby;
1245 }
1246
1247 // Combine tables to create gradient
1248
1249
1250 if (! interlaced) {
1251
1252 // normal pgradient
1253 for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1254 for (xt = xtable, x = 0; x < width; x++) {
1255 *(pr++) = (unsigned char) (tr - (rsign * (*(xt++) + *(yt))));
1256 *(pg++) = (unsigned char) (tg - (gsign * (*(xt++) + *(yt + 1))));
1257 *(pb++) = (unsigned char) (tb - (bsign * (*(xt++) + *(yt + 2))));
1258 }
1259 }
1260
1261 } else {
1262 // faked interlacing effect
1263 unsigned char channel, channel2;
1264
1265 for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1266 for (xt = xtable, x = 0; x < width; x++) {
1267 if (y & 1) {
1268 channel = (unsigned char) (tr - (rsign * (*(xt++) + *(yt))));
1269 channel2 = (channel >> 1) + (channel >> 2);
1270 if (channel2 > channel) channel2 = 0;
1271 *(pr++) = channel2;
1272
1273 channel = (unsigned char) (tg - (gsign * (*(xt++) + *(yt + 1))));
1274 channel2 = (channel >> 1) + (channel >> 2);
1275 if (channel2 > channel) channel2 = 0;
1276 *(pg++) = channel2;
1277
1278 channel = (unsigned char) (tb - (bsign * (*(xt++) + *(yt + 2))));
1279 channel2 = (channel >> 1) + (channel >> 2);
1280 if (channel2 > channel) channel2 = 0;
1281 *(pb++) = channel2;
1282 } else {
1283 channel = (unsigned char) (tr - (rsign * (*(xt++) + *(yt))));
1284 channel2 = channel + (channel >> 3);
1285 if (channel2 < channel) channel2 = ~0;
1286 *(pr++) = channel2;
1287
1288 channel = (unsigned char) (tg - (gsign * (*(xt++) + *(yt + 1))));
1289 channel2 = channel + (channel >> 3);
1290 if (channel2 < channel) channel2 = ~0;
1291 *(pg++) = channel2;
1292
1293 channel = (unsigned char) (tb - (bsign * (*(xt++) + *(yt + 2))));
1294 channel2 = channel + (channel >> 3);
1295 if (channel2 < channel) channel2 = ~0;
1296 *(pb++) = channel2;
1297 }
1298 }
1299 }
1300 }
1301 1329
1330 // Create X table
1331drx /= width;
1332dgx /= width;
1333dbx /= width;
1334
1335for (x = 0; x < width; x++) {
1336*(xt++) = (unsigned char) ((xr < 0) ? -xr : xr);
1337*(xt++) = (unsigned char) ((xg < 0) ? -xg : xg);
1338*(xt++) = (unsigned char) ((xb < 0) ? -xb : xb);
1339
1340xr -= drx;
1341xg -= dgx;
1342xb -= dbx;
1302} 1343}
1303 1344
1345// Create Y table
1346dry /= height;
1347dgy /= height;
1348dby /= height;
1304 1349
1305void TextureRender::rgradient() { 1350for (y = 0; y < height; y++) {
1306 // rectangle gradient - based on original dgradient, written by 1351*(yt++) = ((unsigned char) ((yr < 0) ? -yr : yr));
1307 // Mosfet (mosfet@kde.org) 1352*(yt++) = ((unsigned char) ((yg < 0) ? -yg : yg));
1308 // adapted from kde sources for Blackbox by Brad Hughes 1353*(yt++) = ((unsigned char) ((yb < 0) ? -yb : yb));
1309 1354
1310 float drx, dgx, dbx, dry, dgy, dby, xr, xg, xb, yr, yg, yb; 1355yr -= dry;
1311 int rsign, gsign, bsign; 1356yg -= dgy;
1312 unsigned char *pr = red, *pg = green, *pb = blue; 1357yb -= dby;
1313 unsigned int tr = to->red(), tg = to->green(), tb = to->blue(); 1358}
1314 unsigned int *xt = xtable, *yt = ytable;
1315 1359
1316 register unsigned int x, y; 1360// Combine tables to create gradient
1317 1361
1318 dry = drx = (float) (to->red() - from->red());
1319 dgy = dgx = (float) (to->green() - from->green());
1320 dby = dbx = (float) (to->blue() - from->blue());
1321 1362
1322 rsign = (drx < 0) ? -2 : 2; 1363if (! interlaced) {
1323 gsign = (dgx < 0) ? -2 : 2;
1324 bsign = (dbx < 0) ? -2 : 2;
1325 1364
1326 xr = yr = (drx / 2); 1365// normal rgradient
1327 xg = yg = (dgx / 2); 1366for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1328 xb = yb = (dbx / 2); 1367for (xt = xtable, x = 0; x < width; x++) {
1368*(pr++) = (unsigned char) (tr - (rsign * std::max(*(xt++), *(yt))));
1369*(pg++) = (unsigned char) (tg - (gsign * std::max(*(xt++), *(yt + 1))));
1370*(pb++) = (unsigned char) (tb - (bsign * std::max(*(xt++), *(yt + 2))));
1371}
1372}
1329 1373
1330 // Create X table 1374} else {
1331 drx /= width; 1375// faked interlacing effect
1332 dgx /= width; 1376unsigned char channel, channel2;
1333 dbx /= width; 1377
1334 1378for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1335 for (x = 0; x < width; x++) { 1379for (xt = xtable, x = 0; x < width; x++) {
1336 *(xt++) = (unsigned char) ((xr < 0) ? -xr : xr); 1380if (y & 1) {
1337 *(xt++) = (unsigned char) ((xg < 0) ? -xg : xg); 1381channel = (unsigned char) (tr - (rsign * std::max(*(xt++), *(yt))));
1338 *(xt++) = (unsigned char) ((xb < 0) ? -xb : xb); 1382channel2 = (channel >> 1) + (channel >> 2);
1339 1383if (channel2 > channel) channel2 = 0;
1340 xr -= drx; 1384*(pr++) = channel2;
1341 xg -= dgx; 1385
1342 xb -= dbx; 1386channel = (unsigned char) (tg - (gsign * std::max(*(xt++), *(yt + 1))));
1343 } 1387channel2 = (channel >> 1) + (channel >> 2);
1344 1388if (channel2 > channel) channel2 = 0;
1345 // Create Y table 1389*(pg++) = channel2;
1346 dry /= height; 1390
1347 dgy /= height; 1391channel = (unsigned char) (tb - (bsign * std::max(*(xt++), *(yt + 2))));
1348 dby /= height; 1392channel2 = (channel >> 1) + (channel >> 2);
1349 1393if (channel2 > channel) channel2 = 0;
1350 for (y = 0; y < height; y++) { 1394*(pb++) = channel2;
1351 *(yt++) = ((unsigned char) ((yr < 0) ? -yr : yr)); 1395} else {
1352 *(yt++) = ((unsigned char) ((yg < 0) ? -yg : yg)); 1396channel = (unsigned char) (tr - (rsign * std::max(*(xt++), *(yt))));
1353 *(yt++) = ((unsigned char) ((yb < 0) ? -yb : yb)); 1397channel2 = channel + (channel >> 3);
1354 1398if (channel2 < channel) channel2 = ~0;
1355 yr -= dry; 1399*(pr++) = channel2;
1356 yg -= dgy; 1400
1357 yb -= dby; 1401channel = (unsigned char) (tg - (gsign * std::max(*(xt++), *(yt + 1))));
1358 } 1402channel2 = channel + (channel >> 3);
1359 1403if (channel2 < channel) channel2 = ~0;
1360 // Combine tables to create gradient 1404*(pg++) = channel2;
1361 1405
1362 1406channel = (unsigned char) (tb - (bsign * std::max(*(xt++), *(yt + 2))));
1363 if (! interlaced) { 1407channel2 = channel + (channel >> 3);
1364 1408if (channel2 < channel) channel2 = ~0;
1365 // normal rgradient 1409*(pb++) = channel2;
1366 for (yt = ytable, y = 0; y < height; y++, yt += 3) { 1410}
1367 for (xt = xtable, x = 0; x < width; x++) { 1411}
1368 *(pr++) = (unsigned char) (tr - (rsign * std::max(*(xt++), *(yt)))); 1412}
1369 *(pg++) = (unsigned char) (tg - (gsign * std::max(*(xt++), *(yt + 1)))); 1413}
1370 *(pb++) = (unsigned char) (tb - (bsign * std::max(*(xt++), *(yt + 2))));
1371 }
1372 }
1373
1374 } else {
1375 // faked interlacing effect
1376 unsigned char channel, channel2;
1377
1378 for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1379 for (xt = xtable, x = 0; x < width; x++) {
1380 if (y & 1) {
1381 channel = (unsigned char) (tr - (rsign * std::max(*(xt++), *(yt))));
1382 channel2 = (channel >> 1) + (channel >> 2);
1383 if (channel2 > channel) channel2 = 0;
1384 *(pr++) = channel2;
1385
1386 channel = (unsigned char) (tg - (gsign * std::max(*(xt++), *(yt + 1))));
1387 channel2 = (channel >> 1) + (channel >> 2);
1388 if (channel2 > channel) channel2 = 0;
1389 *(pg++) = channel2;
1390
1391 channel = (unsigned char) (tb - (bsign * std::max(*(xt++), *(yt + 2))));
1392 channel2 = (channel >> 1) + (channel >> 2);
1393 if (channel2 > channel) channel2 = 0;
1394 *(pb++) = channel2;
1395 } else {
1396 channel = (unsigned char) (tr - (rsign * std::max(*(xt++), *(yt))));
1397 channel2 = channel + (channel >> 3);
1398 if (channel2 < channel) channel2 = ~0;
1399 *(pr++) = channel2;
1400
1401 channel = (unsigned char) (tg - (gsign * std::max(*(xt++), *(yt + 1))));
1402 channel2 = channel + (channel >> 3);
1403 if (channel2 < channel) channel2 = ~0;
1404 *(pg++) = channel2;
1405
1406 channel = (unsigned char) (tb - (bsign * std::max(*(xt++), *(yt + 2))));
1407 channel2 = channel + (channel >> 3);
1408 if (channel2 < channel) channel2 = ~0;
1409 *(pb++) = channel2;
1410 }
1411 }
1412 }
1413 }
1414 1414
1415} 1415}
1416 1416
1417 1417
1418void TextureRender::egradient() { 1418void TextureRender::egradient() {
1419 // elliptic gradient - based on original dgradient, written by 1419// elliptic gradient - based on original dgradient, written by
1420 // Mosfet (mosfet@kde.org) 1420// Mosfet (mosfet@kde.org)
1421 // adapted from kde sources for Blackbox by Brad Hughes 1421// adapted from kde sources for Blackbox by Brad Hughes
1422 1422
1423 float drx, dgx, dbx, dry, dgy, dby, yr, yg, yb, xr, xg, xb; 1423float drx, dgx, dbx, dry, dgy, dby, yr, yg, yb, xr, xg, xb;
1424 int rsign, gsign, bsign; 1424int rsign, gsign, bsign;
1425 unsigned char *pr = red, *pg = green, *pb = blue; 1425unsigned char *pr = red, *pg = green, *pb = blue;
1426 unsigned int *xt = xtable, *yt = ytable; 1426unsigned int *xt = xtable, *yt = ytable;
1427 unsigned int tr = (unsigned long) to->red(), 1427unsigned int tr = (unsigned long) to->red(),
1428 tg = (unsigned long) to->green(), 1428 tg = (unsigned long) to->green(),
1429 tb = (unsigned long) to->blue(); 1429 tb = (unsigned long) to->blue();
1430 1430
1431 register unsigned int x, y; 1431register unsigned int x, y;
1432 1432
1433 dry = drx = (float) (to->red() - from->red()); 1433dry = drx = (float) (to->red() - from->red());
1434 dgy = dgx = (float) (to->green() - from->green()); 1434dgy = dgx = (float) (to->green() - from->green());
1435 dby = dbx = (float) (to->blue() - from->blue()); 1435dby = dbx = (float) (to->blue() - from->blue());
1436 1436
1437 rsign = (drx < 0) ? -1 : 1; 1437rsign = (drx < 0) ? -1 : 1;
1438 gsign = (dgx < 0) ? -1 : 1; 1438gsign = (dgx < 0) ? -1 : 1;
1439 bsign = (dbx < 0) ? -1 : 1; 1439bsign = (dbx < 0) ? -1 : 1;
1440 1440
1441 xr = yr = (drx / 2); 1441xr = yr = (drx / 2);
1442 xg = yg = (dgx / 2); 1442xg = yg = (dgx / 2);
1443 xb = yb = (dbx / 2); 1443xb = yb = (dbx / 2);
1444 1444
1445 // Create X table 1445 // Create X table
1446 drx /= width; 1446drx /= width;
1447 dgx /= width; 1447dgx /= width;
1448 dbx /= width; 1448dbx /= width;
1449 1449
1450 for (x = 0; x < width; x++) { 1450for (x = 0; x < width; x++) {
1451 *(xt++) = (unsigned long) (xr * xr); 1451*(xt++) = (unsigned long) (xr * xr);
1452 *(xt++) = (unsigned long) (xg * xg); 1452*(xt++) = (unsigned long) (xg * xg);
1453 *(xt++) = (unsigned long) (xb * xb); 1453*(xt++) = (unsigned long) (xb * xb);
1454 1454
1455 xr -= drx; 1455xr -= drx;
1456 xg -= dgx; 1456xg -= dgx;
1457 xb -= dbx; 1457xb -= dbx;
1458 } 1458}
1459 1459
1460 // Create Y table 1460// Create Y table
1461 dry /= height; 1461dry /= height;
1462 dgy /= height; 1462dgy /= height;
1463 dby /= height; 1463dby /= height;
1464 1464
1465 for (y = 0; y < height; y++) { 1465for (y = 0; y < height; y++) {
1466 *(yt++) = (unsigned long) (yr * yr); 1466*(yt++) = (unsigned long) (yr * yr);
1467 *(yt++) = (unsigned long) (yg * yg); 1467*(yt++) = (unsigned long) (yg * yg);
1468 *(yt++) = (unsigned long) (yb * yb); 1468*(yt++) = (unsigned long) (yb * yb);
1469 1469
1470 yr -= dry; 1470yr -= dry;
1471 yg -= dgy; 1471yg -= dgy;
1472 yb -= dby; 1472yb -= dby;
1473 } 1473}
1474 1474
1475 // Combine tables to create gradient 1475// Combine tables to create gradient
1476 if (! interlaced) { 1476if (! interlaced) {
1477 // normal egradient 1477// normal egradient
1478 for (yt = ytable, y = 0; y < height; y++, yt += 3) { 1478for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1479 for (xt = xtable, x = 0; x < width; x++) { 1479for (xt = xtable, x = 0; x < width; x++) {
1480 *(pr++) = (unsigned char) 1480*(pr++) = (unsigned char)
1481 (tr - (rsign * control.getSqrt(*(xt++) + *(yt)))); 1481 (tr - (rsign * control.getSqrt(*(xt++) + *(yt))));
1482 *(pg++) = (unsigned char) 1482*(pg++) = (unsigned char)
1483 (tg - (gsign * control.getSqrt(*(xt++) + *(yt + 1)))); 1483 (tg - (gsign * control.getSqrt(*(xt++) + *(yt + 1))));
1484 *(pb++) = (unsigned char) 1484*(pb++) = (unsigned char)
1485 (tb - (bsign * control.getSqrt(*(xt++) + *(yt + 2)))); 1485 (tb - (bsign * control.getSqrt(*(xt++) + *(yt + 2))));
1486 } 1486}
1487 } 1487}
1488 1488
1489 } else { 1489} else {
1490 // faked interlacing effect 1490// faked interlacing effect
1491 unsigned char channel, channel2; 1491unsigned char channel, channel2;
1492 1492
1493 for (yt = ytable, y = 0; y < height; y++, yt += 3) { 1493for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1494 for (xt = xtable, x = 0; x < width; x++) { 1494for (xt = xtable, x = 0; x < width; x++) {
1495 if (y & 1) { 1495if (y & 1) {
1496 channel = (unsigned char) 1496channel = (unsigned char)
1497 (tr - (rsign * control.getSqrt(*(xt++) + *(yt)))); 1497 (tr - (rsign * control.getSqrt(*(xt++) + *(yt))));
1498 channel2 = (channel >> 1) + (channel >> 2); 1498channel2 = (channel >> 1) + (channel >> 2);
1499 if (channel2 > channel) channel2 = 0; 1499if (channel2 > channel) channel2 = 0;
1500 *(pr++) = channel2; 1500*(pr++) = channel2;
1501 1501
1502 channel = (unsigned char) 1502channel = (unsigned char)
1503 (tg - (gsign * control.getSqrt(*(xt++) + *(yt + 1)))); 1503 (tg - (gsign * control.getSqrt(*(xt++) + *(yt + 1))));
1504 channel2 = (channel >> 1) + (channel >> 2); 1504channel2 = (channel >> 1) + (channel >> 2);
1505 if (channel2 > channel) channel2 = 0; 1505if (channel2 > channel) channel2 = 0;
1506 *(pg++) = channel2; 1506*(pg++) = channel2;
1507 1507
1508 channel = (unsigned char) 1508channel = (unsigned char)
1509 (tb - (bsign * control.getSqrt(*(xt++) + *(yt + 2)))); 1509 (tb - (bsign * control.getSqrt(*(xt++) + *(yt + 2))));
1510 channel2 = (channel >> 1) + (channel >> 2); 1510channel2 = (channel >> 1) + (channel >> 2);
1511 if (channel2 > channel) channel2 = 0; 1511if (channel2 > channel) channel2 = 0;
1512 *(pb++) = channel2; 1512*(pb++) = channel2;
1513 } else { 1513} else {
1514 channel = (unsigned char) 1514channel = (unsigned char)
1515 (tr - (rsign * control.getSqrt(*(xt++) + *(yt)))); 1515 (tr - (rsign * control.getSqrt(*(xt++) + *(yt))));
1516 channel2 = channel + (channel >> 3); 1516channel2 = channel + (channel >> 3);
1517 if (channel2 < channel) channel2 = ~0; 1517if (channel2 < channel) channel2 = ~0;
1518 *(pr++) = channel2; 1518*(pr++) = channel2;
1519 1519
1520 channel = (unsigned char) 1520channel = (unsigned char)
1521 (tg - (gsign * control.getSqrt(*(xt++) + *(yt + 1)))); 1521 (tg - (gsign * control.getSqrt(*(xt++) + *(yt + 1))));
1522 channel2 = channel + (channel >> 3); 1522channel2 = channel + (channel >> 3);
1523 if (channel2 < channel) channel2 = ~0; 1523if (channel2 < channel) channel2 = ~0;
1524 *(pg++) = channel2; 1524*(pg++) = channel2;
1525 1525
1526 channel = (unsigned char) 1526channel = (unsigned char)
1527 (tb - (bsign * control.getSqrt(*(xt++) + *(yt + 2)))); 1527 (tb - (bsign * control.getSqrt(*(xt++) + *(yt + 2))));
1528 channel2 = channel + (channel >> 3); 1528channel2 = channel + (channel >> 3);
1529 if (channel2 < channel) channel2 = ~0; 1529if (channel2 < channel) channel2 = ~0;
1530 *(pb++) = channel2; 1530*(pb++) = channel2;
1531 } 1531}
1532 } 1532}
1533 } 1533}
1534 } 1534}
1535 1535
1536} 1536}
1537 1537
1538 1538
1539void TextureRender::pcgradient() { 1539void TextureRender::pcgradient() {
1540 // pipe cross gradient - based on original dgradient, written by 1540// pipe cross gradient - based on original dgradient, written by
1541 // Mosfet (mosfet@kde.org) 1541// Mosfet (mosfet@kde.org)
1542 // adapted from kde sources for Blackbox by Brad Hughes 1542// adapted from kde sources for Blackbox by Brad Hughes
1543 1543
1544 float drx, dgx, dbx, dry, dgy, dby, xr, xg, xb, yr, yg, yb; 1544float drx, dgx, dbx, dry, dgy, dby, xr, xg, xb, yr, yg, yb;
1545 int rsign, gsign, bsign; 1545int rsign, gsign, bsign;
1546 unsigned char *pr = red, *pg = green, *pb = blue; 1546unsigned char *pr = red, *pg = green, *pb = blue;
1547 unsigned int *xt = xtable, *yt = ytable; 1547unsigned int *xt = xtable, *yt = ytable;
1548 unsigned int tr = to->red(), 1548unsigned int tr = to->red(),
1549 tg = to->green(), 1549 tg = to->green(),
1550 tb = to->blue(); 1550 tb = to->blue();
1551 1551
1552 register unsigned int x, y; 1552register unsigned int x, y;
1553 1553
1554 dry = drx = (float) (to->red() - from->red()); 1554dry = drx = (float) (to->red() - from->red());
1555 dgy = dgx = (float) (to->green() - from->green()); 1555dgy = dgx = (float) (to->green() - from->green());
1556 dby = dbx = (float) (to->blue() - from->blue()); 1556dby = dbx = (float) (to->blue() - from->blue());
1557 1557
1558 rsign = (drx < 0) ? -2 : 2; 1558rsign = (drx < 0) ? -2 : 2;
1559 gsign = (dgx < 0) ? -2 : 2; 1559gsign = (dgx < 0) ? -2 : 2;
1560 bsign = (dbx < 0) ? -2 : 2; 1560bsign = (dbx < 0) ? -2 : 2;
1561 1561
1562 xr = yr = (drx / 2); 1562xr = yr = (drx / 2);
1563 xg = yg = (dgx / 2); 1563xg = yg = (dgx / 2);
1564 xb = yb = (dbx / 2); 1564xb = yb = (dbx / 2);
1565 1565
1566 // Create X table 1566 // Create X table
1567 drx /= width; 1567drx /= width;
1568 dgx /= width; 1568dgx /= width;
1569 dbx /= width; 1569dbx /= width;
1570 1570
1571 for (x = 0; x < width; x++) { 1571for (x = 0; x < width; x++) {
1572 *(xt++) = (unsigned char) ((xr < 0) ? -xr : xr); 1572*(xt++) = (unsigned char) ((xr < 0) ? -xr : xr);
1573 *(xt++) = (unsigned char) ((xg < 0) ? -xg : xg); 1573*(xt++) = (unsigned char) ((xg < 0) ? -xg : xg);
1574 *(xt++) = (unsigned char) ((xb < 0) ? -xb : xb); 1574*(xt++) = (unsigned char) ((xb < 0) ? -xb : xb);
1575 1575
1576 xr -= drx; 1576xr -= drx;
1577 xg -= dgx; 1577xg -= dgx;
1578 xb -= dbx; 1578xb -= dbx;
1579 } 1579}
1580 1580
1581 // Create Y table 1581// Create Y table
1582 dry /= height; 1582dry /= height;
1583 dgy /= height; 1583dgy /= height;
1584 dby /= height; 1584dby /= height;
1585 1585
1586 for (y = 0; y < height; y++) { 1586for (y = 0; y < height; y++) {
1587 *(yt++) = ((unsigned char) ((yr < 0) ? -yr : yr)); 1587*(yt++) = ((unsigned char) ((yr < 0) ? -yr : yr));
1588 *(yt++) = ((unsigned char) ((yg < 0) ? -yg : yg)); 1588*(yt++) = ((unsigned char) ((yg < 0) ? -yg : yg));
1589 *(yt++) = ((unsigned char) ((yb < 0) ? -yb : yb)); 1589*(yt++) = ((unsigned char) ((yb < 0) ? -yb : yb));
1590 1590
1591 yr -= dry; 1591yr -= dry;
1592 yg -= dgy; 1592yg -= dgy;
1593 yb -= dby; 1593yb -= dby;
1594 } 1594}
1595 1595
1596 // Combine tables to create gradient 1596// Combine tables to create gradient
1597 if (! interlaced) { 1597if (! interlaced) {
1598 1598
1599 // normal pcgradient 1599// normal pcgradient
1600 for (yt = ytable, y = 0; y < height; y++, yt += 3) { 1600for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1601 for (xt = xtable, x = 0; x < width; x++) { 1601for (xt = xtable, x = 0; x < width; x++) {
1602 *(pr++) = (unsigned char) (tr - (rsign * std::min(*(xt++), *(yt)))); 1602*(pr++) = (unsigned char) (tr - (rsign * std::min(*(xt++), *(yt))));
1603 *(pg++) = (unsigned char) (tg - (gsign * std::min(*(xt++), *(yt + 1)))); 1603*(pg++) = (unsigned char) (tg - (gsign * std::min(*(xt++), *(yt + 1))));
1604 *(pb++) = (unsigned char) (tb - (bsign * std::min(*(xt++), *(yt + 2)))); 1604*(pb++) = (unsigned char) (tb - (bsign * std::min(*(xt++), *(yt + 2))));
1605 } 1605}
1606 } 1606}
1607 1607
1608 } else { 1608} else {
1609 // faked interlacing effect 1609// faked interlacing effect
1610 unsigned char channel, channel2; 1610unsigned char channel, channel2;
1611 1611
1612 for (yt = ytable, y = 0; y < height; y++, yt += 3) { 1612for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1613 for (xt = xtable, x = 0; x < width; x++) { 1613for (xt = xtable, x = 0; x < width; x++) {
1614 if (y & 1) { 1614if (y & 1) {
1615 channel = (unsigned char) (tr - (rsign * std::min(*(xt++), *(yt)))); 1615channel = (unsigned char) (tr - (rsign * std::min(*(xt++), *(yt))));
1616 channel2 = (channel >> 1) + (channel >> 2); 1616channel2 = (channel >> 1) + (channel >> 2);
1617 if (channel2 > channel) channel2 = 0; 1617if (channel2 > channel) channel2 = 0;
1618 *(pr++) = channel2; 1618*(pr++) = channel2;
1619 1619
1620 channel = (unsigned char) (tg - (bsign * std::min(*(xt++), *(yt + 1)))); 1620channel = (unsigned char) (tg - (bsign * std::min(*(xt++), *(yt + 1))));
1621 channel2 = (channel >> 1) + (channel >> 2); 1621channel2 = (channel >> 1) + (channel >> 2);
1622 if (channel2 > channel) channel2 = 0; 1622if (channel2 > channel) channel2 = 0;
1623 *(pg++) = channel2; 1623*(pg++) = channel2;
1624 1624
1625 channel = (unsigned char) (tb - (gsign * std::min(*(xt++), *(yt + 2)))); 1625channel = (unsigned char) (tb - (gsign * std::min(*(xt++), *(yt + 2))));
1626 channel2 = (channel >> 1) + (channel >> 2); 1626channel2 = (channel >> 1) + (channel >> 2);
1627 if (channel2 > channel) channel2 = 0; 1627if (channel2 > channel) channel2 = 0;
1628 *(pb++) = channel2; 1628*(pb++) = channel2;
1629 } else { 1629} else {
1630 channel = (unsigned char) (tr - (rsign * std::min(*(xt++), *(yt)))); 1630channel = (unsigned char) (tr - (rsign * std::min(*(xt++), *(yt))));
1631 channel2 = channel + (channel >> 3); 1631channel2 = channel + (channel >> 3);
1632 if (channel2 < channel) channel2 = ~0; 1632if (channel2 < channel) channel2 = ~0;
1633 *(pr++) = channel2; 1633*(pr++) = channel2;
1634 1634
1635 channel = (unsigned char) (tg - (gsign * std::min(*(xt++), *(yt + 1)))); 1635channel = (unsigned char) (tg - (gsign * std::min(*(xt++), *(yt + 1))));
1636 channel2 = channel + (channel >> 3); 1636channel2 = channel + (channel >> 3);
1637 if (channel2 < channel) channel2 = ~0; 1637if (channel2 < channel) channel2 = ~0;
1638 *(pg++) = channel2; 1638*(pg++) = channel2;
1639 1639
1640 channel = (unsigned char) (tb - (bsign * std::min(*(xt++), *(yt + 2)))); 1640channel = (unsigned char) (tb - (bsign * std::min(*(xt++), *(yt + 2))));
1641 channel2 = channel + (channel >> 3); 1641channel2 = channel + (channel >> 3);
1642 if (channel2 < channel) channel2 = ~0; 1642if (channel2 < channel) channel2 = ~0;
1643 *(pb++) = channel2; 1643*(pb++) = channel2;
1644 } 1644}
1645 } 1645}
1646 } 1646}
1647 } 1647}
1648 1648
1649} 1649}
1650 1650
1651 1651
1652void TextureRender::cdgradient() { 1652void TextureRender::cdgradient() {
1653 // cross diagonal gradient - based on original dgradient, written by 1653// cross diagonal gradient - based on original dgradient, written by
1654 // Mosfet (mosfet@kde.org) 1654// Mosfet (mosfet@kde.org)
1655 // adapted from kde sources for Blackbox by Brad Hughes 1655// adapted from kde sources for Blackbox by Brad Hughes
1656
1657float drx, dgx, dbx, dry, dgy, dby, yr = 0.0, yg = 0.0, yb = 0.0,
1658 xr = (float) from->red(),
1659 xg = (float) from->green(),
1660 xb = (float) from->blue();
1661unsigned char *pr = red, *pg = green, *pb = blue;
1662unsigned int w = width * 2, h = height * 2, *xt, *yt;
1663
1664register unsigned int x, y;
1665
1666dry = drx = (float) (to->red() - from->red());
1667dgy = dgx = (float) (to->green() - from->green());
1668dby = dbx = (float) (to->blue() - from->blue());
1669
1670// Create X table
1671drx /= w;
1672dgx /= w;
1673dbx /= w;
1674
1675for (xt = (xtable + (width * 3) - 1), x = 0; x < width; x++) {
1676*(xt--) = (unsigned char) xb;
1677*(xt--) = (unsigned char) xg;
1678*(xt--) = (unsigned char) xr;
1679
1680xr += drx;
1681xg += dgx;
1682xb += dbx;
1683}
1656 1684
1657 float drx, dgx, dbx, dry, dgy, dby, yr = 0.0, yg = 0.0, yb = 0.0, 1685// Create Y table
1658 xr = (float) from->red(), 1686dry /= h;
1659 xg = (float) from->green(), 1687dgy /= h;
1660 xb = (float) from->blue(); 1688dby /= h;
1661 unsigned char *pr = red, *pg = green, *pb = blue;
1662 unsigned int w = width * 2, h = height * 2, *xt, *yt;
1663 1689
1664 register unsigned int x, y; 1690for (yt = ytable, y = 0; y < height; y++) {
1691*(yt++) = (unsigned char) yr;
1692*(yt++) = (unsigned char) yg;
1693*(yt++) = (unsigned char) yb;
1665 1694
1666 dry = drx = (float) (to->red() - from->red()); 1695yr += dry;
1667 dgy = dgx = (float) (to->green() - from->green()); 1696yg += dgy;
1668 dby = dbx = (float) (to->blue() - from->blue()); 1697yb += dby;
1698}
1669 1699
1670 // Create X table 1700// Combine tables to create gradient
1671 drx /= w; 1701
1672 dgx /= w; 1702if (! interlaced) {
1673 dbx /= w; 1703// normal cdgradient
1674 1704for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1675 for (xt = (xtable + (width * 3) - 1), x = 0; x < width; x++) { 1705for (xt = xtable, x = 0; x < width; x++) {
1676 *(xt--) = (unsigned char) xb; 1706*(pr++) = *(xt++) + *(yt);
1677 *(xt--) = (unsigned char) xg; 1707*(pg++) = *(xt++) + *(yt + 1);
1678 *(xt--) = (unsigned char) xr; 1708*(pb++) = *(xt++) + *(yt + 2);
1679 1709}
1680 xr += drx; 1710}
1681 xg += dgx; 1711
1682 xb += dbx; 1712} else {
1683 } 1713// faked interlacing effect
1684 1714unsigned char channel, channel2;
1685 // Create Y table 1715
1686 dry /= h; 1716for (yt = ytable, y = 0; y < height; y++, yt += 3) {
1687 dgy /= h; 1717for (xt = xtable, x = 0; x < width; x++) {
1688 dby /= h; 1718if (y & 1) {
1689 1719channel = *(xt++) + *(yt);
1690 for (yt = ytable, y = 0; y < height; y++) { 1720channel2 = (channel >> 1) + (channel >> 2);
1691 *(yt++) = (unsigned char) yr; 1721if (channel2 > channel) channel2 = 0;
1692 *(yt++) = (unsigned char) yg; 1722*(pr++) = channel2;
1693 *(yt++) = (unsigned char) yb; 1723
1694 1724channel = *(xt++) + *(yt + 1);
1695 yr += dry; 1725channel2 = (channel >> 1) + (channel >> 2);
1696 yg += dgy; 1726if (channel2 > channel) channel2 = 0;
1697 yb += dby; 1727*(pg++) = channel2;
1698 } 1728
1699 1729channel = *(xt++) + *(yt + 2);
1700 // Combine tables to create gradient 1730channel2 = (channel >> 1) + (channel >> 2);
1701 1731if (channel2 > channel) channel2 = 0;
1702 if (! interlaced) { 1732*(pb++) = channel2;
1703 // normal cdgradient 1733} else {
1704 for (yt = ytable, y = 0; y < height; y++, yt += 3) { 1734channel = *(xt++) + *(yt);
1705 for (xt = xtable, x = 0; x < width; x++) { 1735channel2 = channel + (channel >> 3);
1706 *(pr++) = *(xt++) + *(yt); 1736if (channel2 < channel) channel2 = ~0;
1707 *(pg++) = *(xt++) + *(yt + 1); 1737*(pr++) = channel2;
1708 *(pb++) = *(xt++) + *(yt + 2); 1738
1709 } 1739channel = *(xt++) + *(yt + 1);
1710 } 1740channel2 = channel + (channel >> 3);
1711 1741if (channel2 < channel) channel2 = ~0;
1712 } else { 1742*(pg++) = channel2;
1713 // faked interlacing effect 1743
1714 unsigned char channel, channel2; 1744channel = *(xt++) + *(yt + 2);
1715 1745channel2 = channel + (channel >> 3);
1716 for (yt = ytable, y = 0; y < height; y++, yt += 3) { 1746if (channel2 < channel) channel2 = ~0;
1717 for (xt = xtable, x = 0; x < width; x++) { 1747*(pb++) = channel2;
1718 if (y & 1) { 1748}
1719 channel = *(xt++) + *(yt); 1749}
1720 channel2 = (channel >> 1) + (channel >> 2); 1750}
1721 if (channel2 > channel) channel2 = 0; 1751}
1722 *(pr++) = channel2;
1723
1724 channel = *(xt++) + *(yt + 1);
1725 channel2 = (channel >> 1) + (channel >> 2);
1726 if (channel2 > channel) channel2 = 0;
1727 *(pg++) = channel2;
1728
1729 channel = *(xt++) + *(yt + 2);
1730 channel2 = (channel >> 1) + (channel >> 2);
1731 if (channel2 > channel) channel2 = 0;
1732 *(pb++) = channel2;
1733 } else {
1734 channel = *(xt++) + *(yt);
1735 channel2 = channel + (channel >> 3);
1736 if (channel2 < channel) channel2 = ~0;
1737 *(pr++) = channel2;
1738
1739 channel = *(xt++) + *(yt + 1);
1740 channel2 = channel + (channel >> 3);
1741 if (channel2 < channel) channel2 = ~0;
1742 *(pg++) = channel2;
1743
1744 channel = *(xt++) + *(yt + 2);
1745 channel2 = channel + (channel >> 3);
1746 if (channel2 < channel) channel2 = ~0;
1747 *(pb++) = channel2;
1748 }
1749 }
1750 }
1751 }
1752 1752
1753} 1753}
1754 1754