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.144 by sf-exg, Fri Jan 28 00:20:47 2011 UTC vs.
Revision 1.160 by sf-exg, Thu Aug 11 08:37:17 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);
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"))
269 {
270 if (w == 0) w = windowScale;
271
272 h = noScale;
273 geom_flags |= WidthValue|HeightValue;
274 }
275 else if (!strcasecmp (arr[i], "vscale"))
276 {
277 if (h == 0) h = windowScale;
278
279 w = noScale;
280 geom_flags |= WidthValue|HeightValue;
281 }
282 else if (!strcasecmp (arr[i], "scale")) 303 else if (!strcasecmp (arr[i], "scale"))
283 { 304 {
284 if (h == 0) h = windowScale; 305 if (h == 0) h = windowScale;
285 if (w == 0) w = windowScale; 306 if (w == 0) w = windowScale;
286 307
287 geom_flags |= WidthValue|HeightValue; 308 geom_flags |= WidthValue|HeightValue;
288 } 309 }
289 else if (!strcasecmp (arr[i], "auto"))
290 {
291 w = h = windowScale;
292 x = y = centerAlign;
293 geom_flags |= WidthValue|HeightValue|XValue|YValue;
294 }
295 else if (!strcasecmp (arr[i], "root")) 310 else if (!strcasecmp (arr[i], "root"))
296 { 311 {
297 new_flags |= BG_ROOT_ALIGN; 312 new_flags |= BG_TILE|BG_ROOT_ALIGN;
298 w = h = noScale; 313 w = h = noScale;
299 geom_flags |= WidthValue|HeightValue; 314 geom_flags |= WidthValue|HeightValue;
300 } 315 }
301 } /* done parsing ops */ 316 } /* done parsing ops */
302 317
349 x = make_align_position (h_align, target_width, w); 364 x = make_align_position (h_align, target_width, w);
350 y = make_align_position (v_align, target_height, h); 365 y = make_align_position (v_align, target_height, h);
351 } 366 }
352 367
353 bg_flags &= ~BG_IS_SIZE_SENSITIVE; 368 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
369 if (!(bg_flags & BG_TILE)
354 if ((bg_flags & BG_PROP_SCALE) || h_scale || v_scale 370 || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale
355 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) 371 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
356 || w > target_width || h > target_height) 372 || w > target_width || h > target_height)
357 bg_flags |= BG_IS_SIZE_SENSITIVE; 373 bg_flags |= BG_IS_SIZE_SENSITIVE;
358} 374}
359 375
451 100, ASIMAGE_QUALITY_DEFAULT); 467 100, ASIMAGE_QUALITY_DEFAULT);
452 } 468 }
453 469
454 if (background == NULL) 470 if (background == NULL)
455 { 471 {
456 if (h_scale == 0 || v_scale == 0) 472 if (bg_flags & BG_TILE)
457 { 473 {
458 /* if tiling - pixmap has to be sized exactly as the image, 474 /* if tiling - pixmap has to be sized exactly as the image,
459 but there is no need to make it bigger than the window! */ 475 but there is no need to make it bigger than the window! */
460 new_pmap_width = min (result->width, target_width); 476 new_pmap_width = min (result->width, target_width);
461 new_pmap_height = min (result->height, target_height); 477 new_pmap_height = min (result->height, target_height);
486 layers[0].clip_width = target_width; 502 layers[0].clip_width = target_width;
487 layers[0].clip_height = target_height; 503 layers[0].clip_height = target_height;
488 layers[0].tint = background_tint; 504 layers[0].tint = background_tint;
489 layers[1].im = result; 505 layers[1].im = result;
490 506
491 if (h_scale == 0 || v_scale == 0) 507 if (bg_flags & BG_TILE)
492 { 508 {
493 /* tile horizontally */ 509 /* tile horizontally */
494 while (x > 0) x -= (int)result->width; 510 while (x > 0) x -= (int)result->width;
495 layers[1].dst_x = x; 511 layers[1].dst_x = x;
496 layers[1].clip_width = result->width+target_width; 512 layers[1].clip_width = result->width+target_width;
500 /* clip horizontally */ 516 /* clip horizontally */
501 layers[1].dst_x = x; 517 layers[1].dst_x = x;
502 layers[1].clip_width = result->width; 518 layers[1].clip_width = result->width;
503 } 519 }
504 520
505 if (h_scale == 0 || v_scale == 0) 521 if (bg_flags & BG_TILE)
506 { 522 {
507 while (y > 0) y -= (int)result->height; 523 while (y > 0) y -= (int)result->height;
508 layers[1].dst_y = y; 524 layers[1].dst_y = y;
509 layers[1].clip_height = result->height + target_height; 525 layers[1].clip_height = result->height + target_height;
510 } 526 }
560 576
561 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 577 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
562 int dst_width = result->width, dst_height = result->height; 578 int dst_width = result->width, dst_height = result->height;
563 if (background == NULL) 579 if (background == NULL)
564 { 580 {
565 if (!(h_scale == 0 || v_scale == 0)) 581 if (!(bg_flags & BG_TILE))
566 { 582 {
567 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); 583 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); 584 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
569 } 585 }
570 586
616 else if (depth == 15 || depth == 16) 632 else if (depth == 15 || depth == 16)
617 bytes_per_pixel = 2; 633 bytes_per_pixel = 2;
618 else 634 else
619 return false; 635 return false;
620 636
621 width_r = rxvt_popcount (visual->red_mask); 637 width_r = ecb_popcount32 (visual->red_mask);
622 width_g = rxvt_popcount (visual->green_mask); 638 width_g = ecb_popcount32 (visual->green_mask);
623 width_b = rxvt_popcount (visual->blue_mask); 639 width_b = ecb_popcount32 (visual->blue_mask);
624 640
625 if (width_r > 8 || width_g > 8 || width_b > 8) 641 if (width_r > 8 || width_g > 8 || width_b > 8)
626 return false; 642 return false;
627 643
628 sh_r = rxvt_ctz (visual->red_mask); 644 sh_r = ecb_ctz32 (visual->red_mask);
629 sh_g = rxvt_ctz (visual->green_mask); 645 sh_g = ecb_ctz32 (visual->green_mask);
630 sh_b = rxvt_ctz (visual->blue_mask); 646 sh_b = ecb_ctz32 (visual->blue_mask);
631 647
632 if (width > INT_MAX / height / bytes_per_pixel) 648 if (width > INT_MAX / height / bytes_per_pixel)
633 return false; 649 return false;
634 650
635 data = (char *)malloc (width * height * bytes_per_pixel); 651 data = (char *)malloc (width * height * bytes_per_pixel);
642 { 658 {
643 free (data); 659 free (data);
644 return false; 660 return false;
645 } 661 }
646 662
647 ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; 663 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
648 664
649 rowstride = gdk_pixbuf_get_rowstride (pixbuf); 665 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
650 channels = gdk_pixbuf_get_n_channels (pixbuf); 666 channels = gdk_pixbuf_get_n_channels (pixbuf);
651 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; 667 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
652 line = data; 668 line = data;
719 result = gdk_pixbuf_scale_simple (pixbuf, 735 result = gdk_pixbuf_scale_simple (pixbuf,
720 w, h, 736 w, h,
721 GDK_INTERP_BILINEAR); 737 GDK_INTERP_BILINEAR);
722 } 738 }
723 739
740 if (!result)
741 return false;
742
724 bool ret = false; 743 bool ret = false;
725 744
726 if (result)
727 {
728 XGCValues gcv; 745 XGCValues gcv;
729 GC gc; 746 GC gc;
730 Pixmap root_pmap; 747 Pixmap root_pmap;
731 748
732 image_width = gdk_pixbuf_get_width (result); 749 image_width = gdk_pixbuf_get_width (result);
733 image_height = gdk_pixbuf_get_height (result); 750 image_height = gdk_pixbuf_get_height (result);
734 751
735 if (tr_flags) 752 if (tr_flags)
736 { 753 {
737 root_pmap = bg_pixmap; 754 root_pmap = bg_pixmap;
738 bg_pixmap = None; 755 bg_pixmap = None;
756 }
757 else
758 {
759 if (bg_flags & BG_TILE)
739 } 760 {
740 else
741 {
742 if (h_scale == 0 || v_scale == 0)
743 {
744 new_pmap_width = min (image_width, target_width); 761 new_pmap_width = min (image_width, target_width);
745 new_pmap_height = min (image_height, target_height); 762 new_pmap_height = min (image_height, target_height);
746 } 763 }
747 } 764 }
748 765
749 if (bg_pixmap == None 766 if (bg_pixmap == None
750 || bg_pmap_width != new_pmap_width 767 || bg_pmap_width != new_pmap_width
751 || bg_pmap_height != new_pmap_height) 768 || bg_pmap_height != new_pmap_height)
752 { 769 {
753 if (bg_pixmap) 770 if (bg_pixmap)
754 XFreePixmap (dpy, bg_pixmap); 771 XFreePixmap (dpy, bg_pixmap);
755 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); 772 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
756 bg_pmap_width = new_pmap_width; 773 bg_pmap_width = new_pmap_width;
757 bg_pmap_height = new_pmap_height; 774 bg_pmap_height = new_pmap_height;
758 } 775 }
759 776
760 gcv.foreground = pix_colors[Color_bg]; 777 gcv.foreground = pix_colors[Color_bg];
761 gc = XCreateGC (dpy, vt, GCForeground, &gcv); 778 gc = XCreateGC (dpy, vt, GCForeground, &gcv);
762 779
763 if (h_scale == 0 || v_scale == 0) 780 if (gc)
781 {
782 if (bg_flags & BG_TILE)
764 { 783 {
765 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); 784 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth);
766 pixbuf_to_pixmap (result, tile, gc, 785 pixbuf_to_pixmap (result, tile, gc,
767 0, 0, 786 0, 0,
768 0, 0, 787 0, 0,
812 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); 831 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
813 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); 832 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
814 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); 833 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
815 XFreePixmap (dpy, mask_pmap); 834 XFreePixmap (dpy, mask_pmap);
816 835
817 if (src && dst && mask)
818 {
819 XRenderColor mask_c; 836 XRenderColor mask_c;
820 837
821 mask_c.alpha = 0x8000; 838 mask_c.alpha = 0x8000;
822 mask_c.red = 0; 839 mask_c.red = 0;
823 mask_c.green = 0; 840 mask_c.green = 0;
824 mask_c.blue = 0; 841 mask_c.blue = 0;
825 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 842 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); 843 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height);
827 }
828 844
829 XRenderFreePicture (dpy, src); 845 XRenderFreePicture (dpy, src);
830 XRenderFreePicture (dpy, dst); 846 XRenderFreePicture (dpy, dst);
831 XRenderFreePicture (dpy, mask); 847 XRenderFreePicture (dpy, mask);
832
833 XFreePixmap (dpy, root_pmap);
834 } 848 }
835#endif 849#endif
836 850
837 if (result != pixbuf)
838 g_object_unref (result);
839
840 XFreeGC (dpy, gc); 851 XFreeGC (dpy, gc);
841 852
842 ret = true; 853 ret = true;
843 } 854 }
855
856 if (result != pixbuf)
857 g_object_unref (result);
858
859 if (tr_flags)
860 XFreePixmap (dpy, root_pmap);
844 861
845 return ret; 862 return ret;
846} 863}
847# endif /* HAVE_PIXBUF */ 864# endif /* HAVE_PIXBUF */
848 865
939 bg_flags |= BG_NEEDS_BLUR; 956 bg_flags |= BG_NEEDS_BLUR;
940 957
941 return changed; 958 return changed;
942} 959}
943 960
944static inline unsigned long 961void
945compute_tint_shade_flags (rxvt_color *tint, int shade) 962rxvt_term::set_tint_shade_flags ()
946{ 963{
947 unsigned long flags = 0;
948 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 964 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
949 bool has_shade = shade != 100; 965 bool has_shade = shade != 100;
950 966
951 if (tint) 967 bg_flags &= ~BG_TINT_FLAGS;
968
969 if (bg_flags & BG_TINT_SET)
952 { 970 {
953 tint->get (c); 971 tint.get (c);
954 if (!has_shade 972 if (!has_shade
955 && (c.r <= 0x00ff || c.r >= 0xff00) 973 && (c.r <= 0x00ff || c.r >= 0xff00)
956 && (c.g <= 0x00ff || c.g >= 0xff00) 974 && (c.g <= 0x00ff || c.g >= 0xff00)
957 && (c.b <= 0x00ff || c.b >= 0xff00)) 975 && (c.b <= 0x00ff || c.b >= 0xff00))
958 flags |= rxvt_term::BG_TINT_BITAND; 976 bg_flags |= BG_TINT_BITAND;
959 } 977 }
960 978
961 if (has_shade || tint) 979 if (has_shade || (bg_flags & BG_TINT_SET))
962 flags |= rxvt_term::BG_NEEDS_TINT; 980 bg_flags |= BG_NEEDS_TINT;
963
964 return flags;
965} 981}
966 982
967bool 983bool
968rxvt_term::bg_set_tint (rxvt_color &new_tint) 984rxvt_term::bg_set_tint (rxvt_color &new_tint)
969{ 985{
970 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 986 if (!(bg_flags & BG_TINT_SET) || tint != new_tint)
971 { 987 {
972 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
973 tint = new_tint; 988 tint = new_tint;
974 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags | BG_TINT_SET; 989 bg_flags |= BG_TINT_SET;
990 set_tint_shade_flags ();
975 return true; 991 return true;
976 } 992 }
977 993
978 return false; 994 return false;
979} 995}
987 if (new_shade < 0) 1003 if (new_shade < 0)
988 new_shade = 200 - (100 + new_shade); 1004 new_shade = 200 - (100 + new_shade);
989 1005
990 if (new_shade != shade) 1006 if (new_shade != shade)
991 { 1007 {
992 unsigned long new_flags = compute_tint_shade_flags ((bg_flags & BG_TINT_SET) ? &tint : NULL, new_shade);
993 shade = new_shade; 1008 shade = new_shade;
994 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags; 1009 set_tint_shade_flags ();
995 return true; 1010 return true;
996 } 1011 }
997 1012
998 return false; 1013 return false;
999} 1014}
1034 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1049 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1035 1050
1036 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1051 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1037 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1052 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1038 1053
1039 if (kernel && params && src && dst) 1054 if (kernel && params)
1040 { 1055 {
1041 if (h_blurRadius) 1056 if (h_blurRadius)
1042 { 1057 {
1043 size = h_blurRadius * 2 + 1; 1058 size = h_blurRadius * 2 + 1;
1044 get_gaussian_kernel (h_blurRadius, size, kernel, params); 1059 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1109 } 1124 }
1110 } 1125 }
1111 else 1126 else
1112 { 1127 {
1113# if XRENDER 1128# if XRENDER
1114 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1129 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1115 1130
1116 if (bg_flags & BG_TINT_SET) 1131 if (bg_flags & BG_TINT_SET)
1117 tint.get (c); 1132 tint.get (c);
1118 1133
1119 if (shade <= 100) 1134 if (shade <= 100)
1120 { 1135 {
1121 c.r = (c.r * shade) / 100; 1136 c.r = c.r * shade / 100;
1122 c.g = (c.g * shade) / 100; 1137 c.g = c.g * shade / 100;
1123 c.b = (c.b * shade) / 100; 1138 c.b = c.b * shade / 100;
1124 } 1139 }
1125 else 1140 else
1126 { 1141 {
1127 c.r = (c.r * (200 - shade)) / 100; 1142 c.r = c.r * (200 - shade) / 100;
1128 c.g = (c.g * (200 - shade)) / 100; 1143 c.g = c.g * (200 - shade) / 100;
1129 c.b = (c.b * (200 - shade)) / 100; 1144 c.b = c.b * (200 - shade) / 100;
1130 } 1145 }
1131 1146
1132 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); 1147 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1133 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1148 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1134 XRenderPictureAttributes pa; 1149 XRenderPictureAttributes pa;
1141 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); 1156 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1142 XFreePixmap (dpy, overlay_pmap); 1157 XFreePixmap (dpy, overlay_pmap);
1143 1158
1144 pa.component_alpha = True; 1159 pa.component_alpha = True;
1145 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1160 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1146 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); 1161 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1147 XFreePixmap (dpy, mask_pmap); 1162 XFreePixmap (dpy, mask_pmap);
1148 1163
1149 if (mask_pic && overlay_pic && back_pic)
1150 {
1151 XRenderColor mask_c; 1164 XRenderColor mask_c;
1152 1165
1153 mask_c.red = mask_c.green = mask_c.blue = 0;
1154 mask_c.alpha = 0xffff; 1166 mask_c.alpha = 0xffff;
1167 mask_c.red =
1168 mask_c.green =
1169 mask_c.blue = 0;
1170 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1171
1172 mask_c.alpha = 0;
1173 mask_c.red = 0xffff - c.r;
1174 mask_c.green = 0xffff - c.g;
1175 mask_c.blue = 0xffff - c.b;
1176 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1177 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1178
1179 if (shade > 100)
1180 {
1181 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1182 mask_c.alpha = 0;
1155 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1183 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1156 1184
1157 mask_c.alpha = 0;
1158 mask_c.red = 0xffff - c.r;
1159 mask_c.green = 0xffff - c.g;
1160 mask_c.blue = 0xffff - c.b;
1161 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1162 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1163
1164 if (shade > 100)
1165 {
1166 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1167 mask_c.alpha = 0;
1168 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1169
1170 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1185 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1171 } 1186 }
1172 1187
1173 ret = true; 1188 ret = true;
1174 }
1175 1189
1176 XRenderFreePicture (dpy, mask_pic); 1190 XRenderFreePicture (dpy, mask_pic);
1177 XRenderFreePicture (dpy, overlay_pic); 1191 XRenderFreePicture (dpy, overlay_pic);
1178 XRenderFreePicture (dpy, back_pic); 1192 XRenderFreePicture (dpy, back_pic);
1179# endif 1193# endif
1180 } 1194 }
1181 1195
1182 return ret; 1196 return ret;
1183} 1197}
1184 1198
1185/* make_transparency_pixmap() 1199/*
1186 * Builds a pixmap of the same size as the terminal window that contains 1200 * Builds a pixmap of the same size as the terminal window that contains
1187 * the tiled portion of the root pixmap that is supposed to be covered by 1201 * the tiled portion of the root pixmap that is supposed to be covered by
1188 * our window. 1202 * our window.
1189 */ 1203 */
1190unsigned long 1204unsigned long
1234 if (root_pixmap != None && root_depth != depth) 1248 if (root_pixmap != None && root_depth != depth)
1235 { 1249 {
1236#if XRENDER 1250#if XRENDER
1237 if (bg_flags & BG_HAS_RENDER) 1251 if (bg_flags & BG_HAS_RENDER)
1238 { 1252 {
1253 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1254
1239 XRenderPictureAttributes pa; 1255 XRenderPictureAttributes pa;
1240 1256
1241 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1257 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1242 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1258 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1243 1259
1244 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1245 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 1260 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1246 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1261 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1247 1262
1248 if (src && dst)
1249 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); 1263 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1250 else
1251 {
1252 XFreePixmap (dpy, recoded_root_pmap);
1253 root_pixmap = None;
1254 }
1255 1264
1256 XRenderFreePicture (dpy, src); 1265 XRenderFreePicture (dpy, src);
1257 XRenderFreePicture (dpy, dst); 1266 XRenderFreePicture (dpy, dst);
1258 } 1267 }
1259 else 1268 else
1260#endif 1269#endif
1261 root_pixmap = None; 1270 recoded_root_pmap = None;
1262 } 1271 }
1263 1272
1264 if (root_pixmap == None) 1273 if (recoded_root_pmap == None)
1265 return 0; 1274 return 0;
1266 1275
1267 if (bg_pixmap == None 1276 if (bg_pixmap == None
1268 || bg_pmap_width != window_width 1277 || bg_pmap_width != window_width
1269 || bg_pmap_height != window_height) 1278 || bg_pmap_height != window_height)
1273 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); 1282 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth);
1274 bg_pmap_width = window_width; 1283 bg_pmap_width = window_width;
1275 bg_pmap_height = window_height; 1284 bg_pmap_height = window_height;
1276 } 1285 }
1277 1286
1278 if (bg_pixmap == None)
1279 return 0;
1280
1281 /* straightforward pixmap copy */ 1287 /* straightforward pixmap copy */
1282 while (sx < 0) sx += (int)root_width; 1288 while (sx < 0) sx += root_width;
1283 while (sy < 0) sy += (int)root_height; 1289 while (sy < 0) sy += root_height;
1284 1290
1285 gcv.tile = recoded_root_pmap; 1291 gcv.tile = recoded_root_pmap;
1286 gcv.fill_style = FillTiled; 1292 gcv.fill_style = FillTiled;
1287 gcv.ts_x_origin = -sx; 1293 gcv.ts_x_origin = -sx;
1288 gcv.ts_y_origin = -sy; 1294 gcv.ts_y_origin = -sy;
1445 uint32_t mask_r, mask_g, mask_b; 1451 uint32_t mask_r, mask_g, mask_b;
1446 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1452 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1447 rgba low; 1453 rgba low;
1448 rgba high; 1454 rgba high;
1449 int i; 1455 int i;
1450 int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; 1456 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1451 1457
1452 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1458 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1453 1459
1454 /* for convenience */ 1460 /* for convenience */
1455 mask_r = visual->red_mask; 1461 mask_r = visual->red_mask;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines