[babl] extensions/cairo: implement cairo display path from YA float
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] extensions/cairo: implement cairo display path from YA float
- Date: Fri, 16 Dec 2016 00:43:50 +0000 (UTC)
commit 0f02296c0771d1aa704da50ea1cb40fc5a61a2d0
Author: Øyvind Kolås <pippin gimp org>
Date: Fri Dec 16 01:43:34 2016 +0100
extensions/cairo: implement cairo display path from YA float
extensions/cairo.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/extensions/cairo.c b/extensions/cairo.c
index 457b938..5569ab6 100644
--- a/extensions/cairo.c
+++ b/extensions/cairo.c
@@ -287,6 +287,48 @@ conv_rgbafloat_cairo32_le (unsigned char *src,
return samples;
}
+
+static long
+conv_yafloat_cairo32_le (unsigned char *src,
+ unsigned char *dst,
+ long samples)
+{
+ float *fsrc = (float *) src;
+ unsigned char *cdst = (unsigned char *) dst;
+ int n = samples;
+
+ while (n--)
+ {
+ float gray = *fsrc++;
+ float alpha = *fsrc++;
+ if (alpha >= 1.0)
+ {
+ int val = babl_linear_to_gamma_2_2f (gray) * 0xff + 0.5f;
+ val = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ *cdst++ = val;
+ *cdst++ = val;
+ *cdst++ = val;
+ *cdst++ = 0xff;
+ }
+ else if (alpha <= 0.0)
+ {
+ (*(uint32_t*)cdst)=0;
+ cdst+=4;
+ }
+ else
+ {
+ float balpha = alpha * 0xff;
+ int val = babl_linear_to_gamma_2_2f (gray) * balpha + 0.5f;
+ val = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ *cdst++ = val;
+ *cdst++ = val;
+ *cdst++ = val;
+ *cdst++ = balpha + 0.5f;
+ }
+ }
+ return samples;
+}
+
int
init (void)
{
@@ -340,6 +382,8 @@ init (void)
babl_conversion_new (babl_format ("RGBA float"), f32, "linear",
conv_rgbafloat_cairo32_le, NULL);
+ babl_conversion_new (babl_format ("YA float"), f32, "linear",
+ conv_yafloat_cairo32_le, NULL);
babl_conversion_new (babl_format ("R'aG'aB'aA float"), f32, "linear",
conv_rgbA_gamma_float_cairo32_le, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]