[babl/daniel-tolerance-hacks] Add some float<->int16 conversions.
- From: Daniel Sabo <daniels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl/daniel-tolerance-hacks] Add some float<->int16 conversions.
- Date: Mon, 25 Mar 2013 18:48:26 +0000 (UTC)
commit b4c18771042a7d79cb9eabba5c331d9f90267a84
Author: Daniel Sabo <DanielSabo gmail com>
Date: Thu Feb 28 13:28:19 2013 -0800
Add some float<->int16 conversions.
extensions/Makefile.am | 2 +
extensions/int16.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 0 deletions(-)
---
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index 58465f3..456e30e 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -24,6 +24,7 @@ ext_LTLIBRARIES = \
gimp-8bit.la \
float.la \
fast-float.la \
+ int16.la \
naive-CMYK.la \
HSV.la \
sse-fixups.la
@@ -35,6 +36,7 @@ gegl_fixups_la_SOURCES = gegl-fixups.c
gggl_lies_la_SOURCES = gggl-lies.c
gggl_la_SOURCES = gggl.c
gimp_8bit_la_SOURCES = gimp-8bit.c
+int16_la_SOURCES = int16.c
naive_CMYK_la_SOURCES = naive-CMYK.c
HSV_la_SOURCES = HSV.c
sse_fixups_la_SOURCES = sse-fixups.c
diff --git a/extensions/int16.c b/extensions/int16.c
new file mode 100644
index 0000000..af17af5
--- /dev/null
+++ b/extensions/int16.c
@@ -0,0 +1,78 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include "babl.h"
+
+#include "base/util.h"
+
+int init (void);
+
+static long
+float_pre_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;
+ while (n--)
+ {
+ if (src[3] < BABL_ALPHA_THRESHOLD)
+ {
+ dst[0] = 0;
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 0;
+ }
+ else
+ {
+ float a_recip = 65535.0f * (1.0f / src[3]);
+ float r = src[0] * a_recip + 0.5;
+ float g = src[1] * a_recip + 0.5;
+ float b = src[2] * a_recip + 0.5;
+ float a = 65535.0f * src[3] + 0.5;
+ dst[0] = r >= 65535.0f ? 0xFFFF : r;
+ dst[1] = g >= 65535.0f ? 0xFFFF : g;
+ dst[2] = b >= 65535.0f ? 0xFFFF : b;
+ dst[3] = a >= 65535.0f ? 0xFFFF : a;
+ }
+
+ src += 4;
+ dst += 4;
+ }
+ return samples;
+}
+
+static long
+u16_to_float_pre (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ uint16_t *src = (uint16_t *)src_char;
+ float *dst = (float *)dst_char;
+ long n = samples;
+ while (n--)
+ {
+ float a_term = src[3] / (65535.0f * 65535.0f);
+ dst[0] = src[0] * a_term;
+ dst[1] = src[1] * a_term;
+ dst[2] = src[2] * a_term;
+ dst[3] = src[3] / 65535.0;
+
+ src += 4;
+ dst += 4;
+ }
+ return samples;
+}
+
+int
+init (void)
+{
+ babl_conversion_new (babl_format ("RaGaBaA float"),
+ babl_format ("RGBA u16"),
+ "linear",
+ float_pre_to_u16,
+ NULL);
+ babl_conversion_new (babl_format ("RGBA u16"),
+ babl_format ("RaGaBaA float"),
+ "linear",
+ u16_to_float_pre,
+ NULL);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]