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.152 by sf-exg, Sun May 8 21:03:03 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/* 37#ifndef RepeatPad
38 * Pixmap geometry string interpretation : 38#define RepeatPad True
39 * Each geometry string contains zero or one scale/position 39#endif
40 * adjustment and may optionally be followed by a colon and one or more
41 * colon-delimited pixmap operations.
42 * The following table shows the valid geometry strings and their
43 * effects on the background image :
44 *
45 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
46 * W and H are percentages of the terminal window size.
47 * X and Y are also percentages; e.g., +50+50 centers
48 * the image in the window.
49 *
50 * Pixmap Operations : (should be prepended by a colon)
51 * tile Tile image. Scaling/position modifiers above will affect
52 * the tile size and origin.
53 * propscale When scaling, scale proportionally. That is, maintain the
54 * proper aspect ratio for the image. Any portion of the
55 * background not covered by the image is filled with the
56 * current background color.
57 * hscale Scale horizontally, tile vertically ?
58 * vscale Tile horizontally, scale vertically ?
59 * scale Scale both up and down
60 * auto Same as 100x100+50+50
61 */
62 40
63#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
64void 60void
65rxvt_term::bg_destroy () 61rxvt_term::bg_destroy ()
66{ 62{
67#ifdef HAVE_AFTERIMAGE 63#ifdef HAVE_AFTERIMAGE
68 if (original_asim) 64 if (original_asim)
133 129
134 return false; 130 return false;
135} 131}
136 132
137# ifdef BG_IMAGE_FROM_FILE 133# ifdef BG_IMAGE_FROM_FILE
138static inline bool
139check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value)
140{
141 if (geom_flags & flag)
142 {
143 if (new_value > 1000)
144 new_value = 1000;
145 if (new_value != scale)
146 {
147 scale = new_value;
148 return true;
149 }
150 }
151 return false;
152}
153
154static inline bool
155check_set_align_value (int geom_flags, int flag, int &align, int new_value)
156{
157 if (geom_flags & flag)
158 {
159 if (new_value < -100)
160 new_value = -100;
161 else if (new_value > 200)
162 new_value = 200;
163 if (new_value != align)
164 {
165 align = new_value;
166 return true;
167 }
168 }
169 return false;
170}
171
172static inline int 134static inline int
173make_align_position (int align, int window_size, int image_size) 135make_align_position (int align, int window_size, int image_size)
174{ 136{
175 int diff = window_size - image_size; 137 int diff = window_size - image_size;
176 int smaller = min (image_size, window_size); 138 int smaller = min (image_size, window_size);
177 139
178 if (align >= 0 && align <= 100) 140 if (align >= 0 && align <= 100)
179 return diff * align / 100; 141 return diff * align / 100;
180 else if (align > 100 && align <= 200) 142 else if (align > 100 && align <= 200)
181 return ((align - 100) * smaller / 100) + window_size - smaller; 143 return (align - 100) * smaller / 100 + window_size - smaller;
182 else if (align >= -100 && align < 0) 144 else if (align >= -100 && align < 0)
183 return ((align + 100) * smaller / 100) - image_size; 145 return (align + 100) * smaller / 100 - image_size;
184 return 0; 146 return 0;
185} 147}
186 148
187static inline int 149static inline int
188make_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)
195 src_pos = -pos; 157 src_pos = -pos;
196 dst_pos = 0; 158 dst_pos = 0;
197 dst_size += pos; 159 dst_size += pos;
198 } 160 }
199 161
200 if (dst_pos + dst_size > target_size)
201 dst_size = target_size - dst_pos; 162 min_it (dst_size, target_size - dst_pos);
202 return src_pos; 163 return src_pos;
203} 164}
204 165
205bool 166bool
206rxvt_term::bg_set_geometry (const char *geom, bool update) 167rxvt_term::bg_set_geometry (const char *geom, bool update)
207{ 168{
208 bool changed = false; 169 bool changed = false;
209 int geom_flags = 0; 170 int geom_flags = 0;
210 int x = 0, y = 0; 171 int x = h_align;
172 int y = v_align;
211 unsigned int w = 0, h = 0; 173 unsigned int w = h_scale;
212 unsigned int n; 174 unsigned int h = v_scale;
213 unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); 175 unsigned long new_flags = 0;
214 const char *ops;
215 176
216 if (geom == NULL) 177 if (geom == NULL)
217 return false; 178 return false;
218 179
219 char str[256]; 180 if (geom[0])
220
221 ops = strchr (geom, ':');
222 if (ops == NULL)
223 n = strlen (geom);
224 else
225 n = ops - geom;
226
227 if (n >= sizeof (str))
228 return false;
229
230 memcpy (str, geom, n);
231 str[n] = '\0';
232 rxvt_strtrim (str);
233
234 if (str[0])
235 { 181 {
236 /* we have geometry string - let's handle it prior to applying ops */ 182 char **arr = rxvt_strsplit (':', geom);
183
184 for (int i = 0; arr[i]; i++)
185 {
186 if (!strcasecmp (arr[i], "style=tiled"))
187 {
188 new_flags = BG_TILE;
189 w = h = noScale;
190 x = y = 0;
191 geom_flags = WidthValue|HeightValue|XValue|YValue;
192 }
193 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
194 {
195 new_flags = BG_KEEP_ASPECT;
196 w = h = windowScale;
197 x = y = centerAlign;
198 geom_flags = WidthValue|HeightValue|XValue|YValue;
199 }
200 else if (!strcasecmp (arr[i], "style=stretched"))
201 {
202 new_flags = 0;
203 w = h = windowScale;
204 geom_flags = WidthValue|HeightValue;
205 }
206 else if (!strcasecmp (arr[i], "style=centered"))
207 {
208 new_flags = 0;
209 w = h = noScale;
210 x = y = centerAlign;
211 geom_flags = WidthValue|HeightValue|XValue|YValue;
212 }
213 else if (!strcasecmp (arr[i], "style=root-tiled"))
214 {
215 new_flags = BG_TILE|BG_ROOT_ALIGN;
216 w = h = noScale;
217 geom_flags = WidthValue|HeightValue;
218 }
219 else if (!strcasecmp (arr[i], "op=tile"))
220 new_flags |= BG_TILE;
221 else if (!strcasecmp (arr[i], "op=keep-aspect"))
222 new_flags |= BG_KEEP_ASPECT;
223 else if (!strcasecmp (arr[i], "op=root-align"))
224 new_flags |= BG_ROOT_ALIGN;
225
226 // deprecated
227 else if (!strcasecmp (arr[i], "tile"))
228 {
229 new_flags |= BG_TILE;
230 w = h = noScale;
231 geom_flags |= WidthValue|HeightValue;
232 }
233 else if (!strcasecmp (arr[i], "propscale"))
234 {
235 new_flags |= BG_KEEP_ASPECT;
236 w = h = windowScale;
237 geom_flags |= WidthValue|HeightValue;
238 }
239 else if (!strcasecmp (arr[i], "hscale"))
240 {
241 new_flags |= BG_TILE;
242 w = windowScale;
243 h = noScale;
244 geom_flags |= WidthValue|HeightValue;
245 }
246 else if (!strcasecmp (arr[i], "vscale"))
247 {
248 new_flags |= BG_TILE;
249 h = windowScale;
250 w = noScale;
251 geom_flags |= WidthValue|HeightValue;
252 }
253 else if (!strcasecmp (arr[i], "scale"))
254 {
255 w = h = windowScale;
256 geom_flags |= WidthValue|HeightValue;
257 }
258 else if (!strcasecmp (arr[i], "auto"))
259 {
260 w = h = windowScale;
261 x = y = centerAlign;
262 geom_flags |= WidthValue|HeightValue|XValue|YValue;
263 }
264 else if (!strcasecmp (arr[i], "root"))
265 {
266 new_flags |= BG_TILE|BG_ROOT_ALIGN;
267 w = h = noScale;
268 geom_flags |= WidthValue|HeightValue;
269 }
270
271 else
237 geom_flags = XParseGeometry (str, &x, &y, &w, &h); 272 geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h);
238 } /* done parsing geometry string */ 273 } /* done parsing ops */
274
275 rxvt_free_strsplit (arr);
276 }
277
278 new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS;
239 279
240 if (!update) 280 if (!update)
241 { 281 {
242 if (!(geom_flags & XValue)) 282 if (!(geom_flags & XValue))
243 x = y = defaultAlign; 283 x = y = defaultAlign;
248 w = h = defaultScale; 288 w = h = defaultScale;
249 else if (!(geom_flags & HeightValue)) 289 else if (!(geom_flags & HeightValue))
250 h = w; 290 h = w;
251 else if (!(geom_flags & WidthValue)) 291 else if (!(geom_flags & WidthValue))
252 w = h; 292 w = h;
253
254 geom_flags |= WidthValue|HeightValue|XValue|YValue;
255 }
256
257 if (ops)
258 { 293 }
259 char **arr = rxvt_strsplit (':', ops + 1);
260 294
261 for (int i = 0; arr[i]; i++) 295 min_it (w, 1000);
262 { 296 min_it (h, 1000);
263 if (!strcasecmp (arr[i], "tile")) 297 clamp_it (x, -100, 200);
264 { 298 clamp_it (y, -100, 200);
265 w = h = noScale;
266 geom_flags |= WidthValue|HeightValue;
267 }
268 else if (!strcasecmp (arr[i], "propscale"))
269 {
270 new_flags |= BG_PROP_SCALE;
271 }
272 else if (!strcasecmp (arr[i], "hscale"))
273 {
274 if (w == 0) w = windowScale;
275 299
276 h = noScale; 300 if (bg_flags != new_flags
277 geom_flags |= WidthValue|HeightValue; 301 || h_scale != w
278 } 302 || v_scale != h
279 else if (!strcasecmp (arr[i], "vscale")) 303 || h_align != x
280 { 304 || v_align != y)
281 if (h == 0) h = windowScale;
282
283 w = noScale;
284 geom_flags |= WidthValue|HeightValue;
285 }
286 else if (!strcasecmp (arr[i], "scale"))
287 {
288 if (h == 0) h = windowScale;
289 if (w == 0) w = windowScale;
290
291 geom_flags |= WidthValue|HeightValue;
292 }
293 else if (!strcasecmp (arr[i], "auto"))
294 {
295 w = h = windowScale;
296 x = y = centerAlign;
297 geom_flags |= WidthValue|HeightValue|XValue|YValue;
298 }
299 else if (!strcasecmp (arr[i], "root"))
300 {
301 new_flags |= BG_ROOT_ALIGN;
302 w = h = noScale;
303 geom_flags |= WidthValue|HeightValue;
304 }
305 } /* done parsing ops */
306
307 rxvt_free_strsplit (arr);
308 }
309
310 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
311 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
312 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
313 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
314
315 if (new_flags != bg_flags)
316 { 305 {
317 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;
318 changed = true; 311 changed = true;
319 } 312 }
320 313
321 return changed; 314 return changed;
322} 315}
325rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 318rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
326{ 319{
327 int target_width = szHint.width; 320 int target_width = szHint.width;
328 int target_height = szHint.height; 321 int target_height = szHint.height;
329 322
323 w = h_scale * target_width / 100;
324 h = v_scale * target_height / 100;
325
330 if (bg_flags & BG_PROP_SCALE) 326 if (bg_flags & BG_KEEP_ASPECT)
331 { 327 {
332 float scale = (float)target_width / image_width; 328 float scale = (float)w / image_width;
333 min_it (scale, (float)target_height / image_height); 329 min_it (scale, (float)h / image_height);
334 w = image_width * scale + 0.5; 330 w = image_width * scale + 0.5;
335 h = image_height * scale + 0.5; 331 h = image_height * scale + 0.5;
336 } 332 }
337 else
338 {
339 w = h_scale * target_width / 100;
340 h = v_scale * target_height / 100;
341 }
342 333
343 if (!w) w = image_width; 334 if (!w) w = image_width;
344 if (!h) h = image_height; 335 if (!h) h = image_height;
345 336
346 if (bg_flags & BG_ROOT_ALIGN) 337 if (bg_flags & BG_ROOT_ALIGN)
353 x = make_align_position (h_align, target_width, w); 344 x = make_align_position (h_align, target_width, w);
354 y = make_align_position (v_align, target_height, h); 345 y = make_align_position (v_align, target_height, h);
355 } 346 }
356 347
357 bg_flags &= ~BG_IS_SIZE_SENSITIVE; 348 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
358 if ((bg_flags & BG_PROP_SCALE) || h_scale || v_scale 349 if (!(bg_flags & BG_TILE)
350 || h_scale || v_scale
359 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) 351 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
360 || w > target_width || h > target_height) 352 || w > target_width || h > target_height)
361 bg_flags |= BG_IS_SIZE_SENSITIVE; 353 bg_flags |= BG_IS_SIZE_SENSITIVE;
362} 354}
363 355
390 } 382 }
391 383
392 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) 384 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL)
393 { 385 {
394 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,
395 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, 387 ASA_XImage,
396 100, ASIMAGE_QUALITY_DEFAULT); 388 100, ASIMAGE_QUALITY_DEFAULT);
397 if (tmp) 389 if (tmp)
398 { 390 {
399 destroy_asimage (&background); 391 destroy_asimage (&background);
400 background = tmp; 392 background = tmp;
419 411
420 if (!original_asim 412 if (!original_asim
421 || (!(bg_flags & BG_ROOT_ALIGN) 413 || (!(bg_flags & BG_ROOT_ALIGN)
422 && (x >= target_width 414 && (x >= target_width
423 || y >= target_height 415 || y >= target_height
424 || (x + w <= 0) 416 || x + w <= 0
425 || (y + h <= 0)))) 417 || y + h <= 0)))
426 { 418 {
427 if (background) 419 if (background)
428 { 420 {
429 new_pmap_width = background->width; 421 new_pmap_width = background->width;
430 new_pmap_height = background->height; 422 new_pmap_height = background->height;
444 } 436 }
445 else 437 else
446 { 438 {
447 result = original_asim; 439 result = original_asim;
448 440
449 if ((w != original_asim->width) 441 if (w != original_asim->width
450 || (h != original_asim->height)) 442 || h != original_asim->height)
451 { 443 {
452 result = scale_asimage (asv, original_asim, 444 result = scale_asimage (asv, original_asim,
453 w, h, 445 w, h,
454 background ? ASA_ASImage : ASA_XImage, 446 ASA_XImage,
455 100, ASIMAGE_QUALITY_DEFAULT); 447 100, ASIMAGE_QUALITY_DEFAULT);
456 } 448 }
457 449
458 if (background == NULL) 450 if (background == NULL)
459 { 451 {
460 if (h_scale == 0 || v_scale == 0) 452 if (bg_flags & BG_TILE)
461 { 453 {
462 /* if tiling - pixmap has to be sized exactly as the image, 454 /* if tiling - pixmap has to be sized exactly as the image,
463 but there is no need to make it bigger than the window! */ 455 but there is no need to make it bigger than the window! */
464 new_pmap_width = min (result->width, target_width); 456 new_pmap_width = min (result->width, target_width);
465 new_pmap_height = min (result->height, target_height); 457 new_pmap_height = min (result->height, target_height);
490 layers[0].clip_width = target_width; 482 layers[0].clip_width = target_width;
491 layers[0].clip_height = target_height; 483 layers[0].clip_height = target_height;
492 layers[0].tint = background_tint; 484 layers[0].tint = background_tint;
493 layers[1].im = result; 485 layers[1].im = result;
494 486
495 if (h_scale == 0 || v_scale == 0) 487 if (bg_flags & BG_TILE)
496 { 488 {
497 /* tile horizontally */ 489 /* tile horizontally */
498 while (x > 0) x -= (int)result->width; 490 while (x > 0) x -= (int)result->width;
499 layers[1].dst_x = x; 491 layers[1].dst_x = x;
500 layers[1].clip_width = result->width+target_width; 492 layers[1].clip_width = result->width+target_width;
504 /* clip horizontally */ 496 /* clip horizontally */
505 layers[1].dst_x = x; 497 layers[1].dst_x = x;
506 layers[1].clip_width = result->width; 498 layers[1].clip_width = result->width;
507 } 499 }
508 500
509 if (h_scale == 0 || v_scale == 0) 501 if (bg_flags & BG_TILE)
510 { 502 {
511 while (y > 0) y -= (int)result->height; 503 while (y > 0) y -= (int)result->height;
512 layers[1].dst_y = y; 504 layers[1].dst_y = y;
513 layers[1].clip_height = result->height + target_height; 505 layers[1].clip_height = result->height + target_height;
514 } 506 }
564 556
565 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 557 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
566 int dst_width = result->width, dst_height = result->height; 558 int dst_width = result->width, dst_height = result->height;
567 if (background == NULL) 559 if (background == NULL)
568 { 560 {
569 if (!(h_scale == 0 || v_scale == 0)) 561 if (!(bg_flags & BG_TILE))
570 { 562 {
571 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); 563 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
572 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 564 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
573 } 565 }
574 566
620 else if (depth == 15 || depth == 16) 612 else if (depth == 15 || depth == 16)
621 bytes_per_pixel = 2; 613 bytes_per_pixel = 2;
622 else 614 else
623 return false; 615 return false;
624 616
625 width_r = rxvt_popcount (visual->red_mask); 617 width_r = ecb_popcount32 (visual->red_mask);
626 width_g = rxvt_popcount (visual->green_mask); 618 width_g = ecb_popcount32 (visual->green_mask);
627 width_b = rxvt_popcount (visual->blue_mask); 619 width_b = ecb_popcount32 (visual->blue_mask);
628 620
629 if (width_r > 8 || width_g > 8 || width_b > 8) 621 if (width_r > 8 || width_g > 8 || width_b > 8)
630 return false; 622 return false;
631 623
632 sh_r = rxvt_ctz (visual->red_mask); 624 sh_r = ecb_ctz32 (visual->red_mask);
633 sh_g = rxvt_ctz (visual->green_mask); 625 sh_g = ecb_ctz32 (visual->green_mask);
634 sh_b = rxvt_ctz (visual->blue_mask); 626 sh_b = ecb_ctz32 (visual->blue_mask);
635 627
636 if (width > INT_MAX / height / bytes_per_pixel) 628 if (width > INT_MAX / height / bytes_per_pixel)
637 return false; 629 return false;
638 630
639 data = (char *)malloc (width * height * bytes_per_pixel); 631 data = (char *)malloc (width * height * bytes_per_pixel);
646 { 638 {
647 free (data); 639 free (data);
648 return false; 640 return false;
649 } 641 }
650 642
651 ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; 643 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
652 644
653 rowstride = gdk_pixbuf_get_rowstride (pixbuf); 645 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
654 channels = gdk_pixbuf_get_n_channels (pixbuf); 646 channels = gdk_pixbuf_get_n_channels (pixbuf);
655 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; 647 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
656 line = data; 648 line = data;
709 get_image_geometry (image_width, image_height, w, h, x, y); 701 get_image_geometry (image_width, image_height, w, h, x, y);
710 702
711 if (!(bg_flags & BG_ROOT_ALIGN) 703 if (!(bg_flags & BG_ROOT_ALIGN)
712 && (x >= target_width 704 && (x >= target_width
713 || y >= target_height 705 || y >= target_height
714 || (x + w <= 0) 706 || x + w <= 0
715 || (y + h <= 0))) 707 || y + h <= 0))
716 return false; 708 return false;
717 709
718 result = pixbuf; 710 result = pixbuf;
719 711
720 if ((w != image_width) 712 if (w != image_width
721 || (h != image_height)) 713 || h != image_height)
722 { 714 {
723 result = gdk_pixbuf_scale_simple (pixbuf, 715 result = gdk_pixbuf_scale_simple (pixbuf,
724 w, h, 716 w, h,
725 GDK_INTERP_BILINEAR); 717 GDK_INTERP_BILINEAR);
726 } 718 }
742 root_pmap = bg_pixmap; 734 root_pmap = bg_pixmap;
743 bg_pixmap = None; 735 bg_pixmap = None;
744 } 736 }
745 else 737 else
746 { 738 {
747 if (h_scale == 0 || v_scale == 0) 739 if (bg_flags & BG_TILE)
748 { 740 {
749 new_pmap_width = min (image_width, target_width); 741 new_pmap_width = min (image_width, target_width);
750 new_pmap_height = min (image_height, target_height); 742 new_pmap_height = min (image_height, target_height);
751 } 743 }
752 } 744 }
760 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); 752 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
761 bg_pmap_width = new_pmap_width; 753 bg_pmap_width = new_pmap_width;
762 bg_pmap_height = new_pmap_height; 754 bg_pmap_height = new_pmap_height;
763 } 755 }
764 756
765 if (bg_pixmap != None)
766 {
767 gcv.foreground = pix_colors[Color_bg]; 757 gcv.foreground = pix_colors[Color_bg];
768 gc = XCreateGC (dpy, vt, GCForeground, &gcv); 758 gc = XCreateGC (dpy, vt, GCForeground, &gcv);
769 759
770 if (gc) 760 if (gc)
771 { 761 {
772 if (h_scale == 0 || v_scale == 0) 762 if (bg_flags & BG_TILE)
773 { 763 {
774 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); 764 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth);
775
776 if (tile != None)
777 {
778 pixbuf_to_pixmap (result, tile, gc, 765 pixbuf_to_pixmap (result, tile, gc,
779 0, 0, 766 0, 0,
780 0, 0, 767 0, 0,
781 image_width, image_height); 768 image_width, image_height);
782 769
783 gcv.tile = tile; 770 gcv.tile = tile;
784 gcv.fill_style = FillTiled; 771 gcv.fill_style = FillTiled;
785 gcv.ts_x_origin = x; 772 gcv.ts_x_origin = x;
786 gcv.ts_y_origin = y; 773 gcv.ts_y_origin = y;
787 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 774 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
788 775
789 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 776 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
790 XFreePixmap (dpy, tile); 777 XFreePixmap (dpy, tile);
791 }
792 } 778 }
793 else 779 else
794 { 780 {
795 int src_x, src_y, dst_x, dst_y; 781 int src_x, src_y, dst_x, dst_y;
796 int dst_width, dst_height; 782 int dst_width, dst_height;
797 783
798 src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width ); 784 src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width );
799 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); 785 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
800 786
801 if (dst_x > 0 || dst_y > 0 787 if (dst_x > 0 || dst_y > 0
802 || dst_x + dst_width < new_pmap_width 788 || dst_x + dst_width < new_pmap_width
803 || dst_y + dst_height < new_pmap_height) 789 || dst_y + dst_height < new_pmap_height)
804 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 790 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
805 791
806 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 792 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
807 pixbuf_to_pixmap (result, bg_pixmap, gc, 793 pixbuf_to_pixmap (result, bg_pixmap, gc,
808 src_x, src_y, 794 src_x, src_y,
809 dst_x, dst_y, 795 dst_x, dst_y,
810 dst_width, dst_height); 796 dst_width, dst_height);
811 } 797 }
812 798
813#if XRENDER 799#if XRENDER
814 if (tr_flags) 800 if (tr_flags)
815 { 801 {
816 XRenderPictureAttributes pa;
817
818 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); 802 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
803
819 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 804 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0);
820 805
821 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
822 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); 806 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
823 807
824 pa.repeat = True; 808 Picture mask = create_xrender_mask (dpy, vt, False, False);
825 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
826 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
827 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
828 XFreePixmap (dpy, mask_pmap);
829 809
830 if (src && dst && mask)
831 {
832 XRenderColor mask_c; 810 XRenderColor mask_c;
833 811
834 mask_c.alpha = 0x8000; 812 mask_c.alpha = 0x8000;
835 mask_c.red = 0; 813 mask_c.red =
836 mask_c.green = 0; 814 mask_c.green =
837 mask_c.blue = 0; 815 mask_c.blue = 0;
838 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 816 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
817
839 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);
840 }
841 819
842 XRenderFreePicture (dpy, src); 820 XRenderFreePicture (dpy, src);
843 XRenderFreePicture (dpy, dst); 821 XRenderFreePicture (dpy, dst);
844 XRenderFreePicture (dpy, mask); 822 XRenderFreePicture (dpy, mask);
845 } 823 }
846#endif 824#endif
847 825
848 XFreeGC (dpy, gc); 826 XFreeGC (dpy, gc);
849 827
850 ret = true; 828 ret = true;
851 }
852 } 829 }
853 830
854 if (result != pixbuf) 831 if (result != pixbuf)
855 g_object_unref (result); 832 g_object_unref (result);
856 833
865rxvt_term::bg_set_file (const char *file) 842rxvt_term::bg_set_file (const char *file)
866{ 843{
867 if (!file || !*file) 844 if (!file || !*file)
868 return false; 845 return false;
869 846
847 bool ret = false;
870 if (const char *p = strchr (file, ';')) 848 const char *p = strchr (file, ';');
849
850 if (p)
871 { 851 {
872 size_t len = p - file; 852 size_t len = p - file;
873 char *f = rxvt_temp_buf<char> (len + 1); 853 char *f = rxvt_temp_buf<char> (len + 1);
874 memcpy (f, file, len); 854 memcpy (f, file, len);
875 f[len] = '\0'; 855 f[len] = '\0';
884 { 864 {
885 if (original_asim) 865 if (original_asim)
886 safe_asimage_destroy (original_asim); 866 safe_asimage_destroy (original_asim);
887 original_asim = image; 867 original_asim = image;
888 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; 868 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER;
889 return true; 869 ret = true;
890 } 870 }
891# endif 871# endif
892 872
893# ifdef HAVE_PIXBUF 873# ifdef HAVE_PIXBUF
894 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 874 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
896 { 876 {
897 if (pixbuf) 877 if (pixbuf)
898 g_object_unref (pixbuf); 878 g_object_unref (pixbuf);
899 pixbuf = image; 879 pixbuf = image;
900 bg_flags |= BG_IS_FROM_FILE; 880 bg_flags |= BG_IS_FROM_FILE;
901 return true; 881 ret = true;
902 } 882 }
903# endif 883# endif
904 884
885 if (ret)
886 {
887 if (p)
888 bg_set_geometry (p + 1);
889 else
890 bg_set_default_geometry ();
891 }
892
905 return false; 893 return ret;
906} 894}
907 895
908# endif /* BG_IMAGE_FROM_FILE */ 896# endif /* BG_IMAGE_FROM_FILE */
909 897
910# ifdef ENABLE_TRANSPARENCY 898# ifdef ENABLE_TRANSPARENCY
946 { 934 {
947 changed = true; 935 changed = true;
948 v_blurRadius = vr; 936 v_blurRadius = vr;
949 } 937 }
950 938
951 if (v_blurRadius == 0 && h_blurRadius == 0) 939 if (h_blurRadius == 0 || v_blurRadius == 0)
952 bg_flags &= ~BG_NEEDS_BLUR; 940 bg_flags &= ~BG_NEEDS_BLUR;
953 else 941 else
954 bg_flags |= BG_NEEDS_BLUR; 942 bg_flags |= BG_NEEDS_BLUR;
955 943
956 return changed; 944 return changed;
957} 945}
958 946
959void 947void
960rxvt_term::set_tint_shade_flags () 948rxvt_term::set_tint_shade_flags ()
961{ 949{
962 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 950 rgba c;
963 bool has_shade = shade != 100; 951 bool has_shade = shade != 100;
964 952
965 bg_flags &= ~BG_TINT_FLAGS; 953 bg_flags &= ~BG_TINT_FLAGS;
966 954
967 if (bg_flags & BG_TINT_SET) 955 if (bg_flags & BG_TINT_SET)
993} 981}
994 982
995bool 983bool
996rxvt_term::bg_set_shade (const char *shade_str) 984rxvt_term::bg_set_shade (const char *shade_str)
997{ 985{
998 int new_shade = (shade_str) ? atoi (shade_str) : 100; 986 int new_shade = atoi (shade_str);
999 987
1000 clamp_it (new_shade, -100, 200); 988 clamp_it (new_shade, -100, 200);
1001 if (new_shade < 0) 989 if (new_shade < 0)
1002 new_shade = 200 - (100 + new_shade); 990 new_shade = 200 - (100 + new_shade);
1003 991
1033 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1021 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1034} 1022}
1035#endif 1023#endif
1036 1024
1037bool 1025bool
1038rxvt_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)
1039{ 1027{
1040 bool ret = false; 1028 bool ret = false;
1041#if XRENDER 1029#if XRENDER
1030 if (!(bg_flags & BG_HAS_RENDER_CONV))
1031 return false;
1032
1042 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1033 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1043 double *kernel = (double *)malloc (size * sizeof (double)); 1034 double *kernel = (double *)malloc (size * sizeof (double));
1044 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1035 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1045 1036
1046 XRenderPictureAttributes pa; 1037 XRenderPictureAttributes pa;
1047 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1038 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1048 1039
1040 pa.repeat = RepeatPad;
1049 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);
1050 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1043 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
1044 XFreePixmap (dpy, tmp);
1051 1045
1052 if (kernel && params && src && dst) 1046 if (kernel && params)
1053 { 1047 {
1054 if (h_blurRadius)
1055 {
1056 size = h_blurRadius * 2 + 1; 1048 size = h_blurRadius * 2 + 1;
1057 get_gaussian_kernel (h_blurRadius, size, kernel, params); 1049 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1058 1050
1059 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1051 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1060 XRenderComposite (dpy, 1052 XRenderComposite (dpy,
1061 PictOpSrc, 1053 PictOpSrc,
1062 src, 1054 src,
1063 None, 1055 None,
1064 dst, 1056 dst,
1065 0, 0, 1057 0, 0,
1066 0, 0, 1058 0, 0,
1067 0, 0, 1059 0, 0,
1068 width, height); 1060 width, height);
1069 }
1070 1061
1071 if (v_blurRadius) 1062 ::swap (src, dst);
1072 { 1063
1073 size = v_blurRadius * 2 + 1; 1064 size = v_blurRadius * 2 + 1;
1074 get_gaussian_kernel (v_blurRadius, size, kernel, params); 1065 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1075 ::swap (params[0], params[1]); 1066 ::swap (params[0], params[1]);
1076 1067
1077 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1068 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1078 XRenderComposite (dpy, 1069 XRenderComposite (dpy,
1079 PictOpSrc, 1070 PictOpSrc,
1080 src, 1071 src,
1081 None, 1072 None,
1082 dst, 1073 dst,
1083 0, 0, 1074 0, 0,
1084 0, 0, 1075 0, 0,
1085 0, 0, 1076 0, 0,
1086 width, height); 1077 width, height);
1087 }
1088 1078
1089 ret = true; 1079 ret = true;
1090 } 1080 }
1091 1081
1092 free (kernel); 1082 free (kernel);
1119 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); 1109 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1120 ret = true; 1110 ret = true;
1121 XFreeGC (dpy, gc); 1111 XFreeGC (dpy, gc);
1122 } 1112 }
1123 } 1113 }
1124 else
1125 {
1126# if XRENDER 1114# if XRENDER
1115 else if (bg_flags & BG_HAS_RENDER)
1116 {
1127 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1117 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1128 1118
1129 if (bg_flags & BG_TINT_SET) 1119 if (bg_flags & BG_TINT_SET)
1130 tint.get (c); 1120 tint.get (c);
1131 1121
1140 c.r = c.r * (200 - shade) / 100; 1130 c.r = c.r * (200 - shade) / 100;
1141 c.g = c.g * (200 - shade) / 100; 1131 c.g = c.g * (200 - shade) / 100;
1142 c.b = c.b * (200 - shade) / 100; 1132 c.b = c.b * (200 - shade) / 100;
1143 } 1133 }
1144 1134
1145 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1146 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1135 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1147 XRenderPictureAttributes pa;
1148 1136
1149 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1137 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1150 1138
1151 pa.repeat = True; 1139 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
1152 1140
1153 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1141 Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True);
1154 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1155 XFreePixmap (dpy, overlay_pmap);
1156 1142
1157 pa.component_alpha = True;
1158 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1159 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1160 XFreePixmap (dpy, mask_pmap);
1161
1162 if (mask_pic && overlay_pic && back_pic)
1163 {
1164 XRenderColor mask_c; 1143 XRenderColor mask_c;
1165 1144
1166 mask_c.alpha = 0xffff; 1145 mask_c.alpha = 0xffff;
1146 mask_c.red =
1147 mask_c.green =
1148 mask_c.blue = 0;
1149 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1150
1151 mask_c.alpha = 0;
1152 mask_c.red = 0xffff - c.r;
1153 mask_c.green = 0xffff - c.g;
1154 mask_c.blue = 0xffff - c.b;
1155 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1156
1157 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1158
1159 if (shade > 100)
1160 {
1161 mask_c.alpha = 0;
1167 mask_c.red = 1162 mask_c.red =
1168 mask_c.green = 1163 mask_c.green =
1169 mask_c.blue = 0; 1164 mask_c.blue = 0xffff * (shade - 100) / 100;
1170 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1165 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1171 1166
1172 mask_c.alpha = 0;
1173 mask_c.red = 0xffff - c.r;
1174 mask_c.green = 0xffff - c.g;
1175 mask_c.blue = 0xffff - c.b;
1176 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1177 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1178
1179 if (shade > 100)
1180 {
1181 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1182 mask_c.alpha = 0;
1183 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1184
1185 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);
1186 } 1168 }
1187 1169
1188 ret = true; 1170 ret = true;
1189 }
1190 1171
1191 XRenderFreePicture (dpy, mask_pic); 1172 XRenderFreePicture (dpy, mask_pic);
1192 XRenderFreePicture (dpy, overlay_pic); 1173 XRenderFreePicture (dpy, overlay_pic);
1193 XRenderFreePicture (dpy, back_pic); 1174 XRenderFreePicture (dpy, back_pic);
1175 }
1194# endif 1176# endif
1195 }
1196 1177
1197 return ret; 1178 return ret;
1198} 1179}
1199 1180
1200/* 1181/*
1251#if XRENDER 1232#if XRENDER
1252 if (bg_flags & BG_HAS_RENDER) 1233 if (bg_flags & BG_HAS_RENDER)
1253 { 1234 {
1254 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);
1255 1236
1256 if (recoded_root_pmap != None)
1257 {
1258 XRenderPictureAttributes pa;
1259
1260 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1237 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1261 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1238 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1262 1239
1263 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 1240 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1264 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1241 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, 0);
1265 1242
1266 if (src && dst)
1267 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);
1268 else
1269 {
1270 XFreePixmap (dpy, recoded_root_pmap);
1271 recoded_root_pmap = None;
1272 }
1273 1244
1274 XRenderFreePicture (dpy, src); 1245 XRenderFreePicture (dpy, src);
1275 XRenderFreePicture (dpy, dst); 1246 XRenderFreePicture (dpy, dst);
1276 }
1277 } 1247 }
1278 else 1248 else
1279#endif 1249#endif
1280 recoded_root_pmap = None; 1250 recoded_root_pmap = None;
1281 } 1251 }
1292 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); 1262 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth);
1293 bg_pmap_width = window_width; 1263 bg_pmap_width = window_width;
1294 bg_pmap_height = window_height; 1264 bg_pmap_height = window_height;
1295 } 1265 }
1296 1266
1297 if (bg_pixmap != None)
1298 {
1299 /* straightforward pixmap copy */ 1267 /* straightforward pixmap copy */
1300 while (sx < 0) sx += (int)root_width; 1268 while (sx < 0) sx += root_pmap_width;
1301 while (sy < 0) sy += (int)root_height; 1269 while (sy < 0) sy += root_pmap_height;
1302 1270
1303 gcv.tile = recoded_root_pmap; 1271 gcv.tile = recoded_root_pmap;
1304 gcv.fill_style = FillTiled; 1272 gcv.fill_style = FillTiled;
1305 gcv.ts_x_origin = -sx; 1273 gcv.ts_x_origin = -sx;
1306 gcv.ts_y_origin = -sy; 1274 gcv.ts_y_origin = -sy;
1307 gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1275 gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1308 1276
1309 if (gc) 1277 if (gc)
1310 { 1278 {
1311 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1279 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1312 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1280 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1313 XFreeGC (dpy, gc);
1314 1281
1315 if (!(bg_flags & BG_CLIENT_RENDER)) 1282 if (!(bg_flags & BG_CLIENT_RENDER))
1316 { 1283 {
1317 if ((bg_flags & BG_NEEDS_BLUR) 1284 if (bg_flags & BG_NEEDS_BLUR)
1318 && (bg_flags & BG_HAS_RENDER_CONV)) 1285 {
1286 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth))
1287 result &= ~BG_NEEDS_BLUR;
1288 }
1289 if (bg_flags & BG_NEEDS_TINT)
1290 {
1291 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1292 result &= ~BG_NEEDS_TINT;
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)
1319 { 1299 {
1320 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1300 /* our own client-side tinting */
1321 result &= ~BG_NEEDS_BLUR; 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);
1322 } 1305 }
1323 if ((bg_flags & BG_NEEDS_TINT)
1324 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1325 {
1326 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1327 result &= ~BG_NEEDS_TINT;
1328 } 1306 }
1307# endif
1329 } /* server side rendering completed */ 1308 } /* server side rendering completed */
1330 } 1309
1310 XFreeGC (dpy, gc);
1331 } 1311 }
1332 1312
1333 if (recoded_root_pmap != root_pixmap) 1313 if (recoded_root_pmap != root_pixmap)
1334 XFreePixmap (dpy, recoded_root_pmap); 1314 XFreePixmap (dpy, recoded_root_pmap);
1335 1315
1344 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); 1324 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1345 1325
1346 root_pixmap = new_root_pixmap; 1326 root_pixmap = new_root_pixmap;
1347} 1327}
1348# endif /* ENABLE_TRANSPARENCY */ 1328# endif /* ENABLE_TRANSPARENCY */
1349
1350#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1351static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1352# endif
1353 1329
1354bool 1330bool
1355rxvt_term::bg_render () 1331rxvt_term::bg_render ()
1356{ 1332{
1357 unsigned long tr_flags = 0; 1333 unsigned long tr_flags = 0;
1362 { 1338 {
1363 /* we need to re-generate transparency pixmap in that case ! */ 1339 /* we need to re-generate transparency pixmap in that case ! */
1364 tr_flags = make_transparency_pixmap (); 1340 tr_flags = make_transparency_pixmap ();
1365 if (tr_flags == 0) 1341 if (tr_flags == 0)
1366 return false; 1342 return false;
1367 else if (!(tr_flags & BG_EFFECTS_FLAGS))
1368 bg_flags |= BG_IS_VALID; 1343 bg_flags |= BG_IS_VALID;
1369 } 1344 }
1370# endif 1345# endif
1371 1346
1372# ifdef BG_IMAGE_FROM_FILE 1347# ifdef BG_IMAGE_FROM_FILE
1373 if ((bg_flags & BG_IS_FROM_FILE) 1348 if ((bg_flags & BG_IS_FROM_FILE)
1374 || (tr_flags & BG_EFFECTS_FLAGS)) 1349 || (tr_flags & BG_EFFECTS_FLAGS))
1375 { 1350 {
1376 if (render_image (tr_flags)) 1351 if (render_image (tr_flags))
1377 bg_flags |= BG_IS_VALID; 1352 bg_flags |= BG_IS_VALID;
1378 }
1379# endif
1380
1381# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1382 XImage *result = NULL;
1383
1384 if (tr_flags && !(bg_flags & BG_IS_VALID))
1385 {
1386 result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1387 }
1388
1389 if (result)
1390 {
1391 /* our own client-side tinting */
1392 if (tr_flags & BG_NEEDS_TINT)
1393 {
1394 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1395 if (bg_flags & BG_TINT_SET)
1396 tint.get (c);
1397 shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c);
1398 }
1399
1400 GC gc = XCreateGC (dpy, vt, 0UL, NULL);
1401
1402 if (gc)
1403 {
1404 XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1405
1406 XFreeGC (dpy, gc);
1407 bg_flags |= BG_IS_VALID;
1408 }
1409
1410 XDestroyImage (result);
1411 } 1353 }
1412# endif 1354# endif
1413 1355
1414 if (!(bg_flags & BG_IS_VALID)) 1356 if (!(bg_flags & BG_IS_VALID))
1415 { 1357 {
1453} 1395}
1454 1396
1455#endif /* HAVE_BG_PIXMAP */ 1397#endif /* HAVE_BG_PIXMAP */
1456 1398
1457#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1399#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1458/* taken from aterm-0.4.2 */ 1400/* based on code from aterm-0.4.2 */
1459 1401
1460static void 1402static inline void
1461shade_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)
1462{ 1416{
1463 int sh_r, sh_g, sh_b; 1417 int sh_r, sh_g, sh_b;
1464 uint32_t mask_r, mask_g, mask_b; 1418 uint32_t mask_r, mask_g, mask_b;
1465 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1419 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1466 rgba low; 1420 unsigned short low;
1467 rgba high;
1468 int i;
1469 int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; 1421 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1470 1422
1471 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1423 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1472 1424
1473 /* for convenience */ 1425 /* for convenience */
1474 mask_r = visual->red_mask; 1426 mask_r = visual->red_mask;
1532 break; 1484 break;
1533 default: 1485 default:
1534 return; /* we do not support this color depth */ 1486 return; /* we do not support this color depth */
1535 } 1487 }
1536 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
1537 /* prepare limits for color transformation (each channel is handled separately) */ 1494 /* prepare limits for color transformation (each channel is handled separately) */
1538 if (shade > 100) 1495 if (shade > 100)
1539 { 1496 {
1540 shade = 200 - shade;
1541
1542 high.r = c.r * shade / 100;
1543 high.g = c.g * shade / 100;
1544 high.b = c.b * shade / 100;
1545
1546 low.r = 65535 * (100 - shade) / 100; 1497 c.r = c.r * (200 - shade) / 100;
1547 low.g = 65535 * (100 - shade) / 100; 1498 c.g = c.g * (200 - shade) / 100;
1548 low.b = 65535 * (100 - shade) / 100; 1499 c.b = c.b * (200 - shade) / 100;
1500
1501 low = 0xffff * (shade - 100) / 100;
1549 } 1502 }
1550 else 1503 else
1551 { 1504 {
1552 high.r = c.r * shade / 100; 1505 c.r = c.r * shade / 100;
1553 high.g = c.g * shade / 100; 1506 c.g = c.g * shade / 100;
1554 high.b = c.b * shade / 100; 1507 c.b = c.b * shade / 100;
1555 1508
1556 low.r = low.g = low.b = 0; 1509 low = 0;
1557 } 1510 }
1558 1511
1559 /* fill our lookup tables */ 1512 /* fill our lookup tables */
1560 for (i = 0; i <= mask_r>>sh_r; i++) 1513 fill_lut (lookup_r, mask_r, sh_r, low, c.r);
1561 { 1514 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1562 uint32_t tmp; 1515 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1563 tmp = i * high.r;
1564 tmp += (mask_r>>sh_r) * low.r;
1565 lookup_r[i] = (tmp/65535)<<sh_r;
1566 }
1567 for (i = 0; i <= mask_g>>sh_g; i++)
1568 {
1569 uint32_t tmp;
1570 tmp = i * high.g;
1571 tmp += (mask_g>>sh_g) * low.g;
1572 lookup_g[i] = (tmp/65535)<<sh_g;
1573 }
1574 for (i = 0; i <= mask_b>>sh_b; i++)
1575 {
1576 uint32_t tmp;
1577 tmp = i * high.b;
1578 tmp += (mask_b>>sh_b) * low.b;
1579 lookup_b[i] = (tmp/65535)<<sh_b;
1580 }
1581 1516
1582 /* apply table to input image (replacing colors by newly calculated ones) */ 1517 /* apply table to input image (replacing colors by newly calculated ones) */
1583 if (ximage->bits_per_pixel == 32 1518 if (ximage->bits_per_pixel == 32
1584 && (ximage->depth == 24 || ximage->depth == 32) 1519 && (ximage->depth == 24 || ximage->depth == 32)
1585 && ximage->byte_order == host_byte_order) 1520 && ximage->byte_order == host_byte_order)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines