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.224 by sf-exg, Wed May 30 19:30:57 2012 UTC vs.
Revision 1.226 by sf-exg, Thu May 31 05:53:46 2012 UTC

303 h_align = x; 303 h_align = x;
304 v_align = y; 304 v_align = y;
305 changed = true; 305 changed = true;
306 } 306 }
307 307
308 if (!(flags & IM_TILE) 308 if (is_size_sensitive ())
309 || h_scale || v_scale
310 || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align)))
311 flags |= IM_IS_SIZE_SENSITIVE; 309 flags |= IM_IS_SIZE_SENSITIVE;
312 else 310 else
313 flags &= ~IM_IS_SIZE_SENSITIVE; 311 flags &= ~IM_IS_SIZE_SENSITIVE;
314 312
315 return changed; 313 return changed;
605 src_x, src_y, 603 src_x, src_y,
606 dst_x, dst_y, 604 dst_x, dst_y,
607 dst_width, dst_height, need_blend); 605 dst_width, dst_height, need_blend);
608 } 606 }
609 607
608 if (image.need_blur ())
609 blur_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.h_blurRadius, image.v_blurRadius);
610 if (image.need_tint ())
611 tint_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.tint, image.tint_set, image.shade);
612
610#if XRENDER 613#if XRENDER
611 if (need_blend) 614 if (need_blend)
612 { 615 {
613 XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); 616 XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
614 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 617 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
743 return ret; 746 return ret;
744} 747}
745 748
746# endif /* BG_IMAGE_FROM_FILE */ 749# endif /* BG_IMAGE_FROM_FILE */
747 750
748# ifdef ENABLE_TRANSPARENCY
749bool 751bool
750rxvt_term::bg_set_blur (const char *geom) 752image_effects::set_blur (const char *geom)
751{ 753{
752 bool changed = false; 754 bool changed = false;
753 unsigned int hr, vr; 755 unsigned int hr, vr;
754 int junk; 756 int junk;
755 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 757 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
776 778
777 return changed; 779 return changed;
778} 780}
779 781
780bool 782bool
781rxvt_term::bg_set_tint (rxvt_color &new_tint) 783image_effects::set_tint (const rxvt_color &new_tint)
782{ 784{
783 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 785 if (!tint_set || tint != new_tint)
784 { 786 {
785 tint = new_tint; 787 tint = new_tint;
786 bg_flags |= BG_TINT_SET; 788 tint_set = true;
787
788 rgba c;
789 tint.get (c);
790 if ((c.r <= 0x00ff || c.r >= 0xff00)
791 && (c.g <= 0x00ff || c.g >= 0xff00)
792 && (c.b <= 0x00ff || c.b >= 0xff00))
793 bg_flags |= BG_TINT_BITAND;
794 else
795 bg_flags &= ~BG_TINT_BITAND;
796 789
797 return true; 790 return true;
798 } 791 }
799 792
800 return false; 793 return false;
801} 794}
802 795
803bool 796bool
804rxvt_term::bg_set_shade (const char *shade_str) 797image_effects::set_shade (const char *shade_str)
805{ 798{
806 int new_shade = atoi (shade_str); 799 int new_shade = atoi (shade_str);
807 800
808 clamp_it (new_shade, -100, 200); 801 clamp_it (new_shade, -100, 200);
809 if (new_shade < 0) 802 if (new_shade < 0)
840 params[i+2] = XDoubleToFixed (kernel[i] / sum); 833 params[i+2] = XDoubleToFixed (kernel[i] / sum);
841} 834}
842#endif 835#endif
843 836
844bool 837bool
845rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) 838rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius)
846{ 839{
847 bool ret = false; 840 bool ret = false;
848#if XRENDER 841#if XRENDER
849 if (!(bg_flags & BG_HAS_RENDER_CONV)) 842 if (!(bg_flags & BG_HAS_RENDER_CONV))
850 return false; 843 return false;
852 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 845 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
853 double *kernel = (double *)malloc (size * sizeof (double)); 846 double *kernel = (double *)malloc (size * sizeof (double));
854 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 847 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
855 848
856 XRenderPictureAttributes pa; 849 XRenderPictureAttributes pa;
857 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 850 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
851 : XRenderFindVisualFormat (dpy, visual);
858 852
859 pa.repeat = RepeatPad; 853 pa.repeat = RepeatPad;
860 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); 854 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
861 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); 855 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth);
862 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); 856 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
905#endif 899#endif
906 return ret; 900 return ret;
907} 901}
908 902
909bool 903bool
910rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) 904rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade)
911{ 905{
912 bool ret = false; 906 bool ret = false;
913 907
914 if (shade == 100 && (bg_flags & BG_TINT_BITAND)) 908 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
909
910 if (tint_set)
911 tint.get (c);
912
913 if (shade == 100
914 && (c.r <= 0x00ff || c.r >= 0xff00)
915 && (c.g <= 0x00ff || c.g >= 0xff00)
916 && (c.b <= 0x00ff || c.b >= 0xff00))
915 { 917 {
916 XGCValues gcv; 918 XGCValues gcv;
917 GC gc; 919 GC gc;
918 920
919 /* In this case we can tint image server-side getting significant 921 /* In this case we can tint image server-side getting significant
931 } 933 }
932 } 934 }
933# if XRENDER 935# if XRENDER
934 else if (bg_flags & BG_HAS_RENDER) 936 else if (bg_flags & BG_HAS_RENDER)
935 { 937 {
936 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
937
938 if (bg_flags & BG_TINT_SET)
939 tint.get (c);
940
941 if (shade <= 100) 938 if (shade <= 100)
942 { 939 {
943 c.r = c.r * shade / 100; 940 c.r = c.r * shade / 100;
944 c.g = c.g * shade / 100; 941 c.g = c.g * shade / 100;
945 c.b = c.b * shade / 100; 942 c.b = c.b * shade / 100;
949 c.r = c.r * (200 - shade) / 100; 946 c.r = c.r * (200 - shade) / 100;
950 c.g = c.g * (200 - shade) / 100; 947 c.g = c.g * (200 - shade) / 100;
951 c.b = c.b * (200 - shade) / 100; 948 c.b = c.b * (200 - shade) / 100;
952 } 949 }
953 950
954 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 951 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
952 : XRenderFindVisualFormat (dpy, visual);
955 953
956 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); 954 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
957 955
958 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); 956 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
959 957
995# endif 993# endif
996 994
997 return ret; 995 return ret;
998} 996}
999 997
998# ifdef ENABLE_TRANSPARENCY
1000/* 999/*
1001 * Builds a pixmap of the same size as the terminal window that contains 1000 * Builds a pixmap of the same size as the terminal window that contains
1002 * the tiled portion of the root pixmap that is supposed to be covered by 1001 * the tiled portion of the root pixmap that is supposed to be covered by
1003 * our window. 1002 * our window.
1004 */ 1003 */
1095 1094
1096 if (gc) 1095 if (gc)
1097 { 1096 {
1098 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1097 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1099 ret = true; 1098 ret = true;
1100 bool need_blur = h_blurRadius && v_blurRadius; 1099 bool need_blur = root_effects.need_blur ();
1101 bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); 1100 bool need_tint = root_effects.need_tint ();
1102 1101
1103 if (!(bg_flags & BG_CLIENT_RENDER)) 1102 if (!(bg_flags & BG_CLIENT_RENDER))
1104 { 1103 {
1105 if (need_blur) 1104 if (need_blur)
1106 { 1105 {
1107 if (blur_pixmap (bg_pixmap, window_width, window_height)) 1106 if (blur_pixmap (bg_pixmap, window_width, window_height, false,
1107 root_effects.h_blurRadius, root_effects.v_blurRadius))
1108 need_blur = false; 1108 need_blur = false;
1109 } 1109 }
1110 if (need_tint) 1110 if (need_tint)
1111 { 1111 {
1112 if (tint_pixmap (bg_pixmap, window_width, window_height)) 1112 if (tint_pixmap (bg_pixmap, window_width, window_height, false,
1113 root_effects.tint, root_effects.tint_set, root_effects.shade))
1113 need_tint = false; 1114 need_tint = false;
1114 } 1115 }
1115 if (need_tint) 1116 if (need_tint)
1116 { 1117 {
1117 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); 1118 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1118 if (ximage) 1119 if (ximage)
1119 { 1120 {
1120 /* our own client-side tinting */ 1121 /* our own client-side tinting */
1121 tint_ximage (ximage); 1122 tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade);
1122 1123
1123 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); 1124 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1124 XDestroyImage (ximage); 1125 XDestroyImage (ximage);
1125 } 1126 }
1126 } 1127 }
1185} 1186}
1186 1187
1187void 1188void
1188rxvt_term::bg_init () 1189rxvt_term::bg_init ()
1189{ 1190{
1190#ifdef ENABLE_TRANSPARENCY
1191 shade = 100;
1192#endif
1193
1194 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); 1191 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1195#if XRENDER 1192#if XRENDER
1196 int major, minor; 1193 int major, minor;
1197 if (XRenderQueryVersion (dpy, &major, &minor)) 1194 if (XRenderQueryVersion (dpy, &major, &minor))
1198 bg_flags |= BG_HAS_RENDER; 1195 bg_flags |= BG_HAS_RENDER;
1221 while (bg_image != image_vec.end ()) 1218 while (bg_image != image_vec.end ())
1222 { 1219 {
1223 if (!(bg_image->flags & IM_IS_SET)) 1220 if (!(bg_image->flags & IM_IS_SET))
1224 bg_image = image_vec.erase (bg_image); 1221 bg_image = image_vec.erase (bg_image);
1225 else 1222 else
1223 {
1224 if (bg_image->is_size_sensitive ())
1225 bg_image->flags |= IM_IS_SIZE_SENSITIVE;
1226
1226 bg_image++; 1227 bg_image++;
1228 }
1227 } 1229 }
1228# endif 1230# endif
1229 1231
1230 if (image_vec.size () > 0 1232 if (image_vec.size () > 0
1231 && !bg_window_position_sensitive ()) 1233 && !bg_window_position_sensitive ())
1232 update_background (); 1234 update_background ();
1233#endif 1235#endif
1234} 1236}
1235 1237
1236#endif /* HAVE_BG_PIXMAP */
1237
1238#ifdef ENABLE_TRANSPARENCY
1239/* based on code from aterm-0.4.2 */ 1238/* based on code from aterm-0.4.2 */
1240 1239
1241static inline void 1240static inline void
1242fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) 1241fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1243{ 1242{
1249 lookup[i] = (tmp / 0xffff) << sh; 1248 lookup[i] = (tmp / 0xffff) << sh;
1250 } 1249 }
1251} 1250}
1252 1251
1253void 1252void
1254rxvt_term::tint_ximage (XImage *ximage) 1253rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade)
1255{ 1254{
1256 unsigned int size_r, size_g, size_b; 1255 unsigned int size_r, size_g, size_b;
1257 int sh_r, sh_g, sh_b; 1256 int sh_r, sh_g, sh_b;
1258 uint32_t mask_r, mask_g, mask_b; 1257 uint32_t mask_r, mask_g, mask_b;
1259 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1258 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1284 lookup_g = lookup + size_r; 1283 lookup_g = lookup + size_r;
1285 lookup_b = lookup + size_r + size_g; 1284 lookup_b = lookup + size_r + size_g;
1286 1285
1287 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1286 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1288 1287
1289 if (bg_flags & BG_TINT_SET) 1288 if (tint_set)
1290 tint.get (c); 1289 tint.get (c);
1291 1290
1292 /* prepare limits for color transformation (each channel is handled separately) */ 1291 /* prepare limits for color transformation (each channel is handled separately) */
1293 if (shade > 100) 1292 if (shade > 100)
1294 { 1293 {
1344 } 1343 }
1345 } 1344 }
1346 1345
1347 free (lookup); 1346 free (lookup);
1348} 1347}
1349#endif /* ENABLE_TRANSPARENCY */ 1348
1349#endif /* HAVE_BG_PIXMAP */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines