… | |
… | |
24 | |
24 | |
25 | #include <cmath> |
25 | #include <cmath> |
26 | #include "../config.h" /* NECESSARY */ |
26 | #include "../config.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
28 | |
28 | |
|
|
29 | #if XRENDER |
|
|
30 | # include <X11/extensions/Xrender.h> |
|
|
31 | #endif |
|
|
32 | |
|
|
33 | #ifndef FilterConvolution |
|
|
34 | #define FilterConvolution "convolution" |
|
|
35 | #endif |
|
|
36 | |
29 | #define DO_TIMING_TEST 0 |
37 | #define DO_TIMING_TEST 0 |
30 | |
38 | |
31 | #if DO_TIMING_TEST |
39 | #if DO_TIMING_TEST |
32 | # include <sys/time.h> |
40 | # include <sys/time.h> |
33 | #define TIMING_TEST_START(id) \ |
41 | #define TIMING_TEST_START(id) \ |
… | |
… | |
58 | * |
66 | * |
59 | * 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%. |
60 | * W and H are percentages of the terminal window size. |
68 | * W and H are percentages of the terminal window size. |
61 | * X and Y are also percentages; e.g., +50+50 centers |
69 | * X and Y are also percentages; e.g., +50+50 centers |
62 | * the image in the window. |
70 | * the image in the window. |
63 | * WxH+X Assumes Y == X |
|
|
64 | * WxH Assumes Y == X == 50 (centers the image) |
|
|
65 | * W+X+Y Assumes H == W |
|
|
66 | * W+X Assumes H == W and Y == X |
|
|
67 | * W Assumes H == W and Y == X == 50 |
|
|
68 | * |
|
|
69 | * Adjusting position only : |
|
|
70 | * =+X+Y Set position to X% by Y% (absolute). |
|
|
71 | * =+X Set position to X% by X%. |
|
|
72 | * +X+Y Adjust position horizontally X% and vertically Y% |
|
|
73 | * from current position (relative). |
|
|
74 | * +X Adjust position horizontally X% and vertically X% |
|
|
75 | * from current position. |
|
|
76 | * |
|
|
77 | * Adjusting scale only : |
|
|
78 | * Wx0 Multiply horizontal scaling factor by W% |
|
|
79 | * 0xH Multiply vertical scaling factor by H% |
|
|
80 | * 0x0 No scaling (show image at normal size). |
|
|
81 | * |
71 | * |
82 | * Pixmap Operations : (should be prepended by a colon) |
72 | * Pixmap Operations : (should be prepended by a colon) |
83 | * tile Tile image. Scaling/position modifiers above will affect |
73 | * tile Tile image. Scaling/position modifiers above will affect |
84 | * the tile size and origin. |
74 | * the tile size and origin. |
85 | * propscale When scaling, scale proportionally. That is, maintain the |
75 | * propscale When scaling, scale proportionally. That is, maintain the |
… | |
… | |
113 | #endif |
103 | #endif |
114 | flags = 0; |
104 | flags = 0; |
115 | pixmap = None; |
105 | pixmap = None; |
116 | valid_since = invalid_since = 0; |
106 | valid_since = invalid_since = 0; |
117 | target = 0; |
107 | target = 0; |
|
|
108 | target_x = target_y = 0; |
118 | } |
109 | } |
119 | |
110 | |
120 | void |
111 | void |
121 | bgPixmap_t::destroy () |
112 | bgPixmap_t::destroy () |
122 | { |
113 | { |
… | |
… | |
133 | if (pixmap && target) |
124 | if (pixmap && target) |
134 | XFreePixmap (target->dpy, pixmap); |
125 | XFreePixmap (target->dpy, pixmap); |
135 | } |
126 | } |
136 | |
127 | |
137 | 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 |
138 | bgPixmap_t::window_size_sensitive () |
143 | bgPixmap_t::window_size_sensitive () |
139 | { |
144 | { |
140 | # ifdef ENABLE_TRANSPARENCY |
145 | # ifdef ENABLE_TRANSPARENCY |
141 | if (flags & isTransparent) |
146 | if (flags & isTransparent) |
142 | return true; |
147 | return true; |
… | |
… | |
167 | if (flags & rootAlign) |
172 | if (flags & rootAlign) |
168 | return true; |
173 | return true; |
169 | } |
174 | } |
170 | # endif |
175 | # endif |
171 | |
176 | |
172 | return false; |
|
|
173 | }; |
|
|
174 | |
|
|
175 | bool bgPixmap_t::need_client_side_rendering () |
|
|
176 | { |
|
|
177 | # ifdef HAVE_AFTERIMAGE |
|
|
178 | if (original_asim) |
|
|
179 | return true; |
|
|
180 | # endif |
|
|
181 | return false; |
177 | return false; |
182 | } |
178 | } |
183 | |
179 | |
184 | # ifdef BG_IMAGE_FROM_FILE |
180 | # ifdef BG_IMAGE_FROM_FILE |
185 | static inline bool |
181 | static inline bool |
… | |
… | |
248 | dst_size = target_size - dst_pos; |
244 | dst_size = target_size - dst_pos; |
249 | return src_pos; |
245 | return src_pos; |
250 | } |
246 | } |
251 | |
247 | |
252 | bool |
248 | bool |
253 | bgPixmap_t::set_geometry (const char *geom) |
249 | bgPixmap_t::set_geometry (const char *geom, bool update) |
254 | { |
250 | { |
|
|
251 | bool changed = false; |
255 | int geom_flags = 0, changed = 0; |
252 | int geom_flags = 0; |
256 | int x = 0, y = 0; |
253 | int x = 0, y = 0; |
257 | unsigned int w = 0, h = 0; |
254 | unsigned int w = 0, h = 0; |
258 | unsigned int n; |
255 | unsigned int n; |
259 | unsigned long new_flags = (flags & (~geometryFlags)); |
256 | unsigned long new_flags = (flags & (~geometryFlags)); |
260 | const char *p; |
257 | const char *ops; |
261 | # define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ |
|
|
262 | |
258 | |
263 | if (geom == NULL) |
259 | if (geom == NULL) |
264 | return false; |
260 | return false; |
265 | |
261 | |
266 | char str[MAXLEN_GEOM]; |
262 | char str[256]; |
267 | |
263 | |
268 | while (isspace(*geom)) ++geom; |
|
|
269 | if ((p = strchr (geom, ';')) == NULL) |
|
|
270 | p = strchr (geom, '\0'); |
264 | ops = strchr (geom, ':'); |
271 | |
265 | if (ops == NULL) |
|
|
266 | n = strlen (geom); |
|
|
267 | else |
272 | n = (p - geom); |
268 | n = ops - geom; |
273 | if (n < MAXLEN_GEOM) |
|
|
274 | { |
|
|
275 | char *ops; |
|
|
276 | new_flags |= geometrySet; |
|
|
277 | |
269 | |
|
|
270 | if (n >= sizeof (str)) |
|
|
271 | return false; |
|
|
272 | |
278 | memcpy (str, geom, n); |
273 | memcpy (str, geom, n); |
279 | str[n] = '\0'; |
274 | str[n] = '\0'; |
280 | if (str[0] == ':') |
275 | rxvt_strtrim (str); |
281 | ops = &str[0]; |
|
|
282 | else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) |
|
|
283 | ops = &str[0]; |
|
|
284 | else |
|
|
285 | { |
|
|
286 | char *tmp; |
|
|
287 | ops = strchr (str, ':'); |
|
|
288 | if (ops != NULL) |
|
|
289 | { |
|
|
290 | for (tmp = ops-1; tmp >= str && isspace(*tmp); --tmp); |
|
|
291 | *(++tmp) = '\0'; |
|
|
292 | if (ops == tmp) ++ops; |
|
|
293 | } |
|
|
294 | } |
|
|
295 | |
276 | |
296 | if (ops > str || ops == NULL) |
277 | if (str[0]) |
297 | { |
278 | { |
298 | /* 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 */ |
299 | geom_flags = XParseGeometry (str, &x, &y, &w, &h); |
280 | geom_flags = XParseGeometry (str, &x, &y, &w, &h); |
300 | |
|
|
301 | if ((geom_flags & XValue) && !(geom_flags & YValue)) |
|
|
302 | { |
|
|
303 | y = x; |
|
|
304 | geom_flags |= YValue; |
|
|
305 | } |
|
|
306 | |
|
|
307 | if (flags & geometrySet) |
|
|
308 | { |
|
|
309 | /* new geometry is an adjustment to the old one ! */ |
|
|
310 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
|
|
311 | { |
|
|
312 | if (w == 0 && h != 0) |
|
|
313 | { |
|
|
314 | w = h_scale; |
|
|
315 | h = (v_scale * h) / 100; |
|
|
316 | } |
|
|
317 | else if (h == 0 && w != 0) |
|
|
318 | { |
|
|
319 | w = (h_scale * w) / 100; |
|
|
320 | h = v_scale; |
|
|
321 | } |
|
|
322 | } |
|
|
323 | if (geom_flags & XValue) |
|
|
324 | { |
|
|
325 | if (str[0] != '=') |
|
|
326 | { |
|
|
327 | y += v_align; |
|
|
328 | x += h_align; |
|
|
329 | } |
|
|
330 | } |
|
|
331 | } |
|
|
332 | else /* setting up geometry from scratch */ |
|
|
333 | { |
|
|
334 | if (!(geom_flags & XValue)) |
|
|
335 | { |
|
|
336 | /* use default geometry - centered */ |
|
|
337 | x = y = defaultAlign; |
|
|
338 | } |
|
|
339 | else if (!(geom_flags & YValue)) |
|
|
340 | y = x; |
|
|
341 | |
|
|
342 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
|
|
343 | { |
|
|
344 | /* use default geometry - scaled */ |
|
|
345 | w = h = defaultScale; |
|
|
346 | } |
|
|
347 | else if (geom_flags & WidthValue) |
|
|
348 | { |
|
|
349 | if (!(geom_flags & HeightValue)) |
|
|
350 | h = w; |
|
|
351 | } |
|
|
352 | else |
|
|
353 | w = h; |
|
|
354 | } |
|
|
355 | } /* done parsing geometry string */ |
281 | } /* done parsing geometry string */ |
356 | else if (!(flags & geometrySet)) |
282 | |
357 | { |
283 | if (!update) |
358 | /* default geometry - scaled and centered */ |
284 | { |
|
|
285 | if (!(geom_flags & XValue)) |
359 | x = y = defaultAlign; |
286 | x = y = defaultAlign; |
|
|
287 | else if (!(geom_flags & YValue)) |
|
|
288 | y = x; |
|
|
289 | |
|
|
290 | if (!(geom_flags & (WidthValue|HeightValue))) |
360 | w = h = defaultScale; |
291 | w = h = defaultScale; |
361 | } |
292 | else if (!(geom_flags & HeightValue)) |
|
|
293 | h = w; |
|
|
294 | else if (!(geom_flags & WidthValue)) |
|
|
295 | w = h; |
362 | |
296 | |
363 | if (!(flags & geometrySet)) |
|
|
364 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
297 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
|
|
298 | } |
365 | |
299 | |
366 | if (ops) |
300 | if (ops) |
367 | { |
301 | { |
368 | while (*ops) |
302 | char **arr = rxvt_strsplit (':', ops + 1); |
|
|
303 | |
|
|
304 | for (int i = 0; arr[i]; i++) |
369 | { |
305 | { |
370 | while (*ops == ':' || isspace(*ops)) ++ops; |
306 | if (!strcasecmp (arr[i], "tile")) |
371 | |
|
|
372 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0) |
|
|
373 | if (CHECK_GEOM_OPS ("tile")) |
|
|
374 | { |
307 | { |
375 | w = h = noScale; |
308 | w = h = noScale; |
376 | geom_flags |= WidthValue|HeightValue; |
309 | geom_flags |= WidthValue|HeightValue; |
377 | } |
310 | } |
378 | else if (CHECK_GEOM_OPS ("propscale")) |
311 | else if (!strcasecmp (arr[i], "propscale")) |
379 | { |
312 | { |
380 | new_flags |= propScale; |
313 | new_flags |= propScale; |
381 | } |
314 | } |
382 | else if (CHECK_GEOM_OPS ("hscale")) |
315 | else if (!strcasecmp (arr[i], "hscale")) |
383 | { |
316 | { |
384 | if (w == 0) w = windowScale; |
317 | if (w == 0) w = windowScale; |
385 | |
318 | |
386 | h = noScale; |
319 | h = noScale; |
387 | geom_flags |= WidthValue|HeightValue; |
320 | geom_flags |= WidthValue|HeightValue; |
388 | } |
321 | } |
389 | else if (CHECK_GEOM_OPS ("vscale")) |
322 | else if (!strcasecmp (arr[i], "vscale")) |
390 | { |
323 | { |
391 | if (h == 0) h = windowScale; |
324 | if (h == 0) h = windowScale; |
392 | |
325 | |
393 | w = noScale; |
326 | w = noScale; |
394 | geom_flags |= WidthValue|HeightValue; |
327 | geom_flags |= WidthValue|HeightValue; |
395 | } |
328 | } |
396 | else if (CHECK_GEOM_OPS ("scale")) |
329 | else if (!strcasecmp (arr[i], "scale")) |
397 | { |
330 | { |
398 | if (h == 0) h = windowScale; |
331 | if (h == 0) h = windowScale; |
399 | if (w == 0) w = windowScale; |
332 | if (w == 0) w = windowScale; |
400 | |
333 | |
401 | geom_flags |= WidthValue|HeightValue; |
334 | geom_flags |= WidthValue|HeightValue; |
402 | } |
335 | } |
403 | else if (CHECK_GEOM_OPS ("auto")) |
336 | else if (!strcasecmp (arr[i], "auto")) |
404 | { |
337 | { |
405 | w = h = windowScale; |
338 | w = h = windowScale; |
406 | x = y = centerAlign; |
339 | x = y = centerAlign; |
407 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
340 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
408 | } |
341 | } |
409 | else if (CHECK_GEOM_OPS ("root")) |
342 | else if (!strcasecmp (arr[i], "root")) |
410 | { |
343 | { |
411 | new_flags |= rootAlign; |
344 | new_flags |= rootAlign; |
412 | w = h = noScale; |
345 | w = h = noScale; |
413 | geom_flags |= WidthValue|HeightValue; |
346 | geom_flags |= WidthValue|HeightValue; |
414 | } |
347 | } |
415 | # undef CHECK_GEOM_OPS |
|
|
416 | |
|
|
417 | while (*ops != ':' && *ops != '\0') ++ops; |
|
|
418 | } /* done parsing ops */ |
348 | } /* done parsing ops */ |
419 | } |
|
|
420 | |
349 | |
|
|
350 | rxvt_free_strsplit (arr); |
|
|
351 | } |
|
|
352 | |
421 | 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; |
422 | 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; |
423 | 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; |
424 | 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; |
425 | } |
|
|
426 | |
357 | |
427 | if (new_flags != flags) |
358 | if (new_flags != flags) |
428 | { |
359 | { |
429 | flags = new_flags; |
360 | flags = new_flags; |
430 | changed++; |
361 | changed = true; |
431 | } |
362 | } |
432 | |
363 | |
433 | return (changed > 0); |
364 | return changed; |
434 | } |
365 | } |
435 | |
366 | |
436 | void |
367 | void |
437 | 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) |
438 | { |
369 | { |
… | |
… | |
455 | if (!w) w = image_width; |
386 | if (!w) w = image_width; |
456 | if (!h) h = image_height; |
387 | if (!h) h = image_height; |
457 | |
388 | |
458 | if (flags & rootAlign) |
389 | if (flags & rootAlign) |
459 | { |
390 | { |
460 | target->get_window_origin (x, y); |
|
|
461 | x = -x; |
391 | x = -target_x; |
462 | y = -y; |
392 | y = -target_y; |
463 | } |
393 | } |
464 | else |
394 | else |
465 | { |
395 | { |
466 | x = make_align_position (h_align, target_width, w); |
396 | x = make_align_position (h_align, target_width, w); |
467 | y = make_align_position (v_align, target_height, h); |
397 | y = make_align_position (v_align, target_height, h); |
… | |
… | |
661 | if (result) |
591 | if (result) |
662 | { |
592 | { |
663 | XGCValues gcv; |
593 | XGCValues gcv; |
664 | GC gc; |
594 | GC gc; |
665 | |
595 | |
666 | if (pixmap) |
|
|
667 | { |
|
|
668 | if (pmap_width != new_pmap_width |
|
|
669 | || pmap_height != new_pmap_height |
|
|
670 | || pmap_depth != target->depth) |
|
|
671 | { |
|
|
672 | XFreePixmap (target->dpy, pixmap); |
|
|
673 | pixmap = None; |
|
|
674 | } |
|
|
675 | } |
|
|
676 | |
|
|
677 | /* create Pixmap */ |
596 | /* create Pixmap */ |
678 | if (pixmap == None) |
597 | if (pixmap == None |
|
|
598 | || pmap_width != new_pmap_width |
|
|
599 | || pmap_height != new_pmap_height |
|
|
600 | || pmap_depth != target->depth) |
679 | { |
601 | { |
|
|
602 | if (pixmap) |
|
|
603 | XFreePixmap (target->dpy, pixmap); |
680 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
604 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
681 | pmap_width = new_pmap_width; |
605 | pmap_width = new_pmap_width; |
682 | pmap_height = new_pmap_height; |
606 | pmap_height = new_pmap_height; |
683 | pmap_depth = target->depth; |
607 | pmap_depth = target->depth; |
684 | } |
608 | } |
… | |
… | |
721 | } |
645 | } |
722 | # endif /* HAVE_AFTERIMAGE */ |
646 | # endif /* HAVE_AFTERIMAGE */ |
723 | |
647 | |
724 | # ifdef HAVE_PIXBUF |
648 | # ifdef HAVE_PIXBUF |
725 | bool |
649 | bool |
|
|
650 | bgPixmap_t::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
|
|
651 | int src_x, int src_y, int dst_x, int dst_y, |
|
|
652 | unsigned int width, unsigned int height) |
|
|
653 | { |
|
|
654 | XImage *ximage; |
|
|
655 | char *data, *line; |
|
|
656 | int bytes_per_pixel; |
|
|
657 | int width_r, width_g, width_b; |
|
|
658 | int sh_r, sh_g, sh_b; |
|
|
659 | int rowstride; |
|
|
660 | int channels; |
|
|
661 | unsigned char *row; |
|
|
662 | Visual *visual = target->visual; |
|
|
663 | int depth = target->depth; |
|
|
664 | |
|
|
665 | if (visual->c_class != TrueColor) |
|
|
666 | return false; |
|
|
667 | |
|
|
668 | if (depth == 24 || depth == 32) |
|
|
669 | bytes_per_pixel = 4; |
|
|
670 | else if (depth == 15 || depth == 16) |
|
|
671 | bytes_per_pixel = 2; |
|
|
672 | else |
|
|
673 | return false; |
|
|
674 | |
|
|
675 | width_r = rxvt_popcount (visual->red_mask); |
|
|
676 | width_g = rxvt_popcount (visual->green_mask); |
|
|
677 | width_b = rxvt_popcount (visual->blue_mask); |
|
|
678 | |
|
|
679 | if (width_r > 8 || width_g > 8 || width_b > 8) |
|
|
680 | return false; |
|
|
681 | |
|
|
682 | sh_r = rxvt_ctz (visual->red_mask); |
|
|
683 | sh_g = rxvt_ctz (visual->green_mask); |
|
|
684 | sh_b = rxvt_ctz (visual->blue_mask); |
|
|
685 | |
|
|
686 | if (width > INT_MAX / height / bytes_per_pixel) |
|
|
687 | return false; |
|
|
688 | |
|
|
689 | data = (char *)malloc (width * height * bytes_per_pixel); |
|
|
690 | if (!data) |
|
|
691 | return false; |
|
|
692 | |
|
|
693 | ximage = XCreateImage (target->dpy, visual, depth, ZPixmap, 0, data, |
|
|
694 | width, height, bytes_per_pixel * 8, 0); |
|
|
695 | if (!ximage) |
|
|
696 | { |
|
|
697 | free (data); |
|
|
698 | return false; |
|
|
699 | } |
|
|
700 | |
|
|
701 | ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; |
|
|
702 | |
|
|
703 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
|
|
704 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
|
|
705 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
|
|
706 | line = data; |
|
|
707 | |
|
|
708 | for (int y = 0; y < height; y++) |
|
|
709 | { |
|
|
710 | for (int x = 0; x < width; x++) |
|
|
711 | { |
|
|
712 | unsigned char *pixel = row + x * channels; |
|
|
713 | uint32_t value; |
|
|
714 | |
|
|
715 | value = ((pixel[0] >> (8 - width_r)) << sh_r) |
|
|
716 | | ((pixel[1] >> (8 - width_g)) << sh_g) |
|
|
717 | | ((pixel[2] >> (8 - width_b)) << sh_b); |
|
|
718 | |
|
|
719 | if (bytes_per_pixel == 4) |
|
|
720 | ((uint32_t *)line)[x] = value; |
|
|
721 | else |
|
|
722 | ((uint16_t *)line)[x] = value; |
|
|
723 | } |
|
|
724 | |
|
|
725 | row += rowstride; |
|
|
726 | line += ximage->bytes_per_line; |
|
|
727 | } |
|
|
728 | |
|
|
729 | XPutImage (target->dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height); |
|
|
730 | XDestroyImage (ximage); |
|
|
731 | return true; |
|
|
732 | } |
|
|
733 | |
|
|
734 | bool |
726 | bgPixmap_t::render_image (unsigned long background_flags) |
735 | bgPixmap_t::render_image (unsigned long background_flags) |
727 | { |
736 | { |
728 | if (target == NULL) |
737 | if (target == NULL) |
729 | return false; |
738 | return false; |
730 | |
739 | |
731 | if (!pixbuf) |
740 | if (!pixbuf) |
732 | return false; |
741 | return false; |
733 | |
742 | |
734 | #if !XRENDER |
|
|
735 | if (background_flags) |
743 | if (background_flags |
|
|
744 | && !(flags & HAS_RENDER)) |
736 | return false; |
745 | return false; |
737 | #endif |
|
|
738 | |
746 | |
739 | GdkPixbuf *result; |
747 | GdkPixbuf *result; |
740 | |
748 | |
741 | int image_width = gdk_pixbuf_get_width (pixbuf); |
749 | int image_width = gdk_pixbuf_get_width (pixbuf); |
742 | int image_height = gdk_pixbuf_get_height (pixbuf); |
750 | int image_height = gdk_pixbuf_get_height (pixbuf); |
… | |
… | |
793 | new_pmap_width = min (image_width, target_width); |
801 | new_pmap_width = min (image_width, target_width); |
794 | new_pmap_height = min (image_height, target_height); |
802 | new_pmap_height = min (image_height, target_height); |
795 | } |
803 | } |
796 | } |
804 | } |
797 | |
805 | |
798 | if (pixmap) |
|
|
799 | { |
|
|
800 | if (pmap_width != new_pmap_width |
|
|
801 | || pmap_height != new_pmap_height |
|
|
802 | || pmap_depth != target->depth) |
|
|
803 | { |
|
|
804 | XFreePixmap (target->dpy, pixmap); |
|
|
805 | pixmap = None; |
|
|
806 | } |
|
|
807 | } |
|
|
808 | |
|
|
809 | if (pixmap == None) |
806 | if (pixmap == None |
|
|
807 | || pmap_width != new_pmap_width |
|
|
808 | || pmap_height != new_pmap_height |
|
|
809 | || pmap_depth != target->depth) |
810 | { |
810 | { |
|
|
811 | if (pixmap) |
|
|
812 | XFreePixmap (target->dpy, pixmap); |
811 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
813 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
812 | pmap_width = new_pmap_width; |
814 | pmap_width = new_pmap_width; |
813 | pmap_height = new_pmap_height; |
815 | pmap_height = new_pmap_height; |
814 | pmap_depth = target->depth; |
816 | pmap_depth = target->depth; |
815 | } |
817 | } |
… | |
… | |
818 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
820 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
819 | |
821 | |
820 | if (h_scale == 0 || v_scale == 0) |
822 | if (h_scale == 0 || v_scale == 0) |
821 | { |
823 | { |
822 | Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); |
824 | Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); |
823 | gdk_pixbuf_xlib_render_to_drawable (result, tile, gc, |
825 | pixbuf_to_pixmap (result, tile, gc, |
824 | 0, 0, |
826 | 0, 0, |
825 | 0, 0, |
827 | 0, 0, |
826 | image_width, image_height, |
828 | image_width, image_height); |
827 | XLIB_RGB_DITHER_NONE, |
|
|
828 | 0, 0); |
|
|
829 | |
829 | |
830 | gcv.tile = tile; |
830 | gcv.tile = tile; |
831 | gcv.fill_style = FillTiled; |
831 | gcv.fill_style = FillTiled; |
832 | gcv.ts_x_origin = x; |
832 | gcv.ts_x_origin = x; |
833 | gcv.ts_y_origin = y; |
833 | gcv.ts_y_origin = y; |
… | |
… | |
848 | || dst_x + dst_width < new_pmap_width |
848 | || dst_x + dst_width < new_pmap_width |
849 | || dst_y + dst_height < new_pmap_height) |
849 | || dst_y + dst_height < new_pmap_height) |
850 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
850 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
851 | |
851 | |
852 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
852 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
853 | gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc, |
853 | pixbuf_to_pixmap (result, pixmap, gc, |
854 | src_x, src_y, |
854 | src_x, src_y, |
855 | dst_x, dst_y, |
855 | dst_x, dst_y, |
856 | dst_width, dst_height, |
856 | dst_width, dst_height); |
857 | XLIB_RGB_DITHER_NONE, |
|
|
858 | 0, 0); |
|
|
859 | } |
857 | } |
860 | |
858 | |
861 | #if XRENDER |
859 | #if XRENDER |
862 | if (background_flags) |
860 | if (background_flags) |
863 | { |
861 | { |
… | |
… | |
909 | # endif /* HAVE_PIXBUF */ |
907 | # endif /* HAVE_PIXBUF */ |
910 | |
908 | |
911 | bool |
909 | bool |
912 | bgPixmap_t::set_file (const char *file) |
910 | bgPixmap_t::set_file (const char *file) |
913 | { |
911 | { |
914 | assert (file); |
912 | if (!file || !*file) |
|
|
913 | return false; |
915 | |
914 | |
916 | if (*file) |
|
|
917 | { |
|
|
918 | if (const char *p = strchr (file, ';')) |
915 | if (const char *p = strchr (file, ';')) |
919 | { |
916 | { |
920 | size_t len = p - file; |
917 | size_t len = p - file; |
921 | char *f = rxvt_temp_buf<char> (len + 1); |
918 | char *f = rxvt_temp_buf<char> (len + 1); |
922 | memcpy (f, file, len); |
919 | memcpy (f, file, len); |
923 | f[len] = '\0'; |
920 | f[len] = '\0'; |
924 | file = f; |
921 | file = f; |
925 | } |
922 | } |
926 | |
923 | |
927 | # ifdef HAVE_AFTERIMAGE |
924 | # ifdef HAVE_AFTERIMAGE |
928 | if (!target->asimman) |
925 | if (!target->asimman) |
929 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
926 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
930 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
927 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
931 | if (image) |
928 | if (image) |
932 | { |
929 | { |
933 | if (original_asim) |
930 | if (original_asim) |
934 | safe_asimage_destroy (original_asim); |
931 | safe_asimage_destroy (original_asim); |
935 | original_asim = image; |
932 | original_asim = image; |
|
|
933 | flags |= CLIENT_RENDER; |
936 | have_image = true; |
934 | have_image = true; |
937 | return true; |
935 | return true; |
938 | } |
936 | } |
939 | # endif |
937 | # endif |
940 | |
938 | |
941 | # ifdef HAVE_PIXBUF |
939 | # ifdef HAVE_PIXBUF |
942 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
940 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
943 | if (image) |
941 | if (image) |
944 | { |
942 | { |
945 | if (pixbuf) |
943 | if (pixbuf) |
946 | g_object_unref (pixbuf); |
944 | g_object_unref (pixbuf); |
947 | pixbuf = image; |
945 | pixbuf = image; |
948 | have_image = true; |
946 | have_image = true; |
949 | return true; |
947 | return true; |
950 | } |
948 | } |
951 | # endif |
949 | # endif |
952 | } |
|
|
953 | |
950 | |
954 | return false; |
951 | return false; |
955 | } |
952 | } |
956 | |
953 | |
957 | # endif /* BG_IMAGE_FROM_FILE */ |
954 | # endif /* BG_IMAGE_FROM_FILE */ |
… | |
… | |
970 | } |
967 | } |
971 | |
968 | |
972 | bool |
969 | bool |
973 | bgPixmap_t::set_blur_radius (const char *geom) |
970 | bgPixmap_t::set_blur_radius (const char *geom) |
974 | { |
971 | { |
975 | int changed = 0; |
972 | bool changed = false; |
976 | unsigned int hr, vr; |
973 | unsigned int hr, vr; |
977 | int junk; |
974 | int junk; |
978 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
975 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
979 | |
976 | |
980 | if (!(geom_flags & WidthValue)) |
977 | if (!(geom_flags & WidthValue)) |
… | |
… | |
985 | min_it (hr, 128); |
982 | min_it (hr, 128); |
986 | min_it (vr, 128); |
983 | min_it (vr, 128); |
987 | |
984 | |
988 | if (h_blurRadius != hr) |
985 | if (h_blurRadius != hr) |
989 | { |
986 | { |
990 | ++changed; |
987 | changed = true; |
991 | h_blurRadius = hr; |
988 | h_blurRadius = hr; |
992 | } |
989 | } |
993 | |
990 | |
994 | if (v_blurRadius != vr) |
991 | if (v_blurRadius != vr) |
995 | { |
992 | { |
996 | ++changed; |
993 | changed = true; |
997 | v_blurRadius = vr; |
994 | v_blurRadius = vr; |
998 | } |
995 | } |
999 | |
996 | |
1000 | if (v_blurRadius == 0 && h_blurRadius == 0) |
997 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1001 | flags &= ~blurNeeded; |
998 | flags &= ~blurNeeded; |
1002 | else |
999 | else |
1003 | flags |= blurNeeded; |
1000 | flags |= blurNeeded; |
1004 | |
1001 | |
1005 | #if XRENDER |
|
|
1006 | XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); |
|
|
1007 | if (filters) |
|
|
1008 | { |
|
|
1009 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1010 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1011 | flags |= bgPixmap_t::blurServerSide; |
|
|
1012 | |
|
|
1013 | XFree (filters); |
|
|
1014 | } |
|
|
1015 | #endif |
|
|
1016 | |
|
|
1017 | return (changed > 0); |
1002 | return changed; |
1018 | } |
1003 | } |
1019 | |
1004 | |
1020 | static inline unsigned long |
1005 | static inline unsigned long |
1021 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1006 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1022 | { |
1007 | { |
… | |
… | |
1025 | bool has_shade = shade != 100; |
1010 | bool has_shade = shade != 100; |
1026 | |
1011 | |
1027 | if (tint) |
1012 | if (tint) |
1028 | { |
1013 | { |
1029 | tint->get (c); |
1014 | tint->get (c); |
1030 | # define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) |
1015 | if (!has_shade |
1031 | if (!has_shade && IS_COMPONENT_WHOLESOME (c.r) |
1016 | && (c.r <= 0x00ff || c.r >= 0xff00) |
1032 | && IS_COMPONENT_WHOLESOME (c.g) |
1017 | && (c.g <= 0x00ff || c.g >= 0xff00) |
1033 | && IS_COMPONENT_WHOLESOME (c.b)) |
1018 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
1034 | flags |= bgPixmap_t::tintWholesome; |
1019 | flags |= bgPixmap_t::tintWholesome; |
1035 | # undef IS_COMPONENT_WHOLESOME |
|
|
1036 | } |
1020 | } |
1037 | |
1021 | |
1038 | if (has_shade) |
1022 | if (has_shade || tint) |
1039 | flags |= bgPixmap_t::tintNeeded; |
1023 | flags |= bgPixmap_t::tintNeeded; |
1040 | else if (tint) |
|
|
1041 | { |
|
|
1042 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
|
|
1043 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
|
|
1044 | { |
|
|
1045 | flags |= bgPixmap_t::tintNeeded; |
|
|
1046 | } |
|
|
1047 | } |
|
|
1048 | |
|
|
1049 | if (flags & bgPixmap_t::tintNeeded) |
|
|
1050 | { |
|
|
1051 | if (flags & bgPixmap_t::tintWholesome) |
|
|
1052 | flags |= bgPixmap_t::tintServerSide; |
|
|
1053 | else |
|
|
1054 | { |
|
|
1055 | #if XRENDER |
|
|
1056 | flags |= bgPixmap_t::tintServerSide; |
|
|
1057 | #endif |
|
|
1058 | } |
|
|
1059 | } |
|
|
1060 | |
1024 | |
1061 | return flags; |
1025 | return flags; |
1062 | } |
1026 | } |
1063 | |
1027 | |
1064 | bool |
1028 | bool |
… | |
… | |
1067 | if (!(flags & tintSet) || tint != new_tint) |
1031 | if (!(flags & tintSet) || tint != new_tint) |
1068 | { |
1032 | { |
1069 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
1033 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
1070 | tint = new_tint; |
1034 | tint = new_tint; |
1071 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
1035 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
1072 | return true; |
|
|
1073 | } |
|
|
1074 | |
|
|
1075 | return false; |
|
|
1076 | } |
|
|
1077 | |
|
|
1078 | bool |
|
|
1079 | bgPixmap_t::unset_tint () |
|
|
1080 | { |
|
|
1081 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
|
|
1082 | |
|
|
1083 | if (new_flags != (flags & tintFlags)) |
|
|
1084 | { |
|
|
1085 | flags = (flags & ~tintFlags) | new_flags; |
|
|
1086 | return true; |
1036 | return true; |
1087 | } |
1037 | } |
1088 | |
1038 | |
1089 | return false; |
1039 | return false; |
1090 | } |
1040 | } |
… | |
… | |
1235 | c.g = (c.g * shade) / 100; |
1185 | c.g = (c.g * shade) / 100; |
1236 | c.b = (c.b * shade) / 100; |
1186 | c.b = (c.b * shade) / 100; |
1237 | } |
1187 | } |
1238 | else |
1188 | else |
1239 | { |
1189 | { |
1240 | c.r = ((0xffff - c.r) * (200 - shade)) / 100; |
1190 | c.r = (c.r * (200 - shade)) / 100; |
1241 | c.g = ((0xffff - c.g) * (200 - shade)) / 100; |
1191 | c.g = (c.g * (200 - shade)) / 100; |
1242 | c.b = ((0xffff - c.b) * (200 - shade)) / 100; |
1192 | c.b = (c.b * (200 - shade)) / 100; |
1243 | } |
1193 | } |
1244 | |
1194 | |
1245 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1195 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1246 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1196 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1247 | XRenderPictureAttributes pa; |
1197 | XRenderPictureAttributes pa; |
… | |
… | |
1261 | |
1211 | |
1262 | if (mask_pic && overlay_pic && back_pic) |
1212 | if (mask_pic && overlay_pic && back_pic) |
1263 | { |
1213 | { |
1264 | XRenderColor mask_c; |
1214 | XRenderColor mask_c; |
1265 | |
1215 | |
1266 | memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); |
1216 | mask_c.red = mask_c.green = mask_c.blue = 0; |
1267 | mask_c.alpha = 0xffff; |
1217 | mask_c.alpha = 0xffff; |
1268 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1218 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1269 | |
1219 | |
1270 | mask_c.alpha = 0; |
1220 | mask_c.alpha = 0; |
1271 | mask_c.red = 0xffff - c.r; |
1221 | mask_c.red = 0xffff - c.r; |
1272 | mask_c.green = 0xffff - c.g; |
1222 | mask_c.green = 0xffff - c.g; |
1273 | mask_c.blue = 0xffff - c.b; |
1223 | mask_c.blue = 0xffff - c.b; |
1274 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1224 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1275 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1225 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1226 | |
|
|
1227 | if (shade > 100) |
|
|
1228 | { |
|
|
1229 | mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100; |
|
|
1230 | mask_c.alpha = 0; |
|
|
1231 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1232 | |
|
|
1233 | XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1234 | } |
|
|
1235 | |
1276 | ret = true; |
1236 | ret = true; |
1277 | } |
1237 | } |
1278 | |
1238 | |
1279 | XRenderFreePicture (dpy, mask_pic); |
1239 | XRenderFreePicture (dpy, mask_pic); |
1280 | XRenderFreePicture (dpy, overlay_pic); |
1240 | XRenderFreePicture (dpy, overlay_pic); |
… | |
… | |
1311 | int window_height = target->szHint.height; |
1271 | int window_height = target->szHint.height; |
1312 | int sx, sy; |
1272 | int sx, sy; |
1313 | XGCValues gcv; |
1273 | XGCValues gcv; |
1314 | GC gc; |
1274 | GC gc; |
1315 | |
1275 | |
1316 | target->get_window_origin (sx, sy); |
1276 | sx = target_x; |
|
|
1277 | sy = target_y; |
1317 | |
1278 | |
1318 | /* check if we are outside of the visible part of the virtual screen : */ |
1279 | /* check if we are outside of the visible part of the virtual screen : */ |
1319 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1280 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1320 | || sx >= root_width || sy >= root_height) |
1281 | || sx >= root_width || sy >= root_height) |
1321 | return 0; |
1282 | return 0; |
… | |
… | |
1338 | Pixmap recoded_root_pmap = root_pixmap; |
1299 | Pixmap recoded_root_pmap = root_pixmap; |
1339 | |
1300 | |
1340 | if (root_pixmap != None && root_depth != target->depth) |
1301 | if (root_pixmap != None && root_depth != target->depth) |
1341 | { |
1302 | { |
1342 | #if XRENDER |
1303 | #if XRENDER |
|
|
1304 | if (flags & HAS_RENDER) |
|
|
1305 | { |
1343 | XRenderPictureAttributes pa; |
1306 | XRenderPictureAttributes pa; |
1344 | |
1307 | |
1345 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1308 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1346 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1309 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1347 | |
1310 | |
1348 | recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); |
1311 | recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); |
1349 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
1312 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
1350 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1313 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1351 | |
1314 | |
1352 | if (src && dst) |
1315 | if (src && dst) |
1353 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
1316 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
|
|
1317 | else |
|
|
1318 | { |
|
|
1319 | XFreePixmap (dpy, recoded_root_pmap); |
|
|
1320 | root_pixmap = None; |
|
|
1321 | } |
|
|
1322 | |
|
|
1323 | XRenderFreePicture (dpy, src); |
|
|
1324 | XRenderFreePicture (dpy, dst); |
|
|
1325 | } |
1354 | else |
1326 | else |
1355 | root_pixmap = None; |
1327 | #endif |
1356 | |
|
|
1357 | XRenderFreePicture (dpy, src); |
|
|
1358 | XRenderFreePicture (dpy, dst); |
|
|
1359 | #else |
|
|
1360 | root_pixmap = None; |
1328 | root_pixmap = None; |
1361 | #endif |
|
|
1362 | } |
1329 | } |
1363 | |
1330 | |
1364 | if (root_pixmap == None) |
1331 | if (root_pixmap == None) |
1365 | return 0; |
1332 | return 0; |
1366 | |
1333 | |
… | |
… | |
1368 | |
1335 | |
1369 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1336 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1370 | return 0; |
1337 | return 0; |
1371 | |
1338 | |
1372 | /* straightforward pixmap copy */ |
1339 | /* straightforward pixmap copy */ |
|
|
1340 | while (sx < 0) sx += (int)root_width; |
|
|
1341 | while (sy < 0) sy += (int)root_height; |
|
|
1342 | |
1373 | gcv.tile = recoded_root_pmap; |
1343 | gcv.tile = recoded_root_pmap; |
1374 | gcv.fill_style = FillTiled; |
1344 | gcv.fill_style = FillTiled; |
1375 | |
|
|
1376 | while (sx < 0) sx += (int)root_width; |
|
|
1377 | while (sy < 0) sy += (int)root_height; |
|
|
1378 | |
|
|
1379 | gcv.ts_x_origin = -sx; |
1345 | gcv.ts_x_origin = -sx; |
1380 | gcv.ts_y_origin = -sy; |
1346 | gcv.ts_y_origin = -sy; |
1381 | gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1347 | gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1382 | |
1348 | |
1383 | if (gc) |
1349 | if (gc) |
1384 | { |
1350 | { |
1385 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1351 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1386 | result |= transpPmapTiled; |
1352 | result |= transpPmapTiled; |
1387 | XFreeGC (dpy, gc); |
1353 | XFreeGC (dpy, gc); |
1388 | } |
|
|
1389 | |
1354 | |
1390 | if (tiled_root_pmap != None) |
1355 | if (!(flags & CLIENT_RENDER)) |
1391 | { |
|
|
1392 | if (!need_client_side_rendering ()) |
|
|
1393 | { |
1356 | { |
1394 | if (flags & (blurNeeded | blurServerSide)) |
1357 | if ((flags & blurNeeded) |
|
|
1358 | && (flags & HAS_RENDER_CONV)) |
1395 | { |
1359 | { |
1396 | if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1360 | if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1397 | result |= transpPmapBlurred; |
1361 | result |= transpPmapBlurred; |
1398 | } |
1362 | } |
1399 | if (flags & (tintNeeded | tintServerSide)) |
1363 | if ((flags & tintNeeded) |
|
|
1364 | && (flags & (tintWholesome | HAS_RENDER))) |
1400 | { |
1365 | { |
1401 | if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1366 | if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1402 | result |= transpPmapTinted; |
1367 | result |= transpPmapTinted; |
1403 | } |
1368 | } |
1404 | } /* server side rendering completed */ |
1369 | } /* server side rendering completed */ |
… | |
… | |
1409 | pixmap = tiled_root_pmap; |
1374 | pixmap = tiled_root_pmap; |
1410 | pmap_width = window_width; |
1375 | pmap_width = window_width; |
1411 | pmap_height = window_height; |
1376 | pmap_height = window_height; |
1412 | pmap_depth = target->depth; |
1377 | pmap_depth = target->depth; |
1413 | } |
1378 | } |
|
|
1379 | else |
|
|
1380 | XFreePixmap (dpy, tiled_root_pmap); |
1414 | |
1381 | |
1415 | if (recoded_root_pmap != root_pixmap) |
1382 | if (recoded_root_pmap != root_pixmap) |
1416 | XFreePixmap (dpy, recoded_root_pmap); |
1383 | XFreePixmap (dpy, recoded_root_pmap); |
1417 | |
1384 | |
1418 | return result; |
1385 | return result; |
1419 | } |
1386 | } |
1420 | |
1387 | |
1421 | void |
1388 | void |
1422 | bgPixmap_t::set_root_pixmap () |
1389 | bgPixmap_t::set_root_pixmap () |
1423 | { |
1390 | { |
1424 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1391 | Pixmap new_root_pixmap = target->get_pixmap_property (target->xa[XA_XROOTPMAP_ID]); |
1425 | if (new_root_pixmap == None) |
1392 | if (new_root_pixmap == None) |
1426 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1393 | new_root_pixmap = target->get_pixmap_property (target->xa[XA_ESETROOT_PMAP_ID]); |
1427 | |
1394 | |
1428 | root_pixmap = new_root_pixmap; |
1395 | root_pixmap = new_root_pixmap; |
1429 | } |
1396 | } |
1430 | # endif /* ENABLE_TRANSPARENCY */ |
1397 | # endif /* ENABLE_TRANSPARENCY */ |
1431 | |
1398 | |
1432 | # ifndef HAVE_AFTERIMAGE |
1399 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1433 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); |
1400 | static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c); |
1434 | # endif |
1401 | # endif |
1435 | |
1402 | |
1436 | bool |
1403 | bool |
1437 | bgPixmap_t::render () |
1404 | bgPixmap_t::render () |
1438 | { |
1405 | { |
… | |
… | |
1448 | /* we need to re-generate transparency pixmap in that case ! */ |
1415 | /* we need to re-generate transparency pixmap in that case ! */ |
1449 | background_flags = make_transparency_pixmap (); |
1416 | background_flags = make_transparency_pixmap (); |
1450 | if (background_flags == 0) |
1417 | if (background_flags == 0) |
1451 | return false; |
1418 | return false; |
1452 | else if ((background_flags & transpTransformations) == (flags & transpTransformations)) |
1419 | else if ((background_flags & transpTransformations) == (flags & transpTransformations)) |
1453 | flags = flags & ~isInvalid; |
1420 | flags &= ~isInvalid; |
1454 | } |
1421 | } |
1455 | # endif |
1422 | # endif |
1456 | |
1423 | |
1457 | # ifdef BG_IMAGE_FROM_FILE |
1424 | # ifdef BG_IMAGE_FROM_FILE |
1458 | if (have_image |
1425 | if (have_image |
1459 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1426 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1460 | { |
1427 | { |
1461 | if (render_image (background_flags)) |
1428 | if (render_image (background_flags)) |
1462 | flags = flags & ~isInvalid; |
1429 | flags &= ~isInvalid; |
1463 | } |
1430 | } |
1464 | # endif |
1431 | # endif |
1465 | |
1432 | |
|
|
1433 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1466 | XImage *result = NULL; |
1434 | XImage *result = NULL; |
1467 | |
1435 | |
1468 | if (background_flags && (flags & isInvalid)) |
1436 | if (background_flags && (flags & isInvalid)) |
1469 | { |
1437 | { |
1470 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1438 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1471 | } |
1439 | } |
1472 | |
1440 | |
1473 | if (result) |
1441 | if (result) |
1474 | { |
1442 | { |
1475 | # if !defined(HAVE_AFTERIMAGE) && !XRENDER |
|
|
1476 | /* our own client-side tinting */ |
1443 | /* our own client-side tinting */ |
1477 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1444 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1478 | { |
1445 | { |
1479 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1446 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1480 | if (flags & tintSet) |
1447 | if (flags & tintSet) |
1481 | tint.get (c); |
1448 | tint.get (c); |
1482 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); |
1449 | shade_ximage (DefaultVisual (target->dpy, target->display->screen), result, shade, c); |
1483 | } |
1450 | } |
1484 | # endif |
|
|
1485 | |
1451 | |
1486 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1452 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1487 | |
1453 | |
1488 | if (gc) |
1454 | if (gc) |
1489 | { |
1455 | { |
1490 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1456 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1491 | |
1457 | |
1492 | XFreeGC (target->dpy, gc); |
1458 | XFreeGC (target->dpy, gc); |
1493 | flags = flags & ~isInvalid; |
1459 | flags &= ~isInvalid; |
1494 | } |
1460 | } |
1495 | |
1461 | |
1496 | XDestroyImage (result); |
1462 | XDestroyImage (result); |
1497 | } |
1463 | } |
|
|
1464 | # endif |
1498 | |
1465 | |
1499 | if (flags & isInvalid) |
1466 | if (flags & isInvalid) |
1500 | { |
1467 | { |
1501 | if (pixmap != None) |
1468 | if (pixmap != None) |
1502 | { |
1469 | { |
… | |
… | |
1510 | valid_since = ev::now (); |
1477 | valid_since = ev::now (); |
1511 | |
1478 | |
1512 | return true; |
1479 | return true; |
1513 | } |
1480 | } |
1514 | |
1481 | |
1515 | bool |
1482 | void |
1516 | bgPixmap_t::set_target (rxvt_term *new_target) |
1483 | bgPixmap_t::set_target (rxvt_term *new_target) |
1517 | { |
1484 | { |
1518 | if (new_target) |
|
|
1519 | if (target != new_target) |
|
|
1520 | { |
|
|
1521 | target = new_target; |
1485 | target = new_target; |
1522 | return true; |
1486 | |
|
|
1487 | flags &= ~(HAS_RENDER | HAS_RENDER_CONV); |
|
|
1488 | #if XRENDER |
|
|
1489 | int major, minor; |
|
|
1490 | if (XRenderQueryVersion (target->dpy, &major, &minor)) |
|
|
1491 | flags |= HAS_RENDER; |
|
|
1492 | XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); |
|
|
1493 | if (filters) |
|
|
1494 | { |
|
|
1495 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1496 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1497 | flags |= HAS_RENDER_CONV; |
|
|
1498 | |
|
|
1499 | XFree (filters); |
1523 | } |
1500 | } |
1524 | |
1501 | #endif |
1525 | return false; |
|
|
1526 | } |
1502 | } |
1527 | |
1503 | |
1528 | void |
1504 | void |
1529 | bgPixmap_t::apply () |
1505 | bgPixmap_t::apply () |
1530 | { |
1506 | { |
1531 | if (target) |
1507 | if (target == NULL) |
1532 | { |
1508 | return; |
|
|
1509 | |
1533 | if (pixmap != None) |
1510 | if (pixmap != None) |
1534 | { |
1511 | { |
1535 | /* set target's background to pixmap */ |
1512 | /* set target's background to pixmap */ |
1536 | # ifdef ENABLE_TRANSPARENCY |
1513 | # ifdef ENABLE_TRANSPARENCY |
1537 | if (flags & isTransparent) |
1514 | if (flags & isTransparent) |
1538 | { |
1515 | { |
1539 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1516 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1540 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1517 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1541 | |
1518 | |
1542 | if (target->scrollBar.win) |
1519 | if (target->scrollBar.win) |
1543 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1520 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1544 | } |
1521 | } |
1545 | else |
1522 | else |
1546 | # endif |
1523 | # endif |
1547 | { |
1524 | { |
1548 | /* force old pixmap dereference in case it was transparent before :*/ |
1525 | /* force old pixmap dereference in case it was transparent before :*/ |
1549 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1550 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
1551 | /* do we also need to set scrollbar's background here ? */ |
|
|
1552 | |
|
|
1553 | if (target->scrollBar.win) |
|
|
1554 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1555 | } |
|
|
1556 | } |
|
|
1557 | else |
|
|
1558 | { |
|
|
1559 | /* set target background to a pixel */ |
|
|
1560 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1526 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1561 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1527 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1562 | /* do we also need to set scrollbar's background here ? */ |
1528 | /* do we also need to set scrollbar's background here ? */ |
|
|
1529 | |
1563 | if (target->scrollBar.win) |
1530 | if (target->scrollBar.win) |
1564 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1531 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1565 | } |
1532 | } |
|
|
1533 | } |
|
|
1534 | else |
|
|
1535 | { |
|
|
1536 | /* set target background to a pixel */ |
|
|
1537 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1538 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
1539 | /* do we also need to set scrollbar's background here ? */ |
|
|
1540 | if (target->scrollBar.win) |
|
|
1541 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1542 | } |
1566 | |
1543 | |
1567 | /* don't want Expose on the parent or vt. It is better to use |
1544 | /* don't want Expose on the parent or vt. It is better to use |
1568 | scr_touch or we get a great deal of flicker otherwise: */ |
1545 | scr_touch or we get a great deal of flicker otherwise: */ |
1569 | XClearWindow (target->dpy, target->parent[0]); |
1546 | XClearWindow (target->dpy, target->parent[0]); |
1570 | |
1547 | |
1571 | if (target->scrollBar.state && target->scrollBar.win) |
1548 | if (target->scrollBar.state && target->scrollBar.win) |
1572 | { |
1549 | { |
1573 | target->scrollBar.state = STATE_IDLE; |
1550 | target->scrollBar.state = STATE_IDLE; |
1574 | target->scrollBar.show (0); |
1551 | target->scrollBar.show (0); |
1575 | } |
1552 | } |
1576 | |
1553 | |
1577 | target->want_refresh = 1; |
1554 | target->want_refresh = 1; |
1578 | flags |= hasChanged; |
1555 | flags |= hasChanged; |
1579 | } |
|
|
1580 | } |
1556 | } |
1581 | |
1557 | |
1582 | #endif /* HAVE_BG_PIXMAP */ |
1558 | #endif /* HAVE_BG_PIXMAP */ |
1583 | |
1559 | |
1584 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER |
1560 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1585 | /* taken from aterm-0.4.2 */ |
1561 | /* taken from aterm-0.4.2 */ |
1586 | |
1562 | |
1587 | static void |
1563 | static void |
1588 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1564 | shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) |
1589 | { |
1565 | { |
1590 | int sh_r, sh_g, sh_b; |
1566 | int sh_r, sh_g, sh_b; |
1591 | uint32_t mask_r, mask_g, mask_b; |
1567 | uint32_t mask_r, mask_g, mask_b; |
1592 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1568 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1593 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1569 | rgba low; |
1594 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1570 | rgba high; |
1595 | int i; |
1571 | int i; |
1596 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1572 | int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; |
1597 | |
1573 | |
1598 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1574 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1599 | |
1575 | |
1600 | /* for convenience */ |
1576 | /* for convenience */ |
1601 | mask_r = visual->red_mask; |
1577 | mask_r = visual->red_mask; |
1602 | mask_g = visual->green_mask; |
1578 | mask_g = visual->green_mask; |
1603 | mask_b = visual->blue_mask; |
1579 | mask_b = visual->blue_mask; |
1604 | |
1580 | |
1605 | /* boring lookup table pre-initialization */ |
1581 | /* boring lookup table pre-initialization */ |
1606 | switch (srcImage->depth) |
1582 | switch (ximage->depth) |
1607 | { |
1583 | { |
1608 | case 15: |
1584 | case 15: |
1609 | if ((mask_r != 0x7c00) || |
1585 | if ((mask_r != 0x7c00) || |
1610 | (mask_g != 0x03e0) || |
1586 | (mask_g != 0x03e0) || |
1611 | (mask_b != 0x001f)) |
1587 | (mask_b != 0x001f)) |
… | |
… | |
1664 | /* prepare limits for color transformation (each channel is handled separately) */ |
1640 | /* prepare limits for color transformation (each channel is handled separately) */ |
1665 | if (shade > 100) |
1641 | if (shade > 100) |
1666 | { |
1642 | { |
1667 | shade = 200 - shade; |
1643 | shade = 200 - shade; |
1668 | |
1644 | |
1669 | lower_lim_r = 65535-rm; |
1645 | high.r = c.r * shade / 100; |
1670 | lower_lim_g = 65535-gm; |
1646 | high.g = c.g * shade / 100; |
1671 | lower_lim_b = 65535-bm; |
1647 | high.b = c.b * shade / 100; |
1672 | |
1648 | |
1673 | lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); |
1649 | low.r = 65535 * (100 - shade) / 100; |
1674 | lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); |
1650 | low.g = 65535 * (100 - shade) / 100; |
1675 | lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); |
1651 | low.b = 65535 * (100 - shade) / 100; |
1676 | |
|
|
1677 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
|
|
1678 | } |
1652 | } |
1679 | else |
1653 | else |
1680 | { |
1654 | { |
|
|
1655 | high.r = c.r * shade / 100; |
|
|
1656 | high.g = c.g * shade / 100; |
|
|
1657 | high.b = c.b * shade / 100; |
1681 | |
1658 | |
1682 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1659 | low.r = low.g = low.b = 0; |
1683 | |
|
|
1684 | upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100); |
|
|
1685 | upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100); |
|
|
1686 | upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100); |
|
|
1687 | } |
1660 | } |
1688 | |
1661 | |
1689 | /* fill our lookup tables */ |
1662 | /* fill our lookup tables */ |
1690 | for (i = 0; i <= mask_r>>sh_r; i++) |
1663 | for (i = 0; i <= mask_r>>sh_r; i++) |
1691 | { |
1664 | { |
1692 | uint32_t tmp; |
1665 | uint32_t tmp; |
1693 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); |
1666 | tmp = i * high.r; |
1694 | tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); |
1667 | tmp += (mask_r>>sh_r) * low.r; |
1695 | lookup_r[i] = (tmp/65535)<<sh_r; |
1668 | lookup_r[i] = (tmp/65535)<<sh_r; |
1696 | } |
1669 | } |
1697 | for (i = 0; i <= mask_g>>sh_g; i++) |
1670 | for (i = 0; i <= mask_g>>sh_g; i++) |
1698 | { |
1671 | { |
1699 | uint32_t tmp; |
1672 | uint32_t tmp; |
1700 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); |
1673 | tmp = i * high.g; |
1701 | tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); |
1674 | tmp += (mask_g>>sh_g) * low.g; |
1702 | lookup_g[i] = (tmp/65535)<<sh_g; |
1675 | lookup_g[i] = (tmp/65535)<<sh_g; |
1703 | } |
1676 | } |
1704 | for (i = 0; i <= mask_b>>sh_b; i++) |
1677 | for (i = 0; i <= mask_b>>sh_b; i++) |
1705 | { |
1678 | { |
1706 | uint32_t tmp; |
1679 | uint32_t tmp; |
1707 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); |
1680 | tmp = i * high.b; |
1708 | tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); |
1681 | tmp += (mask_b>>sh_b) * low.b; |
1709 | lookup_b[i] = (tmp/65535)<<sh_b; |
1682 | lookup_b[i] = (tmp/65535)<<sh_b; |
1710 | } |
1683 | } |
1711 | |
1684 | |
1712 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1685 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1713 | if (srcImage->bits_per_pixel == 32 |
1686 | if (ximage->bits_per_pixel == 32 |
1714 | && (srcImage->depth == 24 || srcImage->depth == 32) |
1687 | && (ximage->depth == 24 || ximage->depth == 32) |
1715 | && srcImage->byte_order == host_byte_order) |
1688 | && ximage->byte_order == host_byte_order) |
1716 | { |
1689 | { |
1717 | uint32_t *p1, *pf, *p, *pl; |
1690 | uint32_t *p1, *pf, *p, *pl; |
1718 | p1 = (uint32_t *) srcImage->data; |
1691 | p1 = (uint32_t *) ximage->data; |
1719 | pf = (uint32_t *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1692 | pf = (uint32_t *) (ximage->data + ximage->height * ximage->bytes_per_line); |
1720 | |
1693 | |
1721 | while (p1 < pf) |
1694 | while (p1 < pf) |
1722 | { |
1695 | { |
1723 | p = p1; |
1696 | p = p1; |
1724 | pl = p1 + srcImage->width; |
1697 | pl = p1 + ximage->width; |
1725 | for (; p < pl; p++) |
1698 | for (; p < pl; p++) |
1726 | { |
1699 | { |
1727 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1700 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1728 | lookup_g[(*p & 0x00ff00) >> 8] | |
1701 | lookup_g[(*p & 0x00ff00) >> 8] | |
1729 | lookup_b[(*p & 0x0000ff)] | |
1702 | lookup_b[(*p & 0x0000ff)] | |
1730 | (*p & 0xff000000); |
1703 | (*p & 0xff000000); |
1731 | } |
1704 | } |
1732 | p1 = (uint32_t *) ((char *) p1 + srcImage->bytes_per_line); |
1705 | p1 = (uint32_t *) ((char *) p1 + ximage->bytes_per_line); |
1733 | } |
1706 | } |
1734 | } |
1707 | } |
1735 | else |
1708 | else |
1736 | { |
1709 | { |
1737 | for (int y = 0; y < srcImage->height; y++) |
1710 | for (int y = 0; y < ximage->height; y++) |
1738 | for (int x = 0; x < srcImage->width; x++) |
1711 | for (int x = 0; x < ximage->width; x++) |
1739 | { |
1712 | { |
1740 | unsigned long pixel = XGetPixel (srcImage, x, y); |
1713 | unsigned long pixel = XGetPixel (ximage, x, y); |
1741 | pixel = lookup_r[(pixel & mask_r) >> sh_r] | |
1714 | pixel = lookup_r[(pixel & mask_r) >> sh_r] | |
1742 | lookup_g[(pixel & mask_g) >> sh_g] | |
1715 | lookup_g[(pixel & mask_g) >> sh_g] | |
1743 | lookup_b[(pixel & mask_b) >> sh_b]; |
1716 | lookup_b[(pixel & mask_b) >> sh_b]; |
1744 | XPutPixel (srcImage, x, y, pixel); |
1717 | XPutPixel (ximage, x, y, pixel); |
1745 | } |
1718 | } |
1746 | } |
1719 | } |
1747 | |
1720 | |
1748 | free (lookup); |
1721 | free (lookup); |
1749 | } |
1722 | } |