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.158 by sf-exg, Wed Aug 10 07:28:36 2011 UTC vs.
Revision 1.191 by sf-exg, Fri Dec 30 11:22:48 2011 UTC

32 32
33#ifndef FilterConvolution 33#ifndef FilterConvolution
34#define FilterConvolution "convolution" 34#define FilterConvolution "convolution"
35#endif 35#endif
36 36
37/*
38 * Pixmap geometry string interpretation :
39 * Each geometry string contains zero or one scale/position
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
60#ifdef HAVE_BG_PIXMAP 37#ifdef HAVE_BG_PIXMAP
38# if XRENDER
39static Picture
40create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha)
41{
42 Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8);
43
44 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8);
45 XRenderPictureAttributes pa;
46 pa.repeat = True;
47 pa.component_alpha = component_alpha;
48 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa);
49
50 XFreePixmap (dpy, pixmap);
51
52 return mask;
53}
54# endif
55
61void 56void
62rxvt_term::bg_destroy () 57rxvt_term::bg_destroy ()
63{ 58{
64#ifdef HAVE_AFTERIMAGE 59#ifdef HAVE_AFTERIMAGE
65 if (original_asim) 60 if (original_asim)
173 int smaller = min (image_size, window_size); 168 int smaller = min (image_size, window_size);
174 169
175 if (align >= 0 && align <= 100) 170 if (align >= 0 && align <= 100)
176 return diff * align / 100; 171 return diff * align / 100;
177 else if (align > 100 && align <= 200) 172 else if (align > 100 && align <= 200)
178 return ((align - 100) * smaller / 100) + window_size - smaller; 173 return (align - 100) * smaller / 100 + window_size - smaller;
179 else if (align >= -100 && align < 0) 174 else if (align >= -100 && align < 0)
180 return ((align + 100) * smaller / 100) - image_size; 175 return (align + 100) * smaller / 100 - image_size;
181 return 0; 176 return 0;
182} 177}
183 178
184static inline int 179static inline int
185make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 180make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
204{ 199{
205 bool changed = false; 200 bool changed = false;
206 int geom_flags = 0; 201 int geom_flags = 0;
207 int x = 0, y = 0; 202 int x = 0, y = 0;
208 unsigned int w = 0, h = 0; 203 unsigned int w = 0, h = 0;
209 unsigned int n; 204 unsigned long new_flags = 0;
210 unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS));
211 const char *ops;
212 205
213 if (geom == NULL) 206 if (geom == NULL)
214 return false; 207 return false;
215 208
216 char str[256]; 209 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 { 210 {
233 /* we have geometry string - let's handle it prior to applying ops */ 211 char **arr = rxvt_strsplit (':', geom);
212
213 for (int i = 0; arr[i]; i++)
214 {
215 if (!strcasecmp (arr[i], "style=tiled"))
216 {
217 new_flags = BG_TILE;
218 w = h = noScale;
219 x = y = 0;
220 geom_flags = WidthValue|HeightValue|XValue|YValue;
221 }
222 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
223 {
224 new_flags = BG_KEEP_ASPECT;
225 w = h = windowScale;
226 x = y = centerAlign;
227 geom_flags = WidthValue|HeightValue|XValue|YValue;
228 }
229 else if (!strcasecmp (arr[i], "style=stretched"))
230 {
231 new_flags = 0;
232 w = h = windowScale;
233 geom_flags = WidthValue|HeightValue;
234 }
235 else if (!strcasecmp (arr[i], "style=centered"))
236 {
237 new_flags = 0;
238 w = h = noScale;
239 x = y = centerAlign;
240 geom_flags = WidthValue|HeightValue|XValue|YValue;
241 }
242 else if (!strcasecmp (arr[i], "style=root-tiled"))
243 {
244 new_flags = BG_TILE|BG_ROOT_ALIGN;
245 w = h = noScale;
246 geom_flags = WidthValue|HeightValue;
247 }
248 else if (!strcasecmp (arr[i], "op=tile"))
249 new_flags |= BG_TILE;
250 else if (!strcasecmp (arr[i], "op=keep-aspect"))
251 new_flags |= BG_KEEP_ASPECT;
252 else if (!strcasecmp (arr[i], "op=root-align"))
253 new_flags |= BG_ROOT_ALIGN;
254
255 // deprecated
256 else if (!strcasecmp (arr[i], "tile"))
257 {
258 new_flags |= BG_TILE;
259 w = h = noScale;
260 geom_flags |= WidthValue|HeightValue;
261 }
262 else if (!strcasecmp (arr[i], "propscale"))
263 {
264 new_flags |= BG_KEEP_ASPECT;
265 w = h = windowScale;
266 geom_flags |= WidthValue|HeightValue;
267 }
268 else if (!strcasecmp (arr[i], "hscale"))
269 {
270 new_flags |= BG_TILE;
271 w = windowScale;
272 h = noScale;
273 geom_flags |= WidthValue|HeightValue;
274 }
275 else if (!strcasecmp (arr[i], "vscale"))
276 {
277 new_flags |= BG_TILE;
278 h = windowScale;
279 w = noScale;
280 geom_flags |= WidthValue|HeightValue;
281 }
282 else if (!strcasecmp (arr[i], "scale"))
283 {
284 w = h = windowScale;
285 geom_flags |= WidthValue|HeightValue;
286 }
287 else if (!strcasecmp (arr[i], "auto"))
288 {
289 w = h = windowScale;
290 x = y = centerAlign;
291 geom_flags |= WidthValue|HeightValue|XValue|YValue;
292 }
293 else if (!strcasecmp (arr[i], "root"))
294 {
295 new_flags |= BG_TILE|BG_ROOT_ALIGN;
296 w = h = noScale;
297 geom_flags |= WidthValue|HeightValue;
298 }
299
300 else
234 geom_flags = XParseGeometry (str, &x, &y, &w, &h); 301 geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h);
235 } /* done parsing geometry string */ 302 } /* done parsing ops */
303
304 rxvt_free_strsplit (arr);
305 }
306
307 new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS;
236 308
237 if (!update) 309 if (!update)
238 { 310 {
239 if (!(geom_flags & XValue)) 311 if (!(geom_flags & XValue))
240 x = y = defaultAlign; 312 x = y = defaultAlign;
249 w = h; 321 w = h;
250 322
251 geom_flags |= WidthValue|HeightValue|XValue|YValue; 323 geom_flags |= WidthValue|HeightValue|XValue|YValue;
252 } 324 }
253 325
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], "root"))
278 {
279 new_flags |= BG_TILE|BG_ROOT_ALIGN;
280 w = h = noScale;
281 geom_flags |= WidthValue|HeightValue;
282 }
283 } /* done parsing ops */
284
285 rxvt_free_strsplit (arr);
286 }
287
288 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; 326 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
289 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; 327 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
290 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; 328 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
291 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; 329 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
292 330
303rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 341rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
304{ 342{
305 int target_width = szHint.width; 343 int target_width = szHint.width;
306 int target_height = szHint.height; 344 int target_height = szHint.height;
307 345
346 w = h_scale * target_width / 100;
347 h = v_scale * target_height / 100;
348
308 if (bg_flags & BG_PROP_SCALE) 349 if (bg_flags & BG_KEEP_ASPECT)
309 { 350 {
310 float scale = (float)target_width / image_width; 351 float scale = (float)w / image_width;
311 min_it (scale, (float)target_height / image_height); 352 min_it (scale, (float)h / image_height);
312 w = image_width * scale + 0.5; 353 w = image_width * scale + 0.5;
313 h = image_height * scale + 0.5; 354 h = image_height * scale + 0.5;
314 } 355 }
315 else
316 {
317 w = h_scale * target_width / 100;
318 h = v_scale * target_height / 100;
319 }
320 356
321 if (!w) w = image_width; 357 if (!w) w = image_width;
322 if (!h) h = image_height; 358 if (!h) h = image_height;
323 359
324 if (bg_flags & BG_ROOT_ALIGN) 360 if (bg_flags & BG_ROOT_ALIGN)
332 y = make_align_position (v_align, target_height, h); 368 y = make_align_position (v_align, target_height, h);
333 } 369 }
334 370
335 bg_flags &= ~BG_IS_SIZE_SENSITIVE; 371 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
336 if (!(bg_flags & BG_TILE) 372 if (!(bg_flags & BG_TILE)
337 || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale 373 || h_scale || v_scale
338 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) 374 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
339 || w > target_width || h > target_height) 375 || w > target_width || h > target_height)
340 bg_flags |= BG_IS_SIZE_SENSITIVE; 376 bg_flags |= BG_IS_SIZE_SENSITIVE;
341} 377}
342 378
356 if (tr_flags & BG_NEEDS_TINT) 392 if (tr_flags & BG_NEEDS_TINT)
357 { 393 {
358 ShadingInfo as_shade; 394 ShadingInfo as_shade;
359 as_shade.shading = shade; 395 as_shade.shading = shade;
360 396
361 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 397 rgba c;
362 if (bg_flags & BG_TINT_SET)
363 tint.get (c); 398 tint.get (c);
364 as_shade.tintColor.red = c.r; 399 as_shade.tintColor.red = c.r;
365 as_shade.tintColor.green = c.g; 400 as_shade.tintColor.green = c.g;
366 as_shade.tintColor.blue = c.b; 401 as_shade.tintColor.blue = c.b;
367 402
368 background_tint = shading2tint32 (&as_shade); 403 background_tint = shading2tint32 (&as_shade);
369 } 404 }
370 405
371 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) 406 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL)
372 { 407 {
373 ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 408 ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
374 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, 409 ASA_XImage,
375 100, ASIMAGE_QUALITY_DEFAULT); 410 100, ASIMAGE_QUALITY_DEFAULT);
376 if (tmp) 411 if (tmp)
377 { 412 {
378 destroy_asimage (&background); 413 destroy_asimage (&background);
379 background = tmp; 414 background = tmp;
398 433
399 if (!original_asim 434 if (!original_asim
400 || (!(bg_flags & BG_ROOT_ALIGN) 435 || (!(bg_flags & BG_ROOT_ALIGN)
401 && (x >= target_width 436 && (x >= target_width
402 || y >= target_height 437 || y >= target_height
403 || (x + w <= 0) 438 || x + w <= 0
404 || (y + h <= 0)))) 439 || y + h <= 0)))
405 { 440 {
406 if (background) 441 if (background)
407 { 442 {
408 new_pmap_width = background->width; 443 new_pmap_width = background->width;
409 new_pmap_height = background->height; 444 new_pmap_height = background->height;
423 } 458 }
424 else 459 else
425 { 460 {
426 result = original_asim; 461 result = original_asim;
427 462
428 if ((w != original_asim->width) 463 if (w != original_asim->width
429 || (h != original_asim->height)) 464 || h != original_asim->height)
430 { 465 {
431 result = scale_asimage (asv, original_asim, 466 result = scale_asimage (asv, original_asim,
432 w, h, 467 w, h,
433 background ? ASA_ASImage : ASA_XImage, 468 ASA_XImage,
434 100, ASIMAGE_QUALITY_DEFAULT); 469 100, ASIMAGE_QUALITY_DEFAULT);
435 } 470 }
436 471
437 if (background == NULL) 472 if (background == NULL)
438 { 473 {
688 get_image_geometry (image_width, image_height, w, h, x, y); 723 get_image_geometry (image_width, image_height, w, h, x, y);
689 724
690 if (!(bg_flags & BG_ROOT_ALIGN) 725 if (!(bg_flags & BG_ROOT_ALIGN)
691 && (x >= target_width 726 && (x >= target_width
692 || y >= target_height 727 || y >= target_height
693 || (x + w <= 0) 728 || x + w <= 0
694 || (y + h <= 0))) 729 || y + h <= 0))
695 return false; 730 return false;
696 731
697 result = pixbuf; 732 result = pixbuf;
698 733
699 if ((w != image_width) 734 if (w != image_width
700 || (h != image_height)) 735 || h != image_height)
701 { 736 {
702 result = gdk_pixbuf_scale_simple (pixbuf, 737 result = gdk_pixbuf_scale_simple (pixbuf,
703 w, h, 738 w, h,
704 GDK_INTERP_BILINEAR); 739 GDK_INTERP_BILINEAR);
705 } 740 }
784 } 819 }
785 820
786#if XRENDER 821#if XRENDER
787 if (tr_flags) 822 if (tr_flags)
788 { 823 {
789 XRenderPictureAttributes pa;
790
791 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); 824 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
825
792 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 826 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0);
793 827
794 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
795 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); 828 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
796 829
797 pa.repeat = True; 830 Picture mask = create_xrender_mask (dpy, vt, False, False);
798 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
799 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
800 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
801 XFreePixmap (dpy, mask_pmap);
802 831
803 XRenderColor mask_c; 832 XRenderColor mask_c;
804 833
805 mask_c.alpha = 0x8000; 834 mask_c.alpha = 0x8000;
806 mask_c.red = 0; 835 mask_c.red = 0;
834rxvt_term::bg_set_file (const char *file) 863rxvt_term::bg_set_file (const char *file)
835{ 864{
836 if (!file || !*file) 865 if (!file || !*file)
837 return false; 866 return false;
838 867
868 bool ret = false;
839 if (const char *p = strchr (file, ';')) 869 const char *p = strchr (file, ';');
870
871 if (p)
840 { 872 {
841 size_t len = p - file; 873 size_t len = p - file;
842 char *f = rxvt_temp_buf<char> (len + 1); 874 char *f = rxvt_temp_buf<char> (len + 1);
843 memcpy (f, file, len); 875 memcpy (f, file, len);
844 f[len] = '\0'; 876 f[len] = '\0';
853 { 885 {
854 if (original_asim) 886 if (original_asim)
855 safe_asimage_destroy (original_asim); 887 safe_asimage_destroy (original_asim);
856 original_asim = image; 888 original_asim = image;
857 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; 889 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER;
858 return true; 890 ret = true;
859 } 891 }
860# endif 892# endif
861 893
862# ifdef HAVE_PIXBUF 894# ifdef HAVE_PIXBUF
863 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 895 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
865 { 897 {
866 if (pixbuf) 898 if (pixbuf)
867 g_object_unref (pixbuf); 899 g_object_unref (pixbuf);
868 pixbuf = image; 900 pixbuf = image;
869 bg_flags |= BG_IS_FROM_FILE; 901 bg_flags |= BG_IS_FROM_FILE;
870 return true; 902 ret = true;
871 } 903 }
872# endif 904# endif
873 905
906 if (ret)
907 {
908 if (p)
909 bg_set_geometry (p + 1);
910 else
911 bg_set_default_geometry ();
912 }
913
874 return false; 914 return ret;
875} 915}
876 916
877# endif /* BG_IMAGE_FROM_FILE */ 917# endif /* BG_IMAGE_FROM_FILE */
878 918
879# ifdef ENABLE_TRANSPARENCY 919# ifdef ENABLE_TRANSPARENCY
926} 966}
927 967
928void 968void
929rxvt_term::set_tint_shade_flags () 969rxvt_term::set_tint_shade_flags ()
930{ 970{
931 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 971 rgba c;
932 bool has_shade = shade != 100; 972 bool has_shade = shade != 100;
933 973
934 bg_flags &= ~BG_TINT_FLAGS; 974 bg_flags &= ~BG_TINT_FLAGS;
935 975
936 if (bg_flags & BG_TINT_SET)
937 {
938 tint.get (c); 976 tint.get (c);
977
939 if (!has_shade 978 if (!has_shade
940 && (c.r <= 0x00ff || c.r >= 0xff00) 979 && (c.r <= 0x00ff || c.r >= 0xff00)
941 && (c.g <= 0x00ff || c.g >= 0xff00) 980 && (c.g <= 0x00ff || c.g >= 0xff00)
942 && (c.b <= 0x00ff || c.b >= 0xff00)) 981 && (c.b <= 0x00ff || c.b >= 0xff00))
943 bg_flags |= BG_TINT_BITAND; 982 bg_flags |= BG_TINT_BITAND;
944 }
945 983
946 if (has_shade || (bg_flags & BG_TINT_SET)) 984 if (has_shade
985 || c.r < 0xff00
986 || c.g < 0xff00
987 || c.b < 0xff00)
947 bg_flags |= BG_NEEDS_TINT; 988 bg_flags |= BG_NEEDS_TINT;
948} 989}
949 990
950bool 991bool
951rxvt_term::bg_set_tint (rxvt_color &new_tint) 992rxvt_term::bg_set_tint (rxvt_color &new_tint)
952{ 993{
953 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 994 if (tint != new_tint)
954 { 995 {
955 tint = new_tint; 996 tint = new_tint;
956 bg_flags |= BG_TINT_SET;
957 set_tint_shade_flags (); 997 set_tint_shade_flags ();
958 return true; 998 return true;
959 } 999 }
960 1000
961 return false; 1001 return false;
962} 1002}
963 1003
964bool 1004bool
965rxvt_term::bg_set_shade (const char *shade_str) 1005rxvt_term::bg_set_shade (const char *shade_str)
966{ 1006{
967 int new_shade = (shade_str) ? atoi (shade_str) : 100; 1007 int new_shade = atoi (shade_str);
968 1008
969 clamp_it (new_shade, -100, 200); 1009 clamp_it (new_shade, -100, 200);
970 if (new_shade < 0) 1010 if (new_shade < 0)
971 new_shade = 200 - (100 + new_shade); 1011 new_shade = 200 - (100 + new_shade);
972 1012
1006bool 1046bool
1007rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1047rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1008{ 1048{
1009 bool ret = false; 1049 bool ret = false;
1010#if XRENDER 1050#if XRENDER
1051 if (!(bg_flags & BG_HAS_RENDER_CONV))
1052 return false;
1053
1011 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1054 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1012 double *kernel = (double *)malloc (size * sizeof (double)); 1055 double *kernel = (double *)malloc (size * sizeof (double));
1013 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1056 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1014 1057
1015 XRenderPictureAttributes pa;
1016 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1058 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1017 1059
1018 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1060 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1019 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1061 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1020 1062
1021 if (kernel && params) 1063 if (kernel && params)
1022 { 1064 {
1023 if (h_blurRadius) 1065 if (h_blurRadius)
1024 { 1066 {
1088 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); 1130 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1089 ret = true; 1131 ret = true;
1090 XFreeGC (dpy, gc); 1132 XFreeGC (dpy, gc);
1091 } 1133 }
1092 } 1134 }
1093 else
1094 {
1095# if XRENDER 1135# if XRENDER
1096 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1136 else if (bg_flags & BG_HAS_RENDER)
1137 {
1138 rgba c;
1097 1139
1098 if (bg_flags & BG_TINT_SET)
1099 tint.get (c); 1140 tint.get (c);
1100 1141
1101 if (shade <= 100) 1142 if (shade <= 100)
1102 { 1143 {
1103 c.r = c.r * shade / 100; 1144 c.r = c.r * shade / 100;
1104 c.g = c.g * shade / 100; 1145 c.g = c.g * shade / 100;
1109 c.r = c.r * (200 - shade) / 100; 1150 c.r = c.r * (200 - shade) / 100;
1110 c.g = c.g * (200 - shade) / 100; 1151 c.g = c.g * (200 - shade) / 100;
1111 c.b = c.b * (200 - shade) / 100; 1152 c.b = c.b * (200 - shade) / 100;
1112 } 1153 }
1113 1154
1114 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1115 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1155 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1116 XRenderPictureAttributes pa;
1117 1156
1118 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1157 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1119 1158
1120 pa.repeat = True; 1159 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
1121 1160
1122 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1161 Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True);
1123 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1124 XFreePixmap (dpy, overlay_pmap);
1125
1126 pa.component_alpha = True;
1127 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1128 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1129 XFreePixmap (dpy, mask_pmap);
1130 1162
1131 XRenderColor mask_c; 1163 XRenderColor mask_c;
1132 1164
1133 mask_c.alpha = 0xffff; 1165 mask_c.alpha = 0xffff;
1134 mask_c.red = 1166 mask_c.red =
1155 ret = true; 1187 ret = true;
1156 1188
1157 XRenderFreePicture (dpy, mask_pic); 1189 XRenderFreePicture (dpy, mask_pic);
1158 XRenderFreePicture (dpy, overlay_pic); 1190 XRenderFreePicture (dpy, overlay_pic);
1159 XRenderFreePicture (dpy, back_pic); 1191 XRenderFreePicture (dpy, back_pic);
1192 }
1160# endif 1193# endif
1161 }
1162 1194
1163 return ret; 1195 return ret;
1164} 1196}
1165 1197
1166/* 1198/*
1217#if XRENDER 1249#if XRENDER
1218 if (bg_flags & BG_HAS_RENDER) 1250 if (bg_flags & BG_HAS_RENDER)
1219 { 1251 {
1220 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); 1252 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1221 1253
1222 XRenderPictureAttributes pa;
1223
1224 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1254 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1225 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1255 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1226 1256
1227 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 1257 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1228 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1258 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, 0);
1229 1259
1230 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); 1260 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1231 1261
1232 XRenderFreePicture (dpy, src); 1262 XRenderFreePicture (dpy, src);
1233 XRenderFreePicture (dpy, dst); 1263 XRenderFreePicture (dpy, dst);
1250 bg_pmap_width = window_width; 1280 bg_pmap_width = window_width;
1251 bg_pmap_height = window_height; 1281 bg_pmap_height = window_height;
1252 } 1282 }
1253 1283
1254 /* straightforward pixmap copy */ 1284 /* straightforward pixmap copy */
1255 while (sx < 0) sx += root_width; 1285 while (sx < 0) sx += root_pmap_width;
1256 while (sy < 0) sy += root_height; 1286 while (sy < 0) sy += root_pmap_height;
1257 1287
1258 gcv.tile = recoded_root_pmap; 1288 gcv.tile = recoded_root_pmap;
1259 gcv.fill_style = FillTiled; 1289 gcv.fill_style = FillTiled;
1260 gcv.ts_x_origin = -sx; 1290 gcv.ts_x_origin = -sx;
1261 gcv.ts_y_origin = -sy; 1291 gcv.ts_y_origin = -sy;
1263 1293
1264 if (gc) 1294 if (gc)
1265 { 1295 {
1266 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1296 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1267 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1297 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1268 XFreeGC (dpy, gc);
1269 1298
1270 if (!(bg_flags & BG_CLIENT_RENDER)) 1299 if (!(bg_flags & BG_CLIENT_RENDER))
1271 { 1300 {
1272 if ((bg_flags & BG_NEEDS_BLUR) 1301 if (bg_flags & BG_NEEDS_BLUR)
1273 && (bg_flags & BG_HAS_RENDER_CONV))
1274 { 1302 {
1275 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1303 if (blur_pixmap (bg_pixmap, visual, window_width, window_height))
1276 result &= ~BG_NEEDS_BLUR; 1304 result &= ~BG_NEEDS_BLUR;
1277 } 1305 }
1278 if ((bg_flags & BG_NEEDS_TINT) 1306 if (bg_flags & BG_NEEDS_TINT)
1279 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1280 { 1307 {
1281 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1308 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1282 result &= ~BG_NEEDS_TINT; 1309 result &= ~BG_NEEDS_TINT;
1283 } 1310 }
1311# ifndef HAVE_AFTERIMAGE
1312 if (result & BG_NEEDS_TINT)
1313 {
1314 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1315 if (ximage)
1316 {
1317 /* our own client-side tinting */
1318 tint_ximage (DefaultVisual (dpy, display->screen), ximage);
1319
1320 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1321 XDestroyImage (ximage);
1322 }
1323 }
1324# endif
1284 } /* server side rendering completed */ 1325 } /* server side rendering completed */
1326
1327 XFreeGC (dpy, gc);
1285 } 1328 }
1286 1329
1287 if (recoded_root_pmap != root_pixmap) 1330 if (recoded_root_pmap != root_pixmap)
1288 XFreePixmap (dpy, recoded_root_pmap); 1331 XFreePixmap (dpy, recoded_root_pmap);
1289 1332
1298 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); 1341 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1299 1342
1300 root_pixmap = new_root_pixmap; 1343 root_pixmap = new_root_pixmap;
1301} 1344}
1302# endif /* ENABLE_TRANSPARENCY */ 1345# endif /* ENABLE_TRANSPARENCY */
1303
1304#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1305static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1306# endif
1307 1346
1308bool 1347bool
1309rxvt_term::bg_render () 1348rxvt_term::bg_render ()
1310{ 1349{
1311 unsigned long tr_flags = 0; 1350 unsigned long tr_flags = 0;
1316 { 1355 {
1317 /* we need to re-generate transparency pixmap in that case ! */ 1356 /* we need to re-generate transparency pixmap in that case ! */
1318 tr_flags = make_transparency_pixmap (); 1357 tr_flags = make_transparency_pixmap ();
1319 if (tr_flags == 0) 1358 if (tr_flags == 0)
1320 return false; 1359 return false;
1321 else if (!(tr_flags & BG_EFFECTS_FLAGS))
1322 bg_flags |= BG_IS_VALID; 1360 bg_flags |= BG_IS_VALID;
1323 } 1361 }
1324# endif 1362# endif
1325 1363
1326# ifdef BG_IMAGE_FROM_FILE 1364# ifdef BG_IMAGE_FROM_FILE
1327 if ((bg_flags & BG_IS_FROM_FILE) 1365 if ((bg_flags & BG_IS_FROM_FILE)
1330 if (render_image (tr_flags)) 1368 if (render_image (tr_flags))
1331 bg_flags |= BG_IS_VALID; 1369 bg_flags |= BG_IS_VALID;
1332 } 1370 }
1333# endif 1371# endif
1334 1372
1335# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1336 XImage *result = NULL;
1337
1338 if (tr_flags && !(bg_flags & BG_IS_VALID))
1339 {
1340 result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1341 }
1342
1343 if (result)
1344 {
1345 /* our own client-side tinting */
1346 if (tr_flags & BG_NEEDS_TINT)
1347 {
1348 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1349 if (bg_flags & BG_TINT_SET)
1350 tint.get (c);
1351 shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c);
1352 }
1353
1354 GC gc = XCreateGC (dpy, vt, 0UL, NULL);
1355
1356 if (gc)
1357 {
1358 XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1359
1360 XFreeGC (dpy, gc);
1361 bg_flags |= BG_IS_VALID;
1362 }
1363
1364 XDestroyImage (result);
1365 }
1366# endif
1367
1368 if (!(bg_flags & BG_IS_VALID)) 1373 if (!(bg_flags & BG_IS_VALID))
1369 { 1374 {
1370 if (bg_pixmap != None) 1375 if (bg_pixmap != None)
1371 { 1376 {
1372 XFreePixmap (dpy, bg_pixmap); 1377 XFreePixmap (dpy, bg_pixmap);
1384 1389
1385void 1390void
1386rxvt_term::bg_init () 1391rxvt_term::bg_init ()
1387{ 1392{
1388#ifdef ENABLE_TRANSPARENCY 1393#ifdef ENABLE_TRANSPARENCY
1394 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1395 tint.set (this, c);
1389 shade = 100; 1396 shade = 100;
1390#endif 1397#endif
1391 1398
1392 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); 1399 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1393#if XRENDER 1400#if XRENDER
1407} 1414}
1408 1415
1409#endif /* HAVE_BG_PIXMAP */ 1416#endif /* HAVE_BG_PIXMAP */
1410 1417
1411#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1418#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1412/* taken from aterm-0.4.2 */ 1419/* based on code from aterm-0.4.2 */
1413 1420
1414static void 1421static inline void
1415shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) 1422fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1423{
1424 for (int i = 0; i <= mask >> sh; i++)
1425 {
1426 uint32_t tmp;
1427 tmp = i * high;
1428 tmp += (mask >> sh) * low;
1429 lookup[i] = (tmp / 0xffff) << sh;
1430 }
1431}
1432
1433void
1434rxvt_term::tint_ximage (Visual *visual, XImage *ximage)
1416{ 1435{
1417 int sh_r, sh_g, sh_b; 1436 int sh_r, sh_g, sh_b;
1418 uint32_t mask_r, mask_g, mask_b; 1437 uint32_t mask_r, mask_g, mask_b;
1419 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1438 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1420 rgba low; 1439 unsigned short low;
1421 rgba high;
1422 int i;
1423 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 1440 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1424 1441
1425 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1442 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1426 1443
1427 /* for convenience */ 1444 /* for convenience */
1486 break; 1503 break;
1487 default: 1504 default:
1488 return; /* we do not support this color depth */ 1505 return; /* we do not support this color depth */
1489 } 1506 }
1490 1507
1508 rgba c;
1509
1510 tint.get (c);
1511
1491 /* prepare limits for color transformation (each channel is handled separately) */ 1512 /* prepare limits for color transformation (each channel is handled separately) */
1492 if (shade > 100) 1513 if (shade > 100)
1493 { 1514 {
1494 shade = 200 - shade;
1495
1496 high.r = c.r * shade / 100;
1497 high.g = c.g * shade / 100;
1498 high.b = c.b * shade / 100;
1499
1500 low.r = 65535 * (100 - shade) / 100; 1515 c.r = c.r * (200 - shade) / 100;
1501 low.g = 65535 * (100 - shade) / 100; 1516 c.g = c.g * (200 - shade) / 100;
1502 low.b = 65535 * (100 - shade) / 100; 1517 c.b = c.b * (200 - shade) / 100;
1518
1519 low = 0xffff * (shade - 100) / 100;
1503 } 1520 }
1504 else 1521 else
1505 { 1522 {
1506 high.r = c.r * shade / 100; 1523 c.r = c.r * shade / 100;
1507 high.g = c.g * shade / 100; 1524 c.g = c.g * shade / 100;
1508 high.b = c.b * shade / 100; 1525 c.b = c.b * shade / 100;
1509 1526
1510 low.r = low.g = low.b = 0; 1527 low = 0;
1511 } 1528 }
1512 1529
1513 /* fill our lookup tables */ 1530 /* fill our lookup tables */
1514 for (i = 0; i <= mask_r>>sh_r; i++) 1531 fill_lut (lookup_r, mask_r, sh_r, low, c.r);
1515 { 1532 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1516 uint32_t tmp; 1533 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1517 tmp = i * high.r;
1518 tmp += (mask_r>>sh_r) * low.r;
1519 lookup_r[i] = (tmp/65535)<<sh_r;
1520 }
1521 for (i = 0; i <= mask_g>>sh_g; i++)
1522 {
1523 uint32_t tmp;
1524 tmp = i * high.g;
1525 tmp += (mask_g>>sh_g) * low.g;
1526 lookup_g[i] = (tmp/65535)<<sh_g;
1527 }
1528 for (i = 0; i <= mask_b>>sh_b; i++)
1529 {
1530 uint32_t tmp;
1531 tmp = i * high.b;
1532 tmp += (mask_b>>sh_b) * low.b;
1533 lookup_b[i] = (tmp/65535)<<sh_b;
1534 }
1535 1534
1536 /* apply table to input image (replacing colors by newly calculated ones) */ 1535 /* apply table to input image (replacing colors by newly calculated ones) */
1537 if (ximage->bits_per_pixel == 32 1536 if (ximage->bits_per_pixel == 32
1538 && (ximage->depth == 24 || ximage->depth == 32) 1537 && (ximage->depth == 24 || ximage->depth == 32)
1539 && ximage->byte_order == host_byte_order) 1538 && ximage->byte_order == host_byte_order)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines