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.197 by sf-exg, Wed Jan 11 13:22:01 2012 UTC vs.
Revision 1.207 by sf-exg, Thu May 10 21:48:55 2012 UTC

20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *---------------------------------------------------------------------*/ 23 *---------------------------------------------------------------------*/
24 24
25#include <cmath> 25#include <math.h>
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28 28
29#if XRENDER 29#if XRENDER
30# include <X11/extensions/Xrender.h> 30# include <X11/extensions/Xrender.h>
58# endif 58# endif
59 59
60void 60void
61rxvt_term::bg_destroy () 61rxvt_term::bg_destroy ()
62{ 62{
63#ifdef HAVE_AFTERIMAGE
64 if (original_asim)
65 safe_asimage_destroy (original_asim);
66 if (asv)
67 destroy_asvisual (asv, 0);
68 if (asimman)
69 destroy_image_manager (asimman, 0);
70#endif
71
72#ifdef HAVE_PIXBUF 63#ifdef HAVE_PIXBUF
73 if (pixbuf) 64 if (pixbuf)
74 g_object_unref (pixbuf); 65 g_object_unref (pixbuf);
75#endif 66#endif
76 67
129 120
130 return false; 121 return false;
131} 122}
132 123
133# ifdef BG_IMAGE_FROM_FILE 124# ifdef BG_IMAGE_FROM_FILE
134static inline bool
135check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value)
136{
137 if (geom_flags & flag)
138 {
139 if (new_value > 1000)
140 new_value = 1000;
141 if (new_value != scale)
142 {
143 scale = new_value;
144 return true;
145 }
146 }
147 return false;
148}
149
150static inline bool
151check_set_align_value (int geom_flags, int flag, int &align, int new_value)
152{
153 if (geom_flags & flag)
154 {
155 if (new_value < -100)
156 new_value = -100;
157 else if (new_value > 200)
158 new_value = 200;
159 if (new_value != align)
160 {
161 align = new_value;
162 return true;
163 }
164 }
165 return false;
166}
167
168static inline int 125static inline int
169make_align_position (int align, int window_size, int image_size) 126make_align_position (int align, int window_size, int image_size)
170{ 127{
171 int diff = window_size - image_size;
172 int smaller = min (image_size, window_size);
173
174 if (align >= 0 && align <= 100) 128 if (align >= 0 && align <= 100)
175 return diff * align / 100; 129 return lerp (0, window_size - image_size, align);
176 else if (align > 100 && align <= 200) 130 else if (align > 100)
177 return (align - 100) * smaller / 100 + window_size - smaller; 131 return lerp (window_size - image_size, window_size, align - 100);
178 else if (align >= -100 && align < 0) 132 else
179 return (align + 100) * smaller / 100 - image_size; 133 return lerp (-image_size, 0, align + 100);
180 return 0;
181} 134}
182 135
183static inline int 136static inline int
184make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 137make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
185{ 138{
200bool 153bool
201rxvt_term::bg_set_geometry (const char *geom, bool update) 154rxvt_term::bg_set_geometry (const char *geom, bool update)
202{ 155{
203 bool changed = false; 156 bool changed = false;
204 int geom_flags = 0; 157 int geom_flags = 0;
205 int x = 0, y = 0; 158 int x = h_align;
159 int y = v_align;
206 unsigned int w = 0, h = 0; 160 unsigned int w = h_scale;
161 unsigned int h = v_scale;
207 unsigned long new_flags = 0; 162 unsigned long new_flags = 0;
208 163
209 if (geom == NULL) 164 if (geom == NULL)
210 return false; 165 return false;
211 166
320 w = h = defaultScale; 275 w = h = defaultScale;
321 else if (!(geom_flags & HeightValue)) 276 else if (!(geom_flags & HeightValue))
322 h = w; 277 h = w;
323 else if (!(geom_flags & WidthValue)) 278 else if (!(geom_flags & WidthValue))
324 w = h; 279 w = h;
325
326 geom_flags |= WidthValue|HeightValue|XValue|YValue;
327 } 280 }
328 281
329 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; 282 min_it (w, 1000);
330 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; 283 min_it (h, 1000);
331 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; 284 clamp_it (x, -100, 200);
332 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; 285 clamp_it (y, -100, 200);
333 286
334 if (new_flags != bg_flags) 287 if (bg_flags != new_flags
288 || h_scale != w
289 || v_scale != h
290 || h_align != x
291 || v_align != y)
335 { 292 {
336 bg_flags = new_flags; 293 bg_flags = new_flags;
294 h_scale = w;
295 v_scale = h;
296 h_align = x;
297 v_align = y;
337 changed = true; 298 changed = true;
338 } 299 }
339 300
340 return changed; 301 return changed;
341} 302}
369 { 330 {
370 x = make_align_position (h_align, target_width, w); 331 x = make_align_position (h_align, target_width, w);
371 y = make_align_position (v_align, target_height, h); 332 y = make_align_position (v_align, target_height, h);
372 } 333 }
373 334
374 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
375 if (!(bg_flags & BG_TILE) 335 if (!(bg_flags & BG_TILE)
376 || h_scale || v_scale 336 || h_scale || v_scale
377 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) 337 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
378 || w > target_width || h > target_height) 338 || image_width > target_width || image_height > target_height)
379 bg_flags |= BG_IS_SIZE_SENSITIVE; 339 bg_flags |= BG_IS_SIZE_SENSITIVE;
380}
381
382# ifdef HAVE_AFTERIMAGE
383bool
384rxvt_term::render_image (unsigned long tr_flags)
385{
386 init_asv ();
387
388 ASImage *background = NULL;
389 ARGB32 background_tint = TINT_LEAVE_SAME;
390
391# ifdef ENABLE_TRANSPARENCY
392 if (tr_flags)
393 background = pixmap2ximage (asv, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, 100);
394
395 if (tr_flags & BG_NEEDS_TINT)
396 {
397 ShadingInfo as_shade;
398 as_shade.shading = shade;
399
400 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
401 if (bg_flags & BG_TINT_SET)
402 tint.get (c);
403 as_shade.tintColor.red = c.r;
404 as_shade.tintColor.green = c.g;
405 as_shade.tintColor.blue = c.b;
406
407 background_tint = shading2tint32 (&as_shade);
408 }
409
410 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL)
411 {
412 ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
413 ASA_XImage,
414 100, ASIMAGE_QUALITY_DEFAULT);
415 if (tmp)
416 {
417 destroy_asimage (&background);
418 background = tmp;
419 }
420 }
421# endif
422
423 ASImage *result = 0;
424
425 int target_width = szHint.width;
426 int target_height = szHint.height;
427 int new_pmap_width = target_width;
428 int new_pmap_height = target_height;
429
430 int x = 0;
431 int y = 0;
432 int w = 0;
433 int h = 0;
434
435 if (original_asim)
436 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
437
438 if (!original_asim
439 || (!(bg_flags & BG_ROOT_ALIGN)
440 && (x >= target_width
441 || y >= target_height
442 || x + w <= 0
443 || y + h <= 0)))
444 {
445 if (background)
446 {
447 new_pmap_width = background->width;
448 new_pmap_height = background->height;
449 result = background;
450
451 if (background_tint != TINT_LEAVE_SAME)
452 {
453 ASImage *tmp = tile_asimage (asv, background, 0, 0,
454 target_width, target_height, background_tint,
455 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
456 if (tmp)
457 result = tmp;
458 }
459 }
460 else
461 new_pmap_width = new_pmap_height = 0;
462 }
463 else 340 else
464 { 341 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
465 result = original_asim;
466
467 if (w != original_asim->width
468 || h != original_asim->height)
469 {
470 result = scale_asimage (asv, original_asim,
471 w, h,
472 ASA_XImage,
473 100, ASIMAGE_QUALITY_DEFAULT);
474 }
475
476 if (background == NULL)
477 {
478 if (bg_flags & BG_TILE)
479 {
480 /* if tiling - pixmap has to be sized exactly as the image,
481 but there is no need to make it bigger than the window! */
482 new_pmap_width = min (result->width, target_width);
483 new_pmap_height = min (result->height, target_height);
484
485 /* we also need to tile our image in both directions */
486 ASImage *tmp = tile_asimage (asv, result,
487 (int)result->width - x,
488 (int)result->height - y,
489 new_pmap_width,
490 new_pmap_height,
491 TINT_LEAVE_SAME, ASA_XImage,
492 100, ASIMAGE_QUALITY_DEFAULT);
493 if (tmp)
494 {
495 if (result != original_asim)
496 destroy_asimage (&result);
497
498 result = tmp;
499 }
500 }
501 }
502 else
503 {
504 /* if blending background and image - pixmap has to be sized same as target window */
505 ASImageLayer *layers = create_image_layers (2);
506
507 layers[0].im = background;
508 layers[0].clip_width = target_width;
509 layers[0].clip_height = target_height;
510 layers[0].tint = background_tint;
511 layers[1].im = result;
512
513 if (bg_flags & BG_TILE)
514 {
515 /* tile horizontally */
516 while (x > 0) x -= (int)result->width;
517 layers[1].dst_x = x;
518 layers[1].clip_width = result->width+target_width;
519 }
520 else
521 {
522 /* clip horizontally */
523 layers[1].dst_x = x;
524 layers[1].clip_width = result->width;
525 }
526
527 if (bg_flags & BG_TILE)
528 {
529 while (y > 0) y -= (int)result->height;
530 layers[1].dst_y = y;
531 layers[1].clip_height = result->height + target_height;
532 }
533 else
534 {
535 layers[1].dst_y = y;
536 layers[1].clip_height = result->height;
537 }
538
539 if (rs[Rs_blendtype])
540 {
541 layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]);
542 if (layers[1].merge_scanlines == NULL)
543 layers[1].merge_scanlines = alphablend_scanlines;
544 }
545
546 ASImage *tmp = merge_layers (asv, layers, 2, target_width, target_height,
547 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
548
549 if (tmp)
550 {
551 if (result != original_asim)
552 destroy_asimage (&result);
553
554 result = tmp;
555 }
556
557 free (layers);
558 }
559 }
560
561 bool ret = false;
562
563 if (result)
564 {
565 XGCValues gcv;
566 GC gc;
567
568 /* create Pixmap */
569 if (bg_pixmap == None
570 || bg_pmap_width != new_pmap_width
571 || bg_pmap_height != new_pmap_height)
572 {
573 if (bg_pixmap)
574 XFreePixmap (dpy, bg_pixmap);
575 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
576 bg_pmap_width = new_pmap_width;
577 bg_pmap_height = new_pmap_height;
578 }
579 /* fill with background color (if result's not completely overlapping it) */
580 gcv.foreground = pix_colors[Color_bg];
581 gc = XCreateGC (dpy, vt, GCForeground, &gcv);
582
583 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
584 int dst_width = result->width, dst_height = result->height;
585 if (background == NULL)
586 {
587 if (!(bg_flags & BG_TILE))
588 {
589 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
590 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
591 }
592
593 if (dst_x > 0 || dst_y > 0
594 || dst_x + dst_width < new_pmap_width
595 || dst_y + dst_height < new_pmap_height)
596 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
597 }
598
599 /* put result on pixmap */
600 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
601 asimage2drawable (asv, bg_pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
602
603 if (result != background && result != original_asim)
604 destroy_asimage (&result);
605
606 XFreeGC (dpy, gc);
607
608 ret = true;
609 }
610
611 if (background)
612 destroy_asimage (&background);
613
614 return ret;
615} 342}
616# endif /* HAVE_AFTERIMAGE */
617 343
618# ifdef HAVE_PIXBUF 344# ifdef HAVE_PIXBUF
619bool 345bool
620rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, 346rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc,
621 int src_x, int src_y, int dst_x, int dst_y, 347 int src_x, int src_y, int dst_x, int dst_y,
622 unsigned int width, unsigned int height) 348 unsigned int width, unsigned int height)
623{ 349{
624 XImage *ximage; 350 XImage *ximage;
625 char *data, *line; 351 char *data, *line;
626 int bytes_per_pixel; 352 int bytes_per_pixel;
627 int width_r, width_g, width_b; 353 int width_r, width_g, width_b, width_a;
628 int sh_r, sh_g, sh_b; 354 int sh_r, sh_g, sh_b, sh_a;
355 uint32_t alpha_mask;
629 int rowstride; 356 int rowstride;
630 int channels; 357 int channels;
631 unsigned char *row; 358 unsigned char *row;
632 359
633 if (visual->c_class != TrueColor) 360 if (visual->c_class != TrueColor)
634 return false; 361 return false;
362
363#if XRENDER
364 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
365 if (format)
366 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha;
367 else
368#endif
369 alpha_mask = 0;
635 370
636 if (depth == 24 || depth == 32) 371 if (depth == 24 || depth == 32)
637 bytes_per_pixel = 4; 372 bytes_per_pixel = 4;
638 else if (depth == 15 || depth == 16) 373 else if (depth == 15 || depth == 16)
639 bytes_per_pixel = 2; 374 bytes_per_pixel = 2;
641 return false; 376 return false;
642 377
643 width_r = ecb_popcount32 (visual->red_mask); 378 width_r = ecb_popcount32 (visual->red_mask);
644 width_g = ecb_popcount32 (visual->green_mask); 379 width_g = ecb_popcount32 (visual->green_mask);
645 width_b = ecb_popcount32 (visual->blue_mask); 380 width_b = ecb_popcount32 (visual->blue_mask);
381 width_a = ecb_popcount32 (alpha_mask);
646 382
647 if (width_r > 8 || width_g > 8 || width_b > 8) 383 if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8)
648 return false; 384 return false;
649 385
650 sh_r = ecb_ctz32 (visual->red_mask); 386 sh_r = ecb_ctz32 (visual->red_mask);
651 sh_g = ecb_ctz32 (visual->green_mask); 387 sh_g = ecb_ctz32 (visual->green_mask);
652 sh_b = ecb_ctz32 (visual->blue_mask); 388 sh_b = ecb_ctz32 (visual->blue_mask);
389 sh_a = ecb_ctz32 (alpha_mask);
653 390
654 if (width > INT_MAX / height / bytes_per_pixel) 391 if (width > INT_MAX / height / bytes_per_pixel)
655 return false; 392 return false;
656 393
657 data = (char *)malloc (width * height * bytes_per_pixel); 394 data = (char *)malloc (width * height * bytes_per_pixel);
671 rowstride = gdk_pixbuf_get_rowstride (pixbuf); 408 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
672 channels = gdk_pixbuf_get_n_channels (pixbuf); 409 channels = gdk_pixbuf_get_n_channels (pixbuf);
673 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; 410 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
674 line = data; 411 line = data;
675 412
413 rgba c (0, 0, 0);
414
415 if (channels == 4 && alpha_mask == 0)
416 {
417 pix_colors[Color_bg].get (c);
418 c.r >>= 8;
419 c.g >>= 8;
420 c.b >>= 8;
421 }
422
676 for (int y = 0; y < height; y++) 423 for (int y = 0; y < height; y++)
677 { 424 {
678 for (int x = 0; x < width; x++) 425 for (int x = 0; x < width; x++)
679 { 426 {
680 unsigned char *pixel = row + x * channels; 427 unsigned char *pixel = row + x * channels;
681 uint32_t value; 428 uint32_t value;
429 unsigned char r, g, b, a;
682 430
431 if (channels == 4)
432 {
433 a = pixel[3];
434 r = (pixel[0] * a + c.r * (0xff - a)) / 0xff;
435 g = (pixel[1] * a + c.g * (0xff - a)) / 0xff;
436 b = (pixel[2] * a + c.b * (0xff - a)) / 0xff;
437 }
438 else
439 {
440 a = 0xff;
441 r = pixel[0];
442 g = pixel[1];
443 b = pixel[2];
444 }
445
683 value = ((pixel[0] >> (8 - width_r)) << sh_r) 446 value = ((r >> (8 - width_r)) << sh_r)
684 | ((pixel[1] >> (8 - width_g)) << sh_g) 447 | ((g >> (8 - width_g)) << sh_g)
685 | ((pixel[2] >> (8 - width_b)) << sh_b); 448 | ((b >> (8 - width_b)) << sh_b)
449 | ((a >> (8 - width_a)) << sh_a);
686 450
687 if (bytes_per_pixel == 4) 451 if (bytes_per_pixel == 4)
688 ((uint32_t *)line)[x] = value; 452 ((uint32_t *)line)[x] = value;
689 else 453 else
690 ((uint16_t *)line)[x] = value; 454 ((uint16_t *)line)[x] = value;
698 XDestroyImage (ximage); 462 XDestroyImage (ximage);
699 return true; 463 return true;
700} 464}
701 465
702bool 466bool
703rxvt_term::render_image (unsigned long tr_flags) 467rxvt_term::render_image (bool transparent)
704{ 468{
705 if (!pixbuf) 469 if (!pixbuf)
706 return false; 470 return false;
707 471
708 if (tr_flags 472 if (transparent
709 && !(bg_flags & BG_HAS_RENDER)) 473 && !(bg_flags & BG_HAS_RENDER))
710 return false; 474 return false;
711 475
712 GdkPixbuf *result; 476 GdkPixbuf *result;
713 477
753 Pixmap root_pmap; 517 Pixmap root_pmap;
754 518
755 image_width = gdk_pixbuf_get_width (result); 519 image_width = gdk_pixbuf_get_width (result);
756 image_height = gdk_pixbuf_get_height (result); 520 image_height = gdk_pixbuf_get_height (result);
757 521
758 if (tr_flags) 522 if (transparent)
759 { 523 {
760 root_pmap = bg_pixmap; 524 root_pmap = bg_pixmap;
761 bg_pixmap = None; 525 bg_pixmap = None;
762 } 526 }
763 else 527 else
821 dst_x, dst_y, 585 dst_x, dst_y,
822 dst_width, dst_height); 586 dst_width, dst_height);
823 } 587 }
824 588
825#if XRENDER 589#if XRENDER
826 if (tr_flags) 590 if (transparent)
827 { 591 {
828 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 592 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
829 593
830 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); 594 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0);
831 595
855 } 619 }
856 620
857 if (result != pixbuf) 621 if (result != pixbuf)
858 g_object_unref (result); 622 g_object_unref (result);
859 623
860 if (tr_flags) 624 if (transparent)
861 XFreePixmap (dpy, root_pmap); 625 XFreePixmap (dpy, root_pmap);
862 626
863 return ret; 627 return ret;
864} 628}
865# endif /* HAVE_PIXBUF */ 629# endif /* HAVE_PIXBUF */
880 memcpy (f, file, len); 644 memcpy (f, file, len);
881 f[len] = '\0'; 645 f[len] = '\0';
882 file = f; 646 file = f;
883 } 647 }
884 648
885# ifdef HAVE_AFTERIMAGE
886 if (!asimman)
887 asimman = create_generic_imageman (rs[Rs_path]);
888 ASImage *image = get_asimage (asimman, file, 0xFFFFFFFF, 100);
889 if (image)
890 {
891 if (original_asim)
892 safe_asimage_destroy (original_asim);
893 original_asim = image;
894 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER;
895 ret = true;
896 }
897# endif
898
899# ifdef HAVE_PIXBUF 649# ifdef HAVE_PIXBUF
900 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 650 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
901 if (image) 651 if (image)
902 { 652 {
903 if (pixbuf) 653 if (pixbuf)
960 { 710 {
961 changed = true; 711 changed = true;
962 v_blurRadius = vr; 712 v_blurRadius = vr;
963 } 713 }
964 714
965 if (h_blurRadius == 0 || v_blurRadius == 0) 715 if (h_blurRadius && v_blurRadius)
716 bg_flags |= BG_NEEDS_BLUR;
717 else
966 bg_flags &= ~BG_NEEDS_BLUR; 718 bg_flags &= ~BG_NEEDS_BLUR;
967 else
968 bg_flags |= BG_NEEDS_BLUR;
969 719
970 return changed; 720 return changed;
971} 721}
972 722
973void 723void
974rxvt_term::set_tint_shade_flags () 724rxvt_term::set_tint_shade_flags ()
975{ 725{
726 if (shade != 100 || (bg_flags & BG_TINT_SET))
727 bg_flags |= BG_NEEDS_TINT;
728 else
729 bg_flags &= ~BG_NEEDS_TINT;
730}
731
732bool
733rxvt_term::bg_set_tint (rxvt_color &new_tint)
734{
735 if (!(bg_flags & BG_TINT_SET) || tint != new_tint)
736 {
737 tint = new_tint;
738 bg_flags |= BG_TINT_SET;
739
976 rgba c; 740 rgba c;
977 bool has_shade = shade != 100;
978
979 bg_flags &= ~BG_TINT_FLAGS;
980
981 if (bg_flags & BG_TINT_SET)
982 {
983 tint.get (c); 741 tint.get (c);
984 if (!has_shade
985 && (c.r <= 0x00ff || c.r >= 0xff00) 742 if ((c.r <= 0x00ff || c.r >= 0xff00)
986 && (c.g <= 0x00ff || c.g >= 0xff00) 743 && (c.g <= 0x00ff || c.g >= 0xff00)
987 && (c.b <= 0x00ff || c.b >= 0xff00)) 744 && (c.b <= 0x00ff || c.b >= 0xff00))
988 bg_flags |= BG_TINT_BITAND; 745 bg_flags |= BG_TINT_BITAND;
989 } 746 else
990
991 if (has_shade || (bg_flags & BG_TINT_SET))
992 bg_flags |= BG_NEEDS_TINT;
993}
994
995bool
996rxvt_term::bg_set_tint (rxvt_color &new_tint)
997{
998 if (!(bg_flags & BG_TINT_SET) || tint != new_tint)
999 {
1000 tint = new_tint;
1001 bg_flags |= BG_TINT_SET; 747 bg_flags &= ~BG_TINT_BITAND;
748
1002 set_tint_shade_flags (); 749 set_tint_shade_flags ();
1003 return true; 750 return true;
1004 } 751 }
1005 752
1006 return false; 753 return false;
1116bool 863bool
1117rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 864rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1118{ 865{
1119 bool ret = false; 866 bool ret = false;
1120 867
1121 if (bg_flags & BG_TINT_BITAND) 868 if (shade == 100 && (bg_flags & BG_TINT_BITAND))
1122 { 869 {
1123 XGCValues gcv; 870 XGCValues gcv;
1124 GC gc; 871 GC gc;
1125 872
1126 /* In this case we can tint image server-side getting significant 873 /* In this case we can tint image server-side getting significant
1207/* 954/*
1208 * Builds a pixmap of the same size as the terminal window that contains 955 * Builds a pixmap of the same size as the terminal window that contains
1209 * the tiled portion of the root pixmap that is supposed to be covered by 956 * the tiled portion of the root pixmap that is supposed to be covered by
1210 * our window. 957 * our window.
1211 */ 958 */
1212unsigned long 959bool
1213rxvt_term::make_transparency_pixmap () 960rxvt_term::make_transparency_pixmap ()
1214{ 961{
1215 unsigned long result = 0; 962 bool ret = false;
1216 963
1217 /* root dimensions may change from call to call - but Display structure should 964 /* root dimensions may change from call to call - but Display structure should
1218 * be always up-to-date, so let's use it : 965 * be always up-to-date, so let's use it :
1219 */ 966 */
1220 int screen = display->screen; 967 int screen = display->screen;
1301 gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1048 gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1302 1049
1303 if (gc) 1050 if (gc)
1304 { 1051 {
1305 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1052 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1306 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1053 ret = true;
1054 unsigned long tr_flags = bg_flags & BG_EFFECTS_FLAGS;
1307 1055
1308 if (!(bg_flags & BG_CLIENT_RENDER)) 1056 if (!(bg_flags & BG_CLIENT_RENDER))
1309 { 1057 {
1310 if (bg_flags & BG_NEEDS_BLUR) 1058 if (bg_flags & BG_NEEDS_BLUR)
1311 { 1059 {
1312 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) 1060 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth))
1313 result &= ~BG_NEEDS_BLUR; 1061 tr_flags &= ~BG_NEEDS_BLUR;
1314 } 1062 }
1315 if (bg_flags & BG_NEEDS_TINT) 1063 if (bg_flags & BG_NEEDS_TINT)
1316 { 1064 {
1317 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1065 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1318 result &= ~BG_NEEDS_TINT; 1066 tr_flags &= ~BG_NEEDS_TINT;
1319 } 1067 }
1320# ifndef HAVE_AFTERIMAGE
1321 if (result & BG_NEEDS_TINT) 1068 if (tr_flags & BG_NEEDS_TINT)
1322 { 1069 {
1323 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); 1070 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1324 if (ximage) 1071 if (ximage)
1325 { 1072 {
1326 /* our own client-side tinting */ 1073 /* our own client-side tinting */
1328 1075
1329 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); 1076 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1330 XDestroyImage (ximage); 1077 XDestroyImage (ximage);
1331 } 1078 }
1332 } 1079 }
1333# endif
1334 } /* server side rendering completed */ 1080 } /* server side rendering completed */
1335 1081
1336 XFreeGC (dpy, gc); 1082 XFreeGC (dpy, gc);
1337 } 1083 }
1338 1084
1339 if (recoded_root_pmap != root_pixmap) 1085 if (recoded_root_pmap != root_pixmap)
1340 XFreePixmap (dpy, recoded_root_pmap); 1086 XFreePixmap (dpy, recoded_root_pmap);
1341 1087
1342 return result; 1088 return ret;
1343} 1089}
1344 1090
1345void 1091void
1346rxvt_term::bg_set_root_pixmap () 1092rxvt_term::bg_set_root_pixmap ()
1347{ 1093{
1354# endif /* ENABLE_TRANSPARENCY */ 1100# endif /* ENABLE_TRANSPARENCY */
1355 1101
1356bool 1102bool
1357rxvt_term::bg_render () 1103rxvt_term::bg_render ()
1358{ 1104{
1359 unsigned long tr_flags = 0; 1105 bool transparent = false;
1360 1106
1361 bg_invalidate (); 1107 bg_invalidate ();
1362# ifdef ENABLE_TRANSPARENCY 1108# ifdef ENABLE_TRANSPARENCY
1363 if (bg_flags & BG_IS_TRANSPARENT) 1109 if (bg_flags & BG_IS_TRANSPARENT)
1364 { 1110 {
1365 /* we need to re-generate transparency pixmap in that case ! */ 1111 /* we need to re-generate transparency pixmap in that case ! */
1366 tr_flags = make_transparency_pixmap (); 1112 transparent = make_transparency_pixmap ();
1367 if (tr_flags == 0) 1113 if (transparent)
1368 return false;
1369 bg_flags |= BG_IS_VALID; 1114 bg_flags |= BG_IS_VALID;
1370 } 1115 }
1371# endif 1116# endif
1372 1117
1373# ifdef BG_IMAGE_FROM_FILE 1118# ifdef BG_IMAGE_FROM_FILE
1374 if ((bg_flags & BG_IS_FROM_FILE) 1119 if (bg_flags & BG_IS_FROM_FILE)
1375 || (tr_flags & BG_EFFECTS_FLAGS))
1376 { 1120 {
1377 if (render_image (tr_flags)) 1121 if (render_image (transparent))
1378 bg_flags |= BG_IS_VALID; 1122 bg_flags |= BG_IS_VALID;
1379 } 1123 }
1380# endif 1124# endif
1381 1125
1382 if (!(bg_flags & BG_IS_VALID)) 1126 if (!(bg_flags & BG_IS_VALID))
1420#endif 1164#endif
1421} 1165}
1422 1166
1423#endif /* HAVE_BG_PIXMAP */ 1167#endif /* HAVE_BG_PIXMAP */
1424 1168
1425#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1169#ifdef ENABLE_TRANSPARENCY
1426/* based on code from aterm-0.4.2 */ 1170/* based on code from aterm-0.4.2 */
1427 1171
1428static inline void 1172static inline void
1429fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) 1173fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1430{ 1174{
1576 } 1320 }
1577 } 1321 }
1578 1322
1579 free (lookup); 1323 free (lookup);
1580} 1324}
1581#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ 1325#endif /* ENABLE_TRANSPARENCY */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines