… | |
… | |
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 |
… | |
… | |
168 | return true; |
158 | return true; |
169 | } |
159 | } |
170 | # endif |
160 | # endif |
171 | |
161 | |
172 | return false; |
162 | return false; |
173 | }; |
163 | } |
174 | |
164 | |
175 | bool bgPixmap_t::need_client_side_rendering () |
165 | bool bgPixmap_t::need_client_side_rendering () |
176 | { |
166 | { |
177 | # ifdef HAVE_AFTERIMAGE |
167 | # ifdef HAVE_AFTERIMAGE |
178 | if (original_asim) |
168 | if (original_asim) |
… | |
… | |
248 | dst_size = target_size - dst_pos; |
238 | dst_size = target_size - dst_pos; |
249 | return src_pos; |
239 | return src_pos; |
250 | } |
240 | } |
251 | |
241 | |
252 | bool |
242 | bool |
253 | bgPixmap_t::set_geometry (const char *geom) |
243 | bgPixmap_t::set_geometry (const char *geom, bool update) |
254 | { |
244 | { |
|
|
245 | bool changed = false; |
255 | int geom_flags = 0, changed = 0; |
246 | int geom_flags = 0; |
256 | int x = 0, y = 0; |
247 | int x = 0, y = 0; |
257 | unsigned int w = 0, h = 0; |
248 | unsigned int w = 0, h = 0; |
258 | unsigned int n; |
249 | unsigned int n; |
259 | unsigned long new_flags = (flags & (~geometryFlags)); |
250 | unsigned long new_flags = (flags & (~geometryFlags)); |
260 | const char *p; |
251 | const char *p; |
… | |
… | |
271 | |
262 | |
272 | n = (p - geom); |
263 | n = (p - geom); |
273 | if (n < MAXLEN_GEOM) |
264 | if (n < MAXLEN_GEOM) |
274 | { |
265 | { |
275 | char *ops; |
266 | char *ops; |
276 | new_flags |= geometrySet; |
|
|
277 | |
267 | |
278 | memcpy (str, geom, n); |
268 | memcpy (str, geom, n); |
279 | str[n] = '\0'; |
269 | str[n] = '\0'; |
280 | if (str[0] == ':') |
270 | if (str[0] == ':') |
281 | ops = &str[0]; |
271 | ops = &str[0]; |
… | |
… | |
296 | if (ops > str || ops == NULL) |
286 | if (ops > str || ops == NULL) |
297 | { |
287 | { |
298 | /* we have geometry string - let's handle it prior to applying ops */ |
288 | /* we have geometry string - let's handle it prior to applying ops */ |
299 | geom_flags = XParseGeometry (str, &x, &y, &w, &h); |
289 | geom_flags = XParseGeometry (str, &x, &y, &w, &h); |
300 | |
290 | |
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 */ |
291 | if (!update) /* setting up geometry from scratch */ |
333 | { |
292 | { |
334 | if (!(geom_flags & XValue)) |
293 | if (!(geom_flags & XValue)) |
335 | { |
294 | { |
336 | /* use default geometry - centered */ |
295 | /* use default geometry - centered */ |
337 | x = y = defaultAlign; |
296 | x = y = defaultAlign; |
… | |
… | |
351 | } |
310 | } |
352 | else |
311 | else |
353 | w = h; |
312 | w = h; |
354 | } |
313 | } |
355 | } /* done parsing geometry string */ |
314 | } /* done parsing geometry string */ |
356 | else if (!(flags & geometrySet)) |
315 | else if (!update) |
357 | { |
316 | { |
358 | /* default geometry - scaled and centered */ |
317 | /* default geometry - scaled and centered */ |
359 | x = y = defaultAlign; |
318 | x = y = defaultAlign; |
360 | w = h = defaultScale; |
319 | w = h = defaultScale; |
361 | } |
320 | } |
362 | |
321 | |
363 | if (!(flags & geometrySet)) |
322 | if (!update) |
364 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
323 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
365 | |
324 | |
366 | if (ops) |
325 | if (ops) |
367 | { |
326 | { |
368 | while (*ops) |
327 | while (*ops) |
… | |
… | |
416 | |
375 | |
417 | while (*ops != ':' && *ops != '\0') ++ops; |
376 | while (*ops != ':' && *ops != '\0') ++ops; |
418 | } /* done parsing ops */ |
377 | } /* done parsing ops */ |
419 | } |
378 | } |
420 | |
379 | |
421 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; |
380 | 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; |
381 | 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; |
382 | 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; |
383 | if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; |
425 | } |
384 | } |
426 | |
385 | |
427 | if (new_flags != flags) |
386 | if (new_flags != flags) |
428 | { |
387 | { |
429 | flags = new_flags; |
388 | flags = new_flags; |
430 | changed++; |
389 | changed = true; |
431 | } |
390 | } |
432 | |
391 | |
433 | return (changed > 0); |
392 | return changed; |
434 | } |
393 | } |
435 | |
394 | |
436 | void |
395 | void |
437 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
396 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
438 | { |
397 | { |
… | |
… | |
661 | if (result) |
620 | if (result) |
662 | { |
621 | { |
663 | XGCValues gcv; |
622 | XGCValues gcv; |
664 | GC gc; |
623 | GC gc; |
665 | |
624 | |
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 */ |
625 | /* create Pixmap */ |
678 | if (pixmap == None) |
626 | if (pixmap == None |
|
|
627 | || pmap_width != new_pmap_width |
|
|
628 | || pmap_height != new_pmap_height |
|
|
629 | || pmap_depth != target->depth) |
679 | { |
630 | { |
|
|
631 | if (pixmap) |
|
|
632 | XFreePixmap (target->dpy, pixmap); |
680 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
633 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
681 | pmap_width = new_pmap_width; |
634 | pmap_width = new_pmap_width; |
682 | pmap_height = new_pmap_height; |
635 | pmap_height = new_pmap_height; |
683 | pmap_depth = target->depth; |
636 | pmap_depth = target->depth; |
684 | } |
637 | } |
… | |
… | |
792 | new_pmap_width = min (image_width, target_width); |
745 | new_pmap_width = min (image_width, target_width); |
793 | new_pmap_height = min (image_height, target_height); |
746 | new_pmap_height = min (image_height, target_height); |
794 | } |
747 | } |
795 | } |
748 | } |
796 | |
749 | |
797 | if (pixmap) |
|
|
798 | { |
|
|
799 | if (pmap_width != new_pmap_width |
|
|
800 | || pmap_height != new_pmap_height |
|
|
801 | || pmap_depth != target->depth) |
|
|
802 | { |
|
|
803 | XFreePixmap (target->dpy, pixmap); |
|
|
804 | pixmap = None; |
|
|
805 | } |
|
|
806 | } |
|
|
807 | |
|
|
808 | if (pixmap == None) |
750 | if (pixmap == None |
|
|
751 | || pmap_width != new_pmap_width |
|
|
752 | || pmap_height != new_pmap_height |
|
|
753 | || pmap_depth != target->depth) |
809 | { |
754 | { |
|
|
755 | if (pixmap) |
|
|
756 | XFreePixmap (target->dpy, pixmap); |
810 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
757 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
811 | pmap_width = new_pmap_width; |
758 | pmap_width = new_pmap_width; |
812 | pmap_height = new_pmap_height; |
759 | pmap_height = new_pmap_height; |
813 | pmap_depth = target->depth; |
760 | pmap_depth = target->depth; |
814 | } |
761 | } |
… | |
… | |
967 | } |
914 | } |
968 | |
915 | |
969 | bool |
916 | bool |
970 | bgPixmap_t::set_blur_radius (const char *geom) |
917 | bgPixmap_t::set_blur_radius (const char *geom) |
971 | { |
918 | { |
972 | int changed = 0; |
919 | bool changed = false; |
973 | unsigned int hr, vr; |
920 | unsigned int hr, vr; |
974 | int junk; |
921 | int junk; |
975 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
922 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
976 | |
923 | |
977 | if (!(geom_flags & WidthValue)) |
924 | if (!(geom_flags & WidthValue)) |
… | |
… | |
982 | min_it (hr, 128); |
929 | min_it (hr, 128); |
983 | min_it (vr, 128); |
930 | min_it (vr, 128); |
984 | |
931 | |
985 | if (h_blurRadius != hr) |
932 | if (h_blurRadius != hr) |
986 | { |
933 | { |
987 | ++changed; |
934 | changed = true; |
988 | h_blurRadius = hr; |
935 | h_blurRadius = hr; |
989 | } |
936 | } |
990 | |
937 | |
991 | if (v_blurRadius != vr) |
938 | if (v_blurRadius != vr) |
992 | { |
939 | { |
993 | ++changed; |
940 | changed = true; |
994 | v_blurRadius = vr; |
941 | v_blurRadius = vr; |
995 | } |
942 | } |
996 | |
943 | |
997 | if (v_blurRadius == 0 && h_blurRadius == 0) |
944 | if (v_blurRadius == 0 && h_blurRadius == 0) |
998 | flags &= ~blurNeeded; |
945 | flags &= ~blurNeeded; |
999 | else |
946 | else |
1000 | flags |= blurNeeded; |
947 | flags |= blurNeeded; |
1001 | |
948 | |
1002 | return (changed > 0); |
949 | return changed; |
1003 | } |
950 | } |
1004 | |
951 | |
1005 | static inline unsigned long |
952 | static inline unsigned long |
1006 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
953 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1007 | { |
954 | { |
… | |
… | |
1234 | |
1181 | |
1235 | if (mask_pic && overlay_pic && back_pic) |
1182 | if (mask_pic && overlay_pic && back_pic) |
1236 | { |
1183 | { |
1237 | XRenderColor mask_c; |
1184 | XRenderColor mask_c; |
1238 | |
1185 | |
1239 | memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); |
1186 | mask_c.red = mask_c.green = mask_c.blue = shade > 100 ? 0xffff : 0; |
1240 | mask_c.alpha = 0xffff; |
1187 | mask_c.alpha = 0xffff; |
1241 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1188 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1242 | |
1189 | |
1243 | mask_c.alpha = 0; |
1190 | mask_c.alpha = 0; |
1244 | mask_c.red = 0xffff - c.r; |
1191 | mask_c.red = 0xffff - c.r; |
… | |
… | |
1362 | if (gc) |
1309 | if (gc) |
1363 | { |
1310 | { |
1364 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1311 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1365 | result |= transpPmapTiled; |
1312 | result |= transpPmapTiled; |
1366 | XFreeGC (dpy, gc); |
1313 | XFreeGC (dpy, gc); |
1367 | } |
|
|
1368 | |
1314 | |
1369 | if (tiled_root_pmap != None) |
|
|
1370 | { |
|
|
1371 | if (!need_client_side_rendering ()) |
1315 | if (!need_client_side_rendering ()) |
1372 | { |
1316 | { |
1373 | if ((flags & blurNeeded) |
1317 | if ((flags & blurNeeded) |
1374 | && (flags & HAS_RENDER_CONV)) |
1318 | && (flags & HAS_RENDER_CONV)) |
1375 | { |
1319 | { |
… | |
… | |
1390 | pixmap = tiled_root_pmap; |
1334 | pixmap = tiled_root_pmap; |
1391 | pmap_width = window_width; |
1335 | pmap_width = window_width; |
1392 | pmap_height = window_height; |
1336 | pmap_height = window_height; |
1393 | pmap_depth = target->depth; |
1337 | pmap_depth = target->depth; |
1394 | } |
1338 | } |
|
|
1339 | else |
|
|
1340 | XFreePixmap (dpy, tiled_root_pmap); |
1395 | |
1341 | |
1396 | if (recoded_root_pmap != root_pixmap) |
1342 | if (recoded_root_pmap != root_pixmap) |
1397 | XFreePixmap (dpy, recoded_root_pmap); |
1343 | XFreePixmap (dpy, recoded_root_pmap); |
1398 | |
1344 | |
1399 | return result; |
1345 | return result; |
… | |
… | |
1408 | |
1354 | |
1409 | root_pixmap = new_root_pixmap; |
1355 | root_pixmap = new_root_pixmap; |
1410 | } |
1356 | } |
1411 | # endif /* ENABLE_TRANSPARENCY */ |
1357 | # endif /* ENABLE_TRANSPARENCY */ |
1412 | |
1358 | |
1413 | # ifndef HAVE_AFTERIMAGE |
1359 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1414 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); |
1360 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c); |
1415 | # endif |
1361 | # endif |
1416 | |
1362 | |
1417 | bool |
1363 | bool |
1418 | bgPixmap_t::render () |
1364 | bgPixmap_t::render () |
1419 | { |
1365 | { |
… | |
… | |
1442 | if (render_image (background_flags)) |
1388 | if (render_image (background_flags)) |
1443 | flags = flags & ~isInvalid; |
1389 | flags = flags & ~isInvalid; |
1444 | } |
1390 | } |
1445 | # endif |
1391 | # endif |
1446 | |
1392 | |
|
|
1393 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1447 | XImage *result = NULL; |
1394 | XImage *result = NULL; |
1448 | |
1395 | |
1449 | if (background_flags && (flags & isInvalid)) |
1396 | if (background_flags && (flags & isInvalid)) |
1450 | { |
1397 | { |
1451 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1398 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1452 | } |
1399 | } |
1453 | |
1400 | |
1454 | if (result) |
1401 | if (result) |
1455 | { |
1402 | { |
1456 | # if !defined(HAVE_AFTERIMAGE) && !XRENDER |
|
|
1457 | /* our own client-side tinting */ |
1403 | /* our own client-side tinting */ |
1458 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1404 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1459 | { |
1405 | { |
1460 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1406 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1461 | if (flags & tintSet) |
1407 | if (flags & tintSet) |
1462 | tint.get (c); |
1408 | tint.get (c); |
1463 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); |
1409 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c); |
1464 | } |
1410 | } |
1465 | # endif |
|
|
1466 | |
1411 | |
1467 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1412 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1468 | |
1413 | |
1469 | if (gc) |
1414 | if (gc) |
1470 | { |
1415 | { |
… | |
… | |
1474 | flags = flags & ~isInvalid; |
1419 | flags = flags & ~isInvalid; |
1475 | } |
1420 | } |
1476 | |
1421 | |
1477 | XDestroyImage (result); |
1422 | XDestroyImage (result); |
1478 | } |
1423 | } |
|
|
1424 | # endif |
1479 | |
1425 | |
1480 | if (flags & isInvalid) |
1426 | if (flags & isInvalid) |
1481 | { |
1427 | { |
1482 | if (pixmap != None) |
1428 | if (pixmap != None) |
1483 | { |
1429 | { |
… | |
… | |
1569 | flags |= hasChanged; |
1515 | flags |= hasChanged; |
1570 | } |
1516 | } |
1571 | |
1517 | |
1572 | #endif /* HAVE_BG_PIXMAP */ |
1518 | #endif /* HAVE_BG_PIXMAP */ |
1573 | |
1519 | |
1574 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER |
1520 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1575 | /* taken from aterm-0.4.2 */ |
1521 | /* taken from aterm-0.4.2 */ |
1576 | |
1522 | |
1577 | static void |
1523 | static void |
1578 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1524 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c) |
1579 | { |
1525 | { |
1580 | int sh_r, sh_g, sh_b; |
1526 | int sh_r, sh_g, sh_b; |
1581 | uint32_t mask_r, mask_g, mask_b; |
1527 | uint32_t mask_r, mask_g, mask_b; |
1582 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1528 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1583 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1529 | rgba low; |
1584 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1530 | rgba high; |
1585 | int i; |
1531 | int i; |
1586 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1532 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1587 | |
1533 | |
1588 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1534 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1589 | |
1535 | |
… | |
… | |
1654 | /* prepare limits for color transformation (each channel is handled separately) */ |
1600 | /* prepare limits for color transformation (each channel is handled separately) */ |
1655 | if (shade > 100) |
1601 | if (shade > 100) |
1656 | { |
1602 | { |
1657 | shade = 200 - shade; |
1603 | shade = 200 - shade; |
1658 | |
1604 | |
1659 | lower_lim_r = 65535-rm; |
1605 | high.r = (65535 - c.r) * shade / 100; |
1660 | lower_lim_g = 65535-gm; |
1606 | high.g = (65535 - c.g) * shade / 100; |
1661 | lower_lim_b = 65535-bm; |
1607 | high.b = (65535 - c.b) * shade / 100; |
1662 | |
1608 | |
1663 | lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); |
1609 | low.r = 65535 - high.r; |
1664 | lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); |
1610 | low.g = 65535 - high.g; |
1665 | lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); |
1611 | low.b = 65535 - high.b; |
1666 | |
|
|
1667 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
|
|
1668 | } |
1612 | } |
1669 | else |
1613 | else |
1670 | { |
1614 | { |
|
|
1615 | high.r = c.r * shade / 100; |
|
|
1616 | high.g = c.g * shade / 100; |
|
|
1617 | high.b = c.b * shade / 100; |
1671 | |
1618 | |
1672 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1619 | low.r = low.g = low.b = 0; |
1673 | |
|
|
1674 | upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100); |
|
|
1675 | upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100); |
|
|
1676 | upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100); |
|
|
1677 | } |
1620 | } |
1678 | |
1621 | |
1679 | /* fill our lookup tables */ |
1622 | /* fill our lookup tables */ |
1680 | for (i = 0; i <= mask_r>>sh_r; i++) |
1623 | for (i = 0; i <= mask_r>>sh_r; i++) |
1681 | { |
1624 | { |
1682 | uint32_t tmp; |
1625 | uint32_t tmp; |
1683 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); |
1626 | tmp = i * high.r; |
1684 | tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); |
1627 | tmp += (mask_r>>sh_r) * low.r; |
1685 | lookup_r[i] = (tmp/65535)<<sh_r; |
1628 | lookup_r[i] = (tmp/65535)<<sh_r; |
1686 | } |
1629 | } |
1687 | for (i = 0; i <= mask_g>>sh_g; i++) |
1630 | for (i = 0; i <= mask_g>>sh_g; i++) |
1688 | { |
1631 | { |
1689 | uint32_t tmp; |
1632 | uint32_t tmp; |
1690 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); |
1633 | tmp = i * high.g; |
1691 | tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); |
1634 | tmp += (mask_g>>sh_g) * low.g; |
1692 | lookup_g[i] = (tmp/65535)<<sh_g; |
1635 | lookup_g[i] = (tmp/65535)<<sh_g; |
1693 | } |
1636 | } |
1694 | for (i = 0; i <= mask_b>>sh_b; i++) |
1637 | for (i = 0; i <= mask_b>>sh_b; i++) |
1695 | { |
1638 | { |
1696 | uint32_t tmp; |
1639 | uint32_t tmp; |
1697 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); |
1640 | tmp = i * high.b; |
1698 | tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); |
1641 | tmp += (mask_b>>sh_b) * low.b; |
1699 | lookup_b[i] = (tmp/65535)<<sh_b; |
1642 | lookup_b[i] = (tmp/65535)<<sh_b; |
1700 | } |
1643 | } |
1701 | |
1644 | |
1702 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1645 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1703 | if (srcImage->bits_per_pixel == 32 |
1646 | if (srcImage->bits_per_pixel == 32 |