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.159 by sf-exg, Wed Aug 10 07:34:35 2011 UTC vs.
Revision 1.196 by sf-exg, Tue Jan 10 18:50:14 2012 UTC

32 32
33#ifndef FilterConvolution 33#ifndef FilterConvolution
34#define FilterConvolution "convolution" 34#define FilterConvolution "convolution"
35#endif 35#endif
36 36
37/* 37#ifndef RepeatPad
38 * Pixmap geometry string interpretation : 38#define RepeatPad True
39 * Each geometry string contains zero or one scale/position 39#endif
40 * adjustment and may optionally be followed by a colon and one or more
41 * colon-delimited pixmap operations.
42 * The following table shows the valid geometry strings and their
43 * effects on the background image :
44 *
45 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
46 * W and H are percentages of the terminal window size.
47 * X and Y are also percentages; e.g., +50+50 centers
48 * the image in the window.
49 *
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 * scale Scale both up and down
58 */
59 40
60#ifdef HAVE_BG_PIXMAP 41#ifdef HAVE_BG_PIXMAP
42# if XRENDER
43static Picture
44create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha)
45{
46 Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8);
47
48 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8);
49 XRenderPictureAttributes pa;
50 pa.repeat = True;
51 pa.component_alpha = component_alpha;
52 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa);
53
54 XFreePixmap (dpy, pixmap);
55
56 return mask;
57}
58# endif
59
61void 60void
62rxvt_term::bg_destroy () 61rxvt_term::bg_destroy ()
63{ 62{
64#ifdef HAVE_AFTERIMAGE 63#ifdef HAVE_AFTERIMAGE
65 if (original_asim) 64 if (original_asim)
173 int smaller = min (image_size, window_size); 172 int smaller = min (image_size, window_size);
174 173
175 if (align >= 0 && align <= 100) 174 if (align >= 0 && align <= 100)
176 return diff * align / 100; 175 return diff * align / 100;
177 else if (align > 100 && align <= 200) 176 else if (align > 100 && align <= 200)
178 return ((align - 100) * smaller / 100) + window_size - smaller; 177 return (align - 100) * smaller / 100 + window_size - smaller;
179 else if (align >= -100 && align < 0) 178 else if (align >= -100 && align < 0)
180 return ((align + 100) * smaller / 100) - image_size; 179 return (align + 100) * smaller / 100 - image_size;
181 return 0; 180 return 0;
182} 181}
183 182
184static inline int 183static inline int
185make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 184make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
204{ 203{
205 bool changed = false; 204 bool changed = false;
206 int geom_flags = 0; 205 int geom_flags = 0;
207 int x = 0, y = 0; 206 int x = 0, y = 0;
208 unsigned int w = 0, h = 0; 207 unsigned int w = 0, h = 0;
209 unsigned int n; 208 unsigned long new_flags = 0;
210 unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS));
211 const char *ops;
212 209
213 if (geom == NULL) 210 if (geom == NULL)
214 return false; 211 return false;
215 212
216 char str[256]; 213 if (geom[0])
217
218 ops = strchr (geom, ':');
219 if (ops == NULL)
220 n = strlen (geom);
221 else
222 n = ops - geom;
223
224 if (n >= sizeof (str))
225 return false;
226
227 memcpy (str, geom, n);
228 str[n] = '\0';
229 rxvt_strtrim (str);
230
231 if (str[0])
232 { 214 {
233 /* we have geometry string - let's handle it prior to applying ops */ 215 char **arr = rxvt_strsplit (':', geom);
216
217 for (int i = 0; arr[i]; i++)
218 {
219 if (!strcasecmp (arr[i], "style=tiled"))
220 {
221 new_flags = BG_TILE;
222 w = h = noScale;
223 x = y = 0;
224 geom_flags = WidthValue|HeightValue|XValue|YValue;
225 }
226 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
227 {
228 new_flags = BG_KEEP_ASPECT;
229 w = h = windowScale;
230 x = y = centerAlign;
231 geom_flags = WidthValue|HeightValue|XValue|YValue;
232 }
233 else if (!strcasecmp (arr[i], "style=stretched"))
234 {
235 new_flags = 0;
236 w = h = windowScale;
237 geom_flags = WidthValue|HeightValue;
238 }
239 else if (!strcasecmp (arr[i], "style=centered"))
240 {
241 new_flags = 0;
242 w = h = noScale;
243 x = y = centerAlign;
244 geom_flags = WidthValue|HeightValue|XValue|YValue;
245 }
246 else if (!strcasecmp (arr[i], "style=root-tiled"))
247 {
248 new_flags = BG_TILE|BG_ROOT_ALIGN;
249 w = h = noScale;
250 geom_flags = WidthValue|HeightValue;
251 }
252 else if (!strcasecmp (arr[i], "op=tile"))
253 new_flags |= BG_TILE;
254 else if (!strcasecmp (arr[i], "op=keep-aspect"))
255 new_flags |= BG_KEEP_ASPECT;
256 else if (!strcasecmp (arr[i], "op=root-align"))
257 new_flags |= BG_ROOT_ALIGN;
258
259 // deprecated
260 else if (!strcasecmp (arr[i], "tile"))
261 {
262 new_flags |= BG_TILE;
263 w = h = noScale;
264 geom_flags |= WidthValue|HeightValue;
265 }
266 else if (!strcasecmp (arr[i], "propscale"))
267 {
268 new_flags |= BG_KEEP_ASPECT;
269 w = h = windowScale;
270 geom_flags |= WidthValue|HeightValue;
271 }
272 else if (!strcasecmp (arr[i], "hscale"))
273 {
274 new_flags |= BG_TILE;
275 w = windowScale;
276 h = noScale;
277 geom_flags |= WidthValue|HeightValue;
278 }
279 else if (!strcasecmp (arr[i], "vscale"))
280 {
281 new_flags |= BG_TILE;
282 h = windowScale;
283 w = noScale;
284 geom_flags |= WidthValue|HeightValue;
285 }
286 else if (!strcasecmp (arr[i], "scale"))
287 {
288 w = h = windowScale;
289 geom_flags |= WidthValue|HeightValue;
290 }
291 else if (!strcasecmp (arr[i], "auto"))
292 {
293 w = h = windowScale;
294 x = y = centerAlign;
295 geom_flags |= WidthValue|HeightValue|XValue|YValue;
296 }
297 else if (!strcasecmp (arr[i], "root"))
298 {
299 new_flags |= BG_TILE|BG_ROOT_ALIGN;
300 w = h = noScale;
301 geom_flags |= WidthValue|HeightValue;
302 }
303
304 else
234 geom_flags = XParseGeometry (str, &x, &y, &w, &h); 305 geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h);
235 } /* done parsing geometry string */ 306 } /* done parsing ops */
307
308 rxvt_free_strsplit (arr);
309 }
310
311 new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS;
236 312
237 if (!update) 313 if (!update)
238 { 314 {
239 if (!(geom_flags & XValue)) 315 if (!(geom_flags & XValue))
240 x = y = defaultAlign; 316 x = y = defaultAlign;
249 w = h; 325 w = h;
250 326
251 geom_flags |= WidthValue|HeightValue|XValue|YValue; 327 geom_flags |= WidthValue|HeightValue|XValue|YValue;
252 } 328 }
253 329
254 if (ops)
255 {
256 char **arr = rxvt_strsplit (':', ops + 1);
257
258 for (int i = 0; arr[i]; i++)
259 {
260 if (!strcasecmp (arr[i], "tile"))
261 {
262 new_flags |= BG_TILE;
263 w = h = noScale;
264 geom_flags |= WidthValue|HeightValue;
265 }
266 else if (!strcasecmp (arr[i], "propscale"))
267 {
268 new_flags |= BG_PROP_SCALE;
269 }
270 else if (!strcasecmp (arr[i], "scale"))
271 {
272 if (h == 0) h = windowScale;
273 if (w == 0) w = windowScale;
274
275 geom_flags |= WidthValue|HeightValue;
276 }
277 else if (!strcasecmp (arr[i], "center"))
278 {
279 w = h = noScale;
280 x = y = centerAlign;
281 geom_flags |= WidthValue|HeightValue|XValue|YValue;
282 }
283 else if (!strcasecmp (arr[i], "root"))
284 {
285 new_flags |= BG_TILE|BG_ROOT_ALIGN;
286 w = h = noScale;
287 geom_flags |= WidthValue|HeightValue;
288 }
289 } /* done parsing ops */
290
291 rxvt_free_strsplit (arr);
292 }
293
294 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; 330 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
295 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; 331 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
296 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; 332 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
297 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; 333 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
298 334
309rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 345rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
310{ 346{
311 int target_width = szHint.width; 347 int target_width = szHint.width;
312 int target_height = szHint.height; 348 int target_height = szHint.height;
313 349
350 w = h_scale * target_width / 100;
351 h = v_scale * target_height / 100;
352
314 if (bg_flags & BG_PROP_SCALE) 353 if (bg_flags & BG_KEEP_ASPECT)
315 { 354 {
316 float scale = (float)target_width / image_width; 355 float scale = (float)w / image_width;
317 min_it (scale, (float)target_height / image_height); 356 min_it (scale, (float)h / image_height);
318 w = image_width * scale + 0.5; 357 w = image_width * scale + 0.5;
319 h = image_height * scale + 0.5; 358 h = image_height * scale + 0.5;
320 } 359 }
321 else
322 {
323 w = h_scale * target_width / 100;
324 h = v_scale * target_height / 100;
325 }
326 360
327 if (!w) w = image_width; 361 if (!w) w = image_width;
328 if (!h) h = image_height; 362 if (!h) h = image_height;
329 363
330 if (bg_flags & BG_ROOT_ALIGN) 364 if (bg_flags & BG_ROOT_ALIGN)
338 y = make_align_position (v_align, target_height, h); 372 y = make_align_position (v_align, target_height, h);
339 } 373 }
340 374
341 bg_flags &= ~BG_IS_SIZE_SENSITIVE; 375 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
342 if (!(bg_flags & BG_TILE) 376 if (!(bg_flags & BG_TILE)
343 || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale 377 || h_scale || v_scale
344 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) 378 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
345 || w > target_width || h > target_height) 379 || w > target_width || h > target_height)
346 bg_flags |= BG_IS_SIZE_SENSITIVE; 380 bg_flags |= BG_IS_SIZE_SENSITIVE;
347} 381}
348 382
375 } 409 }
376 410
377 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) 411 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL)
378 { 412 {
379 ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 413 ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
380 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, 414 ASA_XImage,
381 100, ASIMAGE_QUALITY_DEFAULT); 415 100, ASIMAGE_QUALITY_DEFAULT);
382 if (tmp) 416 if (tmp)
383 { 417 {
384 destroy_asimage (&background); 418 destroy_asimage (&background);
385 background = tmp; 419 background = tmp;
404 438
405 if (!original_asim 439 if (!original_asim
406 || (!(bg_flags & BG_ROOT_ALIGN) 440 || (!(bg_flags & BG_ROOT_ALIGN)
407 && (x >= target_width 441 && (x >= target_width
408 || y >= target_height 442 || y >= target_height
409 || (x + w <= 0) 443 || x + w <= 0
410 || (y + h <= 0)))) 444 || y + h <= 0)))
411 { 445 {
412 if (background) 446 if (background)
413 { 447 {
414 new_pmap_width = background->width; 448 new_pmap_width = background->width;
415 new_pmap_height = background->height; 449 new_pmap_height = background->height;
429 } 463 }
430 else 464 else
431 { 465 {
432 result = original_asim; 466 result = original_asim;
433 467
434 if ((w != original_asim->width) 468 if (w != original_asim->width
435 || (h != original_asim->height)) 469 || h != original_asim->height)
436 { 470 {
437 result = scale_asimage (asv, original_asim, 471 result = scale_asimage (asv, original_asim,
438 w, h, 472 w, h,
439 background ? ASA_ASImage : ASA_XImage, 473 ASA_XImage,
440 100, ASIMAGE_QUALITY_DEFAULT); 474 100, ASIMAGE_QUALITY_DEFAULT);
441 } 475 }
442 476
443 if (background == NULL) 477 if (background == NULL)
444 { 478 {
694 get_image_geometry (image_width, image_height, w, h, x, y); 728 get_image_geometry (image_width, image_height, w, h, x, y);
695 729
696 if (!(bg_flags & BG_ROOT_ALIGN) 730 if (!(bg_flags & BG_ROOT_ALIGN)
697 && (x >= target_width 731 && (x >= target_width
698 || y >= target_height 732 || y >= target_height
699 || (x + w <= 0) 733 || x + w <= 0
700 || (y + h <= 0))) 734 || y + h <= 0))
701 return false; 735 return false;
702 736
703 result = pixbuf; 737 result = pixbuf;
704 738
705 if ((w != image_width) 739 if (w != image_width
706 || (h != image_height)) 740 || h != image_height)
707 { 741 {
708 result = gdk_pixbuf_scale_simple (pixbuf, 742 result = gdk_pixbuf_scale_simple (pixbuf,
709 w, h, 743 w, h,
710 GDK_INTERP_BILINEAR); 744 GDK_INTERP_BILINEAR);
711 } 745 }
790 } 824 }
791 825
792#if XRENDER 826#if XRENDER
793 if (tr_flags) 827 if (tr_flags)
794 { 828 {
795 XRenderPictureAttributes pa;
796
797 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); 829 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
830
798 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 831 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0);
799 832
800 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
801 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); 833 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
802 834
803 pa.repeat = True; 835 Picture mask = create_xrender_mask (dpy, vt, False, False);
804 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
805 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
806 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
807 XFreePixmap (dpy, mask_pmap);
808 836
809 XRenderColor mask_c; 837 XRenderColor mask_c;
810 838
811 mask_c.alpha = 0x8000; 839 mask_c.alpha = 0x8000;
812 mask_c.red = 0; 840 mask_c.red =
813 mask_c.green = 0; 841 mask_c.green =
814 mask_c.blue = 0; 842 mask_c.blue = 0;
815 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 843 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
844
816 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); 845 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height);
817 846
818 XRenderFreePicture (dpy, src); 847 XRenderFreePicture (dpy, src);
819 XRenderFreePicture (dpy, dst); 848 XRenderFreePicture (dpy, dst);
820 XRenderFreePicture (dpy, mask); 849 XRenderFreePicture (dpy, mask);
840rxvt_term::bg_set_file (const char *file) 869rxvt_term::bg_set_file (const char *file)
841{ 870{
842 if (!file || !*file) 871 if (!file || !*file)
843 return false; 872 return false;
844 873
874 bool ret = false;
845 if (const char *p = strchr (file, ';')) 875 const char *p = strchr (file, ';');
876
877 if (p)
846 { 878 {
847 size_t len = p - file; 879 size_t len = p - file;
848 char *f = rxvt_temp_buf<char> (len + 1); 880 char *f = rxvt_temp_buf<char> (len + 1);
849 memcpy (f, file, len); 881 memcpy (f, file, len);
850 f[len] = '\0'; 882 f[len] = '\0';
859 { 891 {
860 if (original_asim) 892 if (original_asim)
861 safe_asimage_destroy (original_asim); 893 safe_asimage_destroy (original_asim);
862 original_asim = image; 894 original_asim = image;
863 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; 895 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER;
864 return true; 896 ret = true;
865 } 897 }
866# endif 898# endif
867 899
868# ifdef HAVE_PIXBUF 900# ifdef HAVE_PIXBUF
869 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 901 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
871 { 903 {
872 if (pixbuf) 904 if (pixbuf)
873 g_object_unref (pixbuf); 905 g_object_unref (pixbuf);
874 pixbuf = image; 906 pixbuf = image;
875 bg_flags |= BG_IS_FROM_FILE; 907 bg_flags |= BG_IS_FROM_FILE;
876 return true; 908 ret = true;
877 } 909 }
878# endif 910# endif
879 911
912 if (ret)
913 {
914 if (p)
915 bg_set_geometry (p + 1);
916 else
917 bg_set_default_geometry ();
918 }
919
880 return false; 920 return ret;
881} 921}
882 922
883# endif /* BG_IMAGE_FROM_FILE */ 923# endif /* BG_IMAGE_FROM_FILE */
884 924
885# ifdef ENABLE_TRANSPARENCY 925# ifdef ENABLE_TRANSPARENCY
921 { 961 {
922 changed = true; 962 changed = true;
923 v_blurRadius = vr; 963 v_blurRadius = vr;
924 } 964 }
925 965
926 if (v_blurRadius == 0 && h_blurRadius == 0) 966 if (h_blurRadius == 0 || v_blurRadius == 0)
927 bg_flags &= ~BG_NEEDS_BLUR; 967 bg_flags &= ~BG_NEEDS_BLUR;
928 else 968 else
929 bg_flags |= BG_NEEDS_BLUR; 969 bg_flags |= BG_NEEDS_BLUR;
930 970
931 return changed; 971 return changed;
932} 972}
933 973
934void 974void
935rxvt_term::set_tint_shade_flags () 975rxvt_term::set_tint_shade_flags ()
936{ 976{
937 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 977 rgba c;
938 bool has_shade = shade != 100; 978 bool has_shade = shade != 100;
939 979
940 bg_flags &= ~BG_TINT_FLAGS; 980 bg_flags &= ~BG_TINT_FLAGS;
941 981
942 if (bg_flags & BG_TINT_SET) 982 if (bg_flags & BG_TINT_SET)
968} 1008}
969 1009
970bool 1010bool
971rxvt_term::bg_set_shade (const char *shade_str) 1011rxvt_term::bg_set_shade (const char *shade_str)
972{ 1012{
973 int new_shade = (shade_str) ? atoi (shade_str) : 100; 1013 int new_shade = atoi (shade_str);
974 1014
975 clamp_it (new_shade, -100, 200); 1015 clamp_it (new_shade, -100, 200);
976 if (new_shade < 0) 1016 if (new_shade < 0)
977 new_shade = 200 - (100 + new_shade); 1017 new_shade = 200 - (100 + new_shade);
978 1018
1008 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1048 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1009} 1049}
1010#endif 1050#endif
1011 1051
1012bool 1052bool
1013rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1053rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth)
1014{ 1054{
1015 bool ret = false; 1055 bool ret = false;
1016#if XRENDER 1056#if XRENDER
1057 if (!(bg_flags & BG_HAS_RENDER_CONV))
1058 return false;
1059
1017 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1060 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1018 double *kernel = (double *)malloc (size * sizeof (double)); 1061 double *kernel = (double *)malloc (size * sizeof (double));
1019 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1062 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1020 1063
1021 XRenderPictureAttributes pa; 1064 XRenderPictureAttributes pa;
1022 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1065 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1023 1066
1067 pa.repeat = RepeatPad;
1024 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1068 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
1069 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth);
1025 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1070 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
1071 XFreePixmap (dpy, tmp);
1026 1072
1027 if (kernel && params) 1073 if (kernel && params)
1028 { 1074 {
1029 if (h_blurRadius)
1030 {
1031 size = h_blurRadius * 2 + 1; 1075 size = h_blurRadius * 2 + 1;
1032 get_gaussian_kernel (h_blurRadius, size, kernel, params); 1076 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1033 1077
1034 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1078 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1035 XRenderComposite (dpy, 1079 XRenderComposite (dpy,
1036 PictOpSrc, 1080 PictOpSrc,
1037 src, 1081 src,
1038 None, 1082 None,
1039 dst, 1083 dst,
1040 0, 0, 1084 0, 0,
1041 0, 0, 1085 0, 0,
1042 0, 0, 1086 0, 0,
1043 width, height); 1087 width, height);
1044 }
1045 1088
1046 if (v_blurRadius) 1089 ::swap (src, dst);
1047 { 1090
1048 size = v_blurRadius * 2 + 1; 1091 size = v_blurRadius * 2 + 1;
1049 get_gaussian_kernel (v_blurRadius, size, kernel, params); 1092 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1050 ::swap (params[0], params[1]); 1093 ::swap (params[0], params[1]);
1051 1094
1052 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1095 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1053 XRenderComposite (dpy, 1096 XRenderComposite (dpy,
1054 PictOpSrc, 1097 PictOpSrc,
1055 src, 1098 src,
1056 None, 1099 None,
1057 dst, 1100 dst,
1058 0, 0, 1101 0, 0,
1059 0, 0, 1102 0, 0,
1060 0, 0, 1103 0, 0,
1061 width, height); 1104 width, height);
1062 }
1063 1105
1064 ret = true; 1106 ret = true;
1065 } 1107 }
1066 1108
1067 free (kernel); 1109 free (kernel);
1094 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); 1136 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1095 ret = true; 1137 ret = true;
1096 XFreeGC (dpy, gc); 1138 XFreeGC (dpy, gc);
1097 } 1139 }
1098 } 1140 }
1099 else
1100 {
1101# if XRENDER 1141# if XRENDER
1142 else if (bg_flags & BG_HAS_RENDER)
1143 {
1102 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1144 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1103 1145
1104 if (bg_flags & BG_TINT_SET) 1146 if (bg_flags & BG_TINT_SET)
1105 tint.get (c); 1147 tint.get (c);
1106 1148
1115 c.r = c.r * (200 - shade) / 100; 1157 c.r = c.r * (200 - shade) / 100;
1116 c.g = c.g * (200 - shade) / 100; 1158 c.g = c.g * (200 - shade) / 100;
1117 c.b = c.b * (200 - shade) / 100; 1159 c.b = c.b * (200 - shade) / 100;
1118 } 1160 }
1119 1161
1120 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1121 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1162 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1122 XRenderPictureAttributes pa;
1123 1163
1124 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1164 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1125 1165
1126 pa.repeat = True; 1166 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
1127 1167
1128 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1168 Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True);
1129 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1130 XFreePixmap (dpy, overlay_pmap);
1131
1132 pa.component_alpha = True;
1133 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1134 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1135 XFreePixmap (dpy, mask_pmap);
1136 1169
1137 XRenderColor mask_c; 1170 XRenderColor mask_c;
1138 1171
1139 mask_c.alpha = 0xffff; 1172 mask_c.alpha = 0xffff;
1140 mask_c.red = 1173 mask_c.red =
1145 mask_c.alpha = 0; 1178 mask_c.alpha = 0;
1146 mask_c.red = 0xffff - c.r; 1179 mask_c.red = 0xffff - c.r;
1147 mask_c.green = 0xffff - c.g; 1180 mask_c.green = 0xffff - c.g;
1148 mask_c.blue = 0xffff - c.b; 1181 mask_c.blue = 0xffff - c.b;
1149 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1182 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1183
1150 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1184 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1151 1185
1152 if (shade > 100) 1186 if (shade > 100)
1153 { 1187 {
1154 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1155 mask_c.alpha = 0; 1188 mask_c.alpha = 0;
1189 mask_c.red =
1190 mask_c.green =
1191 mask_c.blue = 0xffff * (shade - 100) / 100;
1156 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1192 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1157 1193
1158 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1194 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1159 } 1195 }
1160 1196
1161 ret = true; 1197 ret = true;
1162 1198
1163 XRenderFreePicture (dpy, mask_pic); 1199 XRenderFreePicture (dpy, mask_pic);
1164 XRenderFreePicture (dpy, overlay_pic); 1200 XRenderFreePicture (dpy, overlay_pic);
1165 XRenderFreePicture (dpy, back_pic); 1201 XRenderFreePicture (dpy, back_pic);
1202 }
1166# endif 1203# endif
1167 }
1168 1204
1169 return ret; 1205 return ret;
1170} 1206}
1171 1207
1172/* 1208/*
1223#if XRENDER 1259#if XRENDER
1224 if (bg_flags & BG_HAS_RENDER) 1260 if (bg_flags & BG_HAS_RENDER)
1225 { 1261 {
1226 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); 1262 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1227 1263
1228 XRenderPictureAttributes pa;
1229
1230 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1264 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1231 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1265 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1232 1266
1233 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 1267 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1234 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1268 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, 0);
1235 1269
1236 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); 1270 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1237 1271
1238 XRenderFreePicture (dpy, src); 1272 XRenderFreePicture (dpy, src);
1239 XRenderFreePicture (dpy, dst); 1273 XRenderFreePicture (dpy, dst);
1256 bg_pmap_width = window_width; 1290 bg_pmap_width = window_width;
1257 bg_pmap_height = window_height; 1291 bg_pmap_height = window_height;
1258 } 1292 }
1259 1293
1260 /* straightforward pixmap copy */ 1294 /* straightforward pixmap copy */
1261 while (sx < 0) sx += root_width; 1295 while (sx < 0) sx += root_pmap_width;
1262 while (sy < 0) sy += root_height; 1296 while (sy < 0) sy += root_pmap_height;
1263 1297
1264 gcv.tile = recoded_root_pmap; 1298 gcv.tile = recoded_root_pmap;
1265 gcv.fill_style = FillTiled; 1299 gcv.fill_style = FillTiled;
1266 gcv.ts_x_origin = -sx; 1300 gcv.ts_x_origin = -sx;
1267 gcv.ts_y_origin = -sy; 1301 gcv.ts_y_origin = -sy;
1269 1303
1270 if (gc) 1304 if (gc)
1271 { 1305 {
1272 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1306 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1273 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1307 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1274 XFreeGC (dpy, gc);
1275 1308
1276 if (!(bg_flags & BG_CLIENT_RENDER)) 1309 if (!(bg_flags & BG_CLIENT_RENDER))
1277 { 1310 {
1278 if ((bg_flags & BG_NEEDS_BLUR) 1311 if (bg_flags & BG_NEEDS_BLUR)
1279 && (bg_flags & BG_HAS_RENDER_CONV))
1280 { 1312 {
1281 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1313 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth))
1282 result &= ~BG_NEEDS_BLUR; 1314 result &= ~BG_NEEDS_BLUR;
1283 } 1315 }
1284 if ((bg_flags & BG_NEEDS_TINT) 1316 if (bg_flags & BG_NEEDS_TINT)
1285 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1286 { 1317 {
1287 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1318 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1288 result &= ~BG_NEEDS_TINT; 1319 result &= ~BG_NEEDS_TINT;
1289 } 1320 }
1321# ifndef HAVE_AFTERIMAGE
1322 if (result & BG_NEEDS_TINT)
1323 {
1324 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1325 if (ximage)
1326 {
1327 /* our own client-side tinting */
1328 tint_ximage (DefaultVisual (dpy, display->screen), ximage);
1329
1330 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1331 XDestroyImage (ximage);
1332 }
1333 }
1334# endif
1290 } /* server side rendering completed */ 1335 } /* server side rendering completed */
1336
1337 XFreeGC (dpy, gc);
1291 } 1338 }
1292 1339
1293 if (recoded_root_pmap != root_pixmap) 1340 if (recoded_root_pmap != root_pixmap)
1294 XFreePixmap (dpy, recoded_root_pmap); 1341 XFreePixmap (dpy, recoded_root_pmap);
1295 1342
1304 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); 1351 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1305 1352
1306 root_pixmap = new_root_pixmap; 1353 root_pixmap = new_root_pixmap;
1307} 1354}
1308# endif /* ENABLE_TRANSPARENCY */ 1355# endif /* ENABLE_TRANSPARENCY */
1309
1310#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1311static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1312# endif
1313 1356
1314bool 1357bool
1315rxvt_term::bg_render () 1358rxvt_term::bg_render ()
1316{ 1359{
1317 unsigned long tr_flags = 0; 1360 unsigned long tr_flags = 0;
1322 { 1365 {
1323 /* we need to re-generate transparency pixmap in that case ! */ 1366 /* we need to re-generate transparency pixmap in that case ! */
1324 tr_flags = make_transparency_pixmap (); 1367 tr_flags = make_transparency_pixmap ();
1325 if (tr_flags == 0) 1368 if (tr_flags == 0)
1326 return false; 1369 return false;
1327 else if (!(tr_flags & BG_EFFECTS_FLAGS))
1328 bg_flags |= BG_IS_VALID; 1370 bg_flags |= BG_IS_VALID;
1329 } 1371 }
1330# endif 1372# endif
1331 1373
1332# ifdef BG_IMAGE_FROM_FILE 1374# ifdef BG_IMAGE_FROM_FILE
1333 if ((bg_flags & BG_IS_FROM_FILE) 1375 if ((bg_flags & BG_IS_FROM_FILE)
1334 || (tr_flags & BG_EFFECTS_FLAGS)) 1376 || (tr_flags & BG_EFFECTS_FLAGS))
1335 { 1377 {
1336 if (render_image (tr_flags)) 1378 if (render_image (tr_flags))
1337 bg_flags |= BG_IS_VALID; 1379 bg_flags |= BG_IS_VALID;
1338 }
1339# endif
1340
1341# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1342 XImage *result = NULL;
1343
1344 if (tr_flags && !(bg_flags & BG_IS_VALID))
1345 {
1346 result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1347 }
1348
1349 if (result)
1350 {
1351 /* our own client-side tinting */
1352 if (tr_flags & BG_NEEDS_TINT)
1353 {
1354 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1355 if (bg_flags & BG_TINT_SET)
1356 tint.get (c);
1357 shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c);
1358 }
1359
1360 GC gc = XCreateGC (dpy, vt, 0UL, NULL);
1361
1362 if (gc)
1363 {
1364 XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1365
1366 XFreeGC (dpy, gc);
1367 bg_flags |= BG_IS_VALID;
1368 }
1369
1370 XDestroyImage (result);
1371 } 1380 }
1372# endif 1381# endif
1373 1382
1374 if (!(bg_flags & BG_IS_VALID)) 1383 if (!(bg_flags & BG_IS_VALID))
1375 { 1384 {
1413} 1422}
1414 1423
1415#endif /* HAVE_BG_PIXMAP */ 1424#endif /* HAVE_BG_PIXMAP */
1416 1425
1417#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1426#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1418/* taken from aterm-0.4.2 */ 1427/* based on code from aterm-0.4.2 */
1419 1428
1420static void 1429static inline void
1421shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) 1430fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1431{
1432 for (int i = 0; i <= mask >> sh; i++)
1433 {
1434 uint32_t tmp;
1435 tmp = i * high;
1436 tmp += (mask >> sh) * low;
1437 lookup[i] = (tmp / 0xffff) << sh;
1438 }
1439}
1440
1441void
1442rxvt_term::tint_ximage (Visual *visual, XImage *ximage)
1422{ 1443{
1423 int sh_r, sh_g, sh_b; 1444 int sh_r, sh_g, sh_b;
1424 uint32_t mask_r, mask_g, mask_b; 1445 uint32_t mask_r, mask_g, mask_b;
1425 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1446 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1426 rgba low; 1447 unsigned short low;
1427 rgba high;
1428 int i;
1429 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 1448 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1430 1449
1431 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1450 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1432 1451
1433 /* for convenience */ 1452 /* for convenience */
1492 break; 1511 break;
1493 default: 1512 default:
1494 return; /* we do not support this color depth */ 1513 return; /* we do not support this color depth */
1495 } 1514 }
1496 1515
1516 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1517
1518 if (bg_flags & BG_TINT_SET)
1519 tint.get (c);
1520
1497 /* prepare limits for color transformation (each channel is handled separately) */ 1521 /* prepare limits for color transformation (each channel is handled separately) */
1498 if (shade > 100) 1522 if (shade > 100)
1499 { 1523 {
1500 shade = 200 - shade;
1501
1502 high.r = c.r * shade / 100;
1503 high.g = c.g * shade / 100;
1504 high.b = c.b * shade / 100;
1505
1506 low.r = 65535 * (100 - shade) / 100; 1524 c.r = c.r * (200 - shade) / 100;
1507 low.g = 65535 * (100 - shade) / 100; 1525 c.g = c.g * (200 - shade) / 100;
1508 low.b = 65535 * (100 - shade) / 100; 1526 c.b = c.b * (200 - shade) / 100;
1527
1528 low = 0xffff * (shade - 100) / 100;
1509 } 1529 }
1510 else 1530 else
1511 { 1531 {
1512 high.r = c.r * shade / 100; 1532 c.r = c.r * shade / 100;
1513 high.g = c.g * shade / 100; 1533 c.g = c.g * shade / 100;
1514 high.b = c.b * shade / 100; 1534 c.b = c.b * shade / 100;
1515 1535
1516 low.r = low.g = low.b = 0; 1536 low = 0;
1517 } 1537 }
1518 1538
1519 /* fill our lookup tables */ 1539 /* fill our lookup tables */
1520 for (i = 0; i <= mask_r>>sh_r; i++) 1540 fill_lut (lookup_r, mask_r, sh_r, low, c.r);
1521 { 1541 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1522 uint32_t tmp; 1542 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1523 tmp = i * high.r;
1524 tmp += (mask_r>>sh_r) * low.r;
1525 lookup_r[i] = (tmp/65535)<<sh_r;
1526 }
1527 for (i = 0; i <= mask_g>>sh_g; i++)
1528 {
1529 uint32_t tmp;
1530 tmp = i * high.g;
1531 tmp += (mask_g>>sh_g) * low.g;
1532 lookup_g[i] = (tmp/65535)<<sh_g;
1533 }
1534 for (i = 0; i <= mask_b>>sh_b; i++)
1535 {
1536 uint32_t tmp;
1537 tmp = i * high.b;
1538 tmp += (mask_b>>sh_b) * low.b;
1539 lookup_b[i] = (tmp/65535)<<sh_b;
1540 }
1541 1543
1542 /* apply table to input image (replacing colors by newly calculated ones) */ 1544 /* apply table to input image (replacing colors by newly calculated ones) */
1543 if (ximage->bits_per_pixel == 32 1545 if (ximage->bits_per_pixel == 32
1544 && (ximage->depth == 24 || ximage->depth == 32) 1546 && (ximage->depth == 24 || ximage->depth == 32)
1545 && ximage->byte_order == host_byte_order) 1547 && ximage->byte_order == host_byte_order)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines