… | |
… | |
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. |
… | |
… | |
175 | { |
176 | { |
176 | # ifdef HAVE_AFTERIMAGE |
177 | # ifdef HAVE_AFTERIMAGE |
177 | if (original_asim) |
178 | if (original_asim) |
178 | return true; |
179 | return true; |
179 | # endif |
180 | # 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; |
181 | return false; |
192 | } |
182 | } |
193 | |
183 | |
194 | # ifdef BG_IMAGE_FROM_FILE |
184 | # ifdef BG_IMAGE_FROM_FILE |
195 | static inline bool |
185 | static inline bool |
… | |
… | |
232 | int diff = window_size - image_size; |
222 | int diff = window_size - image_size; |
233 | int smaller = min (image_size, window_size); |
223 | int smaller = min (image_size, window_size); |
234 | |
224 | |
235 | if (align >= 0 && align <= 100) |
225 | if (align >= 0 && align <= 100) |
236 | return diff * align / 100; |
226 | return diff * align / 100; |
237 | else if (align > 100 && align <= 200 ) |
227 | else if (align > 100 && align <= 200) |
238 | return ((align - 100) * smaller / 100) + window_size - smaller; |
228 | return ((align - 100) * smaller / 100) + window_size - smaller; |
239 | else if (align >= -100 && align < 0) |
229 | else if (align >= -100 && align < 0) |
240 | return ((align + 100) * smaller / 100) - image_size; |
230 | return ((align + 100) * smaller / 100) - image_size; |
241 | return 0; |
231 | return 0; |
242 | } |
232 | } |
… | |
… | |
478 | x = make_align_position (h_align, target_width, w); |
468 | x = make_align_position (h_align, target_width, w); |
479 | y = make_align_position (v_align, target_height, h); |
469 | y = make_align_position (v_align, target_height, h); |
480 | } |
470 | } |
481 | |
471 | |
482 | flags &= ~sizeSensitive; |
472 | flags &= ~sizeSensitive; |
483 | if (h_scale != 0 || v_scale != 0 |
473 | if ((flags & propScale) || h_scale || v_scale |
484 | || h_align != 0 || v_align != 0 |
474 | || (!(flags & rootAlign) && (h_align || v_align)) |
485 | || w > target_width || h > target_height) |
475 | || w > target_width || h > target_height) |
486 | flags |= sizeSensitive; |
476 | flags |= sizeSensitive; |
487 | } |
477 | } |
488 | |
478 | |
489 | # ifdef HAVE_AFTERIMAGE |
479 | # ifdef HAVE_AFTERIMAGE |
… | |
… | |
941 | } |
931 | } |
942 | |
932 | |
943 | # ifdef HAVE_AFTERIMAGE |
933 | # ifdef HAVE_AFTERIMAGE |
944 | if (!target->asimman) |
934 | if (!target->asimman) |
945 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
935 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
946 | original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
936 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
|
|
937 | if (image) |
|
|
938 | { |
947 | if (original_asim) |
939 | if (original_asim) |
|
|
940 | safe_asimage_destroy (original_asim); |
|
|
941 | original_asim = image; |
948 | have_image = true; |
942 | have_image = true; |
949 | return have_image; |
943 | return true; |
|
|
944 | } |
950 | # endif |
945 | # endif |
951 | |
946 | |
952 | # ifdef HAVE_PIXBUF |
947 | # ifdef HAVE_PIXBUF |
953 | pixbuf = gdk_pixbuf_new_from_file (file, NULL); |
948 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
|
|
949 | if (image) |
|
|
950 | { |
954 | if (pixbuf) |
951 | if (pixbuf) |
|
|
952 | g_object_unref (pixbuf); |
|
|
953 | pixbuf = image; |
955 | have_image = true; |
954 | have_image = true; |
956 | return have_image; |
955 | return true; |
|
|
956 | } |
957 | # endif |
957 | # endif |
958 | } |
958 | } |
959 | |
959 | |
960 | return false; |
960 | return false; |
961 | } |
961 | } |
… | |
… | |
1007 | flags &= ~blurNeeded; |
1007 | flags &= ~blurNeeded; |
1008 | else |
1008 | else |
1009 | flags |= blurNeeded; |
1009 | flags |= blurNeeded; |
1010 | |
1010 | |
1011 | #if XFT |
1011 | #if XFT |
1012 | XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); |
1012 | XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); |
1013 | if (filters) |
1013 | if (filters) |
1014 | { |
1014 | { |
1015 | for (int i = 0; i < filters->nfilter; i++) |
1015 | for (int i = 0; i < filters->nfilter; i++) |
1016 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1016 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1017 | flags |= bgPixmap_t::blurServerSide; |
1017 | flags |= bgPixmap_t::blurServerSide; |
1018 | |
1018 | |
1019 | XFree (filters); |
1019 | XFree (filters); |
1020 | } |
1020 | } |
1021 | #endif |
1021 | #endif |
1022 | |
1022 | |
1023 | return (changed > 0); |
1023 | return (changed > 0); |
1024 | } |
1024 | } |
1025 | |
1025 | |
… | |
… | |
1113 | } |
1113 | } |
1114 | |
1114 | |
1115 | return false; |
1115 | return false; |
1116 | } |
1116 | } |
1117 | |
1117 | |
|
|
1118 | #if XFT |
1118 | static void |
1119 | static void |
1119 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1120 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1120 | { |
1121 | { |
1121 | double sigma = radius / 2.0; |
1122 | double sigma = radius / 2.0; |
1122 | double scale = sqrt (2.0 * M_PI) * sigma; |
1123 | double scale = sqrt (2.0 * M_PI) * sigma; |
1123 | double sum = 0.0; |
1124 | double sum = 0.0; |
1124 | |
1125 | |
1125 | for (int i = 0; i < width; i++) |
1126 | for (int i = 0; i < width; i++) |
1126 | { |
1127 | { |
1127 | double x = i - width / 2; |
1128 | double x = i - width / 2; |
1128 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
1129 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
1129 | sum += kernel[i]; |
1130 | sum += kernel[i]; |
1130 | } |
1131 | } |
1131 | |
1132 | |
1132 | params[0] = XDoubleToFixed (width); |
1133 | params[0] = XDoubleToFixed (width); |
1133 | params[1] = XDoubleToFixed (1); |
1134 | params[1] = XDoubleToFixed (1); |
1134 | |
1135 | |
1135 | for (int i = 0; i < width; i++) |
1136 | for (int i = 0; i < width; i++) |
1136 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1137 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1137 | } |
1138 | } |
|
|
1139 | #endif |
1138 | |
1140 | |
1139 | bool |
1141 | bool |
1140 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1142 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1141 | { |
1143 | { |
1142 | bool ret = false; |
1144 | bool ret = false; |
… | |
… | |
1316 | unsigned int root_pmap_width, root_pmap_height; |
1318 | unsigned int root_pmap_width, root_pmap_height; |
1317 | int window_width = target->szHint.width; |
1319 | int window_width = target->szHint.width; |
1318 | int window_height = target->szHint.height; |
1320 | int window_height = target->szHint.height; |
1319 | int sx, sy; |
1321 | int sx, sy; |
1320 | XGCValues gcv; |
1322 | XGCValues gcv; |
|
|
1323 | GC gc; |
1321 | |
1324 | |
1322 | TIMING_TEST_START (tp); |
1325 | TIMING_TEST_START (tp); |
1323 | target->get_window_origin (sx, sy); |
1326 | target->get_window_origin (sx, sy); |
1324 | |
1327 | |
1325 | /* check if we are outside of the visible part of the virtual screen : */ |
1328 | /* check if we are outside of the visible part of the virtual screen : */ |
… | |
… | |
1339 | root_pixmap = None; |
1342 | root_pixmap = None; |
1340 | |
1343 | |
1341 | target->allowedxerror = 0; |
1344 | target->allowedxerror = 0; |
1342 | } |
1345 | } |
1343 | |
1346 | |
|
|
1347 | if (root_pixmap == None) |
|
|
1348 | return 0; |
|
|
1349 | |
1344 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); |
1350 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); |
1345 | GC gc = NULL; |
|
|
1346 | |
1351 | |
1347 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1352 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1348 | return 0; |
1353 | return 0; |
1349 | |
1354 | |
1350 | if (root_pixmap == None) |
|
|
1351 | { |
|
|
1352 | /* use tricks to obtain the root background image :*/ |
|
|
1353 | /* we want to create Overrideredirect window overlapping out window |
|
|
1354 | with background type of Parent Relative and then grab it */ |
|
|
1355 | XSetWindowAttributes attr; |
|
|
1356 | Window src; |
|
|
1357 | bool success = false; |
|
|
1358 | |
|
|
1359 | attr.background_pixmap = ParentRelative; |
|
|
1360 | attr.backing_store = Always; |
|
|
1361 | attr.event_mask = ExposureMask; |
|
|
1362 | attr.override_redirect = True; |
|
|
1363 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
|
|
1364 | CopyFromParent, CopyFromParent, CopyFromParent, |
|
|
1365 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
|
|
1366 | &attr); |
|
|
1367 | |
|
|
1368 | if (src != None) |
|
|
1369 | { |
|
|
1370 | XEvent event; |
|
|
1371 | int ev_count = 0; |
|
|
1372 | XGrabServer (dpy); |
|
|
1373 | XMapRaised (dpy, src); |
|
|
1374 | XSync (dpy, False); |
|
|
1375 | |
|
|
1376 | /* XSync should get window where it's properly exposed, |
|
|
1377 | * but to be on the safe side - let's check for the actual event to arrive : */ |
|
|
1378 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
|
|
1379 | ++ev_count; |
|
|
1380 | |
|
|
1381 | if (ev_count > 0); |
|
|
1382 | { |
|
|
1383 | /* hooray! - we can grab the image! */ |
|
|
1384 | gc = XCreateGC (dpy, root, 0, NULL); |
|
|
1385 | if (gc) |
|
|
1386 | { |
|
|
1387 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
|
|
1388 | success = true; |
|
|
1389 | } |
|
|
1390 | } |
|
|
1391 | |
|
|
1392 | XDestroyWindow (dpy, src); |
|
|
1393 | XUngrabServer (dpy); |
|
|
1394 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
|
|
1395 | } |
|
|
1396 | |
|
|
1397 | if (!success) |
|
|
1398 | { |
|
|
1399 | XFreePixmap (dpy, tiled_root_pmap); |
|
|
1400 | tiled_root_pmap = None; |
|
|
1401 | } |
|
|
1402 | else |
|
|
1403 | result |= transpPmapTiled; |
|
|
1404 | } |
|
|
1405 | else |
|
|
1406 | { |
|
|
1407 | /* straightforward pixmap copy */ |
1355 | /* straightforward pixmap copy */ |
1408 | gcv.tile = root_pixmap; |
1356 | gcv.tile = root_pixmap; |
1409 | gcv.fill_style = FillTiled; |
1357 | gcv.fill_style = FillTiled; |
1410 | |
1358 | |
1411 | while (sx < 0) sx += (int)root_width; |
1359 | while (sx < 0) sx += (int)root_width; |
1412 | while (sy < 0) sy += (int)root_height; |
1360 | while (sy < 0) sy += (int)root_height; |
1413 | |
1361 | |
1414 | gcv.ts_x_origin = -sx; |
1362 | gcv.ts_x_origin = -sx; |
1415 | gcv.ts_y_origin = -sy; |
1363 | gcv.ts_y_origin = -sy; |
1416 | gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1364 | gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1417 | |
1365 | |
1418 | if (gc) |
1366 | if (gc) |
1419 | { |
1367 | { |
1420 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1368 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1421 | result |= transpPmapTiled; |
1369 | result |= transpPmapTiled; |
1422 | } |
1370 | XFreeGC (dpy, gc); |
1423 | } |
1371 | } |
1424 | TIMING_TEST_PRINT_RESULT (tp); |
1372 | TIMING_TEST_PRINT_RESULT (tp); |
1425 | |
1373 | |
1426 | if (tiled_root_pmap != None) |
1374 | if (tiled_root_pmap != None) |
1427 | { |
1375 | { |
1428 | if (!need_client_side_rendering ()) |
1376 | if (!need_client_side_rendering ()) |
1429 | { |
1377 | { |
1430 | if ((flags & blurNeeded)) |
1378 | if (flags & (blurNeeded | blurServerSide)) |
1431 | { |
1379 | { |
1432 | if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
1380 | if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) |
1433 | result |= transpPmapBlurred; |
1381 | result |= transpPmapBlurred; |
1434 | } |
1382 | } |
1435 | if ((flags & tintNeeded)) |
1383 | if (flags & (tintNeeded | tintServerSide)) |
1436 | { |
1384 | { |
1437 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
1385 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) |
1438 | result |= transpPmapTinted; |
1386 | result |= transpPmapTinted; |
1439 | } |
1387 | } |
1440 | } /* server side rendering completed */ |
1388 | } /* server side rendering completed */ |
1441 | |
1389 | |
1442 | if (pixmap) |
1390 | if (pixmap) |
… | |
… | |
1445 | pixmap = tiled_root_pmap; |
1393 | pixmap = tiled_root_pmap; |
1446 | pmap_width = window_width; |
1394 | pmap_width = window_width; |
1447 | pmap_height = window_height; |
1395 | pmap_height = window_height; |
1448 | pmap_depth = root_depth; |
1396 | pmap_depth = root_depth; |
1449 | } |
1397 | } |
1450 | |
|
|
1451 | if (gc) |
|
|
1452 | XFreeGC (dpy, gc); |
|
|
1453 | |
1398 | |
1454 | TIMING_TEST_PRINT_RESULT (tp); |
1399 | TIMING_TEST_PRINT_RESULT (tp); |
1455 | |
1400 | |
1456 | return result; |
1401 | return result; |
1457 | } |
1402 | } |
… | |
… | |
1682 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1627 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1683 | int i; |
1628 | int i; |
1684 | |
1629 | |
1685 | Visual *visual = term->visual; |
1630 | Visual *visual = term->visual; |
1686 | |
1631 | |
1687 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; |
1632 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1688 | |
1633 | |
1689 | /* for convenience */ |
1634 | /* for convenience */ |
1690 | mask_r = visual->red_mask; |
1635 | mask_r = visual->red_mask; |
1691 | mask_g = visual->green_mask; |
1636 | mask_g = visual->green_mask; |
1692 | mask_b = visual->blue_mask; |
1637 | mask_b = visual->blue_mask; |
1693 | |
1638 | |
1694 | /* boring lookup table pre-initialization */ |
1639 | /* boring lookup table pre-initialization */ |
1695 | switch (srcImage->bits_per_pixel) { |
1640 | switch (srcImage->bits_per_pixel) |
|
|
1641 | { |
1696 | case 15: |
1642 | case 15: |
1697 | if ((mask_r != 0x7c00) || |
1643 | if ((mask_r != 0x7c00) || |
1698 | (mask_g != 0x03e0) || |
1644 | (mask_g != 0x03e0) || |
1699 | (mask_b != 0x001f)) |
1645 | (mask_b != 0x001f)) |
1700 | return; |
1646 | return; |
1701 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); |
1647 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); |
1702 | lookup_r = lookup; |
1648 | lookup_r = lookup; |
1703 | lookup_g = lookup+32; |
1649 | lookup_g = lookup+32; |
1704 | lookup_b = lookup+32+32; |
1650 | lookup_b = lookup+32+32; |
1705 | sh_r = 10; |
1651 | sh_r = 10; |
1706 | sh_g = 5; |
1652 | sh_g = 5; |
1707 | sh_b = 0; |
1653 | sh_b = 0; |
1708 | break; |
1654 | break; |
1709 | case 16: |
1655 | case 16: |
1710 | if ((mask_r != 0xf800) || |
1656 | if ((mask_r != 0xf800) || |
1711 | (mask_g != 0x07e0) || |
1657 | (mask_g != 0x07e0) || |
1712 | (mask_b != 0x001f)) |
1658 | (mask_b != 0x001f)) |
1713 | return; |
1659 | return; |
1714 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); |
1660 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); |
1715 | lookup_r = lookup; |
1661 | lookup_r = lookup; |
1716 | lookup_g = lookup+32; |
1662 | lookup_g = lookup+32; |
1717 | lookup_b = lookup+32+64; |
1663 | lookup_b = lookup+32+64; |
1718 | sh_r = 11; |
1664 | sh_r = 11; |
1719 | sh_g = 5; |
1665 | sh_g = 5; |
1720 | sh_b = 0; |
1666 | sh_b = 0; |
1721 | break; |
1667 | break; |
1722 | case 24: |
1668 | case 24: |
1723 | if ((mask_r != 0xff0000) || |
1669 | if ((mask_r != 0xff0000) || |
1724 | (mask_g != 0x00ff00) || |
1670 | (mask_g != 0x00ff00) || |
1725 | (mask_b != 0x0000ff)) |
1671 | (mask_b != 0x0000ff)) |
1726 | return; |
1672 | return; |
1727 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
1673 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
1728 | lookup_r = lookup; |
1674 | lookup_r = lookup; |
1729 | lookup_g = lookup+256; |
1675 | lookup_g = lookup+256; |
1730 | lookup_b = lookup+256+256; |
1676 | lookup_b = lookup+256+256; |
1731 | sh_r = 16; |
1677 | sh_r = 16; |
1732 | sh_g = 8; |
1678 | sh_g = 8; |
1733 | sh_b = 0; |
1679 | sh_b = 0; |
1734 | break; |
1680 | break; |
1735 | case 32: |
1681 | case 32: |
1736 | if ((mask_r != 0xff0000) || |
1682 | if ((mask_r != 0xff0000) || |
1737 | (mask_g != 0x00ff00) || |
1683 | (mask_g != 0x00ff00) || |
1738 | (mask_b != 0x0000ff)) |
1684 | (mask_b != 0x0000ff)) |
1739 | return; |
1685 | return; |
1740 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
1686 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
1741 | lookup_r = lookup; |
1687 | lookup_r = lookup; |
1742 | lookup_g = lookup+256; |
1688 | lookup_g = lookup+256; |
1743 | lookup_b = lookup+256+256; |
1689 | lookup_b = lookup+256+256; |
1744 | sh_r = 16; |
1690 | sh_r = 16; |
1745 | sh_g = 8; |
1691 | sh_g = 8; |
1746 | sh_b = 0; |
1692 | sh_b = 0; |
1747 | break; |
1693 | break; |
1748 | default: |
1694 | default: |
1749 | return; /* we do not support this color depth */ |
1695 | return; /* we do not support this color depth */ |
1750 | } |
1696 | } |
1751 | |
1697 | |
1752 | /* prepare limits for color transformation (each channel is handled separately) */ |
1698 | /* prepare limits for color transformation (each channel is handled separately) */ |
1753 | if (shade > 100) { |
1699 | if (shade > 100) |
|
|
1700 | { |
1754 | shade = 200 - shade; |
1701 | shade = 200 - shade; |
1755 | |
1702 | |
1756 | lower_lim_r = 65535-rm; |
1703 | lower_lim_r = 65535-rm; |
1757 | lower_lim_g = 65535-gm; |
1704 | lower_lim_g = 65535-gm; |
1758 | lower_lim_b = 65535-bm; |
1705 | lower_lim_b = 65535-bm; |
1759 | |
1706 | |
1760 | lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); |
1707 | lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); |
1761 | lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); |
1708 | lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); |
1762 | lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); |
1709 | lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); |
1763 | |
1710 | |
1764 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
1711 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
|
|
1712 | } |
1765 | } else { |
1713 | else |
|
|
1714 | { |
1766 | |
1715 | |
1767 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1716 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1768 | |
1717 | |
1769 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
1718 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
1770 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |
1719 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |
1771 | upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); |
1720 | upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); |
1772 | } |
1721 | } |
1773 | |
1722 | |
1774 | /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */ |
1723 | /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */ |
1775 | if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 )) |
1724 | if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000)) |
1776 | { |
1725 | { |
1777 | unsigned int tmp; |
1726 | unsigned int tmp; |
1778 | |
1727 | |
1779 | tmp = lower_lim_r; |
1728 | tmp = lower_lim_r; |
1780 | lower_lim_r = lower_lim_b; |
1729 | lower_lim_r = lower_lim_b; |
1781 | lower_lim_b = tmp; |
1730 | lower_lim_b = tmp; |
1782 | |
1731 | |
1783 | tmp = upper_lim_r; |
1732 | tmp = upper_lim_r; |
1784 | upper_lim_r = upper_lim_b; |
1733 | upper_lim_r = upper_lim_b; |
1785 | upper_lim_b = tmp; |
1734 | upper_lim_b = tmp; |
1786 | } |
1735 | } |
1787 | |
1736 | |
1788 | /* fill our lookup tables */ |
1737 | /* fill our lookup tables */ |
1789 | for (i = 0; i <= mask_r>>sh_r; i++) |
1738 | for (i = 0; i <= mask_r>>sh_r; i++) |
1790 | { |
1739 | { |
1791 | RUINT32T tmp; |
1740 | RUINT32T tmp; |
1792 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); |
1741 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); |
1793 | tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); |
1742 | tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); |
1794 | lookup_r[i] = (tmp/65535)<<sh_r; |
1743 | lookup_r[i] = (tmp/65535)<<sh_r; |
1795 | } |
1744 | } |
1796 | for (i = 0; i <= mask_g>>sh_g; i++) |
1745 | for (i = 0; i <= mask_g>>sh_g; i++) |
1797 | { |
1746 | { |
1798 | RUINT32T tmp; |
1747 | RUINT32T tmp; |
1799 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); |
1748 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); |
1800 | tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); |
1749 | tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); |
1801 | lookup_g[i] = (tmp/65535)<<sh_g; |
1750 | lookup_g[i] = (tmp/65535)<<sh_g; |
1802 | } |
1751 | } |
1803 | for (i = 0; i <= mask_b>>sh_b; i++) |
1752 | for (i = 0; i <= mask_b>>sh_b; i++) |
1804 | { |
1753 | { |
1805 | RUINT32T tmp; |
1754 | RUINT32T tmp; |
1806 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); |
1755 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); |
1807 | tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); |
1756 | tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); |
1808 | lookup_b[i] = (tmp/65535)<<sh_b; |
1757 | lookup_b[i] = (tmp/65535)<<sh_b; |
1809 | } |
1758 | } |
1810 | |
1759 | |
1811 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1760 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1812 | switch (srcImage->bits_per_pixel) |
1761 | switch (srcImage->bits_per_pixel) |
1813 | { |
1762 | { |
1814 | case 15: |
1763 | case 15: |
1815 | { |
1764 | { |
1816 | unsigned short *p1, *pf, *p, *pl; |
1765 | unsigned short *p1, *pf, *p, *pl; |
1817 | p1 = (unsigned short *) srcImage->data; |
1766 | p1 = (unsigned short *) srcImage->data; |
1818 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1767 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1819 | while (p1 < pf) |
1768 | while (p1 < pf) |
1820 | { |
1769 | { |
1821 | p = p1; |
1770 | p = p1; |
1822 | pl = p1 + srcImage->width; |
1771 | pl = p1 + srcImage->width; |
1823 | for (; p < pl; p++) |
1772 | for (; p < pl; p++) |
1824 | { |
1773 | { |
1825 | *p = lookup_r[(*p & 0x7c00)>>10] | |
1774 | *p = lookup_r[(*p & 0x7c00)>>10] | |
1826 | lookup_g[(*p & 0x03e0)>> 5] | |
1775 | lookup_g[(*p & 0x03e0)>> 5] | |
1827 | lookup_b[(*p & 0x001f)]; |
1776 | lookup_b[(*p & 0x001f)]; |
1828 | } |
1777 | } |
1829 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
1778 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1779 | } |
|
|
1780 | break; |
1830 | } |
1781 | } |
1831 | break; |
|
|
1832 | } |
|
|
1833 | case 16: |
1782 | case 16: |
1834 | { |
1783 | { |
1835 | unsigned short *p1, *pf, *p, *pl; |
1784 | unsigned short *p1, *pf, *p, *pl; |
1836 | p1 = (unsigned short *) srcImage->data; |
1785 | p1 = (unsigned short *) srcImage->data; |
1837 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1786 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1838 | while (p1 < pf) |
1787 | while (p1 < pf) |
1839 | { |
1788 | { |
1840 | p = p1; |
1789 | p = p1; |
1841 | pl = p1 + srcImage->width; |
1790 | pl = p1 + srcImage->width; |
1842 | for (; p < pl; p++) |
1791 | for (; p < pl; p++) |
1843 | { |
1792 | { |
1844 | *p = lookup_r[(*p & 0xf800)>>11] | |
1793 | *p = lookup_r[(*p & 0xf800)>>11] | |
1845 | lookup_g[(*p & 0x07e0)>> 5] | |
1794 | lookup_g[(*p & 0x07e0)>> 5] | |
1846 | lookup_b[(*p & 0x001f)]; |
1795 | lookup_b[(*p & 0x001f)]; |
1847 | } |
1796 | } |
1848 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
1797 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1798 | } |
|
|
1799 | break; |
1849 | } |
1800 | } |
1850 | break; |
|
|
1851 | } |
|
|
1852 | case 24: |
1801 | case 24: |
1853 | { |
1802 | { |
1854 | unsigned char *p1, *pf, *p, *pl; |
1803 | unsigned char *p1, *pf, *p, *pl; |
1855 | p1 = (unsigned char *) srcImage->data; |
1804 | p1 = (unsigned char *) srcImage->data; |
1856 | pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1805 | pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1857 | while (p1 < pf) |
1806 | while (p1 < pf) |
1858 | { |
1807 | { |
1859 | p = p1; |
1808 | p = p1; |
1860 | pl = p1 + srcImage->width * 3; |
1809 | pl = p1 + srcImage->width * 3; |
1861 | for (; p < pl; p += 3) |
1810 | for (; p < pl; p += 3) |
1862 | { |
1811 | { |
1863 | p[0] = lookup_r[(p[0] & 0xff0000)>>16]; |
1812 | p[0] = lookup_r[(p[0] & 0xff0000)>>16]; |
1864 | p[1] = lookup_r[(p[1] & 0x00ff00)>> 8]; |
1813 | p[1] = lookup_r[(p[1] & 0x00ff00)>> 8]; |
1865 | p[2] = lookup_r[(p[2] & 0x0000ff)]; |
1814 | p[2] = lookup_r[(p[2] & 0x0000ff)]; |
1866 | } |
1815 | } |
1867 | p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line); |
1816 | p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1817 | } |
|
|
1818 | break; |
1868 | } |
1819 | } |
1869 | break; |
|
|
1870 | } |
|
|
1871 | case 32: |
1820 | case 32: |
1872 | { |
1821 | { |
1873 | RUINT32T *p1, *pf, *p, *pl; |
1822 | RUINT32T *p1, *pf, *p, *pl; |
1874 | p1 = (RUINT32T *) srcImage->data; |
1823 | p1 = (RUINT32T *) srcImage->data; |
1875 | pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1824 | pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1876 | |
1825 | |
1877 | while (p1 < pf) |
1826 | while (p1 < pf) |
1878 | { |
1827 | { |
1879 | p = p1; |
1828 | p = p1; |
1880 | pl = p1 + srcImage->width; |
1829 | pl = p1 + srcImage->width; |
1881 | for (; p < pl; p++) |
1830 | for (; p < pl; p++) |
1882 | { |
1831 | { |
1883 | *p = lookup_r[(*p & 0xff0000)>>16] | |
1832 | *p = lookup_r[(*p & 0xff0000)>>16] | |
1884 | lookup_g[(*p & 0x00ff00)>> 8] | |
1833 | lookup_g[(*p & 0x00ff00)>> 8] | |
1885 | lookup_b[(*p & 0x0000ff)] | |
1834 | lookup_b[(*p & 0x0000ff)] | |
1886 | (*p & ~0xffffff); |
1835 | (*p & ~0xffffff); |
1887 | } |
1836 | } |
1888 | p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line); |
1837 | p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1838 | } |
|
|
1839 | break; |
1889 | } |
1840 | } |
1890 | break; |
|
|
1891 | } |
|
|
1892 | } |
1841 | } |
1893 | |
1842 | |
1894 | free (lookup); |
1843 | free (lookup); |
1895 | } |
1844 | } |
1896 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |
1845 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |