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.148 by root, Tue Apr 26 09:48:09 2011 UTC vs.
Revision 1.199 by sf-exg, Tue Jan 17 19:51:30 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 }
727 719
720 if (!result)
721 return false;
722
728 bool ret = false; 723 bool ret = false;
729 724
730 if (result)
731 {
732 XGCValues gcv; 725 XGCValues gcv;
733 GC gc; 726 GC gc;
734 Pixmap root_pmap; 727 Pixmap root_pmap;
735 728
736 image_width = gdk_pixbuf_get_width (result); 729 image_width = gdk_pixbuf_get_width (result);
737 image_height = gdk_pixbuf_get_height (result); 730 image_height = gdk_pixbuf_get_height (result);
738 731
739 if (tr_flags) 732 if (tr_flags)
740 { 733 {
741 root_pmap = bg_pixmap; 734 root_pmap = bg_pixmap;
742 bg_pixmap = None; 735 bg_pixmap = None;
736 }
737 else
738 {
739 if (bg_flags & BG_TILE)
743 } 740 {
744 else
745 {
746 if (h_scale == 0 || v_scale == 0)
747 {
748 new_pmap_width = min (image_width, target_width); 741 new_pmap_width = min (image_width, target_width);
749 new_pmap_height = min (image_height, target_height); 742 new_pmap_height = min (image_height, target_height);
750 } 743 }
751 } 744 }
752 745
753 if (bg_pixmap == None 746 if (bg_pixmap == None
754 || bg_pmap_width != new_pmap_width 747 || bg_pmap_width != new_pmap_width
755 || bg_pmap_height != new_pmap_height) 748 || bg_pmap_height != new_pmap_height)
756 { 749 {
757 if (bg_pixmap) 750 if (bg_pixmap)
758 XFreePixmap (dpy, bg_pixmap); 751 XFreePixmap (dpy, bg_pixmap);
759 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);
760 bg_pmap_width = new_pmap_width; 753 bg_pmap_width = new_pmap_width;
761 bg_pmap_height = new_pmap_height; 754 bg_pmap_height = new_pmap_height;
762 } 755 }
763 756
764 gcv.foreground = pix_colors[Color_bg]; 757 gcv.foreground = pix_colors[Color_bg];
765 gc = XCreateGC (dpy, vt, GCForeground, &gcv); 758 gc = XCreateGC (dpy, vt, GCForeground, &gcv);
766 759
767 if (h_scale == 0 || v_scale == 0) 760 if (gc)
761 {
762 if (bg_flags & BG_TILE)
768 { 763 {
769 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); 764 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth);
770 pixbuf_to_pixmap (result, tile, gc, 765 pixbuf_to_pixmap (result, tile, gc,
771 0, 0, 766 0, 0,
772 0, 0, 767 0, 0,
802 } 797 }
803 798
804#if XRENDER 799#if XRENDER
805 if (tr_flags) 800 if (tr_flags)
806 { 801 {
807 XRenderPictureAttributes pa;
808
809 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); 802 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
803
810 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 804 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0);
811 805
812 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
813 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); 806 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
814 807
815 pa.repeat = True; 808 Picture mask = create_xrender_mask (dpy, vt, False, False);
816 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
817 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
818 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
819 XFreePixmap (dpy, mask_pmap);
820 809
821 if (src && dst && mask)
822 {
823 XRenderColor mask_c; 810 XRenderColor mask_c;
824 811
825 mask_c.alpha = 0x8000; 812 mask_c.alpha = 0x8000;
826 mask_c.red = 0; 813 mask_c.red =
827 mask_c.green = 0; 814 mask_c.green =
828 mask_c.blue = 0; 815 mask_c.blue = 0;
829 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 816 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
817
830 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);
831 }
832 819
833 XRenderFreePicture (dpy, src); 820 XRenderFreePicture (dpy, src);
834 XRenderFreePicture (dpy, dst); 821 XRenderFreePicture (dpy, dst);
835 XRenderFreePicture (dpy, mask); 822 XRenderFreePicture (dpy, mask);
836
837 XFreePixmap (dpy, root_pmap);
838 } 823 }
839#endif 824#endif
840 825
841 if (result != pixbuf)
842 g_object_unref (result);
843
844 XFreeGC (dpy, gc); 826 XFreeGC (dpy, gc);
845 827
846 ret = true; 828 ret = true;
847 } 829 }
830
831 if (result != pixbuf)
832 g_object_unref (result);
833
834 if (tr_flags)
835 XFreePixmap (dpy, root_pmap);
848 836
849 return ret; 837 return ret;
850} 838}
851# endif /* HAVE_PIXBUF */ 839# endif /* HAVE_PIXBUF */
852 840
854rxvt_term::bg_set_file (const char *file) 842rxvt_term::bg_set_file (const char *file)
855{ 843{
856 if (!file || !*file) 844 if (!file || !*file)
857 return false; 845 return false;
858 846
847 bool ret = false;
859 if (const char *p = strchr (file, ';')) 848 const char *p = strchr (file, ';');
849
850 if (p)
860 { 851 {
861 size_t len = p - file; 852 size_t len = p - file;
862 char *f = rxvt_temp_buf<char> (len + 1); 853 char *f = rxvt_temp_buf<char> (len + 1);
863 memcpy (f, file, len); 854 memcpy (f, file, len);
864 f[len] = '\0'; 855 f[len] = '\0';
873 { 864 {
874 if (original_asim) 865 if (original_asim)
875 safe_asimage_destroy (original_asim); 866 safe_asimage_destroy (original_asim);
876 original_asim = image; 867 original_asim = image;
877 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; 868 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER;
878 return true; 869 ret = true;
879 } 870 }
880# endif 871# endif
881 872
882# ifdef HAVE_PIXBUF 873# ifdef HAVE_PIXBUF
883 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 874 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
885 { 876 {
886 if (pixbuf) 877 if (pixbuf)
887 g_object_unref (pixbuf); 878 g_object_unref (pixbuf);
888 pixbuf = image; 879 pixbuf = image;
889 bg_flags |= BG_IS_FROM_FILE; 880 bg_flags |= BG_IS_FROM_FILE;
890 return true; 881 ret = true;
891 } 882 }
892# endif 883# endif
893 884
885 if (ret)
886 {
887 if (p)
888 bg_set_geometry (p + 1);
889 else
890 bg_set_default_geometry ();
891 }
892
894 return false; 893 return ret;
895} 894}
896 895
897# endif /* BG_IMAGE_FROM_FILE */ 896# endif /* BG_IMAGE_FROM_FILE */
898 897
899# ifdef ENABLE_TRANSPARENCY 898# ifdef ENABLE_TRANSPARENCY
935 { 934 {
936 changed = true; 935 changed = true;
937 v_blurRadius = vr; 936 v_blurRadius = vr;
938 } 937 }
939 938
940 if (v_blurRadius == 0 && h_blurRadius == 0) 939 if (h_blurRadius == 0 || v_blurRadius == 0)
941 bg_flags &= ~BG_NEEDS_BLUR; 940 bg_flags &= ~BG_NEEDS_BLUR;
942 else 941 else
943 bg_flags |= BG_NEEDS_BLUR; 942 bg_flags |= BG_NEEDS_BLUR;
944 943
945 return changed; 944 return changed;
946} 945}
947 946
948void 947void
949rxvt_term::set_tint_shade_flags () 948rxvt_term::set_tint_shade_flags ()
950{ 949{
951 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 950 rgba c;
952 bool has_shade = shade != 100; 951 bool has_shade = shade != 100;
953 952
954 bg_flags &= ~BG_TINT_FLAGS; 953 bg_flags &= ~BG_TINT_FLAGS;
955 954
956 if (bg_flags & BG_TINT_SET) 955 if (bg_flags & BG_TINT_SET)
982} 981}
983 982
984bool 983bool
985rxvt_term::bg_set_shade (const char *shade_str) 984rxvt_term::bg_set_shade (const char *shade_str)
986{ 985{
987 int new_shade = (shade_str) ? atoi (shade_str) : 100; 986 int new_shade = atoi (shade_str);
988 987
989 clamp_it (new_shade, -100, 200); 988 clamp_it (new_shade, -100, 200);
990 if (new_shade < 0) 989 if (new_shade < 0)
991 new_shade = 200 - (100 + new_shade); 990 new_shade = 200 - (100 + new_shade);
992 991
1022 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1021 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1023} 1022}
1024#endif 1023#endif
1025 1024
1026bool 1025bool
1027rxvt_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)
1028{ 1027{
1029 bool ret = false; 1028 bool ret = false;
1030#if XRENDER 1029#if XRENDER
1030 if (!(bg_flags & BG_HAS_RENDER_CONV))
1031 return false;
1032
1031 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1033 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1032 double *kernel = (double *)malloc (size * sizeof (double)); 1034 double *kernel = (double *)malloc (size * sizeof (double));
1033 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1035 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1034 1036
1035 XRenderPictureAttributes pa; 1037 XRenderPictureAttributes pa;
1036 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1038 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1037 1039
1040 pa.repeat = RepeatPad;
1038 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);
1039 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1043 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
1044 XFreePixmap (dpy, tmp);
1040 1045
1041 if (kernel && params && src && dst) 1046 if (kernel && params)
1042 { 1047 {
1043 if (h_blurRadius)
1044 {
1045 size = h_blurRadius * 2 + 1; 1048 size = h_blurRadius * 2 + 1;
1046 get_gaussian_kernel (h_blurRadius, size, kernel, params); 1049 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1047 1050
1048 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1051 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1049 XRenderComposite (dpy, 1052 XRenderComposite (dpy,
1050 PictOpSrc, 1053 PictOpSrc,
1051 src, 1054 src,
1052 None, 1055 None,
1053 dst, 1056 dst,
1054 0, 0, 1057 0, 0,
1055 0, 0, 1058 0, 0,
1056 0, 0, 1059 0, 0,
1057 width, height); 1060 width, height);
1058 }
1059 1061
1060 if (v_blurRadius) 1062 ::swap (src, dst);
1061 { 1063
1062 size = v_blurRadius * 2 + 1; 1064 size = v_blurRadius * 2 + 1;
1063 get_gaussian_kernel (v_blurRadius, size, kernel, params); 1065 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1064 ::swap (params[0], params[1]); 1066 ::swap (params[0], params[1]);
1065 1067
1066 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1068 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1067 XRenderComposite (dpy, 1069 XRenderComposite (dpy,
1068 PictOpSrc, 1070 PictOpSrc,
1069 src, 1071 src,
1070 None, 1072 None,
1071 dst, 1073 dst,
1072 0, 0, 1074 0, 0,
1073 0, 0, 1075 0, 0,
1074 0, 0, 1076 0, 0,
1075 width, height); 1077 width, height);
1076 }
1077 1078
1078 ret = true; 1079 ret = true;
1079 } 1080 }
1080 1081
1081 free (kernel); 1082 free (kernel);
1108 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); 1109 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1109 ret = true; 1110 ret = true;
1110 XFreeGC (dpy, gc); 1111 XFreeGC (dpy, gc);
1111 } 1112 }
1112 } 1113 }
1113 else
1114 {
1115# if XRENDER 1114# if XRENDER
1115 else if (bg_flags & BG_HAS_RENDER)
1116 {
1116 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1117 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1117 1118
1118 if (bg_flags & BG_TINT_SET) 1119 if (bg_flags & BG_TINT_SET)
1119 tint.get (c); 1120 tint.get (c);
1120 1121
1129 c.r = c.r * (200 - shade) / 100; 1130 c.r = c.r * (200 - shade) / 100;
1130 c.g = c.g * (200 - shade) / 100; 1131 c.g = c.g * (200 - shade) / 100;
1131 c.b = c.b * (200 - shade) / 100; 1132 c.b = c.b * (200 - shade) / 100;
1132 } 1133 }
1133 1134
1134 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1135 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1135 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1136 XRenderPictureAttributes pa;
1137 1136
1138 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1137 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1139 1138
1140 pa.repeat = True; 1139 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
1141 1140
1142 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1141 Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True);
1143 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1144 XFreePixmap (dpy, overlay_pmap);
1145 1142
1146 pa.component_alpha = True;
1147 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1148 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1149 XFreePixmap (dpy, mask_pmap);
1150
1151 if (mask_pic && overlay_pic && back_pic)
1152 {
1153 XRenderColor mask_c; 1143 XRenderColor mask_c;
1154 1144
1155 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;
1156 mask_c.red = 1162 mask_c.red =
1157 mask_c.green = 1163 mask_c.green =
1158 mask_c.blue = 0; 1164 mask_c.blue = 0xffff * (shade - 100) / 100;
1159 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1165 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1160 1166
1161 mask_c.alpha = 0;
1162 mask_c.red = 0xffff - c.r;
1163 mask_c.green = 0xffff - c.g;
1164 mask_c.blue = 0xffff - c.b;
1165 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1166 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1167
1168 if (shade > 100)
1169 {
1170 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1171 mask_c.alpha = 0;
1172 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1173
1174 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);
1175 } 1168 }
1176 1169
1177 ret = true; 1170 ret = true;
1178 }
1179 1171
1180 XRenderFreePicture (dpy, mask_pic); 1172 XRenderFreePicture (dpy, mask_pic);
1181 XRenderFreePicture (dpy, overlay_pic); 1173 XRenderFreePicture (dpy, overlay_pic);
1182 XRenderFreePicture (dpy, back_pic); 1174 XRenderFreePicture (dpy, back_pic);
1175 }
1183# endif 1176# endif
1184 }
1185 1177
1186 return ret; 1178 return ret;
1187} 1179}
1188 1180
1189/* make_transparency_pixmap() 1181/*
1190 * Builds a pixmap of the same size as the terminal window that contains 1182 * Builds a pixmap of the same size as the terminal window that contains
1191 * the tiled portion of the root pixmap that is supposed to be covered by 1183 * the tiled portion of the root pixmap that is supposed to be covered by
1192 * our window. 1184 * our window.
1193 */ 1185 */
1194unsigned long 1186unsigned long
1238 if (root_pixmap != None && root_depth != depth) 1230 if (root_pixmap != None && root_depth != depth)
1239 { 1231 {
1240#if XRENDER 1232#if XRENDER
1241 if (bg_flags & BG_HAS_RENDER) 1233 if (bg_flags & BG_HAS_RENDER)
1242 { 1234 {
1243 XRenderPictureAttributes pa; 1235 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1244 1236
1245 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1237 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1246 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1238 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1247 1239
1248 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1249 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 1240 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1250 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1241 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, 0);
1251 1242
1252 if (src && dst)
1253 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);
1254 else
1255 {
1256 XFreePixmap (dpy, recoded_root_pmap);
1257 root_pixmap = None;
1258 }
1259 1244
1260 XRenderFreePicture (dpy, src); 1245 XRenderFreePicture (dpy, src);
1261 XRenderFreePicture (dpy, dst); 1246 XRenderFreePicture (dpy, dst);
1262 } 1247 }
1263 else 1248 else
1264#endif 1249#endif
1265 root_pixmap = None; 1250 recoded_root_pmap = None;
1266 } 1251 }
1267 1252
1268 if (root_pixmap == None) 1253 if (recoded_root_pmap == None)
1269 return 0; 1254 return 0;
1270 1255
1271 if (bg_pixmap == None 1256 if (bg_pixmap == None
1272 || bg_pmap_width != window_width 1257 || bg_pmap_width != window_width
1273 || bg_pmap_height != window_height) 1258 || bg_pmap_height != window_height)
1277 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); 1262 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth);
1278 bg_pmap_width = window_width; 1263 bg_pmap_width = window_width;
1279 bg_pmap_height = window_height; 1264 bg_pmap_height = window_height;
1280 } 1265 }
1281 1266
1282 if (bg_pixmap == None)
1283 return 0;
1284
1285 /* straightforward pixmap copy */ 1267 /* straightforward pixmap copy */
1286 while (sx < 0) sx += (int)root_width; 1268 while (sx < 0) sx += root_pmap_width;
1287 while (sy < 0) sy += (int)root_height; 1269 while (sy < 0) sy += root_pmap_height;
1288 1270
1289 gcv.tile = recoded_root_pmap; 1271 gcv.tile = recoded_root_pmap;
1290 gcv.fill_style = FillTiled; 1272 gcv.fill_style = FillTiled;
1291 gcv.ts_x_origin = -sx; 1273 gcv.ts_x_origin = -sx;
1292 gcv.ts_y_origin = -sy; 1274 gcv.ts_y_origin = -sy;
1294 1276
1295 if (gc) 1277 if (gc)
1296 { 1278 {
1297 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1279 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1298 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1280 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1299 XFreeGC (dpy, gc);
1300 1281
1301 if (!(bg_flags & BG_CLIENT_RENDER)) 1282 if (!(bg_flags & BG_CLIENT_RENDER))
1302 { 1283 {
1303 if ((bg_flags & BG_NEEDS_BLUR) 1284 if (bg_flags & BG_NEEDS_BLUR)
1304 && (bg_flags & BG_HAS_RENDER_CONV))
1305 { 1285 {
1306 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1286 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth))
1307 result &= ~BG_NEEDS_BLUR; 1287 result &= ~BG_NEEDS_BLUR;
1308 } 1288 }
1309 if ((bg_flags & BG_NEEDS_TINT) 1289 if (bg_flags & BG_NEEDS_TINT)
1310 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1311 { 1290 {
1312 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1291 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1313 result &= ~BG_NEEDS_TINT; 1292 result &= ~BG_NEEDS_TINT;
1314 } 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
1315 } /* server side rendering completed */ 1308 } /* server side rendering completed */
1309
1310 XFreeGC (dpy, gc);
1316 } 1311 }
1317 1312
1318 if (recoded_root_pmap != root_pixmap) 1313 if (recoded_root_pmap != root_pixmap)
1319 XFreePixmap (dpy, recoded_root_pmap); 1314 XFreePixmap (dpy, recoded_root_pmap);
1320 1315
1330 1325
1331 root_pixmap = new_root_pixmap; 1326 root_pixmap = new_root_pixmap;
1332} 1327}
1333# endif /* ENABLE_TRANSPARENCY */ 1328# endif /* ENABLE_TRANSPARENCY */
1334 1329
1335#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1336static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1337# endif
1338
1339bool 1330bool
1340rxvt_term::bg_render () 1331rxvt_term::bg_render ()
1341{ 1332{
1342 unsigned long tr_flags = 0; 1333 unsigned long tr_flags = 0;
1343 1334
1345# ifdef ENABLE_TRANSPARENCY 1336# ifdef ENABLE_TRANSPARENCY
1346 if (bg_flags & BG_IS_TRANSPARENT) 1337 if (bg_flags & BG_IS_TRANSPARENT)
1347 { 1338 {
1348 /* we need to re-generate transparency pixmap in that case ! */ 1339 /* we need to re-generate transparency pixmap in that case ! */
1349 tr_flags = make_transparency_pixmap (); 1340 tr_flags = make_transparency_pixmap ();
1350 if (tr_flags == 0) 1341 if (tr_flags)
1351 return false;
1352 else if (!(tr_flags & BG_EFFECTS_FLAGS))
1353 bg_flags |= BG_IS_VALID; 1342 bg_flags |= BG_IS_VALID;
1354 } 1343 }
1355# endif 1344# endif
1356 1345
1357# ifdef BG_IMAGE_FROM_FILE 1346# ifdef BG_IMAGE_FROM_FILE
1358 if ((bg_flags & BG_IS_FROM_FILE) 1347 if ((bg_flags & BG_IS_FROM_FILE)
1359 || (tr_flags & BG_EFFECTS_FLAGS)) 1348 || (tr_flags & BG_EFFECTS_FLAGS))
1360 { 1349 {
1361 if (render_image (tr_flags)) 1350 if (render_image (tr_flags))
1362 bg_flags |= BG_IS_VALID; 1351 bg_flags |= BG_IS_VALID;
1363 }
1364# endif
1365
1366# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1367 XImage *result = NULL;
1368
1369 if (tr_flags && !(bg_flags & BG_IS_VALID))
1370 {
1371 result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1372 }
1373
1374 if (result)
1375 {
1376 /* our own client-side tinting */
1377 if (tr_flags & BG_NEEDS_TINT)
1378 {
1379 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1380 if (bg_flags & BG_TINT_SET)
1381 tint.get (c);
1382 shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c);
1383 }
1384
1385 GC gc = XCreateGC (dpy, vt, 0UL, NULL);
1386
1387 if (gc)
1388 {
1389 XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1390
1391 XFreeGC (dpy, gc);
1392 bg_flags |= BG_IS_VALID;
1393 }
1394
1395 XDestroyImage (result);
1396 } 1352 }
1397# endif 1353# endif
1398 1354
1399 if (!(bg_flags & BG_IS_VALID)) 1355 if (!(bg_flags & BG_IS_VALID))
1400 { 1356 {
1438} 1394}
1439 1395
1440#endif /* HAVE_BG_PIXMAP */ 1396#endif /* HAVE_BG_PIXMAP */
1441 1397
1442#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1398#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1443/* taken from aterm-0.4.2 */ 1399/* based on code from aterm-0.4.2 */
1444 1400
1445static void 1401static inline void
1446shade_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)
1447{ 1415{
1448 int sh_r, sh_g, sh_b; 1416 int sh_r, sh_g, sh_b;
1449 uint32_t mask_r, mask_g, mask_b; 1417 uint32_t mask_r, mask_g, mask_b;
1450 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1418 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1451 rgba low; 1419 unsigned short low;
1452 rgba high;
1453 int i;
1454 int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; 1420 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1455 1421
1456 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1422 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1457 1423
1458 /* for convenience */ 1424 /* for convenience */
1459 mask_r = visual->red_mask; 1425 mask_r = visual->red_mask;
1517 break; 1483 break;
1518 default: 1484 default:
1519 return; /* we do not support this color depth */ 1485 return; /* we do not support this color depth */
1520 } 1486 }
1521 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
1522 /* prepare limits for color transformation (each channel is handled separately) */ 1493 /* prepare limits for color transformation (each channel is handled separately) */
1523 if (shade > 100) 1494 if (shade > 100)
1524 { 1495 {
1525 shade = 200 - shade;
1526
1527 high.r = c.r * shade / 100;
1528 high.g = c.g * shade / 100;
1529 high.b = c.b * shade / 100;
1530
1531 low.r = 65535 * (100 - shade) / 100; 1496 c.r = c.r * (200 - shade) / 100;
1532 low.g = 65535 * (100 - shade) / 100; 1497 c.g = c.g * (200 - shade) / 100;
1533 low.b = 65535 * (100 - shade) / 100; 1498 c.b = c.b * (200 - shade) / 100;
1499
1500 low = 0xffff * (shade - 100) / 100;
1534 } 1501 }
1535 else 1502 else
1536 { 1503 {
1537 high.r = c.r * shade / 100; 1504 c.r = c.r * shade / 100;
1538 high.g = c.g * shade / 100; 1505 c.g = c.g * shade / 100;
1539 high.b = c.b * shade / 100; 1506 c.b = c.b * shade / 100;
1540 1507
1541 low.r = low.g = low.b = 0; 1508 low = 0;
1542 } 1509 }
1543 1510
1544 /* fill our lookup tables */ 1511 /* fill our lookup tables */
1545 for (i = 0; i <= mask_r>>sh_r; i++) 1512 fill_lut (lookup_r, mask_r, sh_r, low, c.r);
1546 { 1513 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1547 uint32_t tmp; 1514 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1548 tmp = i * high.r;
1549 tmp += (mask_r>>sh_r) * low.r;
1550 lookup_r[i] = (tmp/65535)<<sh_r;
1551 }
1552 for (i = 0; i <= mask_g>>sh_g; i++)
1553 {
1554 uint32_t tmp;
1555 tmp = i * high.g;
1556 tmp += (mask_g>>sh_g) * low.g;
1557 lookup_g[i] = (tmp/65535)<<sh_g;
1558 }
1559 for (i = 0; i <= mask_b>>sh_b; i++)
1560 {
1561 uint32_t tmp;
1562 tmp = i * high.b;
1563 tmp += (mask_b>>sh_b) * low.b;
1564 lookup_b[i] = (tmp/65535)<<sh_b;
1565 }
1566 1515
1567 /* apply table to input image (replacing colors by newly calculated ones) */ 1516 /* apply table to input image (replacing colors by newly calculated ones) */
1568 if (ximage->bits_per_pixel == 32 1517 if (ximage->bits_per_pixel == 32
1569 && (ximage->depth == 24 || ximage->depth == 32) 1518 && (ximage->depth == 24 || ximage->depth == 32)
1570 && ximage->byte_order == host_byte_order) 1519 && ximage->byte_order == host_byte_order)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines