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.190 by sf-exg, Thu Dec 29 20:35:37 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 }
785 820
786#if XRENDER 821#if XRENDER
787 if (tr_flags) 822 if (tr_flags)
788 { 823 {
789 XRenderPictureAttributes pa; 824 XRenderPictureAttributes pa;
790
791 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); 825 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
826
792 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 827 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, &pa);
793 828
794 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
795 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); 829 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, &pa);
796 830
797 pa.repeat = True; 831 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 832
803 XRenderColor mask_c; 833 XRenderColor mask_c;
804 834
805 mask_c.alpha = 0x8000; 835 mask_c.alpha = 0x8000;
806 mask_c.red = 0; 836 mask_c.red = 0;
834rxvt_term::bg_set_file (const char *file) 864rxvt_term::bg_set_file (const char *file)
835{ 865{
836 if (!file || !*file) 866 if (!file || !*file)
837 return false; 867 return false;
838 868
869 bool ret = false;
839 if (const char *p = strchr (file, ';')) 870 const char *p = strchr (file, ';');
871
872 if (p)
840 { 873 {
841 size_t len = p - file; 874 size_t len = p - file;
842 char *f = rxvt_temp_buf<char> (len + 1); 875 char *f = rxvt_temp_buf<char> (len + 1);
843 memcpy (f, file, len); 876 memcpy (f, file, len);
844 f[len] = '\0'; 877 f[len] = '\0';
853 { 886 {
854 if (original_asim) 887 if (original_asim)
855 safe_asimage_destroy (original_asim); 888 safe_asimage_destroy (original_asim);
856 original_asim = image; 889 original_asim = image;
857 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; 890 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER;
858 return true; 891 ret = true;
859 } 892 }
860# endif 893# endif
861 894
862# ifdef HAVE_PIXBUF 895# ifdef HAVE_PIXBUF
863 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 896 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
865 { 898 {
866 if (pixbuf) 899 if (pixbuf)
867 g_object_unref (pixbuf); 900 g_object_unref (pixbuf);
868 pixbuf = image; 901 pixbuf = image;
869 bg_flags |= BG_IS_FROM_FILE; 902 bg_flags |= BG_IS_FROM_FILE;
870 return true; 903 ret = true;
871 } 904 }
872# endif 905# endif
873 906
907 if (ret)
908 {
909 if (p)
910 bg_set_geometry (p + 1);
911 else
912 bg_set_default_geometry ();
913 }
914
874 return false; 915 return ret;
875} 916}
876 917
877# endif /* BG_IMAGE_FROM_FILE */ 918# endif /* BG_IMAGE_FROM_FILE */
878 919
879# ifdef ENABLE_TRANSPARENCY 920# ifdef ENABLE_TRANSPARENCY
926} 967}
927 968
928void 969void
929rxvt_term::set_tint_shade_flags () 970rxvt_term::set_tint_shade_flags ()
930{ 971{
931 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 972 rgba c;
932 bool has_shade = shade != 100; 973 bool has_shade = shade != 100;
933 974
934 bg_flags &= ~BG_TINT_FLAGS; 975 bg_flags &= ~BG_TINT_FLAGS;
935 976
936 if (bg_flags & BG_TINT_SET)
937 {
938 tint.get (c); 977 tint.get (c);
978
939 if (!has_shade 979 if (!has_shade
940 && (c.r <= 0x00ff || c.r >= 0xff00) 980 && (c.r <= 0x00ff || c.r >= 0xff00)
941 && (c.g <= 0x00ff || c.g >= 0xff00) 981 && (c.g <= 0x00ff || c.g >= 0xff00)
942 && (c.b <= 0x00ff || c.b >= 0xff00)) 982 && (c.b <= 0x00ff || c.b >= 0xff00))
943 bg_flags |= BG_TINT_BITAND; 983 bg_flags |= BG_TINT_BITAND;
944 }
945 984
946 if (has_shade || (bg_flags & BG_TINT_SET)) 985 if (has_shade
986 || c.r < 0xff00
987 || c.g < 0xff00
988 || c.b < 0xff00)
947 bg_flags |= BG_NEEDS_TINT; 989 bg_flags |= BG_NEEDS_TINT;
948} 990}
949 991
950bool 992bool
951rxvt_term::bg_set_tint (rxvt_color &new_tint) 993rxvt_term::bg_set_tint (rxvt_color &new_tint)
952{ 994{
953 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 995 if (tint != new_tint)
954 { 996 {
955 tint = new_tint; 997 tint = new_tint;
956 bg_flags |= BG_TINT_SET;
957 set_tint_shade_flags (); 998 set_tint_shade_flags ();
958 return true; 999 return true;
959 } 1000 }
960 1001
961 return false; 1002 return false;
962} 1003}
963 1004
964bool 1005bool
965rxvt_term::bg_set_shade (const char *shade_str) 1006rxvt_term::bg_set_shade (const char *shade_str)
966{ 1007{
967 int new_shade = (shade_str) ? atoi (shade_str) : 100; 1008 int new_shade = atoi (shade_str);
968 1009
969 clamp_it (new_shade, -100, 200); 1010 clamp_it (new_shade, -100, 200);
970 if (new_shade < 0) 1011 if (new_shade < 0)
971 new_shade = 200 - (100 + new_shade); 1012 new_shade = 200 - (100 + new_shade);
972 1013
1006bool 1047bool
1007rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1048rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1008{ 1049{
1009 bool ret = false; 1050 bool ret = false;
1010#if XRENDER 1051#if XRENDER
1052 if (!(bg_flags & BG_HAS_RENDER_CONV))
1053 return false;
1054
1011 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1055 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1012 double *kernel = (double *)malloc (size * sizeof (double)); 1056 double *kernel = (double *)malloc (size * sizeof (double));
1013 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1057 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1014 1058
1015 XRenderPictureAttributes pa; 1059 XRenderPictureAttributes pa;
1088 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); 1132 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1089 ret = true; 1133 ret = true;
1090 XFreeGC (dpy, gc); 1134 XFreeGC (dpy, gc);
1091 } 1135 }
1092 } 1136 }
1093 else
1094 {
1095# if XRENDER 1137# if XRENDER
1096 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1138 else if (bg_flags & BG_HAS_RENDER)
1139 {
1140 rgba c;
1097 1141
1098 if (bg_flags & BG_TINT_SET)
1099 tint.get (c); 1142 tint.get (c);
1100 1143
1101 if (shade <= 100) 1144 if (shade <= 100)
1102 { 1145 {
1103 c.r = c.r * shade / 100; 1146 c.r = c.r * shade / 100;
1104 c.g = c.g * shade / 100; 1147 c.g = c.g * shade / 100;
1109 c.r = c.r * (200 - shade) / 100; 1152 c.r = c.r * (200 - shade) / 100;
1110 c.g = c.g * (200 - shade) / 100; 1153 c.g = c.g * (200 - shade) / 100;
1111 c.b = c.b * (200 - shade) / 100; 1154 c.b = c.b * (200 - shade) / 100;
1112 } 1155 }
1113 1156
1114 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1115 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1157 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1116 XRenderPictureAttributes pa; 1158 XRenderPictureAttributes pa;
1117 1159
1118 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1160 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1119 1161
1120 pa.repeat = True; 1162 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
1121 1163
1122 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1164 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 1165
1131 XRenderColor mask_c; 1166 XRenderColor mask_c;
1132 1167
1133 mask_c.alpha = 0xffff; 1168 mask_c.alpha = 0xffff;
1134 mask_c.red = 1169 mask_c.red =
1155 ret = true; 1190 ret = true;
1156 1191
1157 XRenderFreePicture (dpy, mask_pic); 1192 XRenderFreePicture (dpy, mask_pic);
1158 XRenderFreePicture (dpy, overlay_pic); 1193 XRenderFreePicture (dpy, overlay_pic);
1159 XRenderFreePicture (dpy, back_pic); 1194 XRenderFreePicture (dpy, back_pic);
1195 }
1160# endif 1196# endif
1161 }
1162 1197
1163 return ret; 1198 return ret;
1164} 1199}
1165 1200
1166/* 1201/*
1250 bg_pmap_width = window_width; 1285 bg_pmap_width = window_width;
1251 bg_pmap_height = window_height; 1286 bg_pmap_height = window_height;
1252 } 1287 }
1253 1288
1254 /* straightforward pixmap copy */ 1289 /* straightforward pixmap copy */
1255 while (sx < 0) sx += root_width; 1290 while (sx < 0) sx += root_pmap_width;
1256 while (sy < 0) sy += root_height; 1291 while (sy < 0) sy += root_pmap_height;
1257 1292
1258 gcv.tile = recoded_root_pmap; 1293 gcv.tile = recoded_root_pmap;
1259 gcv.fill_style = FillTiled; 1294 gcv.fill_style = FillTiled;
1260 gcv.ts_x_origin = -sx; 1295 gcv.ts_x_origin = -sx;
1261 gcv.ts_y_origin = -sy; 1296 gcv.ts_y_origin = -sy;
1263 1298
1264 if (gc) 1299 if (gc)
1265 { 1300 {
1266 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1301 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1267 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1302 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1268 XFreeGC (dpy, gc);
1269 1303
1270 if (!(bg_flags & BG_CLIENT_RENDER)) 1304 if (!(bg_flags & BG_CLIENT_RENDER))
1271 { 1305 {
1272 if ((bg_flags & BG_NEEDS_BLUR) 1306 if (bg_flags & BG_NEEDS_BLUR)
1273 && (bg_flags & BG_HAS_RENDER_CONV))
1274 { 1307 {
1275 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1308 if (blur_pixmap (bg_pixmap, visual, window_width, window_height))
1276 result &= ~BG_NEEDS_BLUR; 1309 result &= ~BG_NEEDS_BLUR;
1277 } 1310 }
1278 if ((bg_flags & BG_NEEDS_TINT) 1311 if (bg_flags & BG_NEEDS_TINT)
1279 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1280 { 1312 {
1281 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1313 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1282 result &= ~BG_NEEDS_TINT; 1314 result &= ~BG_NEEDS_TINT;
1283 } 1315 }
1316# ifndef HAVE_AFTERIMAGE
1317 if (result & BG_NEEDS_TINT)
1318 {
1319 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1320 if (ximage)
1321 {
1322 /* our own client-side tinting */
1323 tint_ximage (DefaultVisual (dpy, display->screen), ximage);
1324
1325 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1326 XDestroyImage (ximage);
1327 }
1328 }
1329# endif
1284 } /* server side rendering completed */ 1330 } /* server side rendering completed */
1331
1332 XFreeGC (dpy, gc);
1285 } 1333 }
1286 1334
1287 if (recoded_root_pmap != root_pixmap) 1335 if (recoded_root_pmap != root_pixmap)
1288 XFreePixmap (dpy, recoded_root_pmap); 1336 XFreePixmap (dpy, recoded_root_pmap);
1289 1337
1298 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); 1346 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1299 1347
1300 root_pixmap = new_root_pixmap; 1348 root_pixmap = new_root_pixmap;
1301} 1349}
1302# endif /* ENABLE_TRANSPARENCY */ 1350# 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 1351
1308bool 1352bool
1309rxvt_term::bg_render () 1353rxvt_term::bg_render ()
1310{ 1354{
1311 unsigned long tr_flags = 0; 1355 unsigned long tr_flags = 0;
1316 { 1360 {
1317 /* we need to re-generate transparency pixmap in that case ! */ 1361 /* we need to re-generate transparency pixmap in that case ! */
1318 tr_flags = make_transparency_pixmap (); 1362 tr_flags = make_transparency_pixmap ();
1319 if (tr_flags == 0) 1363 if (tr_flags == 0)
1320 return false; 1364 return false;
1321 else if (!(tr_flags & BG_EFFECTS_FLAGS))
1322 bg_flags |= BG_IS_VALID; 1365 bg_flags |= BG_IS_VALID;
1323 } 1366 }
1324# endif 1367# endif
1325 1368
1326# ifdef BG_IMAGE_FROM_FILE 1369# ifdef BG_IMAGE_FROM_FILE
1327 if ((bg_flags & BG_IS_FROM_FILE) 1370 if ((bg_flags & BG_IS_FROM_FILE)
1330 if (render_image (tr_flags)) 1373 if (render_image (tr_flags))
1331 bg_flags |= BG_IS_VALID; 1374 bg_flags |= BG_IS_VALID;
1332 } 1375 }
1333# endif 1376# endif
1334 1377
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)) 1378 if (!(bg_flags & BG_IS_VALID))
1369 { 1379 {
1370 if (bg_pixmap != None) 1380 if (bg_pixmap != None)
1371 { 1381 {
1372 XFreePixmap (dpy, bg_pixmap); 1382 XFreePixmap (dpy, bg_pixmap);
1384 1394
1385void 1395void
1386rxvt_term::bg_init () 1396rxvt_term::bg_init ()
1387{ 1397{
1388#ifdef ENABLE_TRANSPARENCY 1398#ifdef ENABLE_TRANSPARENCY
1399 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1400 tint.set (this, c);
1389 shade = 100; 1401 shade = 100;
1390#endif 1402#endif
1391 1403
1392 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); 1404 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1393#if XRENDER 1405#if XRENDER
1407} 1419}
1408 1420
1409#endif /* HAVE_BG_PIXMAP */ 1421#endif /* HAVE_BG_PIXMAP */
1410 1422
1411#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1423#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1412/* taken from aterm-0.4.2 */ 1424/* based on code from aterm-0.4.2 */
1413 1425
1414static void 1426static inline void
1415shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) 1427fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1428{
1429 for (int i = 0; i <= mask >> sh; i++)
1430 {
1431 uint32_t tmp;
1432 tmp = i * high;
1433 tmp += (mask >> sh) * low;
1434 lookup[i] = (tmp / 0xffff) << sh;
1435 }
1436}
1437
1438void
1439rxvt_term::tint_ximage (Visual *visual, XImage *ximage)
1416{ 1440{
1417 int sh_r, sh_g, sh_b; 1441 int sh_r, sh_g, sh_b;
1418 uint32_t mask_r, mask_g, mask_b; 1442 uint32_t mask_r, mask_g, mask_b;
1419 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1443 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1420 rgba low; 1444 unsigned short low;
1421 rgba high;
1422 int i;
1423 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 1445 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1424 1446
1425 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1447 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1426 1448
1427 /* for convenience */ 1449 /* for convenience */
1486 break; 1508 break;
1487 default: 1509 default:
1488 return; /* we do not support this color depth */ 1510 return; /* we do not support this color depth */
1489 } 1511 }
1490 1512
1513 rgba c;
1514
1515 tint.get (c);
1516
1491 /* prepare limits for color transformation (each channel is handled separately) */ 1517 /* prepare limits for color transformation (each channel is handled separately) */
1492 if (shade > 100) 1518 if (shade > 100)
1493 { 1519 {
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; 1520 c.r = c.r * (200 - shade) / 100;
1501 low.g = 65535 * (100 - shade) / 100; 1521 c.g = c.g * (200 - shade) / 100;
1502 low.b = 65535 * (100 - shade) / 100; 1522 c.b = c.b * (200 - shade) / 100;
1523
1524 low = 0xffff * (shade - 100) / 100;
1503 } 1525 }
1504 else 1526 else
1505 { 1527 {
1506 high.r = c.r * shade / 100; 1528 c.r = c.r * shade / 100;
1507 high.g = c.g * shade / 100; 1529 c.g = c.g * shade / 100;
1508 high.b = c.b * shade / 100; 1530 c.b = c.b * shade / 100;
1509 1531
1510 low.r = low.g = low.b = 0; 1532 low = 0;
1511 } 1533 }
1512 1534
1513 /* fill our lookup tables */ 1535 /* fill our lookup tables */
1514 for (i = 0; i <= mask_r>>sh_r; i++) 1536 fill_lut (lookup_r, mask_r, sh_r, low, c.r);
1515 { 1537 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1516 uint32_t tmp; 1538 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 1539
1536 /* apply table to input image (replacing colors by newly calculated ones) */ 1540 /* apply table to input image (replacing colors by newly calculated ones) */
1537 if (ximage->bits_per_pixel == 32 1541 if (ximage->bits_per_pixel == 32
1538 && (ximage->depth == 24 || ximage->depth == 32) 1542 && (ximage->depth == 24 || ximage->depth == 32)
1539 && ximage->byte_order == host_byte_order) 1543 && ximage->byte_order == host_byte_order)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines