[babl] extensions/cairo: remove some arithmetic
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] extensions/cairo: remove some arithmetic
- Date: Thu, 17 Nov 2016 00:31:40 +0000 (UTC)
commit a036b789ec093dcdd98955bbde32739e965b55ec
Author: Øyvind Kolås <pippin gimp org>
Date: Wed Nov 16 23:11:15 2016 +0100
extensions/cairo: remove some arithmetic
extensions/cairo.c | 31 ++++++++++++++++++++++---------
1 files changed, 22 insertions(+), 9 deletions(-)
---
diff --git a/extensions/cairo.c b/extensions/cairo.c
index 331ec79..4e13337 100644
--- a/extensions/cairo.c
+++ b/extensions/cairo.c
@@ -102,13 +102,25 @@ static void init_table(void)
for (index = 0; index < 65536 * 1; index++)
{
float value = index / (65535 * 1.0);
- linear_to_gamma[index] = babl_linear_to_gamma_2_2 (value) * 65536 * 1;
+ linear_to_gamma[index] = babl_linear_to_gamma_2_2 (value) * 65536;
}
}
static inline unsigned char
-conv_rgbafloat_cairo32_map (float value,
- float alpha)
+conv_rgbafloat_cairo32_map (float value)
+{
+ unsigned int index;
+ if (value <= 0.0)
+ return 0x00;
+ if (value >= 1.0)
+ return 0xFF;
+ index = (unsigned int)(value * 65535);
+ return linear_to_gamma[index] / 257 + 0.5f;
+}
+
+static inline unsigned char
+conv_rgbafloat_cairo32_map_a (float value,
+ float alpha)
{
unsigned int index;
if (value <= 0.0)
@@ -119,6 +131,7 @@ conv_rgbafloat_cairo32_map (float value,
return linear_to_gamma[index] * alpha / 257 + 0.5f;
}
+
static long
conv_rgbafloat_cairo32_le (unsigned char *src_char,
unsigned char *dst,
@@ -137,16 +150,16 @@ conv_rgbafloat_cairo32_le (unsigned char *src_char,
{
if (src[3] >= 1.0)
{
- dst[0] = conv_rgbafloat_cairo32_map (src[2], 1.0f);
- dst[1] = conv_rgbafloat_cairo32_map (src[1], 1.0f);
- dst[2] = conv_rgbafloat_cairo32_map (src[0], 1.0f);
+ dst[0] = conv_rgbafloat_cairo32_map (src[2]);
+ dst[1] = conv_rgbafloat_cairo32_map (src[1]);
+ dst[2] = conv_rgbafloat_cairo32_map (src[0]);
dst[3] = 0xFF;
}
else
{
- dst[0] = conv_rgbafloat_cairo32_map (src[2], src[3]);
- dst[1] = conv_rgbafloat_cairo32_map (src[1], src[3]);
- dst[2] = conv_rgbafloat_cairo32_map (src[0], src[3]);
+ dst[0] = conv_rgbafloat_cairo32_map_a (src[2], src[3]);
+ dst[1] = conv_rgbafloat_cairo32_map_a (src[1], src[3]);
+ dst[2] = conv_rgbafloat_cairo32_map_a (src[0], src[3]);
dst[3] = src[3] * 0xFF + 0.5f;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]