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.172 by sf-exg, Tue Aug 30 15:00:27 2011 UTC vs.
Revision 1.198 by sf-exg, Wed Jan 11 13:51:07 2012 UTC

32 32
33#ifndef FilterConvolution 33#ifndef FilterConvolution
34#define FilterConvolution "convolution" 34#define FilterConvolution "convolution"
35#endif 35#endif
36 36
37#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);
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;
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
1323 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); 1324 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
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#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1330static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1331# endif
1332 1329
1333bool 1330bool
1334rxvt_term::bg_render () 1331rxvt_term::bg_render ()
1335{ 1332{
1336 unsigned long tr_flags = 0; 1333 unsigned long tr_flags = 0;
1351 if ((bg_flags & BG_IS_FROM_FILE) 1348 if ((bg_flags & BG_IS_FROM_FILE)
1352 || (tr_flags & BG_EFFECTS_FLAGS)) 1349 || (tr_flags & BG_EFFECTS_FLAGS))
1353 { 1350 {
1354 if (render_image (tr_flags)) 1351 if (render_image (tr_flags))
1355 bg_flags |= BG_IS_VALID; 1352 bg_flags |= BG_IS_VALID;
1356 }
1357# endif
1358
1359# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1360 XImage *result = NULL;
1361
1362 if (tr_flags & BG_NEEDS_TINT)
1363 {
1364 result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1365 }
1366
1367 if (result)
1368 {
1369 /* our own client-side tinting */
1370 //if (tr_flags & BG_NEEDS_TINT)
1371 if (1)
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 }
1387
1388 XDestroyImage (result);
1389 } 1353 }
1390# endif 1354# endif
1391 1355
1392 if (!(bg_flags & BG_IS_VALID)) 1356 if (!(bg_flags & BG_IS_VALID))
1393 { 1357 {
1433#endif /* HAVE_BG_PIXMAP */ 1397#endif /* HAVE_BG_PIXMAP */
1434 1398
1435#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1399#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1436/* based on code from aterm-0.4.2 */ 1400/* based on code from aterm-0.4.2 */
1437 1401
1438static void 1402static inline void
1439shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) 1403fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1404{
1405 for (int i = 0; i <= mask >> sh; i++)
1406 {
1407 uint32_t tmp;
1408 tmp = i * high;
1409 tmp += (mask >> sh) * low;
1410 lookup[i] = (tmp / 0xffff) << sh;
1411 }
1412}
1413
1414void
1415rxvt_term::tint_ximage (Visual *visual, XImage *ximage)
1440{ 1416{
1441 int sh_r, sh_g, sh_b; 1417 int sh_r, sh_g, sh_b;
1442 uint32_t mask_r, mask_g, mask_b; 1418 uint32_t mask_r, mask_g, mask_b;
1443 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1419 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1444 rgba low; 1420 unsigned short low;
1445 rgba high;
1446 int i;
1447 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 1421 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1448 1422
1449 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1423 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1450 1424
1451 /* for convenience */ 1425 /* for convenience */
1510 break; 1484 break;
1511 default: 1485 default:
1512 return; /* we do not support this color depth */ 1486 return; /* we do not support this color depth */
1513 } 1487 }
1514 1488
1489 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1490
1491 if (bg_flags & BG_TINT_SET)
1492 tint.get (c);
1493
1515 /* prepare limits for color transformation (each channel is handled separately) */ 1494 /* prepare limits for color transformation (each channel is handled separately) */
1516 if (shade > 100) 1495 if (shade > 100)
1517 { 1496 {
1518 shade = 200 - shade;
1519
1520 high.r = c.r * shade / 100;
1521 high.g = c.g * shade / 100;
1522 high.b = c.b * shade / 100;
1523
1524 low.r = 65535 * (100 - shade) / 100; 1497 c.r = c.r * (200 - shade) / 100;
1525 low.g = 65535 * (100 - shade) / 100; 1498 c.g = c.g * (200 - shade) / 100;
1526 low.b = 65535 * (100 - shade) / 100; 1499 c.b = c.b * (200 - shade) / 100;
1500
1501 low = 0xffff * (shade - 100) / 100;
1527 } 1502 }
1528 else 1503 else
1529 { 1504 {
1530 high.r = c.r * shade / 100; 1505 c.r = c.r * shade / 100;
1531 high.g = c.g * shade / 100; 1506 c.g = c.g * shade / 100;
1532 high.b = c.b * shade / 100; 1507 c.b = c.b * shade / 100;
1533 1508
1534 low.r = low.g = low.b = 0; 1509 low = 0;
1535 } 1510 }
1536 1511
1537 /* fill our lookup tables */ 1512 /* fill our lookup tables */
1538 for (i = 0; i <= mask_r>>sh_r; i++) 1513 fill_lut (lookup_r, mask_r, sh_r, low, c.r);
1539 { 1514 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1540 uint32_t tmp; 1515 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1541 tmp = i * high.r;
1542 tmp += (mask_r>>sh_r) * low.r;
1543 lookup_r[i] = (tmp/65535)<<sh_r;
1544 }
1545 for (i = 0; i <= mask_g>>sh_g; i++)
1546 {
1547 uint32_t tmp;
1548 tmp = i * high.g;
1549 tmp += (mask_g>>sh_g) * low.g;
1550 lookup_g[i] = (tmp/65535)<<sh_g;
1551 }
1552 for (i = 0; i <= mask_b>>sh_b; i++)
1553 {
1554 uint32_t tmp;
1555 tmp = i * high.b;
1556 tmp += (mask_b>>sh_b) * low.b;
1557 lookup_b[i] = (tmp/65535)<<sh_b;
1558 }
1559 1516
1560 /* apply table to input image (replacing colors by newly calculated ones) */ 1517 /* apply table to input image (replacing colors by newly calculated ones) */
1561 if (ximage->bits_per_pixel == 32 1518 if (ximage->bits_per_pixel == 32
1562 && (ximage->depth == 24 || ximage->depth == 32) 1519 && (ximage->depth == 24 || ximage->depth == 32)
1563 && ximage->byte_order == host_byte_order) 1520 && ximage->byte_order == host_byte_order)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines