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.1 by sasha, Wed Sep 12 20:29:24 2007 UTC vs.
Revision 1.79 by sf-exg, Wed Oct 13 23:01:40 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines