ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.82 by sf-exg, Thu Oct 14 16:01:28 2010 UTC vs.
Revision 1.98 by sf-exg, Sat Oct 30 10:57:52 2010 UTC

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
195static inline bool 185static 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}
438 { 428 {
439 flags = new_flags; 429 flags = new_flags;
440 changed++; 430 changed++;
441 } 431 }
442 432
443 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
444 // flags, h_scale, v_scale, h_align, v_align);
445 return (changed > 0); 433 return (changed > 0);
446} 434}
447 435
448void 436void
449bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 437bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
478 x = make_align_position (h_align, target_width, w); 466 x = make_align_position (h_align, target_width, w);
479 y = make_align_position (v_align, target_height, h); 467 y = make_align_position (v_align, target_height, h);
480 } 468 }
481 469
482 flags &= ~sizeSensitive; 470 flags &= ~sizeSensitive;
483 if (h_scale != 0 || v_scale != 0 471 if ((flags & propScale) || h_scale || v_scale
484 || h_align != 0 || v_align != 0 472 || (!(flags & rootAlign) && (h_align || v_align))
485 || w > target_width || h > target_height) 473 || w > target_width || h > target_height)
486 flags |= sizeSensitive; 474 flags |= sizeSensitive;
487} 475}
488 476
489# ifdef HAVE_AFTERIMAGE 477# ifdef HAVE_AFTERIMAGE
539 527
540 int x = 0; 528 int x = 0;
541 int y = 0; 529 int y = 0;
542 int w = 0; 530 int w = 0;
543 int h = 0; 531 int h = 0;
544
545 TIMING_TEST_START (asim);
546 532
547 if (original_asim) 533 if (original_asim)
548 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);
549 535
550 if (!original_asim 536 if (!original_asim
667 } 653 }
668 654
669 free (layers); 655 free (layers);
670 } 656 }
671 } 657 }
672 TIMING_TEST_PRINT_RESULT (asim);
673 658
674 bool ret = false; 659 bool ret = false;
675 660
676 if (result) 661 if (result)
677 { 662 {
723 708
724 if (result != background && result != original_asim) 709 if (result != background && result != original_asim)
725 destroy_asimage (&result); 710 destroy_asimage (&result);
726 711
727 XFreeGC (target->dpy, gc); 712 XFreeGC (target->dpy, gc);
728 TIMING_TEST_PRINT_RESULT (asim);
729 713
730 ret = true; 714 ret = true;
731 } 715 }
732 716
733 if (background) 717 if (background)
1017 flags &= ~blurNeeded; 1001 flags &= ~blurNeeded;
1018 else 1002 else
1019 flags |= blurNeeded; 1003 flags |= blurNeeded;
1020 1004
1021#if XFT 1005#if XFT
1022 XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); 1006 XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root);
1023 if (filters) 1007 if (filters)
1024 { 1008 {
1025 for (int i = 0; i < filters->nfilter; i++) 1009 for (int i = 0; i < filters->nfilter; i++)
1026 if (!strcmp (filters->filter[i], FilterConvolution)) 1010 if (!strcmp (filters->filter[i], FilterConvolution))
1027 flags |= bgPixmap_t::blurServerSide; 1011 flags |= bgPixmap_t::blurServerSide;
1028 1012
1029 XFree (filters); 1013 XFree (filters);
1030 } 1014 }
1031#endif 1015#endif
1032 1016
1033 return (changed > 0); 1017 return (changed > 0);
1034} 1018}
1035 1019
1123 } 1107 }
1124 1108
1125 return false; 1109 return false;
1126} 1110}
1127 1111
1112#if XFT
1128static void 1113static void
1129get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) 1114get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
1130{ 1115{
1131 double sigma = radius / 2.0; 1116 double sigma = radius / 2.0;
1132 double scale = sqrt (2.0 * M_PI) * sigma; 1117 double scale = sqrt (2.0 * M_PI) * sigma;
1133 double sum = 0.0; 1118 double sum = 0.0;
1134 1119
1135 for (int i = 0; i < width; i++) 1120 for (int i = 0; i < width; i++)
1136 { 1121 {
1137 double x = i - width / 2; 1122 double x = i - width / 2;
1138 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; 1123 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale;
1139 sum += kernel[i]; 1124 sum += kernel[i];
1140 } 1125 }
1141 1126
1142 params[0] = XDoubleToFixed (width); 1127 params[0] = XDoubleToFixed (width);
1143 params[1] = XDoubleToFixed (1); 1128 params[1] = XDoubleToFixed (1);
1144 1129
1145 for (int i = 0; i < width; i++) 1130 for (int i = 0; i < width; i++)
1146 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1131 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1147} 1132}
1133#endif
1148 1134
1149bool 1135bool
1150bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1136bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1151{ 1137{
1152 bool ret = false; 1138 bool ret = false;
1155 double *kernel = (double *)malloc (size * sizeof (double)); 1141 double *kernel = (double *)malloc (size * sizeof (double));
1156 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1142 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1157 1143
1158 Display *dpy = target->dpy; 1144 Display *dpy = target->dpy;
1159 XRenderPictureAttributes pa; 1145 XRenderPictureAttributes pa;
1160 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, target->visual); 1146 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1161 1147
1162 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1148 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1163 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1149 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1164 1150
1165 if (kernel && params && src && dst) 1151 if (kernel && params && src && dst)
1291 } 1277 }
1292 1278
1293 XRenderFreePicture (dpy, mask_pic); 1279 XRenderFreePicture (dpy, mask_pic);
1294 XRenderFreePicture (dpy, overlay_pic); 1280 XRenderFreePicture (dpy, overlay_pic);
1295 XRenderFreePicture (dpy, back_pic); 1281 XRenderFreePicture (dpy, back_pic);
1296# if DO_TIMING_TEST
1297 XSync (dpy, False);
1298# endif
1299# endif 1282# endif
1300 } 1283 }
1301 1284
1302 return ret; 1285 return ret;
1303} 1286}
1328 int window_height = target->szHint.height; 1311 int window_height = target->szHint.height;
1329 int sx, sy; 1312 int sx, sy;
1330 XGCValues gcv; 1313 XGCValues gcv;
1331 GC gc; 1314 GC gc;
1332 1315
1333 TIMING_TEST_START (tp);
1334 target->get_window_origin (sx, sy); 1316 target->get_window_origin (sx, sy);
1335 1317
1336 /* 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 : */
1337 if (sx + window_width <= 0 || sy + window_height <= 0 1319 if (sx + window_width <= 0 || sy + window_height <= 0
1338 || sx >= root_width || sy >= root_height) 1320 || sx >= root_width || sy >= root_height)
1375 { 1357 {
1376 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);
1377 result |= transpPmapTiled; 1359 result |= transpPmapTiled;
1378 XFreeGC (dpy, gc); 1360 XFreeGC (dpy, gc);
1379 } 1361 }
1380 TIMING_TEST_PRINT_RESULT (tp);
1381 1362
1382 if (tiled_root_pmap != None) 1363 if (tiled_root_pmap != None)
1383 { 1364 {
1384 if (!need_client_side_rendering ()) 1365 if (!need_client_side_rendering ())
1385 { 1366 {
1386 if ((flags & blurNeeded)) 1367 if (flags & (blurNeeded | blurServerSide))
1387 { 1368 {
1388 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))
1389 result |= transpPmapBlurred; 1370 result |= transpPmapBlurred;
1390 } 1371 }
1391 if ((flags & tintNeeded)) 1372 if (flags & (tintNeeded | tintServerSide))
1392 { 1373 {
1393 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))
1394 result |= transpPmapTinted; 1375 result |= transpPmapTinted;
1395 } 1376 }
1396 } /* server side rendering completed */ 1377 } /* server side rendering completed */
1397 1378
1398 if (pixmap) 1379 if (pixmap)
1402 pmap_width = window_width; 1383 pmap_width = window_width;
1403 pmap_height = window_height; 1384 pmap_height = window_height;
1404 pmap_depth = root_depth; 1385 pmap_depth = root_depth;
1405 } 1386 }
1406 1387
1407 TIMING_TEST_PRINT_RESULT (tp);
1408
1409 return result; 1388 return result;
1410} 1389}
1411 1390
1412bool 1391void
1413bgPixmap_t::set_root_pixmap () 1392bgPixmap_t::set_root_pixmap ()
1414{ 1393{
1415 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1394 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1416 if (new_root_pixmap == None) 1395 if (new_root_pixmap == None)
1417 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1396 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1418 1397
1419 if (new_root_pixmap != root_pixmap)
1420 {
1421 root_pixmap = new_root_pixmap; 1398 root_pixmap = new_root_pixmap;
1422 return true;
1423 }
1424
1425 return false;
1426} 1399}
1427# endif /* ENABLE_TRANSPARENCY */ 1400# endif /* ENABLE_TRANSPARENCY */
1428 1401
1429# ifndef HAVE_AFTERIMAGE 1402# ifndef HAVE_AFTERIMAGE
1430static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); 1403static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm);
1431# endif 1404# endif
1432 1405
1433bool 1406bool
1434bgPixmap_t::render () 1407bgPixmap_t::render ()
1435{ 1408{
1436 unsigned long background_flags = 0; 1409 unsigned long background_flags = 0;
1437 1410
1438 if (target == NULL) 1411 if (target == NULL)
1439 return false; 1412 return false;
1440
1441 TIMING_TEST_START (tp);
1442 1413
1443 invalidate (); 1414 invalidate ();
1444# ifdef ENABLE_TRANSPARENCY 1415# ifdef ENABLE_TRANSPARENCY
1445 if (flags & isTransparent) 1416 if (flags & isTransparent)
1446 { 1417 {
1479 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1450 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1480 { 1451 {
1481 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1452 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1482 if (flags & tintSet) 1453 if (flags & tintSet)
1483 tint.get (c); 1454 tint.get (c);
1484 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1455 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b);
1485 } 1456 }
1486# endif 1457# endif
1487 1458
1488 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1459 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1489 1460
1535 } 1506 }
1536 } 1507 }
1537 1508
1538 apply (); 1509 apply ();
1539 1510
1540 XSync (target->dpy, False);
1541 valid_since = ev::now (); 1511 valid_since = ev::now ();
1542
1543 TIMING_TEST_PRINT_RESULT (tp);
1544 1512
1545 return true; 1513 return true;
1546} 1514}
1547 1515
1548bool 1516bool
1564void 1532void
1565bgPixmap_t::apply () 1533bgPixmap_t::apply ()
1566{ 1534{
1567 if (target) 1535 if (target)
1568 { 1536 {
1569 flags &= ~isVtOrigin;
1570
1571 if (pixmap != None) 1537 if (pixmap != None)
1572 { 1538 {
1573 /* set target's background to pixmap */ 1539 /* set target's background to pixmap */
1574# ifdef ENABLE_TRANSPARENCY 1540# ifdef ENABLE_TRANSPARENCY
1575 if (flags & isTransparent) 1541 if (flags & isTransparent)
1581 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1547 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1582 } 1548 }
1583 else 1549 else
1584# endif 1550# endif
1585 { 1551 {
1586 flags |= isVtOrigin;
1587 /* force old pixmap dereference in case it was transparent before :*/ 1552 /* force old pixmap dereference in case it was transparent before :*/
1588 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1553 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1589 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1554 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1590 /* do we also need to set scrollbar's background here ? */ 1555 /* do we also need to set scrollbar's background here ? */
1591 1556
1621#endif /* HAVE_BG_PIXMAP */ 1586#endif /* HAVE_BG_PIXMAP */
1622 1587
1623#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT 1588#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT
1624/* taken from aterm-0.4.2 */ 1589/* taken from aterm-0.4.2 */
1625 1590
1626typedef uint32_t RUINT32T;
1627
1628static void 1591static void
1629ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) 1592ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm)
1630{ 1593{
1631 int sh_r, sh_g, sh_b; 1594 int sh_r, sh_g, sh_b;
1632 RUINT32T mask_r, mask_g, mask_b; 1595 uint32_t mask_r, mask_g, mask_b;
1633 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 1596 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1634 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1597 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
1635 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1598 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
1636 int i; 1599 int i;
1600 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst;
1637 1601
1638 Visual *visual = term->visual;
1639
1640 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; 1602 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return;
1641 1603
1642 /* for convenience */ 1604 /* for convenience */
1643 mask_r = visual->red_mask; 1605 mask_r = visual->red_mask;
1644 mask_g = visual->green_mask; 1606 mask_g = visual->green_mask;
1645 mask_b = visual->blue_mask; 1607 mask_b = visual->blue_mask;
1646 1608
1647 /* boring lookup table pre-initialization */ 1609 /* boring lookup table pre-initialization */
1648 switch (srcImage->bits_per_pixel) { 1610 switch (srcImage->depth)
1611 {
1649 case 15: 1612 case 15:
1650 if ((mask_r != 0x7c00) || 1613 if ((mask_r != 0x7c00) ||
1651 (mask_g != 0x03e0) || 1614 (mask_g != 0x03e0) ||
1652 (mask_b != 0x001f)) 1615 (mask_b != 0x001f))
1653 return; 1616 return;
1654 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); 1617 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32));
1655 lookup_r = lookup; 1618 lookup_r = lookup;
1656 lookup_g = lookup+32; 1619 lookup_g = lookup+32;
1657 lookup_b = lookup+32+32; 1620 lookup_b = lookup+32+32;
1658 sh_r = 10; 1621 sh_r = 10;
1659 sh_g = 5; 1622 sh_g = 5;
1660 sh_b = 0; 1623 sh_b = 0;
1661 break; 1624 break;
1662 case 16: 1625 case 16:
1663 if ((mask_r != 0xf800) || 1626 if ((mask_r != 0xf800) ||
1664 (mask_g != 0x07e0) || 1627 (mask_g != 0x07e0) ||
1665 (mask_b != 0x001f)) 1628 (mask_b != 0x001f))
1666 return; 1629 return;
1667 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); 1630 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32));
1668 lookup_r = lookup; 1631 lookup_r = lookup;
1669 lookup_g = lookup+32; 1632 lookup_g = lookup+32;
1670 lookup_b = lookup+32+64; 1633 lookup_b = lookup+32+64;
1671 sh_r = 11; 1634 sh_r = 11;
1672 sh_g = 5; 1635 sh_g = 5;
1673 sh_b = 0; 1636 sh_b = 0;
1674 break; 1637 break;
1675 case 24: 1638 case 24:
1676 if ((mask_r != 0xff0000) || 1639 if ((mask_r != 0xff0000) ||
1677 (mask_g != 0x00ff00) || 1640 (mask_g != 0x00ff00) ||
1678 (mask_b != 0x0000ff)) 1641 (mask_b != 0x0000ff))
1679 return; 1642 return;
1680 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); 1643 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1681 lookup_r = lookup; 1644 lookup_r = lookup;
1682 lookup_g = lookup+256; 1645 lookup_g = lookup+256;
1683 lookup_b = lookup+256+256; 1646 lookup_b = lookup+256+256;
1684 sh_r = 16; 1647 sh_r = 16;
1685 sh_g = 8; 1648 sh_g = 8;
1686 sh_b = 0; 1649 sh_b = 0;
1687 break; 1650 break;
1688 case 32: 1651 case 32:
1689 if ((mask_r != 0xff0000) || 1652 if ((mask_r != 0xff0000) ||
1690 (mask_g != 0x00ff00) || 1653 (mask_g != 0x00ff00) ||
1691 (mask_b != 0x0000ff)) 1654 (mask_b != 0x0000ff))
1692 return; 1655 return;
1693 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); 1656 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1694 lookup_r = lookup; 1657 lookup_r = lookup;
1695 lookup_g = lookup+256; 1658 lookup_g = lookup+256;
1696 lookup_b = lookup+256+256; 1659 lookup_b = lookup+256+256;
1697 sh_r = 16; 1660 sh_r = 16;
1698 sh_g = 8; 1661 sh_g = 8;
1699 sh_b = 0; 1662 sh_b = 0;
1700 break; 1663 break;
1701 default: 1664 default:
1702 return; /* we do not support this color depth */ 1665 return; /* we do not support this color depth */
1703 } 1666 }
1704 1667
1705 /* prepare limits for color transformation (each channel is handled separately) */ 1668 /* prepare limits for color transformation (each channel is handled separately) */
1706 if (shade > 100) { 1669 if (shade > 100)
1670 {
1707 shade = 200 - shade; 1671 shade = 200 - shade;
1708 1672
1709 lower_lim_r = 65535-rm; 1673 lower_lim_r = 65535-rm;
1710 lower_lim_g = 65535-gm; 1674 lower_lim_g = 65535-gm;
1711 lower_lim_b = 65535-bm; 1675 lower_lim_b = 65535-bm;
1712 1676
1713 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); 1677 lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100);
1714 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); 1678 lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100);
1715 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); 1679 lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100);
1716 1680
1717 upper_lim_r = upper_lim_g = upper_lim_b = 65535; 1681 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1682 }
1718 } else { 1683 else
1684 {
1719 1685
1720 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1686 lower_lim_r = lower_lim_g = lower_lim_b = 0;
1721 1687
1722 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); 1688 upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100);
1723 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); 1689 upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100);
1724 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); 1690 upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100);
1725 } 1691 }
1726
1727 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
1728 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
1729 {
1730 unsigned int tmp;
1731
1732 tmp = lower_lim_r;
1733 lower_lim_r = lower_lim_b;
1734 lower_lim_b = tmp;
1735
1736 tmp = upper_lim_r;
1737 upper_lim_r = upper_lim_b;
1738 upper_lim_b = tmp;
1739 }
1740 1692
1741 /* fill our lookup tables */ 1693 /* fill our lookup tables */
1742 for (i = 0; i <= mask_r>>sh_r; i++) 1694 for (i = 0; i <= mask_r>>sh_r; i++)
1743 { 1695 {
1744 RUINT32T tmp; 1696 uint32_t tmp;
1745 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); 1697 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r));
1746 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); 1698 tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r);
1747 lookup_r[i] = (tmp/65535)<<sh_r; 1699 lookup_r[i] = (tmp/65535)<<sh_r;
1748 } 1700 }
1749 for (i = 0; i <= mask_g>>sh_g; i++) 1701 for (i = 0; i <= mask_g>>sh_g; i++)
1750 { 1702 {
1751 RUINT32T tmp; 1703 uint32_t tmp;
1752 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); 1704 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g));
1753 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); 1705 tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g);
1754 lookup_g[i] = (tmp/65535)<<sh_g; 1706 lookup_g[i] = (tmp/65535)<<sh_g;
1755 } 1707 }
1756 for (i = 0; i <= mask_b>>sh_b; i++) 1708 for (i = 0; i <= mask_b>>sh_b; i++)
1757 { 1709 {
1758 RUINT32T tmp; 1710 uint32_t tmp;
1759 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); 1711 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b));
1760 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); 1712 tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b);
1761 lookup_b[i] = (tmp/65535)<<sh_b; 1713 lookup_b[i] = (tmp/65535)<<sh_b;
1762 } 1714 }
1763 1715
1764 /* apply table to input image (replacing colors by newly calculated ones) */ 1716 /* apply table to input image (replacing colors by newly calculated ones) */
1765 switch (srcImage->bits_per_pixel) 1717 if (srcImage->bits_per_pixel == 32
1718 && (srcImage->depth == 24 || srcImage->depth == 32)
1719 && srcImage->byte_order == host_byte_order)
1766 { 1720 {
1767 case 15:
1768 {
1769 unsigned short *p1, *pf, *p, *pl; 1721 uint32_t *p1, *pf, *p, *pl;
1770 p1 = (unsigned short *) srcImage->data; 1722 p1 = (uint32_t *) srcImage->data;
1771 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); 1723 pf = (uint32_t *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1724
1772 while (p1 < pf) 1725 while (p1 < pf)
1773 { 1726 {
1774 p = p1; 1727 p = p1;
1775 pl = p1 + srcImage->width; 1728 pl = p1 + srcImage->width;
1776 for (; p < pl; p++) 1729 for (; p < pl; p++)
1777 { 1730 {
1778 *p = lookup_r[(*p & 0x7c00)>>10] |
1779 lookup_g[(*p & 0x03e0)>> 5] |
1780 lookup_b[(*p & 0x001f)];
1781 }
1782 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
1783 }
1784 break;
1785 }
1786 case 16:
1787 {
1788 unsigned short *p1, *pf, *p, *pl;
1789 p1 = (unsigned short *) srcImage->data;
1790 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1791 while (p1 < pf)
1792 {
1793 p = p1;
1794 pl = p1 + srcImage->width;
1795 for (; p < pl; p++)
1796 {
1797 *p = lookup_r[(*p & 0xf800)>>11] |
1798 lookup_g[(*p & 0x07e0)>> 5] |
1799 lookup_b[(*p & 0x001f)];
1800 }
1801 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
1802 }
1803 break;
1804 }
1805 case 24:
1806 {
1807 unsigned char *p1, *pf, *p, *pl;
1808 p1 = (unsigned char *) srcImage->data;
1809 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1810 while (p1 < pf)
1811 {
1812 p = p1;
1813 pl = p1 + srcImage->width * 3;
1814 for (; p < pl; p += 3)
1815 {
1816 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
1817 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
1818 p[2] = lookup_r[(p[2] & 0x0000ff)];
1819 }
1820 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
1821 }
1822 break;
1823 }
1824 case 32:
1825 {
1826 RUINT32T *p1, *pf, *p, *pl;
1827 p1 = (RUINT32T *) srcImage->data;
1828 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1829
1830 while (p1 < pf)
1831 {
1832 p = p1;
1833 pl = p1 + srcImage->width;
1834 for (; p < pl; p++)
1835 {
1836 *p = lookup_r[(*p & 0xff0000)>>16] | 1731 *p = lookup_r[(*p & 0xff0000) >> 16] |
1837 lookup_g[(*p & 0x00ff00)>> 8] | 1732 lookup_g[(*p & 0x00ff00) >> 8] |
1838 lookup_b[(*p & 0x0000ff)] | 1733 lookup_b[(*p & 0x0000ff)] |
1839 (*p & ~0xffffff); 1734 (*p & 0xff000000);
1735 }
1736 p1 = (uint32_t *) ((char *) p1 + srcImage->bytes_per_line);
1737 }
1738 }
1739 else
1740 {
1741 for (int y = 0; y < srcImage->height; y++)
1742 for (int x = 0; x < srcImage->width; x++)
1743 {
1744 unsigned long pixel = XGetPixel (srcImage, x, y);
1745 pixel = lookup_r[(pixel & mask_r) >> sh_r] |
1746 lookup_g[(pixel & mask_g) >> sh_g] |
1747 lookup_b[(pixel & mask_b) >> sh_b];
1748 XPutPixel (srcImage, x, y, pixel);
1840 } 1749 }
1841 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
1842 } 1750 }
1843 break;
1844 }
1845 }
1846 1751
1847 free (lookup); 1752 free (lookup);
1848} 1753}
1849#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ 1754#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines