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.83 by sf-exg, Thu Oct 14 17:39:42 2010 UTC vs.
Revision 1.97 by sf-exg, Fri Oct 22 18:03:10 2010 UTC

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
438void 436void
439bgPixmap_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)
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
1113 } 1107 }
1114 1108
1115 return false; 1109 return false;
1116} 1110}
1117 1111
1112#if XFT
1118static void 1113static void
1119get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) 1114get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
1120{ 1115{
1121 double sigma = radius / 2.0; 1116 double sigma = radius / 2.0;
1122 double scale = sqrt (2.0 * M_PI) * sigma; 1117 double scale = sqrt (2.0 * M_PI) * sigma;
1123 double sum = 0.0; 1118 double sum = 0.0;
1124 1119
1125 for (int i = 0; i < width; i++) 1120 for (int i = 0; i < width; i++)
1126 { 1121 {
1127 double x = i - width / 2; 1122 double x = i - width / 2;
1128 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; 1123 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale;
1129 sum += kernel[i]; 1124 sum += kernel[i];
1130 } 1125 }
1131 1126
1132 params[0] = XDoubleToFixed (width); 1127 params[0] = XDoubleToFixed (width);
1133 params[1] = XDoubleToFixed (1); 1128 params[1] = XDoubleToFixed (1);
1134 1129
1135 for (int i = 0; i < width; i++) 1130 for (int i = 0; i < width; i++)
1136 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1131 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1137} 1132}
1133#endif
1138 1134
1139bool 1135bool
1140bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1136bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1141{ 1137{
1142 bool ret = false; 1138 bool ret = false;
1145 double *kernel = (double *)malloc (size * sizeof (double)); 1141 double *kernel = (double *)malloc (size * sizeof (double));
1146 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1142 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1147 1143
1148 Display *dpy = target->dpy; 1144 Display *dpy = target->dpy;
1149 XRenderPictureAttributes pa; 1145 XRenderPictureAttributes pa;
1150 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, target->visual); 1146 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1151 1147
1152 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1148 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1153 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1149 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1154 1150
1155 if (kernel && params && src && dst) 1151 if (kernel && params && src && dst)
1281 } 1277 }
1282 1278
1283 XRenderFreePicture (dpy, mask_pic); 1279 XRenderFreePicture (dpy, mask_pic);
1284 XRenderFreePicture (dpy, overlay_pic); 1280 XRenderFreePicture (dpy, overlay_pic);
1285 XRenderFreePicture (dpy, back_pic); 1281 XRenderFreePicture (dpy, back_pic);
1286# if DO_TIMING_TEST
1287 XSync (dpy, False);
1288# endif
1289# endif 1282# endif
1290 } 1283 }
1291 1284
1292 return ret; 1285 return ret;
1293} 1286}
1318 int window_height = target->szHint.height; 1311 int window_height = target->szHint.height;
1319 int sx, sy; 1312 int sx, sy;
1320 XGCValues gcv; 1313 XGCValues gcv;
1321 GC gc; 1314 GC gc;
1322 1315
1323 TIMING_TEST_START (tp);
1324 target->get_window_origin (sx, sy); 1316 target->get_window_origin (sx, sy);
1325 1317
1326 /* 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 : */
1327 if (sx + window_width <= 0 || sy + window_height <= 0 1319 if (sx + window_width <= 0 || sy + window_height <= 0
1328 || sx >= root_width || sy >= root_height) 1320 || sx >= root_width || sy >= root_height)
1365 { 1357 {
1366 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);
1367 result |= transpPmapTiled; 1359 result |= transpPmapTiled;
1368 XFreeGC (dpy, gc); 1360 XFreeGC (dpy, gc);
1369 } 1361 }
1370 TIMING_TEST_PRINT_RESULT (tp);
1371 1362
1372 if (tiled_root_pmap != None) 1363 if (tiled_root_pmap != None)
1373 { 1364 {
1374 if (!need_client_side_rendering ()) 1365 if (!need_client_side_rendering ())
1375 { 1366 {
1376 if (flags & (blurNeeded | blurServerSide)) 1367 if (flags & (blurNeeded | blurServerSide))
1377 { 1368 {
1378 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))
1379 result |= transpPmapBlurred; 1370 result |= transpPmapBlurred;
1380 } 1371 }
1381 if (flags & (tintNeeded | tintServerSide)) 1372 if (flags & (tintNeeded | tintServerSide))
1382 { 1373 {
1383 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))
1384 result |= transpPmapTinted; 1375 result |= transpPmapTinted;
1385 } 1376 }
1386 } /* server side rendering completed */ 1377 } /* server side rendering completed */
1387 1378
1388 if (pixmap) 1379 if (pixmap)
1392 pmap_width = window_width; 1383 pmap_width = window_width;
1393 pmap_height = window_height; 1384 pmap_height = window_height;
1394 pmap_depth = root_depth; 1385 pmap_depth = root_depth;
1395 } 1386 }
1396 1387
1397 TIMING_TEST_PRINT_RESULT (tp);
1398
1399 return result; 1388 return result;
1400} 1389}
1401 1390
1402bool 1391bool
1403bgPixmap_t::set_root_pixmap () 1392bgPixmap_t::set_root_pixmap ()
1415 return false; 1404 return false;
1416} 1405}
1417# endif /* ENABLE_TRANSPARENCY */ 1406# endif /* ENABLE_TRANSPARENCY */
1418 1407
1419# ifndef HAVE_AFTERIMAGE 1408# ifndef HAVE_AFTERIMAGE
1420static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); 1409static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm);
1421# endif 1410# endif
1422 1411
1423bool 1412bool
1424bgPixmap_t::render () 1413bgPixmap_t::render ()
1425{ 1414{
1426 unsigned long background_flags = 0; 1415 unsigned long background_flags = 0;
1427 1416
1428 if (target == NULL) 1417 if (target == NULL)
1429 return false; 1418 return false;
1430
1431 TIMING_TEST_START (tp);
1432 1419
1433 invalidate (); 1420 invalidate ();
1434# ifdef ENABLE_TRANSPARENCY 1421# ifdef ENABLE_TRANSPARENCY
1435 if (flags & isTransparent) 1422 if (flags & isTransparent)
1436 { 1423 {
1469 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1456 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1470 { 1457 {
1471 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1458 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1472 if (flags & tintSet) 1459 if (flags & tintSet)
1473 tint.get (c); 1460 tint.get (c);
1474 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);
1475 } 1462 }
1476# endif 1463# endif
1477 1464
1478 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1465 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1479 1466
1525 } 1512 }
1526 } 1513 }
1527 1514
1528 apply (); 1515 apply ();
1529 1516
1530 XSync (target->dpy, False);
1531 valid_since = ev::now (); 1517 valid_since = ev::now ();
1532
1533 TIMING_TEST_PRINT_RESULT (tp);
1534 1518
1535 return true; 1519 return true;
1536} 1520}
1537 1521
1538bool 1522bool
1554void 1538void
1555bgPixmap_t::apply () 1539bgPixmap_t::apply ()
1556{ 1540{
1557 if (target) 1541 if (target)
1558 { 1542 {
1559 flags &= ~isVtOrigin;
1560
1561 if (pixmap != None) 1543 if (pixmap != None)
1562 { 1544 {
1563 /* set target's background to pixmap */ 1545 /* set target's background to pixmap */
1564# ifdef ENABLE_TRANSPARENCY 1546# ifdef ENABLE_TRANSPARENCY
1565 if (flags & isTransparent) 1547 if (flags & isTransparent)
1571 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1553 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1572 } 1554 }
1573 else 1555 else
1574# endif 1556# endif
1575 { 1557 {
1576 flags |= isVtOrigin;
1577 /* force old pixmap dereference in case it was transparent before :*/ 1558 /* force old pixmap dereference in case it was transparent before :*/
1578 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1559 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1579 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1560 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1580 /* do we also need to set scrollbar's background here ? */ 1561 /* do we also need to set scrollbar's background here ? */
1581 1562
1611#endif /* HAVE_BG_PIXMAP */ 1592#endif /* HAVE_BG_PIXMAP */
1612 1593
1613#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT 1594#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT
1614/* taken from aterm-0.4.2 */ 1595/* taken from aterm-0.4.2 */
1615 1596
1616typedef uint32_t RUINT32T;
1617
1618static void 1597static void
1619ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) 1598ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm)
1620{ 1599{
1621 int sh_r, sh_g, sh_b; 1600 int sh_r, sh_g, sh_b;
1622 RUINT32T mask_r, mask_g, mask_b; 1601 uint32_t mask_r, mask_g, mask_b;
1623 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 1602 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1624 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1603 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
1625 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1604 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
1626 int i; 1605 int i;
1606 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst;
1627 1607
1628 Visual *visual = term->visual;
1629
1630 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; 1608 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return;
1631 1609
1632 /* for convenience */ 1610 /* for convenience */
1633 mask_r = visual->red_mask; 1611 mask_r = visual->red_mask;
1634 mask_g = visual->green_mask; 1612 mask_g = visual->green_mask;
1635 mask_b = visual->blue_mask; 1613 mask_b = visual->blue_mask;
1636 1614
1637 /* boring lookup table pre-initialization */ 1615 /* boring lookup table pre-initialization */
1638 switch (srcImage->bits_per_pixel) { 1616 switch (srcImage->depth)
1617 {
1639 case 15: 1618 case 15:
1640 if ((mask_r != 0x7c00) || 1619 if ((mask_r != 0x7c00) ||
1641 (mask_g != 0x03e0) || 1620 (mask_g != 0x03e0) ||
1642 (mask_b != 0x001f)) 1621 (mask_b != 0x001f))
1643 return; 1622 return;
1644 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); 1623 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32));
1645 lookup_r = lookup; 1624 lookup_r = lookup;
1646 lookup_g = lookup+32; 1625 lookup_g = lookup+32;
1647 lookup_b = lookup+32+32; 1626 lookup_b = lookup+32+32;
1648 sh_r = 10; 1627 sh_r = 10;
1649 sh_g = 5; 1628 sh_g = 5;
1650 sh_b = 0; 1629 sh_b = 0;
1651 break; 1630 break;
1652 case 16: 1631 case 16:
1653 if ((mask_r != 0xf800) || 1632 if ((mask_r != 0xf800) ||
1654 (mask_g != 0x07e0) || 1633 (mask_g != 0x07e0) ||
1655 (mask_b != 0x001f)) 1634 (mask_b != 0x001f))
1656 return; 1635 return;
1657 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); 1636 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32));
1658 lookup_r = lookup; 1637 lookup_r = lookup;
1659 lookup_g = lookup+32; 1638 lookup_g = lookup+32;
1660 lookup_b = lookup+32+64; 1639 lookup_b = lookup+32+64;
1661 sh_r = 11; 1640 sh_r = 11;
1662 sh_g = 5; 1641 sh_g = 5;
1663 sh_b = 0; 1642 sh_b = 0;
1664 break; 1643 break;
1665 case 24: 1644 case 24:
1666 if ((mask_r != 0xff0000) || 1645 if ((mask_r != 0xff0000) ||
1667 (mask_g != 0x00ff00) || 1646 (mask_g != 0x00ff00) ||
1668 (mask_b != 0x0000ff)) 1647 (mask_b != 0x0000ff))
1669 return; 1648 return;
1670 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); 1649 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1671 lookup_r = lookup; 1650 lookup_r = lookup;
1672 lookup_g = lookup+256; 1651 lookup_g = lookup+256;
1673 lookup_b = lookup+256+256; 1652 lookup_b = lookup+256+256;
1674 sh_r = 16; 1653 sh_r = 16;
1675 sh_g = 8; 1654 sh_g = 8;
1676 sh_b = 0; 1655 sh_b = 0;
1677 break; 1656 break;
1678 case 32: 1657 case 32:
1679 if ((mask_r != 0xff0000) || 1658 if ((mask_r != 0xff0000) ||
1680 (mask_g != 0x00ff00) || 1659 (mask_g != 0x00ff00) ||
1681 (mask_b != 0x0000ff)) 1660 (mask_b != 0x0000ff))
1682 return; 1661 return;
1683 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); 1662 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1684 lookup_r = lookup; 1663 lookup_r = lookup;
1685 lookup_g = lookup+256; 1664 lookup_g = lookup+256;
1686 lookup_b = lookup+256+256; 1665 lookup_b = lookup+256+256;
1687 sh_r = 16; 1666 sh_r = 16;
1688 sh_g = 8; 1667 sh_g = 8;
1689 sh_b = 0; 1668 sh_b = 0;
1690 break; 1669 break;
1691 default: 1670 default:
1692 return; /* we do not support this color depth */ 1671 return; /* we do not support this color depth */
1693 } 1672 }
1694 1673
1695 /* prepare limits for color transformation (each channel is handled separately) */ 1674 /* prepare limits for color transformation (each channel is handled separately) */
1696 if (shade > 100) { 1675 if (shade > 100)
1676 {
1697 shade = 200 - shade; 1677 shade = 200 - shade;
1698 1678
1699 lower_lim_r = 65535-rm; 1679 lower_lim_r = 65535-rm;
1700 lower_lim_g = 65535-gm; 1680 lower_lim_g = 65535-gm;
1701 lower_lim_b = 65535-bm; 1681 lower_lim_b = 65535-bm;
1702 1682
1703 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);
1704 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);
1705 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);
1706 1686
1707 upper_lim_r = upper_lim_g = upper_lim_b = 65535; 1687 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1688 }
1708 } else { 1689 else
1690 {
1709 1691
1710 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1692 lower_lim_r = lower_lim_g = lower_lim_b = 0;
1711 1693
1712 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); 1694 upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100);
1713 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); 1695 upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100);
1714 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); 1696 upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100);
1715 } 1697 }
1716
1717 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
1718 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
1719 {
1720 unsigned int tmp;
1721
1722 tmp = lower_lim_r;
1723 lower_lim_r = lower_lim_b;
1724 lower_lim_b = tmp;
1725
1726 tmp = upper_lim_r;
1727 upper_lim_r = upper_lim_b;
1728 upper_lim_b = tmp;
1729 }
1730 1698
1731 /* fill our lookup tables */ 1699 /* fill our lookup tables */
1732 for (i = 0; i <= mask_r>>sh_r; i++) 1700 for (i = 0; i <= mask_r>>sh_r; i++)
1733 { 1701 {
1734 RUINT32T tmp; 1702 uint32_t tmp;
1735 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); 1703 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r));
1736 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); 1704 tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r);
1737 lookup_r[i] = (tmp/65535)<<sh_r; 1705 lookup_r[i] = (tmp/65535)<<sh_r;
1738 } 1706 }
1739 for (i = 0; i <= mask_g>>sh_g; i++) 1707 for (i = 0; i <= mask_g>>sh_g; i++)
1740 { 1708 {
1741 RUINT32T tmp; 1709 uint32_t tmp;
1742 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); 1710 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g));
1743 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); 1711 tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g);
1744 lookup_g[i] = (tmp/65535)<<sh_g; 1712 lookup_g[i] = (tmp/65535)<<sh_g;
1745 } 1713 }
1746 for (i = 0; i <= mask_b>>sh_b; i++) 1714 for (i = 0; i <= mask_b>>sh_b; i++)
1747 { 1715 {
1748 RUINT32T tmp; 1716 uint32_t tmp;
1749 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); 1717 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b));
1750 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); 1718 tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b);
1751 lookup_b[i] = (tmp/65535)<<sh_b; 1719 lookup_b[i] = (tmp/65535)<<sh_b;
1752 } 1720 }
1753 1721
1754 /* apply table to input image (replacing colors by newly calculated ones) */ 1722 /* apply table to input image (replacing colors by newly calculated ones) */
1755 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)
1756 { 1726 {
1757 case 15:
1758 {
1759 unsigned short *p1, *pf, *p, *pl; 1727 uint32_t *p1, *pf, *p, *pl;
1760 p1 = (unsigned short *) srcImage->data; 1728 p1 = (uint32_t *) srcImage->data;
1761 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); 1729 pf = (uint32_t *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1730
1762 while (p1 < pf) 1731 while (p1 < pf)
1763 { 1732 {
1764 p = p1; 1733 p = p1;
1765 pl = p1 + srcImage->width; 1734 pl = p1 + srcImage->width;
1766 for (; p < pl; p++) 1735 for (; p < pl; p++)
1767 { 1736 {
1768 *p = lookup_r[(*p & 0x7c00)>>10] |
1769 lookup_g[(*p & 0x03e0)>> 5] |
1770 lookup_b[(*p & 0x001f)];
1771 }
1772 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
1773 }
1774 break;
1775 }
1776 case 16:
1777 {
1778 unsigned short *p1, *pf, *p, *pl;
1779 p1 = (unsigned short *) srcImage->data;
1780 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1781 while (p1 < pf)
1782 {
1783 p = p1;
1784 pl = p1 + srcImage->width;
1785 for (; p < pl; p++)
1786 {
1787 *p = lookup_r[(*p & 0xf800)>>11] |
1788 lookup_g[(*p & 0x07e0)>> 5] |
1789 lookup_b[(*p & 0x001f)];
1790 }
1791 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
1792 }
1793 break;
1794 }
1795 case 24:
1796 {
1797 unsigned char *p1, *pf, *p, *pl;
1798 p1 = (unsigned char *) srcImage->data;
1799 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1800 while (p1 < pf)
1801 {
1802 p = p1;
1803 pl = p1 + srcImage->width * 3;
1804 for (; p < pl; p += 3)
1805 {
1806 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
1807 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
1808 p[2] = lookup_r[(p[2] & 0x0000ff)];
1809 }
1810 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
1811 }
1812 break;
1813 }
1814 case 32:
1815 {
1816 RUINT32T *p1, *pf, *p, *pl;
1817 p1 = (RUINT32T *) srcImage->data;
1818 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1819
1820 while (p1 < pf)
1821 {
1822 p = p1;
1823 pl = p1 + srcImage->width;
1824 for (; p < pl; p++)
1825 {
1826 *p = lookup_r[(*p & 0xff0000)>>16] | 1737 *p = lookup_r[(*p & 0xff0000) >> 16] |
1827 lookup_g[(*p & 0x00ff00)>> 8] | 1738 lookup_g[(*p & 0x00ff00) >> 8] |
1828 lookup_b[(*p & 0x0000ff)] | 1739 lookup_b[(*p & 0x0000ff)] |
1829 (*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);
1830 } 1755 }
1831 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
1832 } 1756 }
1833 break;
1834 }
1835 }
1836 1757
1837 free (lookup); 1758 free (lookup);
1838} 1759}
1839#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ 1760#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines