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