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.167 by sf-exg, Fri Aug 19 17:42:09 2011 UTC vs.
Revision 1.200 by sf-exg, Thu Jan 19 13:33:43 2012 UTC

20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *---------------------------------------------------------------------*/ 23 *---------------------------------------------------------------------*/
24 24
25#include <cmath> 25#include <math.h>
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28 28
29#if XRENDER 29#if XRENDER
30# include <X11/extensions/Xrender.h> 30# include <X11/extensions/Xrender.h>
32 32
33#ifndef FilterConvolution 33#ifndef FilterConvolution
34#define FilterConvolution "convolution" 34#define FilterConvolution "convolution"
35#endif 35#endif
36 36
37#ifndef RepeatPad
38#define RepeatPad True
39#endif
40
37#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
38void 60void
39rxvt_term::bg_destroy () 61rxvt_term::bg_destroy ()
40{ 62{
41#ifdef HAVE_AFTERIMAGE 63#ifdef HAVE_AFTERIMAGE
42 if (original_asim) 64 if (original_asim)
107 129
108 return false; 130 return false;
109} 131}
110 132
111# ifdef BG_IMAGE_FROM_FILE 133# ifdef BG_IMAGE_FROM_FILE
112static inline bool
113check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value)
114{
115 if (geom_flags & flag)
116 {
117 if (new_value > 1000)
118 new_value = 1000;
119 if (new_value != scale)
120 {
121 scale = new_value;
122 return true;
123 }
124 }
125 return false;
126}
127
128static inline bool
129check_set_align_value (int geom_flags, int flag, int &align, int new_value)
130{
131 if (geom_flags & flag)
132 {
133 if (new_value < -100)
134 new_value = -100;
135 else if (new_value > 200)
136 new_value = 200;
137 if (new_value != align)
138 {
139 align = new_value;
140 return true;
141 }
142 }
143 return false;
144}
145
146static inline int 134static inline int
147make_align_position (int align, int window_size, int image_size) 135make_align_position (int align, int window_size, int image_size)
148{ 136{
149 int diff = window_size - image_size; 137 int diff = window_size - image_size;
150 int smaller = min (image_size, window_size); 138 int smaller = min (image_size, window_size);
151 139
152 if (align >= 0 && align <= 100) 140 if (align >= 0 && align <= 100)
153 return diff * align / 100; 141 return diff * align / 100;
154 else if (align > 100 && align <= 200) 142 else if (align > 100 && align <= 200)
155 return ((align - 100) * smaller / 100) + window_size - smaller; 143 return (align - 100) * smaller / 100 + window_size - smaller;
156 else if (align >= -100 && align < 0) 144 else if (align >= -100 && align < 0)
157 return ((align + 100) * smaller / 100) - image_size; 145 return (align + 100) * smaller / 100 - image_size;
158 return 0; 146 return 0;
159} 147}
160 148
161static inline int 149static inline int
162make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 150make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
169 src_pos = -pos; 157 src_pos = -pos;
170 dst_pos = 0; 158 dst_pos = 0;
171 dst_size += pos; 159 dst_size += pos;
172 } 160 }
173 161
174 if (dst_pos + dst_size > target_size)
175 dst_size = target_size - dst_pos; 162 min_it (dst_size, target_size - dst_pos);
176 return src_pos; 163 return src_pos;
177} 164}
178 165
179bool 166bool
180rxvt_term::bg_set_geometry (const char *geom, bool update) 167rxvt_term::bg_set_geometry (const char *geom, bool update)
181{ 168{
182 bool changed = false; 169 bool changed = false;
183 int geom_flags = 0; 170 int geom_flags = 0;
184 int x = 0, y = 0; 171 int x = h_align;
172 int y = v_align;
185 unsigned int w = 0, h = 0; 173 unsigned int w = h_scale;
186 unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); 174 unsigned int h = v_scale;
175 unsigned long new_flags = 0;
187 176
188 if (geom == NULL) 177 if (geom == NULL)
189 return false; 178 return false;
190 179
191 if (geom[0]) 180 if (geom[0])
192 { 181 {
193 char **arr = rxvt_strsplit (':', geom); 182 char **arr = rxvt_strsplit (':', geom);
194 183
195 for (int i = 0; arr[i]; i++) 184 for (int i = 0; arr[i]; i++)
196 { 185 {
197 if (!strcasecmp (arr[i], "style=tiled")) 186 if (!strcasecmp (arr[i], "style=tiled"))
198 { 187 {
199 new_flags = BG_TILE; 188 new_flags = BG_TILE;
200 w = h = noScale; 189 w = h = noScale;
201 x = y = 0; 190 x = y = 0;
202 geom_flags = WidthValue|HeightValue|XValue|YValue; 191 geom_flags = WidthValue|HeightValue|XValue|YValue;
203 } 192 }
204 else if (!strcasecmp (arr[i], "style=aspect-stretched")) 193 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
205 { 194 {
206 new_flags = BG_PROP_SCALE; 195 new_flags = BG_KEEP_ASPECT;
207 w = h = windowScale; 196 w = h = windowScale;
208 x = y = centerAlign; 197 x = y = centerAlign;
209 geom_flags = WidthValue|HeightValue|XValue|YValue; 198 geom_flags = WidthValue|HeightValue|XValue|YValue;
210 } 199 }
211 else if (!strcasecmp (arr[i], "style=stretched")) 200 else if (!strcasecmp (arr[i], "style=stretched"))
227 w = h = noScale; 216 w = h = noScale;
228 geom_flags = WidthValue|HeightValue; 217 geom_flags = WidthValue|HeightValue;
229 } 218 }
230 else if (!strcasecmp (arr[i], "op=tile")) 219 else if (!strcasecmp (arr[i], "op=tile"))
231 new_flags |= BG_TILE; 220 new_flags |= BG_TILE;
232 else if (!strcasecmp (arr[i], "op=pscale")) 221 else if (!strcasecmp (arr[i], "op=keep-aspect"))
233 new_flags |= BG_PROP_SCALE; 222 new_flags |= BG_KEEP_ASPECT;
234 else if (!strcasecmp (arr[i], "op=root")) 223 else if (!strcasecmp (arr[i], "op=root-align"))
235 new_flags |= BG_ROOT_ALIGN; 224 new_flags |= BG_ROOT_ALIGN;
236 225
237 // deprecated 226 // deprecated
238 else if (!strcasecmp (arr[i], "tile")) 227 else if (!strcasecmp (arr[i], "tile"))
239 { 228 {
241 w = h = noScale; 230 w = h = noScale;
242 geom_flags |= WidthValue|HeightValue; 231 geom_flags |= WidthValue|HeightValue;
243 } 232 }
244 else if (!strcasecmp (arr[i], "propscale")) 233 else if (!strcasecmp (arr[i], "propscale"))
245 { 234 {
246 new_flags |= BG_PROP_SCALE; 235 new_flags |= BG_KEEP_ASPECT;
236 w = h = windowScale;
237 geom_flags |= WidthValue|HeightValue;
247 } 238 }
248 else if (!strcasecmp (arr[i], "hscale")) 239 else if (!strcasecmp (arr[i], "hscale"))
249 { 240 {
250 new_flags |= BG_TILE; 241 new_flags |= BG_TILE;
251 w = windowScale; 242 w = windowScale;
281 geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h); 272 geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h);
282 } /* done parsing ops */ 273 } /* done parsing ops */
283 274
284 rxvt_free_strsplit (arr); 275 rxvt_free_strsplit (arr);
285 } 276 }
277
278 new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS;
286 279
287 if (!update) 280 if (!update)
288 { 281 {
289 if (!(geom_flags & XValue)) 282 if (!(geom_flags & XValue))
290 x = y = defaultAlign; 283 x = y = defaultAlign;
295 w = h = defaultScale; 288 w = h = defaultScale;
296 else if (!(geom_flags & HeightValue)) 289 else if (!(geom_flags & HeightValue))
297 h = w; 290 h = w;
298 else if (!(geom_flags & WidthValue)) 291 else if (!(geom_flags & WidthValue))
299 w = h; 292 w = h;
300
301 geom_flags |= WidthValue|HeightValue|XValue|YValue;
302 } 293 }
303 294
304 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; 295 min_it (w, 1000);
305 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; 296 min_it (h, 1000);
306 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; 297 clamp_it (x, -100, 200);
307 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; 298 clamp_it (y, -100, 200);
308 299
309 if (new_flags != bg_flags) 300 if (bg_flags != new_flags
301 || h_scale != w
302 || v_scale != h
303 || h_align != x
304 || v_align != y)
310 { 305 {
311 bg_flags = new_flags; 306 bg_flags = new_flags;
307 h_scale = w;
308 v_scale = h;
309 h_align = x;
310 v_align = y;
312 changed = true; 311 changed = true;
313 } 312 }
314 313
315 return changed; 314 return changed;
316} 315}
322 int target_height = szHint.height; 321 int target_height = szHint.height;
323 322
324 w = h_scale * target_width / 100; 323 w = h_scale * target_width / 100;
325 h = v_scale * target_height / 100; 324 h = v_scale * target_height / 100;
326 325
327 if (bg_flags & BG_PROP_SCALE) 326 if (bg_flags & BG_KEEP_ASPECT)
328 { 327 {
329 float scale = (float)w / image_width; 328 float scale = (float)w / image_width;
330 min_it (scale, (float)h / image_height); 329 min_it (scale, (float)h / image_height);
331 w = image_width * scale + 0.5; 330 w = image_width * scale + 0.5;
332 h = image_height * scale + 0.5; 331 h = image_height * scale + 0.5;
383 } 382 }
384 383
385 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) 384 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL)
386 { 385 {
387 ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 386 ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
388 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, 387 ASA_XImage,
389 100, ASIMAGE_QUALITY_DEFAULT); 388 100, ASIMAGE_QUALITY_DEFAULT);
390 if (tmp) 389 if (tmp)
391 { 390 {
392 destroy_asimage (&background); 391 destroy_asimage (&background);
393 background = tmp; 392 background = tmp;
412 411
413 if (!original_asim 412 if (!original_asim
414 || (!(bg_flags & BG_ROOT_ALIGN) 413 || (!(bg_flags & BG_ROOT_ALIGN)
415 && (x >= target_width 414 && (x >= target_width
416 || y >= target_height 415 || y >= target_height
417 || (x + w <= 0) 416 || x + w <= 0
418 || (y + h <= 0)))) 417 || y + h <= 0)))
419 { 418 {
420 if (background) 419 if (background)
421 { 420 {
422 new_pmap_width = background->width; 421 new_pmap_width = background->width;
423 new_pmap_height = background->height; 422 new_pmap_height = background->height;
437 } 436 }
438 else 437 else
439 { 438 {
440 result = original_asim; 439 result = original_asim;
441 440
442 if ((w != original_asim->width) 441 if (w != original_asim->width
443 || (h != original_asim->height)) 442 || h != original_asim->height)
444 { 443 {
445 result = scale_asimage (asv, original_asim, 444 result = scale_asimage (asv, original_asim,
446 w, h, 445 w, h,
447 background ? ASA_ASImage : ASA_XImage, 446 ASA_XImage,
448 100, ASIMAGE_QUALITY_DEFAULT); 447 100, ASIMAGE_QUALITY_DEFAULT);
449 } 448 }
450 449
451 if (background == NULL) 450 if (background == NULL)
452 { 451 {
702 get_image_geometry (image_width, image_height, w, h, x, y); 701 get_image_geometry (image_width, image_height, w, h, x, y);
703 702
704 if (!(bg_flags & BG_ROOT_ALIGN) 703 if (!(bg_flags & BG_ROOT_ALIGN)
705 && (x >= target_width 704 && (x >= target_width
706 || y >= target_height 705 || y >= target_height
707 || (x + w <= 0) 706 || x + w <= 0
708 || (y + h <= 0))) 707 || y + h <= 0))
709 return false; 708 return false;
710 709
711 result = pixbuf; 710 result = pixbuf;
712 711
713 if ((w != image_width) 712 if (w != image_width
714 || (h != image_height)) 713 || h != image_height)
715 { 714 {
716 result = gdk_pixbuf_scale_simple (pixbuf, 715 result = gdk_pixbuf_scale_simple (pixbuf,
717 w, h, 716 w, h,
718 GDK_INTERP_BILINEAR); 717 GDK_INTERP_BILINEAR);
719 } 718 }
798 } 797 }
799 798
800#if XRENDER 799#if XRENDER
801 if (tr_flags) 800 if (tr_flags)
802 { 801 {
803 XRenderPictureAttributes pa;
804
805 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); 802 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
803
806 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 804 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0);
807 805
808 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
809 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); 806 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
810 807
811 pa.repeat = True; 808 Picture mask = create_xrender_mask (dpy, vt, False, False);
812 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
813 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
814 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
815 XFreePixmap (dpy, mask_pmap);
816 809
817 XRenderColor mask_c; 810 XRenderColor mask_c;
818 811
819 mask_c.alpha = 0x8000; 812 mask_c.alpha = 0x8000;
820 mask_c.red = 0; 813 mask_c.red =
821 mask_c.green = 0; 814 mask_c.green =
822 mask_c.blue = 0; 815 mask_c.blue = 0;
823 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 816 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
817
824 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); 818 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height);
825 819
826 XRenderFreePicture (dpy, src); 820 XRenderFreePicture (dpy, src);
827 XRenderFreePicture (dpy, dst); 821 XRenderFreePicture (dpy, dst);
828 XRenderFreePicture (dpy, mask); 822 XRenderFreePicture (dpy, mask);
940 { 934 {
941 changed = true; 935 changed = true;
942 v_blurRadius = vr; 936 v_blurRadius = vr;
943 } 937 }
944 938
945 if (v_blurRadius == 0 && h_blurRadius == 0) 939 if (h_blurRadius == 0 || v_blurRadius == 0)
946 bg_flags &= ~BG_NEEDS_BLUR; 940 bg_flags &= ~BG_NEEDS_BLUR;
947 else 941 else
948 bg_flags |= BG_NEEDS_BLUR; 942 bg_flags |= BG_NEEDS_BLUR;
949 943
950 return changed; 944 return changed;
951} 945}
952 946
953void 947void
954rxvt_term::set_tint_shade_flags () 948rxvt_term::set_tint_shade_flags ()
955{ 949{
956 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 950 rgba c;
957 bool has_shade = shade != 100; 951 bool has_shade = shade != 100;
958 952
959 bg_flags &= ~BG_TINT_FLAGS; 953 bg_flags &= ~BG_TINT_FLAGS;
960 954
961 if (bg_flags & BG_TINT_SET) 955 if (bg_flags & BG_TINT_SET)
987} 981}
988 982
989bool 983bool
990rxvt_term::bg_set_shade (const char *shade_str) 984rxvt_term::bg_set_shade (const char *shade_str)
991{ 985{
992 int new_shade = (shade_str) ? atoi (shade_str) : 100; 986 int new_shade = atoi (shade_str);
993 987
994 clamp_it (new_shade, -100, 200); 988 clamp_it (new_shade, -100, 200);
995 if (new_shade < 0) 989 if (new_shade < 0)
996 new_shade = 200 - (100 + new_shade); 990 new_shade = 200 - (100 + new_shade);
997 991
1027 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1021 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1028} 1022}
1029#endif 1023#endif
1030 1024
1031bool 1025bool
1032rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1026rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth)
1033{ 1027{
1034 bool ret = false; 1028 bool ret = false;
1035#if XRENDER 1029#if XRENDER
1030 if (!(bg_flags & BG_HAS_RENDER_CONV))
1031 return false;
1032
1036 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1033 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1037 double *kernel = (double *)malloc (size * sizeof (double)); 1034 double *kernel = (double *)malloc (size * sizeof (double));
1038 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1035 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1039 1036
1040 XRenderPictureAttributes pa; 1037 XRenderPictureAttributes pa;
1041 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1038 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1042 1039
1040 pa.repeat = RepeatPad;
1043 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1041 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
1042 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth);
1044 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1043 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
1044 XFreePixmap (dpy, tmp);
1045 1045
1046 if (kernel && params) 1046 if (kernel && params)
1047 { 1047 {
1048 if (h_blurRadius)
1049 {
1050 size = h_blurRadius * 2 + 1; 1048 size = h_blurRadius * 2 + 1;
1051 get_gaussian_kernel (h_blurRadius, size, kernel, params); 1049 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1052 1050
1053 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1051 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1054 XRenderComposite (dpy, 1052 XRenderComposite (dpy,
1055 PictOpSrc, 1053 PictOpSrc,
1056 src, 1054 src,
1057 None, 1055 None,
1058 dst, 1056 dst,
1059 0, 0, 1057 0, 0,
1060 0, 0, 1058 0, 0,
1061 0, 0, 1059 0, 0,
1062 width, height); 1060 width, height);
1063 }
1064 1061
1065 if (v_blurRadius) 1062 ::swap (src, dst);
1066 { 1063
1067 size = v_blurRadius * 2 + 1; 1064 size = v_blurRadius * 2 + 1;
1068 get_gaussian_kernel (v_blurRadius, size, kernel, params); 1065 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1069 ::swap (params[0], params[1]); 1066 ::swap (params[0], params[1]);
1070 1067
1071 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1068 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1072 XRenderComposite (dpy, 1069 XRenderComposite (dpy,
1073 PictOpSrc, 1070 PictOpSrc,
1074 src, 1071 src,
1075 None, 1072 None,
1076 dst, 1073 dst,
1077 0, 0, 1074 0, 0,
1078 0, 0, 1075 0, 0,
1079 0, 0, 1076 0, 0,
1080 width, height); 1077 width, height);
1081 }
1082 1078
1083 ret = true; 1079 ret = true;
1084 } 1080 }
1085 1081
1086 free (kernel); 1082 free (kernel);
1113 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); 1109 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1114 ret = true; 1110 ret = true;
1115 XFreeGC (dpy, gc); 1111 XFreeGC (dpy, gc);
1116 } 1112 }
1117 } 1113 }
1118 else
1119 {
1120# if XRENDER 1114# if XRENDER
1115 else if (bg_flags & BG_HAS_RENDER)
1116 {
1121 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1117 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1122 1118
1123 if (bg_flags & BG_TINT_SET) 1119 if (bg_flags & BG_TINT_SET)
1124 tint.get (c); 1120 tint.get (c);
1125 1121
1134 c.r = c.r * (200 - shade) / 100; 1130 c.r = c.r * (200 - shade) / 100;
1135 c.g = c.g * (200 - shade) / 100; 1131 c.g = c.g * (200 - shade) / 100;
1136 c.b = c.b * (200 - shade) / 100; 1132 c.b = c.b * (200 - shade) / 100;
1137 } 1133 }
1138 1134
1139 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1140 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1135 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1141 XRenderPictureAttributes pa;
1142 1136
1143 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1137 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1144 1138
1145 pa.repeat = True; 1139 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
1146 1140
1147 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1141 Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True);
1148 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1149 XFreePixmap (dpy, overlay_pmap);
1150
1151 pa.component_alpha = True;
1152 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1153 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1154 XFreePixmap (dpy, mask_pmap);
1155 1142
1156 XRenderColor mask_c; 1143 XRenderColor mask_c;
1157 1144
1158 mask_c.alpha = 0xffff; 1145 mask_c.alpha = 0xffff;
1159 mask_c.red = 1146 mask_c.red =
1164 mask_c.alpha = 0; 1151 mask_c.alpha = 0;
1165 mask_c.red = 0xffff - c.r; 1152 mask_c.red = 0xffff - c.r;
1166 mask_c.green = 0xffff - c.g; 1153 mask_c.green = 0xffff - c.g;
1167 mask_c.blue = 0xffff - c.b; 1154 mask_c.blue = 0xffff - c.b;
1168 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1155 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1156
1169 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1157 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1170 1158
1171 if (shade > 100) 1159 if (shade > 100)
1172 { 1160 {
1173 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1174 mask_c.alpha = 0; 1161 mask_c.alpha = 0;
1162 mask_c.red =
1163 mask_c.green =
1164 mask_c.blue = 0xffff * (shade - 100) / 100;
1175 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1165 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1176 1166
1177 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1167 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1178 } 1168 }
1179 1169
1180 ret = true; 1170 ret = true;
1181 1171
1182 XRenderFreePicture (dpy, mask_pic); 1172 XRenderFreePicture (dpy, mask_pic);
1183 XRenderFreePicture (dpy, overlay_pic); 1173 XRenderFreePicture (dpy, overlay_pic);
1184 XRenderFreePicture (dpy, back_pic); 1174 XRenderFreePicture (dpy, back_pic);
1175 }
1185# endif 1176# endif
1186 }
1187 1177
1188 return ret; 1178 return ret;
1189} 1179}
1190 1180
1191/* 1181/*
1242#if XRENDER 1232#if XRENDER
1243 if (bg_flags & BG_HAS_RENDER) 1233 if (bg_flags & BG_HAS_RENDER)
1244 { 1234 {
1245 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); 1235 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1246 1236
1247 XRenderPictureAttributes pa;
1248
1249 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1237 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1250 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1238 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1251 1239
1252 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 1240 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1253 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1241 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, 0);
1254 1242
1255 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); 1243 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1256 1244
1257 XRenderFreePicture (dpy, src); 1245 XRenderFreePicture (dpy, src);
1258 XRenderFreePicture (dpy, dst); 1246 XRenderFreePicture (dpy, dst);
1275 bg_pmap_width = window_width; 1263 bg_pmap_width = window_width;
1276 bg_pmap_height = window_height; 1264 bg_pmap_height = window_height;
1277 } 1265 }
1278 1266
1279 /* straightforward pixmap copy */ 1267 /* straightforward pixmap copy */
1280 while (sx < 0) sx += root_width; 1268 while (sx < 0) sx += root_pmap_width;
1281 while (sy < 0) sy += root_height; 1269 while (sy < 0) sy += root_pmap_height;
1282 1270
1283 gcv.tile = recoded_root_pmap; 1271 gcv.tile = recoded_root_pmap;
1284 gcv.fill_style = FillTiled; 1272 gcv.fill_style = FillTiled;
1285 gcv.ts_x_origin = -sx; 1273 gcv.ts_x_origin = -sx;
1286 gcv.ts_y_origin = -sy; 1274 gcv.ts_y_origin = -sy;
1288 1276
1289 if (gc) 1277 if (gc)
1290 { 1278 {
1291 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1279 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1292 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1280 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1293 XFreeGC (dpy, gc);
1294 1281
1295 if (!(bg_flags & BG_CLIENT_RENDER)) 1282 if (!(bg_flags & BG_CLIENT_RENDER))
1296 { 1283 {
1297 if ((bg_flags & BG_NEEDS_BLUR) 1284 if (bg_flags & BG_NEEDS_BLUR)
1298 && (bg_flags & BG_HAS_RENDER_CONV))
1299 { 1285 {
1300 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1286 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth))
1301 result &= ~BG_NEEDS_BLUR; 1287 result &= ~BG_NEEDS_BLUR;
1302 } 1288 }
1303 if ((bg_flags & BG_NEEDS_TINT) 1289 if (bg_flags & BG_NEEDS_TINT)
1304 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1305 { 1290 {
1306 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1291 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1307 result &= ~BG_NEEDS_TINT; 1292 result &= ~BG_NEEDS_TINT;
1308 } 1293 }
1294# ifndef HAVE_AFTERIMAGE
1295 if (result & BG_NEEDS_TINT)
1296 {
1297 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1298 if (ximage)
1299 {
1300 /* our own client-side tinting */
1301 tint_ximage (DefaultVisual (dpy, display->screen), ximage);
1302
1303 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1304 XDestroyImage (ximage);
1305 }
1306 }
1307# endif
1309 } /* server side rendering completed */ 1308 } /* server side rendering completed */
1309
1310 XFreeGC (dpy, gc);
1310 } 1311 }
1311 1312
1312 if (recoded_root_pmap != root_pixmap) 1313 if (recoded_root_pmap != root_pixmap)
1313 XFreePixmap (dpy, recoded_root_pmap); 1314 XFreePixmap (dpy, recoded_root_pmap);
1314 1315
1324 1325
1325 root_pixmap = new_root_pixmap; 1326 root_pixmap = new_root_pixmap;
1326} 1327}
1327# endif /* ENABLE_TRANSPARENCY */ 1328# endif /* ENABLE_TRANSPARENCY */
1328 1329
1329#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1330static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1331# endif
1332
1333bool 1330bool
1334rxvt_term::bg_render () 1331rxvt_term::bg_render ()
1335{ 1332{
1336 unsigned long tr_flags = 0; 1333 unsigned long tr_flags = 0;
1337 1334
1339# ifdef ENABLE_TRANSPARENCY 1336# ifdef ENABLE_TRANSPARENCY
1340 if (bg_flags & BG_IS_TRANSPARENT) 1337 if (bg_flags & BG_IS_TRANSPARENT)
1341 { 1338 {
1342 /* we need to re-generate transparency pixmap in that case ! */ 1339 /* we need to re-generate transparency pixmap in that case ! */
1343 tr_flags = make_transparency_pixmap (); 1340 tr_flags = make_transparency_pixmap ();
1344 if (tr_flags == 0) 1341 if (tr_flags)
1345 return false;
1346 else if (!(tr_flags & BG_EFFECTS_FLAGS))
1347 bg_flags |= BG_IS_VALID; 1342 bg_flags |= BG_IS_VALID;
1348 } 1343 }
1349# endif 1344# endif
1350 1345
1351# ifdef BG_IMAGE_FROM_FILE 1346# ifdef BG_IMAGE_FROM_FILE
1352 if ((bg_flags & BG_IS_FROM_FILE) 1347 if ((bg_flags & BG_IS_FROM_FILE)
1353 || (tr_flags & BG_EFFECTS_FLAGS)) 1348 || (tr_flags & BG_EFFECTS_FLAGS))
1354 { 1349 {
1355 if (render_image (tr_flags)) 1350 if (render_image (tr_flags))
1356 bg_flags |= BG_IS_VALID; 1351 bg_flags |= BG_IS_VALID;
1357 }
1358# endif
1359
1360# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1361 XImage *result = NULL;
1362
1363 if (tr_flags && !(bg_flags & BG_IS_VALID))
1364 {
1365 result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1366 }
1367
1368 if (result)
1369 {
1370 /* our own client-side tinting */
1371 if (tr_flags & BG_NEEDS_TINT)
1372 {
1373 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1374 if (bg_flags & BG_TINT_SET)
1375 tint.get (c);
1376 shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c);
1377 }
1378
1379 GC gc = XCreateGC (dpy, vt, 0UL, NULL);
1380
1381 if (gc)
1382 {
1383 XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1384
1385 XFreeGC (dpy, gc);
1386 bg_flags |= BG_IS_VALID;
1387 }
1388
1389 XDestroyImage (result);
1390 } 1352 }
1391# endif 1353# endif
1392 1354
1393 if (!(bg_flags & BG_IS_VALID)) 1355 if (!(bg_flags & BG_IS_VALID))
1394 { 1356 {
1427 bg_flags |= BG_HAS_RENDER_CONV; 1389 bg_flags |= BG_HAS_RENDER_CONV;
1428 1390
1429 XFree (filters); 1391 XFree (filters);
1430 } 1392 }
1431#endif 1393#endif
1432
1433#ifdef HAVE_AFTERIMAGE
1434 set_application_name ((char *)rs[Rs_name]);
1435 set_output_threshold (OUTPUT_LEVEL_WARNING);
1436#endif
1437
1438#ifdef HAVE_PIXBUF
1439 g_type_init ();
1440#endif
1441} 1394}
1442 1395
1443#endif /* HAVE_BG_PIXMAP */ 1396#endif /* HAVE_BG_PIXMAP */
1444 1397
1445#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1398#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1446/* taken from aterm-0.4.2 */ 1399/* based on code from aterm-0.4.2 */
1447 1400
1448static void 1401static inline void
1449shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) 1402fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1403{
1404 for (int i = 0; i <= mask >> sh; i++)
1405 {
1406 uint32_t tmp;
1407 tmp = i * high;
1408 tmp += (mask >> sh) * low;
1409 lookup[i] = (tmp / 0xffff) << sh;
1410 }
1411}
1412
1413void
1414rxvt_term::tint_ximage (Visual *visual, XImage *ximage)
1450{ 1415{
1451 int sh_r, sh_g, sh_b; 1416 int sh_r, sh_g, sh_b;
1452 uint32_t mask_r, mask_g, mask_b; 1417 uint32_t mask_r, mask_g, mask_b;
1453 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1418 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1454 rgba low; 1419 unsigned short low;
1455 rgba high;
1456 int i;
1457 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 1420 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1458 1421
1459 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1422 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1460 1423
1461 /* for convenience */ 1424 /* for convenience */
1520 break; 1483 break;
1521 default: 1484 default:
1522 return; /* we do not support this color depth */ 1485 return; /* we do not support this color depth */
1523 } 1486 }
1524 1487
1488 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1489
1490 if (bg_flags & BG_TINT_SET)
1491 tint.get (c);
1492
1525 /* prepare limits for color transformation (each channel is handled separately) */ 1493 /* prepare limits for color transformation (each channel is handled separately) */
1526 if (shade > 100) 1494 if (shade > 100)
1527 { 1495 {
1528 shade = 200 - shade;
1529
1530 high.r = c.r * shade / 100;
1531 high.g = c.g * shade / 100;
1532 high.b = c.b * shade / 100;
1533
1534 low.r = 65535 * (100 - shade) / 100; 1496 c.r = c.r * (200 - shade) / 100;
1535 low.g = 65535 * (100 - shade) / 100; 1497 c.g = c.g * (200 - shade) / 100;
1536 low.b = 65535 * (100 - shade) / 100; 1498 c.b = c.b * (200 - shade) / 100;
1499
1500 low = 0xffff * (shade - 100) / 100;
1537 } 1501 }
1538 else 1502 else
1539 { 1503 {
1540 high.r = c.r * shade / 100; 1504 c.r = c.r * shade / 100;
1541 high.g = c.g * shade / 100; 1505 c.g = c.g * shade / 100;
1542 high.b = c.b * shade / 100; 1506 c.b = c.b * shade / 100;
1543 1507
1544 low.r = low.g = low.b = 0; 1508 low = 0;
1545 } 1509 }
1546 1510
1547 /* fill our lookup tables */ 1511 /* fill our lookup tables */
1548 for (i = 0; i <= mask_r>>sh_r; i++) 1512 fill_lut (lookup_r, mask_r, sh_r, low, c.r);
1549 { 1513 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1550 uint32_t tmp; 1514 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1551 tmp = i * high.r;
1552 tmp += (mask_r>>sh_r) * low.r;
1553 lookup_r[i] = (tmp/65535)<<sh_r;
1554 }
1555 for (i = 0; i <= mask_g>>sh_g; i++)
1556 {
1557 uint32_t tmp;
1558 tmp = i * high.g;
1559 tmp += (mask_g>>sh_g) * low.g;
1560 lookup_g[i] = (tmp/65535)<<sh_g;
1561 }
1562 for (i = 0; i <= mask_b>>sh_b; i++)
1563 {
1564 uint32_t tmp;
1565 tmp = i * high.b;
1566 tmp += (mask_b>>sh_b) * low.b;
1567 lookup_b[i] = (tmp/65535)<<sh_b;
1568 }
1569 1515
1570 /* apply table to input image (replacing colors by newly calculated ones) */ 1516 /* apply table to input image (replacing colors by newly calculated ones) */
1571 if (ximage->bits_per_pixel == 32 1517 if (ximage->bits_per_pixel == 32
1572 && (ximage->depth == 24 || ximage->depth == 32) 1518 && (ximage->depth == 24 || ximage->depth == 32)
1573 && ximage->byte_order == host_byte_order) 1519 && ximage->byte_order == host_byte_order)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines