[babl] extensions/gggl{,-lies}.c: fix a Fixme: (>>8 vs /255)
- From: Massimo Valentini <mvalentini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] extensions/gggl{,-lies}.c: fix a Fixme: (>>8 vs /255)
- Date: Sat, 14 Jul 2012 15:21:35 +0000 (UTC)
commit 0550e4016f904a5de43a194e6f5c735e7d894391
Author: Massimo Valentini <mvalentini src gnome org>
Date: Sat Jul 14 17:07:38 2012 +0200
extensions/gggl{,-lies}.c: fix a Fixme: (>>8 vs /255)
division per 0x100-1 is implemented using 1 term of (1 + x)^-1
MacLaurin expansion
(1+x)^-1 == 1 + (-1) x
a * (1 - 1/256)^-1 * (256^-1) == (a + a / 256) / 256
with integer division rounded toward the nearest.
extensions/gggl-lies.c | 7 ++++---
extensions/gggl.c | 7 ++++---
2 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/extensions/gggl-lies.c b/extensions/gggl-lies.c
index 849e3f4..d56a50e 100644
--- a/extensions/gggl-lies.c
+++ b/extensions/gggl-lies.c
@@ -1064,9 +1064,10 @@ conv_rgba8_rgbA8 (unsigned char *src, unsigned char *dst, long samples)
}
else
{
- dst[0] = (src[0] * src[3]) >> 8; /* FIXME: check if this faster */
- dst[1] = (src[1] * src[3]) >> 8; /* version (>>8 vs /255) */
- dst[2] = (src[2] * src[3]) >> 8; /* is accurate enough */
+#define div_255(a) ((((a)+127)+(((a)+127)>>8))>>8)
+ dst[0] = div_255 (src[0] * src[3]);
+ dst[1] = div_255 (src[1] * src[3]);
+ dst[2] = div_255 (src[2] * src[3]);
dst[3] = src[3];
}
dst += 4;
diff --git a/extensions/gggl.c b/extensions/gggl.c
index 10094ac..f1fb8c0 100644
--- a/extensions/gggl.c
+++ b/extensions/gggl.c
@@ -1035,9 +1035,10 @@ conv_rgba8_rgbA8 (unsigned char *src, unsigned char *dst, long samples)
}
else
{
- dst[0] = (src[0] * src[3]) >> 8; /* FIXME: check if this faster */
- dst[1] = (src[1] * src[3]) >> 8; /* version (>>8 vs /255) */
- dst[2] = (src[2] * src[3]) >> 8; /* is accurate enough */
+#define div_255(a) ((((a)+127)+(((a)+127)>>8))>>8)
+ dst[0] = div_255 (src[0] * src[3]);
+ dst[1] = div_255 (src[1] * src[3]);
+ dst[2] = div_255 (src[2] * src[3]);
dst[3] = src[3];
}
dst += 4;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]