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.82 by sf-exg, Thu Oct 14 16:01:28 2010 UTC vs.
Revision 1.139 by sf-exg, Sat Jan 22 15:41:19 2011 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 <pcg@goof.com> 6 * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com>
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 * 9 *
9 * 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
10 * 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
11 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version. 13 * (at your option) any later version.
23 24
24#include <cmath> 25#include <cmath>
25#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
26#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
27 28
28#define DO_TIMING_TEST 0 29#if XRENDER
30# include <X11/extensions/Xrender.h>
31#endif
29 32
30#if DO_TIMING_TEST 33#ifndef FilterConvolution
31# include <sys/time.h> 34#define FilterConvolution "convolution"
32#define TIMING_TEST_START(id) \
33 struct timeval timing_test_##id##_stv; \
34 gettimeofday (&timing_test_##id##_stv, NULL);
35
36#define TIMING_TEST_PRINT_RESULT(id) \
37 do { \
38 struct timeval tv; \
39 gettimeofday (&tv, NULL); \
40 tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \
41 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \
42 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \
43 } while (0)
44
45#else
46#define TIMING_TEST_START(id) do {} while (0)
47#define TIMING_TEST_PRINT_RESULT(id) do {} while (0)
48#endif 35#endif
49 36
50/* 37/*
51 * Pixmap geometry string interpretation : 38 * Pixmap geometry string interpretation :
52 * Each geometry string contains zero or one scale/position 39 * Each geometry string contains zero or one scale/position
57 * 44 *
58 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. 45 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
59 * W and H are percentages of the terminal window size. 46 * W and H are percentages of the terminal window size.
60 * X and Y are also percentages; e.g., +50+50 centers 47 * X and Y are also percentages; e.g., +50+50 centers
61 * the image in the window. 48 * the image in the window.
62 * WxH+X Assumes Y == X
63 * WxH Assumes Y == X == 50 (centers the image)
64 * W+X+Y Assumes H == W
65 * W+X Assumes H == W and Y == X
66 * W Assumes H == W and Y == X == 50
67 *
68 * Adjusting position only :
69 * =+X+Y Set position to X% by Y% (absolute).
70 * =+X Set position to X% by X%.
71 * +X+Y Adjust position horizontally X% and vertically Y%
72 * from current position (relative).
73 * +X Adjust position horizontally X% and vertically X%
74 * from current position.
75 *
76 * Adjusting scale only :
77 * Wx0 Multiply horizontal scaling factor by W%
78 * 0xH Multiply vertical scaling factor by H%
79 * 0x0 No scaling (show image at normal size).
80 * 49 *
81 * Pixmap Operations : (should be prepended by a colon) 50 * Pixmap Operations : (should be prepended by a colon)
82 * tile Tile image. Scaling/position modifiers above will affect 51 * tile Tile image. Scaling/position modifiers above will affect
83 * the tile size and origin. 52 * the tile size and origin.
84 * propscale When scaling, scale proportionally. That is, maintain the 53 * propscale When scaling, scale proportionally. That is, maintain the
110#ifdef ENABLE_TRANSPARENCY 79#ifdef ENABLE_TRANSPARENCY
111 shade = 100; 80 shade = 100;
112#endif 81#endif
113 flags = 0; 82 flags = 0;
114 pixmap = None; 83 pixmap = None;
115 valid_since = invalid_since = 0; 84 valid_since = 0;
116 target = 0; 85 target = 0;
86 target_x = target_y = 0;
117} 87}
118 88
119void 89void
120bgPixmap_t::destroy () 90bgPixmap_t::destroy ()
121{ 91{
132 if (pixmap && target) 102 if (pixmap && target)
133 XFreePixmap (target->dpy, pixmap); 103 XFreePixmap (target->dpy, pixmap);
134} 104}
135 105
136bool 106bool
107bgPixmap_t::set_position (int x, int y)
108{
109
110 if (target_x != x
111 || target_y != y)
112 {
113 target_x = x;
114 target_y = y;
115 return true;
116 }
117 return false;
118}
119
120bool
137bgPixmap_t::window_size_sensitive () 121bgPixmap_t::window_size_sensitive ()
138{ 122{
139# ifdef ENABLE_TRANSPARENCY 123# ifdef ENABLE_TRANSPARENCY
140 if (flags & isTransparent) 124 if (flags & isTransparent)
141 return true; 125 return true;
166 if (flags & rootAlign) 150 if (flags & rootAlign)
167 return true; 151 return true;
168 } 152 }
169# endif 153# endif
170 154
171 return false;
172};
173
174bool bgPixmap_t::need_client_side_rendering ()
175{
176# ifdef HAVE_AFTERIMAGE
177 if (original_asim)
178 return true;
179# endif
180# ifdef ENABLE_TRANSPARENCY
181 if (flags & isTransparent)
182 {
183# ifdef HAVE_AFTERIMAGE
184 if ((flags & blurNeeded) && !(flags & blurServerSide))
185 return true;
186# endif
187 if ((flags & tintNeeded) && !(flags & tintServerSide))
188 return true;
189 }
190# endif
191 return false; 155 return false;
192} 156}
193 157
194# ifdef BG_IMAGE_FROM_FILE 158# ifdef BG_IMAGE_FROM_FILE
195static inline bool 159static inline bool
232 int diff = window_size - image_size; 196 int diff = window_size - image_size;
233 int smaller = min (image_size, window_size); 197 int smaller = min (image_size, window_size);
234 198
235 if (align >= 0 && align <= 100) 199 if (align >= 0 && align <= 100)
236 return diff * align / 100; 200 return diff * align / 100;
237 else if (align > 100 && align <= 200 ) 201 else if (align > 100 && align <= 200)
238 return ((align - 100) * smaller / 100) + window_size - smaller; 202 return ((align - 100) * smaller / 100) + window_size - smaller;
239 else if (align >= -100 && align < 0) 203 else if (align >= -100 && align < 0)
240 return ((align + 100) * smaller / 100) - image_size; 204 return ((align + 100) * smaller / 100) - image_size;
241 return 0; 205 return 0;
242} 206}
258 dst_size = target_size - dst_pos; 222 dst_size = target_size - dst_pos;
259 return src_pos; 223 return src_pos;
260} 224}
261 225
262bool 226bool
263bgPixmap_t::set_geometry (const char *geom) 227bgPixmap_t::set_geometry (const char *geom, bool update)
264{ 228{
229 bool changed = false;
265 int geom_flags = 0, changed = 0; 230 int geom_flags = 0;
266 int x = 0, y = 0; 231 int x = 0, y = 0;
267 unsigned int w = 0, h = 0; 232 unsigned int w = 0, h = 0;
268 unsigned int n; 233 unsigned int n;
269 unsigned long new_flags = (flags & (~geometryFlags)); 234 unsigned long new_flags = (flags & (~geometryFlags));
270 const char *p; 235 const char *ops;
271# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
272 236
273 if (geom == NULL) 237 if (geom == NULL)
274 return false; 238 return false;
275 239
276 char str[MAXLEN_GEOM]; 240 char str[256];
277 241
278 while (isspace(*geom)) ++geom;
279 if ((p = strchr (geom, ';')) == NULL)
280 p = strchr (geom, '\0'); 242 ops = strchr (geom, ':');
281 243 if (ops == NULL)
244 n = strlen (geom);
245 else
282 n = (p - geom); 246 n = ops - geom;
283 if (n < MAXLEN_GEOM)
284 {
285 char *ops;
286 new_flags |= geometrySet;
287 247
248 if (n >= sizeof (str))
249 return false;
250
288 memcpy (str, geom, n); 251 memcpy (str, geom, n);
289 str[n] = '\0'; 252 str[n] = '\0';
290 if (str[0] == ':') 253 rxvt_strtrim (str);
291 ops = &str[0];
292 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
293 ops = &str[0];
294 else
295 {
296 char *tmp;
297 ops = strchr (str, ':');
298 if (ops != NULL)
299 {
300 for (tmp = ops-1; tmp >= str && isspace(*tmp); --tmp);
301 *(++tmp) = '\0';
302 if (ops == tmp) ++ops;
303 }
304 }
305 254
306 if (ops > str || ops == NULL) 255 if (str[0])
307 { 256 {
308 /* we have geometry string - let's handle it prior to applying ops */ 257 /* we have geometry string - let's handle it prior to applying ops */
309 geom_flags = XParseGeometry (str, &x, &y, &w, &h); 258 geom_flags = XParseGeometry (str, &x, &y, &w, &h);
310
311 if ((geom_flags & XValue) && !(geom_flags & YValue))
312 {
313 y = x;
314 geom_flags |= YValue;
315 }
316
317 if (flags & geometrySet)
318 {
319 /* new geometry is an adjustment to the old one ! */
320 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
321 {
322 if (w == 0 && h != 0)
323 {
324 w = h_scale;
325 h = (v_scale * h) / 100;
326 }
327 else if (h == 0 && w != 0)
328 {
329 w = (h_scale * w) / 100;
330 h = v_scale;
331 }
332 }
333 if (geom_flags & XValue)
334 {
335 if (str[0] != '=')
336 {
337 y += v_align;
338 x += h_align;
339 }
340 }
341 }
342 else /* setting up geometry from scratch */
343 {
344 if (!(geom_flags & XValue))
345 {
346 /* use default geometry - centered */
347 x = y = defaultAlign;
348 }
349 else if (!(geom_flags & YValue))
350 y = x;
351
352 if ((geom_flags & (WidthValue|HeightValue)) == 0)
353 {
354 /* use default geometry - scaled */
355 w = h = defaultScale;
356 }
357 else if (geom_flags & WidthValue)
358 {
359 if (!(geom_flags & HeightValue))
360 h = w;
361 }
362 else
363 w = h;
364 }
365 } /* done parsing geometry string */ 259 } /* done parsing geometry string */
366 else if (!(flags & geometrySet)) 260
367 { 261 if (!update)
368 /* default geometry - scaled and centered */ 262 {
263 if (!(geom_flags & XValue))
369 x = y = defaultAlign; 264 x = y = defaultAlign;
265 else if (!(geom_flags & YValue))
266 y = x;
267
268 if (!(geom_flags & (WidthValue|HeightValue)))
370 w = h = defaultScale; 269 w = h = defaultScale;
371 } 270 else if (!(geom_flags & HeightValue))
271 h = w;
272 else if (!(geom_flags & WidthValue))
273 w = h;
372 274
373 if (!(flags & geometrySet))
374 geom_flags |= WidthValue|HeightValue|XValue|YValue; 275 geom_flags |= WidthValue|HeightValue|XValue|YValue;
276 }
375 277
376 if (ops) 278 if (ops)
377 { 279 {
378 while (*ops) 280 char **arr = rxvt_strsplit (':', ops + 1);
281
282 for (int i = 0; arr[i]; i++)
379 { 283 {
380 while (*ops == ':' || isspace(*ops)) ++ops; 284 if (!strcasecmp (arr[i], "tile"))
381
382# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0)
383 if (CHECK_GEOM_OPS ("tile"))
384 { 285 {
385 w = h = noScale; 286 w = h = noScale;
386 geom_flags |= WidthValue|HeightValue; 287 geom_flags |= WidthValue|HeightValue;
387 } 288 }
388 else if (CHECK_GEOM_OPS ("propscale")) 289 else if (!strcasecmp (arr[i], "propscale"))
389 { 290 {
390 new_flags |= propScale; 291 new_flags |= propScale;
391 } 292 }
392 else if (CHECK_GEOM_OPS ("hscale")) 293 else if (!strcasecmp (arr[i], "hscale"))
393 { 294 {
394 if (w == 0) w = windowScale; 295 if (w == 0) w = windowScale;
395 296
396 h = noScale; 297 h = noScale;
397 geom_flags |= WidthValue|HeightValue; 298 geom_flags |= WidthValue|HeightValue;
398 } 299 }
399 else if (CHECK_GEOM_OPS ("vscale")) 300 else if (!strcasecmp (arr[i], "vscale"))
400 { 301 {
401 if (h == 0) h = windowScale; 302 if (h == 0) h = windowScale;
402 303
403 w = noScale; 304 w = noScale;
404 geom_flags |= WidthValue|HeightValue; 305 geom_flags |= WidthValue|HeightValue;
405 } 306 }
406 else if (CHECK_GEOM_OPS ("scale")) 307 else if (!strcasecmp (arr[i], "scale"))
407 { 308 {
408 if (h == 0) h = windowScale; 309 if (h == 0) h = windowScale;
409 if (w == 0) w = windowScale; 310 if (w == 0) w = windowScale;
410 311
411 geom_flags |= WidthValue|HeightValue; 312 geom_flags |= WidthValue|HeightValue;
412 } 313 }
413 else if (CHECK_GEOM_OPS ("auto")) 314 else if (!strcasecmp (arr[i], "auto"))
414 { 315 {
415 w = h = windowScale; 316 w = h = windowScale;
416 x = y = centerAlign; 317 x = y = centerAlign;
417 geom_flags |= WidthValue|HeightValue|XValue|YValue; 318 geom_flags |= WidthValue|HeightValue|XValue|YValue;
418 } 319 }
419 else if (CHECK_GEOM_OPS ("root")) 320 else if (!strcasecmp (arr[i], "root"))
420 { 321 {
421 new_flags |= rootAlign; 322 new_flags |= rootAlign;
422 w = h = noScale; 323 w = h = noScale;
423 geom_flags |= WidthValue|HeightValue; 324 geom_flags |= WidthValue|HeightValue;
424 } 325 }
425# undef CHECK_GEOM_OPS
426
427 while (*ops != ':' && *ops != '\0') ++ops;
428 } /* done parsing ops */ 326 } /* done parsing ops */
429 }
430 327
328 rxvt_free_strsplit (arr);
329 }
330
431 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; 331 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
432 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed; 332 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
433 if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed; 333 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
434 if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed; 334 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
435 }
436 335
437 if (new_flags != flags) 336 if (new_flags != flags)
438 { 337 {
439 flags = new_flags; 338 flags = new_flags;
440 changed++; 339 changed = true;
441 } 340 }
442 341
443 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
444 // flags, h_scale, v_scale, h_align, v_align);
445 return (changed > 0); 342 return changed;
446} 343}
447 344
448void 345void
449bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 346bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
450{ 347{
467 if (!w) w = image_width; 364 if (!w) w = image_width;
468 if (!h) h = image_height; 365 if (!h) h = image_height;
469 366
470 if (flags & rootAlign) 367 if (flags & rootAlign)
471 { 368 {
472 target->get_window_origin (x, y);
473 x = -x; 369 x = -target_x;
474 y = -y; 370 y = -target_y;
475 } 371 }
476 else 372 else
477 { 373 {
478 x = make_align_position (h_align, target_width, w); 374 x = make_align_position (h_align, target_width, w);
479 y = make_align_position (v_align, target_height, h); 375 y = make_align_position (v_align, target_height, h);
480 } 376 }
481 377
482 flags &= ~sizeSensitive; 378 flags &= ~sizeSensitive;
483 if (h_scale != 0 || v_scale != 0 379 if ((flags & propScale) || h_scale || v_scale
484 || h_align != 0 || v_align != 0 380 || (!(flags & rootAlign) && (h_align || v_align))
485 || w > target_width || h > target_height) 381 || w > target_width || h > target_height)
486 flags |= sizeSensitive; 382 flags |= sizeSensitive;
487} 383}
488 384
489# ifdef HAVE_AFTERIMAGE 385# ifdef HAVE_AFTERIMAGE
539 435
540 int x = 0; 436 int x = 0;
541 int y = 0; 437 int y = 0;
542 int w = 0; 438 int w = 0;
543 int h = 0; 439 int h = 0;
544
545 TIMING_TEST_START (asim);
546 440
547 if (original_asim) 441 if (original_asim)
548 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); 442 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
549 443
550 if (!original_asim 444 if (!original_asim
667 } 561 }
668 562
669 free (layers); 563 free (layers);
670 } 564 }
671 } 565 }
672 TIMING_TEST_PRINT_RESULT (asim);
673 566
674 bool ret = false; 567 bool ret = false;
675 568
676 if (result) 569 if (result)
677 { 570 {
678 XGCValues gcv; 571 XGCValues gcv;
679 GC gc; 572 GC gc;
680 573
681 if (pixmap)
682 {
683 if (pmap_width != new_pmap_width
684 || pmap_height != new_pmap_height
685 || pmap_depth != target->depth)
686 {
687 XFreePixmap (target->dpy, pixmap);
688 pixmap = None;
689 }
690 }
691
692 /* create Pixmap */ 574 /* create Pixmap */
693 if (pixmap == None) 575 if (pixmap == None
576 || pmap_width != new_pmap_width
577 || pmap_height != new_pmap_height)
694 { 578 {
579 if (pixmap)
580 XFreePixmap (target->dpy, pixmap);
695 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 581 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
696 pmap_width = new_pmap_width; 582 pmap_width = new_pmap_width;
697 pmap_height = new_pmap_height; 583 pmap_height = new_pmap_height;
698 pmap_depth = target->depth;
699 } 584 }
700 /* fill with background color (if result's not completely overlapping it) */ 585 /* fill with background color (if result's not completely overlapping it) */
701 gcv.foreground = target->pix_colors[Color_bg]; 586 gcv.foreground = target->pix_colors[Color_bg];
702 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 587 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
703 588
723 608
724 if (result != background && result != original_asim) 609 if (result != background && result != original_asim)
725 destroy_asimage (&result); 610 destroy_asimage (&result);
726 611
727 XFreeGC (target->dpy, gc); 612 XFreeGC (target->dpy, gc);
728 TIMING_TEST_PRINT_RESULT (asim);
729 613
730 ret = true; 614 ret = true;
731 } 615 }
732 616
733 if (background) 617 if (background)
737} 621}
738# endif /* HAVE_AFTERIMAGE */ 622# endif /* HAVE_AFTERIMAGE */
739 623
740# ifdef HAVE_PIXBUF 624# ifdef HAVE_PIXBUF
741bool 625bool
626bgPixmap_t::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc,
627 int src_x, int src_y, int dst_x, int dst_y,
628 unsigned int width, unsigned int height)
629{
630 XImage *ximage;
631 char *data, *line;
632 int bytes_per_pixel;
633 int width_r, width_g, width_b;
634 int sh_r, sh_g, sh_b;
635 int rowstride;
636 int channels;
637 unsigned char *row;
638 Visual *visual = target->visual;
639 int depth = target->depth;
640
641 if (visual->c_class != TrueColor)
642 return false;
643
644 if (depth == 24 || depth == 32)
645 bytes_per_pixel = 4;
646 else if (depth == 15 || depth == 16)
647 bytes_per_pixel = 2;
648 else
649 return false;
650
651 width_r = rxvt_popcount (visual->red_mask);
652 width_g = rxvt_popcount (visual->green_mask);
653 width_b = rxvt_popcount (visual->blue_mask);
654
655 if (width_r > 8 || width_g > 8 || width_b > 8)
656 return false;
657
658 sh_r = rxvt_ctz (visual->red_mask);
659 sh_g = rxvt_ctz (visual->green_mask);
660 sh_b = rxvt_ctz (visual->blue_mask);
661
662 if (width > INT_MAX / height / bytes_per_pixel)
663 return false;
664
665 data = (char *)malloc (width * height * bytes_per_pixel);
666 if (!data)
667 return false;
668
669 ximage = XCreateImage (target->dpy, visual, depth, ZPixmap, 0, data,
670 width, height, bytes_per_pixel * 8, 0);
671 if (!ximage)
672 {
673 free (data);
674 return false;
675 }
676
677 ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst;
678
679 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
680 channels = gdk_pixbuf_get_n_channels (pixbuf);
681 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
682 line = data;
683
684 for (int y = 0; y < height; y++)
685 {
686 for (int x = 0; x < width; x++)
687 {
688 unsigned char *pixel = row + x * channels;
689 uint32_t value;
690
691 value = ((pixel[0] >> (8 - width_r)) << sh_r)
692 | ((pixel[1] >> (8 - width_g)) << sh_g)
693 | ((pixel[2] >> (8 - width_b)) << sh_b);
694
695 if (bytes_per_pixel == 4)
696 ((uint32_t *)line)[x] = value;
697 else
698 ((uint16_t *)line)[x] = value;
699 }
700
701 row += rowstride;
702 line += ximage->bytes_per_line;
703 }
704
705 XPutImage (target->dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height);
706 XDestroyImage (ximage);
707 return true;
708}
709
710bool
742bgPixmap_t::render_image (unsigned long background_flags) 711bgPixmap_t::render_image (unsigned long background_flags)
743{ 712{
744 if (target == NULL) 713 if (target == NULL)
745 return false; 714 return false;
746 715
747 if (!pixbuf) 716 if (!pixbuf)
748 return false; 717 return false;
749 718
750#if !XFT
751 if (background_flags) 719 if (background_flags
720 && !(flags & HAS_RENDER))
752 return false; 721 return false;
753#endif
754 722
755 GdkPixbuf *result; 723 GdkPixbuf *result;
756 724
757 int image_width = gdk_pixbuf_get_width (pixbuf); 725 int image_width = gdk_pixbuf_get_width (pixbuf);
758 int image_height = gdk_pixbuf_get_height (pixbuf); 726 int image_height = gdk_pixbuf_get_height (pixbuf);
809 new_pmap_width = min (image_width, target_width); 777 new_pmap_width = min (image_width, target_width);
810 new_pmap_height = min (image_height, target_height); 778 new_pmap_height = min (image_height, target_height);
811 } 779 }
812 } 780 }
813 781
814 if (pixmap)
815 {
816 if (pmap_width != new_pmap_width
817 || pmap_height != new_pmap_height
818 || pmap_depth != target->depth)
819 {
820 XFreePixmap (target->dpy, pixmap);
821 pixmap = None;
822 }
823 }
824
825 if (pixmap == None) 782 if (pixmap == None
783 || pmap_width != new_pmap_width
784 || pmap_height != new_pmap_height)
826 { 785 {
786 if (pixmap)
787 XFreePixmap (target->dpy, pixmap);
827 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 788 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
828 pmap_width = new_pmap_width; 789 pmap_width = new_pmap_width;
829 pmap_height = new_pmap_height; 790 pmap_height = new_pmap_height;
830 pmap_depth = target->depth;
831 } 791 }
832 792
833 gcv.foreground = target->pix_colors[Color_bg]; 793 gcv.foreground = target->pix_colors[Color_bg];
834 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 794 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
835 795
836 if (h_scale == 0 || v_scale == 0) 796 if (h_scale == 0 || v_scale == 0)
837 { 797 {
838 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); 798 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
839 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc, 799 pixbuf_to_pixmap (result, tile, gc,
840 0, 0, 800 0, 0,
841 0, 0, 801 0, 0,
842 image_width, image_height, 802 image_width, image_height);
843 XLIB_RGB_DITHER_NONE,
844 0, 0);
845 803
846 gcv.tile = tile; 804 gcv.tile = tile;
847 gcv.fill_style = FillTiled; 805 gcv.fill_style = FillTiled;
848 gcv.ts_x_origin = x; 806 gcv.ts_x_origin = x;
849 gcv.ts_y_origin = y; 807 gcv.ts_y_origin = y;
864 || dst_x + dst_width < new_pmap_width 822 || dst_x + dst_width < new_pmap_width
865 || dst_y + dst_height < new_pmap_height) 823 || dst_y + dst_height < new_pmap_height)
866 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 824 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
867 825
868 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 826 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
869 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc, 827 pixbuf_to_pixmap (result, pixmap, gc,
870 src_x, src_y, 828 src_x, src_y,
871 dst_x, dst_y, 829 dst_x, dst_y,
872 dst_width, dst_height, 830 dst_width, dst_height);
873 XLIB_RGB_DITHER_NONE,
874 0, 0);
875 } 831 }
876 832
877#if XFT 833#if XRENDER
878 if (background_flags) 834 if (background_flags)
879 { 835 {
880 Display *dpy = target->dpy; 836 Display *dpy = target->dpy;
881 XRenderPictureAttributes pa; 837 XRenderPictureAttributes pa;
882 838
883 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); 839 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual);
884 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 840 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
885 841
886 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 842 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
887 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); 843 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa);
888 844
925# endif /* HAVE_PIXBUF */ 881# endif /* HAVE_PIXBUF */
926 882
927bool 883bool
928bgPixmap_t::set_file (const char *file) 884bgPixmap_t::set_file (const char *file)
929{ 885{
930 assert (file); 886 if (!file || !*file)
887 return false;
931 888
932 if (*file)
933 {
934 if (const char *p = strchr (file, ';')) 889 if (const char *p = strchr (file, ';'))
935 { 890 {
936 size_t len = p - file; 891 size_t len = p - file;
937 char *f = rxvt_temp_buf<char> (len + 1); 892 char *f = rxvt_temp_buf<char> (len + 1);
938 memcpy (f, file, len); 893 memcpy (f, file, len);
939 f[len] = '\0'; 894 f[len] = '\0';
940 file = f; 895 file = f;
941 } 896 }
942 897
943# ifdef HAVE_AFTERIMAGE 898# ifdef HAVE_AFTERIMAGE
944 if (!target->asimman) 899 if (!target->asimman)
945 target->asimman = create_generic_imageman (target->rs[Rs_path]); 900 target->asimman = create_generic_imageman (target->rs[Rs_path]);
946 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 901 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
947 if (image) 902 if (image)
948 { 903 {
949 if (original_asim) 904 if (original_asim)
950 safe_asimage_destroy (original_asim); 905 safe_asimage_destroy (original_asim);
951 original_asim = image; 906 original_asim = image;
907 flags |= CLIENT_RENDER;
952 have_image = true; 908 have_image = true;
953 return true; 909 return true;
954 } 910 }
955# endif 911# endif
956 912
957# ifdef HAVE_PIXBUF 913# ifdef HAVE_PIXBUF
958 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 914 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
959 if (image) 915 if (image)
960 { 916 {
961 if (pixbuf) 917 if (pixbuf)
962 g_object_unref (pixbuf); 918 g_object_unref (pixbuf);
963 pixbuf = image; 919 pixbuf = image;
964 have_image = true; 920 have_image = true;
965 return true; 921 return true;
966 } 922 }
967# endif 923# endif
968 }
969 924
970 return false; 925 return false;
971} 926}
972 927
973# endif /* BG_IMAGE_FROM_FILE */ 928# endif /* BG_IMAGE_FROM_FILE */
986} 941}
987 942
988bool 943bool
989bgPixmap_t::set_blur_radius (const char *geom) 944bgPixmap_t::set_blur_radius (const char *geom)
990{ 945{
991 int changed = 0; 946 bool changed = false;
992 unsigned int hr, vr; 947 unsigned int hr, vr;
993 int junk; 948 int junk;
994 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 949 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
995 950
996 if (!(geom_flags & WidthValue)) 951 if (!(geom_flags & WidthValue))
1001 min_it (hr, 128); 956 min_it (hr, 128);
1002 min_it (vr, 128); 957 min_it (vr, 128);
1003 958
1004 if (h_blurRadius != hr) 959 if (h_blurRadius != hr)
1005 { 960 {
1006 ++changed; 961 changed = true;
1007 h_blurRadius = hr; 962 h_blurRadius = hr;
1008 } 963 }
1009 964
1010 if (v_blurRadius != vr) 965 if (v_blurRadius != vr)
1011 { 966 {
1012 ++changed; 967 changed = true;
1013 v_blurRadius = vr; 968 v_blurRadius = vr;
1014 } 969 }
1015 970
1016 if (v_blurRadius == 0 && h_blurRadius == 0) 971 if (v_blurRadius == 0 && h_blurRadius == 0)
1017 flags &= ~blurNeeded; 972 flags &= ~blurNeeded;
1018 else 973 else
1019 flags |= blurNeeded; 974 flags |= blurNeeded;
1020 975
1021#if XFT
1022 XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root);
1023 if (filters)
1024 {
1025 for (int i = 0; i < filters->nfilter; i++)
1026 if (!strcmp (filters->filter[i], FilterConvolution))
1027 flags |= bgPixmap_t::blurServerSide;
1028
1029 XFree (filters);
1030 }
1031#endif
1032
1033 return (changed > 0); 976 return changed;
1034} 977}
1035 978
1036static inline unsigned long 979static inline unsigned long
1037compute_tint_shade_flags (rxvt_color *tint, int shade) 980compute_tint_shade_flags (rxvt_color *tint, int shade)
1038{ 981{
1041 bool has_shade = shade != 100; 984 bool has_shade = shade != 100;
1042 985
1043 if (tint) 986 if (tint)
1044 { 987 {
1045 tint->get (c); 988 tint->get (c);
1046# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 989 if (!has_shade
1047 if (!has_shade && IS_COMPONENT_WHOLESOME (c.r) 990 && (c.r <= 0x00ff || c.r >= 0xff00)
1048 && IS_COMPONENT_WHOLESOME (c.g) 991 && (c.g <= 0x00ff || c.g >= 0xff00)
1049 && IS_COMPONENT_WHOLESOME (c.b)) 992 && (c.b <= 0x00ff || c.b >= 0xff00))
1050 flags |= bgPixmap_t::tintWholesome; 993 flags |= bgPixmap_t::tintWholesome;
1051# undef IS_COMPONENT_WHOLESOME
1052 } 994 }
1053 995
1054 if (has_shade) 996 if (has_shade || tint)
1055 flags |= bgPixmap_t::tintNeeded; 997 flags |= bgPixmap_t::tintNeeded;
1056 else if (tint)
1057 {
1058 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
1059 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
1060 {
1061 flags |= bgPixmap_t::tintNeeded;
1062 }
1063 }
1064
1065 if (flags & bgPixmap_t::tintNeeded)
1066 {
1067 if (flags & bgPixmap_t::tintWholesome)
1068 flags |= bgPixmap_t::tintServerSide;
1069 else
1070 {
1071#if XFT
1072 flags |= bgPixmap_t::tintServerSide;
1073#endif
1074 }
1075 }
1076 998
1077 return flags; 999 return flags;
1078} 1000}
1079 1001
1080bool 1002bool
1090 1012
1091 return false; 1013 return false;
1092} 1014}
1093 1015
1094bool 1016bool
1095bgPixmap_t::unset_tint ()
1096{
1097 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
1098
1099 if (new_flags != (flags & tintFlags))
1100 {
1101 flags = (flags & ~tintFlags) | new_flags;
1102 return true;
1103 }
1104
1105 return false;
1106}
1107
1108bool
1109bgPixmap_t::set_shade (const char *shade_str) 1017bgPixmap_t::set_shade (const char *shade_str)
1110{ 1018{
1111 int new_shade = (shade_str) ? atoi (shade_str) : 100; 1019 int new_shade = (shade_str) ? atoi (shade_str) : 100;
1112 1020
1113 clamp_it (new_shade, -100, 200); 1021 clamp_it (new_shade, -100, 200);
1116 1024
1117 if (new_shade != shade) 1025 if (new_shade != shade)
1118 { 1026 {
1119 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 1027 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
1120 shade = new_shade; 1028 shade = new_shade;
1121 flags = (flags & (~tintFlags | tintSet)) | new_flags; 1029 flags = (flags & ~tintFlags) | new_flags;
1122 return true; 1030 return true;
1123 } 1031 }
1124 1032
1125 return false; 1033 return false;
1126} 1034}
1127 1035
1036#if XRENDER
1128static void 1037static void
1129get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) 1038get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
1130{ 1039{
1131 double sigma = radius / 2.0; 1040 double sigma = radius / 2.0;
1132 double scale = sqrt (2.0 * M_PI) * sigma; 1041 double scale = sqrt (2.0 * M_PI) * sigma;
1133 double sum = 0.0; 1042 double sum = 0.0;
1134 1043
1135 for (int i = 0; i < width; i++) 1044 for (int i = 0; i < width; i++)
1136 { 1045 {
1137 double x = i - width / 2; 1046 double x = i - width / 2;
1138 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; 1047 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale;
1139 sum += kernel[i]; 1048 sum += kernel[i];
1140 } 1049 }
1141 1050
1142 params[0] = XDoubleToFixed (width); 1051 params[0] = XDoubleToFixed (width);
1143 params[1] = XDoubleToFixed (1); 1052 params[1] = XDoubleToFixed (1);
1144 1053
1145 for (int i = 0; i < width; i++) 1054 for (int i = 0; i < width; i++)
1146 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1055 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1147} 1056}
1057#endif
1148 1058
1149bool 1059bool
1150bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1060bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1151{ 1061{
1152 bool ret = false; 1062 bool ret = false;
1153#if XFT 1063#if XRENDER
1154 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1064 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1155 double *kernel = (double *)malloc (size * sizeof (double)); 1065 double *kernel = (double *)malloc (size * sizeof (double));
1156 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1066 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1157 1067
1158 Display *dpy = target->dpy; 1068 Display *dpy = target->dpy;
1159 XRenderPictureAttributes pa; 1069 XRenderPictureAttributes pa;
1160 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, target->visual); 1070 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1161 1071
1162 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1072 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1163 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1073 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1164 1074
1165 if (kernel && params && src && dst) 1075 if (kernel && params && src && dst)
1235 XFreeGC (dpy, gc); 1145 XFreeGC (dpy, gc);
1236 } 1146 }
1237 } 1147 }
1238 else 1148 else
1239 { 1149 {
1240# if XFT 1150# if XRENDER
1241 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1151 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1242 1152
1243 if (flags & tintSet) 1153 if (flags & tintSet)
1244 tint.get (c); 1154 tint.get (c);
1245 1155
1249 c.g = (c.g * shade) / 100; 1159 c.g = (c.g * shade) / 100;
1250 c.b = (c.b * shade) / 100; 1160 c.b = (c.b * shade) / 100;
1251 } 1161 }
1252 else 1162 else
1253 { 1163 {
1254 c.r = ((0xffff - c.r) * (200 - shade)) / 100; 1164 c.r = (c.r * (200 - shade)) / 100;
1255 c.g = ((0xffff - c.g) * (200 - shade)) / 100; 1165 c.g = (c.g * (200 - shade)) / 100;
1256 c.b = ((0xffff - c.b) * (200 - shade)) / 100; 1166 c.b = (c.b * (200 - shade)) / 100;
1257 } 1167 }
1258 1168
1259 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); 1169 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1260 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1170 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1261 XRenderPictureAttributes pa; 1171 XRenderPictureAttributes pa;
1275 1185
1276 if (mask_pic && overlay_pic && back_pic) 1186 if (mask_pic && overlay_pic && back_pic)
1277 { 1187 {
1278 XRenderColor mask_c; 1188 XRenderColor mask_c;
1279 1189
1280 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); 1190 mask_c.red = mask_c.green = mask_c.blue = 0;
1281 mask_c.alpha = 0xffff; 1191 mask_c.alpha = 0xffff;
1282 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1192 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1283 1193
1284 mask_c.alpha = 0; 1194 mask_c.alpha = 0;
1285 mask_c.red = 0xffff - c.r; 1195 mask_c.red = 0xffff - c.r;
1286 mask_c.green = 0xffff - c.g; 1196 mask_c.green = 0xffff - c.g;
1287 mask_c.blue = 0xffff - c.b; 1197 mask_c.blue = 0xffff - c.b;
1288 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1198 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1289 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1199 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1200
1201 if (shade > 100)
1202 {
1203 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1204 mask_c.alpha = 0;
1205 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1206
1207 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1208 }
1209
1290 ret = true; 1210 ret = true;
1291 } 1211 }
1292 1212
1293 XRenderFreePicture (dpy, mask_pic); 1213 XRenderFreePicture (dpy, mask_pic);
1294 XRenderFreePicture (dpy, overlay_pic); 1214 XRenderFreePicture (dpy, overlay_pic);
1295 XRenderFreePicture (dpy, back_pic); 1215 XRenderFreePicture (dpy, back_pic);
1296# if DO_TIMING_TEST
1297 XSync (dpy, False);
1298# endif
1299# endif 1216# endif
1300 } 1217 }
1301 1218
1302 return ret; 1219 return ret;
1303} 1220}
1304 1221
1305/* make_transparency_pixmap() 1222/* make_transparency_pixmap()
1306 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1223 * Builds a pixmap of the same size as the terminal window that contains
1307 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 1224 * the tiled portion of the root pixmap that is supposed to be covered by
1308 * our window. 1225 * our window.
1309 */ 1226 */
1310unsigned long 1227unsigned long
1311bgPixmap_t::make_transparency_pixmap () 1228bgPixmap_t::make_transparency_pixmap ()
1312{ 1229{
1316 return 0; 1233 return 0;
1317 1234
1318 /* root dimensions may change from call to call - but Display structure should 1235 /* root dimensions may change from call to call - but Display structure should
1319 * be always up-to-date, so let's use it : 1236 * be always up-to-date, so let's use it :
1320 */ 1237 */
1321 Window root = target->display->root;
1322 int screen = target->display->screen; 1238 int screen = target->display->screen;
1323 Display *dpy = target->dpy; 1239 Display *dpy = target->dpy;
1240 int root_depth = DefaultDepth (dpy, screen);
1324 int root_width = DisplayWidth (dpy, screen); 1241 int root_width = DisplayWidth (dpy, screen);
1325 int root_height = DisplayHeight (dpy, screen); 1242 int root_height = DisplayHeight (dpy, screen);
1326 unsigned int root_pmap_width, root_pmap_height; 1243 unsigned int root_pmap_width, root_pmap_height;
1327 int window_width = target->szHint.width; 1244 int window_width = target->szHint.width;
1328 int window_height = target->szHint.height; 1245 int window_height = target->szHint.height;
1329 int sx, sy; 1246 int sx, sy;
1330 XGCValues gcv; 1247 XGCValues gcv;
1331 GC gc; 1248 GC gc;
1332 1249
1333 TIMING_TEST_START (tp); 1250 sx = target_x;
1334 target->get_window_origin (sx, sy); 1251 sy = target_y;
1335 1252
1336 /* check if we are outside of the visible part of the virtual screen : */ 1253 /* check if we are outside of the visible part of the virtual screen : */
1337 if (sx + window_width <= 0 || sy + window_height <= 0 1254 if (sx + window_width <= 0 || sy + window_height <= 0
1338 || sx >= root_width || sy >= root_height) 1255 || sx >= root_width || sy >= root_height)
1339 return 0; 1256 return 0;
1340 1257
1258 // validate root pixmap and get its size
1341 if (root_pixmap != None) 1259 if (root_pixmap != None)
1342 { 1260 {
1343 /* we want to validate the pixmap and get its size at the same time : */ 1261 Window wdummy;
1344 int junk; 1262 int idummy;
1345 unsigned int ujunk; 1263 unsigned int udummy;
1346 /* root pixmap may be bad - allow a error */ 1264
1347 target->allowedxerror = -1; 1265 target->allowedxerror = -1;
1348 1266
1349 if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk)) 1267 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy))
1350 root_pixmap = None; 1268 root_pixmap = None;
1351 1269
1352 target->allowedxerror = 0; 1270 target->allowedxerror = 0;
1271 }
1272
1273 Pixmap recoded_root_pmap = root_pixmap;
1274
1275 if (root_pixmap != None && root_depth != target->depth)
1276 {
1277#if XRENDER
1278 if (flags & HAS_RENDER)
1279 {
1280 XRenderPictureAttributes pa;
1281
1282 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1283 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1284
1285 recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth);
1286 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
1287 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1288
1289 if (src && dst)
1290 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1291 else
1292 {
1293 XFreePixmap (dpy, recoded_root_pmap);
1294 root_pixmap = None;
1295 }
1296
1297 XRenderFreePicture (dpy, src);
1298 XRenderFreePicture (dpy, dst);
1299 }
1300 else
1301#endif
1302 root_pixmap = None;
1353 } 1303 }
1354 1304
1355 if (root_pixmap == None) 1305 if (root_pixmap == None)
1356 return 0; 1306 return 0;
1357 1307
1358 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 1308 if (pixmap == None
1309 || pmap_width != window_width
1310 || pmap_height != window_height)
1311 {
1312 if (pixmap)
1313 XFreePixmap (target->dpy, pixmap);
1314 pixmap = XCreatePixmap (target->dpy, target->vt, window_width, window_height, target->depth);
1315 pmap_width = window_width;
1316 pmap_height = window_height;
1317 }
1359 1318
1360 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1319 if (pixmap == None)
1361 return 0; 1320 return 0;
1362 1321
1363 /* straightforward pixmap copy */ 1322 /* straightforward pixmap copy */
1364 gcv.tile = root_pixmap;
1365 gcv.fill_style = FillTiled;
1366
1367 while (sx < 0) sx += (int)root_width; 1323 while (sx < 0) sx += (int)root_width;
1368 while (sy < 0) sy += (int)root_height; 1324 while (sy < 0) sy += (int)root_height;
1369 1325
1326 gcv.tile = recoded_root_pmap;
1327 gcv.fill_style = FillTiled;
1370 gcv.ts_x_origin = -sx; 1328 gcv.ts_x_origin = -sx;
1371 gcv.ts_y_origin = -sy; 1329 gcv.ts_y_origin = -sy;
1372 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1330 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1373 1331
1374 if (gc) 1332 if (gc)
1375 { 1333 {
1376 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1334 XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height);
1377 result |= transpPmapTiled; 1335 result |= transpPmapTiled;
1378 XFreeGC (dpy, gc); 1336 XFreeGC (dpy, gc);
1379 }
1380 TIMING_TEST_PRINT_RESULT (tp);
1381 1337
1382 if (tiled_root_pmap != None) 1338 if (!(flags & CLIENT_RENDER))
1383 {
1384 if (!need_client_side_rendering ())
1385 { 1339 {
1386 if ((flags & blurNeeded)) 1340 if ((flags & blurNeeded)
1341 && (flags & HAS_RENDER_CONV))
1387 { 1342 {
1388 if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) 1343 if (blur_pixmap (pixmap, target->visual, window_width, window_height))
1389 result |= transpPmapBlurred; 1344 result |= transpPmapBlurred;
1390 } 1345 }
1391 if ((flags & tintNeeded)) 1346 if ((flags & tintNeeded)
1347 && (flags & (tintWholesome | HAS_RENDER)))
1392 { 1348 {
1393 if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) 1349 if (tint_pixmap (pixmap, target->visual, window_width, window_height))
1394 result |= transpPmapTinted; 1350 result |= transpPmapTinted;
1395 } 1351 }
1396 } /* server side rendering completed */ 1352 } /* server side rendering completed */
1397
1398 if (pixmap)
1399 XFreePixmap (dpy, pixmap);
1400
1401 pixmap = tiled_root_pmap;
1402 pmap_width = window_width;
1403 pmap_height = window_height;
1404 pmap_depth = root_depth;
1405 } 1353 }
1406 1354
1407 TIMING_TEST_PRINT_RESULT (tp); 1355 if (recoded_root_pmap != root_pixmap)
1356 XFreePixmap (dpy, recoded_root_pmap);
1408 1357
1409 return result; 1358 return result;
1410} 1359}
1411 1360
1412bool 1361void
1413bgPixmap_t::set_root_pixmap () 1362bgPixmap_t::set_root_pixmap ()
1414{ 1363{
1415 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1364 Pixmap new_root_pixmap = target->get_pixmap_property (target->xa[XA_XROOTPMAP_ID]);
1416 if (new_root_pixmap == None) 1365 if (new_root_pixmap == None)
1417 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1366 new_root_pixmap = target->get_pixmap_property (target->xa[XA_ESETROOT_PMAP_ID]);
1418 1367
1419 if (new_root_pixmap != root_pixmap)
1420 {
1421 root_pixmap = new_root_pixmap; 1368 root_pixmap = new_root_pixmap;
1422 return true;
1423 }
1424
1425 return false;
1426} 1369}
1427# endif /* ENABLE_TRANSPARENCY */ 1370# endif /* ENABLE_TRANSPARENCY */
1428 1371
1429# ifndef HAVE_AFTERIMAGE 1372#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1430static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); 1373static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1431# endif 1374# endif
1432 1375
1433bool 1376bool
1434bgPixmap_t::render () 1377bgPixmap_t::render ()
1435{ 1378{
1436 unsigned long background_flags = 0; 1379 unsigned long background_flags = 0;
1437 1380
1438 if (target == NULL) 1381 if (target == NULL)
1439 return false; 1382 return false;
1440
1441 TIMING_TEST_START (tp);
1442 1383
1443 invalidate (); 1384 invalidate ();
1444# ifdef ENABLE_TRANSPARENCY 1385# ifdef ENABLE_TRANSPARENCY
1445 if (flags & isTransparent) 1386 if (flags & isTransparent)
1446 { 1387 {
1447 /* we need to re-generate transparency pixmap in that case ! */ 1388 /* we need to re-generate transparency pixmap in that case ! */
1448 background_flags = make_transparency_pixmap (); 1389 background_flags = make_transparency_pixmap ();
1449 if (background_flags == 0) 1390 if (background_flags == 0)
1450 return false; 1391 return false;
1451 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1392 else if ((background_flags & transpTransformations) == (flags & transpTransformations))
1452 && pmap_depth == target->depth)
1453 flags = flags & ~isInvalid; 1393 flags &= ~isInvalid;
1454 } 1394 }
1455# endif 1395# endif
1456 1396
1457# ifdef BG_IMAGE_FROM_FILE 1397# ifdef BG_IMAGE_FROM_FILE
1458 if (have_image 1398 if (have_image
1459 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1399 || (background_flags & transpTransformations) != (flags & transpTransformations))
1460 { 1400 {
1461 if (render_image (background_flags)) 1401 if (render_image (background_flags))
1462 flags = flags & ~isInvalid; 1402 flags &= ~isInvalid;
1463 } 1403 }
1464# endif 1404# endif
1465 1405
1406# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1466 XImage *result = NULL; 1407 XImage *result = NULL;
1467 1408
1468 if (background_flags && (flags & isInvalid)) 1409 if (background_flags && (flags & isInvalid))
1469 { 1410 {
1470 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1411 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1471 } 1412 }
1472 1413
1473 if (result) 1414 if (result)
1474 { 1415 {
1475# if !defined(HAVE_AFTERIMAGE) && !XFT
1476 /* our own client-side tinting */ 1416 /* our own client-side tinting */
1477 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1478 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1479 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1417 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1480 { 1418 {
1481 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1419 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1482 if (flags & tintSet) 1420 if (flags & tintSet)
1483 tint.get (c); 1421 tint.get (c);
1484 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1422 shade_ximage (DefaultVisual (target->dpy, target->display->screen), result, shade, c);
1485 } 1423 }
1486# endif
1487 1424
1488 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1425 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1489 1426
1490 if (gc) 1427 if (gc)
1491 { 1428 {
1492 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1493 {
1494 XFreePixmap (target->dpy, pixmap);
1495 pixmap = None;
1496 }
1497
1498 if (pixmap == None)
1499 {
1500 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1501 pmap_width = result->width;
1502 pmap_height = result->height;
1503 pmap_depth = target->depth;
1504 }
1505
1506 if (pmap_depth != result->depth)
1507 {
1508 /* Bad Match error will ensue ! stupid X !!!! */
1509 if (result->depth == 24 && pmap_depth == 32)
1510 result->depth = 32;
1511 else if (result->depth == 32 && pmap_depth == 24)
1512 result->depth = 24;
1513 else
1514 {
1515 /* TODO: implement image recoding */
1516 }
1517 }
1518
1519 if (pmap_depth == result->depth)
1520 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1429 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1521 1430
1522 XFreeGC (target->dpy, gc); 1431 XFreeGC (target->dpy, gc);
1523 flags = flags & ~isInvalid; 1432 flags &= ~isInvalid;
1524 } 1433 }
1525 1434
1526 XDestroyImage (result); 1435 XDestroyImage (result);
1527 } 1436 }
1437# endif
1528 1438
1529 if (flags & isInvalid) 1439 if (flags & isInvalid)
1530 { 1440 {
1531 if (pixmap != None) 1441 if (pixmap != None)
1532 { 1442 {
1533 XFreePixmap (target->dpy, pixmap); 1443 XFreePixmap (target->dpy, pixmap);
1534 pixmap = None; 1444 pixmap = None;
1535 } 1445 }
1536 } 1446 }
1537 1447
1538 apply (); 1448 target->scr_recolour (false);
1449 flags |= hasChanged;
1539 1450
1540 XSync (target->dpy, False);
1541 valid_since = ev::now (); 1451 valid_since = ev::now ();
1542 1452
1543 TIMING_TEST_PRINT_RESULT (tp);
1544
1545 return true; 1453 return true;
1546} 1454}
1547 1455
1548bool 1456void
1549bgPixmap_t::set_target (rxvt_term *new_target) 1457bgPixmap_t::set_target (rxvt_term *new_target)
1550{ 1458{
1551 if (new_target)
1552 if (target != new_target)
1553 {
1554 target = new_target; 1459 target = new_target;
1555# ifdef ENABLE_TRANSPARENCY 1460
1556 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1461 flags &= ~(HAS_RENDER | HAS_RENDER_CONV);
1462#if XRENDER
1463 int major, minor;
1464 if (XRenderQueryVersion (target->dpy, &major, &minor))
1465 flags |= HAS_RENDER;
1466 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt);
1467 if (filters)
1468 {
1469 for (int i = 0; i < filters->nfilter; i++)
1470 if (!strcmp (filters->filter[i], FilterConvolution))
1471 flags |= HAS_RENDER_CONV;
1472
1473 XFree (filters);
1474 }
1557# endif 1475#endif
1558 return true;
1559 }
1560
1561 return false;
1562}
1563
1564void
1565bgPixmap_t::apply ()
1566{
1567 if (target)
1568 {
1569 flags &= ~isVtOrigin;
1570
1571 if (pixmap != None)
1572 {
1573 /* set target's background to pixmap */
1574# ifdef ENABLE_TRANSPARENCY
1575 if (flags & isTransparent)
1576 {
1577 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1578 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1579
1580 if (target->scrollBar.win)
1581 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1582 }
1583 else
1584# endif
1585 {
1586 flags |= isVtOrigin;
1587 /* force old pixmap dereference in case it was transparent before :*/
1588 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1589 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1590 /* do we also need to set scrollbar's background here ? */
1591
1592 if (target->scrollBar.win)
1593 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1594 }
1595 }
1596 else
1597 {
1598 /* set target background to a pixel */
1599 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1600 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1601 /* do we also need to set scrollbar's background here ? */
1602 if (target->scrollBar.win)
1603 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1604 }
1605
1606 /* don't want Expose on the parent or vt. It is better to use
1607 scr_touch or we get a great deal of flicker otherwise: */
1608 XClearWindow (target->dpy, target->parent[0]);
1609
1610 if (target->scrollBar.state && target->scrollBar.win)
1611 {
1612 target->scrollBar.state = STATE_IDLE;
1613 target->scrollBar.show (0);
1614 }
1615
1616 target->want_refresh = 1;
1617 flags |= hasChanged;
1618 }
1619} 1476}
1620 1477
1621#endif /* HAVE_BG_PIXMAP */ 1478#endif /* HAVE_BG_PIXMAP */
1622 1479
1623#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT 1480#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1624/* taken from aterm-0.4.2 */ 1481/* taken from aterm-0.4.2 */
1625 1482
1626typedef uint32_t RUINT32T;
1627
1628static void 1483static void
1629ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) 1484shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c)
1630{ 1485{
1631 int sh_r, sh_g, sh_b; 1486 int sh_r, sh_g, sh_b;
1632 RUINT32T mask_r, mask_g, mask_b; 1487 uint32_t mask_r, mask_g, mask_b;
1633 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 1488 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1634 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1489 rgba low;
1635 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1490 rgba high;
1636 int i; 1491 int i;
1492 int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst;
1637 1493
1638 Visual *visual = term->visual;
1639
1640 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; 1494 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1641 1495
1642 /* for convenience */ 1496 /* for convenience */
1643 mask_r = visual->red_mask; 1497 mask_r = visual->red_mask;
1644 mask_g = visual->green_mask; 1498 mask_g = visual->green_mask;
1645 mask_b = visual->blue_mask; 1499 mask_b = visual->blue_mask;
1646 1500
1647 /* boring lookup table pre-initialization */ 1501 /* boring lookup table pre-initialization */
1648 switch (srcImage->bits_per_pixel) { 1502 switch (ximage->depth)
1503 {
1649 case 15: 1504 case 15:
1650 if ((mask_r != 0x7c00) || 1505 if ((mask_r != 0x7c00) ||
1651 (mask_g != 0x03e0) || 1506 (mask_g != 0x03e0) ||
1652 (mask_b != 0x001f)) 1507 (mask_b != 0x001f))
1653 return; 1508 return;
1654 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); 1509 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32));
1655 lookup_r = lookup; 1510 lookup_r = lookup;
1656 lookup_g = lookup+32; 1511 lookup_g = lookup+32;
1657 lookup_b = lookup+32+32; 1512 lookup_b = lookup+32+32;
1658 sh_r = 10; 1513 sh_r = 10;
1659 sh_g = 5; 1514 sh_g = 5;
1660 sh_b = 0; 1515 sh_b = 0;
1661 break; 1516 break;
1662 case 16: 1517 case 16:
1663 if ((mask_r != 0xf800) || 1518 if ((mask_r != 0xf800) ||
1664 (mask_g != 0x07e0) || 1519 (mask_g != 0x07e0) ||
1665 (mask_b != 0x001f)) 1520 (mask_b != 0x001f))
1666 return; 1521 return;
1667 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); 1522 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32));
1668 lookup_r = lookup; 1523 lookup_r = lookup;
1669 lookup_g = lookup+32; 1524 lookup_g = lookup+32;
1670 lookup_b = lookup+32+64; 1525 lookup_b = lookup+32+64;
1671 sh_r = 11; 1526 sh_r = 11;
1672 sh_g = 5; 1527 sh_g = 5;
1673 sh_b = 0; 1528 sh_b = 0;
1674 break; 1529 break;
1675 case 24: 1530 case 24:
1676 if ((mask_r != 0xff0000) || 1531 if ((mask_r != 0xff0000) ||
1677 (mask_g != 0x00ff00) || 1532 (mask_g != 0x00ff00) ||
1678 (mask_b != 0x0000ff)) 1533 (mask_b != 0x0000ff))
1679 return; 1534 return;
1680 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); 1535 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1681 lookup_r = lookup; 1536 lookup_r = lookup;
1682 lookup_g = lookup+256; 1537 lookup_g = lookup+256;
1683 lookup_b = lookup+256+256; 1538 lookup_b = lookup+256+256;
1684 sh_r = 16; 1539 sh_r = 16;
1685 sh_g = 8; 1540 sh_g = 8;
1686 sh_b = 0; 1541 sh_b = 0;
1687 break; 1542 break;
1688 case 32: 1543 case 32:
1689 if ((mask_r != 0xff0000) || 1544 if ((mask_r != 0xff0000) ||
1690 (mask_g != 0x00ff00) || 1545 (mask_g != 0x00ff00) ||
1691 (mask_b != 0x0000ff)) 1546 (mask_b != 0x0000ff))
1692 return; 1547 return;
1693 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); 1548 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1694 lookup_r = lookup; 1549 lookup_r = lookup;
1695 lookup_g = lookup+256; 1550 lookup_g = lookup+256;
1696 lookup_b = lookup+256+256; 1551 lookup_b = lookup+256+256;
1697 sh_r = 16; 1552 sh_r = 16;
1698 sh_g = 8; 1553 sh_g = 8;
1699 sh_b = 0; 1554 sh_b = 0;
1700 break; 1555 break;
1701 default: 1556 default:
1702 return; /* we do not support this color depth */ 1557 return; /* we do not support this color depth */
1703 } 1558 }
1704 1559
1705 /* prepare limits for color transformation (each channel is handled separately) */ 1560 /* prepare limits for color transformation (each channel is handled separately) */
1706 if (shade > 100) { 1561 if (shade > 100)
1562 {
1707 shade = 200 - shade; 1563 shade = 200 - shade;
1708 1564
1709 lower_lim_r = 65535-rm; 1565 high.r = c.r * shade / 100;
1710 lower_lim_g = 65535-gm; 1566 high.g = c.g * shade / 100;
1711 lower_lim_b = 65535-bm; 1567 high.b = c.b * shade / 100;
1712 1568
1713 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); 1569 low.r = 65535 * (100 - shade) / 100;
1714 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); 1570 low.g = 65535 * (100 - shade) / 100;
1715 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); 1571 low.b = 65535 * (100 - shade) / 100;
1716
1717 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1718 } else {
1719
1720 lower_lim_r = lower_lim_g = lower_lim_b = 0;
1721
1722 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
1723 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
1724 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
1725 } 1572 }
1726 1573 else
1727 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
1728 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
1729 { 1574 {
1730 unsigned int tmp; 1575 high.r = c.r * shade / 100;
1576 high.g = c.g * shade / 100;
1577 high.b = c.b * shade / 100;
1731 1578
1732 tmp = lower_lim_r; 1579 low.r = low.g = low.b = 0;
1733 lower_lim_r = lower_lim_b;
1734 lower_lim_b = tmp;
1735
1736 tmp = upper_lim_r;
1737 upper_lim_r = upper_lim_b;
1738 upper_lim_b = tmp;
1739 } 1580 }
1740 1581
1741 /* fill our lookup tables */ 1582 /* fill our lookup tables */
1742 for (i = 0; i <= mask_r>>sh_r; i++) 1583 for (i = 0; i <= mask_r>>sh_r; i++)
1743 { 1584 {
1744 RUINT32T tmp; 1585 uint32_t tmp;
1745 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); 1586 tmp = i * high.r;
1746 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); 1587 tmp += (mask_r>>sh_r) * low.r;
1747 lookup_r[i] = (tmp/65535)<<sh_r; 1588 lookup_r[i] = (tmp/65535)<<sh_r;
1748 } 1589 }
1749 for (i = 0; i <= mask_g>>sh_g; i++) 1590 for (i = 0; i <= mask_g>>sh_g; i++)
1750 { 1591 {
1751 RUINT32T tmp; 1592 uint32_t tmp;
1752 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); 1593 tmp = i * high.g;
1753 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); 1594 tmp += (mask_g>>sh_g) * low.g;
1754 lookup_g[i] = (tmp/65535)<<sh_g; 1595 lookup_g[i] = (tmp/65535)<<sh_g;
1755 } 1596 }
1756 for (i = 0; i <= mask_b>>sh_b; i++) 1597 for (i = 0; i <= mask_b>>sh_b; i++)
1757 { 1598 {
1758 RUINT32T tmp; 1599 uint32_t tmp;
1759 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); 1600 tmp = i * high.b;
1760 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); 1601 tmp += (mask_b>>sh_b) * low.b;
1761 lookup_b[i] = (tmp/65535)<<sh_b; 1602 lookup_b[i] = (tmp/65535)<<sh_b;
1762 } 1603 }
1763 1604
1764 /* apply table to input image (replacing colors by newly calculated ones) */ 1605 /* apply table to input image (replacing colors by newly calculated ones) */
1765 switch (srcImage->bits_per_pixel) 1606 if (ximage->bits_per_pixel == 32
1607 && (ximage->depth == 24 || ximage->depth == 32)
1608 && ximage->byte_order == host_byte_order)
1766 { 1609 {
1767 case 15:
1768 {
1769 unsigned short *p1, *pf, *p, *pl; 1610 uint32_t *p1, *pf, *p, *pl;
1770 p1 = (unsigned short *) srcImage->data; 1611 p1 = (uint32_t *) ximage->data;
1771 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); 1612 pf = (uint32_t *) (ximage->data + ximage->height * ximage->bytes_per_line);
1613
1772 while (p1 < pf) 1614 while (p1 < pf)
1773 { 1615 {
1774 p = p1; 1616 p = p1;
1775 pl = p1 + srcImage->width; 1617 pl = p1 + ximage->width;
1776 for (; p < pl; p++) 1618 for (; p < pl; p++)
1777 { 1619 {
1778 *p = lookup_r[(*p & 0x7c00)>>10] |
1779 lookup_g[(*p & 0x03e0)>> 5] |
1780 lookup_b[(*p & 0x001f)];
1781 }
1782 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
1783 }
1784 break;
1785 }
1786 case 16:
1787 {
1788 unsigned short *p1, *pf, *p, *pl;
1789 p1 = (unsigned short *) srcImage->data;
1790 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1791 while (p1 < pf)
1792 {
1793 p = p1;
1794 pl = p1 + srcImage->width;
1795 for (; p < pl; p++)
1796 {
1797 *p = lookup_r[(*p & 0xf800)>>11] |
1798 lookup_g[(*p & 0x07e0)>> 5] |
1799 lookup_b[(*p & 0x001f)];
1800 }
1801 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
1802 }
1803 break;
1804 }
1805 case 24:
1806 {
1807 unsigned char *p1, *pf, *p, *pl;
1808 p1 = (unsigned char *) srcImage->data;
1809 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1810 while (p1 < pf)
1811 {
1812 p = p1;
1813 pl = p1 + srcImage->width * 3;
1814 for (; p < pl; p += 3)
1815 {
1816 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
1817 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
1818 p[2] = lookup_r[(p[2] & 0x0000ff)];
1819 }
1820 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
1821 }
1822 break;
1823 }
1824 case 32:
1825 {
1826 RUINT32T *p1, *pf, *p, *pl;
1827 p1 = (RUINT32T *) srcImage->data;
1828 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1829
1830 while (p1 < pf)
1831 {
1832 p = p1;
1833 pl = p1 + srcImage->width;
1834 for (; p < pl; p++)
1835 {
1836 *p = lookup_r[(*p & 0xff0000)>>16] | 1620 *p = lookup_r[(*p & 0xff0000) >> 16] |
1837 lookup_g[(*p & 0x00ff00)>> 8] | 1621 lookup_g[(*p & 0x00ff00) >> 8] |
1838 lookup_b[(*p & 0x0000ff)] | 1622 lookup_b[(*p & 0x0000ff)] |
1839 (*p & ~0xffffff); 1623 (*p & 0xff000000);
1624 }
1625 p1 = (uint32_t *) ((char *) p1 + ximage->bytes_per_line);
1626 }
1627 }
1628 else
1629 {
1630 for (int y = 0; y < ximage->height; y++)
1631 for (int x = 0; x < ximage->width; x++)
1632 {
1633 unsigned long pixel = XGetPixel (ximage, x, y);
1634 pixel = lookup_r[(pixel & mask_r) >> sh_r] |
1635 lookup_g[(pixel & mask_g) >> sh_g] |
1636 lookup_b[(pixel & mask_b) >> sh_b];
1637 XPutPixel (ximage, x, y, pixel);
1840 } 1638 }
1841 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
1842 } 1639 }
1843 break;
1844 }
1845 }
1846 1640
1847 free (lookup); 1641 free (lookup);
1848} 1642}
1849#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ 1643#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines