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.206 by sf-exg, Thu Apr 12 10:22:50 2012 UTC vs.
Revision 1.235 by sf-exg, Thu Jun 7 09:34:51 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; 359 int width_r, width_g, width_b, width_a;
354 int sh_r, sh_g, sh_b; 360 int sh_r, sh_g, sh_b, sh_a;
361 uint32_t red_mask, green_mask, blue_mask, alpha_mask;
355 int rowstride; 362 int rowstride;
356 int channels; 363 int channels;
357 unsigned char *row; 364 unsigned char *row;
358 365
359 if (visual->c_class != TrueColor) 366 if (visual->c_class != TrueColor)
360 return false; 367 return false;
361 368
362 if (depth == 24 || depth == 32) 369 if (argb)
363 bytes_per_pixel = 4; 370 {
364 else if (depth == 15 || depth == 16) 371 red_mask = 0xff << 16;
365 bytes_per_pixel = 2; 372 green_mask = 0xff << 8;
373 blue_mask = 0xff;
374 alpha_mask = 0xff << 24;
375 }
366 else 376 else
377 {
378 red_mask = visual->red_mask;
379 green_mask = visual->green_mask;
380 blue_mask = visual->blue_mask;
381#if XRENDER
382 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
383 if (format)
384 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha;
385 else
386#endif
387 alpha_mask = 0;
388 }
389
390 width_r = ecb_popcount32 (red_mask);
391 width_g = ecb_popcount32 (green_mask);
392 width_b = ecb_popcount32 (blue_mask);
393 width_a = ecb_popcount32 (alpha_mask);
394
395 if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8)
367 return false; 396 return false;
368 397
369 width_r = ecb_popcount32 (visual->red_mask); 398 sh_r = ecb_ctz32 (red_mask);
370 width_g = ecb_popcount32 (visual->green_mask); 399 sh_g = ecb_ctz32 (green_mask);
371 width_b = ecb_popcount32 (visual->blue_mask); 400 sh_b = ecb_ctz32 (blue_mask);
401 sh_a = ecb_ctz32 (alpha_mask);
372 402
373 if (width_r > 8 || width_g > 8 || width_b > 8) 403 if (width > 32767 || height > 32767)
374 return false; 404 return false;
375 405
376 sh_r = ecb_ctz32 (visual->red_mask); 406 ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0,
377 sh_g = ecb_ctz32 (visual->green_mask); 407 width, height, 32, 0);
378 sh_b = ecb_ctz32 (visual->blue_mask); 408 if (!ximage)
379
380 if (width > INT_MAX / height / bytes_per_pixel)
381 return false; 409 return false;
382 410
383 data = (char *)malloc (width * height * bytes_per_pixel); 411 if (height > INT_MAX / ximage->bytes_per_line
384 if (!data) 412 || !(ximage->data = (char *)malloc (height * ximage->bytes_per_line)))
385 return false;
386
387 ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, data,
388 width, height, bytes_per_pixel * 8, 0);
389 if (!ximage)
390 { 413 {
391 free (data); 414 XDestroyImage (ximage);
392 return false; 415 return false;
393 } 416 }
394 417
395 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 418 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
396 419
397 rowstride = gdk_pixbuf_get_rowstride (pixbuf); 420 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
398 channels = gdk_pixbuf_get_n_channels (pixbuf); 421 channels = gdk_pixbuf_get_n_channels (pixbuf);
399 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;
400 line = data; 423 line = ximage->data;
424
425 rgba c (0, 0, 0);
426
427 if (channels == 4 && alpha_mask == 0)
428 {
429 pix_colors[Color_bg].get (c);
430 c.r >>= 8;
431 c.g >>= 8;
432 c.b >>= 8;
433 }
401 434
402 for (int y = 0; y < height; y++) 435 for (int y = 0; y < height; y++)
403 { 436 {
404 for (int x = 0; x < width; x++) 437 for (int x = 0; x < width; x++)
405 { 438 {
406 unsigned char *pixel = row + x * channels; 439 unsigned char *pixel = row + x * channels;
407 uint32_t value; 440 uint32_t value;
441 unsigned char r, g, b, a;
408 442
443 if (channels == 4)
444 {
445 a = pixel[3];
446 r = (pixel[0] * a + c.r * (0xff - a)) / 0xff;
447 g = (pixel[1] * a + c.g * (0xff - a)) / 0xff;
448 b = (pixel[2] * a + c.b * (0xff - a)) / 0xff;
449 }
450 else
451 {
452 a = 0xff;
453 r = pixel[0];
454 g = pixel[1];
455 b = pixel[2];
456 }
457
409 value = ((pixel[0] >> (8 - width_r)) << sh_r) 458 value = ((r >> (8 - width_r)) << sh_r)
410 | ((pixel[1] >> (8 - width_g)) << sh_g) 459 | ((g >> (8 - width_g)) << sh_g)
411 | ((pixel[2] >> (8 - width_b)) << sh_b); 460 | ((b >> (8 - width_b)) << sh_b)
461 | ((a >> (8 - width_a)) << sh_a);
412 462
413 if (bytes_per_pixel == 4) 463 if (ximage->bits_per_pixel == 32)
414 ((uint32_t *)line)[x] = value; 464 ((uint32_t *)line)[x] = value;
415 else 465 else
416 ((uint16_t *)line)[x] = value; 466 XPutPixel (ximage, x, y, value);
417 } 467 }
418 468
419 row += rowstride; 469 row += rowstride;
420 line += ximage->bytes_per_line; 470 line += ximage->bytes_per_line;
421 } 471 }
424 XDestroyImage (ximage); 474 XDestroyImage (ximage);
425 return true; 475 return true;
426} 476}
427 477
428bool 478bool
429rxvt_term::render_image (bool transparent) 479rxvt_term::render_image (rxvt_image &image)
430{ 480{
481 GdkPixbuf *pixbuf = image.pixbuf;
431 if (!pixbuf) 482 if (!pixbuf)
432 return false; 483 return false;
433 484
434 if (transparent 485 bool need_blend = bg_flags & BG_IS_VALID;
486
487 if (need_blend
435 && !(bg_flags & BG_HAS_RENDER)) 488 && !(display->flags & DISPLAY_HAS_RENDER))
436 return false; 489 return false;
437 490
438 GdkPixbuf *result; 491 GdkPixbuf *result;
439 492
440 int image_width = gdk_pixbuf_get_width (pixbuf); 493 int image_width = gdk_pixbuf_get_width (pixbuf);
448 int x = 0; 501 int x = 0;
449 int y = 0; 502 int y = 0;
450 int w = 0; 503 int w = 0;
451 int h = 0; 504 int h = 0;
452 505
453 get_image_geometry (image_width, image_height, w, h, x, y); 506 get_image_geometry (image, w, h, x, y);
454 507
455 if (!(bg_flags & BG_ROOT_ALIGN) 508 if (!(image.flags & IM_ROOT_ALIGN)
456 && (x >= target_width 509 && (x >= target_width
457 || y >= target_height 510 || y >= target_height
458 || x + w <= 0 511 || x + w <= 0
459 || y + h <= 0)) 512 || y + h <= 0))
460 return false; 513 return false;
474 527
475 bool ret = false; 528 bool ret = false;
476 529
477 XGCValues gcv; 530 XGCValues gcv;
478 GC gc; 531 GC gc;
479 Pixmap root_pmap; 532 Pixmap tmp_pixmap;
480 533
481 image_width = gdk_pixbuf_get_width (result); 534 image_width = gdk_pixbuf_get_width (result);
482 image_height = gdk_pixbuf_get_height (result); 535 image_height = gdk_pixbuf_get_height (result);
483 536
484 if (transparent) 537 if (need_blend)
485 { 538 tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32);
486 root_pmap = bg_pixmap;
487 bg_pixmap = None;
488 }
489 else 539 else
490 { 540 {
491 if (bg_flags & BG_TILE) 541 if (image.flags & IM_TILE)
492 { 542 {
493 new_pmap_width = min (image_width, target_width); 543 new_pmap_width = min (image_width, target_width);
494 new_pmap_height = min (image_height, target_height); 544 new_pmap_height = min (image_height, target_height);
495 } 545 }
496 }
497 546
498 if (bg_pixmap == None 547 if (bg_pixmap == None
499 || bg_pmap_width != new_pmap_width 548 || bg_pmap_width != new_pmap_width
500 || bg_pmap_height != new_pmap_height) 549 || bg_pmap_height != new_pmap_height)
501 { 550 {
502 if (bg_pixmap) 551 if (bg_pixmap)
503 XFreePixmap (dpy, bg_pixmap); 552 XFreePixmap (dpy, bg_pixmap);
504 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);
505 bg_pmap_width = new_pmap_width; 554 bg_pmap_width = new_pmap_width;
506 bg_pmap_height = new_pmap_height; 555 bg_pmap_height = new_pmap_height;
556 }
557
558 tmp_pixmap = bg_pixmap;
507 } 559 }
508 560
509 gcv.foreground = pix_colors[Color_bg]; 561 gcv.foreground = pix_colors[Color_bg];
510 gc = XCreateGC (dpy, vt, GCForeground, &gcv); 562 gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv);
511 563
512 if (gc) 564 if (gc)
513 { 565 {
514 if (bg_flags & BG_TILE) 566 if (image.flags & IM_TILE)
515 { 567 {
516 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); 568 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth);
517 pixbuf_to_pixmap (result, tile, gc, 569 pixbuf_to_pixmap (result, tile, gc,
518 0, 0, 570 0, 0,
519 0, 0, 571 0, 0,
520 image_width, image_height); 572 image_width, image_height, need_blend);
521 573
522 gcv.tile = tile; 574 gcv.tile = tile;
523 gcv.fill_style = FillTiled; 575 gcv.fill_style = FillTiled;
524 gcv.ts_x_origin = x; 576 gcv.ts_x_origin = x;
525 gcv.ts_y_origin = y; 577 gcv.ts_y_origin = y;
526 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 578 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
527 579
528 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);
529 XFreePixmap (dpy, tile); 581 XFreePixmap (dpy, tile);
530 } 582 }
531 else 583 else
532 { 584 {
533 int src_x, src_y, dst_x, dst_y; 585 int src_x, src_y, dst_x, dst_y;
537 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);
538 590
539 if (dst_x > 0 || dst_y > 0 591 if (dst_x > 0 || dst_y > 0
540 || dst_x + dst_width < new_pmap_width 592 || dst_x + dst_width < new_pmap_width
541 || dst_y + dst_height < new_pmap_height) 593 || dst_y + dst_height < new_pmap_height)
542 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);
543 595
544 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 596 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
545 pixbuf_to_pixmap (result, bg_pixmap, gc, 597 pixbuf_to_pixmap (result, tmp_pixmap, gc,
546 src_x, src_y, 598 src_x, src_y,
547 dst_x, dst_y, 599 dst_x, dst_y,
548 dst_width, dst_height); 600 dst_width, dst_height, need_blend);
549 } 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);
550 607
551#if XRENDER 608#if XRENDER
552 if (transparent) 609 if (need_blend)
553 { 610 {
611 XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
554 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 612 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
555 613
556 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); 614 Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0);
557 615
558 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); 616 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
559 617
560 Picture mask = create_xrender_mask (dpy, vt, False, False); 618 Picture mask = create_xrender_mask (dpy, vt, False, False);
561 619
562 XRenderColor mask_c; 620 XRenderColor mask_c;
563 621
564 mask_c.alpha = 0x8000; 622 mask_c.alpha = image.alpha;
565 mask_c.red = 623 mask_c.red =
566 mask_c.green = 624 mask_c.green =
567 mask_c.blue = 0; 625 mask_c.blue = 0;
568 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 626 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
569 627
581 } 639 }
582 640
583 if (result != pixbuf) 641 if (result != pixbuf)
584 g_object_unref (result); 642 g_object_unref (result);
585 643
586 if (transparent) 644 if (need_blend)
587 XFreePixmap (dpy, root_pmap); 645 XFreePixmap (dpy, tmp_pixmap);
588 646
589 return ret; 647 return ret;
590} 648}
591# endif /* HAVE_PIXBUF */ 649# endif /* HAVE_PIXBUF */
592 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
593bool 665bool
594rxvt_term::bg_set_file (const char *file) 666rxvt_image::set_file_geometry (const char *file)
595{ 667{
596 if (!file || !*file) 668 if (!file || !*file)
597 return false; 669 return false;
598 670
599 bool ret = false;
600 const char *p = strchr (file, ';'); 671 const char *p = strchr (file, ';');
601 672
602 if (p) 673 if (p)
603 { 674 {
604 size_t len = p - file; 675 size_t len = p - file;
606 memcpy (f, file, len); 677 memcpy (f, file, len);
607 f[len] = '\0'; 678 f[len] = '\0';
608 file = f; 679 file = f;
609 } 680 }
610 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
611# ifdef HAVE_PIXBUF 694# if HAVE_PIXBUF
612 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 695 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
613 if (image) 696 if (image)
614 { 697 {
615 if (pixbuf) 698 if (pixbuf)
616 g_object_unref (pixbuf); 699 g_object_unref (pixbuf);
617 pixbuf = image; 700 pixbuf = image;
618 bg_flags |= BG_IS_FROM_FILE;
619 ret = true; 701 ret = true;
620 } 702 }
621# endif 703# endif
622 704
623 if (ret) 705 if (ret)
624 { 706 flags |= IM_IS_SET;
625 if (p)
626 bg_set_geometry (p + 1);
627 else
628 bg_set_default_geometry ();
629 }
630 707
631 return ret; 708 return ret;
632} 709}
633 710
634# endif /* BG_IMAGE_FROM_FILE */ 711# endif /* BG_IMAGE_FROM_FILE */
635 712
636# ifdef ENABLE_TRANSPARENCY
637bool 713bool
638rxvt_term::bg_set_transparent () 714image_effects::set_blur (const char *geom)
639{
640 if (!(bg_flags & BG_IS_TRANSPARENT))
641 {
642 bg_flags |= BG_IS_TRANSPARENT;
643 return true;
644 }
645
646 return false;
647}
648
649bool
650rxvt_term::bg_set_blur (const char *geom)
651{ 715{
652 bool changed = false; 716 bool changed = false;
653 unsigned int hr, vr; 717 unsigned int hr, vr;
654 int junk; 718 int junk;
655 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 719 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
672 { 736 {
673 changed = true; 737 changed = true;
674 v_blurRadius = vr; 738 v_blurRadius = vr;
675 } 739 }
676 740
677 if (h_blurRadius && v_blurRadius)
678 bg_flags |= BG_NEEDS_BLUR;
679 else
680 bg_flags &= ~BG_NEEDS_BLUR;
681
682 return changed; 741 return changed;
683} 742}
684 743
685void
686rxvt_term::set_tint_shade_flags ()
687{
688 if (shade != 100 || (bg_flags & BG_TINT_SET))
689 bg_flags |= BG_NEEDS_TINT;
690 else
691 bg_flags &= ~BG_NEEDS_TINT;
692}
693
694bool 744bool
695rxvt_term::bg_set_tint (rxvt_color &new_tint) 745image_effects::set_tint (const rxvt_color &new_tint)
696{ 746{
697 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 747 if (!tint_set || tint != new_tint)
698 { 748 {
699 tint = new_tint; 749 tint = new_tint;
700 bg_flags |= BG_TINT_SET; 750 tint_set = true;
701 751
702 rgba c;
703 tint.get (c);
704 if ((c.r <= 0x00ff || c.r >= 0xff00)
705 && (c.g <= 0x00ff || c.g >= 0xff00)
706 && (c.b <= 0x00ff || c.b >= 0xff00))
707 bg_flags |= BG_TINT_BITAND;
708 else
709 bg_flags &= ~BG_TINT_BITAND;
710
711 set_tint_shade_flags ();
712 return true; 752 return true;
713 } 753 }
714 754
715 return false; 755 return false;
716} 756}
717 757
718bool 758bool
719rxvt_term::bg_set_shade (const char *shade_str) 759image_effects::set_shade (const char *shade_str)
720{ 760{
721 int new_shade = atoi (shade_str); 761 int new_shade = atoi (shade_str);
722 762
723 clamp_it (new_shade, -100, 200); 763 clamp_it (new_shade, -100, 200);
724 if (new_shade < 0) 764 if (new_shade < 0)
725 new_shade = 200 - (100 + new_shade); 765 new_shade = 200 - (100 + new_shade);
726 766
727 if (new_shade != shade) 767 if (new_shade != shade)
728 { 768 {
729 shade = new_shade; 769 shade = new_shade;
730 set_tint_shade_flags ();
731 return true; 770 return true;
732 } 771 }
733 772
734 return false; 773 return false;
735} 774}
756 params[i+2] = XDoubleToFixed (kernel[i] / sum); 795 params[i+2] = XDoubleToFixed (kernel[i] / sum);
757} 796}
758#endif 797#endif
759 798
760bool 799bool
761rxvt_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)
762{ 801{
763 bool ret = false; 802 bool ret = false;
764#if XRENDER 803#if XRENDER
765 if (!(bg_flags & BG_HAS_RENDER_CONV)) 804 if (!(display->flags & DISPLAY_HAS_RENDER_CONV))
766 return false; 805 return false;
767 806
768 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 807 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
769 double *kernel = (double *)malloc (size * sizeof (double)); 808 double *kernel = (double *)malloc (size * sizeof (double));
770 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 809 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
771 810
772 XRenderPictureAttributes pa; 811 XRenderPictureAttributes pa;
773 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 812 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
813 : XRenderFindVisualFormat (dpy, visual);
774 814
775 pa.repeat = RepeatPad; 815 pa.repeat = RepeatPad;
776 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); 816 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
777 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); 817 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth);
778 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); 818 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
821#endif 861#endif
822 return ret; 862 return ret;
823} 863}
824 864
825bool 865bool
826rxvt_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)
827{ 867{
828 bool ret = false; 868 bool ret = false;
829 869
830 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))
831 { 879 {
832 XGCValues gcv; 880 XGCValues gcv;
833 GC gc; 881 GC gc;
834 882
835 /* In this case we can tint image server-side getting significant 883 /* In this case we can tint image server-side getting significant
845 ret = true; 893 ret = true;
846 XFreeGC (dpy, gc); 894 XFreeGC (dpy, gc);
847 } 895 }
848 } 896 }
849# if XRENDER 897# if XRENDER
850 else if (bg_flags & BG_HAS_RENDER) 898 else if (display->flags & DISPLAY_HAS_RENDER)
851 { 899 {
852 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
853
854 if (bg_flags & BG_TINT_SET)
855 tint.get (c);
856
857 if (shade <= 100) 900 if (shade <= 100)
858 { 901 {
859 c.r = c.r * shade / 100; 902 c.r = c.r * shade / 100;
860 c.g = c.g * shade / 100; 903 c.g = c.g * shade / 100;
861 c.b = c.b * shade / 100; 904 c.b = c.b * shade / 100;
865 c.r = c.r * (200 - shade) / 100; 908 c.r = c.r * (200 - shade) / 100;
866 c.g = c.g * (200 - shade) / 100; 909 c.g = c.g * (200 - shade) / 100;
867 c.b = c.b * (200 - shade) / 100; 910 c.b = c.b * (200 - shade) / 100;
868 } 911 }
869 912
870 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 913 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
914 : XRenderFindVisualFormat (dpy, visual);
871 915
872 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); 916 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
873 917
874 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); 918 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
875 919
911# endif 955# endif
912 956
913 return ret; 957 return ret;
914} 958}
915 959
960# if ENABLE_TRANSPARENCY
916/* 961/*
917 * 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
918 * 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
919 * our window. 964 * our window.
920 */ 965 */
921bool 966bool
922rxvt_term::make_transparency_pixmap () 967rxvt_term::render_root_image ()
923{ 968{
924 bool ret = false; 969 bool ret = false;
925 970
926 /* 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
927 * be always up-to-date, so let's use it : 972 * be always up-to-date, so let's use it :
963 Pixmap recoded_root_pmap = root_pixmap; 1008 Pixmap recoded_root_pmap = root_pixmap;
964 1009
965 if (root_pixmap != None && root_depth != depth) 1010 if (root_pixmap != None && root_depth != depth)
966 { 1011 {
967#if XRENDER 1012#if XRENDER
968 if (bg_flags & BG_HAS_RENDER) 1013 if (display->flags & DISPLAY_HAS_RENDER)
969 { 1014 {
970 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);
971 1016
972 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1017 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
973 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); 1018 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1011 1056
1012 if (gc) 1057 if (gc)
1013 { 1058 {
1014 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1059 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1015 ret = true; 1060 ret = true;
1016 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 ();
1017 1063
1018 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;
1019 { 1069 }
1020 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)
1021 { 1080 {
1022 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) 1081 /* our own client-side tinting */
1023 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);
1024 } 1086 }
1025 if (bg_flags & BG_NEEDS_TINT)
1026 {
1027 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1028 tr_flags &= ~BG_NEEDS_TINT;
1029 } 1087 }
1030 if (tr_flags & BG_NEEDS_TINT)
1031 {
1032 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1033 if (ximage)
1034 {
1035 /* our own client-side tinting */
1036 tint_ximage (DefaultVisual (dpy, display->screen), ximage);
1037
1038 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1039 XDestroyImage (ximage);
1040 }
1041 }
1042 } /* server side rendering completed */
1043 1088
1044 XFreeGC (dpy, gc); 1089 XFreeGC (dpy, gc);
1045 } 1090 }
1046 1091
1047 if (recoded_root_pmap != root_pixmap) 1092 if (recoded_root_pmap != root_pixmap)
1051} 1096}
1052 1097
1053void 1098void
1054rxvt_term::bg_set_root_pixmap () 1099rxvt_term::bg_set_root_pixmap ()
1055{ 1100{
1056 Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]); 1101 Pixmap new_root_pixmap = display->get_pixmap_property (xa[XA_XROOTPMAP_ID]);
1057 if (new_root_pixmap == None) 1102 if (new_root_pixmap == None)
1058 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); 1103 new_root_pixmap = display->get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1059 1104
1060 root_pixmap = new_root_pixmap; 1105 root_pixmap = new_root_pixmap;
1061} 1106}
1062# endif /* ENABLE_TRANSPARENCY */ 1107# endif /* ENABLE_TRANSPARENCY */
1063 1108
1064bool 1109void
1065rxvt_term::bg_render () 1110rxvt_term::bg_render ()
1066{ 1111{
1067 bool transparent = false; 1112 if (bg_flags & BG_INHIBIT_RENDER)
1113 return;
1068 1114
1069 bg_invalidate (); 1115 bg_invalidate ();
1070# ifdef ENABLE_TRANSPARENCY 1116# if ENABLE_TRANSPARENCY
1071 if (bg_flags & BG_IS_TRANSPARENT) 1117 if (bg_flags & BG_IS_TRANSPARENT)
1072 { 1118 {
1073 /* we need to re-generate transparency pixmap in that case ! */ 1119 /* we need to re-generate transparency pixmap in that case ! */
1074 transparent = make_transparency_pixmap (); 1120 if (render_root_image ())
1075 if (transparent)
1076 bg_flags |= BG_IS_VALID; 1121 bg_flags |= BG_IS_VALID;
1077 } 1122 }
1078# endif 1123# endif
1079 1124
1080# ifdef BG_IMAGE_FROM_FILE 1125# if BG_IMAGE_FROM_FILE
1081 if (bg_flags & BG_IS_FROM_FILE) 1126 if (fimage.flags & IM_IS_SET)
1082 { 1127 {
1083 if (render_image (transparent)) 1128 if (render_image (fimage))
1084 bg_flags |= BG_IS_VALID; 1129 bg_flags |= BG_IS_VALID;
1085 } 1130 }
1086# endif 1131# endif
1087 1132
1088 if (!(bg_flags & BG_IS_VALID)) 1133 if (!(bg_flags & BG_IS_VALID))
1096 1141
1097 scr_recolour (false); 1142 scr_recolour (false);
1098 bg_flags |= BG_NEEDS_REFRESH; 1143 bg_flags |= BG_NEEDS_REFRESH;
1099 1144
1100 bg_valid_since = ev::now (); 1145 bg_valid_since = ev::now ();
1101
1102 return true;
1103} 1146}
1104 1147
1105void 1148void
1106rxvt_term::bg_init () 1149rxvt_term::bg_init ()
1107{ 1150{
1108#ifdef ENABLE_TRANSPARENCY 1151#if BG_IMAGE_FROM_FILE
1109 shade = 100; 1152 if (rs[Rs_backgroundPixmap])
1153 {
1154 if (fimage.set_file_geometry (rs[Rs_backgroundPixmap])
1155 && !bg_window_position_sensitive ())
1156 update_background ();
1157 }
1110#endif 1158#endif
1111
1112 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1113#if XRENDER
1114 int major, minor;
1115 if (XRenderQueryVersion (dpy, &major, &minor))
1116 bg_flags |= BG_HAS_RENDER;
1117 XFilters *filters = XRenderQueryFilters (dpy, vt);
1118 if (filters)
1119 {
1120 for (int i = 0; i < filters->nfilter; i++)
1121 if (!strcmp (filters->filter[i], FilterConvolution))
1122 bg_flags |= BG_HAS_RENDER_CONV;
1123
1124 XFree (filters);
1125 }
1126#endif
1127} 1159}
1128 1160
1129#endif /* HAVE_BG_PIXMAP */
1130
1131#ifdef ENABLE_TRANSPARENCY
1132/* based on code from aterm-0.4.2 */ 1161/* based on code from aterm-0.4.2 */
1133 1162
1134static inline void 1163static inline void
1135fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) 1164fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1136{ 1165{
1142 lookup[i] = (tmp / 0xffff) << sh; 1171 lookup[i] = (tmp / 0xffff) << sh;
1143 } 1172 }
1144} 1173}
1145 1174
1146void 1175void
1147rxvt_term::tint_ximage (Visual *visual, XImage *ximage) 1176rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade)
1148{ 1177{
1178 unsigned int size_r, size_g, size_b;
1149 int sh_r, sh_g, sh_b; 1179 int sh_r, sh_g, sh_b;
1150 uint32_t mask_r, mask_g, mask_b; 1180 uint32_t mask_r, mask_g, mask_b;
1151 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1181 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1152 unsigned short low; 1182 unsigned short low;
1153 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 1183 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1158 mask_r = visual->red_mask; 1188 mask_r = visual->red_mask;
1159 mask_g = visual->green_mask; 1189 mask_g = visual->green_mask;
1160 mask_b = visual->blue_mask; 1190 mask_b = visual->blue_mask;
1161 1191
1162 /* boring lookup table pre-initialization */ 1192 /* boring lookup table pre-initialization */
1163 switch (ximage->depth) 1193 sh_r = ecb_ctz32 (mask_r);
1164 { 1194 sh_g = ecb_ctz32 (mask_g);
1165 case 15: 1195 sh_b = ecb_ctz32 (mask_b);
1166 if ((mask_r != 0x7c00) || 1196
1167 (mask_g != 0x03e0) || 1197 size_r = mask_r >> sh_r;
1168 (mask_b != 0x001f)) 1198 size_g = mask_g >> sh_g;
1199 size_b = mask_b >> sh_b;
1200
1201 if (size_r++ > 255 || size_g++ > 255 || size_b++ > 255)
1169 return; 1202 return;
1170 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32)); 1203
1204 lookup = (uint32_t *)malloc (sizeof (uint32_t) * (size_r + size_g + size_b));
1171 lookup_r = lookup; 1205 lookup_r = lookup;
1172 lookup_g = lookup+32; 1206 lookup_g = lookup + size_r;
1173 lookup_b = lookup+32+32; 1207 lookup_b = lookup + size_r + size_g;
1174 sh_r = 10;
1175 sh_g = 5;
1176 sh_b = 0;
1177 break;
1178 case 16:
1179 if ((mask_r != 0xf800) ||
1180 (mask_g != 0x07e0) ||
1181 (mask_b != 0x001f))
1182 return;
1183 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32));
1184 lookup_r = lookup;
1185 lookup_g = lookup+32;
1186 lookup_b = lookup+32+64;
1187 sh_r = 11;
1188 sh_g = 5;
1189 sh_b = 0;
1190 break;
1191 case 24:
1192 if ((mask_r != 0xff0000) ||
1193 (mask_g != 0x00ff00) ||
1194 (mask_b != 0x0000ff))
1195 return;
1196 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1197 lookup_r = lookup;
1198 lookup_g = lookup+256;
1199 lookup_b = lookup+256+256;
1200 sh_r = 16;
1201 sh_g = 8;
1202 sh_b = 0;
1203 break;
1204 case 32:
1205 if ((mask_r != 0xff0000) ||
1206 (mask_g != 0x00ff00) ||
1207 (mask_b != 0x0000ff))
1208 return;
1209 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1210 lookup_r = lookup;
1211 lookup_g = lookup+256;
1212 lookup_b = lookup+256+256;
1213 sh_r = 16;
1214 sh_g = 8;
1215 sh_b = 0;
1216 break;
1217 default:
1218 return; /* we do not support this color depth */
1219 }
1220 1208
1221 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1209 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1222 1210
1223 if (bg_flags & BG_TINT_SET) 1211 if (tint_set)
1224 tint.get (c); 1212 tint.get (c);
1225 1213
1226 /* prepare limits for color transformation (each channel is handled separately) */ 1214 /* prepare limits for color transformation (each channel is handled separately) */
1227 if (shade > 100) 1215 if (shade > 100)
1228 { 1216 {
1246 fill_lut (lookup_g, mask_g, sh_g, low, c.g); 1234 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1247 fill_lut (lookup_b, mask_b, sh_b, low, c.b); 1235 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1248 1236
1249 /* apply table to input image (replacing colors by newly calculated ones) */ 1237 /* apply table to input image (replacing colors by newly calculated ones) */
1250 if (ximage->bits_per_pixel == 32 1238 if (ximage->bits_per_pixel == 32
1251 && (ximage->depth == 24 || ximage->depth == 32)
1252 && ximage->byte_order == host_byte_order) 1239 && ximage->byte_order == host_byte_order)
1253 { 1240 {
1254 uint32_t *p1, *pf, *p, *pl; 1241 char *line = ximage->data;
1255 p1 = (uint32_t *) ximage->data;
1256 pf = (uint32_t *) (ximage->data + ximage->height * ximage->bytes_per_line);
1257 1242
1258 while (p1 < pf) 1243 for (int y = 0; y < ximage->height; y++)
1259 { 1244 {
1260 p = p1; 1245 uint32_t *p = (uint32_t *)line;
1261 pl = p1 + ximage->width; 1246 for (int x = 0; x < ximage->width; x++)
1262 for (; p < pl; p++)
1263 { 1247 {
1264 *p = lookup_r[(*p & 0xff0000) >> 16] | 1248 *p = lookup_r[(*p & mask_r) >> sh_r] |
1265 lookup_g[(*p & 0x00ff00) >> 8] | 1249 lookup_g[(*p & mask_g) >> sh_g] |
1266 lookup_b[(*p & 0x0000ff)] | 1250 lookup_b[(*p & mask_b) >> sh_b];
1267 (*p & 0xff000000); 1251 p++;
1268 } 1252 }
1269 p1 = (uint32_t *) ((char *) p1 + ximage->bytes_per_line); 1253 line += ximage->bytes_per_line;
1270 } 1254 }
1271 } 1255 }
1272 else 1256 else
1273 { 1257 {
1274 for (int y = 0; y < ximage->height; y++) 1258 for (int y = 0; y < ximage->height; y++)
1282 } 1266 }
1283 } 1267 }
1284 1268
1285 free (lookup); 1269 free (lookup);
1286} 1270}
1287#endif /* ENABLE_TRANSPARENCY */ 1271
1272#endif /* HAVE_BG_PIXMAP */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines