[babl/daniel-tolerance-hacks: 8/14] Minimal float -> u8 conversions



commit 94f22f2a4f9dac6fc4754eaae8c199a54ce1385b
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Tue Jan 29 18:41:44 2013 -0800

    Minimal float -> u8 conversions
    
    Add some simplistic but "accurate" float -> u8 conversions to make
    the gamma lookup tables usable with cairo. The main difference
    from the existing conversions is that these clamp out of range
    values and make the path error checker happy.

 extensions/Makefile.am |    2 +
 extensions/expar.c     |   54 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index 220d18a..58465f3 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -17,6 +17,7 @@ extdir = $(libdir)/babl- BABL_API_VERSION@
 ext_LTLIBRARIES = \
 	cairo.la        \
 	CIE.la          \
+	expar.la        \
 	gegl-fixups.la  \
 	gggl-lies.la    \
 	gggl.la         \
@@ -29,6 +30,7 @@ ext_LTLIBRARIES = \
 
 cairo_la_SOURCES = cairo.c
 CIE_la_SOURCES = CIE.c
+expar_la_SOURCES = expar.c
 gegl_fixups_la_SOURCES = gegl-fixups.c
 gggl_lies_la_SOURCES = gggl-lies.c
 gggl_la_SOURCES = gggl.c
diff --git a/extensions/expar.c b/extensions/expar.c
new file mode 100644
index 0000000..f36febb
--- /dev/null
+++ b/extensions/expar.c
@@ -0,0 +1,54 @@
+#include <stdlib.h>
+#include "babl.h"
+
+int init (void);
+
+static inline long
+float_to_u8 (unsigned char *src_char, unsigned char *dst, long samples)
+{
+  float *src = (float *)src_char;
+  long n = samples * 4;
+  while (n--)
+    {
+      if (*src >= 1.0)
+      {
+        *dst++ = 0xFF;
+        src++;
+      }
+      else if (*src <= 0.0)
+      {
+        *dst++ = 0x0;
+        src++;
+      }
+      else
+        *dst++ = 0xFF * *src++ + 0.5;
+    }
+  return samples;
+}
+
+int
+init (void)
+{
+  babl_conversion_new (babl_format ("R'aG'aB'aA float"),
+                       babl_format ("R'aG'aB'aA u8"),
+                      "linear", 
+                       float_to_u8,
+                       NULL);
+  babl_conversion_new (babl_format ("R'G'B'A float"),
+                       babl_format ("R'G'B'A u8"),
+                      "linear", 
+                       float_to_u8,
+                       NULL);
+  babl_conversion_new (babl_format ("RGBA float"),
+                       babl_format ("RGBA u8"),
+                      "linear", 
+                       float_to_u8,
+                       NULL);
+  babl_conversion_new (babl_format ("RaGaBaA float"),
+                       babl_format ("RaGaBaA u8"),
+                      "linear", 
+                       float_to_u8,
+                       NULL);
+
+  return 0;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]