[babl] cairo: add code path from Y'A float



commit 88ad0ad42cb0620deb9f6c91e79dd071a0aaab2e
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu Aug 22 22:11:20 2019 +0200

    cairo: add code path from Y'A float

 extensions/cairo.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
---
diff --git a/extensions/cairo.c b/extensions/cairo.c
index d1ccfb512..08ccf6780 100644
--- a/extensions/cairo.c
+++ b/extensions/cairo.c
@@ -514,6 +514,49 @@ conv_yafloat_cairo32_le (const Babl    *conversion,
     }
 }
 
+
+static void
+conv_yafloat_nl_cairo32_le (const Babl    *conversion,
+                            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 = 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 = gray * balpha + 0.5f;
+        val = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+        *cdst++ = val;
+        *cdst++ = val;
+        *cdst++ = val;
+        *cdst++ = balpha + 0.5f;
+      }
+    }
+}
+
+
 int
 init (void)
 {
@@ -588,6 +631,8 @@ init (void)
                            conv_rgbafloat_cairo32_le, NULL);
       babl_conversion_new (babl_format ("YA float"), f32, "linear",
                            conv_yafloat_cairo32_le, NULL);
+      babl_conversion_new (babl_format ("Y'A float"), f32, "linear",
+                           conv_yafloat_nl_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]