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.208 by sf-exg, Fri May 11 08:16:58 2012 UTC vs.
Revision 1.234 by sf-exg, Thu Jun 7 09:21:18 2012 UTC

3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de> 6 * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de>
7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> 7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
8 * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it> 8 * Copyright (c) 2010-2012 Emanuele Giaquinta <e.giaquinta@glauco.it>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
58# endif 58# endif
59 59
60void 60void
61rxvt_term::bg_destroy () 61rxvt_term::bg_destroy ()
62{ 62{
63#ifdef HAVE_PIXBUF 63# if BG_IMAGE_FROM_FILE
64 if (pixbuf) 64 fimage.destroy ();
65 g_object_unref (pixbuf);
66#endif 65# endif
67 66
68 if (bg_pixmap) 67 if (bg_pixmap)
69 XFreePixmap (dpy, bg_pixmap); 68 XFreePixmap (dpy, bg_pixmap);
70} 69}
71 70
84} 83}
85 84
86bool 85bool
87rxvt_term::bg_window_size_sensitive () 86rxvt_term::bg_window_size_sensitive ()
88{ 87{
89# ifdef ENABLE_TRANSPARENCY 88# if ENABLE_TRANSPARENCY
90 if (bg_flags & BG_IS_TRANSPARENT) 89 if (bg_flags & BG_IS_TRANSPARENT)
91 return true; 90 return true;
92# endif 91# endif
93 92
94# ifdef BG_IMAGE_FROM_FILE 93# if BG_IMAGE_FROM_FILE
95 if (bg_flags & BG_IS_FROM_FILE) 94 if (fimage.flags & IM_IS_SET)
96 { 95 {
97 if (bg_flags & BG_IS_SIZE_SENSITIVE) 96 if ((fimage.flags & IM_IS_SIZE_SENSITIVE)
97 || fimage.width () > szHint.width
98 || fimage.height () > szHint.height)
98 return true; 99 return true;
99 } 100 }
100# endif 101# endif
101 102
102 return false; 103 return false;
103} 104}
104 105
105bool 106bool
106rxvt_term::bg_window_position_sensitive () 107rxvt_term::bg_window_position_sensitive ()
107{ 108{
108# ifdef ENABLE_TRANSPARENCY 109# if ENABLE_TRANSPARENCY
109 if (bg_flags & BG_IS_TRANSPARENT) 110 if (bg_flags & BG_IS_TRANSPARENT)
110 return true; 111 return true;
111# endif 112# endif
112 113
113# ifdef BG_IMAGE_FROM_FILE 114# if BG_IMAGE_FROM_FILE
114 if (bg_flags & BG_IS_FROM_FILE) 115 if (fimage.flags & IM_IS_SET)
115 { 116 {
116 if (bg_flags & BG_ROOT_ALIGN) 117 if (fimage.flags & IM_ROOT_ALIGN)
117 return true; 118 return true;
118 } 119 }
119# endif 120# endif
120 121
121 return false; 122 return false;
122} 123}
123 124
124# ifdef BG_IMAGE_FROM_FILE 125# if BG_IMAGE_FROM_FILE
125static inline int 126static inline int
126make_align_position (int align, int window_size, int image_size) 127make_align_position (int align, int window_size, int image_size)
127{ 128{
128 if (align >= 0 && align <= 100) 129 if (align >= 0 && align <= 100)
129 return lerp (0, window_size - image_size, align); 130 return lerp (0, window_size - image_size, align);
148 149
149 min_it (dst_size, target_size - dst_pos); 150 min_it (dst_size, target_size - dst_pos);
150 return src_pos; 151 return src_pos;
151} 152}
152 153
154static void
155parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags)
156{
157 if (!strcasecmp (style, "tiled"))
158 {
159 flags = IM_TILE;
160 w = h = noScale;
161 x = y = 0;
162 }
163 else if (!strcasecmp (style, "aspect-stretched"))
164 {
165 flags = IM_KEEP_ASPECT;
166 w = h = windowScale;
167 x = y = centerAlign;
168 }
169 else if (!strcasecmp (style, "stretched"))
170 {
171 flags = 0;
172 w = h = windowScale;
173 x = y = centerAlign;
174 }
175 else if (!strcasecmp (style, "centered"))
176 {
177 flags = 0;
178 w = h = noScale;
179 x = y = centerAlign;
180 }
181 else if (!strcasecmp (style, "root-tiled"))
182 {
183 flags = IM_TILE|IM_ROOT_ALIGN;
184 w = h = noScale;
185 x = y = 0;
186 }
187}
188
153bool 189bool
154rxvt_term::bg_set_geometry (const char *geom, bool update) 190rxvt_image::set_geometry (const char *geom, bool update)
155{ 191{
156 bool changed = false; 192 bool changed = false;
157 int geom_flags = 0; 193 int geom_flags = 0;
158 int x = h_align; 194 int x = h_align;
159 int y = v_align; 195 int y = v_align;
160 unsigned int w = h_scale; 196 unsigned int w = h_scale;
161 unsigned int h = v_scale; 197 unsigned int h = v_scale;
162 unsigned long new_flags = 0; 198 uint8_t new_flags = 0;
163 199
164 if (geom == NULL) 200 if (geom == NULL)
165 return false; 201 return false;
166 202
167 if (geom[0]) 203 if (geom[0])
168 { 204 {
169 char **arr = rxvt_strsplit (':', geom); 205 char **arr = rxvt_strsplit (':', geom);
170 206
171 for (int i = 0; arr[i]; i++) 207 for (int i = 0; arr[i]; i++)
172 { 208 {
173 if (!strcasecmp (arr[i], "style=tiled")) 209 if (!strncasecmp (arr[i], "style=", 6))
174 { 210 {
175 new_flags = BG_TILE; 211 parse_style (arr[i] + 6, x, y, w, h, new_flags);
176 w = h = noScale;
177 x = y = 0;
178 geom_flags = WidthValue|HeightValue|XValue|YValue; 212 geom_flags = WidthValue|HeightValue|XValue|YValue;
179 } 213 }
180 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
181 {
182 new_flags = BG_KEEP_ASPECT;
183 w = h = windowScale;
184 x = y = centerAlign;
185 geom_flags = WidthValue|HeightValue|XValue|YValue;
186 }
187 else if (!strcasecmp (arr[i], "style=stretched"))
188 {
189 new_flags = 0;
190 w = h = windowScale;
191 geom_flags = WidthValue|HeightValue;
192 }
193 else if (!strcasecmp (arr[i], "style=centered"))
194 {
195 new_flags = 0;
196 w = h = noScale;
197 x = y = centerAlign;
198 geom_flags = WidthValue|HeightValue|XValue|YValue;
199 }
200 else if (!strcasecmp (arr[i], "style=root-tiled"))
201 {
202 new_flags = BG_TILE|BG_ROOT_ALIGN;
203 w = h = noScale;
204 geom_flags = WidthValue|HeightValue;
205 }
206 else if (!strcasecmp (arr[i], "op=tile")) 214 else if (!strcasecmp (arr[i], "op=tile"))
207 new_flags |= BG_TILE; 215 new_flags |= IM_TILE;
208 else if (!strcasecmp (arr[i], "op=keep-aspect")) 216 else if (!strcasecmp (arr[i], "op=keep-aspect"))
209 new_flags |= BG_KEEP_ASPECT; 217 new_flags |= IM_KEEP_ASPECT;
210 else if (!strcasecmp (arr[i], "op=root-align")) 218 else if (!strcasecmp (arr[i], "op=root-align"))
211 new_flags |= BG_ROOT_ALIGN; 219 new_flags |= IM_ROOT_ALIGN;
212 220
213 // deprecated 221 // deprecated
214 else if (!strcasecmp (arr[i], "tile")) 222 else if (!strcasecmp (arr[i], "tile"))
215 { 223 {
216 new_flags |= BG_TILE; 224 new_flags |= IM_TILE;
217 w = h = noScale; 225 w = h = noScale;
218 geom_flags |= WidthValue|HeightValue; 226 geom_flags |= WidthValue|HeightValue;
219 } 227 }
220 else if (!strcasecmp (arr[i], "propscale")) 228 else if (!strcasecmp (arr[i], "propscale"))
221 { 229 {
222 new_flags |= BG_KEEP_ASPECT; 230 new_flags |= IM_KEEP_ASPECT;
223 w = h = windowScale; 231 w = h = windowScale;
224 geom_flags |= WidthValue|HeightValue; 232 geom_flags |= WidthValue|HeightValue;
225 } 233 }
226 else if (!strcasecmp (arr[i], "hscale")) 234 else if (!strcasecmp (arr[i], "hscale"))
227 { 235 {
228 new_flags |= BG_TILE; 236 new_flags |= IM_TILE;
229 w = windowScale; 237 w = windowScale;
230 h = noScale; 238 h = noScale;
231 geom_flags |= WidthValue|HeightValue; 239 geom_flags |= WidthValue|HeightValue;
232 } 240 }
233 else if (!strcasecmp (arr[i], "vscale")) 241 else if (!strcasecmp (arr[i], "vscale"))
234 { 242 {
235 new_flags |= BG_TILE; 243 new_flags |= IM_TILE;
236 h = windowScale; 244 h = windowScale;
237 w = noScale; 245 w = noScale;
238 geom_flags |= WidthValue|HeightValue; 246 geom_flags |= WidthValue|HeightValue;
239 } 247 }
240 else if (!strcasecmp (arr[i], "scale")) 248 else if (!strcasecmp (arr[i], "scale"))
248 x = y = centerAlign; 256 x = y = centerAlign;
249 geom_flags |= WidthValue|HeightValue|XValue|YValue; 257 geom_flags |= WidthValue|HeightValue|XValue|YValue;
250 } 258 }
251 else if (!strcasecmp (arr[i], "root")) 259 else if (!strcasecmp (arr[i], "root"))
252 { 260 {
253 new_flags |= BG_TILE|BG_ROOT_ALIGN; 261 new_flags |= IM_TILE|IM_ROOT_ALIGN;
254 w = h = noScale; 262 w = h = noScale;
255 geom_flags |= WidthValue|HeightValue; 263 geom_flags |= WidthValue|HeightValue;
256 } 264 }
257 265
258 else 266 else
260 } /* done parsing ops */ 268 } /* done parsing ops */
261 269
262 rxvt_free_strsplit (arr); 270 rxvt_free_strsplit (arr);
263 } 271 }
264 272
265 new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; 273 new_flags |= flags & ~IM_GEOMETRY_FLAGS;
266 274
267 if (!update) 275 if (!update)
268 { 276 {
269 if (!(geom_flags & XValue)) 277 if (!(geom_flags & XValue))
270 x = y = defaultAlign; 278 x = y = defaultAlign;
277 h = w; 285 h = w;
278 else if (!(geom_flags & WidthValue)) 286 else if (!(geom_flags & WidthValue))
279 w = h; 287 w = h;
280 } 288 }
281 289
282 min_it (w, 1000);
283 min_it (h, 1000);
284 clamp_it (x, -100, 200); 290 clamp_it (x, -100, 200);
285 clamp_it (y, -100, 200); 291 clamp_it (y, -100, 200);
286 292
287 if (bg_flags != new_flags 293 if (flags != new_flags
288 || h_scale != w 294 || h_scale != w
289 || v_scale != h 295 || v_scale != h
290 || h_align != x 296 || h_align != x
291 || v_align != y) 297 || v_align != y)
292 { 298 {
293 bg_flags = new_flags; 299 flags = new_flags;
294 h_scale = w; 300 h_scale = w;
295 v_scale = h; 301 v_scale = h;
296 h_align = x; 302 h_align = x;
297 v_align = y; 303 v_align = y;
298 changed = true; 304 changed = true;
299 } 305 }
300 306
307 if (is_size_sensitive ())
308 flags |= IM_IS_SIZE_SENSITIVE;
309 else
310 flags &= ~IM_IS_SIZE_SENSITIVE;
311
301 return changed; 312 return changed;
302} 313}
303 314
304void 315void
305rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 316rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y)
306{ 317{
318 int image_width = image.width ();
319 int image_height = image.height ();
307 int target_width = szHint.width; 320 int target_width = szHint.width;
308 int target_height = szHint.height; 321 int target_height = szHint.height;
322 int h_scale = min (image.h_scale, 32767 * 100 / target_width);
323 int v_scale = min (image.v_scale, 32767 * 100 / target_height);
309 324
310 w = h_scale * target_width / 100; 325 w = h_scale * target_width / 100;
311 h = v_scale * target_height / 100; 326 h = v_scale * target_height / 100;
312 327
313 if (bg_flags & BG_KEEP_ASPECT) 328 if (image.flags & IM_KEEP_ASPECT)
314 { 329 {
315 float scale = (float)w / image_width; 330 float scale = (float)w / image_width;
316 min_it (scale, (float)h / image_height); 331 min_it (scale, (float)h / image_height);
317 w = image_width * scale + 0.5; 332 w = image_width * scale + 0.5;
318 h = image_height * scale + 0.5; 333 h = image_height * scale + 0.5;
319 } 334 }
320 335
321 if (!w) w = image_width; 336 if (!w) w = image_width;
322 if (!h) h = image_height; 337 if (!h) h = image_height;
323 338
324 if (bg_flags & BG_ROOT_ALIGN) 339 if (image.flags & IM_ROOT_ALIGN)
325 { 340 {
326 x = -target_x; 341 x = -target_x;
327 y = -target_y; 342 y = -target_y;
328 } 343 }
329 else 344 else
330 { 345 {
331 x = make_align_position (h_align, target_width, w); 346 x = make_align_position (image.h_align, target_width, w);
332 y = make_align_position (v_align, target_height, h); 347 y = make_align_position (image.v_align, target_height, h);
333 } 348 }
334
335 if (!(bg_flags & BG_TILE)
336 || h_scale || v_scale
337 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
338 || image_width > target_width || image_height > target_height)
339 bg_flags |= BG_IS_SIZE_SENSITIVE;
340 else
341 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
342} 349}
343 350
344# ifdef HAVE_PIXBUF 351# if HAVE_PIXBUF
345bool 352bool
346rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, 353rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc,
347 int src_x, int src_y, int dst_x, int dst_y, 354 int src_x, int src_y, int dst_x, int dst_y,
348 unsigned int width, unsigned int height) 355 unsigned int width, unsigned int height, bool argb)
349{ 356{
350 XImage *ximage; 357 XImage *ximage;
351 char *data, *line; 358 char *line;
352 int bytes_per_pixel;
353 int width_r, width_g, width_b, width_a; 359 int width_r, width_g, width_b, width_a;
354 int sh_r, sh_g, sh_b, sh_a; 360 int sh_r, sh_g, sh_b, sh_a;
355 uint32_t alpha_mask; 361 uint32_t red_mask, green_mask, blue_mask, alpha_mask;
356 int rowstride; 362 int rowstride;
357 int channels; 363 int channels;
358 unsigned char *row; 364 unsigned char *row;
359 365
360 if (visual->c_class != TrueColor) 366 if (visual->c_class != TrueColor)
361 return false; 367 return false;
362 368
369 if (argb)
370 {
371 red_mask = 0xff << 16;
372 green_mask = 0xff << 8;
373 blue_mask = 0xff;
374 alpha_mask = 0xff << 24;
375 }
376 else
377 {
378 red_mask = visual->red_mask;
379 green_mask = visual->green_mask;
380 blue_mask = visual->blue_mask;
363#if XRENDER 381#if XRENDER
364 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 382 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
365 if (format) 383 if (format)
366 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; 384 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha;
367 else 385 else
368#endif 386#endif
369 alpha_mask = 0; 387 alpha_mask = 0;
388 }
370 389
371 if (depth == 24 || depth == 32)
372 bytes_per_pixel = 4;
373 else if (depth == 15 || depth == 16)
374 bytes_per_pixel = 2;
375 else
376 return false;
377
378 width_r = ecb_popcount32 (visual->red_mask); 390 width_r = ecb_popcount32 (red_mask);
379 width_g = ecb_popcount32 (visual->green_mask); 391 width_g = ecb_popcount32 (green_mask);
380 width_b = ecb_popcount32 (visual->blue_mask); 392 width_b = ecb_popcount32 (blue_mask);
381 width_a = ecb_popcount32 (alpha_mask); 393 width_a = ecb_popcount32 (alpha_mask);
382 394
383 if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) 395 if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8)
384 return false; 396 return false;
385 397
386 sh_r = ecb_ctz32 (visual->red_mask); 398 sh_r = ecb_ctz32 (red_mask);
387 sh_g = ecb_ctz32 (visual->green_mask); 399 sh_g = ecb_ctz32 (green_mask);
388 sh_b = ecb_ctz32 (visual->blue_mask); 400 sh_b = ecb_ctz32 (blue_mask);
389 sh_a = ecb_ctz32 (alpha_mask); 401 sh_a = ecb_ctz32 (alpha_mask);
390 402
391 if (width > INT_MAX / height / bytes_per_pixel) 403 if (width > 32767 || height > 32767)
392 return false; 404 return false;
393 405
394 data = (char *)malloc (width * height * bytes_per_pixel); 406 ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0,
395 if (!data) 407 width, height, 32, 0);
408 if (!ximage)
396 return false; 409 return false;
397 410
398 ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, data, 411 if (height > INT_MAX / ximage->bytes_per_line
399 width, height, bytes_per_pixel * 8, 0); 412 || !(ximage->data = (char *)malloc (height * ximage->bytes_per_line)))
400 if (!ximage)
401 { 413 {
402 free (data); 414 XDestroyImage (ximage);
403 return false; 415 return false;
404 } 416 }
405 417
406 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 418 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
407 419
408 rowstride = gdk_pixbuf_get_rowstride (pixbuf); 420 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
409 channels = gdk_pixbuf_get_n_channels (pixbuf); 421 channels = gdk_pixbuf_get_n_channels (pixbuf);
410 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; 422 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
411 line = data; 423 line = ximage->data;
412 424
413 rgba c (0, 0, 0); 425 rgba c (0, 0, 0);
414 426
415 if (channels == 4 && alpha_mask == 0) 427 if (channels == 4 && alpha_mask == 0)
416 { 428 {
446 value = ((r >> (8 - width_r)) << sh_r) 458 value = ((r >> (8 - width_r)) << sh_r)
447 | ((g >> (8 - width_g)) << sh_g) 459 | ((g >> (8 - width_g)) << sh_g)
448 | ((b >> (8 - width_b)) << sh_b) 460 | ((b >> (8 - width_b)) << sh_b)
449 | ((a >> (8 - width_a)) << sh_a); 461 | ((a >> (8 - width_a)) << sh_a);
450 462
451 if (bytes_per_pixel == 4) 463 if (ximage->bits_per_pixel == 32)
452 ((uint32_t *)line)[x] = value; 464 ((uint32_t *)line)[x] = value;
453 else 465 else
454 ((uint16_t *)line)[x] = value; 466 XPutPixel (ximage, x, y, value);
455 } 467 }
456 468
457 row += rowstride; 469 row += rowstride;
458 line += ximage->bytes_per_line; 470 line += ximage->bytes_per_line;
459 } 471 }
462 XDestroyImage (ximage); 474 XDestroyImage (ximage);
463 return true; 475 return true;
464} 476}
465 477
466bool 478bool
467rxvt_term::render_image (bool transparent) 479rxvt_term::render_image (rxvt_image &image)
468{ 480{
481 GdkPixbuf *pixbuf = image.pixbuf;
469 if (!pixbuf) 482 if (!pixbuf)
470 return false; 483 return false;
471 484
472 if (transparent 485 bool need_blend = bg_flags & BG_IS_VALID;
486
487 if (need_blend
473 && !(bg_flags & BG_HAS_RENDER)) 488 && !(display->flags & DISPLAY_HAS_RENDER))
474 return false; 489 return false;
475 490
476 GdkPixbuf *result; 491 GdkPixbuf *result;
477 492
478 int image_width = gdk_pixbuf_get_width (pixbuf); 493 int image_width = gdk_pixbuf_get_width (pixbuf);
486 int x = 0; 501 int x = 0;
487 int y = 0; 502 int y = 0;
488 int w = 0; 503 int w = 0;
489 int h = 0; 504 int h = 0;
490 505
491 get_image_geometry (image_width, image_height, w, h, x, y); 506 get_image_geometry (image, w, h, x, y);
492 507
493 if (!(bg_flags & BG_ROOT_ALIGN) 508 if (!(image.flags & IM_ROOT_ALIGN)
494 && (x >= target_width 509 && (x >= target_width
495 || y >= target_height 510 || y >= target_height
496 || x + w <= 0 511 || x + w <= 0
497 || y + h <= 0)) 512 || y + h <= 0))
498 return false; 513 return false;
512 527
513 bool ret = false; 528 bool ret = false;
514 529
515 XGCValues gcv; 530 XGCValues gcv;
516 GC gc; 531 GC gc;
517 Pixmap root_pmap; 532 Pixmap tmp_pixmap;
518 533
519 image_width = gdk_pixbuf_get_width (result); 534 image_width = gdk_pixbuf_get_width (result);
520 image_height = gdk_pixbuf_get_height (result); 535 image_height = gdk_pixbuf_get_height (result);
521 536
522 if (transparent) 537 if (need_blend)
523 { 538 tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32);
524 root_pmap = bg_pixmap;
525 bg_pixmap = None;
526 }
527 else 539 else
528 { 540 {
529 if (bg_flags & BG_TILE) 541 if (image.flags & IM_TILE)
530 { 542 {
531 new_pmap_width = min (image_width, target_width); 543 new_pmap_width = min (image_width, target_width);
532 new_pmap_height = min (image_height, target_height); 544 new_pmap_height = min (image_height, target_height);
533 } 545 }
534 }
535 546
536 if (bg_pixmap == None 547 if (bg_pixmap == None
537 || bg_pmap_width != new_pmap_width 548 || bg_pmap_width != new_pmap_width
538 || bg_pmap_height != new_pmap_height) 549 || bg_pmap_height != new_pmap_height)
539 { 550 {
540 if (bg_pixmap) 551 if (bg_pixmap)
541 XFreePixmap (dpy, bg_pixmap); 552 XFreePixmap (dpy, bg_pixmap);
542 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); 553 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
543 bg_pmap_width = new_pmap_width; 554 bg_pmap_width = new_pmap_width;
544 bg_pmap_height = new_pmap_height; 555 bg_pmap_height = new_pmap_height;
556 }
557
558 tmp_pixmap = bg_pixmap;
545 } 559 }
546 560
547 gcv.foreground = pix_colors[Color_bg]; 561 gcv.foreground = pix_colors[Color_bg];
548 gc = XCreateGC (dpy, vt, GCForeground, &gcv); 562 gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv);
549 563
550 if (gc) 564 if (gc)
551 { 565 {
552 if (bg_flags & BG_TILE) 566 if (image.flags & IM_TILE)
553 { 567 {
554 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); 568 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth);
555 pixbuf_to_pixmap (result, tile, gc, 569 pixbuf_to_pixmap (result, tile, gc,
556 0, 0, 570 0, 0,
557 0, 0, 571 0, 0,
558 image_width, image_height); 572 image_width, image_height, need_blend);
559 573
560 gcv.tile = tile; 574 gcv.tile = tile;
561 gcv.fill_style = FillTiled; 575 gcv.fill_style = FillTiled;
562 gcv.ts_x_origin = x; 576 gcv.ts_x_origin = x;
563 gcv.ts_y_origin = y; 577 gcv.ts_y_origin = y;
564 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 578 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
565 579
566 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 580 XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
567 XFreePixmap (dpy, tile); 581 XFreePixmap (dpy, tile);
568 } 582 }
569 else 583 else
570 { 584 {
571 int src_x, src_y, dst_x, dst_y; 585 int src_x, src_y, dst_x, dst_y;
575 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); 589 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
576 590
577 if (dst_x > 0 || dst_y > 0 591 if (dst_x > 0 || dst_y > 0
578 || dst_x + dst_width < new_pmap_width 592 || dst_x + dst_width < new_pmap_width
579 || dst_y + dst_height < new_pmap_height) 593 || dst_y + dst_height < new_pmap_height)
580 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 594 XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
581 595
582 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 596 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
583 pixbuf_to_pixmap (result, bg_pixmap, gc, 597 pixbuf_to_pixmap (result, tmp_pixmap, gc,
584 src_x, src_y, 598 src_x, src_y,
585 dst_x, dst_y, 599 dst_x, dst_y,
586 dst_width, dst_height); 600 dst_width, dst_height, need_blend);
587 } 601 }
602
603 if (image.need_blur ())
604 blur_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.h_blurRadius, image.v_blurRadius);
605 if (image.need_tint ())
606 tint_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.tint, image.tint_set, image.shade);
588 607
589#if XRENDER 608#if XRENDER
590 if (transparent) 609 if (need_blend)
591 { 610 {
611 XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
592 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 612 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
593 613
594 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); 614 Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0);
595 615
596 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); 616 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
597 617
598 Picture mask = create_xrender_mask (dpy, vt, False, False); 618 Picture mask = create_xrender_mask (dpy, vt, False, False);
599 619
600 XRenderColor mask_c; 620 XRenderColor mask_c;
601 621
602 mask_c.alpha = 0x8000; 622 mask_c.alpha = image.alpha;
603 mask_c.red = 623 mask_c.red =
604 mask_c.green = 624 mask_c.green =
605 mask_c.blue = 0; 625 mask_c.blue = 0;
606 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 626 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
607 627
619 } 639 }
620 640
621 if (result != pixbuf) 641 if (result != pixbuf)
622 g_object_unref (result); 642 g_object_unref (result);
623 643
624 if (transparent) 644 if (need_blend)
625 XFreePixmap (dpy, root_pmap); 645 XFreePixmap (dpy, tmp_pixmap);
626 646
627 return ret; 647 return ret;
628} 648}
629# endif /* HAVE_PIXBUF */ 649# endif /* HAVE_PIXBUF */
630 650
651rxvt_image::rxvt_image ()
652{
653 alpha = 0xffff;
654 flags = 0;
655 h_scale =
656 v_scale = defaultScale;
657 h_align =
658 v_align = defaultAlign;
659
660# if HAVE_PIXBUF
661 pixbuf = 0;
662# endif
663}
664
631bool 665bool
632rxvt_term::bg_set_file (const char *file) 666rxvt_image::set_file_geometry (const char *file)
633{ 667{
634 if (!file || !*file) 668 if (!file || !*file)
635 return false; 669 return false;
636 670
637 bool ret = false;
638 const char *p = strchr (file, ';'); 671 const char *p = strchr (file, ';');
639 672
640 if (p) 673 if (p)
641 { 674 {
642 size_t len = p - file; 675 size_t len = p - file;
644 memcpy (f, file, len); 677 memcpy (f, file, len);
645 f[len] = '\0'; 678 f[len] = '\0';
646 file = f; 679 file = f;
647 } 680 }
648 681
682 bool ret = set_file (file);
683 alpha = 0x8000;
684 if (ret)
685 set_geometry (p ? p + 1 : "");
686 return ret;
687}
688
689bool
690rxvt_image::set_file (const char *file)
691{
692 bool ret = false;
693
649# ifdef HAVE_PIXBUF 694# if HAVE_PIXBUF
650 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 695 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
651 if (image) 696 if (image)
652 { 697 {
653 if (pixbuf) 698 if (pixbuf)
654 g_object_unref (pixbuf); 699 g_object_unref (pixbuf);
655 pixbuf = image; 700 pixbuf = image;
656 bg_flags |= BG_IS_FROM_FILE;
657 ret = true; 701 ret = true;
658 } 702 }
659# endif 703# endif
660 704
661 if (ret) 705 if (ret)
662 { 706 flags |= IM_IS_SET;
663 if (p)
664 bg_set_geometry (p + 1);
665 else
666 bg_set_default_geometry ();
667 }
668 707
669 return ret; 708 return ret;
670} 709}
671 710
672# endif /* BG_IMAGE_FROM_FILE */ 711# endif /* BG_IMAGE_FROM_FILE */
673 712
674# ifdef ENABLE_TRANSPARENCY
675bool 713bool
676rxvt_term::bg_set_transparent () 714image_effects::set_blur (const char *geom)
677{
678 if (!(bg_flags & BG_IS_TRANSPARENT))
679 {
680 bg_flags |= BG_IS_TRANSPARENT;
681 return true;
682 }
683
684 return false;
685}
686
687bool
688rxvt_term::bg_set_blur (const char *geom)
689{ 715{
690 bool changed = false; 716 bool changed = false;
691 unsigned int hr, vr; 717 unsigned int hr, vr;
692 int junk; 718 int junk;
693 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 719 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
710 { 736 {
711 changed = true; 737 changed = true;
712 v_blurRadius = vr; 738 v_blurRadius = vr;
713 } 739 }
714 740
715 if (h_blurRadius && v_blurRadius)
716 bg_flags |= BG_NEEDS_BLUR;
717 else
718 bg_flags &= ~BG_NEEDS_BLUR;
719
720 return changed; 741 return changed;
721} 742}
722 743
723void
724rxvt_term::set_tint_shade_flags ()
725{
726 if (shade != 100 || (bg_flags & BG_TINT_SET))
727 bg_flags |= BG_NEEDS_TINT;
728 else
729 bg_flags &= ~BG_NEEDS_TINT;
730}
731
732bool 744bool
733rxvt_term::bg_set_tint (rxvt_color &new_tint) 745image_effects::set_tint (const rxvt_color &new_tint)
734{ 746{
735 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 747 if (!tint_set || tint != new_tint)
736 { 748 {
737 tint = new_tint; 749 tint = new_tint;
738 bg_flags |= BG_TINT_SET; 750 tint_set = true;
739 751
740 rgba c;
741 tint.get (c);
742 if ((c.r <= 0x00ff || c.r >= 0xff00)
743 && (c.g <= 0x00ff || c.g >= 0xff00)
744 && (c.b <= 0x00ff || c.b >= 0xff00))
745 bg_flags |= BG_TINT_BITAND;
746 else
747 bg_flags &= ~BG_TINT_BITAND;
748
749 set_tint_shade_flags ();
750 return true; 752 return true;
751 } 753 }
752 754
753 return false; 755 return false;
754} 756}
755 757
756bool 758bool
757rxvt_term::bg_set_shade (const char *shade_str) 759image_effects::set_shade (const char *shade_str)
758{ 760{
759 int new_shade = atoi (shade_str); 761 int new_shade = atoi (shade_str);
760 762
761 clamp_it (new_shade, -100, 200); 763 clamp_it (new_shade, -100, 200);
762 if (new_shade < 0) 764 if (new_shade < 0)
763 new_shade = 200 - (100 + new_shade); 765 new_shade = 200 - (100 + new_shade);
764 766
765 if (new_shade != shade) 767 if (new_shade != shade)
766 { 768 {
767 shade = new_shade; 769 shade = new_shade;
768 set_tint_shade_flags ();
769 return true; 770 return true;
770 } 771 }
771 772
772 return false; 773 return false;
773} 774}
794 params[i+2] = XDoubleToFixed (kernel[i] / sum); 795 params[i+2] = XDoubleToFixed (kernel[i] / sum);
795} 796}
796#endif 797#endif
797 798
798bool 799bool
799rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) 800rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius)
800{ 801{
801 bool ret = false; 802 bool ret = false;
802#if XRENDER 803#if XRENDER
803 if (!(bg_flags & BG_HAS_RENDER_CONV)) 804 if (!(display->flags & DISPLAY_HAS_RENDER_CONV))
804 return false; 805 return false;
805 806
806 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 807 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
807 double *kernel = (double *)malloc (size * sizeof (double)); 808 double *kernel = (double *)malloc (size * sizeof (double));
808 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 809 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
809 810
810 XRenderPictureAttributes pa; 811 XRenderPictureAttributes pa;
811 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 812 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
813 : XRenderFindVisualFormat (dpy, visual);
812 814
813 pa.repeat = RepeatPad; 815 pa.repeat = RepeatPad;
814 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); 816 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
815 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); 817 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth);
816 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); 818 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
859#endif 861#endif
860 return ret; 862 return ret;
861} 863}
862 864
863bool 865bool
864rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 866rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade)
865{ 867{
866 bool ret = false; 868 bool ret = false;
867 869
868 if (shade == 100 && (bg_flags & BG_TINT_BITAND)) 870 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
871
872 if (tint_set)
873 tint.get (c);
874
875 if (shade == 100
876 && (c.r <= 0x00ff || c.r >= 0xff00)
877 && (c.g <= 0x00ff || c.g >= 0xff00)
878 && (c.b <= 0x00ff || c.b >= 0xff00))
869 { 879 {
870 XGCValues gcv; 880 XGCValues gcv;
871 GC gc; 881 GC gc;
872 882
873 /* In this case we can tint image server-side getting significant 883 /* In this case we can tint image server-side getting significant
883 ret = true; 893 ret = true;
884 XFreeGC (dpy, gc); 894 XFreeGC (dpy, gc);
885 } 895 }
886 } 896 }
887# if XRENDER 897# if XRENDER
888 else if (bg_flags & BG_HAS_RENDER) 898 else if (display->flags & DISPLAY_HAS_RENDER)
889 { 899 {
890 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
891
892 if (bg_flags & BG_TINT_SET)
893 tint.get (c);
894
895 if (shade <= 100) 900 if (shade <= 100)
896 { 901 {
897 c.r = c.r * shade / 100; 902 c.r = c.r * shade / 100;
898 c.g = c.g * shade / 100; 903 c.g = c.g * shade / 100;
899 c.b = c.b * shade / 100; 904 c.b = c.b * shade / 100;
903 c.r = c.r * (200 - shade) / 100; 908 c.r = c.r * (200 - shade) / 100;
904 c.g = c.g * (200 - shade) / 100; 909 c.g = c.g * (200 - shade) / 100;
905 c.b = c.b * (200 - shade) / 100; 910 c.b = c.b * (200 - shade) / 100;
906 } 911 }
907 912
908 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 913 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
914 : XRenderFindVisualFormat (dpy, visual);
909 915
910 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); 916 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
911 917
912 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); 918 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
913 919
949# endif 955# endif
950 956
951 return ret; 957 return ret;
952} 958}
953 959
960# if ENABLE_TRANSPARENCY
954/* 961/*
955 * Builds a pixmap of the same size as the terminal window that contains 962 * Builds a pixmap of the same size as the terminal window that contains
956 * the tiled portion of the root pixmap that is supposed to be covered by 963 * the tiled portion of the root pixmap that is supposed to be covered by
957 * our window. 964 * our window.
958 */ 965 */
959bool 966bool
960rxvt_term::make_transparency_pixmap () 967rxvt_term::render_root_image ()
961{ 968{
962 bool ret = false; 969 bool ret = false;
963 970
964 /* root dimensions may change from call to call - but Display structure should 971 /* root dimensions may change from call to call - but Display structure should
965 * be always up-to-date, so let's use it : 972 * be always up-to-date, so let's use it :
1001 Pixmap recoded_root_pmap = root_pixmap; 1008 Pixmap recoded_root_pmap = root_pixmap;
1002 1009
1003 if (root_pixmap != None && root_depth != depth) 1010 if (root_pixmap != None && root_depth != depth)
1004 { 1011 {
1005#if XRENDER 1012#if XRENDER
1006 if (bg_flags & BG_HAS_RENDER) 1013 if (display->flags & DISPLAY_HAS_RENDER)
1007 { 1014 {
1008 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); 1015 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1009 1016
1010 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1017 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1011 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); 1018 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1049 1056
1050 if (gc) 1057 if (gc)
1051 { 1058 {
1052 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1059 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1053 ret = true; 1060 ret = true;
1054 unsigned long tr_flags = bg_flags & BG_EFFECTS_FLAGS; 1061 bool need_blur = root_effects.need_blur ();
1062 bool need_tint = root_effects.need_tint ();
1055 1063
1056 if (!(bg_flags & BG_CLIENT_RENDER)) 1064 if (need_blur)
1065 {
1066 if (blur_pixmap (bg_pixmap, window_width, window_height, false,
1067 root_effects.h_blurRadius, root_effects.v_blurRadius))
1068 need_blur = false;
1057 { 1069 }
1058 if (bg_flags & BG_NEEDS_BLUR) 1070 if (need_tint)
1071 {
1072 if (tint_pixmap (bg_pixmap, window_width, window_height, false,
1073 root_effects.tint, root_effects.tint_set, root_effects.shade))
1074 need_tint = false;
1075 }
1076 if (need_tint)
1077 {
1078 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1079 if (ximage)
1059 { 1080 {
1060 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) 1081 /* our own client-side tinting */
1061 tr_flags &= ~BG_NEEDS_BLUR; 1082 tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade);
1083
1084 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1085 XDestroyImage (ximage);
1062 } 1086 }
1063 if (bg_flags & BG_NEEDS_TINT)
1064 {
1065 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1066 tr_flags &= ~BG_NEEDS_TINT;
1067 } 1087 }
1068 if (tr_flags & BG_NEEDS_TINT)
1069 {
1070 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1071 if (ximage)
1072 {
1073 /* our own client-side tinting */
1074 tint_ximage (DefaultVisual (dpy, display->screen), ximage);
1075
1076 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1077 XDestroyImage (ximage);
1078 }
1079 }
1080 } /* server side rendering completed */
1081 1088
1082 XFreeGC (dpy, gc); 1089 XFreeGC (dpy, gc);
1083 } 1090 }
1084 1091
1085 if (recoded_root_pmap != root_pixmap) 1092 if (recoded_root_pmap != root_pixmap)
1089} 1096}
1090 1097
1091void 1098void
1092rxvt_term::bg_set_root_pixmap () 1099rxvt_term::bg_set_root_pixmap ()
1093{ 1100{
1094 Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]); 1101 Pixmap new_root_pixmap = display->get_pixmap_property (xa[XA_XROOTPMAP_ID]);
1095 if (new_root_pixmap == None) 1102 if (new_root_pixmap == None)
1096 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); 1103 new_root_pixmap = display->get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1097 1104
1098 root_pixmap = new_root_pixmap; 1105 root_pixmap = new_root_pixmap;
1099} 1106}
1100# endif /* ENABLE_TRANSPARENCY */ 1107# endif /* ENABLE_TRANSPARENCY */
1101 1108
1102bool 1109void
1103rxvt_term::bg_render () 1110rxvt_term::bg_render ()
1104{ 1111{
1105 bool transparent = false;
1106
1107 bg_invalidate (); 1112 bg_invalidate ();
1108# ifdef ENABLE_TRANSPARENCY 1113# if ENABLE_TRANSPARENCY
1109 if (bg_flags & BG_IS_TRANSPARENT) 1114 if (bg_flags & BG_IS_TRANSPARENT)
1110 { 1115 {
1111 /* we need to re-generate transparency pixmap in that case ! */ 1116 /* we need to re-generate transparency pixmap in that case ! */
1112 transparent = make_transparency_pixmap (); 1117 if (render_root_image ())
1113 if (transparent)
1114 bg_flags |= BG_IS_VALID; 1118 bg_flags |= BG_IS_VALID;
1115 } 1119 }
1116# endif 1120# endif
1117 1121
1118# ifdef BG_IMAGE_FROM_FILE 1122# if BG_IMAGE_FROM_FILE
1119 if (bg_flags & BG_IS_FROM_FILE) 1123 if (fimage.flags & IM_IS_SET)
1120 { 1124 {
1121 if (render_image (transparent)) 1125 if (render_image (fimage))
1122 bg_flags |= BG_IS_VALID; 1126 bg_flags |= BG_IS_VALID;
1123 } 1127 }
1124# endif 1128# endif
1125 1129
1126 if (!(bg_flags & BG_IS_VALID)) 1130 if (!(bg_flags & BG_IS_VALID))
1134 1138
1135 scr_recolour (false); 1139 scr_recolour (false);
1136 bg_flags |= BG_NEEDS_REFRESH; 1140 bg_flags |= BG_NEEDS_REFRESH;
1137 1141
1138 bg_valid_since = ev::now (); 1142 bg_valid_since = ev::now ();
1139
1140 return true;
1141} 1143}
1142 1144
1143void 1145void
1144rxvt_term::bg_init () 1146rxvt_term::bg_init ()
1145{ 1147{
1146#ifdef ENABLE_TRANSPARENCY 1148#if BG_IMAGE_FROM_FILE
1147 shade = 100; 1149 if (rs[Rs_backgroundPixmap])
1150 {
1151 if (fimage.set_file_geometry (rs[Rs_backgroundPixmap])
1152 && !bg_window_position_sensitive ())
1153 update_background ();
1154 }
1148#endif 1155#endif
1149
1150 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1151#if XRENDER
1152 int major, minor;
1153 if (XRenderQueryVersion (dpy, &major, &minor))
1154 bg_flags |= BG_HAS_RENDER;
1155 XFilters *filters = XRenderQueryFilters (dpy, vt);
1156 if (filters)
1157 {
1158 for (int i = 0; i < filters->nfilter; i++)
1159 if (!strcmp (filters->filter[i], FilterConvolution))
1160 bg_flags |= BG_HAS_RENDER_CONV;
1161
1162 XFree (filters);
1163 }
1164#endif
1165} 1156}
1166 1157
1167#endif /* HAVE_BG_PIXMAP */
1168
1169#ifdef ENABLE_TRANSPARENCY
1170/* based on code from aterm-0.4.2 */ 1158/* based on code from aterm-0.4.2 */
1171 1159
1172static inline void 1160static inline void
1173fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) 1161fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1174{ 1162{
1180 lookup[i] = (tmp / 0xffff) << sh; 1168 lookup[i] = (tmp / 0xffff) << sh;
1181 } 1169 }
1182} 1170}
1183 1171
1184void 1172void
1185rxvt_term::tint_ximage (Visual *visual, XImage *ximage) 1173rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade)
1186{ 1174{
1175 unsigned int size_r, size_g, size_b;
1187 int sh_r, sh_g, sh_b; 1176 int sh_r, sh_g, sh_b;
1188 uint32_t mask_r, mask_g, mask_b; 1177 uint32_t mask_r, mask_g, mask_b;
1189 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1178 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1190 unsigned short low; 1179 unsigned short low;
1191 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 1180 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1196 mask_r = visual->red_mask; 1185 mask_r = visual->red_mask;
1197 mask_g = visual->green_mask; 1186 mask_g = visual->green_mask;
1198 mask_b = visual->blue_mask; 1187 mask_b = visual->blue_mask;
1199 1188
1200 /* boring lookup table pre-initialization */ 1189 /* boring lookup table pre-initialization */
1201 switch (ximage->depth) 1190 sh_r = ecb_ctz32 (mask_r);
1202 { 1191 sh_g = ecb_ctz32 (mask_g);
1203 case 15: 1192 sh_b = ecb_ctz32 (mask_b);
1204 if ((mask_r != 0x7c00) || 1193
1205 (mask_g != 0x03e0) || 1194 size_r = mask_r >> sh_r;
1206 (mask_b != 0x001f)) 1195 size_g = mask_g >> sh_g;
1196 size_b = mask_b >> sh_b;
1197
1198 if (size_r++ > 255 || size_g++ > 255 || size_b++ > 255)
1207 return; 1199 return;
1208 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32)); 1200
1201 lookup = (uint32_t *)malloc (sizeof (uint32_t) * (size_r + size_g + size_b));
1209 lookup_r = lookup; 1202 lookup_r = lookup;
1210 lookup_g = lookup+32; 1203 lookup_g = lookup + size_r;
1211 lookup_b = lookup+32+32; 1204 lookup_b = lookup + size_r + size_g;
1212 sh_r = 10;
1213 sh_g = 5;
1214 sh_b = 0;
1215 break;
1216 case 16:
1217 if ((mask_r != 0xf800) ||
1218 (mask_g != 0x07e0) ||
1219 (mask_b != 0x001f))
1220 return;
1221 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32));
1222 lookup_r = lookup;
1223 lookup_g = lookup+32;
1224 lookup_b = lookup+32+64;
1225 sh_r = 11;
1226 sh_g = 5;
1227 sh_b = 0;
1228 break;
1229 case 24:
1230 if ((mask_r != 0xff0000) ||
1231 (mask_g != 0x00ff00) ||
1232 (mask_b != 0x0000ff))
1233 return;
1234 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1235 lookup_r = lookup;
1236 lookup_g = lookup+256;
1237 lookup_b = lookup+256+256;
1238 sh_r = 16;
1239 sh_g = 8;
1240 sh_b = 0;
1241 break;
1242 case 32:
1243 if ((mask_r != 0xff0000) ||
1244 (mask_g != 0x00ff00) ||
1245 (mask_b != 0x0000ff))
1246 return;
1247 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1248 lookup_r = lookup;
1249 lookup_g = lookup+256;
1250 lookup_b = lookup+256+256;
1251 sh_r = 16;
1252 sh_g = 8;
1253 sh_b = 0;
1254 break;
1255 default:
1256 return; /* we do not support this color depth */
1257 }
1258 1205
1259 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1206 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1260 1207
1261 if (bg_flags & BG_TINT_SET) 1208 if (tint_set)
1262 tint.get (c); 1209 tint.get (c);
1263 1210
1264 /* prepare limits for color transformation (each channel is handled separately) */ 1211 /* prepare limits for color transformation (each channel is handled separately) */
1265 if (shade > 100) 1212 if (shade > 100)
1266 { 1213 {
1284 fill_lut (lookup_g, mask_g, sh_g, low, c.g); 1231 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1285 fill_lut (lookup_b, mask_b, sh_b, low, c.b); 1232 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1286 1233
1287 /* apply table to input image (replacing colors by newly calculated ones) */ 1234 /* apply table to input image (replacing colors by newly calculated ones) */
1288 if (ximage->bits_per_pixel == 32 1235 if (ximage->bits_per_pixel == 32
1289 && (ximage->depth == 24 || ximage->depth == 32)
1290 && ximage->byte_order == host_byte_order) 1236 && ximage->byte_order == host_byte_order)
1291 { 1237 {
1292 char *line = ximage->data; 1238 char *line = ximage->data;
1293 1239
1294 for (int y = 0; y < ximage->height; y++) 1240 for (int y = 0; y < ximage->height; y++)
1295 { 1241 {
1296 uint32_t *p = (uint32_t *)line; 1242 uint32_t *p = (uint32_t *)line;
1297 for (int x = 0; x < ximage->width; x++) 1243 for (int x = 0; x < ximage->width; x++)
1298 { 1244 {
1299 *p = lookup_r[(*p & 0xff0000) >> 16] | 1245 *p = lookup_r[(*p & mask_r) >> sh_r] |
1300 lookup_g[(*p & 0x00ff00) >> 8] | 1246 lookup_g[(*p & mask_g) >> sh_g] |
1301 lookup_b[(*p & 0x0000ff)] | 1247 lookup_b[(*p & mask_b) >> sh_b];
1302 (*p & 0xff000000);
1303 p++; 1248 p++;
1304 } 1249 }
1305 line += ximage->bytes_per_line; 1250 line += ximage->bytes_per_line;
1306 } 1251 }
1307 } 1252 }
1318 } 1263 }
1319 } 1264 }
1320 1265
1321 free (lookup); 1266 free (lookup);
1322} 1267}
1323#endif /* ENABLE_TRANSPARENCY */ 1268
1269#endif /* HAVE_BG_PIXMAP */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines