[babl/daniel-tolerance-hacks: 9/14] Add float -> u16 conversions to expar



commit 04d28aeb7982144f82ba267b21902f4ba6d0f355
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Wed Jan 30 18:17:40 2013 -0800

    Add float -> u16 conversions to expar

 extensions/expar.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/extensions/expar.c b/extensions/expar.c
index f36febb..5abc0a4 100644
--- a/extensions/expar.c
+++ b/extensions/expar.c
@@ -1,4 +1,5 @@
 #include <stdlib.h>
+#include <stdint.h>
 #include "babl.h"
 
 int init (void);
@@ -26,6 +27,30 @@ float_to_u8 (unsigned char *src_char, unsigned char *dst, long samples)
   return samples;
 }
 
+static inline long
+float_to_u16 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+  float *src    = (float *)src_char;
+  uint16_t *dst = (uint16_t *)dst_char;
+  long n = samples * 4;
+  while (n--)
+    {
+      if (*src >= 1.0)
+      {
+        *dst++ = 0xFFFF;
+        src++;
+      }
+      else if (*src <= 0.0)
+      {
+        *dst++ = 0x0;
+        src++;
+      }
+      else
+        *dst++ = 0xFFFF * *src++ + 0.5;
+    }
+  return samples;
+}
+
 int
 init (void)
 {
@@ -49,6 +74,27 @@ init (void)
                       "linear", 
                        float_to_u8,
                        NULL);
+                       
+  babl_conversion_new (babl_format ("R'aG'aB'aA float"),
+                       babl_format ("R'aG'aB'aA u16"),
+                      "linear", 
+                       float_to_u16,
+                       NULL);
+  babl_conversion_new (babl_format ("R'G'B'A float"),
+                       babl_format ("R'G'B'A u16"),
+                      "linear", 
+                       float_to_u16,
+                       NULL);
+  babl_conversion_new (babl_format ("RGBA float"),
+                       babl_format ("RGBA u16"),
+                      "linear", 
+                       float_to_u16,
+                       NULL);
+  babl_conversion_new (babl_format ("RaGaBaA float"),
+                       babl_format ("RaGaBaA u16"),
+                      "linear", 
+                       float_to_u16,
+                       NULL);
 
   return 0;
 }


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