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.23 by ayin, Sat Jan 5 13:52:23 2008 UTC vs.
Revision 1.62 by sf-exg, Sun Oct 3 21:44:13 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 * 8 *
9 * 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
10 * 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
11 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
27#define DO_TIMING_TEST 0 27#define DO_TIMING_TEST 0
28 28
29#if DO_TIMING_TEST 29#if DO_TIMING_TEST
30# include <sys/time.h> 30# include <sys/time.h>
31#define TIMING_TEST_START(id) \ 31#define TIMING_TEST_START(id) \
32 struct timeval timing_test_##id##_stv;\ 32 struct timeval timing_test_##id##_stv; \
33 gettimeofday (&timing_test_##id##_stv, NULL); 33 gettimeofday (&timing_test_##id##_stv, NULL);
34 34
35#define TIMING_TEST_PRINT_RESULT(id) \ 35#define TIMING_TEST_PRINT_RESULT(id) \
36 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; \
37 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__, \
38 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)
39 43
40#else 44#else
41#define TIMING_TEST_START(id) do{}while (0) 45#define TIMING_TEST_START(id) do {} while (0)
42#define TIMING_TEST_PRINT_RESULT(id) do{}while (0) 46#define TIMING_TEST_PRINT_RESULT(id) do {} while (0)
43#endif 47#endif
44 48
45/* 49/*
46 * Pixmap geometry string interpretation : 50 * Pixmap geometry string interpretation :
47 * Each geometry string contains zero or one scale/position 51 * Each geometry string contains zero or one scale/position
48 * 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
49 * colon-delimited pixmap operations. 53 * colon-delimited pixmap operations.
50 * The following table shows the valid geometry strings and their 54 * The following table shows the valid geometry strings and their
51 * affects on the background image : 55 * effects on the background image :
52 * 56 *
53 * 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%.
54 * W and H are percentages of the terminal window size. 58 * W and H are percentages of the terminal window size.
55 * X and Y are also percentages; e.g., +50+50 centers 59 * X and Y are also percentages; e.g., +50+50 centers
56 * the image in the window. 60 * the image in the window.
57 * WxH+X Assumes Y == X 61 * WxH+X Assumes Y == X
58 * WxH Assumes Y == X == 50 (centers the image) 62 * WxH Assumes Y == X == 50 (centers the image)
59 * W+X+Y Assumes H == W 63 * W+X+Y Assumes H == W
60 * W+X Assumes H == W and Y == X 64 * W+X Assumes H == W and Y == X
61 * W Assumes H == W and Y == X == 50 65 * W Assumes H == W and Y == X == 50
62 * 66 *
63 * Adjusting position only : 67 * Adjusting position only :
64 * =+X+Y Set position to X% by Y% (absolute). 68 * =+X+Y Set position to X% by Y% (absolute).
65 * =+X Set position to X% by X%. 69 * =+X Set position to X% by X%.
66 * +X+Y Adjust position horizontally X% and vertically Y% 70 * +X+Y Adjust position horizontally X% and vertically Y%
67 * from current position (relative). 71 * from current position (relative).
68 * +X Adjust position horizontally X% and vertically X% 72 * +X Adjust position horizontally X% and vertically X%
69 * from current position. 73 * from current position.
70 * 74 *
71 * Adjusting scale only : 75 * Adjusting scale only :
72 * Wx0 Multiply horizontal scaling factor by W% 76 * Wx0 Multiply horizontal scaling factor by W%
73 * 0xH Multiply vertical scaling factor by H% 77 * 0xH Multiply vertical scaling factor by H%
74 * 0x0 No scaling (show image at normal size). 78 * 0x0 No scaling (show image at normal size).
75 * 79 *
76 * Pixmap Operations : (should be prepended by a colon) 80 * Pixmap Operations : (should be prepended by a colon)
77 * tile Tile image. Scaling/position modifiers above will affect 81 * tile Tile image. Scaling/position modifiers above will affect
78 * the tile size and origin. 82 * the tile size and origin.
79 * propscale When scaling, scale proportionally. That is, maintain the 83 * propscale When scaling, scale proportionally. That is, maintain the
80 * proper aspect ratio for the image. Any portion of the 84 * proper aspect ratio for the image. Any portion of the
81 * background not covered by the image is filled with the 85 * background not covered by the image is filled with the
82 * current background color. 86 * current background color.
83 * hscale Scale horizontally, tile vertically ? 87 * hscale Scale horizontally, tile vertically ?
84 * vscale Tile horizontally, scale vertically ? 88 * vscale Tile horizontally, scale vertically ?
87 */ 91 */
88 92
89#ifdef HAVE_BG_PIXMAP 93#ifdef HAVE_BG_PIXMAP
90bgPixmap_t::bgPixmap_t () 94bgPixmap_t::bgPixmap_t ()
91{ 95{
96 // this is basically redundant as bgPixmap_t is only used in
97 // zero_initialised-derived structs
92#ifdef HAVE_AFTERIMAGE 98#ifdef HAVE_AFTERIMAGE
93 original_asim = NULL; 99 original_asim = NULL;
94#endif 100#endif
101#ifdef HAVE_PIXBUF
102 pixbuf = NULL;
103#endif
95#ifdef BG_IMAGE_FROM_FILE 104#ifdef BG_IMAGE_FROM_FILE
105 have_image = false;
96 h_scale = v_scale = 0; 106 h_scale = v_scale = 0;
97 h_align = v_align = 0; 107 h_align = v_align = 0;
98#endif 108#endif
99 flags = 0; 109 flags = 0;
100 pixmap = None; 110 pixmap = None;
101 valid_since = invalid_since = 0; 111 valid_since = invalid_since = 0;
112 target = 0;
102} 113}
103 114
104void 115void
105bgPixmap_t::destroy () 116bgPixmap_t::destroy ()
106{ 117{
107#ifdef HAVE_AFTERIMAGE 118#ifdef HAVE_AFTERIMAGE
108 if (original_asim) 119 if (original_asim)
109 safe_asimage_destroy (original_asim); 120 safe_asimage_destroy (original_asim);
110#endif 121#endif
111 122
123#ifdef HAVE_PIXBUF
124 if (pixbuf)
125 g_object_unref (pixbuf);
126#endif
127
112 if (pixmap && target) 128 if (pixmap && target)
113 XFreePixmap (target->dpy, pixmap); 129 XFreePixmap (target->dpy, pixmap);
114} 130}
115 131
116bool 132bool
120 if (flags & isTransparent) 136 if (flags & isTransparent)
121 return true; 137 return true;
122# endif 138# endif
123 139
124# ifdef BG_IMAGE_FROM_FILE 140# ifdef BG_IMAGE_FROM_FILE
125# ifdef HAVE_AFTERIMAGE 141 if (have_image)
126 if (original_asim != NULL)
127# endif
128 { 142 {
129 if (h_scale != 0 || v_scale != 0 143 if (flags & sizeSensitive)
130 || h_align != 0 || v_align != 0)
131 return true; 144 return true;
132 } 145 }
133# endif 146# endif
134 147
135 return false; 148 return false;
136} 149}
137 150
138bool 151bool
139bgPixmap_t::window_position_sensitive () 152bgPixmap_t::window_position_sensitive ()
140{ 153{
141# ifdef ENABLE_TRANSPARENCY 154# ifdef ENABLE_TRANSPARENCY
142 if (flags & isTransparent) 155 if (flags & isTransparent)
143 return true; 156 return true;
144# endif 157# endif
145 158
146# ifdef BG_IMAGE_FROM_FILE 159# ifdef BG_IMAGE_FROM_FILE
147# ifdef HAVE_AFTERIMAGE 160 if (have_image)
148 if (original_asim != NULL)
149# endif
150 { 161 {
151 if (h_align == rootAlign || v_align == rootAlign) 162 if (h_align == rootAlign || v_align == rootAlign)
152 return true; 163 return true;
153 } 164 }
154# endif 165# endif
157}; 168};
158 169
159bool bgPixmap_t::need_client_side_rendering () 170bool bgPixmap_t::need_client_side_rendering ()
160{ 171{
161# ifdef HAVE_AFTERIMAGE 172# ifdef HAVE_AFTERIMAGE
162 if (original_asim != NULL) 173 if (original_asim)
163 return true; 174 return true;
164# endif 175# endif
165# ifdef ENABLE_TRANSPARENCY 176# ifdef ENABLE_TRANSPARENCY
166 if (flags & isTransparent) 177 if (flags & isTransparent)
167 { 178 {
216 227
217static inline int 228static inline int
218make_align_position (int align, int window_size, int image_size) 229make_align_position (int align, int window_size, int image_size)
219{ 230{
220 int diff = window_size - image_size; 231 int diff = window_size - image_size;
221 int smaller = MIN (image_size,window_size); 232 int smaller = min (image_size, window_size);
222 233
223 if (align >= 0 && align <= 50) 234 if (align >= 0 && align <= 50)
224 return diff * align / 100; 235 return diff * align / 100;
225 else if (align > 50 && align <= 100) 236 else if (align > 50 && align <= 100)
226 return window_size - image_size - diff * (100 - align) / 100; 237 return window_size - image_size - diff * (100 - align) / 100;
235make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 246make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
236{ 247{
237 int src_pos = 0; 248 int src_pos = 0;
238 dst_pos = 0; 249 dst_pos = 0;
239 dst_size = size; 250 dst_size = size;
240 if (pos < 0 && size > target_size) 251 if (pos < 0)
241 { 252 {
242 src_pos = -pos; 253 src_pos = -pos;
243 dst_size += pos; 254 dst_size += pos;
244 } 255 }
245 else if (pos > 0) 256 else if (pos > 0)
256 int geom_flags = 0, changed = 0; 267 int geom_flags = 0, changed = 0;
257 int x = 0, y = 0; 268 int x = 0, y = 0;
258 unsigned int w = 0, h = 0; 269 unsigned int w = 0, h = 0;
259 unsigned int n; 270 unsigned int n;
260 unsigned long new_flags = (flags & (~geometryFlags)); 271 unsigned long new_flags = (flags & (~geometryFlags));
261 char *p; 272 const char *p;
262# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ 273# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
263 274
264 if (geom == NULL) 275 if (geom == NULL)
265 return false; 276 return false;
266 277
274 if (n < MAXLEN_GEOM) 285 if (n < MAXLEN_GEOM)
275 { 286 {
276 char *ops; 287 char *ops;
277 new_flags |= geometrySet; 288 new_flags |= geometrySet;
278 289
279 strncpy (str, geom, n); 290 memcpy (str, geom, n);
280 str[n] = '\0'; 291 str[n] = '\0';
281 if (str[0] == ':') 292 if (str[0] == ':')
282 ops = &str[0]; 293 ops = &str[0];
283 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) 294 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
284 ops = &str[0]; 295 ops = &str[0];
367 if (ops) 378 if (ops)
368 { 379 {
369 while (*ops) 380 while (*ops)
370 { 381 {
371 while (*ops == ':' || isspace(*ops)) ++ops; 382 while (*ops == ':' || isspace(*ops)) ++ops;
383
372# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) 384# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0)
373 if (CHECK_GEOM_OPS("tile")) 385 if (CHECK_GEOM_OPS ("tile"))
374 { 386 {
375 w = h = noScale; 387 w = h = noScale;
376 geom_flags |= WidthValue|HeightValue; 388 geom_flags |= WidthValue|HeightValue;
377 } 389 }
378 else if (CHECK_GEOM_OPS("propscale")) 390 else if (CHECK_GEOM_OPS ("propscale"))
379 { 391 {
380 if (w == 0 && h == 0)
381 {
382 w = windowScale;
383 geom_flags |= WidthValue;
384 }
385 new_flags |= propScale; 392 new_flags |= propScale;
386 } 393 }
387 else if (CHECK_GEOM_OPS("hscale")) 394 else if (CHECK_GEOM_OPS ("hscale"))
388 { 395 {
389 if (w == 0)
390 w = windowScale; 396 if (w == 0) w = windowScale;
397
391 h = noScale; 398 h = noScale;
392 geom_flags |= WidthValue|HeightValue; 399 geom_flags |= WidthValue|HeightValue;
393 } 400 }
394 else if (CHECK_GEOM_OPS("vscale")) 401 else if (CHECK_GEOM_OPS ("vscale"))
395 { 402 {
396 if (h == 0)
397 h = windowScale; 403 if (h == 0) h = windowScale;
404
398 w = noScale; 405 w = noScale;
399 geom_flags |= WidthValue|HeightValue; 406 geom_flags |= WidthValue|HeightValue;
400 } 407 }
401 else if (CHECK_GEOM_OPS("scale")) 408 else if (CHECK_GEOM_OPS ("scale"))
402 { 409 {
403 if (h == 0)
404 h = windowScale; 410 if (h == 0) h = windowScale;
405 if (w == 0)
406 w = windowScale; 411 if (w == 0) w = windowScale;
412
407 geom_flags |= WidthValue|HeightValue; 413 geom_flags |= WidthValue|HeightValue;
408 } 414 }
409 else if (CHECK_GEOM_OPS("auto")) 415 else if (CHECK_GEOM_OPS ("auto"))
410 { 416 {
411 w = h = windowScale; 417 w = h = windowScale;
412 x = y = centerAlign; 418 x = y = centerAlign;
413 geom_flags |= WidthValue|HeightValue|XValue|YValue; 419 geom_flags |= WidthValue|HeightValue|XValue|YValue;
414 } 420 }
415 else if (CHECK_GEOM_OPS("root")) 421 else if (CHECK_GEOM_OPS ("root"))
416 { 422 {
417 w = h = noScale; 423 w = h = noScale;
418 x = y = rootAlign; 424 x = y = rootAlign;
419 geom_flags |= WidthValue|HeightValue|XValue|YValue; 425 geom_flags |= WidthValue|HeightValue|XValue|YValue;
420 } 426 }
421# undef CHECK_GEOM_OPS 427# undef CHECK_GEOM_OPS
428
422 while (*ops != ':' && *ops != '\0') ++ops; 429 while (*ops != ':' && *ops != '\0') ++ops;
423 } /* done parsing ops */ 430 } /* done parsing ops */
424 } 431 }
425 432
426 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) 433 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed;
427 ++changed;
428 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) 434 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed;
429 ++changed;
430 if (check_set_align_value (geom_flags, XValue, h_align, x)) 435 if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed;
431 ++changed;
432 if (check_set_align_value (geom_flags, YValue, v_align, y)) 436 if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed;
433 ++changed;
434 } 437 }
435 438
436 if (new_flags != flags) 439 if (new_flags != flags)
437 { 440 {
438 flags = new_flags; 441 flags = new_flags;
439 changed++; 442 changed++;
440 } 443 }
444
441//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 445 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
442// flags, h_scale, v_scale, h_align, v_align); 446 // flags, h_scale, v_scale, h_align, v_align);
443 return (changed > 0); 447 return (changed > 0);
448}
449
450void
451bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
452{
453 int target_width = target->szHint.width;
454 int target_height = target->szHint.height;
455
456 if (flags & propScale)
457 {
458 float scale = (float)target_width / image_width;
459 min_it (scale, (float)target_height / image_height);
460 w = image_width * scale + 0.5;
461 h = image_height * scale + 0.5;
462 }
463 else
464 {
465 w = h_scale * target_width / 100;
466 h = v_scale * target_height / 100;
467 }
468
469 if (h_align == rootAlign || v_align == rootAlign)
470 {
471 target->get_window_origin (x, y);
472 x = -x;
473 y = -y;
474 }
475
476 if (h_align != rootAlign)
477 x = make_align_position (h_align, target_width, w > 0 ? w : image_width);
478
479 if (v_align != rootAlign)
480 y = make_align_position (v_align, target_height, h > 0 ? h : image_height);
481
482 flags &= ~sizeSensitive;
483 if (h_scale != 0 || v_scale != 0
484 || h_align != 0 || v_align != 0
485 || image_width > target_width || image_height > target_height)
486 flags |= sizeSensitive;
444} 487}
445 488
446# ifdef HAVE_AFTERIMAGE 489# ifdef HAVE_AFTERIMAGE
447bool 490bool
448bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) 491bgPixmap_t::render_image (unsigned long background_flags)
449{ 492{
450 if (target == NULL) 493 if (target == NULL)
451 return false; 494 return false;
452 495
496 target->init_asv ();
497
498 ASImage *background = NULL;
499 ARGB32 background_tint = TINT_LEAVE_SAME;
500
501# ifdef ENABLE_TRANSPARENCY
502 if (background_flags)
503 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
504
505 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
506 {
507 ShadingInfo as_shade;
508 as_shade.shading = (shade == 0) ? 100 : shade;
509
510 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
511 if (flags & tintSet)
512 tint.get (c);
513 as_shade.tintColor.red = c.r;
514 as_shade.tintColor.green = c.g;
515 as_shade.tintColor.blue = c.b;
516
517 background_tint = shading2tint32 (&as_shade);
518 }
519
520 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
521 {
522 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
523 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage,
524 100, ASIMAGE_QUALITY_DEFAULT);
525 if (tmp)
526 {
527 destroy_asimage (&background);
528 background = tmp;
529 }
530 }
531# endif
532
533 ASImage *result = 0;
534
453 int target_width = (int)target->szHint.width; 535 int target_width = target->szHint.width;
454 int target_height = (int)target->szHint.height; 536 int target_height = target->szHint.height;
455 int new_pmap_width = target_width, new_pmap_height = target_height; 537 int new_pmap_width = target_width;
456 ASImage *result = NULL; 538 int new_pmap_height = target_height;
457 539
458 int x = 0; 540 int x = 0;
459 int y = 0; 541 int y = 0;
460 int w = h_scale * target_width / 100; 542 int w = 0;
461 int h = v_scale * target_height / 100; 543 int h = 0;
462 544
463 TIMING_TEST_START (asim); 545 TIMING_TEST_START (asim);
464 546
465 if (original_asim) 547 if (original_asim)
466 { 548 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
467 if (h_align == rootAlign || v_align == rootAlign)
468 {
469 target->get_window_origin(x, y);
470 x = -x;
471 y = -y;
472 }
473 if (h_align != rootAlign)
474 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
475 if (v_align != rootAlign)
476 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
477 }
478 549
479 if (original_asim == NULL 550 if (!original_asim
480 || x >= target_width 551 || x >= target_width
481 || y >= target_height 552 || y >= target_height
482 || (w > 0 && x + w <= 0) 553 || (w > 0 && x + w <= 0)
483 || (h > 0 && y + h <= 0)) 554 || (h > 0 && y + h <= 0))
484 { 555 {
485 if (background) 556 if (background)
486 { 557 {
487 new_pmap_width = background->width; 558 new_pmap_width = background->width;
488 new_pmap_height = background->height; 559 new_pmap_height = background->height;
489 result = background; 560 result = background;
561
490 if (background_tint != TINT_LEAVE_SAME) 562 if (background_tint != TINT_LEAVE_SAME)
491 { 563 {
492 ASImage* tmp = tile_asimage (target->asv, background, 0, 0, 564 ASImage *tmp = tile_asimage (target->asv, background, 0, 0,
493 target_width, target_height, background_tint, 565 target_width, target_height, background_tint,
494 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); 566 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
495 if (tmp) 567 if (tmp)
496 result = tmp; 568 result = tmp;
497 } 569 }
500 new_pmap_width = new_pmap_height = 0; 572 new_pmap_width = new_pmap_height = 0;
501 } 573 }
502 else 574 else
503 { 575 {
504 result = original_asim; 576 result = original_asim;
577
505 if ((w > 0 && w != original_asim->width) 578 if ((w > 0 && w != original_asim->width)
506 || (h > 0 && h != original_asim->height)) 579 || (h > 0 && h != original_asim->height))
507 { 580 {
508 result = scale_asimage (target->asv, original_asim, 581 result = scale_asimage (target->asv, original_asim,
509 w > 0 ? w : original_asim->width, 582 w > 0 ? w : original_asim->width,
510 h > 0 ? h : original_asim->height, 583 h > 0 ? h : original_asim->height,
511 background ? ASA_ASImage : ASA_XImage, 584 background ? ASA_ASImage : ASA_XImage,
512 100, ASIMAGE_QUALITY_DEFAULT); 585 100, ASIMAGE_QUALITY_DEFAULT);
513 } 586 }
587
514 if (background == NULL) 588 if (background == NULL)
515 { 589 {
516 /* if tiling - pixmap has to be sized exactly as the image,
517 but there is no need to make it bigger than the window! */
518 if (h_scale == 0)
519 new_pmap_width = min (result->width, target_width);
520 if (v_scale == 0)
521 new_pmap_height = min (result->height, target_height);
522 /* we also need to tile our image in one or both directions */
523 if (h_scale == 0 || v_scale == 0) 590 if (h_scale == 0 || v_scale == 0)
524 { 591 {
592 /* if tiling - pixmap has to be sized exactly as the image,
593 but there is no need to make it bigger than the window! */
594 new_pmap_width = min (result->width, target_width);
595 new_pmap_height = min (result->height, target_height);
596
597 /* we also need to tile our image in both directions */
525 ASImage *tmp = tile_asimage (target->asv, result, 598 ASImage *tmp = tile_asimage (target->asv, result,
526 (h_scale > 0) ? 0 : (int)result->width - x, 599 (int)result->width - x,
527 (v_scale > 0) ? 0 : (int)result->height - y, 600 (int)result->height - y,
528 new_pmap_width, 601 new_pmap_width,
529 new_pmap_height, 602 new_pmap_height,
530 TINT_LEAVE_SAME, ASA_XImage, 603 TINT_LEAVE_SAME, ASA_XImage,
531 100, ASIMAGE_QUALITY_DEFAULT); 604 100, ASIMAGE_QUALITY_DEFAULT);
532 if (tmp) 605 if (tmp)
533 { 606 {
534 if (result != original_asim) 607 if (result != original_asim)
535 destroy_asimage (&result); 608 destroy_asimage (&result);
609
536 result = tmp; 610 result = tmp;
537 } 611 }
538 } 612 }
539 } 613 }
540 else 614 else
541 { 615 {
542 /* if blending background and image - pixmap has to be sized same as target window */ 616 /* if blending background and image - pixmap has to be sized same as target window */
543 ASImageLayer *layers = create_image_layers (2); 617 ASImageLayer *layers = create_image_layers (2);
544 ASImage *merged_im = NULL;
545 618
546 layers[0].im = background; 619 layers[0].im = background;
547 layers[0].clip_width = target_width; 620 layers[0].clip_width = target_width;
548 layers[0].clip_height = target_height; 621 layers[0].clip_height = target_height;
549 layers[0].tint = background_tint; 622 layers[0].tint = background_tint;
550 layers[1].im = result; 623 layers[1].im = result;
624
551 if (w <= 0) 625 if (w <= 0)
552 { 626 {
553 /* tile horizontally */ 627 /* tile horizontally */
554 while (x > 0) x -= (int)result->width; 628 while (x > 0) x -= (int)result->width;
555 layers[1].dst_x = x; 629 layers[1].dst_x = x;
559 { 633 {
560 /* clip horizontally */ 634 /* clip horizontally */
561 layers[1].dst_x = x; 635 layers[1].dst_x = x;
562 layers[1].clip_width = result->width; 636 layers[1].clip_width = result->width;
563 } 637 }
638
564 if (h <= 0) 639 if (h <= 0)
565 { 640 {
566 while (y > 0) y -= (int)result->height; 641 while (y > 0) y -= (int)result->height;
567 layers[1].dst_y = y; 642 layers[1].dst_y = y;
568 layers[1].clip_height = result->height + target_height; 643 layers[1].clip_height = result->height + target_height;
570 else 645 else
571 { 646 {
572 layers[1].dst_y = y; 647 layers[1].dst_y = y;
573 layers[1].clip_height = result->height; 648 layers[1].clip_height = result->height;
574 } 649 }
650
575 if (target->rs[Rs_blendtype]) 651 if (target->rs[Rs_blendtype])
576 { 652 {
577 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); 653 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]);
578 if (layers[1].merge_scanlines == NULL) 654 if (layers[1].merge_scanlines == NULL)
579 layers[1].merge_scanlines = alphablend_scanlines; 655 layers[1].merge_scanlines = alphablend_scanlines;
580 } 656 }
657
581 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, 658 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height,
582 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); 659 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
660
583 if (tmp) 661 if (tmp)
584 { 662 {
585 if (result != original_asim) 663 if (result != original_asim)
586 destroy_asimage (&result); 664 destroy_asimage (&result);
665
587 result = tmp; 666 result = tmp;
588 } 667 }
668
589 free (layers); 669 free (layers);
590 } 670 }
591 } 671 }
592 TIMING_TEST_PRINT_RESULT (asim); 672 TIMING_TEST_PRINT_RESULT (asim);
593 673
594 if (pixmap) 674 bool ret = false;
595 {
596 if (result == NULL
597 || pmap_width != new_pmap_width
598 || pmap_height != new_pmap_height
599 || pmap_depth != target->depth)
600 {
601 XFreePixmap (target->dpy, pixmap);
602 pixmap = None;
603 }
604 }
605 675
606 if (result) 676 if (result)
607 { 677 {
608 XGCValues gcv; 678 XGCValues gcv;
609 GC gc; 679 GC gc;
680
681 if (pixmap)
682 {
683 if (pmap_width != new_pmap_width
684 || pmap_height != new_pmap_height
685 || pmap_depth != target->depth)
686 {
687 XFreePixmap (target->dpy, pixmap);
688 pixmap = None;
689 }
690 }
610 691
611 /* create Pixmap */ 692 /* create Pixmap */
612 if (pixmap == None) 693 if (pixmap == None)
613 { 694 {
614 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 695 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
615 pmap_width = new_pmap_width; 696 pmap_width = new_pmap_width;
616 pmap_height = new_pmap_height; 697 pmap_height = new_pmap_height;
617 pmap_depth = target->depth; 698 pmap_depth = target->depth;
618 } 699 }
619 /* fill with background color ( if result's not completely overlapping it)*/ 700 /* fill with background color (if result's not completely overlapping it) */
620 gcv.foreground = target->pix_colors[Color_bg]; 701 gcv.foreground = target->pix_colors[Color_bg];
621 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 702 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
622 703
623 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 704 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
624 int dst_width = result->width, dst_height = result->height; 705 int dst_width = result->width, dst_height = result->height;
625 if (background == NULL) 706 if (background == NULL)
626 { 707 {
627 if (h_scale > 0) 708 if (!(h_scale == 0 || v_scale == 0))
709 {
628 src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width); 710 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
629 if (v_scale > 0)
630 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 711 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
712 }
631 713
632 if (dst_x > 0 || dst_y > 0 714 if (dst_x > 0 || dst_y > 0
633 || dst_x + dst_width < new_pmap_width 715 || dst_x + dst_width < new_pmap_width
634 || dst_y + dst_height < new_pmap_height) 716 || dst_y + dst_height < new_pmap_height)
635 {
636 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 717 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
637 }
638 } 718 }
639 719
640 /* put result on pixmap */ 720 /* put result on pixmap */
641 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 721 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
642 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); 722 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
644 if (result != background && result != original_asim) 724 if (result != background && result != original_asim)
645 destroy_asimage (&result); 725 destroy_asimage (&result);
646 726
647 XFreeGC (target->dpy, gc); 727 XFreeGC (target->dpy, gc);
648 TIMING_TEST_PRINT_RESULT (asim); 728 TIMING_TEST_PRINT_RESULT (asim);
649 }
650 729
730 ret = true;
731 }
732
733 if (background)
734 destroy_asimage (&background);
735
651 return true; 736 return ret;
652} 737}
653# endif /* HAVE_AFTERIMAGE */ 738# endif /* HAVE_AFTERIMAGE */
739
740# ifdef HAVE_PIXBUF
741bool
742bgPixmap_t::render_image (unsigned long background_flags)
743{
744 if (target == NULL)
745 return false;
746
747 if (!pixbuf)
748 return false;
749
750 // TODO: add alpha blending
751 if (background_flags)
752 return false;
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 (x >= target_width
772 || y >= target_height
773 || (w > 0 && x + w <= 0)
774 || (h > 0 && y + h <= 0))
775 return false;
776
777 result = pixbuf;
778
779 if ((w > 0 && w != image_width)
780 || (h > 0 && h != image_height))
781 {
782 result = gdk_pixbuf_scale_simple (pixbuf,
783 w > 0 ? w : image_width,
784 h > 0 ? h : image_height,
785 GDK_INTERP_BILINEAR);
786 }
787
788 bool ret = false;
789
790 if (result)
791 {
792 XGCValues gcv;
793 GC gc;
794
795 image_width = gdk_pixbuf_get_width (result);
796 image_height = gdk_pixbuf_get_height (result);
797
798 if (h_scale == 0 || v_scale == 0)
799 {
800 new_pmap_width = min (image_width, target_width);
801 new_pmap_height = min (image_height, target_height);
802 }
803
804 if (pixmap)
805 {
806 if (pmap_width != new_pmap_width
807 || pmap_height != new_pmap_height
808 || pmap_depth != target->depth)
809 {
810 XFreePixmap (target->dpy, pixmap);
811 pixmap = None;
812 }
813 }
814
815 if (pixmap == None)
816 {
817 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
818 pmap_width = new_pmap_width;
819 pmap_height = new_pmap_height;
820 pmap_depth = target->depth;
821 }
822
823 gcv.foreground = target->pix_colors[Color_bg];
824 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
825
826 if (h_scale == 0 || v_scale == 0)
827 {
828 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
829 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc,
830 0, 0,
831 0, 0,
832 image_width, image_height,
833 XLIB_RGB_DITHER_NONE,
834 0, 0);
835
836 gcv.tile = tile;
837 gcv.fill_style = FillTiled;
838 gcv.ts_x_origin = x;
839 gcv.ts_y_origin = y;
840 XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
841
842 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
843 XFreePixmap (target->dpy, tile);
844 }
845 else
846 {
847 int src_x, src_y, dst_x, dst_y;
848 int dst_width, dst_height;
849
850 src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width );
851 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
852
853 if (dst_x > 0 || dst_y > 0
854 || dst_x + dst_width < new_pmap_width
855 || dst_y + dst_height < new_pmap_height)
856 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
857
858 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
859 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc,
860 src_x, src_y,
861 dst_x, dst_y,
862 dst_width, dst_height,
863 XLIB_RGB_DITHER_NONE,
864 0, 0);
865 }
866
867 if (result != pixbuf)
868 g_object_unref (result);
869
870 XFreeGC (target->dpy, gc);
871
872 ret = true;
873 }
874
875 return ret;
876}
877# endif /* HAVE_PIXBUF */
654 878
655bool 879bool
656bgPixmap_t::set_file (const char *file) 880bgPixmap_t::set_file (const char *file)
657{ 881{
658 char *f;
659
660 assert (file != NULL); 882 assert (file);
661 883
662 if (*file != '\0') 884 if (*file)
663 { 885 {
886 if (const char *p = strchr (file, ';'))
887 {
888 size_t len = p - file;
889 char *f = rxvt_temp_buf<char> (len + 1);
890 memcpy (f, file, len);
891 f[len] = '\0';
892 file = f;
893 }
894
664# ifdef HAVE_AFTERIMAGE 895# ifdef HAVE_AFTERIMAGE
665 if (target->asimman == NULL) 896 if (!target->asimman)
666 target->asimman = create_generic_imageman (target->rs[Rs_path]); 897 target->asimman = create_generic_imageman (target->rs[Rs_path]);
667 if ((f = strchr (file, ';')) == NULL)
668 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 898 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
669 else 899 if (original_asim)
670 { 900 have_image = true;
671 size_t len = f - file; 901 return have_image;
672 f = (char *)malloc (len + 1);
673 strncpy (f, file, len);
674 f[len] = '\0';
675 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
676 free (f);
677 }
678 return (original_asim != NULL);
679# endif 902# endif
903
904# ifdef HAVE_PIXBUF
905 pixbuf = gdk_pixbuf_new_from_file (file, NULL);
906 if (pixbuf)
907 have_image = true;
908 return have_image;
909# endif
680 } 910 }
911
681 return false; 912 return false;
682} 913}
683 914
684# endif /* BG_IMAGE_FROM_FILE */ 915# endif /* BG_IMAGE_FROM_FILE */
685 916
690 if (!(flags & isTransparent)) 921 if (!(flags & isTransparent))
691 { 922 {
692 flags |= isTransparent; 923 flags |= isTransparent;
693 return true; 924 return true;
694 } 925 }
926
695 return false; 927 return false;
696} 928}
697 929
698bool 930bool
699bgPixmap_t::set_blur_radius (const char *geom) 931bgPixmap_t::set_blur_radius (const char *geom)
701 int changed = 0; 933 int changed = 0;
702 unsigned int hr, vr; 934 unsigned int hr, vr;
703 int junk; 935 int junk;
704 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 936 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
705 937
706 if (!(geom_flags&WidthValue)) 938 if (!(geom_flags & WidthValue))
707 hr = 1; 939 hr = 1;
708 if (!(geom_flags&HeightValue)) 940 if (!(geom_flags & HeightValue))
709 vr = hr; 941 vr = hr;
710 942
711 if (h_blurRadius != hr) 943 if (h_blurRadius != hr)
712 { 944 {
713 ++changed; 945 ++changed;
723 if (v_blurRadius == 0 && h_blurRadius == 0) 955 if (v_blurRadius == 0 && h_blurRadius == 0)
724 flags &= ~blurNeeded; 956 flags &= ~blurNeeded;
725 else 957 else
726 flags |= blurNeeded; 958 flags |= blurNeeded;
727 959
728 return (changed>0); 960 return (changed > 0);
729} 961}
730 962
731static inline unsigned long 963static inline unsigned long
732compute_tint_shade_flags (rxvt_color *tint, int shade) 964compute_tint_shade_flags (rxvt_color *tint, int shade)
733{ 965{
750 flags |= bgPixmap_t::tintNeeded; 982 flags |= bgPixmap_t::tintNeeded;
751 else if (tint) 983 else if (tint)
752 { 984 {
753 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 985 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
754 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 986 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
755 { 987 {
756 flags |= bgPixmap_t::tintNeeded; 988 flags |= bgPixmap_t::tintNeeded;
757 } 989 }
758 } 990 }
759 991
760 if (flags & bgPixmap_t::tintNeeded) 992 if (flags & bgPixmap_t::tintNeeded)
761 { 993 {
762 if (flags & bgPixmap_t::tintWholesome) 994 if (flags & bgPixmap_t::tintWholesome)
791{ 1023{
792 unsigned long new_flags = compute_tint_shade_flags (NULL, shade); 1024 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
793 1025
794 if (new_flags != (flags & tintFlags)) 1026 if (new_flags != (flags & tintFlags))
795 { 1027 {
796 flags = (flags&~tintFlags)|new_flags; 1028 flags = (flags & ~tintFlags) | new_flags;
797 return true; 1029 return true;
798 } 1030 }
799 1031
800 return false; 1032 return false;
801} 1033}
802 1034
832 unsigned long result = 0; 1064 unsigned long result = 0;
833 1065
834 if (target == NULL) 1066 if (target == NULL)
835 return 0; 1067 return 0;
836 1068
837 /* root dimentions may change from call to call - but Display structure should 1069 /* root dimensions may change from call to call - but Display structure should
838 * be always up-to-date, so let's use it : 1070 * be always up-to-date, so let's use it :
839 */ 1071 */
840 Window root = target->display->root; 1072 Window root = target->display->root;
841 int screen = target->display->screen; 1073 int screen = target->display->screen;
842 Display *dpy = target->dpy; 1074 Display *dpy = target->dpy;
887 1119
888 attr.background_pixmap = ParentRelative; 1120 attr.background_pixmap = ParentRelative;
889 attr.backing_store = Always; 1121 attr.backing_store = Always;
890 attr.event_mask = ExposureMask; 1122 attr.event_mask = ExposureMask;
891 attr.override_redirect = True; 1123 attr.override_redirect = True;
892 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, 1124 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
893 CopyFromParent, CopyFromParent, CopyFromParent, 1125 CopyFromParent, CopyFromParent, CopyFromParent,
894 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, 1126 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
895 &attr); 1127 &attr);
896 1128
897 if (src != None) 1129 if (src != None)
921 XDestroyWindow (dpy, src); 1153 XDestroyWindow (dpy, src);
922 XUngrabServer (dpy); 1154 XUngrabServer (dpy);
923 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); 1155 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
924 } 1156 }
925 1157
926 if (!success) 1158 if (!success)
927 { 1159 {
928 XFreePixmap (dpy, tiled_root_pmap); 1160 XFreePixmap (dpy, tiled_root_pmap);
929 tiled_root_pmap = None; 1161 tiled_root_pmap = None;
930 } 1162 }
931 else 1163 else
932 result |= transpPmapTiled; 1164 result |= transpPmapTiled;
933 } 1165 }
934 else 1166 else
935 { 1167 {
936 /* strightforward pixmap copy */ 1168 /* straightforward pixmap copy */
937 gcv.tile = root_pixmap; 1169 gcv.tile = root_pixmap;
938 gcv.fill_style = FillTiled; 1170 gcv.fill_style = FillTiled;
939 1171
940 while (sx < 0) sx += (int)root_width; 1172 while (sx < 0) sx += (int)root_width;
941 while (sy < 0) sy += (int)root_height; 1173 while (sy < 0) sy += (int)root_height;
1054# if DO_TIMING_TEST 1286# if DO_TIMING_TEST
1055 XSync (dpy, False); 1287 XSync (dpy, False);
1056# endif 1288# endif
1057# endif 1289# endif
1058 } 1290 }
1059 } 1291 }
1060 } /* server side rendering completed */ 1292 } /* server side rendering completed */
1061 1293
1062 if (pixmap) 1294 if (pixmap)
1063 XFreePixmap (dpy, pixmap); 1295 XFreePixmap (dpy, pixmap);
1064 1296
1092 return false; 1324 return false;
1093} 1325}
1094# endif /* ENABLE_TRANSPARENCY */ 1326# endif /* ENABLE_TRANSPARENCY */
1095 1327
1096# ifndef HAVE_AFTERIMAGE 1328# ifndef HAVE_AFTERIMAGE
1097static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); 1329static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm);
1098# endif 1330# endif
1099 1331
1100bool 1332bool
1101bgPixmap_t::render () 1333bgPixmap_t::render ()
1102{ 1334{
1105 if (target == NULL) 1337 if (target == NULL)
1106 return false; 1338 return false;
1107 1339
1108 TIMING_TEST_START (tp); 1340 TIMING_TEST_START (tp);
1109 1341
1110 invalidate(); 1342 invalidate ();
1111# ifdef ENABLE_TRANSPARENCY 1343# ifdef ENABLE_TRANSPARENCY
1112 if (flags & isTransparent) 1344 if (flags & isTransparent)
1113 { 1345 {
1114 /* we need to re-generate transparency pixmap in that case ! */ 1346 /* we need to re-generate transparency pixmap in that case ! */
1115 background_flags = make_transparency_pixmap (); 1347 background_flags = make_transparency_pixmap ();
1116 if (background_flags == 0) 1348 if (background_flags == 0)
1117 return false; 1349 return false;
1118 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1350 else if ((background_flags & transpTransformations) == (flags & transpTransformations)
1119 && pmap_depth == target->depth) 1351 && pmap_depth == target->depth)
1120 flags = flags & ~isInvalid; 1352 flags = flags & ~isInvalid;
1121 } 1353 }
1122# endif 1354# endif
1123 1355
1356# ifdef BG_IMAGE_FROM_FILE
1357 if (have_image
1358 || (background_flags & transpTransformations) != (flags & transpTransformations))
1359 {
1360 if (render_image (background_flags))
1361 flags = flags & ~isInvalid;
1362 }
1363# endif
1364
1124 XImage *result = NULL; 1365 XImage *result = NULL;
1125# ifdef HAVE_AFTERIMAGE 1366
1126 if (original_asim 1367 if (background_flags && (flags & isInvalid))
1127 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1368 {
1369 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1128 { 1370 }
1129 ASImage *background = NULL;
1130 ARGB32 as_tint = TINT_LEAVE_SAME;
1131 if (background_flags)
1132 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
1133 1371
1134# ifdef ENABLE_TRANSPARENCY 1372 if (result)
1373 {
1374# if !defined(HAVE_AFTERIMAGE) && !XFT
1375 /* our own client-side tinting */
1376 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1377 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1135 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1378 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1136 {
1137 ShadingInfo as_shade;
1138 as_shade.shading = (shade == 0) ? 100 : shade;
1139
1140 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1141 if (flags & tintSet)
1142 tint.get (c);
1143 as_shade.tintColor.red = c.r;
1144 as_shade.tintColor.green = c.g;
1145 as_shade.tintColor.blue = c.b;
1146
1147 as_tint = shading2tint32 (&as_shade);
1148 }
1149 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1150 {
1151 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
1152 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1153 100, ASIMAGE_QUALITY_DEFAULT);
1154 if (tmp)
1155 {
1156 destroy_asimage (&background);
1157 background = tmp;
1158 }
1159 }
1160# endif
1161
1162 if (render_asim (background, as_tint))
1163 flags = flags & ~isInvalid;
1164 if (background)
1165 destroy_asimage (&background);
1166 }
1167 else if (background_flags && pmap_depth != target->depth)
1168 {
1169 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1170 }
1171
1172# elif !XFT /* our own client-side tinting */
1173
1174 /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side.
1175 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1176
1177 if (background_flags && (flags & isInvalid))
1178 {
1179 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1180 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1181 { 1379 {
1182 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1380 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1183 if (flags & tintSet) 1381 if (flags & tintSet)
1184 tint.get (c); 1382 tint.get (c);
1185 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1383 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1186 } 1384 }
1187 } 1385# endif
1188# endif /* HAVE_AFTERIMAGE */
1189 1386
1190 if (result)
1191 {
1192 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1387 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1193 1388
1194 if (gc) 1389 if (gc)
1195 { 1390 {
1196 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1391 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1225 1420
1226 XFreeGC (target->dpy, gc); 1421 XFreeGC (target->dpy, gc);
1227 flags = flags & ~isInvalid; 1422 flags = flags & ~isInvalid;
1228 } 1423 }
1229 1424
1230 XDestroyImage (result); 1425 XDestroyImage (result);
1231 } 1426 }
1232 1427
1233 if (flags & isInvalid) 1428 if (flags & isInvalid)
1234 { 1429 {
1235 if (pixmap != None) 1430 if (pixmap != None)
1259# ifdef ENABLE_TRANSPARENCY 1454# ifdef ENABLE_TRANSPARENCY
1260 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1455 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
1261# endif 1456# endif
1262 return true; 1457 return true;
1263 } 1458 }
1459
1264 return false; 1460 return false;
1265} 1461}
1266 1462
1267void 1463void
1268bgPixmap_t::apply () 1464bgPixmap_t::apply ()
1269{ 1465{
1270 if (target) 1466 if (target)
1271 { 1467 {
1272 flags &= ~isVtOrigin; 1468 flags &= ~isVtOrigin;
1469
1273 if (pixmap != None) 1470 if (pixmap != None)
1274 { 1471 {
1275 /* set target's background to pixmap */ 1472 /* set target's background to pixmap */
1276# ifdef ENABLE_TRANSPARENCY 1473# ifdef ENABLE_TRANSPARENCY
1277 if (flags & isTransparent) 1474 if (flags & isTransparent)
1278 { 1475 {
1279 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1476 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1280 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1477 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1281# if HAVE_SCROLLBARS 1478
1282 if (target->scrollBar.win) 1479 if (target->scrollBar.win)
1283 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1480 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1284# endif
1285 } 1481 }
1286 else 1482 else
1287# endif 1483# endif
1288 { 1484 {
1289 flags |= isVtOrigin; 1485 flags |= isVtOrigin;
1290 /* force old pixmap dereference in case it was transparent before :*/ 1486 /* force old pixmap dereference in case it was transparent before :*/
1291 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1487 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1292 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1488 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1293 /* do we also need to set scrollbar's background here ? */ 1489 /* do we also need to set scrollbar's background here ? */
1294# if HAVE_SCROLLBARS 1490
1295 if (target->scrollBar.win) 1491 if (target->scrollBar.win)
1296 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1492 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1297# endif
1298 } 1493 }
1299 } 1494 }
1300 else 1495 else
1301 { 1496 {
1302 /* set target background to a pixel */ 1497 /* set target background to a pixel */
1303 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1498 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1304 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1499 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1305 /* do we also need to set scrollbar's background here ? */ 1500 /* do we also need to set scrollbar's background here ? */
1306# if HAVE_SCROLLBARS
1307 if (target->scrollBar.win) 1501 if (target->scrollBar.win)
1308 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1502 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1309# endif
1310 } 1503 }
1504
1311 /* don't want Expose on the parent or vt. It is better to use 1505 /* don't want Expose on the parent or vt. It is better to use
1312 scr_touch or we get a great deal of flicker otherwise: */ 1506 scr_touch or we get a great deal of flicker otherwise: */
1313 XClearWindow (target->dpy, target->parent[0]); 1507 XClearWindow (target->dpy, target->parent[0]);
1314 1508
1315# if HAVE_SCROLLBARS 1509 if (target->scrollBar.state && target->scrollBar.win)
1316 if (target->scrollBar.win)
1317 { 1510 {
1318 target->scrollBar.setIdle (); 1511 target->scrollBar.state = STATE_IDLE;
1319 target->scrollbar_show (0); 1512 target->scrollBar.show (0);
1320 } 1513 }
1321# endif
1322 1514
1323 target->want_refresh = 1; 1515 target->want_refresh = 1;
1324 flags |= hasChanged; 1516 flags |= hasChanged;
1325 } 1517 }
1326} 1518}
1331/* taken from aterm-0.4.2 */ 1523/* taken from aterm-0.4.2 */
1332 1524
1333typedef uint32_t RUINT32T; 1525typedef uint32_t RUINT32T;
1334 1526
1335static void 1527static void
1336ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) 1528ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm)
1337{ 1529{
1338 int sh_r, sh_g, sh_b; 1530 int sh_r, sh_g, sh_b;
1339 RUINT32T mask_r, mask_g, mask_b; 1531 RUINT32T mask_r, mask_g, mask_b;
1340 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 1532 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
1341 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1533 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines