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.110 by sf-exg, Wed Nov 3 11:58:03 2010 UTC vs.
Revision 1.118 by sf-exg, Tue Nov 16 15:49:56 2010 UTC

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 29#if XRENDER
30# include <X11/extensions/Xrender.h> 30# include <X11/extensions/Xrender.h>
31#endif
32
33#ifndef FilterConvolution
34#define FilterConvolution "convolution"
31#endif 35#endif
32 36
33#define DO_TIMING_TEST 0 37#define DO_TIMING_TEST 0
34 38
35#if DO_TIMING_TEST 39#if DO_TIMING_TEST
172 return true; 176 return true;
173 } 177 }
174# endif 178# endif
175 179
176 return false; 180 return false;
177}; 181}
178 182
179bool bgPixmap_t::need_client_side_rendering () 183bool bgPixmap_t::need_client_side_rendering ()
180{ 184{
181# ifdef HAVE_AFTERIMAGE 185# ifdef HAVE_AFTERIMAGE
182 if (original_asim) 186 if (original_asim)
666 if (result) 670 if (result)
667 { 671 {
668 XGCValues gcv; 672 XGCValues gcv;
669 GC gc; 673 GC gc;
670 674
671 if (pixmap)
672 {
673 if (pmap_width != new_pmap_width
674 || pmap_height != new_pmap_height
675 || pmap_depth != target->depth)
676 {
677 XFreePixmap (target->dpy, pixmap);
678 pixmap = None;
679 }
680 }
681
682 /* create Pixmap */ 675 /* create Pixmap */
683 if (pixmap == None) 676 if (pixmap == None
677 || pmap_width != new_pmap_width
678 || pmap_height != new_pmap_height
679 || pmap_depth != target->depth)
684 { 680 {
681 if (pixmap)
682 XFreePixmap (target->dpy, pixmap);
685 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 683 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
686 pmap_width = new_pmap_width; 684 pmap_width = new_pmap_width;
687 pmap_height = new_pmap_height; 685 pmap_height = new_pmap_height;
688 pmap_depth = target->depth; 686 pmap_depth = target->depth;
689 } 687 }
797 new_pmap_width = min (image_width, target_width); 795 new_pmap_width = min (image_width, target_width);
798 new_pmap_height = min (image_height, target_height); 796 new_pmap_height = min (image_height, target_height);
799 } 797 }
800 } 798 }
801 799
802 if (pixmap)
803 {
804 if (pmap_width != new_pmap_width
805 || pmap_height != new_pmap_height
806 || pmap_depth != target->depth)
807 {
808 XFreePixmap (target->dpy, pixmap);
809 pixmap = None;
810 }
811 }
812
813 if (pixmap == None) 800 if (pixmap == None
801 || pmap_width != new_pmap_width
802 || pmap_height != new_pmap_height
803 || pmap_depth != target->depth)
814 { 804 {
805 if (pixmap)
806 XFreePixmap (target->dpy, pixmap);
815 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 807 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
816 pmap_width = new_pmap_width; 808 pmap_width = new_pmap_width;
817 pmap_height = new_pmap_height; 809 pmap_height = new_pmap_height;
818 pmap_depth = target->depth; 810 pmap_depth = target->depth;
819 } 811 }
1239 1231
1240 if (mask_pic && overlay_pic && back_pic) 1232 if (mask_pic && overlay_pic && back_pic)
1241 { 1233 {
1242 XRenderColor mask_c; 1234 XRenderColor mask_c;
1243 1235
1244 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); 1236 mask_c.red = mask_c.green = mask_c.blue = shade > 100 ? 0xffff : 0;
1245 mask_c.alpha = 0xffff; 1237 mask_c.alpha = 0xffff;
1246 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1238 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1247 1239
1248 mask_c.alpha = 0; 1240 mask_c.alpha = 0;
1249 mask_c.red = 0xffff - c.r; 1241 mask_c.red = 0xffff - c.r;
1367 if (gc) 1359 if (gc)
1368 { 1360 {
1369 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1361 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1370 result |= transpPmapTiled; 1362 result |= transpPmapTiled;
1371 XFreeGC (dpy, gc); 1363 XFreeGC (dpy, gc);
1372 }
1373 1364
1374 if (tiled_root_pmap != None)
1375 {
1376 if (!need_client_side_rendering ()) 1365 if (!need_client_side_rendering ())
1377 { 1366 {
1378 if ((flags & blurNeeded) 1367 if ((flags & blurNeeded)
1379 && (flags & HAS_RENDER_CONV)) 1368 && (flags & HAS_RENDER_CONV))
1380 { 1369 {
1395 pixmap = tiled_root_pmap; 1384 pixmap = tiled_root_pmap;
1396 pmap_width = window_width; 1385 pmap_width = window_width;
1397 pmap_height = window_height; 1386 pmap_height = window_height;
1398 pmap_depth = target->depth; 1387 pmap_depth = target->depth;
1399 } 1388 }
1389 else
1390 XFreePixmap (dpy, tiled_root_pmap);
1400 1391
1401 if (recoded_root_pmap != root_pixmap) 1392 if (recoded_root_pmap != root_pixmap)
1402 XFreePixmap (dpy, recoded_root_pmap); 1393 XFreePixmap (dpy, recoded_root_pmap);
1403 1394
1404 return result; 1395 return result;
1413 1404
1414 root_pixmap = new_root_pixmap; 1405 root_pixmap = new_root_pixmap;
1415} 1406}
1416# endif /* ENABLE_TRANSPARENCY */ 1407# endif /* ENABLE_TRANSPARENCY */
1417 1408
1418# ifndef HAVE_AFTERIMAGE 1409#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1419static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); 1410static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c);
1420# endif 1411# endif
1421 1412
1422bool 1413bool
1423bgPixmap_t::render () 1414bgPixmap_t::render ()
1424{ 1415{
1447 if (render_image (background_flags)) 1438 if (render_image (background_flags))
1448 flags = flags & ~isInvalid; 1439 flags = flags & ~isInvalid;
1449 } 1440 }
1450# endif 1441# endif
1451 1442
1443# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1452 XImage *result = NULL; 1444 XImage *result = NULL;
1453 1445
1454 if (background_flags && (flags & isInvalid)) 1446 if (background_flags && (flags & isInvalid))
1455 { 1447 {
1456 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1448 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1457 } 1449 }
1458 1450
1459 if (result) 1451 if (result)
1460 { 1452 {
1461# if !defined(HAVE_AFTERIMAGE) && !XRENDER
1462 /* our own client-side tinting */ 1453 /* our own client-side tinting */
1463 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1454 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1464 { 1455 {
1465 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1456 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1466 if (flags & tintSet) 1457 if (flags & tintSet)
1467 tint.get (c); 1458 tint.get (c);
1468 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); 1459 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c);
1469 } 1460 }
1470# endif
1471 1461
1472 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1462 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1473 1463
1474 if (gc) 1464 if (gc)
1475 { 1465 {
1479 flags = flags & ~isInvalid; 1469 flags = flags & ~isInvalid;
1480 } 1470 }
1481 1471
1482 XDestroyImage (result); 1472 XDestroyImage (result);
1483 } 1473 }
1474# endif
1484 1475
1485 if (flags & isInvalid) 1476 if (flags & isInvalid)
1486 { 1477 {
1487 if (pixmap != None) 1478 if (pixmap != None)
1488 { 1479 {
1574 flags |= hasChanged; 1565 flags |= hasChanged;
1575} 1566}
1576 1567
1577#endif /* HAVE_BG_PIXMAP */ 1568#endif /* HAVE_BG_PIXMAP */
1578 1569
1579#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER 1570#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1580/* taken from aterm-0.4.2 */ 1571/* taken from aterm-0.4.2 */
1581 1572
1582static void 1573static void
1583ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) 1574ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c)
1584{ 1575{
1585 int sh_r, sh_g, sh_b; 1576 int sh_r, sh_g, sh_b;
1586 uint32_t mask_r, mask_g, mask_b; 1577 uint32_t mask_r, mask_g, mask_b;
1587 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1578 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1588 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1579 rgba low;
1589 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1580 rgba high;
1590 int i; 1581 int i;
1591 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; 1582 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst;
1592 1583
1593 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; 1584 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return;
1594 1585
1659 /* prepare limits for color transformation (each channel is handled separately) */ 1650 /* prepare limits for color transformation (each channel is handled separately) */
1660 if (shade > 100) 1651 if (shade > 100)
1661 { 1652 {
1662 shade = 200 - shade; 1653 shade = 200 - shade;
1663 1654
1664 lower_lim_r = 65535-rm; 1655 high.r = (65535 - c.r) * shade / 100;
1665 lower_lim_g = 65535-gm; 1656 high.g = (65535 - c.g) * shade / 100;
1666 lower_lim_b = 65535-bm; 1657 high.b = (65535 - c.b) * shade / 100;
1667 1658
1668 lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); 1659 low.r = 65535 - high.r;
1669 lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); 1660 low.g = 65535 - high.g;
1670 lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); 1661 low.b = 65535 - high.b;
1671
1672 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1673 } 1662 }
1674 else 1663 else
1675 { 1664 {
1665 high.r = c.r * shade / 100;
1666 high.g = c.g * shade / 100;
1667 high.b = c.b * shade / 100;
1676 1668
1677 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1669 low.r = low.g = low.b = 0;
1678
1679 upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100);
1680 upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100);
1681 upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100);
1682 } 1670 }
1683 1671
1684 /* fill our lookup tables */ 1672 /* fill our lookup tables */
1685 for (i = 0; i <= mask_r>>sh_r; i++) 1673 for (i = 0; i <= mask_r>>sh_r; i++)
1686 { 1674 {
1687 uint32_t tmp; 1675 uint32_t tmp;
1688 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); 1676 tmp = i * high.r;
1689 tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); 1677 tmp += (mask_r>>sh_r) * low.r;
1690 lookup_r[i] = (tmp/65535)<<sh_r; 1678 lookup_r[i] = (tmp/65535)<<sh_r;
1691 } 1679 }
1692 for (i = 0; i <= mask_g>>sh_g; i++) 1680 for (i = 0; i <= mask_g>>sh_g; i++)
1693 { 1681 {
1694 uint32_t tmp; 1682 uint32_t tmp;
1695 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); 1683 tmp = i * high.g;
1696 tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); 1684 tmp += (mask_g>>sh_g) * low.g;
1697 lookup_g[i] = (tmp/65535)<<sh_g; 1685 lookup_g[i] = (tmp/65535)<<sh_g;
1698 } 1686 }
1699 for (i = 0; i <= mask_b>>sh_b; i++) 1687 for (i = 0; i <= mask_b>>sh_b; i++)
1700 { 1688 {
1701 uint32_t tmp; 1689 uint32_t tmp;
1702 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); 1690 tmp = i * high.b;
1703 tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); 1691 tmp += (mask_b>>sh_b) * low.b;
1704 lookup_b[i] = (tmp/65535)<<sh_b; 1692 lookup_b[i] = (tmp/65535)<<sh_b;
1705 } 1693 }
1706 1694
1707 /* apply table to input image (replacing colors by newly calculated ones) */ 1695 /* apply table to input image (replacing colors by newly calculated ones) */
1708 if (srcImage->bits_per_pixel == 32 1696 if (srcImage->bits_per_pixel == 32

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines