… | |
… | |
222 | int diff = window_size - image_size; |
222 | int diff = window_size - image_size; |
223 | int smaller = min (image_size, window_size); |
223 | int smaller = min (image_size, window_size); |
224 | |
224 | |
225 | if (align >= 0 && align <= 100) |
225 | if (align >= 0 && align <= 100) |
226 | return diff * align / 100; |
226 | return diff * align / 100; |
227 | else if (align > 100 && align <= 200 ) |
227 | else if (align > 100 && align <= 200) |
228 | return ((align - 100) * smaller / 100) + window_size - smaller; |
228 | return ((align - 100) * smaller / 100) + window_size - smaller; |
229 | else if (align >= -100 && align < 0) |
229 | else if (align >= -100 && align < 0) |
230 | return ((align + 100) * smaller / 100) - image_size; |
230 | return ((align + 100) * smaller / 100) - image_size; |
231 | return 0; |
231 | return 0; |
232 | } |
232 | } |
… | |
… | |
428 | { |
428 | { |
429 | flags = new_flags; |
429 | flags = new_flags; |
430 | changed++; |
430 | changed++; |
431 | } |
431 | } |
432 | |
432 | |
433 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
|
|
434 | // flags, h_scale, v_scale, h_align, v_align); |
|
|
435 | return (changed > 0); |
433 | return (changed > 0); |
436 | } |
434 | } |
437 | |
435 | |
438 | void |
436 | void |
439 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
437 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
… | |
… | |
468 | x = make_align_position (h_align, target_width, w); |
466 | x = make_align_position (h_align, target_width, w); |
469 | y = make_align_position (v_align, target_height, h); |
467 | y = make_align_position (v_align, target_height, h); |
470 | } |
468 | } |
471 | |
469 | |
472 | flags &= ~sizeSensitive; |
470 | flags &= ~sizeSensitive; |
473 | if (h_scale != 0 || v_scale != 0 |
471 | if ((flags & propScale) || h_scale || v_scale |
474 | || h_align != 0 || v_align != 0 |
472 | || (!(flags & rootAlign) && (h_align || v_align)) |
475 | || w > target_width || h > target_height) |
473 | || w > target_width || h > target_height) |
476 | flags |= sizeSensitive; |
474 | flags |= sizeSensitive; |
477 | } |
475 | } |
478 | |
476 | |
479 | # ifdef HAVE_AFTERIMAGE |
477 | # ifdef HAVE_AFTERIMAGE |
… | |
… | |
529 | |
527 | |
530 | int x = 0; |
528 | int x = 0; |
531 | int y = 0; |
529 | int y = 0; |
532 | int w = 0; |
530 | int w = 0; |
533 | int h = 0; |
531 | int h = 0; |
534 | |
|
|
535 | TIMING_TEST_START (asim); |
|
|
536 | |
532 | |
537 | if (original_asim) |
533 | if (original_asim) |
538 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
534 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
539 | |
535 | |
540 | if (!original_asim |
536 | if (!original_asim |
… | |
… | |
657 | } |
653 | } |
658 | |
654 | |
659 | free (layers); |
655 | free (layers); |
660 | } |
656 | } |
661 | } |
657 | } |
662 | TIMING_TEST_PRINT_RESULT (asim); |
|
|
663 | |
658 | |
664 | bool ret = false; |
659 | bool ret = false; |
665 | |
660 | |
666 | if (result) |
661 | if (result) |
667 | { |
662 | { |
… | |
… | |
713 | |
708 | |
714 | if (result != background && result != original_asim) |
709 | if (result != background && result != original_asim) |
715 | destroy_asimage (&result); |
710 | destroy_asimage (&result); |
716 | |
711 | |
717 | XFreeGC (target->dpy, gc); |
712 | XFreeGC (target->dpy, gc); |
718 | TIMING_TEST_PRINT_RESULT (asim); |
|
|
719 | |
713 | |
720 | ret = true; |
714 | ret = true; |
721 | } |
715 | } |
722 | |
716 | |
723 | if (background) |
717 | if (background) |
… | |
… | |
1007 | flags &= ~blurNeeded; |
1001 | flags &= ~blurNeeded; |
1008 | else |
1002 | else |
1009 | flags |= blurNeeded; |
1003 | flags |= blurNeeded; |
1010 | |
1004 | |
1011 | #if XFT |
1005 | #if XFT |
1012 | XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); |
1006 | XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); |
1013 | if (filters) |
1007 | if (filters) |
1014 | { |
1008 | { |
1015 | for (int i = 0; i < filters->nfilter; i++) |
1009 | for (int i = 0; i < filters->nfilter; i++) |
1016 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1010 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1017 | flags |= bgPixmap_t::blurServerSide; |
1011 | flags |= bgPixmap_t::blurServerSide; |
1018 | |
1012 | |
1019 | XFree (filters); |
1013 | XFree (filters); |
1020 | } |
1014 | } |
1021 | #endif |
1015 | #endif |
1022 | |
1016 | |
1023 | return (changed > 0); |
1017 | return (changed > 0); |
1024 | } |
1018 | } |
1025 | |
1019 | |
… | |
… | |
1117 | |
1111 | |
1118 | #if XFT |
1112 | #if XFT |
1119 | static void |
1113 | static void |
1120 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1114 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1121 | { |
1115 | { |
1122 | double sigma = radius / 2.0; |
1116 | double sigma = radius / 2.0; |
1123 | double scale = sqrt (2.0 * M_PI) * sigma; |
1117 | double scale = sqrt (2.0 * M_PI) * sigma; |
1124 | double sum = 0.0; |
1118 | double sum = 0.0; |
1125 | |
1119 | |
1126 | for (int i = 0; i < width; i++) |
1120 | for (int i = 0; i < width; i++) |
1127 | { |
1121 | { |
1128 | double x = i - width / 2; |
1122 | double x = i - width / 2; |
1129 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
1123 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
1130 | sum += kernel[i]; |
1124 | sum += kernel[i]; |
1131 | } |
1125 | } |
1132 | |
1126 | |
1133 | params[0] = XDoubleToFixed (width); |
1127 | params[0] = XDoubleToFixed (width); |
1134 | params[1] = XDoubleToFixed (1); |
1128 | params[1] = XDoubleToFixed (1); |
1135 | |
1129 | |
1136 | for (int i = 0; i < width; i++) |
1130 | for (int i = 0; i < width; i++) |
1137 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1131 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1138 | } |
1132 | } |
1139 | #endif |
1133 | #endif |
1140 | |
1134 | |
1141 | bool |
1135 | bool |
1142 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1136 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
… | |
… | |
1147 | double *kernel = (double *)malloc (size * sizeof (double)); |
1141 | double *kernel = (double *)malloc (size * sizeof (double)); |
1148 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1142 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1149 | |
1143 | |
1150 | Display *dpy = target->dpy; |
1144 | Display *dpy = target->dpy; |
1151 | XRenderPictureAttributes pa; |
1145 | XRenderPictureAttributes pa; |
1152 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, target->visual); |
1146 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1153 | |
1147 | |
1154 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1148 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1155 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1149 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1156 | |
1150 | |
1157 | if (kernel && params && src && dst) |
1151 | if (kernel && params && src && dst) |
… | |
… | |
1283 | } |
1277 | } |
1284 | |
1278 | |
1285 | XRenderFreePicture (dpy, mask_pic); |
1279 | XRenderFreePicture (dpy, mask_pic); |
1286 | XRenderFreePicture (dpy, overlay_pic); |
1280 | XRenderFreePicture (dpy, overlay_pic); |
1287 | XRenderFreePicture (dpy, back_pic); |
1281 | XRenderFreePicture (dpy, back_pic); |
1288 | # if DO_TIMING_TEST |
|
|
1289 | XSync (dpy, False); |
|
|
1290 | # endif |
|
|
1291 | # endif |
1282 | # endif |
1292 | } |
1283 | } |
1293 | |
1284 | |
1294 | return ret; |
1285 | return ret; |
1295 | } |
1286 | } |
… | |
… | |
1320 | int window_height = target->szHint.height; |
1311 | int window_height = target->szHint.height; |
1321 | int sx, sy; |
1312 | int sx, sy; |
1322 | XGCValues gcv; |
1313 | XGCValues gcv; |
1323 | GC gc; |
1314 | GC gc; |
1324 | |
1315 | |
1325 | TIMING_TEST_START (tp); |
|
|
1326 | target->get_window_origin (sx, sy); |
1316 | target->get_window_origin (sx, sy); |
1327 | |
1317 | |
1328 | /* check if we are outside of the visible part of the virtual screen : */ |
1318 | /* check if we are outside of the visible part of the virtual screen : */ |
1329 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1319 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1330 | || sx >= root_width || sy >= root_height) |
1320 | || sx >= root_width || sy >= root_height) |
… | |
… | |
1367 | { |
1357 | { |
1368 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1358 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1369 | result |= transpPmapTiled; |
1359 | result |= transpPmapTiled; |
1370 | XFreeGC (dpy, gc); |
1360 | XFreeGC (dpy, gc); |
1371 | } |
1361 | } |
1372 | TIMING_TEST_PRINT_RESULT (tp); |
|
|
1373 | |
1362 | |
1374 | if (tiled_root_pmap != None) |
1363 | if (tiled_root_pmap != None) |
1375 | { |
1364 | { |
1376 | if (!need_client_side_rendering ()) |
1365 | if (!need_client_side_rendering ()) |
1377 | { |
1366 | { |
1378 | if (flags & (blurNeeded | blurServerSide)) |
1367 | if (flags & (blurNeeded | blurServerSide)) |
1379 | { |
1368 | { |
1380 | if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
1369 | if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) |
1381 | result |= transpPmapBlurred; |
1370 | result |= transpPmapBlurred; |
1382 | } |
1371 | } |
1383 | if (flags & (tintNeeded | tintServerSide)) |
1372 | if (flags & (tintNeeded | tintServerSide)) |
1384 | { |
1373 | { |
1385 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
1374 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) |
1386 | result |= transpPmapTinted; |
1375 | result |= transpPmapTinted; |
1387 | } |
1376 | } |
1388 | } /* server side rendering completed */ |
1377 | } /* server side rendering completed */ |
1389 | |
1378 | |
1390 | if (pixmap) |
1379 | if (pixmap) |
… | |
… | |
1394 | pmap_width = window_width; |
1383 | pmap_width = window_width; |
1395 | pmap_height = window_height; |
1384 | pmap_height = window_height; |
1396 | pmap_depth = root_depth; |
1385 | pmap_depth = root_depth; |
1397 | } |
1386 | } |
1398 | |
1387 | |
1399 | TIMING_TEST_PRINT_RESULT (tp); |
|
|
1400 | |
|
|
1401 | return result; |
1388 | return result; |
1402 | } |
1389 | } |
1403 | |
1390 | |
1404 | bool |
1391 | bool |
1405 | bgPixmap_t::set_root_pixmap () |
1392 | bgPixmap_t::set_root_pixmap () |
… | |
… | |
1417 | return false; |
1404 | return false; |
1418 | } |
1405 | } |
1419 | # endif /* ENABLE_TRANSPARENCY */ |
1406 | # endif /* ENABLE_TRANSPARENCY */ |
1420 | |
1407 | |
1421 | # ifndef HAVE_AFTERIMAGE |
1408 | # ifndef HAVE_AFTERIMAGE |
1422 | static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); |
1409 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); |
1423 | # endif |
1410 | # endif |
1424 | |
1411 | |
1425 | bool |
1412 | bool |
1426 | bgPixmap_t::render () |
1413 | bgPixmap_t::render () |
1427 | { |
1414 | { |
1428 | unsigned long background_flags = 0; |
1415 | unsigned long background_flags = 0; |
1429 | |
1416 | |
1430 | if (target == NULL) |
1417 | if (target == NULL) |
1431 | return false; |
1418 | return false; |
1432 | |
|
|
1433 | TIMING_TEST_START (tp); |
|
|
1434 | |
1419 | |
1435 | invalidate (); |
1420 | invalidate (); |
1436 | # ifdef ENABLE_TRANSPARENCY |
1421 | # ifdef ENABLE_TRANSPARENCY |
1437 | if (flags & isTransparent) |
1422 | if (flags & isTransparent) |
1438 | { |
1423 | { |
… | |
… | |
1471 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1456 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1472 | { |
1457 | { |
1473 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1458 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1474 | if (flags & tintSet) |
1459 | if (flags & tintSet) |
1475 | tint.get (c); |
1460 | tint.get (c); |
1476 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1461 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); |
1477 | } |
1462 | } |
1478 | # endif |
1463 | # endif |
1479 | |
1464 | |
1480 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1465 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1481 | |
1466 | |
… | |
… | |
1527 | } |
1512 | } |
1528 | } |
1513 | } |
1529 | |
1514 | |
1530 | apply (); |
1515 | apply (); |
1531 | |
1516 | |
1532 | XSync (target->dpy, False); |
|
|
1533 | valid_since = ev::now (); |
1517 | valid_since = ev::now (); |
1534 | |
|
|
1535 | TIMING_TEST_PRINT_RESULT (tp); |
|
|
1536 | |
1518 | |
1537 | return true; |
1519 | return true; |
1538 | } |
1520 | } |
1539 | |
1521 | |
1540 | bool |
1522 | bool |
… | |
… | |
1556 | void |
1538 | void |
1557 | bgPixmap_t::apply () |
1539 | bgPixmap_t::apply () |
1558 | { |
1540 | { |
1559 | if (target) |
1541 | if (target) |
1560 | { |
1542 | { |
1561 | flags &= ~isVtOrigin; |
|
|
1562 | |
|
|
1563 | if (pixmap != None) |
1543 | if (pixmap != None) |
1564 | { |
1544 | { |
1565 | /* set target's background to pixmap */ |
1545 | /* set target's background to pixmap */ |
1566 | # ifdef ENABLE_TRANSPARENCY |
1546 | # ifdef ENABLE_TRANSPARENCY |
1567 | if (flags & isTransparent) |
1547 | if (flags & isTransparent) |
… | |
… | |
1573 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1553 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1574 | } |
1554 | } |
1575 | else |
1555 | else |
1576 | # endif |
1556 | # endif |
1577 | { |
1557 | { |
1578 | flags |= isVtOrigin; |
|
|
1579 | /* force old pixmap dereference in case it was transparent before :*/ |
1558 | /* force old pixmap dereference in case it was transparent before :*/ |
1580 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1559 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1581 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1560 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1582 | /* do we also need to set scrollbar's background here ? */ |
1561 | /* do we also need to set scrollbar's background here ? */ |
1583 | |
1562 | |
… | |
… | |
1613 | #endif /* HAVE_BG_PIXMAP */ |
1592 | #endif /* HAVE_BG_PIXMAP */ |
1614 | |
1593 | |
1615 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT |
1594 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT |
1616 | /* taken from aterm-0.4.2 */ |
1595 | /* taken from aterm-0.4.2 */ |
1617 | |
1596 | |
1618 | typedef uint32_t RUINT32T; |
|
|
1619 | |
|
|
1620 | static void |
1597 | static void |
1621 | ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) |
1598 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1622 | { |
1599 | { |
1623 | int sh_r, sh_g, sh_b; |
1600 | int sh_r, sh_g, sh_b; |
1624 | RUINT32T mask_r, mask_g, mask_b; |
1601 | uint32_t mask_r, mask_g, mask_b; |
1625 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1602 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1626 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1603 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1627 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1604 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1628 | int i; |
1605 | int i; |
|
|
1606 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1629 | |
1607 | |
1630 | Visual *visual = term->visual; |
|
|
1631 | |
|
|
1632 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; |
1608 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1633 | |
1609 | |
1634 | /* for convenience */ |
1610 | /* for convenience */ |
1635 | mask_r = visual->red_mask; |
1611 | mask_r = visual->red_mask; |
1636 | mask_g = visual->green_mask; |
1612 | mask_g = visual->green_mask; |
1637 | mask_b = visual->blue_mask; |
1613 | mask_b = visual->blue_mask; |
1638 | |
1614 | |
1639 | /* boring lookup table pre-initialization */ |
1615 | /* boring lookup table pre-initialization */ |
1640 | switch (srcImage->bits_per_pixel) { |
1616 | switch (srcImage->depth) |
|
|
1617 | { |
1641 | case 15: |
1618 | case 15: |
1642 | if ((mask_r != 0x7c00) || |
1619 | if ((mask_r != 0x7c00) || |
1643 | (mask_g != 0x03e0) || |
1620 | (mask_g != 0x03e0) || |
1644 | (mask_b != 0x001f)) |
1621 | (mask_b != 0x001f)) |
1645 | return; |
1622 | return; |
1646 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); |
1623 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32)); |
1647 | lookup_r = lookup; |
1624 | lookup_r = lookup; |
1648 | lookup_g = lookup+32; |
1625 | lookup_g = lookup+32; |
1649 | lookup_b = lookup+32+32; |
1626 | lookup_b = lookup+32+32; |
1650 | sh_r = 10; |
1627 | sh_r = 10; |
1651 | sh_g = 5; |
1628 | sh_g = 5; |
1652 | sh_b = 0; |
1629 | sh_b = 0; |
1653 | break; |
1630 | break; |
1654 | case 16: |
1631 | case 16: |
1655 | if ((mask_r != 0xf800) || |
1632 | if ((mask_r != 0xf800) || |
1656 | (mask_g != 0x07e0) || |
1633 | (mask_g != 0x07e0) || |
1657 | (mask_b != 0x001f)) |
1634 | (mask_b != 0x001f)) |
1658 | return; |
1635 | return; |
1659 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); |
1636 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32)); |
1660 | lookup_r = lookup; |
1637 | lookup_r = lookup; |
1661 | lookup_g = lookup+32; |
1638 | lookup_g = lookup+32; |
1662 | lookup_b = lookup+32+64; |
1639 | lookup_b = lookup+32+64; |
1663 | sh_r = 11; |
1640 | sh_r = 11; |
1664 | sh_g = 5; |
1641 | sh_g = 5; |
1665 | sh_b = 0; |
1642 | sh_b = 0; |
1666 | break; |
1643 | break; |
1667 | case 24: |
1644 | case 24: |
1668 | if ((mask_r != 0xff0000) || |
1645 | if ((mask_r != 0xff0000) || |
1669 | (mask_g != 0x00ff00) || |
1646 | (mask_g != 0x00ff00) || |
1670 | (mask_b != 0x0000ff)) |
1647 | (mask_b != 0x0000ff)) |
1671 | return; |
1648 | return; |
1672 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
1649 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256)); |
1673 | lookup_r = lookup; |
1650 | lookup_r = lookup; |
1674 | lookup_g = lookup+256; |
1651 | lookup_g = lookup+256; |
1675 | lookup_b = lookup+256+256; |
1652 | lookup_b = lookup+256+256; |
1676 | sh_r = 16; |
1653 | sh_r = 16; |
1677 | sh_g = 8; |
1654 | sh_g = 8; |
1678 | sh_b = 0; |
1655 | sh_b = 0; |
1679 | break; |
1656 | break; |
1680 | case 32: |
1657 | case 32: |
1681 | if ((mask_r != 0xff0000) || |
1658 | if ((mask_r != 0xff0000) || |
1682 | (mask_g != 0x00ff00) || |
1659 | (mask_g != 0x00ff00) || |
1683 | (mask_b != 0x0000ff)) |
1660 | (mask_b != 0x0000ff)) |
1684 | return; |
1661 | return; |
1685 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
1662 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256)); |
1686 | lookup_r = lookup; |
1663 | lookup_r = lookup; |
1687 | lookup_g = lookup+256; |
1664 | lookup_g = lookup+256; |
1688 | lookup_b = lookup+256+256; |
1665 | lookup_b = lookup+256+256; |
1689 | sh_r = 16; |
1666 | sh_r = 16; |
1690 | sh_g = 8; |
1667 | sh_g = 8; |
1691 | sh_b = 0; |
1668 | sh_b = 0; |
1692 | break; |
1669 | break; |
1693 | default: |
1670 | default: |
1694 | return; /* we do not support this color depth */ |
1671 | return; /* we do not support this color depth */ |
1695 | } |
1672 | } |
1696 | |
1673 | |
1697 | /* prepare limits for color transformation (each channel is handled separately) */ |
1674 | /* prepare limits for color transformation (each channel is handled separately) */ |
1698 | if (shade > 100) { |
1675 | if (shade > 100) |
|
|
1676 | { |
1699 | shade = 200 - shade; |
1677 | shade = 200 - shade; |
1700 | |
1678 | |
1701 | lower_lim_r = 65535-rm; |
1679 | lower_lim_r = 65535-rm; |
1702 | lower_lim_g = 65535-gm; |
1680 | lower_lim_g = 65535-gm; |
1703 | lower_lim_b = 65535-bm; |
1681 | lower_lim_b = 65535-bm; |
1704 | |
1682 | |
1705 | lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); |
1683 | lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); |
1706 | lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); |
1684 | lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); |
1707 | lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); |
1685 | lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); |
1708 | |
1686 | |
1709 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
1687 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
|
|
1688 | } |
1710 | } else { |
1689 | else |
|
|
1690 | { |
1711 | |
1691 | |
1712 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1692 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1713 | |
1693 | |
1714 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
1694 | upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100); |
1715 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |
1695 | upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100); |
1716 | upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); |
1696 | upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100); |
1717 | } |
1697 | } |
1718 | |
|
|
1719 | /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */ |
|
|
1720 | if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 )) |
|
|
1721 | { |
|
|
1722 | unsigned int tmp; |
|
|
1723 | |
|
|
1724 | tmp = lower_lim_r; |
|
|
1725 | lower_lim_r = lower_lim_b; |
|
|
1726 | lower_lim_b = tmp; |
|
|
1727 | |
|
|
1728 | tmp = upper_lim_r; |
|
|
1729 | upper_lim_r = upper_lim_b; |
|
|
1730 | upper_lim_b = tmp; |
|
|
1731 | } |
|
|
1732 | |
1698 | |
1733 | /* fill our lookup tables */ |
1699 | /* fill our lookup tables */ |
1734 | for (i = 0; i <= mask_r>>sh_r; i++) |
1700 | for (i = 0; i <= mask_r>>sh_r; i++) |
1735 | { |
1701 | { |
1736 | RUINT32T tmp; |
1702 | uint32_t tmp; |
1737 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); |
1703 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); |
1738 | tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); |
1704 | tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); |
1739 | lookup_r[i] = (tmp/65535)<<sh_r; |
1705 | lookup_r[i] = (tmp/65535)<<sh_r; |
1740 | } |
1706 | } |
1741 | for (i = 0; i <= mask_g>>sh_g; i++) |
1707 | for (i = 0; i <= mask_g>>sh_g; i++) |
1742 | { |
1708 | { |
1743 | RUINT32T tmp; |
1709 | uint32_t tmp; |
1744 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); |
1710 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); |
1745 | tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); |
1711 | tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); |
1746 | lookup_g[i] = (tmp/65535)<<sh_g; |
1712 | lookup_g[i] = (tmp/65535)<<sh_g; |
1747 | } |
1713 | } |
1748 | for (i = 0; i <= mask_b>>sh_b; i++) |
1714 | for (i = 0; i <= mask_b>>sh_b; i++) |
1749 | { |
1715 | { |
1750 | RUINT32T tmp; |
1716 | uint32_t tmp; |
1751 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); |
1717 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); |
1752 | tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); |
1718 | tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); |
1753 | lookup_b[i] = (tmp/65535)<<sh_b; |
1719 | lookup_b[i] = (tmp/65535)<<sh_b; |
1754 | } |
1720 | } |
1755 | |
1721 | |
1756 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1722 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1757 | switch (srcImage->bits_per_pixel) |
1723 | if (srcImage->bits_per_pixel == 32 |
|
|
1724 | && (srcImage->depth == 24 || srcImage->depth == 32) |
|
|
1725 | && srcImage->byte_order == host_byte_order) |
1758 | { |
1726 | { |
1759 | case 15: |
|
|
1760 | { |
|
|
1761 | unsigned short *p1, *pf, *p, *pl; |
1727 | uint32_t *p1, *pf, *p, *pl; |
1762 | p1 = (unsigned short *) srcImage->data; |
1728 | p1 = (uint32_t *) srcImage->data; |
1763 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1729 | pf = (uint32_t *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1730 | |
1764 | while (p1 < pf) |
1731 | while (p1 < pf) |
1765 | { |
1732 | { |
1766 | p = p1; |
1733 | p = p1; |
1767 | pl = p1 + srcImage->width; |
1734 | pl = p1 + srcImage->width; |
1768 | for (; p < pl; p++) |
1735 | for (; p < pl; p++) |
1769 | { |
1736 | { |
1770 | *p = lookup_r[(*p & 0x7c00)>>10] | |
|
|
1771 | lookup_g[(*p & 0x03e0)>> 5] | |
|
|
1772 | lookup_b[(*p & 0x001f)]; |
|
|
1773 | } |
|
|
1774 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1775 | } |
|
|
1776 | break; |
|
|
1777 | } |
|
|
1778 | case 16: |
|
|
1779 | { |
|
|
1780 | unsigned short *p1, *pf, *p, *pl; |
|
|
1781 | p1 = (unsigned short *) srcImage->data; |
|
|
1782 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1783 | while (p1 < pf) |
|
|
1784 | { |
|
|
1785 | p = p1; |
|
|
1786 | pl = p1 + srcImage->width; |
|
|
1787 | for (; p < pl; p++) |
|
|
1788 | { |
|
|
1789 | *p = lookup_r[(*p & 0xf800)>>11] | |
|
|
1790 | lookup_g[(*p & 0x07e0)>> 5] | |
|
|
1791 | lookup_b[(*p & 0x001f)]; |
|
|
1792 | } |
|
|
1793 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1794 | } |
|
|
1795 | break; |
|
|
1796 | } |
|
|
1797 | case 24: |
|
|
1798 | { |
|
|
1799 | unsigned char *p1, *pf, *p, *pl; |
|
|
1800 | p1 = (unsigned char *) srcImage->data; |
|
|
1801 | pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1802 | while (p1 < pf) |
|
|
1803 | { |
|
|
1804 | p = p1; |
|
|
1805 | pl = p1 + srcImage->width * 3; |
|
|
1806 | for (; p < pl; p += 3) |
|
|
1807 | { |
|
|
1808 | p[0] = lookup_r[(p[0] & 0xff0000)>>16]; |
|
|
1809 | p[1] = lookup_r[(p[1] & 0x00ff00)>> 8]; |
|
|
1810 | p[2] = lookup_r[(p[2] & 0x0000ff)]; |
|
|
1811 | } |
|
|
1812 | p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1813 | } |
|
|
1814 | break; |
|
|
1815 | } |
|
|
1816 | case 32: |
|
|
1817 | { |
|
|
1818 | RUINT32T *p1, *pf, *p, *pl; |
|
|
1819 | p1 = (RUINT32T *) srcImage->data; |
|
|
1820 | pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1821 | |
|
|
1822 | while (p1 < pf) |
|
|
1823 | { |
|
|
1824 | p = p1; |
|
|
1825 | pl = p1 + srcImage->width; |
|
|
1826 | for (; p < pl; p++) |
|
|
1827 | { |
|
|
1828 | *p = lookup_r[(*p & 0xff0000)>>16] | |
1737 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1829 | lookup_g[(*p & 0x00ff00)>> 8] | |
1738 | lookup_g[(*p & 0x00ff00) >> 8] | |
1830 | lookup_b[(*p & 0x0000ff)] | |
1739 | lookup_b[(*p & 0x0000ff)] | |
1831 | (*p & ~0xffffff); |
1740 | (*p & 0xff000000); |
|
|
1741 | } |
|
|
1742 | p1 = (uint32_t *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1743 | } |
|
|
1744 | } |
|
|
1745 | else |
|
|
1746 | { |
|
|
1747 | for (int y = 0; y < srcImage->height; y++) |
|
|
1748 | for (int x = 0; x < srcImage->width; x++) |
|
|
1749 | { |
|
|
1750 | unsigned long pixel = XGetPixel (srcImage, x, y); |
|
|
1751 | pixel = lookup_r[(pixel & mask_r) >> sh_r] | |
|
|
1752 | lookup_g[(pixel & mask_g) >> sh_g] | |
|
|
1753 | lookup_b[(pixel & mask_b) >> sh_b]; |
|
|
1754 | XPutPixel (srcImage, x, y, pixel); |
1832 | } |
1755 | } |
1833 | p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1834 | } |
1756 | } |
1835 | break; |
|
|
1836 | } |
|
|
1837 | } |
|
|
1838 | |
1757 | |
1839 | free (lookup); |
1758 | free (lookup); |
1840 | } |
1759 | } |
1841 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |
1760 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |