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.155 by sf-exg, Mon May 30 18:39:02 2011 UTC vs.
Revision 1.200 by sf-exg, Thu Jan 19 13:33:43 2012 UTC

20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *---------------------------------------------------------------------*/ 23 *---------------------------------------------------------------------*/
24 24
25#include <cmath> 25#include <math.h>
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28 28
29#if XRENDER 29#if XRENDER
30# include <X11/extensions/Xrender.h> 30# include <X11/extensions/Xrender.h>
32 32
33#ifndef FilterConvolution 33#ifndef FilterConvolution
34#define FilterConvolution "convolution" 34#define FilterConvolution "convolution"
35#endif 35#endif
36 36
37/* 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
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 }
765 gcv.foreground = pix_colors[Color_bg]; 757 gcv.foreground = pix_colors[Color_bg];
766 gc = XCreateGC (dpy, vt, GCForeground, &gcv); 758 gc = XCreateGC (dpy, vt, GCForeground, &gcv);
767 759
768 if (gc) 760 if (gc)
769 { 761 {
770 if (h_scale == 0 || v_scale == 0) 762 if (bg_flags & BG_TILE)
771 { 763 {
772 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); 764 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth);
773 pixbuf_to_pixmap (result, tile, gc, 765 pixbuf_to_pixmap (result, tile, gc,
774 0, 0, 766 0, 0,
775 0, 0, 767 0, 0,
805 } 797 }
806 798
807#if XRENDER 799#if XRENDER
808 if (tr_flags) 800 if (tr_flags)
809 { 801 {
810 XRenderPictureAttributes pa;
811
812 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); 802 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
803
813 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 804 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0);
814 805
815 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
816 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); 806 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
817 807
818 pa.repeat = True; 808 Picture mask = create_xrender_mask (dpy, vt, False, False);
819 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
820 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
821 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
822 XFreePixmap (dpy, mask_pmap);
823 809
824 XRenderColor mask_c; 810 XRenderColor mask_c;
825 811
826 mask_c.alpha = 0x8000; 812 mask_c.alpha = 0x8000;
827 mask_c.red = 0; 813 mask_c.red =
828 mask_c.green = 0; 814 mask_c.green =
829 mask_c.blue = 0; 815 mask_c.blue = 0;
830 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 816 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
817
831 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);
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);
855rxvt_term::bg_set_file (const char *file) 842rxvt_term::bg_set_file (const char *file)
856{ 843{
857 if (!file || !*file) 844 if (!file || !*file)
858 return false; 845 return false;
859 846
847 bool ret = false;
860 if (const char *p = strchr (file, ';')) 848 const char *p = strchr (file, ';');
849
850 if (p)
861 { 851 {
862 size_t len = p - file; 852 size_t len = p - file;
863 char *f = rxvt_temp_buf<char> (len + 1); 853 char *f = rxvt_temp_buf<char> (len + 1);
864 memcpy (f, file, len); 854 memcpy (f, file, len);
865 f[len] = '\0'; 855 f[len] = '\0';
874 { 864 {
875 if (original_asim) 865 if (original_asim)
876 safe_asimage_destroy (original_asim); 866 safe_asimage_destroy (original_asim);
877 original_asim = image; 867 original_asim = image;
878 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; 868 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER;
879 return true; 869 ret = true;
880 } 870 }
881# endif 871# endif
882 872
883# ifdef HAVE_PIXBUF 873# ifdef HAVE_PIXBUF
884 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 874 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
886 { 876 {
887 if (pixbuf) 877 if (pixbuf)
888 g_object_unref (pixbuf); 878 g_object_unref (pixbuf);
889 pixbuf = image; 879 pixbuf = image;
890 bg_flags |= BG_IS_FROM_FILE; 880 bg_flags |= BG_IS_FROM_FILE;
891 return true; 881 ret = true;
892 } 882 }
893# endif 883# endif
894 884
885 if (ret)
886 {
887 if (p)
888 bg_set_geometry (p + 1);
889 else
890 bg_set_default_geometry ();
891 }
892
895 return false; 893 return ret;
896} 894}
897 895
898# endif /* BG_IMAGE_FROM_FILE */ 896# endif /* BG_IMAGE_FROM_FILE */
899 897
900# ifdef ENABLE_TRANSPARENCY 898# ifdef ENABLE_TRANSPARENCY
936 { 934 {
937 changed = true; 935 changed = true;
938 v_blurRadius = vr; 936 v_blurRadius = vr;
939 } 937 }
940 938
941 if (v_blurRadius == 0 && h_blurRadius == 0) 939 if (h_blurRadius == 0 || v_blurRadius == 0)
942 bg_flags &= ~BG_NEEDS_BLUR; 940 bg_flags &= ~BG_NEEDS_BLUR;
943 else 941 else
944 bg_flags |= BG_NEEDS_BLUR; 942 bg_flags |= BG_NEEDS_BLUR;
945 943
946 return changed; 944 return changed;
947} 945}
948 946
949void 947void
950rxvt_term::set_tint_shade_flags () 948rxvt_term::set_tint_shade_flags ()
951{ 949{
952 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 950 rgba c;
953 bool has_shade = shade != 100; 951 bool has_shade = shade != 100;
954 952
955 bg_flags &= ~BG_TINT_FLAGS; 953 bg_flags &= ~BG_TINT_FLAGS;
956 954
957 if (bg_flags & BG_TINT_SET) 955 if (bg_flags & BG_TINT_SET)
983} 981}
984 982
985bool 983bool
986rxvt_term::bg_set_shade (const char *shade_str) 984rxvt_term::bg_set_shade (const char *shade_str)
987{ 985{
988 int new_shade = (shade_str) ? atoi (shade_str) : 100; 986 int new_shade = atoi (shade_str);
989 987
990 clamp_it (new_shade, -100, 200); 988 clamp_it (new_shade, -100, 200);
991 if (new_shade < 0) 989 if (new_shade < 0)
992 new_shade = 200 - (100 + new_shade); 990 new_shade = 200 - (100 + new_shade);
993 991
1023 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1021 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1024} 1022}
1025#endif 1023#endif
1026 1024
1027bool 1025bool
1028rxvt_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)
1029{ 1027{
1030 bool ret = false; 1028 bool ret = false;
1031#if XRENDER 1029#if XRENDER
1030 if (!(bg_flags & BG_HAS_RENDER_CONV))
1031 return false;
1032
1032 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1033 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1033 double *kernel = (double *)malloc (size * sizeof (double)); 1034 double *kernel = (double *)malloc (size * sizeof (double));
1034 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1035 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1035 1036
1036 XRenderPictureAttributes pa; 1037 XRenderPictureAttributes pa;
1037 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1038 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1038 1039
1040 pa.repeat = RepeatPad;
1039 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);
1040 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1043 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
1044 XFreePixmap (dpy, tmp);
1041 1045
1042 if (kernel && params) 1046 if (kernel && params)
1043 { 1047 {
1044 if (h_blurRadius)
1045 {
1046 size = h_blurRadius * 2 + 1; 1048 size = h_blurRadius * 2 + 1;
1047 get_gaussian_kernel (h_blurRadius, size, kernel, params); 1049 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1048 1050
1049 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1051 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1050 XRenderComposite (dpy, 1052 XRenderComposite (dpy,
1051 PictOpSrc, 1053 PictOpSrc,
1052 src, 1054 src,
1053 None, 1055 None,
1054 dst, 1056 dst,
1055 0, 0, 1057 0, 0,
1056 0, 0, 1058 0, 0,
1057 0, 0, 1059 0, 0,
1058 width, height); 1060 width, height);
1059 }
1060 1061
1061 if (v_blurRadius) 1062 ::swap (src, dst);
1062 { 1063
1063 size = v_blurRadius * 2 + 1; 1064 size = v_blurRadius * 2 + 1;
1064 get_gaussian_kernel (v_blurRadius, size, kernel, params); 1065 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1065 ::swap (params[0], params[1]); 1066 ::swap (params[0], params[1]);
1066 1067
1067 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1068 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1068 XRenderComposite (dpy, 1069 XRenderComposite (dpy,
1069 PictOpSrc, 1070 PictOpSrc,
1070 src, 1071 src,
1071 None, 1072 None,
1072 dst, 1073 dst,
1073 0, 0, 1074 0, 0,
1074 0, 0, 1075 0, 0,
1075 0, 0, 1076 0, 0,
1076 width, height); 1077 width, height);
1077 }
1078 1078
1079 ret = true; 1079 ret = true;
1080 } 1080 }
1081 1081
1082 free (kernel); 1082 free (kernel);
1109 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); 1109 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1110 ret = true; 1110 ret = true;
1111 XFreeGC (dpy, gc); 1111 XFreeGC (dpy, gc);
1112 } 1112 }
1113 } 1113 }
1114 else
1115 {
1116# if XRENDER 1114# if XRENDER
1115 else if (bg_flags & BG_HAS_RENDER)
1116 {
1117 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1117 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1118 1118
1119 if (bg_flags & BG_TINT_SET) 1119 if (bg_flags & BG_TINT_SET)
1120 tint.get (c); 1120 tint.get (c);
1121 1121
1130 c.r = c.r * (200 - shade) / 100; 1130 c.r = c.r * (200 - shade) / 100;
1131 c.g = c.g * (200 - shade) / 100; 1131 c.g = c.g * (200 - shade) / 100;
1132 c.b = c.b * (200 - shade) / 100; 1132 c.b = c.b * (200 - shade) / 100;
1133 } 1133 }
1134 1134
1135 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1136 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1135 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1137 XRenderPictureAttributes pa;
1138 1136
1139 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1137 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1140 1138
1141 pa.repeat = True; 1139 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
1142 1140
1143 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1141 Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True);
1144 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1145 XFreePixmap (dpy, overlay_pmap);
1146
1147 pa.component_alpha = True;
1148 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1149 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1150 XFreePixmap (dpy, mask_pmap);
1151 1142
1152 XRenderColor mask_c; 1143 XRenderColor mask_c;
1153 1144
1154 mask_c.alpha = 0xffff; 1145 mask_c.alpha = 0xffff;
1155 mask_c.red = 1146 mask_c.red =
1160 mask_c.alpha = 0; 1151 mask_c.alpha = 0;
1161 mask_c.red = 0xffff - c.r; 1152 mask_c.red = 0xffff - c.r;
1162 mask_c.green = 0xffff - c.g; 1153 mask_c.green = 0xffff - c.g;
1163 mask_c.blue = 0xffff - c.b; 1154 mask_c.blue = 0xffff - c.b;
1164 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1155 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1156
1165 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1157 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1166 1158
1167 if (shade > 100) 1159 if (shade > 100)
1168 { 1160 {
1169 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1170 mask_c.alpha = 0; 1161 mask_c.alpha = 0;
1162 mask_c.red =
1163 mask_c.green =
1164 mask_c.blue = 0xffff * (shade - 100) / 100;
1171 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1165 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1172 1166
1173 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);
1174 } 1168 }
1175 1169
1176 ret = true; 1170 ret = true;
1177 1171
1178 XRenderFreePicture (dpy, mask_pic); 1172 XRenderFreePicture (dpy, mask_pic);
1179 XRenderFreePicture (dpy, overlay_pic); 1173 XRenderFreePicture (dpy, overlay_pic);
1180 XRenderFreePicture (dpy, back_pic); 1174 XRenderFreePicture (dpy, back_pic);
1175 }
1181# endif 1176# endif
1182 }
1183 1177
1184 return ret; 1178 return ret;
1185} 1179}
1186 1180
1187/* 1181/*
1238#if XRENDER 1232#if XRENDER
1239 if (bg_flags & BG_HAS_RENDER) 1233 if (bg_flags & BG_HAS_RENDER)
1240 { 1234 {
1241 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);
1242 1236
1243 XRenderPictureAttributes pa;
1244
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 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 1240 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1249 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1241 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, 0);
1250 1242
1251 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);
1252 1244
1253 XRenderFreePicture (dpy, src); 1245 XRenderFreePicture (dpy, src);
1254 XRenderFreePicture (dpy, dst); 1246 XRenderFreePicture (dpy, dst);
1271 bg_pmap_width = window_width; 1263 bg_pmap_width = window_width;
1272 bg_pmap_height = window_height; 1264 bg_pmap_height = window_height;
1273 } 1265 }
1274 1266
1275 /* straightforward pixmap copy */ 1267 /* straightforward pixmap copy */
1276 while (sx < 0) sx += root_width; 1268 while (sx < 0) sx += root_pmap_width;
1277 while (sy < 0) sy += root_height; 1269 while (sy < 0) sy += root_pmap_height;
1278 1270
1279 gcv.tile = recoded_root_pmap; 1271 gcv.tile = recoded_root_pmap;
1280 gcv.fill_style = FillTiled; 1272 gcv.fill_style = FillTiled;
1281 gcv.ts_x_origin = -sx; 1273 gcv.ts_x_origin = -sx;
1282 gcv.ts_y_origin = -sy; 1274 gcv.ts_y_origin = -sy;
1284 1276
1285 if (gc) 1277 if (gc)
1286 { 1278 {
1287 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1279 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1288 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1280 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1289 XFreeGC (dpy, gc);
1290 1281
1291 if (!(bg_flags & BG_CLIENT_RENDER)) 1282 if (!(bg_flags & BG_CLIENT_RENDER))
1292 { 1283 {
1293 if ((bg_flags & BG_NEEDS_BLUR) 1284 if (bg_flags & BG_NEEDS_BLUR)
1294 && (bg_flags & BG_HAS_RENDER_CONV))
1295 { 1285 {
1296 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1286 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth))
1297 result &= ~BG_NEEDS_BLUR; 1287 result &= ~BG_NEEDS_BLUR;
1298 } 1288 }
1299 if ((bg_flags & BG_NEEDS_TINT) 1289 if (bg_flags & BG_NEEDS_TINT)
1300 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1301 { 1290 {
1302 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1291 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1303 result &= ~BG_NEEDS_TINT; 1292 result &= ~BG_NEEDS_TINT;
1304 } 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
1305 } /* server side rendering completed */ 1308 } /* server side rendering completed */
1309
1310 XFreeGC (dpy, gc);
1306 } 1311 }
1307 1312
1308 if (recoded_root_pmap != root_pixmap) 1313 if (recoded_root_pmap != root_pixmap)
1309 XFreePixmap (dpy, recoded_root_pmap); 1314 XFreePixmap (dpy, recoded_root_pmap);
1310 1315
1320 1325
1321 root_pixmap = new_root_pixmap; 1326 root_pixmap = new_root_pixmap;
1322} 1327}
1323# endif /* ENABLE_TRANSPARENCY */ 1328# endif /* ENABLE_TRANSPARENCY */
1324 1329
1325#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1326static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1327# endif
1328
1329bool 1330bool
1330rxvt_term::bg_render () 1331rxvt_term::bg_render ()
1331{ 1332{
1332 unsigned long tr_flags = 0; 1333 unsigned long tr_flags = 0;
1333 1334
1335# ifdef ENABLE_TRANSPARENCY 1336# ifdef ENABLE_TRANSPARENCY
1336 if (bg_flags & BG_IS_TRANSPARENT) 1337 if (bg_flags & BG_IS_TRANSPARENT)
1337 { 1338 {
1338 /* we need to re-generate transparency pixmap in that case ! */ 1339 /* we need to re-generate transparency pixmap in that case ! */
1339 tr_flags = make_transparency_pixmap (); 1340 tr_flags = make_transparency_pixmap ();
1340 if (tr_flags == 0) 1341 if (tr_flags)
1341 return false;
1342 else if (!(tr_flags & BG_EFFECTS_FLAGS))
1343 bg_flags |= BG_IS_VALID; 1342 bg_flags |= BG_IS_VALID;
1344 } 1343 }
1345# endif 1344# endif
1346 1345
1347# ifdef BG_IMAGE_FROM_FILE 1346# ifdef BG_IMAGE_FROM_FILE
1348 if ((bg_flags & BG_IS_FROM_FILE) 1347 if ((bg_flags & BG_IS_FROM_FILE)
1349 || (tr_flags & BG_EFFECTS_FLAGS)) 1348 || (tr_flags & BG_EFFECTS_FLAGS))
1350 { 1349 {
1351 if (render_image (tr_flags)) 1350 if (render_image (tr_flags))
1352 bg_flags |= BG_IS_VALID; 1351 bg_flags |= BG_IS_VALID;
1353 }
1354# endif
1355
1356# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1357 XImage *result = NULL;
1358
1359 if (tr_flags && !(bg_flags & BG_IS_VALID))
1360 {
1361 result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1362 }
1363
1364 if (result)
1365 {
1366 /* our own client-side tinting */
1367 if (tr_flags & BG_NEEDS_TINT)
1368 {
1369 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1370 if (bg_flags & BG_TINT_SET)
1371 tint.get (c);
1372 shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c);
1373 }
1374
1375 GC gc = XCreateGC (dpy, vt, 0UL, NULL);
1376
1377 if (gc)
1378 {
1379 XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1380
1381 XFreeGC (dpy, gc);
1382 bg_flags |= BG_IS_VALID;
1383 }
1384
1385 XDestroyImage (result);
1386 } 1352 }
1387# endif 1353# endif
1388 1354
1389 if (!(bg_flags & BG_IS_VALID)) 1355 if (!(bg_flags & BG_IS_VALID))
1390 { 1356 {
1428} 1394}
1429 1395
1430#endif /* HAVE_BG_PIXMAP */ 1396#endif /* HAVE_BG_PIXMAP */
1431 1397
1432#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1398#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1433/* taken from aterm-0.4.2 */ 1399/* based on code from aterm-0.4.2 */
1434 1400
1435static void 1401static inline void
1436shade_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)
1437{ 1415{
1438 int sh_r, sh_g, sh_b; 1416 int sh_r, sh_g, sh_b;
1439 uint32_t mask_r, mask_g, mask_b; 1417 uint32_t mask_r, mask_g, mask_b;
1440 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1418 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1441 rgba low; 1419 unsigned short low;
1442 rgba high;
1443 int i;
1444 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 1420 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1445 1421
1446 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1422 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1447 1423
1448 /* for convenience */ 1424 /* for convenience */
1507 break; 1483 break;
1508 default: 1484 default:
1509 return; /* we do not support this color depth */ 1485 return; /* we do not support this color depth */
1510 } 1486 }
1511 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
1512 /* prepare limits for color transformation (each channel is handled separately) */ 1493 /* prepare limits for color transformation (each channel is handled separately) */
1513 if (shade > 100) 1494 if (shade > 100)
1514 { 1495 {
1515 shade = 200 - shade;
1516
1517 high.r = c.r * shade / 100;
1518 high.g = c.g * shade / 100;
1519 high.b = c.b * shade / 100;
1520
1521 low.r = 65535 * (100 - shade) / 100; 1496 c.r = c.r * (200 - shade) / 100;
1522 low.g = 65535 * (100 - shade) / 100; 1497 c.g = c.g * (200 - shade) / 100;
1523 low.b = 65535 * (100 - shade) / 100; 1498 c.b = c.b * (200 - shade) / 100;
1499
1500 low = 0xffff * (shade - 100) / 100;
1524 } 1501 }
1525 else 1502 else
1526 { 1503 {
1527 high.r = c.r * shade / 100; 1504 c.r = c.r * shade / 100;
1528 high.g = c.g * shade / 100; 1505 c.g = c.g * shade / 100;
1529 high.b = c.b * shade / 100; 1506 c.b = c.b * shade / 100;
1530 1507
1531 low.r = low.g = low.b = 0; 1508 low = 0;
1532 } 1509 }
1533 1510
1534 /* fill our lookup tables */ 1511 /* fill our lookup tables */
1535 for (i = 0; i <= mask_r>>sh_r; i++) 1512 fill_lut (lookup_r, mask_r, sh_r, low, c.r);
1536 { 1513 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1537 uint32_t tmp; 1514 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1538 tmp = i * high.r;
1539 tmp += (mask_r>>sh_r) * low.r;
1540 lookup_r[i] = (tmp/65535)<<sh_r;
1541 }
1542 for (i = 0; i <= mask_g>>sh_g; i++)
1543 {
1544 uint32_t tmp;
1545 tmp = i * high.g;
1546 tmp += (mask_g>>sh_g) * low.g;
1547 lookup_g[i] = (tmp/65535)<<sh_g;
1548 }
1549 for (i = 0; i <= mask_b>>sh_b; i++)
1550 {
1551 uint32_t tmp;
1552 tmp = i * high.b;
1553 tmp += (mask_b>>sh_b) * low.b;
1554 lookup_b[i] = (tmp/65535)<<sh_b;
1555 }
1556 1515
1557 /* apply table to input image (replacing colors by newly calculated ones) */ 1516 /* apply table to input image (replacing colors by newly calculated ones) */
1558 if (ximage->bits_per_pixel == 32 1517 if (ximage->bits_per_pixel == 32
1559 && (ximage->depth == 24 || ximage->depth == 32) 1518 && (ximage->depth == 24 || ximage->depth == 32)
1560 && ximage->byte_order == host_byte_order) 1519 && ximage->byte_order == host_byte_order)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines