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.143 by sf-exg, Fri Jan 28 00:08:57 2011 UTC vs.
Revision 1.161 by sf-exg, Thu Aug 11 08:39:10 2011 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-2008 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de>
7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> 7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
8 * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it> 8 * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
46 * W and H are percentages of the terminal window size. 46 * W and H are percentages of the terminal window size.
47 * X and Y are also percentages; e.g., +50+50 centers 47 * X and Y are also percentages; e.g., +50+50 centers
48 * the image in the window. 48 * the image in the window.
49 * 49 *
50 * Pixmap Operations : (should be prepended by a colon) 50 * Pixmap Operations : (should be prepended by a colon)
51 * tile Tile image. Scaling/position modifiers above will affect
52 * the tile size and origin.
53 * propscale When scaling, scale proportionally. That is, maintain the
54 * proper aspect ratio for the image. Any portion of the
55 * background not covered by the image is filled with the
56 * current background color.
57 * hscale Scale horizontally, tile vertically ?
58 * vscale Tile horizontally, scale vertically ?
59 * scale Scale both up and down
60 * auto Same as 100x100+50+50
61 */ 51 */
62 52
63#ifdef HAVE_BG_PIXMAP 53#ifdef HAVE_BG_PIXMAP
64void 54void
65rxvt_term::bg_destroy () 55rxvt_term::bg_destroy ()
66{ 56{
67#ifdef HAVE_AFTERIMAGE 57#ifdef HAVE_AFTERIMAGE
68 if (original_asim) 58 if (original_asim)
69 safe_asimage_destroy (original_asim); 59 safe_asimage_destroy (original_asim);
60 if (asv)
61 destroy_asvisual (asv, 0);
62 if (asimman)
63 destroy_image_manager (asimman, 0);
70#endif 64#endif
71 65
72#ifdef HAVE_PIXBUF 66#ifdef HAVE_PIXBUF
73 if (pixbuf) 67 if (pixbuf)
74 g_object_unref (pixbuf); 68 g_object_unref (pixbuf);
99 if (bg_flags & BG_IS_TRANSPARENT) 93 if (bg_flags & BG_IS_TRANSPARENT)
100 return true; 94 return true;
101# endif 95# endif
102 96
103# ifdef BG_IMAGE_FROM_FILE 97# ifdef BG_IMAGE_FROM_FILE
104 if (have_image) 98 if (bg_flags & BG_IS_FROM_FILE)
105 { 99 {
106 if (bg_flags & BG_IS_SIZE_SENSITIVE) 100 if (bg_flags & BG_IS_SIZE_SENSITIVE)
107 return true; 101 return true;
108 } 102 }
109# endif 103# endif
118 if (bg_flags & BG_IS_TRANSPARENT) 112 if (bg_flags & BG_IS_TRANSPARENT)
119 return true; 113 return true;
120# endif 114# endif
121 115
122# ifdef BG_IMAGE_FROM_FILE 116# ifdef BG_IMAGE_FROM_FILE
123 if (have_image) 117 if (bg_flags & BG_IS_FROM_FILE)
124 { 118 {
125 if (bg_flags & BG_ROOT_ALIGN) 119 if (bg_flags & BG_ROOT_ALIGN)
126 return true; 120 return true;
127 } 121 }
128# endif 122# endif
254 { 248 {
255 char **arr = rxvt_strsplit (':', ops + 1); 249 char **arr = rxvt_strsplit (':', ops + 1);
256 250
257 for (int i = 0; arr[i]; i++) 251 for (int i = 0; arr[i]; i++)
258 { 252 {
253 if (!strcasecmp (arr[i], "style=tiled"))
254 {
255 new_flags = BG_TILE;
256 w = h = noScale;
257 x = y = 0;
258 geom_flags = WidthValue|HeightValue|XValue|YValue;
259 }
260 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
261 {
262 new_flags = BG_PROP_SCALE;
263 x = y = centerAlign;
264 geom_flags = XValue|YValue;
265 }
266 else if (!strcasecmp (arr[i], "style=stretched"))
267 {
268 new_flags = 0;
269 w = h = windowScale;
270 geom_flags = WidthValue|HeightValue;
271 }
272 else if (!strcasecmp (arr[i], "style=centered"))
273 {
274 new_flags = 0;
275 w = h = noScale;
276 x = y = centerAlign;
277 geom_flags = WidthValue|HeightValue|XValue|YValue;
278 }
279 else if (!strcasecmp (arr[i], "style=root-tiled"))
280 {
281 new_flags = BG_TILE|BG_ROOT_ALIGN;
282 w = h = noScale;
283 geom_flags = WidthValue|HeightValue;
284 }
285 else if (!strcasecmp (arr[i], "op=tile"))
286 new_flags |= BG_TILE;
287 else if (!strcasecmp (arr[i], "op=pscale"))
288 new_flags |= BG_PROP_SCALE;
289 else if (!strcasecmp (arr[i], "op=root"))
290 new_flags |= BG_ROOT_ALIGN;
291
292 // deprecated
259 if (!strcasecmp (arr[i], "tile")) 293 else if (!strcasecmp (arr[i], "tile"))
260 { 294 {
295 new_flags |= BG_TILE;
261 w = h = noScale; 296 w = h = noScale;
262 geom_flags |= WidthValue|HeightValue; 297 geom_flags |= WidthValue|HeightValue;
263 } 298 }
264 else if (!strcasecmp (arr[i], "propscale")) 299 else if (!strcasecmp (arr[i], "propscale"))
265 { 300 {
266 new_flags |= BG_PROP_SCALE; 301 new_flags |= BG_PROP_SCALE;
267 } 302 }
268 else if (!strcasecmp (arr[i], "hscale")) 303 else if (!strcasecmp (arr[i], "hscale"))
269 { 304 {
270 if (w == 0) w = windowScale; 305 w = windowScale;
271
272 h = noScale; 306 h = noScale;
273 geom_flags |= WidthValue|HeightValue; 307 geom_flags |= WidthValue|HeightValue;
274 } 308 }
275 else if (!strcasecmp (arr[i], "vscale")) 309 else if (!strcasecmp (arr[i], "vscale"))
276 { 310 {
277 if (h == 0) h = windowScale; 311 h = windowScale;
278
279 w = noScale; 312 w = noScale;
280 geom_flags |= WidthValue|HeightValue; 313 geom_flags |= WidthValue|HeightValue;
281 } 314 }
282 else if (!strcasecmp (arr[i], "scale")) 315 else if (!strcasecmp (arr[i], "scale"))
283 { 316 {
284 if (h == 0) h = windowScale;
285 if (w == 0) w = windowScale; 317 w = h = windowScale;
286
287 geom_flags |= WidthValue|HeightValue; 318 geom_flags |= WidthValue|HeightValue;
288 } 319 }
289 else if (!strcasecmp (arr[i], "auto")) 320 else if (!strcasecmp (arr[i], "auto"))
290 { 321 {
291 w = h = windowScale; 322 w = h = windowScale;
292 x = y = centerAlign; 323 x = y = centerAlign;
293 geom_flags |= WidthValue|HeightValue|XValue|YValue; 324 geom_flags |= WidthValue|HeightValue|XValue|YValue;
294 } 325 }
295 else if (!strcasecmp (arr[i], "root")) 326 else if (!strcasecmp (arr[i], "root"))
296 { 327 {
297 new_flags |= BG_ROOT_ALIGN; 328 new_flags |= BG_TILE|BG_ROOT_ALIGN;
298 w = h = noScale; 329 w = h = noScale;
299 geom_flags |= WidthValue|HeightValue; 330 geom_flags |= WidthValue|HeightValue;
300 } 331 }
301 } /* done parsing ops */ 332 } /* done parsing ops */
302 333
349 x = make_align_position (h_align, target_width, w); 380 x = make_align_position (h_align, target_width, w);
350 y = make_align_position (v_align, target_height, h); 381 y = make_align_position (v_align, target_height, h);
351 } 382 }
352 383
353 bg_flags &= ~BG_IS_SIZE_SENSITIVE; 384 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
385 if (!(bg_flags & BG_TILE)
354 if ((bg_flags & BG_PROP_SCALE) || h_scale || v_scale 386 || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale
355 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) 387 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
356 || w > target_width || h > target_height) 388 || w > target_width || h > target_height)
357 bg_flags |= BG_IS_SIZE_SENSITIVE; 389 bg_flags |= BG_IS_SIZE_SENSITIVE;
358} 390}
359 391
451 100, ASIMAGE_QUALITY_DEFAULT); 483 100, ASIMAGE_QUALITY_DEFAULT);
452 } 484 }
453 485
454 if (background == NULL) 486 if (background == NULL)
455 { 487 {
456 if (h_scale == 0 || v_scale == 0) 488 if (bg_flags & BG_TILE)
457 { 489 {
458 /* if tiling - pixmap has to be sized exactly as the image, 490 /* if tiling - pixmap has to be sized exactly as the image,
459 but there is no need to make it bigger than the window! */ 491 but there is no need to make it bigger than the window! */
460 new_pmap_width = min (result->width, target_width); 492 new_pmap_width = min (result->width, target_width);
461 new_pmap_height = min (result->height, target_height); 493 new_pmap_height = min (result->height, target_height);
486 layers[0].clip_width = target_width; 518 layers[0].clip_width = target_width;
487 layers[0].clip_height = target_height; 519 layers[0].clip_height = target_height;
488 layers[0].tint = background_tint; 520 layers[0].tint = background_tint;
489 layers[1].im = result; 521 layers[1].im = result;
490 522
491 if (h_scale == 0 || v_scale == 0) 523 if (bg_flags & BG_TILE)
492 { 524 {
493 /* tile horizontally */ 525 /* tile horizontally */
494 while (x > 0) x -= (int)result->width; 526 while (x > 0) x -= (int)result->width;
495 layers[1].dst_x = x; 527 layers[1].dst_x = x;
496 layers[1].clip_width = result->width+target_width; 528 layers[1].clip_width = result->width+target_width;
500 /* clip horizontally */ 532 /* clip horizontally */
501 layers[1].dst_x = x; 533 layers[1].dst_x = x;
502 layers[1].clip_width = result->width; 534 layers[1].clip_width = result->width;
503 } 535 }
504 536
505 if (h_scale == 0 || v_scale == 0) 537 if (bg_flags & BG_TILE)
506 { 538 {
507 while (y > 0) y -= (int)result->height; 539 while (y > 0) y -= (int)result->height;
508 layers[1].dst_y = y; 540 layers[1].dst_y = y;
509 layers[1].clip_height = result->height + target_height; 541 layers[1].clip_height = result->height + target_height;
510 } 542 }
560 592
561 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 593 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
562 int dst_width = result->width, dst_height = result->height; 594 int dst_width = result->width, dst_height = result->height;
563 if (background == NULL) 595 if (background == NULL)
564 { 596 {
565 if (!(h_scale == 0 || v_scale == 0)) 597 if (!(bg_flags & BG_TILE))
566 { 598 {
567 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); 599 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
568 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 600 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
569 } 601 }
570 602
616 else if (depth == 15 || depth == 16) 648 else if (depth == 15 || depth == 16)
617 bytes_per_pixel = 2; 649 bytes_per_pixel = 2;
618 else 650 else
619 return false; 651 return false;
620 652
621 width_r = rxvt_popcount (visual->red_mask); 653 width_r = ecb_popcount32 (visual->red_mask);
622 width_g = rxvt_popcount (visual->green_mask); 654 width_g = ecb_popcount32 (visual->green_mask);
623 width_b = rxvt_popcount (visual->blue_mask); 655 width_b = ecb_popcount32 (visual->blue_mask);
624 656
625 if (width_r > 8 || width_g > 8 || width_b > 8) 657 if (width_r > 8 || width_g > 8 || width_b > 8)
626 return false; 658 return false;
627 659
628 sh_r = rxvt_ctz (visual->red_mask); 660 sh_r = ecb_ctz32 (visual->red_mask);
629 sh_g = rxvt_ctz (visual->green_mask); 661 sh_g = ecb_ctz32 (visual->green_mask);
630 sh_b = rxvt_ctz (visual->blue_mask); 662 sh_b = ecb_ctz32 (visual->blue_mask);
631 663
632 if (width > INT_MAX / height / bytes_per_pixel) 664 if (width > INT_MAX / height / bytes_per_pixel)
633 return false; 665 return false;
634 666
635 data = (char *)malloc (width * height * bytes_per_pixel); 667 data = (char *)malloc (width * height * bytes_per_pixel);
642 { 674 {
643 free (data); 675 free (data);
644 return false; 676 return false;
645 } 677 }
646 678
647 ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; 679 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
648 680
649 rowstride = gdk_pixbuf_get_rowstride (pixbuf); 681 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
650 channels = gdk_pixbuf_get_n_channels (pixbuf); 682 channels = gdk_pixbuf_get_n_channels (pixbuf);
651 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; 683 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
652 line = data; 684 line = data;
719 result = gdk_pixbuf_scale_simple (pixbuf, 751 result = gdk_pixbuf_scale_simple (pixbuf,
720 w, h, 752 w, h,
721 GDK_INTERP_BILINEAR); 753 GDK_INTERP_BILINEAR);
722 } 754 }
723 755
756 if (!result)
757 return false;
758
724 bool ret = false; 759 bool ret = false;
725 760
726 if (result)
727 {
728 XGCValues gcv; 761 XGCValues gcv;
729 GC gc; 762 GC gc;
730 Pixmap root_pmap; 763 Pixmap root_pmap;
731 764
732 image_width = gdk_pixbuf_get_width (result); 765 image_width = gdk_pixbuf_get_width (result);
733 image_height = gdk_pixbuf_get_height (result); 766 image_height = gdk_pixbuf_get_height (result);
734 767
735 if (tr_flags) 768 if (tr_flags)
736 { 769 {
737 root_pmap = bg_pixmap; 770 root_pmap = bg_pixmap;
738 bg_pixmap = None; 771 bg_pixmap = None;
772 }
773 else
774 {
775 if (bg_flags & BG_TILE)
739 } 776 {
740 else
741 {
742 if (h_scale == 0 || v_scale == 0)
743 {
744 new_pmap_width = min (image_width, target_width); 777 new_pmap_width = min (image_width, target_width);
745 new_pmap_height = min (image_height, target_height); 778 new_pmap_height = min (image_height, target_height);
746 } 779 }
747 } 780 }
748 781
749 if (bg_pixmap == None 782 if (bg_pixmap == None
750 || bg_pmap_width != new_pmap_width 783 || bg_pmap_width != new_pmap_width
751 || bg_pmap_height != new_pmap_height) 784 || bg_pmap_height != new_pmap_height)
752 { 785 {
753 if (bg_pixmap) 786 if (bg_pixmap)
754 XFreePixmap (dpy, bg_pixmap); 787 XFreePixmap (dpy, bg_pixmap);
755 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); 788 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
756 bg_pmap_width = new_pmap_width; 789 bg_pmap_width = new_pmap_width;
757 bg_pmap_height = new_pmap_height; 790 bg_pmap_height = new_pmap_height;
758 } 791 }
759 792
760 gcv.foreground = pix_colors[Color_bg]; 793 gcv.foreground = pix_colors[Color_bg];
761 gc = XCreateGC (dpy, vt, GCForeground, &gcv); 794 gc = XCreateGC (dpy, vt, GCForeground, &gcv);
762 795
763 if (h_scale == 0 || v_scale == 0) 796 if (gc)
797 {
798 if (bg_flags & BG_TILE)
764 { 799 {
765 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); 800 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth);
766 pixbuf_to_pixmap (result, tile, gc, 801 pixbuf_to_pixmap (result, tile, gc,
767 0, 0, 802 0, 0,
768 0, 0, 803 0, 0,
812 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); 847 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
813 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); 848 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
814 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); 849 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
815 XFreePixmap (dpy, mask_pmap); 850 XFreePixmap (dpy, mask_pmap);
816 851
817 if (src && dst && mask)
818 {
819 XRenderColor mask_c; 852 XRenderColor mask_c;
820 853
821 mask_c.alpha = 0x8000; 854 mask_c.alpha = 0x8000;
822 mask_c.red = 0; 855 mask_c.red = 0;
823 mask_c.green = 0; 856 mask_c.green = 0;
824 mask_c.blue = 0; 857 mask_c.blue = 0;
825 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 858 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
826 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); 859 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height);
827 }
828 860
829 XRenderFreePicture (dpy, src); 861 XRenderFreePicture (dpy, src);
830 XRenderFreePicture (dpy, dst); 862 XRenderFreePicture (dpy, dst);
831 XRenderFreePicture (dpy, mask); 863 XRenderFreePicture (dpy, mask);
832
833 XFreePixmap (dpy, root_pmap);
834 } 864 }
835#endif 865#endif
836 866
837 if (result != pixbuf)
838 g_object_unref (result);
839
840 XFreeGC (dpy, gc); 867 XFreeGC (dpy, gc);
841 868
842 ret = true; 869 ret = true;
843 } 870 }
871
872 if (result != pixbuf)
873 g_object_unref (result);
874
875 if (tr_flags)
876 XFreePixmap (dpy, root_pmap);
844 877
845 return ret; 878 return ret;
846} 879}
847# endif /* HAVE_PIXBUF */ 880# endif /* HAVE_PIXBUF */
848 881
868 if (image) 901 if (image)
869 { 902 {
870 if (original_asim) 903 if (original_asim)
871 safe_asimage_destroy (original_asim); 904 safe_asimage_destroy (original_asim);
872 original_asim = image; 905 original_asim = image;
873 bg_flags |= BG_CLIENT_RENDER; 906 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER;
874 have_image = true;
875 return true; 907 return true;
876 } 908 }
877# endif 909# endif
878 910
879# ifdef HAVE_PIXBUF 911# ifdef HAVE_PIXBUF
881 if (image) 913 if (image)
882 { 914 {
883 if (pixbuf) 915 if (pixbuf)
884 g_object_unref (pixbuf); 916 g_object_unref (pixbuf);
885 pixbuf = image; 917 pixbuf = image;
886 have_image = true; 918 bg_flags |= BG_IS_FROM_FILE;
887 return true; 919 return true;
888 } 920 }
889# endif 921# endif
890 922
891 return false; 923 return false;
940 bg_flags |= BG_NEEDS_BLUR; 972 bg_flags |= BG_NEEDS_BLUR;
941 973
942 return changed; 974 return changed;
943} 975}
944 976
945static inline unsigned long 977void
946compute_tint_shade_flags (rxvt_color *tint, int shade) 978rxvt_term::set_tint_shade_flags ()
947{ 979{
948 unsigned long flags = 0;
949 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 980 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
950 bool has_shade = shade != 100; 981 bool has_shade = shade != 100;
951 982
952 if (tint) 983 bg_flags &= ~BG_TINT_FLAGS;
984
985 if (bg_flags & BG_TINT_SET)
953 { 986 {
954 tint->get (c); 987 tint.get (c);
955 if (!has_shade 988 if (!has_shade
956 && (c.r <= 0x00ff || c.r >= 0xff00) 989 && (c.r <= 0x00ff || c.r >= 0xff00)
957 && (c.g <= 0x00ff || c.g >= 0xff00) 990 && (c.g <= 0x00ff || c.g >= 0xff00)
958 && (c.b <= 0x00ff || c.b >= 0xff00)) 991 && (c.b <= 0x00ff || c.b >= 0xff00))
959 flags |= rxvt_term::BG_TINT_BITAND; 992 bg_flags |= BG_TINT_BITAND;
960 } 993 }
961 994
962 if (has_shade || tint) 995 if (has_shade || (bg_flags & BG_TINT_SET))
963 flags |= rxvt_term::BG_NEEDS_TINT; 996 bg_flags |= BG_NEEDS_TINT;
964
965 return flags;
966} 997}
967 998
968bool 999bool
969rxvt_term::bg_set_tint (rxvt_color &new_tint) 1000rxvt_term::bg_set_tint (rxvt_color &new_tint)
970{ 1001{
971 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 1002 if (!(bg_flags & BG_TINT_SET) || tint != new_tint)
972 { 1003 {
973 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
974 tint = new_tint; 1004 tint = new_tint;
975 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags | BG_TINT_SET; 1005 bg_flags |= BG_TINT_SET;
1006 set_tint_shade_flags ();
976 return true; 1007 return true;
977 } 1008 }
978 1009
979 return false; 1010 return false;
980} 1011}
988 if (new_shade < 0) 1019 if (new_shade < 0)
989 new_shade = 200 - (100 + new_shade); 1020 new_shade = 200 - (100 + new_shade);
990 1021
991 if (new_shade != shade) 1022 if (new_shade != shade)
992 { 1023 {
993 unsigned long new_flags = compute_tint_shade_flags ((bg_flags & BG_TINT_SET) ? &tint : NULL, new_shade);
994 shade = new_shade; 1024 shade = new_shade;
995 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags; 1025 set_tint_shade_flags ();
996 return true; 1026 return true;
997 } 1027 }
998 1028
999 return false; 1029 return false;
1000} 1030}
1035 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1065 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1036 1066
1037 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1067 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1038 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1068 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1039 1069
1040 if (kernel && params && src && dst) 1070 if (kernel && params)
1041 { 1071 {
1042 if (h_blurRadius) 1072 if (h_blurRadius)
1043 { 1073 {
1044 size = h_blurRadius * 2 + 1; 1074 size = h_blurRadius * 2 + 1;
1045 get_gaussian_kernel (h_blurRadius, size, kernel, params); 1075 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1110 } 1140 }
1111 } 1141 }
1112 else 1142 else
1113 { 1143 {
1114# if XRENDER 1144# if XRENDER
1115 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1145 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1116 1146
1117 if (bg_flags & BG_TINT_SET) 1147 if (bg_flags & BG_TINT_SET)
1118 tint.get (c); 1148 tint.get (c);
1119 1149
1120 if (shade <= 100) 1150 if (shade <= 100)
1121 { 1151 {
1122 c.r = (c.r * shade) / 100; 1152 c.r = c.r * shade / 100;
1123 c.g = (c.g * shade) / 100; 1153 c.g = c.g * shade / 100;
1124 c.b = (c.b * shade) / 100; 1154 c.b = c.b * shade / 100;
1125 } 1155 }
1126 else 1156 else
1127 { 1157 {
1128 c.r = (c.r * (200 - shade)) / 100; 1158 c.r = c.r * (200 - shade) / 100;
1129 c.g = (c.g * (200 - shade)) / 100; 1159 c.g = c.g * (200 - shade) / 100;
1130 c.b = (c.b * (200 - shade)) / 100; 1160 c.b = c.b * (200 - shade) / 100;
1131 } 1161 }
1132 1162
1133 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); 1163 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1134 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1164 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1135 XRenderPictureAttributes pa; 1165 XRenderPictureAttributes pa;
1142 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); 1172 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1143 XFreePixmap (dpy, overlay_pmap); 1173 XFreePixmap (dpy, overlay_pmap);
1144 1174
1145 pa.component_alpha = True; 1175 pa.component_alpha = True;
1146 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1176 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1147 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); 1177 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1148 XFreePixmap (dpy, mask_pmap); 1178 XFreePixmap (dpy, mask_pmap);
1149 1179
1150 if (mask_pic && overlay_pic && back_pic)
1151 {
1152 XRenderColor mask_c; 1180 XRenderColor mask_c;
1153 1181
1154 mask_c.red = mask_c.green = mask_c.blue = 0;
1155 mask_c.alpha = 0xffff; 1182 mask_c.alpha = 0xffff;
1183 mask_c.red =
1184 mask_c.green =
1185 mask_c.blue = 0;
1186 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1187
1188 mask_c.alpha = 0;
1189 mask_c.red = 0xffff - c.r;
1190 mask_c.green = 0xffff - c.g;
1191 mask_c.blue = 0xffff - c.b;
1192 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1193 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1194
1195 if (shade > 100)
1196 {
1197 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1198 mask_c.alpha = 0;
1156 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1199 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1157 1200
1158 mask_c.alpha = 0;
1159 mask_c.red = 0xffff - c.r;
1160 mask_c.green = 0xffff - c.g;
1161 mask_c.blue = 0xffff - c.b;
1162 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1163 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1164
1165 if (shade > 100)
1166 {
1167 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1168 mask_c.alpha = 0;
1169 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1170
1171 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1201 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1172 } 1202 }
1173 1203
1174 ret = true; 1204 ret = true;
1175 }
1176 1205
1177 XRenderFreePicture (dpy, mask_pic); 1206 XRenderFreePicture (dpy, mask_pic);
1178 XRenderFreePicture (dpy, overlay_pic); 1207 XRenderFreePicture (dpy, overlay_pic);
1179 XRenderFreePicture (dpy, back_pic); 1208 XRenderFreePicture (dpy, back_pic);
1180# endif 1209# endif
1181 } 1210 }
1182 1211
1183 return ret; 1212 return ret;
1184} 1213}
1185 1214
1186/* make_transparency_pixmap() 1215/*
1187 * Builds a pixmap of the same size as the terminal window that contains 1216 * Builds a pixmap of the same size as the terminal window that contains
1188 * the tiled portion of the root pixmap that is supposed to be covered by 1217 * the tiled portion of the root pixmap that is supposed to be covered by
1189 * our window. 1218 * our window.
1190 */ 1219 */
1191unsigned long 1220unsigned long
1235 if (root_pixmap != None && root_depth != depth) 1264 if (root_pixmap != None && root_depth != depth)
1236 { 1265 {
1237#if XRENDER 1266#if XRENDER
1238 if (bg_flags & BG_HAS_RENDER) 1267 if (bg_flags & BG_HAS_RENDER)
1239 { 1268 {
1269 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1270
1240 XRenderPictureAttributes pa; 1271 XRenderPictureAttributes pa;
1241 1272
1242 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1273 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1243 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1274 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1244 1275
1245 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1246 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 1276 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1247 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1277 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1248 1278
1249 if (src && dst)
1250 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); 1279 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1251 else
1252 {
1253 XFreePixmap (dpy, recoded_root_pmap);
1254 root_pixmap = None;
1255 }
1256 1280
1257 XRenderFreePicture (dpy, src); 1281 XRenderFreePicture (dpy, src);
1258 XRenderFreePicture (dpy, dst); 1282 XRenderFreePicture (dpy, dst);
1259 } 1283 }
1260 else 1284 else
1261#endif 1285#endif
1262 root_pixmap = None; 1286 recoded_root_pmap = None;
1263 } 1287 }
1264 1288
1265 if (root_pixmap == None) 1289 if (recoded_root_pmap == None)
1266 return 0; 1290 return 0;
1267 1291
1268 if (bg_pixmap == None 1292 if (bg_pixmap == None
1269 || bg_pmap_width != window_width 1293 || bg_pmap_width != window_width
1270 || bg_pmap_height != window_height) 1294 || bg_pmap_height != window_height)
1274 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); 1298 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth);
1275 bg_pmap_width = window_width; 1299 bg_pmap_width = window_width;
1276 bg_pmap_height = window_height; 1300 bg_pmap_height = window_height;
1277 } 1301 }
1278 1302
1279 if (bg_pixmap == None)
1280 return 0;
1281
1282 /* straightforward pixmap copy */ 1303 /* straightforward pixmap copy */
1283 while (sx < 0) sx += (int)root_width; 1304 while (sx < 0) sx += root_width;
1284 while (sy < 0) sy += (int)root_height; 1305 while (sy < 0) sy += root_height;
1285 1306
1286 gcv.tile = recoded_root_pmap; 1307 gcv.tile = recoded_root_pmap;
1287 gcv.fill_style = FillTiled; 1308 gcv.fill_style = FillTiled;
1288 gcv.ts_x_origin = -sx; 1309 gcv.ts_x_origin = -sx;
1289 gcv.ts_y_origin = -sy; 1310 gcv.ts_y_origin = -sy;
1350 bg_flags |= BG_IS_VALID; 1371 bg_flags |= BG_IS_VALID;
1351 } 1372 }
1352# endif 1373# endif
1353 1374
1354# ifdef BG_IMAGE_FROM_FILE 1375# ifdef BG_IMAGE_FROM_FILE
1355 if (have_image 1376 if ((bg_flags & BG_IS_FROM_FILE)
1356 || (tr_flags & BG_EFFECTS_FLAGS)) 1377 || (tr_flags & BG_EFFECTS_FLAGS))
1357 { 1378 {
1358 if (render_image (tr_flags)) 1379 if (render_image (tr_flags))
1359 bg_flags |= BG_IS_VALID; 1380 bg_flags |= BG_IS_VALID;
1360 } 1381 }
1446 uint32_t mask_r, mask_g, mask_b; 1467 uint32_t mask_r, mask_g, mask_b;
1447 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1468 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1448 rgba low; 1469 rgba low;
1449 rgba high; 1470 rgba high;
1450 int i; 1471 int i;
1451 int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; 1472 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1452 1473
1453 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1474 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1454 1475
1455 /* for convenience */ 1476 /* for convenience */
1456 mask_r = visual->red_mask; 1477 mask_r = visual->red_mask;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines