ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.15 by sasha, Mon Nov 19 15:50:46 2007 UTC vs.
Revision 1.111 by sf-exg, Fri Nov 5 17:27:58 2010 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: background.C - former xpm.C 2 * File: background.C - former xpm.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com>
7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> 7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
8 * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it>
8 * 9 *
9 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version. 13 * (at your option) any later version.
19 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *---------------------------------------------------------------------*/ 23 *---------------------------------------------------------------------*/
23 24
25#include <cmath>
24#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
25#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
26 28
29#if XRENDER
30# include <X11/extensions/Xrender.h>
31#endif
32
27#define DO_TIMING_TEST 0 33#define DO_TIMING_TEST 0
28 34
29#if DO_TIMING_TEST 35#if DO_TIMING_TEST
36# include <sys/time.h>
30#define TIMING_TEST_START(id) \ 37#define TIMING_TEST_START(id) \
31 struct timeval timing_test_##id##_stv;\ 38 struct timeval timing_test_##id##_stv; \
32 gettimeofday (&timing_test_##id##_stv, NULL); 39 gettimeofday (&timing_test_##id##_stv, NULL);
33 40
34#define TIMING_TEST_PRINT_RESULT(id) \ 41#define TIMING_TEST_PRINT_RESULT(id) \
35 do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ 42 do { \
43 struct timeval tv; \
44 gettimeofday (&tv, NULL); \
45 tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \
36 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ 46 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \
37 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0) 47 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \
48 } while (0)
38 49
39#else 50#else
40#define TIMING_TEST_START(id) do{}while (0) 51#define TIMING_TEST_START(id) do {} while (0)
41#define TIMING_TEST_PRINT_RESULT(id) do{}while (0) 52#define TIMING_TEST_PRINT_RESULT(id) do {} while (0)
42#endif 53#endif
43 54
44/* 55/*
45 * Pixmap geometry string interpretation : 56 * Pixmap geometry string interpretation :
46 * Each geometry string contains zero or one scale/position 57 * Each geometry string contains zero or one scale/position
47 * adjustment and may optionally be followed by a colon and one or more 58 * adjustment and may optionally be followed by a colon and one or more
48 * colon-delimited pixmap operations. 59 * colon-delimited pixmap operations.
49 * The following table shows the valid geometry strings and their 60 * The following table shows the valid geometry strings and their
50 * affects on the background image : 61 * effects on the background image :
51 * 62 *
52 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. 63 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
53 * W and H are percentages of the terminal window size. 64 * W and H are percentages of the terminal window size.
54 * X and Y are also percentages; e.g., +50+50 centers 65 * X and Y are also percentages; e.g., +50+50 centers
55 * the image in the window. 66 * the image in the window.
56 * WxH+X Assumes Y == X 67 * WxH+X Assumes Y == X
57 * WxH Assumes Y == X == 50 (centers the image) 68 * WxH Assumes Y == X == 50 (centers the image)
58 * W+X+Y Assumes H == W 69 * W+X+Y Assumes H == W
59 * W+X Assumes H == W and Y == X 70 * W+X Assumes H == W and Y == X
60 * W Assumes H == W and Y == X == 50 71 * W Assumes H == W and Y == X == 50
61 * 72 *
62 * Adjusting position only : 73 * Adjusting position only :
63 * =+X+Y Set position to X% by Y% (absolute). 74 * =+X+Y Set position to X% by Y% (absolute).
64 * =+X Set position to X% by X%. 75 * =+X Set position to X% by X%.
65 * +X+Y Adjust position horizontally X% and vertically Y% 76 * +X+Y Adjust position horizontally X% and vertically Y%
66 * from current position (relative). 77 * from current position (relative).
67 * +X Adjust position horizontally X% and vertically X% 78 * +X Adjust position horizontally X% and vertically X%
68 * from current position. 79 * from current position.
69 * 80 *
70 * Adjusting scale only : 81 * Adjusting scale only :
71 * Wx0 Multiply horizontal scaling factor by W% 82 * Wx0 Multiply horizontal scaling factor by W%
72 * 0xH Multiply vertical scaling factor by H% 83 * 0xH Multiply vertical scaling factor by H%
73 * 0x0 No scaling (show image at normal size). 84 * 0x0 No scaling (show image at normal size).
74 * 85 *
75 * Pixmap Operations : (should be prepended by a colon) 86 * Pixmap Operations : (should be prepended by a colon)
76 * tile Tile image. Scaling/position modifiers above will affect 87 * tile Tile image. Scaling/position modifiers above will affect
77 * the tile size and origin. 88 * the tile size and origin.
78 * propscale When scaling, scale proportionally. That is, maintain the 89 * propscale When scaling, scale proportionally. That is, maintain the
79 * proper aspect ratio for the image. Any portion of the 90 * proper aspect ratio for the image. Any portion of the
80 * background not covered by the image is filled with the 91 * background not covered by the image is filled with the
81 * current background color. 92 * current background color.
82 * hscale Scale horizontally, tile vertically ? 93 * hscale Scale horizontally, tile vertically ?
83 * vscale Tile horizontally, scale vertically ? 94 * vscale Tile horizontally, scale vertically ?
86 */ 97 */
87 98
88#ifdef HAVE_BG_PIXMAP 99#ifdef HAVE_BG_PIXMAP
89bgPixmap_t::bgPixmap_t () 100bgPixmap_t::bgPixmap_t ()
90{ 101{
102 // this is basically redundant as bgPixmap_t is only used in
103 // zero_initialised-derived structs
91#ifdef HAVE_AFTERIMAGE 104#ifdef HAVE_AFTERIMAGE
92 original_asim = NULL; 105 original_asim = NULL;
93#endif 106#endif
107#ifdef HAVE_PIXBUF
108 pixbuf = NULL;
109#endif
94#ifdef BG_IMAGE_FROM_FILE 110#ifdef BG_IMAGE_FROM_FILE
111 have_image = false;
95 h_scale = v_scale = 0; 112 h_scale = v_scale = 0;
96 h_align = v_align = 0; 113 h_align = v_align = 0;
97#endif 114#endif
115#ifdef ENABLE_TRANSPARENCY
116 shade = 100;
117#endif
98 flags = 0; 118 flags = 0;
99 pixmap = None; 119 pixmap = None;
120 valid_since = invalid_since = 0;
121 target = 0;
100} 122}
101 123
102void 124void
103bgPixmap_t::destroy () 125bgPixmap_t::destroy ()
104{ 126{
105#ifdef HAVE_AFTERIMAGE 127#ifdef HAVE_AFTERIMAGE
106 if (original_asim) 128 if (original_asim)
107 safe_asimage_destroy (original_asim); 129 safe_asimage_destroy (original_asim);
108#endif 130#endif
109 131
132#ifdef HAVE_PIXBUF
133 if (pixbuf)
134 g_object_unref (pixbuf);
135#endif
136
110 if (pixmap && target) 137 if (pixmap && target)
111 XFreePixmap (target->dpy, pixmap); 138 XFreePixmap (target->dpy, pixmap);
112} 139}
113 140
114bool 141bool
118 if (flags & isTransparent) 145 if (flags & isTransparent)
119 return true; 146 return true;
120# endif 147# endif
121 148
122# ifdef BG_IMAGE_FROM_FILE 149# ifdef BG_IMAGE_FROM_FILE
123# ifdef HAVE_AFTERIMAGE 150 if (have_image)
124 if (original_asim != NULL)
125# endif
126 { 151 {
127 if (h_scale != 0 || v_scale != 0 152 if (flags & sizeSensitive)
128 || h_align != 0 || v_align != 0)
129 return true; 153 return true;
130 } 154 }
131# endif 155# endif
132 156
133 return false; 157 return false;
134} 158}
135 159
136bool 160bool
137bgPixmap_t::window_position_sensitive () 161bgPixmap_t::window_position_sensitive ()
138{ 162{
139# ifdef ENABLE_TRANSPARENCY 163# ifdef ENABLE_TRANSPARENCY
140 if (flags & isTransparent) 164 if (flags & isTransparent)
141 return true; 165 return true;
142# endif 166# endif
143 167
144# ifdef BG_IMAGE_FROM_FILE 168# ifdef BG_IMAGE_FROM_FILE
145# ifdef HAVE_AFTERIMAGE 169 if (have_image)
146 if (original_asim != NULL)
147# endif
148 { 170 {
149 if (h_align == rootAlign || v_align == rootAlign) 171 if (flags & rootAlign)
150 return true; 172 return true;
151 } 173 }
152# endif 174# endif
153 175
154 return false; 176 return false;
155}; 177};
156 178
157bool bgPixmap_t::need_client_side_rendering () 179bool bgPixmap_t::need_client_side_rendering ()
158{ 180{
159# ifdef HAVE_AFTERIMAGE 181# ifdef HAVE_AFTERIMAGE
160 if (original_asim != NULL) 182 if (original_asim)
161 return true; 183 return true;
162# endif
163# ifdef ENABLE_TRANSPARENCY
164 if (flags & isTransparent)
165 {
166# ifdef HAVE_AFTERIMAGE // can't blur without libAI anyways
167 if ((flags & blurNeeded) && !(flags & blurServerSide))
168 return true;
169# endif
170 if ((flags & tintNeeded) && !(flags & tintServerSide))
171 return true;
172 }
173# endif 184# endif
174 return false; 185 return false;
175} 186}
176 187
177# ifdef BG_IMAGE_FROM_FILE 188# ifdef BG_IMAGE_FROM_FILE
194static inline bool 205static inline bool
195check_set_align_value (int geom_flags, int flag, int &align, int new_value) 206check_set_align_value (int geom_flags, int flag, int &align, int new_value)
196{ 207{
197 if (geom_flags & flag) 208 if (geom_flags & flag)
198 { 209 {
199 if (new_value != bgPixmap_t::rootAlign)
200 {
201 if (new_value < -100) 210 if (new_value < -100)
202 new_value = -100; 211 new_value = -100;
203 else if (new_value > 200) 212 else if (new_value > 200)
204 new_value = 200; 213 new_value = 200;
205 }
206 if (new_value != align) 214 if (new_value != align)
207 { 215 {
208 align = new_value; 216 align = new_value;
209 return true; 217 return true;
210 } 218 }
214 222
215static inline int 223static inline int
216make_align_position (int align, int window_size, int image_size) 224make_align_position (int align, int window_size, int image_size)
217{ 225{
218 int diff = window_size - image_size; 226 int diff = window_size - image_size;
219 int smaller = MIN (image_size,window_size); 227 int smaller = min (image_size, window_size);
220 228
221 if (align >= 0 && align <= 50) 229 if (align >= 0 && align <= 100)
222 return diff * align / 100; 230 return diff * align / 100;
223 else if (align > 50 && align <= 100)
224 return window_size - image_size - diff * (100 - align) / 100;
225 else if (align > 100 && align <= 200 ) 231 else if (align > 100 && align <= 200)
226 return ((align - 100) * smaller / 100) + window_size - smaller; 232 return ((align - 100) * smaller / 100) + window_size - smaller;
227 else if (align > -100 && align < 0) 233 else if (align >= -100 && align < 0)
228 return ((align + 100) * smaller / 100) - image_size; 234 return ((align + 100) * smaller / 100) - image_size;
229 return 0; 235 return 0;
230} 236}
231 237
232static inline int 238static inline int
233make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 239make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
234{ 240{
235 int src_pos = 0; 241 int src_pos = 0;
236 dst_pos = 0; 242 dst_pos = pos;
237 dst_size = size; 243 dst_size = size;
238 if (pos < 0 && size > target_size) 244 if (pos < 0)
239 { 245 {
240 src_pos = -pos; 246 src_pos = -pos;
247 dst_pos = 0;
241 dst_size += pos; 248 dst_size += pos;
242 } 249 }
243 else if (pos > 0)
244 dst_pos = pos;
245 250
246 if (dst_pos + dst_size > target_size) 251 if (dst_pos + dst_size > target_size)
247 dst_size = target_size - dst_pos; 252 dst_size = target_size - dst_pos;
248 return src_pos; 253 return src_pos;
249} 254}
250 255
251bool 256bool
252bgPixmap_t::set_geometry (const char *geom) 257bgPixmap_t::set_geometry (const char *geom)
253{ 258{
259 bool changed = false;
254 int geom_flags = 0, changed = 0; 260 int geom_flags = 0;
255 int x = 0, y = 0; 261 int x = 0, y = 0;
256 unsigned int w = 0, h = 0; 262 unsigned int w = 0, h = 0;
257 unsigned int n; 263 unsigned int n;
258 unsigned long new_flags = (flags & (~geometryFlags)); 264 unsigned long new_flags = (flags & (~geometryFlags));
259 char *p; 265 const char *p;
260# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ 266# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
261 267
262 if (geom == NULL) 268 if (geom == NULL)
263 return false; 269 return false;
264 270
265 char str[MAXLEN_GEOM]; 271 char str[MAXLEN_GEOM];
272 if (n < MAXLEN_GEOM) 278 if (n < MAXLEN_GEOM)
273 { 279 {
274 char *ops; 280 char *ops;
275 new_flags |= geometrySet; 281 new_flags |= geometrySet;
276 282
277 strncpy (str, geom, n); 283 memcpy (str, geom, n);
278 str[n] = '\0'; 284 str[n] = '\0';
279 if (str[0] == ':') 285 if (str[0] == ':')
280 ops = &str[0]; 286 ops = &str[0];
281 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) 287 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
282 ops = &str[0]; 288 ops = &str[0];
302 y = x; 308 y = x;
303 geom_flags |= YValue; 309 geom_flags |= YValue;
304 } 310 }
305 311
306 if (flags & geometrySet) 312 if (flags & geometrySet)
313 {
307 {/* new geometry is an adjustment to the old one ! */ 314 /* new geometry is an adjustment to the old one ! */
308 if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) 315 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
309 { 316 {
310 if (w == 0 && h != 0) 317 if (w == 0 && h != 0)
311 { 318 {
312 w = h_scale; 319 w = h_scale;
328 } 335 }
329 } 336 }
330 else /* setting up geometry from scratch */ 337 else /* setting up geometry from scratch */
331 { 338 {
332 if (!(geom_flags & XValue)) 339 if (!(geom_flags & XValue))
340 {
333 {/* use default geometry - centered */ 341 /* use default geometry - centered */
334 x = y = defaultAlign; 342 x = y = defaultAlign;
335 } 343 }
336 else if (!(geom_flags & YValue)) 344 else if (!(geom_flags & YValue))
337 y = x; 345 y = x;
338 346
339 if ((geom_flags & (WidthValue|HeightValue)) == 0) 347 if ((geom_flags & (WidthValue|HeightValue)) == 0)
348 {
340 {/* use default geometry - scaled */ 349 /* use default geometry - scaled */
341 w = h = defaultScale; 350 w = h = defaultScale;
342 } 351 }
343 else if (geom_flags & WidthValue) 352 else if (geom_flags & WidthValue)
344 { 353 {
345 if (!(geom_flags & HeightValue)) 354 if (!(geom_flags & HeightValue))
348 else 357 else
349 w = h; 358 w = h;
350 } 359 }
351 } /* done parsing geometry string */ 360 } /* done parsing geometry string */
352 else if (!(flags & geometrySet)) 361 else if (!(flags & geometrySet))
362 {
353 { /* default geometry - scaled and centered */ 363 /* default geometry - scaled and centered */
354 x = y = defaultAlign; 364 x = y = defaultAlign;
355 w = h = defaultScale; 365 w = h = defaultScale;
356 } 366 }
357 367
358 if (!(flags & geometrySet)) 368 if (!(flags & geometrySet))
361 if (ops) 371 if (ops)
362 { 372 {
363 while (*ops) 373 while (*ops)
364 { 374 {
365 while (*ops == ':' || isspace(*ops)) ++ops; 375 while (*ops == ':' || isspace(*ops)) ++ops;
376
366# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) 377# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0)
367 if (CHECK_GEOM_OPS("tile")) 378 if (CHECK_GEOM_OPS ("tile"))
368 { 379 {
369 w = h = noScale; 380 w = h = noScale;
370 geom_flags |= WidthValue|HeightValue; 381 geom_flags |= WidthValue|HeightValue;
371 } 382 }
372 else if (CHECK_GEOM_OPS("propscale")) 383 else if (CHECK_GEOM_OPS ("propscale"))
373 { 384 {
374 if (w == 0 && h == 0)
375 {
376 w = windowScale;
377 geom_flags |= WidthValue;
378 }
379 new_flags |= propScale; 385 new_flags |= propScale;
380 } 386 }
381 else if (CHECK_GEOM_OPS("hscale")) 387 else if (CHECK_GEOM_OPS ("hscale"))
382 { 388 {
383 if (w == 0)
384 w = windowScale; 389 if (w == 0) w = windowScale;
390
385 h = noScale; 391 h = noScale;
386 geom_flags |= WidthValue|HeightValue; 392 geom_flags |= WidthValue|HeightValue;
387 } 393 }
388 else if (CHECK_GEOM_OPS("vscale")) 394 else if (CHECK_GEOM_OPS ("vscale"))
389 { 395 {
390 if (h == 0)
391 h = windowScale; 396 if (h == 0) h = windowScale;
397
392 w = noScale; 398 w = noScale;
393 geom_flags |= WidthValue|HeightValue; 399 geom_flags |= WidthValue|HeightValue;
394 } 400 }
395 else if (CHECK_GEOM_OPS("scale")) 401 else if (CHECK_GEOM_OPS ("scale"))
396 { 402 {
397 if (h == 0)
398 h = windowScale; 403 if (h == 0) h = windowScale;
399 if (w == 0)
400 w = windowScale; 404 if (w == 0) w = windowScale;
405
401 geom_flags |= WidthValue|HeightValue; 406 geom_flags |= WidthValue|HeightValue;
402 } 407 }
403 else if (CHECK_GEOM_OPS("auto")) 408 else if (CHECK_GEOM_OPS ("auto"))
404 { 409 {
405 w = h = windowScale; 410 w = h = windowScale;
406 x = y = centerAlign; 411 x = y = centerAlign;
407 geom_flags |= WidthValue|HeightValue|XValue|YValue; 412 geom_flags |= WidthValue|HeightValue|XValue|YValue;
408 } 413 }
409 else if (CHECK_GEOM_OPS("root")) 414 else if (CHECK_GEOM_OPS ("root"))
410 { 415 {
416 new_flags |= rootAlign;
411 w = h = noScale; 417 w = h = noScale;
412 x = y = rootAlign;
413 geom_flags |= WidthValue|HeightValue|XValue|YValue; 418 geom_flags |= WidthValue|HeightValue;
414 } 419 }
415# undef CHECK_GEOM_OPS 420# undef CHECK_GEOM_OPS
421
416 while (*ops != ':' && *ops != '\0') ++ops; 422 while (*ops != ':' && *ops != '\0') ++ops;
417 } /* done parsing ops */ 423 } /* done parsing ops */
418 } 424 }
419 425
420 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) 426 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
421 ++changed;
422 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) 427 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
423 ++changed;
424 if (check_set_align_value (geom_flags, XValue, h_align, x)) 428 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
425 ++changed;
426 if (check_set_align_value (geom_flags, YValue, v_align, y)) 429 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
427 ++changed;
428 } 430 }
429 431
430 if (new_flags != flags) 432 if (new_flags != flags)
431 { 433 {
432 flags = new_flags; 434 flags = new_flags;
433 changed++; 435 changed = true;
434 } 436 }
435//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 437
436// flags, h_scale, v_scale, h_align, v_align);
437 return (changed > 0); 438 return changed;
439}
440
441void
442bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
443{
444 int target_width = target->szHint.width;
445 int target_height = target->szHint.height;
446
447 if (flags & propScale)
448 {
449 float scale = (float)target_width / image_width;
450 min_it (scale, (float)target_height / image_height);
451 w = image_width * scale + 0.5;
452 h = image_height * scale + 0.5;
453 }
454 else
455 {
456 w = h_scale * target_width / 100;
457 h = v_scale * target_height / 100;
458 }
459
460 if (!w) w = image_width;
461 if (!h) h = image_height;
462
463 if (flags & rootAlign)
464 {
465 target->get_window_origin (x, y);
466 x = -x;
467 y = -y;
468 }
469 else
470 {
471 x = make_align_position (h_align, target_width, w);
472 y = make_align_position (v_align, target_height, h);
473 }
474
475 flags &= ~sizeSensitive;
476 if ((flags & propScale) || h_scale || v_scale
477 || (!(flags & rootAlign) && (h_align || v_align))
478 || w > target_width || h > target_height)
479 flags |= sizeSensitive;
438} 480}
439 481
440# ifdef HAVE_AFTERIMAGE 482# ifdef HAVE_AFTERIMAGE
441bool 483bool
442bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) 484bgPixmap_t::render_image (unsigned long background_flags)
443{ 485{
444 if (target == NULL) 486 if (target == NULL)
445 return false; 487 return false;
446 488
489 target->init_asv ();
490
491 ASImage *background = NULL;
492 ARGB32 background_tint = TINT_LEAVE_SAME;
493
494# ifdef ENABLE_TRANSPARENCY
495 if (background_flags)
496 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
497
498 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
499 {
500 ShadingInfo as_shade;
501 as_shade.shading = shade;
502
503 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
504 if (flags & tintSet)
505 tint.get (c);
506 as_shade.tintColor.red = c.r;
507 as_shade.tintColor.green = c.g;
508 as_shade.tintColor.blue = c.b;
509
510 background_tint = shading2tint32 (&as_shade);
511 }
512
513 if (!(background_flags & transpPmapBlurred) && (flags & blurNeeded) && background != NULL)
514 {
515 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
516 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage,
517 100, ASIMAGE_QUALITY_DEFAULT);
518 if (tmp)
519 {
520 destroy_asimage (&background);
521 background = tmp;
522 }
523 }
524# endif
525
526 ASImage *result = 0;
527
447 int target_width = (int)target->szHint.width; 528 int target_width = target->szHint.width;
448 int target_height = (int)target->szHint.height; 529 int target_height = target->szHint.height;
449 int new_pmap_width = target_width, new_pmap_height = target_height; 530 int new_pmap_width = target_width;
450 ASImage *result = NULL; 531 int new_pmap_height = target_height;
451 532
452 int x = 0; 533 int x = 0;
453 int y = 0; 534 int y = 0;
454 int w = h_scale * target_width / 100; 535 int w = 0;
455 int h = v_scale * target_height / 100; 536 int h = 0;
456
457 TIMING_TEST_START (asim);
458 537
459 if (original_asim) 538 if (original_asim)
460 { 539 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
461 if (h_align == rootAlign || v_align == rootAlign)
462 {
463 target->get_window_origin(x, y);
464 x = -x;
465 y = -y;
466 }
467 if (h_align != rootAlign)
468 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
469 if (v_align != rootAlign)
470 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
471 }
472 540
473 if (original_asim == NULL 541 if (!original_asim
542 || (!(flags & rootAlign)
474 || x >= target_width 543 && (x >= target_width
475 || y >= target_height 544 || y >= target_height
476 || (w > 0 && x + w <= 0) 545 || (x + w <= 0)
477 || (h > 0 && y + h <= 0)) 546 || (y + h <= 0))))
478 { 547 {
479 if (background) 548 if (background)
480 { 549 {
481 new_pmap_width = background->width; 550 new_pmap_width = background->width;
482 new_pmap_height = background->height; 551 new_pmap_height = background->height;
483 result = background; 552 result = background;
553
484 if (background_tint != TINT_LEAVE_SAME) 554 if (background_tint != TINT_LEAVE_SAME)
485 { 555 {
486 ASImage* tmp = tile_asimage (target->asv, background, 0, 0, 556 ASImage *tmp = tile_asimage (target->asv, background, 0, 0,
487 target_width, target_height, background_tint, 557 target_width, target_height, background_tint,
488 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); 558 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
489 if (tmp) 559 if (tmp)
490 result = tmp; 560 result = tmp;
491 } 561 }
494 new_pmap_width = new_pmap_height = 0; 564 new_pmap_width = new_pmap_height = 0;
495 } 565 }
496 else 566 else
497 { 567 {
498 result = original_asim; 568 result = original_asim;
569
499 if ((w > 0 && w != original_asim->width) 570 if ((w != original_asim->width)
500 || (h > 0 && h != original_asim->height)) 571 || (h != original_asim->height))
501 { 572 {
502 result = scale_asimage (target->asv, original_asim, 573 result = scale_asimage (target->asv, original_asim,
503 w > 0 ? w : original_asim->width, 574 w, h,
504 h > 0 ? h : original_asim->height,
505 background ? ASA_ASImage : ASA_XImage, 575 background ? ASA_ASImage : ASA_XImage,
506 100, ASIMAGE_QUALITY_DEFAULT); 576 100, ASIMAGE_QUALITY_DEFAULT);
507 } 577 }
578
508 if (background == NULL) 579 if (background == NULL)
509 {/* if tiling - pixmap has to be sized exactly as the image, 580 {
510 but there is no need to make it bigger then the window! */
511 if (h_scale == 0)
512 new_pmap_width = min (result->width, target_width);
513 if (v_scale == 0)
514 new_pmap_height = min (result->height, target_height);
515 /* we also need to tile our image in one or both directions */
516 if (h_scale == 0 || v_scale == 0) 581 if (h_scale == 0 || v_scale == 0)
517 { 582 {
583 /* if tiling - pixmap has to be sized exactly as the image,
584 but there is no need to make it bigger than the window! */
585 new_pmap_width = min (result->width, target_width);
586 new_pmap_height = min (result->height, target_height);
587
588 /* we also need to tile our image in both directions */
518 ASImage *tmp = tile_asimage (target->asv, result, 589 ASImage *tmp = tile_asimage (target->asv, result,
519 (h_scale > 0) ? 0 : (int)result->width - x, 590 (int)result->width - x,
520 (v_scale > 0) ? 0 : (int)result->height - y, 591 (int)result->height - y,
521 new_pmap_width, 592 new_pmap_width,
522 new_pmap_height, 593 new_pmap_height,
523 TINT_LEAVE_SAME, ASA_XImage, 594 TINT_LEAVE_SAME, ASA_XImage,
524 100, ASIMAGE_QUALITY_DEFAULT); 595 100, ASIMAGE_QUALITY_DEFAULT);
525 if (tmp) 596 if (tmp)
526 { 597 {
527 if (result != original_asim) 598 if (result != original_asim)
528 destroy_asimage (&result); 599 destroy_asimage (&result);
600
529 result = tmp; 601 result = tmp;
530 } 602 }
531 } 603 }
532 } 604 }
533 else 605 else
606 {
534 {/* if blending background and image - pixmap has to be sized same as target window */ 607 /* if blending background and image - pixmap has to be sized same as target window */
535 ASImageLayer *layers = create_image_layers (2); 608 ASImageLayer *layers = create_image_layers (2);
536 ASImage *merged_im = NULL;
537 609
538 layers[0].im = background; 610 layers[0].im = background;
539 layers[0].clip_width = target_width; 611 layers[0].clip_width = target_width;
540 layers[0].clip_height = target_height; 612 layers[0].clip_height = target_height;
541 layers[0].tint = background_tint; 613 layers[0].tint = background_tint;
542 layers[1].im = result; 614 layers[1].im = result;
543 if (w <= 0) 615
616 if (h_scale == 0 || v_scale == 0)
617 {
544 {/* tile horizontally */ 618 /* tile horizontally */
545 while (x > 0) x -= (int)result->width; 619 while (x > 0) x -= (int)result->width;
546 layers[1].dst_x = x; 620 layers[1].dst_x = x;
547 layers[1].clip_width = result->width+target_width; 621 layers[1].clip_width = result->width+target_width;
548 } 622 }
549 else 623 else
624 {
550 {/* clip horizontally */ 625 /* clip horizontally */
551 layers[1].dst_x = x; 626 layers[1].dst_x = x;
552 layers[1].clip_width = result->width; 627 layers[1].clip_width = result->width;
553 } 628 }
554 if (h <= 0) 629
630 if (h_scale == 0 || v_scale == 0)
555 { 631 {
556 while (y > 0) y -= (int)result->height; 632 while (y > 0) y -= (int)result->height;
557 layers[1].dst_y = y; 633 layers[1].dst_y = y;
558 layers[1].clip_height = result->height + target_height; 634 layers[1].clip_height = result->height + target_height;
559 } 635 }
560 else 636 else
561 { 637 {
562 layers[1].dst_y = y; 638 layers[1].dst_y = y;
563 layers[1].clip_height = result->height; 639 layers[1].clip_height = result->height;
564 } 640 }
641
565 if (target->rs[Rs_blendtype]) 642 if (target->rs[Rs_blendtype])
566 { 643 {
567 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); 644 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]);
568 if (layers[1].merge_scanlines == NULL) 645 if (layers[1].merge_scanlines == NULL)
569 layers[1].merge_scanlines = alphablend_scanlines; 646 layers[1].merge_scanlines = alphablend_scanlines;
570 } 647 }
648
571 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, 649 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height,
572 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); 650 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
651
573 if (tmp) 652 if (tmp)
574 { 653 {
575 if (result != original_asim) 654 if (result != original_asim)
576 destroy_asimage (&result); 655 destroy_asimage (&result);
656
577 result = tmp; 657 result = tmp;
578 } 658 }
659
579 free (layers); 660 free (layers);
580 } 661 }
581 } 662 }
582 TIMING_TEST_PRINT_RESULT (asim);
583 663
584 if (pixmap) 664 bool ret = false;
585 {
586 if (result == NULL
587 || pmap_width != new_pmap_width
588 || pmap_height != new_pmap_height
589 || pmap_depth != target->depth)
590 {
591 XFreePixmap (target->dpy, pixmap);
592 pixmap = None;
593 }
594 }
595 665
596 if (result) 666 if (result)
597 { 667 {
598 XGCValues gcv; 668 XGCValues gcv;
599 GC gc; 669 GC gc;
670
671 if (pixmap)
672 {
673 if (pmap_width != new_pmap_width
674 || pmap_height != new_pmap_height
675 || pmap_depth != target->depth)
676 {
677 XFreePixmap (target->dpy, pixmap);
678 pixmap = None;
679 }
680 }
600 681
601 /* create Pixmap */ 682 /* create Pixmap */
602 if (pixmap == None) 683 if (pixmap == None)
603 { 684 {
604 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 685 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
605 pmap_width = new_pmap_width; 686 pmap_width = new_pmap_width;
606 pmap_height = new_pmap_height; 687 pmap_height = new_pmap_height;
607 pmap_depth = target->depth; 688 pmap_depth = target->depth;
608 } 689 }
609 /* fill with background color ( if result's not completely overlapping it)*/ 690 /* fill with background color (if result's not completely overlapping it) */
610 gcv.foreground = target->pix_colors[Color_bg]; 691 gcv.foreground = target->pix_colors[Color_bg];
611 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 692 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
612 693
613 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 694 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
614 int dst_width = result->width, dst_height = result->height; 695 int dst_width = result->width, dst_height = result->height;
615 if (background == NULL) 696 if (background == NULL)
616 { 697 {
617 if (h_scale > 0) 698 if (!(h_scale == 0 || v_scale == 0))
699 {
618 src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width); 700 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
619 if (v_scale > 0)
620 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 701 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
702 }
621 703
622 if (dst_x > 0 || dst_y > 0 704 if (dst_x > 0 || dst_y > 0
623 || dst_x + dst_width < new_pmap_width 705 || dst_x + dst_width < new_pmap_width
624 || dst_y + dst_height < new_pmap_height) 706 || dst_y + dst_height < new_pmap_height)
625 {
626 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 707 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
627 }
628 } 708 }
629 709
630 /* put result on pixmap */ 710 /* put result on pixmap */
631 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 711 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
632 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); 712 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
633 713
634 if (result != background && result != original_asim) 714 if (result != background && result != original_asim)
635 destroy_asimage (&result); 715 destroy_asimage (&result);
636 716
637 XFreeGC (target->dpy, gc); 717 XFreeGC (target->dpy, gc);
638 TIMING_TEST_PRINT_RESULT (asim);
639 }
640 718
719 ret = true;
720 }
721
722 if (background)
723 destroy_asimage (&background);
724
641 return true; 725 return ret;
642} 726}
643# endif /* HAVE_AFTERIMAGE */ 727# endif /* HAVE_AFTERIMAGE */
728
729# ifdef HAVE_PIXBUF
730bool
731bgPixmap_t::render_image (unsigned long background_flags)
732{
733 if (target == NULL)
734 return false;
735
736 if (!pixbuf)
737 return false;
738
739 if (background_flags
740 && !(flags & HAS_RENDER))
741 return false;
742
743 GdkPixbuf *result;
744
745 int image_width = gdk_pixbuf_get_width (pixbuf);
746 int image_height = gdk_pixbuf_get_height (pixbuf);
747
748 int target_width = target->szHint.width;
749 int target_height = target->szHint.height;
750 int new_pmap_width = target_width;
751 int new_pmap_height = target_height;
752
753 int x = 0;
754 int y = 0;
755 int w = 0;
756 int h = 0;
757
758 get_image_geometry (image_width, image_height, w, h, x, y);
759
760 if (!(flags & rootAlign)
761 && (x >= target_width
762 || y >= target_height
763 || (x + w <= 0)
764 || (y + h <= 0)))
765 return false;
766
767 result = pixbuf;
768
769 if ((w != image_width)
770 || (h != image_height))
771 {
772 result = gdk_pixbuf_scale_simple (pixbuf,
773 w, h,
774 GDK_INTERP_BILINEAR);
775 }
776
777 bool ret = false;
778
779 if (result)
780 {
781 XGCValues gcv;
782 GC gc;
783 Pixmap root_pmap;
784
785 image_width = gdk_pixbuf_get_width (result);
786 image_height = gdk_pixbuf_get_height (result);
787
788 if (background_flags)
789 {
790 root_pmap = pixmap;
791 pixmap = None;
792 }
793 else
794 {
795 if (h_scale == 0 || v_scale == 0)
796 {
797 new_pmap_width = min (image_width, target_width);
798 new_pmap_height = min (image_height, target_height);
799 }
800 }
801
802 if (pixmap)
803 {
804 if (pmap_width != new_pmap_width
805 || pmap_height != new_pmap_height
806 || pmap_depth != target->depth)
807 {
808 XFreePixmap (target->dpy, pixmap);
809 pixmap = None;
810 }
811 }
812
813 if (pixmap == None)
814 {
815 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
816 pmap_width = new_pmap_width;
817 pmap_height = new_pmap_height;
818 pmap_depth = target->depth;
819 }
820
821 gcv.foreground = target->pix_colors[Color_bg];
822 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
823
824 if (h_scale == 0 || v_scale == 0)
825 {
826 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
827 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc,
828 0, 0,
829 0, 0,
830 image_width, image_height,
831 XLIB_RGB_DITHER_NONE,
832 0, 0);
833
834 gcv.tile = tile;
835 gcv.fill_style = FillTiled;
836 gcv.ts_x_origin = x;
837 gcv.ts_y_origin = y;
838 XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
839
840 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
841 XFreePixmap (target->dpy, tile);
842 }
843 else
844 {
845 int src_x, src_y, dst_x, dst_y;
846 int dst_width, dst_height;
847
848 src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width );
849 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
850
851 if (dst_x > 0 || dst_y > 0
852 || dst_x + dst_width < new_pmap_width
853 || dst_y + dst_height < new_pmap_height)
854 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
855
856 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
857 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc,
858 src_x, src_y,
859 dst_x, dst_y,
860 dst_width, dst_height,
861 XLIB_RGB_DITHER_NONE,
862 0, 0);
863 }
864
865#if XRENDER
866 if (background_flags)
867 {
868 Display *dpy = target->dpy;
869 XRenderPictureAttributes pa;
870
871 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual);
872 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
873
874 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
875 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa);
876
877 pa.repeat = True;
878 Pixmap mask_pmap = XCreatePixmap (dpy, target->vt, 1, 1, 8);
879 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
880 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
881 XFreePixmap (dpy, mask_pmap);
882
883 if (src && dst && mask)
884 {
885 XRenderColor mask_c;
886
887 mask_c.alpha = 0x8000;
888 mask_c.red = 0;
889 mask_c.green = 0;
890 mask_c.blue = 0;
891 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
892 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height);
893 }
894
895 XRenderFreePicture (dpy, src);
896 XRenderFreePicture (dpy, dst);
897 XRenderFreePicture (dpy, mask);
898
899 XFreePixmap (dpy, root_pmap);
900 }
901#endif
902
903 if (result != pixbuf)
904 g_object_unref (result);
905
906 XFreeGC (target->dpy, gc);
907
908 ret = true;
909 }
910
911 return ret;
912}
913# endif /* HAVE_PIXBUF */
644 914
645bool 915bool
646bgPixmap_t::set_file (const char *file) 916bgPixmap_t::set_file (const char *file)
647{ 917{
648 char *f; 918 if (!file || !*file)
919 return false;
649 920
650 assert (file != NULL); 921 if (const char *p = strchr (file, ';'))
651 922 {
652 if (*file != '\0') 923 size_t len = p - file;
924 char *f = rxvt_temp_buf<char> (len + 1);
925 memcpy (f, file, len);
926 f[len] = '\0';
927 file = f;
653 { 928 }
929
654# ifdef HAVE_AFTERIMAGE 930# ifdef HAVE_AFTERIMAGE
655 if (target->asimman == NULL) 931 if (!target->asimman)
656 target->asimman = create_generic_imageman (target->rs[Rs_path]); 932 target->asimman = create_generic_imageman (target->rs[Rs_path]);
657 if ((f = strchr (file, ';')) == NULL)
658 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 933 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
659 else 934 if (image)
660 { 935 {
661 size_t len = f - file; 936 if (original_asim)
662 f = (char *)malloc (len + 1); 937 safe_asimage_destroy (original_asim);
663 strncpy (f, file, len); 938 original_asim = image;
664 f[len] = '\0'; 939 have_image = true;
665 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 940 return true;
666 free (f); 941 }
667 }
668 return (original_asim != NULL);
669# endif 942# endif
943
944# ifdef HAVE_PIXBUF
945 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
946 if (image)
670 } 947 {
948 if (pixbuf)
949 g_object_unref (pixbuf);
950 pixbuf = image;
951 have_image = true;
952 return true;
953 }
954# endif
955
671 return false; 956 return false;
672} 957}
673 958
674# endif /* BG_IMAGE_FROM_FILE */ 959# endif /* BG_IMAGE_FROM_FILE */
675 960
680 if (!(flags & isTransparent)) 965 if (!(flags & isTransparent))
681 { 966 {
682 flags |= isTransparent; 967 flags |= isTransparent;
683 return true; 968 return true;
684 } 969 }
970
685 return false; 971 return false;
686} 972}
687 973
688bool 974bool
689bgPixmap_t::set_blur_radius (const char *geom) 975bgPixmap_t::set_blur_radius (const char *geom)
690{ 976{
691 int changed = 0; 977 bool changed = false;
692 unsigned int hr, vr; 978 unsigned int hr, vr;
693 int junk; 979 int junk;
694 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 980 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
695 981
696 if (!(geom_flags&WidthValue)) 982 if (!(geom_flags & WidthValue))
697 hr = 1; 983 hr = 1;
698 if (!(geom_flags&HeightValue)) 984 if (!(geom_flags & HeightValue))
699 vr = hr; 985 vr = hr;
700 986
987 min_it (hr, 128);
988 min_it (vr, 128);
989
701 if (h_blurRadius != hr) 990 if (h_blurRadius != hr)
702 { 991 {
703 ++changed; 992 changed = true;
704 h_blurRadius = hr; 993 h_blurRadius = hr;
705 } 994 }
706 995
707 if (v_blurRadius != vr) 996 if (v_blurRadius != vr)
708 { 997 {
709 ++changed; 998 changed = true;
710 v_blurRadius = vr; 999 v_blurRadius = vr;
711 } 1000 }
712 1001
713 if (v_blurRadius == 0 && h_blurRadius == 0) 1002 if (v_blurRadius == 0 && h_blurRadius == 0)
714 flags &= ~blurNeeded; 1003 flags &= ~blurNeeded;
715 else 1004 else
716 flags |= blurNeeded; 1005 flags |= blurNeeded;
717 1006
718 return (changed>0); 1007 return changed;
719} 1008}
720 1009
721static inline unsigned long 1010static inline unsigned long
722compute_tint_shade_flags (rxvt_color *tint, int shade) 1011compute_tint_shade_flags (rxvt_color *tint, int shade)
723{ 1012{
724 unsigned long flags = 0; 1013 unsigned long flags = 0;
725 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1014 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
726 bool has_shade = (shade > 0 && shade < 100) || (shade > 100 && shade < 200); 1015 bool has_shade = shade != 100;
727 1016
728 if (tint) 1017 if (tint)
729 { 1018 {
730 tint->get (c); 1019 tint->get (c);
731# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 1020# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
740 flags |= bgPixmap_t::tintNeeded; 1029 flags |= bgPixmap_t::tintNeeded;
741 else if (tint) 1030 else if (tint)
742 { 1031 {
743 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 1032 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
744 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 1033 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
745 { 1034 {
746 flags |= bgPixmap_t::tintNeeded; 1035 flags |= bgPixmap_t::tintNeeded;
747 }
748 }
749
750 if (flags & bgPixmap_t::tintNeeded)
751 {
752 if (flags & bgPixmap_t::tintWholesome)
753 flags |= bgPixmap_t::tintServerSide;
754 else
755 {
756#if XFT
757 flags |= bgPixmap_t::tintServerSide;
758#endif
759 } 1036 }
760 } 1037 }
761 1038
762 return flags; 1039 return flags;
763} 1040}
764 1041
765bool 1042bool
766bgPixmap_t::set_tint (rxvt_color &new_tint) 1043bgPixmap_t::set_tint (rxvt_color &new_tint)
767{ 1044{
768 if (tint != new_tint) 1045 if (!(flags & tintSet) || tint != new_tint)
769 { 1046 {
770 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 1047 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
771 tint = new_tint; 1048 tint = new_tint;
772 flags = (flags & ~tintFlags) | new_flags | tintSet; 1049 flags = (flags & ~tintFlags) | new_flags | tintSet;
773 return true; 1050 return true;
774 } 1051 }
1052
775 return false; 1053 return false;
776} 1054}
777 1055
778bool 1056bool
779bgPixmap_t::unset_tint () 1057bgPixmap_t::unset_tint ()
780{ 1058{
781 unsigned long new_flags = compute_tint_shade_flags (NULL, shade); 1059 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
782 1060
783 if (new_flags != (flags & tintFlags)) 1061 if (new_flags != (flags & tintFlags))
784 { 1062 {
785 flags = (flags&~tintFlags)|new_flags; 1063 flags = (flags & ~tintFlags) | new_flags;
786 return true; 1064 return true;
787 } 1065 }
1066
788 return false; 1067 return false;
789} 1068}
790 1069
791bool 1070bool
792bgPixmap_t::set_shade (const char *shade_str) 1071bgPixmap_t::set_shade (const char *shade_str)
793{ 1072{
794 int new_shade = (shade_str) ? atoi (shade_str) : 0; 1073 int new_shade = (shade_str) ? atoi (shade_str) : 100;
795 1074
796 if (new_shade < 0 && new_shade > -100) 1075 clamp_it (new_shade, -100, 200);
1076 if (new_shade < 0)
797 new_shade = 200 - (100 + new_shade); 1077 new_shade = 200 - (100 + new_shade);
798 else if (new_shade == 100)
799 new_shade = 0;
800 1078
801 if (new_shade != shade) 1079 if (new_shade != shade)
802 { 1080 {
803 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 1081 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
804 shade = new_shade; 1082 shade = new_shade;
805 flags = (flags & (~tintFlags | tintSet)) | new_flags; 1083 flags = (flags & (~tintFlags | tintSet)) | new_flags;
806 return true; 1084 return true;
807 } 1085 }
1086
808 return false; 1087 return false;
809} 1088}
810 1089
1090#if XRENDER
1091static void
1092get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
1093{
1094 double sigma = radius / 2.0;
1095 double scale = sqrt (2.0 * M_PI) * sigma;
1096 double sum = 0.0;
1097
1098 for (int i = 0; i < width; i++)
1099 {
1100 double x = i - width / 2;
1101 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale;
1102 sum += kernel[i];
1103 }
1104
1105 params[0] = XDoubleToFixed (width);
1106 params[1] = XDoubleToFixed (1);
1107
1108 for (int i = 0; i < width; i++)
1109 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1110}
1111#endif
1112
1113bool
1114bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1115{
1116 bool ret = false;
1117#if XRENDER
1118 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1119 double *kernel = (double *)malloc (size * sizeof (double));
1120 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1121
1122 Display *dpy = target->dpy;
1123 XRenderPictureAttributes pa;
1124 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1125
1126 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1127 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1128
1129 if (kernel && params && src && dst)
1130 {
1131 if (h_blurRadius)
1132 {
1133 size = h_blurRadius * 2 + 1;
1134 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1135
1136 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1137 XRenderComposite (dpy,
1138 PictOpSrc,
1139 src,
1140 None,
1141 dst,
1142 0, 0,
1143 0, 0,
1144 0, 0,
1145 width, height);
1146 }
1147
1148 if (v_blurRadius)
1149 {
1150 size = v_blurRadius * 2 + 1;
1151 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1152 swap (params[0], params[1]);
1153
1154 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1155 XRenderComposite (dpy,
1156 PictOpSrc,
1157 src,
1158 None,
1159 dst,
1160 0, 0,
1161 0, 0,
1162 0, 0,
1163 width, height);
1164 }
1165
1166 ret = true;
1167 }
1168
1169 free (kernel);
1170 free (params);
1171 XRenderFreePicture (dpy, src);
1172 XRenderFreePicture (dpy, dst);
1173#endif
1174 return ret;
1175}
1176
1177bool
1178bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1179{
1180 Display *dpy = target->dpy;
1181 bool ret = false;
1182
1183 if (flags & tintWholesome)
1184 {
1185 XGCValues gcv;
1186 GC gc;
1187
1188 /* In this case we can tint image server-side getting significant
1189 * performance improvements, as we eliminate XImage transfer
1190 */
1191 gcv.foreground = Pixel (tint);
1192 gcv.function = GXand;
1193 gcv.fill_style = FillSolid;
1194 gc = XCreateGC (dpy, pixmap, GCFillStyle | GCForeground | GCFunction, &gcv);
1195 if (gc)
1196 {
1197 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1198 ret = true;
1199 XFreeGC (dpy, gc);
1200 }
1201 }
1202 else
1203 {
1204# if XRENDER
1205 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1206
1207 if (flags & tintSet)
1208 tint.get (c);
1209
1210 if (shade <= 100)
1211 {
1212 c.r = (c.r * shade) / 100;
1213 c.g = (c.g * shade) / 100;
1214 c.b = (c.b * shade) / 100;
1215 }
1216 else
1217 {
1218 c.r = ((0xffff - c.r) * (200 - shade)) / 100;
1219 c.g = ((0xffff - c.g) * (200 - shade)) / 100;
1220 c.b = ((0xffff - c.b) * (200 - shade)) / 100;
1221 }
1222
1223 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1224 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1225 XRenderPictureAttributes pa;
1226
1227 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1228
1229 pa.repeat = True;
1230
1231 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1232 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1233 XFreePixmap (dpy, overlay_pmap);
1234
1235 pa.component_alpha = True;
1236 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1237 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
1238 XFreePixmap (dpy, mask_pmap);
1239
1240 if (mask_pic && overlay_pic && back_pic)
1241 {
1242 XRenderColor mask_c;
1243
1244 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
1245 mask_c.alpha = 0xffff;
1246 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1247
1248 mask_c.alpha = 0;
1249 mask_c.red = 0xffff - c.r;
1250 mask_c.green = 0xffff - c.g;
1251 mask_c.blue = 0xffff - c.b;
1252 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1253 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1254 ret = true;
1255 }
1256
1257 XRenderFreePicture (dpy, mask_pic);
1258 XRenderFreePicture (dpy, overlay_pic);
1259 XRenderFreePicture (dpy, back_pic);
1260# endif
1261 }
1262
1263 return ret;
1264}
1265
811/* make_transparency_pixmap() 1266/* make_transparency_pixmap()
812 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1267 * Builds a pixmap of the same size as the terminal window that contains
813 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 1268 * the tiled portion of the root pixmap that is supposed to be covered by
814 * our window. 1269 * our window.
815 */ 1270 */
816unsigned long 1271unsigned long
817bgPixmap_t::make_transparency_pixmap () 1272bgPixmap_t::make_transparency_pixmap ()
818{ 1273{
819 unsigned long result = 0; 1274 unsigned long result = 0;
820 1275
821 if (target == NULL) 1276 if (target == NULL)
822 return 0; 1277 return 0;
823 1278
824 /* root dimentions may change from call to call - but Display structure should 1279 /* root dimensions may change from call to call - but Display structure should
825 * be always up-to-date, so let's use it : 1280 * be always up-to-date, so let's use it :
826 */ 1281 */
827 Window root = target->display->root;
828 int screen = target->display->screen; 1282 int screen = target->display->screen;
829 Display *dpy = target->dpy; 1283 Display *dpy = target->dpy;
1284 int root_depth = DefaultDepth (dpy, screen);
830 int root_width = DisplayWidth (dpy, screen); 1285 int root_width = DisplayWidth (dpy, screen);
831 int root_height = DisplayHeight (dpy, screen); 1286 int root_height = DisplayHeight (dpy, screen);
832 unsigned int root_pmap_width, root_pmap_height; 1287 unsigned int root_pmap_width, root_pmap_height;
833 int window_width = target->szHint.width; 1288 int window_width = target->szHint.width;
834 int window_height = target->szHint.height; 1289 int window_height = target->szHint.height;
835 int sx, sy; 1290 int sx, sy;
836 XGCValues gcv; 1291 XGCValues gcv;
1292 GC gc;
837 1293
838 TIMING_TEST_START (tp);
839 target->get_window_origin (sx, sy); 1294 target->get_window_origin (sx, sy);
840 1295
841 /* check if we are outside of the visible part of the virtual screen : */ 1296 /* check if we are outside of the visible part of the virtual screen : */
842 if (sx + window_width <= 0 || sy + window_height <= 0 1297 if (sx + window_width <= 0 || sy + window_height <= 0
843 || sx >= root_width || sy >= root_height) 1298 || sx >= root_width || sy >= root_height)
844 return 0; 1299 return 0;
845 1300
1301 // validate root pixmap and get its size
846 if (root_pixmap != None) 1302 if (root_pixmap != None)
847 {/* we want to validate the pixmap and get it's size at the same time : */ 1303 {
1304 Window wdummy;
848 int junk; 1305 int idummy;
849 unsigned int ujunk; 1306 unsigned int udummy;
850 /* root pixmap may be bad - allow a error */ 1307
851 target->allowedxerror = -1; 1308 target->allowedxerror = -1;
852 1309
853 if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk)) 1310 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy))
854 root_pixmap = None; 1311 root_pixmap = None;
855 1312
856 target->allowedxerror = 0; 1313 target->allowedxerror = 0;
857 } 1314 }
858 1315
1316 Pixmap recoded_root_pmap = root_pixmap;
1317
1318 if (root_pixmap != None && root_depth != target->depth)
1319 {
1320#if XRENDER
1321 if (flags & HAS_RENDER)
1322 {
1323 XRenderPictureAttributes pa;
1324
1325 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1326 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1327
1328 recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth);
1329 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
1330 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1331
1332 if (src && dst)
1333 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1334 else
1335 {
1336 XFreePixmap (dpy, recoded_root_pmap);
1337 root_pixmap = None;
1338 }
1339
1340 XRenderFreePicture (dpy, src);
1341 XRenderFreePicture (dpy, dst);
1342 }
1343 else
1344#endif
1345 root_pixmap = None;
1346 }
1347
1348 if (root_pixmap == None)
1349 return 0;
1350
859 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 1351 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth);
860 GC gc = NULL;
861 1352
862 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1353 if (tiled_root_pmap == None) /* something really bad happened - abort */
863 return 0; 1354 return 0;
864 1355
865 if (root_pixmap == None)
866 { /* use tricks to obtain the root background image :*/
867 /* we want to create Overrideredirect window overlapping out window
868 with background type of Parent Relative and then grab it */
869 XSetWindowAttributes attr;
870 Window src;
871 bool success = false;
872
873 attr.background_pixmap = ParentRelative;
874 attr.backing_store = Always;
875 attr.event_mask = ExposureMask;
876 attr.override_redirect = True;
877 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
878 CopyFromParent, CopyFromParent, CopyFromParent,
879 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
880 &attr);
881
882 if (src != None)
883 {
884 XEvent event;
885 int ev_count = 0;
886 XGrabServer (dpy);
887 XMapRaised (dpy, src);
888 XSync (dpy, False);
889
890 /* XSync should get window where it's properly exposed,
891 * but to be on the safe side - let's check for the actuall event to arrive : */
892 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
893 ++ev_count;
894
895 if (ev_count > 0);
896 { /* hooray! - we can grab the image! */
897 gc = XCreateGC (dpy, root, 0, NULL);
898 if (gc)
899 {
900 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
901 success = true;
902 }
903 }
904 XDestroyWindow (dpy, src);
905 XUngrabServer (dpy);
906 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
907 }
908
909 if (!success)
910 {
911 XFreePixmap (dpy, tiled_root_pmap);
912 tiled_root_pmap = None;
913 }
914 else
915 result |= transpPmapTiled;
916 }
917 else
918 {/* strightforward pixmap copy */ 1356 /* straightforward pixmap copy */
919 gcv.tile = root_pixmap; 1357 gcv.tile = recoded_root_pmap;
920 gcv.fill_style = FillTiled; 1358 gcv.fill_style = FillTiled;
921 1359
922 while (sx < 0) sx += (int)root_width; 1360 while (sx < 0) sx += (int)root_width;
923 while (sy < 0) sy += (int)root_height; 1361 while (sy < 0) sy += (int)root_height;
924 1362
925 gcv.ts_x_origin = -sx; 1363 gcv.ts_x_origin = -sx;
926 gcv.ts_y_origin = -sy; 1364 gcv.ts_y_origin = -sy;
927 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1365 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
928 1366
929 if (gc) 1367 if (gc)
930 { 1368 {
931 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1369 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
932 result |= transpPmapTiled; 1370 result |= transpPmapTiled;
933 } 1371 XFreeGC (dpy, gc);
934 } 1372 }
935 TIMING_TEST_PRINT_RESULT (tp);
936 1373
937 if (tiled_root_pmap != None) 1374 if (tiled_root_pmap != None)
938 { 1375 {
939 if (!need_client_side_rendering ()) 1376 if (!need_client_side_rendering ())
940 { 1377 {
1378 if ((flags & blurNeeded)
1379 && (flags & HAS_RENDER_CONV))
1380 {
1381 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1382 result |= transpPmapBlurred;
1383 }
941 if ((flags & tintNeeded)) 1384 if ((flags & tintNeeded)
942 {
943 if (flags & tintWholesome) 1385 && (flags & (tintWholesome | HAS_RENDER)))
944 { 1386 {
945 /* In this case we can tint image server-side getting significant 1387 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
946 * performance improvements, as we eliminate XImage transfer
947 */
948 gcv.foreground = Pixel (tint);
949 gcv.function = GXand;
950 gcv.fill_style = FillSolid;
951 if (gc)
952 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
953 else
954 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
955 if (gc)
956 {
957 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
958 result |= transpPmapTinted; 1388 result |= transpPmapTinted;
959 }
960 }
961 else
962 {
963# if XFT
964 Picture back_pic = 0;
965 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
966
967 if (flags & tintSet)
968 tint.get (c);
969
970 if (shade > 0 && shade < 100)
971 {
972 c.r = (c.r * shade) / 100;
973 c.g = (c.g * shade) / 100;
974 c.b = (c.b * shade) / 100;
975 }
976 else if( shade > 100 && shade < 200)
977 {
978 c.r = (c.r * (200 - shade)) / 100;
979 c.g = (c.g * (200 - shade)) / 100;
980 c.b = (c.b * (200 - shade)) / 100;
981 }
982
983 XRenderPictFormat pf;
984 pf.type = PictTypeDirect;
985 pf.depth = 32;
986 pf.direct.redMask = 0xff;
987 pf.direct.greenMask = 0xff;
988 pf.direct.blueMask = 0xff;
989 pf.direct.alphaMask = 0xff;
990
991 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
992 (PictFormatType|
993 PictFormatDepth|
994 PictFormatRedMask|
995 PictFormatGreenMask|
996 PictFormatBlueMask|
997 PictFormatAlphaMask),
998 &pf,
999 0);
1000 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
1001 XRenderPictureAttributes pa ;
1002
1003 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa);
1004
1005 pa.repeat = True;
1006
1007 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1008 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1009 XFreePixmap (dpy, overlay_pmap);
1010
1011 pa.component_alpha = True;
1012 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1013 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
1014 XFreePixmap (dpy, mask_pmap);
1015
1016 if (mask_pic && overlay_pic && back_pic)
1017 {
1018 XRenderColor mask_c;
1019
1020 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
1021 mask_c.alpha = 0xffff;
1022 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1023
1024 mask_c.alpha = 0;
1025 mask_c.red = 0xffff - c.r;
1026 mask_c.green = 0xffff - c.g;
1027 mask_c.blue = 0xffff - c.b;
1028 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1029 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
1030 result |= transpPmapTinted;
1031 }
1032 XRenderFreePicture (dpy, mask_pic);
1033 XRenderFreePicture (dpy, overlay_pic);
1034 XRenderFreePicture (dpy, back_pic);
1035# if DO_TIMING_TEST
1036 XSync (dpy, False);
1037# endif
1038# endif
1039 }
1040 } 1389 }
1041 } /* server side rendering completed */ 1390 } /* server side rendering completed */
1042 1391
1043 if (pixmap) 1392 if (pixmap)
1044 XFreePixmap (dpy, pixmap); 1393 XFreePixmap (dpy, pixmap);
1045 1394
1046 pixmap = tiled_root_pmap; 1395 pixmap = tiled_root_pmap;
1047 pmap_width = window_width; 1396 pmap_width = window_width;
1048 pmap_height = window_height; 1397 pmap_height = window_height;
1049 pmap_depth = root_depth; 1398 pmap_depth = target->depth;
1050 } 1399 }
1051 1400
1052 if (gc) 1401 if (recoded_root_pmap != root_pixmap)
1053 XFreeGC (dpy, gc); 1402 XFreePixmap (dpy, recoded_root_pmap);
1054
1055 TIMING_TEST_PRINT_RESULT (tp);
1056 1403
1057 return result; 1404 return result;
1058} 1405}
1059 1406
1060bool 1407void
1061bgPixmap_t::set_root_pixmap () 1408bgPixmap_t::set_root_pixmap ()
1062{ 1409{
1063 Pixmap new_root_pixmap = None;
1064
1065 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1410 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1066 if (new_root_pixmap == None) 1411 if (new_root_pixmap == None)
1067 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1412 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1068 1413
1069 if (new_root_pixmap != root_pixmap)
1070 {
1071 root_pixmap = new_root_pixmap; 1414 root_pixmap = new_root_pixmap;
1072 return true;
1073 }
1074 return false;
1075} 1415}
1076# endif /* ENABLE_TRANSPARENCY */ 1416# endif /* ENABLE_TRANSPARENCY */
1077 1417
1078# ifndef HAVE_AFTERIMAGE 1418# ifndef HAVE_AFTERIMAGE
1079static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); 1419static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm);
1080# endif 1420# endif
1081
1082 1421
1083bool 1422bool
1084bgPixmap_t::render () 1423bgPixmap_t::render ()
1085{ 1424{
1086 unsigned long background_flags = 0; 1425 unsigned long background_flags = 0;
1087 1426
1088 if (target == NULL) 1427 if (target == NULL)
1089 return false; 1428 return false;
1090 1429
1091 TIMING_TEST_START (tp);
1092
1093 invalidate(); 1430 invalidate ();
1094# ifdef ENABLE_TRANSPARENCY 1431# ifdef ENABLE_TRANSPARENCY
1095 if (flags & isTransparent) 1432 if (flags & isTransparent)
1096 { 1433 {
1097 /* we need to re-generate transparency pixmap in that case ! */ 1434 /* we need to re-generate transparency pixmap in that case ! */
1098 background_flags = make_transparency_pixmap (); 1435 background_flags = make_transparency_pixmap ();
1099 if (background_flags == 0) 1436 if (background_flags == 0)
1100 return false; 1437 return false;
1101 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1438 else if ((background_flags & transpTransformations) == (flags & transpTransformations))
1102 && pmap_depth == target->depth)
1103 flags = flags & ~isInvalid; 1439 flags = flags & ~isInvalid;
1104 } 1440 }
1105# endif 1441# endif
1106 1442
1443# ifdef BG_IMAGE_FROM_FILE
1444 if (have_image
1445 || (background_flags & transpTransformations) != (flags & transpTransformations))
1446 {
1447 if (render_image (background_flags))
1448 flags = flags & ~isInvalid;
1449 }
1450# endif
1451
1452# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER
1107 XImage *result = NULL; 1453 XImage *result = NULL;
1108# ifdef HAVE_AFTERIMAGE 1454
1109 if (original_asim 1455 if (background_flags && (flags & isInvalid))
1110 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1456 {
1457 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1111 { 1458 }
1112 ASImage *background = NULL;
1113 ARGB32 as_tint = TINT_LEAVE_SAME;
1114 if (background_flags)
1115 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
1116 1459
1117# ifdef ENABLE_TRANSPARENCY 1460 if (result)
1461 {
1462 /* our own client-side tinting */
1118 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1463 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1119 { 1464 {
1120 ShadingInfo as_shade;
1121 as_shade.shading = (shade == 0) ? 100 : shade;
1122
1123 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1465 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1124 if (flags & tintSet) 1466 if (flags & tintSet)
1125 tint.get (c); 1467 tint.get (c);
1126 as_shade.tintColor.red = c.r; 1468 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b);
1127 as_shade.tintColor.green = c.g;
1128 as_shade.tintColor.blue = c.b;
1129
1130 as_tint = shading2tint32 (&as_shade);
1131 }
1132 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1133 { 1469 }
1134 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
1135 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1136 100, ASIMAGE_QUALITY_DEFAULT);
1137 if (tmp)
1138 {
1139 destroy_asimage (&background);
1140 background = tmp;
1141 }
1142 }
1143# endif
1144 1470
1145 if (render_asim (background, as_tint))
1146 flags = flags & ~isInvalid;
1147 if (background)
1148 destroy_asimage (&background);
1149 }
1150 else if (background_flags && pmap_depth != target->depth)
1151 {
1152 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1153 }
1154
1155# elif !XFT /* our own client-side tinting */
1156
1157 /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side.
1158 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1159
1160 if (background_flags && (flags & isInvalid))
1161 {
1162 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1163 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1164 {
1165 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1166 if (flags & tintSet)
1167 tint.get (c);
1168 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1169 }
1170 }
1171# endif /* HAVE_AFTERIMAGE */
1172
1173 if (result != NULL)
1174 {
1175 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1471 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1472
1176 if (gc) 1473 if (gc)
1177 { 1474 {
1178 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1179 {
1180 XFreePixmap (target->dpy, pixmap);
1181 pixmap = None;
1182 }
1183 if (pixmap == None)
1184 {
1185 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1186 pmap_width = result->width;
1187 pmap_height = result->height;
1188 pmap_depth = target->depth;
1189 }
1190 if (pmap_depth != result->depth)
1191 { /* Bad Match error will ensue ! stupid X !!!! */
1192 if( result->depth == 24 && pmap_depth == 32)
1193 result->depth = 32;
1194 else if( result->depth == 32 && pmap_depth == 24)
1195 result->depth = 24;
1196 else
1197 {
1198 /* TODO: implement image recoding */
1199 }
1200 }
1201 if (pmap_depth == result->depth)
1202 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1475 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1476
1203 XFreeGC (target->dpy, gc); 1477 XFreeGC (target->dpy, gc);
1204 flags = flags & ~isInvalid; 1478 flags = flags & ~isInvalid;
1205 } 1479 }
1480
1206 XDestroyImage (result); 1481 XDestroyImage (result);
1207 } 1482 }
1483# endif
1208 1484
1209 if (flags & isInvalid) 1485 if (flags & isInvalid)
1210 { 1486 {
1211 if (pixmap != None) 1487 if (pixmap != None)
1212 { 1488 {
1215 } 1491 }
1216 } 1492 }
1217 1493
1218 apply (); 1494 apply ();
1219 1495
1220 TIMING_TEST_PRINT_RESULT (tp); 1496 valid_since = ev::now ();
1221 1497
1222 return true; 1498 return true;
1223} 1499}
1224 1500
1225bool 1501void
1226bgPixmap_t::set_target (rxvt_term *new_target) 1502bgPixmap_t::set_target (rxvt_term *new_target)
1227{ 1503{
1228 if (new_target)
1229 if (target != new_target)
1230 {
1231 target = new_target; 1504 target = new_target;
1505
1506 flags &= ~(HAS_RENDER | HAS_RENDER_CONV);
1507#if XRENDER
1508 int major, minor;
1509 if (XRenderQueryVersion (target->dpy, &major, &minor))
1510 flags |= HAS_RENDER;
1511 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt);
1512 if (filters)
1513 {
1514 for (int i = 0; i < filters->nfilter; i++)
1515 if (!strcmp (filters->filter[i], FilterConvolution))
1516 flags |= HAS_RENDER_CONV;
1517
1518 XFree (filters);
1519 }
1520#endif
1521}
1522
1523void
1524bgPixmap_t::apply ()
1525{
1526 if (target == NULL)
1527 return;
1528
1529 if (pixmap != None)
1530 {
1531 /* set target's background to pixmap */
1232# ifdef ENABLE_TRANSPARENCY 1532# ifdef ENABLE_TRANSPARENCY
1233 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1533 if (flags & isTransparent)
1534 {
1535 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1536 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1537
1538 if (target->scrollBar.win)
1539 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1540 }
1541 else
1234# endif 1542# endif
1235 return true;
1236 }
1237 return false;
1238}
1239
1240void
1241bgPixmap_t::apply()
1242{
1243 if (target)
1244 {
1245 flags &= ~isVtOrigin;
1246 if (pixmap != None)
1247 { /* set target's background to pixmap */
1248# ifdef ENABLE_TRANSPARENCY
1249 if (flags & isTransparent)
1250 { 1543 {
1251 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1252 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1253# if HAVE_SCROLLBARS
1254 if (target->scrollBar.win)
1255 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1256# endif
1257 }
1258 else
1259# endif
1260 {
1261 flags |= isVtOrigin;
1262 /* force old pixmap dereference in case it was transparent before :*/ 1544 /* force old pixmap dereference in case it was transparent before :*/
1263 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1264 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1265 /* do we also need to set scrollbar's background here ? */
1266# if HAVE_SCROLLBARS
1267 if (target->scrollBar.win)
1268 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1269# endif
1270 }
1271 }
1272 else
1273 { /* set target background to a pixel */
1274 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1545 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1275 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1546 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1276 /* do we also need to set scrollbar's background here ? */ 1547 /* do we also need to set scrollbar's background here ? */
1277# if HAVE_SCROLLBARS 1548
1278 if (target->scrollBar.win) 1549 if (target->scrollBar.win)
1279 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1550 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1280# endif
1281 } 1551 }
1282 /* don't want Expose on the parent or vt. It is better to use 1552 }
1283 scr_touch or we get a great deal of flicker otherwise: */ 1553 else
1284 XClearWindow (target->dpy, target->parent[0]); 1554 {
1285 1555 /* set target background to a pixel */
1286# if HAVE_SCROLLBARS 1556 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1557 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1558 /* do we also need to set scrollbar's background here ? */
1287 if (target->scrollBar.win) 1559 if (target->scrollBar.win)
1288 { 1560 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1289 target->scrollBar.setIdle (); 1561 }
1562
1563 /* don't want Expose on the parent or vt. It is better to use
1564 scr_touch or we get a great deal of flicker otherwise: */
1565 XClearWindow (target->dpy, target->parent[0]);
1566
1567 if (target->scrollBar.state && target->scrollBar.win)
1568 {
1569 target->scrollBar.state = STATE_IDLE;
1290 target->scrollbar_show (0); 1570 target->scrollBar.show (0);
1291 } 1571 }
1292# endif
1293 1572
1294 target->want_refresh = 1; 1573 target->want_refresh = 1;
1295 flags |= hasChanged; 1574 flags |= hasChanged;
1296 }
1297} 1575}
1298 1576
1299#endif /* HAVE_BG_PIXMAP */ 1577#endif /* HAVE_BG_PIXMAP */
1300 1578
1301#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT 1579#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER
1302/* taken from aterm-0.4.2 */ 1580/* taken from aterm-0.4.2 */
1303 1581
1304typedef uint32_t RUINT32T;
1305
1306static void 1582static void
1307ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) 1583ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm)
1308{ 1584{
1309 int sh_r, sh_g, sh_b; 1585 int sh_r, sh_g, sh_b;
1310 RUINT32T mask_r, mask_g, mask_b; 1586 uint32_t mask_r, mask_g, mask_b;
1311 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 1587 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1312 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1588 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
1313 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1589 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
1314 int i; 1590 int i;
1591 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst;
1315 1592
1316 Visual *visual = term->visual;
1317
1318 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; 1593 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return;
1319
1320 if (shade == 0)
1321 shade = 100;
1322 1594
1323 /* for convenience */ 1595 /* for convenience */
1324 mask_r = visual->red_mask; 1596 mask_r = visual->red_mask;
1325 mask_g = visual->green_mask; 1597 mask_g = visual->green_mask;
1326 mask_b = visual->blue_mask; 1598 mask_b = visual->blue_mask;
1327 1599
1328 /* boring lookup table pre-initialization */ 1600 /* boring lookup table pre-initialization */
1329 switch (srcImage->bits_per_pixel) { 1601 switch (srcImage->depth)
1602 {
1330 case 15: 1603 case 15:
1331 if ((mask_r != 0x7c00) || 1604 if ((mask_r != 0x7c00) ||
1332 (mask_g != 0x03e0) || 1605 (mask_g != 0x03e0) ||
1333 (mask_b != 0x001f)) 1606 (mask_b != 0x001f))
1334 return; 1607 return;
1335 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); 1608 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32));
1336 lookup_r = lookup; 1609 lookup_r = lookup;
1337 lookup_g = lookup+32; 1610 lookup_g = lookup+32;
1338 lookup_b = lookup+32+32; 1611 lookup_b = lookup+32+32;
1339 sh_r = 10; 1612 sh_r = 10;
1340 sh_g = 5; 1613 sh_g = 5;
1341 sh_b = 0; 1614 sh_b = 0;
1342 break; 1615 break;
1343 case 16: 1616 case 16:
1344 if ((mask_r != 0xf800) || 1617 if ((mask_r != 0xf800) ||
1345 (mask_g != 0x07e0) || 1618 (mask_g != 0x07e0) ||
1346 (mask_b != 0x001f)) 1619 (mask_b != 0x001f))
1347 return; 1620 return;
1348 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); 1621 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32));
1349 lookup_r = lookup; 1622 lookup_r = lookup;
1350 lookup_g = lookup+32; 1623 lookup_g = lookup+32;
1351 lookup_b = lookup+32+64; 1624 lookup_b = lookup+32+64;
1352 sh_r = 11; 1625 sh_r = 11;
1353 sh_g = 5; 1626 sh_g = 5;
1354 sh_b = 0; 1627 sh_b = 0;
1355 break; 1628 break;
1356 case 24: 1629 case 24:
1357 if ((mask_r != 0xff0000) || 1630 if ((mask_r != 0xff0000) ||
1358 (mask_g != 0x00ff00) || 1631 (mask_g != 0x00ff00) ||
1359 (mask_b != 0x0000ff)) 1632 (mask_b != 0x0000ff))
1360 return; 1633 return;
1361 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); 1634 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1362 lookup_r = lookup; 1635 lookup_r = lookup;
1363 lookup_g = lookup+256; 1636 lookup_g = lookup+256;
1364 lookup_b = lookup+256+256; 1637 lookup_b = lookup+256+256;
1365 sh_r = 16; 1638 sh_r = 16;
1366 sh_g = 8; 1639 sh_g = 8;
1367 sh_b = 0; 1640 sh_b = 0;
1368 break; 1641 break;
1369 case 32: 1642 case 32:
1370 if ((mask_r != 0xff0000) || 1643 if ((mask_r != 0xff0000) ||
1371 (mask_g != 0x00ff00) || 1644 (mask_g != 0x00ff00) ||
1372 (mask_b != 0x0000ff)) 1645 (mask_b != 0x0000ff))
1373 return; 1646 return;
1374 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); 1647 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1375 lookup_r = lookup; 1648 lookup_r = lookup;
1376 lookup_g = lookup+256; 1649 lookup_g = lookup+256;
1377 lookup_b = lookup+256+256; 1650 lookup_b = lookup+256+256;
1378 sh_r = 16; 1651 sh_r = 16;
1379 sh_g = 8; 1652 sh_g = 8;
1380 sh_b = 0; 1653 sh_b = 0;
1381 break; 1654 break;
1382 default: 1655 default:
1383 return; /* we do not support this color depth */ 1656 return; /* we do not support this color depth */
1384 } 1657 }
1385 1658
1386 /* prepare limits for color transformation (each channel is handled separately) */ 1659 /* prepare limits for color transformation (each channel is handled separately) */
1387 if (shade < 0) { 1660 if (shade > 100)
1661 {
1388 shade = -shade; 1662 shade = 200 - shade;
1389 if (shade < 0) shade = 0;
1390 if (shade > 100) shade = 100;
1391 1663
1392 lower_lim_r = 65535-rm; 1664 lower_lim_r = 65535-rm;
1393 lower_lim_g = 65535-gm; 1665 lower_lim_g = 65535-gm;
1394 lower_lim_b = 65535-bm; 1666 lower_lim_b = 65535-bm;
1395 1667
1396 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); 1668 lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100);
1397 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); 1669 lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100);
1398 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); 1670 lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100);
1399 1671
1400 upper_lim_r = upper_lim_g = upper_lim_b = 65535; 1672 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1673 }
1401 } else { 1674 else
1402 if (shade < 0) shade = 0; 1675 {
1403 if (shade > 100) shade = 100;
1404 1676
1405 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1677 lower_lim_r = lower_lim_g = lower_lim_b = 0;
1406 1678
1407 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); 1679 upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100);
1408 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); 1680 upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100);
1409 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); 1681 upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100);
1410 } 1682 }
1411
1412 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
1413 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
1414 {
1415 unsigned int tmp;
1416
1417 tmp = lower_lim_r;
1418 lower_lim_r = lower_lim_b;
1419 lower_lim_b = tmp;
1420
1421 tmp = upper_lim_r;
1422 upper_lim_r = upper_lim_b;
1423 upper_lim_b = tmp;
1424 }
1425 1683
1426 /* fill our lookup tables */ 1684 /* fill our lookup tables */
1427 for (i = 0; i <= mask_r>>sh_r; i++) 1685 for (i = 0; i <= mask_r>>sh_r; i++)
1428 { 1686 {
1429 RUINT32T tmp; 1687 uint32_t tmp;
1430 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); 1688 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r));
1431 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); 1689 tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r);
1432 lookup_r[i] = (tmp/65535)<<sh_r; 1690 lookup_r[i] = (tmp/65535)<<sh_r;
1433 } 1691 }
1434 for (i = 0; i <= mask_g>>sh_g; i++) 1692 for (i = 0; i <= mask_g>>sh_g; i++)
1435 { 1693 {
1436 RUINT32T tmp; 1694 uint32_t tmp;
1437 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); 1695 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g));
1438 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); 1696 tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g);
1439 lookup_g[i] = (tmp/65535)<<sh_g; 1697 lookup_g[i] = (tmp/65535)<<sh_g;
1440 } 1698 }
1441 for (i = 0; i <= mask_b>>sh_b; i++) 1699 for (i = 0; i <= mask_b>>sh_b; i++)
1442 { 1700 {
1443 RUINT32T tmp; 1701 uint32_t tmp;
1444 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); 1702 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b));
1445 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); 1703 tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b);
1446 lookup_b[i] = (tmp/65535)<<sh_b; 1704 lookup_b[i] = (tmp/65535)<<sh_b;
1447 } 1705 }
1448 1706
1449 /* apply table to input image (replacing colors by newly calculated ones) */ 1707 /* apply table to input image (replacing colors by newly calculated ones) */
1450 switch (srcImage->bits_per_pixel) 1708 if (srcImage->bits_per_pixel == 32
1709 && (srcImage->depth == 24 || srcImage->depth == 32)
1710 && srcImage->byte_order == host_byte_order)
1451 { 1711 {
1452 case 15:
1453 {
1454 unsigned short *p1, *pf, *p, *pl; 1712 uint32_t *p1, *pf, *p, *pl;
1455 p1 = (unsigned short *) srcImage->data; 1713 p1 = (uint32_t *) srcImage->data;
1456 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); 1714 pf = (uint32_t *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1715
1457 while (p1 < pf) 1716 while (p1 < pf)
1458 { 1717 {
1459 p = p1; 1718 p = p1;
1460 pl = p1 + srcImage->width; 1719 pl = p1 + srcImage->width;
1461 for (; p < pl; p++) 1720 for (; p < pl; p++)
1462 { 1721 {
1463 *p = lookup_r[(*p & 0x7c00)>>10] |
1464 lookup_g[(*p & 0x03e0)>> 5] |
1465 lookup_b[(*p & 0x001f)];
1466 }
1467 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
1468 }
1469 break;
1470 }
1471 case 16:
1472 {
1473 unsigned short *p1, *pf, *p, *pl;
1474 p1 = (unsigned short *) srcImage->data;
1475 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1476 while (p1 < pf)
1477 {
1478 p = p1;
1479 pl = p1 + srcImage->width;
1480 for (; p < pl; p++)
1481 {
1482 *p = lookup_r[(*p & 0xf800)>>11] |
1483 lookup_g[(*p & 0x07e0)>> 5] |
1484 lookup_b[(*p & 0x001f)];
1485 }
1486 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
1487 }
1488 break;
1489 }
1490 case 24:
1491 {
1492 unsigned char *p1, *pf, *p, *pl;
1493 p1 = (unsigned char *) srcImage->data;
1494 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1495 while (p1 < pf)
1496 {
1497 p = p1;
1498 pl = p1 + srcImage->width * 3;
1499 for (; p < pl; p += 3)
1500 {
1501 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
1502 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
1503 p[2] = lookup_r[(p[2] & 0x0000ff)];
1504 }
1505 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
1506 }
1507 break;
1508 }
1509 case 32:
1510 {
1511 RUINT32T *p1, *pf, *p, *pl;
1512 p1 = (RUINT32T *) srcImage->data;
1513 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1514
1515 while (p1 < pf)
1516 {
1517 p = p1;
1518 pl = p1 + srcImage->width;
1519 for (; p < pl; p++)
1520 {
1521 *p = lookup_r[(*p & 0xff0000)>>16] | 1722 *p = lookup_r[(*p & 0xff0000) >> 16] |
1522 lookup_g[(*p & 0x00ff00)>> 8] | 1723 lookup_g[(*p & 0x00ff00) >> 8] |
1523 lookup_b[(*p & 0x0000ff)] | 1724 lookup_b[(*p & 0x0000ff)] |
1524 (*p & ~0xffffff); 1725 (*p & 0xff000000);
1726 }
1727 p1 = (uint32_t *) ((char *) p1 + srcImage->bytes_per_line);
1728 }
1729 }
1730 else
1731 {
1732 for (int y = 0; y < srcImage->height; y++)
1733 for (int x = 0; x < srcImage->width; x++)
1734 {
1735 unsigned long pixel = XGetPixel (srcImage, x, y);
1736 pixel = lookup_r[(pixel & mask_r) >> sh_r] |
1737 lookup_g[(pixel & mask_g) >> sh_g] |
1738 lookup_b[(pixel & mask_b) >> sh_b];
1739 XPutPixel (srcImage, x, y, pixel);
1525 } 1740 }
1526 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
1527 } 1741 }
1528 break;
1529 }
1530 }
1531 1742
1532 free (lookup); 1743 free (lookup);
1533} 1744}
1534#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ 1745#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines