[babl] add a u15 type that is 16bit only using 15bits
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] add a u15 type that is 16bit only using 15bits
- Date: Sun, 13 May 2012 02:16:23 +0000 (UTC)
commit 8167d33480d05308b753ad61acaaa17ff2f26c3c
Author: Ãyvind KolÃs <pippin gimp org>
Date: Thu May 3 01:20:29 2012 +0200
add a u15 type that is 16bit only using 15bits
babl/base/Makefile.am | 1 +
babl/base/babl-base.c | 3 +
babl/base/babl-base.h | 1 +
babl/base/model-gray.c | 37 +++++++++++++
babl/base/model-rgb.c | 53 +++++++++++++++++++
babl/base/type-u15.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 231 insertions(+), 0 deletions(-)
---
diff --git a/babl/base/Makefile.am b/babl/base/Makefile.am
index 74052c2..55cd1df 100644
--- a/babl/base/Makefile.am
+++ b/babl/base/Makefile.am
@@ -8,6 +8,7 @@ c_sources = \
type-float.c \
type-half.c \
type-u8.c \
+ type-u15.c \
type-u16.c \
type-u32.c \
model-rgb.c \
diff --git a/babl/base/babl-base.c b/babl/base/babl-base.c
index 0831eb1..3fe3cfc 100644
--- a/babl/base/babl-base.c
+++ b/babl/base/babl-base.c
@@ -50,6 +50,7 @@ babl_base_destroy (void)
static void
types (void)
{
+ babl_base_type_u15 ();
babl_base_type_half ();
babl_base_type_float ();
babl_base_type_u8 ();
@@ -65,7 +66,9 @@ types (void)
static void
models (void)
{
+ babl_hmpf_on_name_lookups--;
babl_base_model_rgb ();
babl_base_model_gray ();
+ babl_hmpf_on_name_lookups++;
babl_base_model_ycbcr ();
}
diff --git a/babl/base/babl-base.h b/babl/base/babl-base.h
index f3bf6cd..588e2f1 100644
--- a/babl/base/babl-base.h
+++ b/babl/base/babl-base.h
@@ -27,6 +27,7 @@ void babl_base_type_half (void);
void babl_base_type_float (void);
void babl_base_type_u8 (void);
void babl_base_type_u16 (void);
+void babl_base_type_u15 (void);
void babl_base_type_u32 (void);
void babl_base_model_pal (void);
diff --git a/babl/base/model-gray.c b/babl/base/model-gray.c
index 057c831..239333e 100644
--- a/babl/base/model-gray.c
+++ b/babl/base/model-gray.c
@@ -625,6 +625,43 @@ formats (void)
babl_type_from_id (BABL_HALF),
babl_component_from_id (BABL_LUMA),
NULL);
+ /***********/
+
+ babl_format_new (
+ babl_model_from_id (BABL_GRAY_ALPHA),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_LUMINANCE),
+ babl_component_from_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_from_id (BABL_GRAY_ALPHA_PREMULTIPLIED),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_LUMINANCE_MUL_ALPHA),
+ babl_component_from_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_from_id (BABL_GRAY),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_LUMINANCE),
+ NULL);
+ babl_format_new (
+ babl_model_from_id (BABL_GRAY_GAMMA_2_2_ALPHA),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_LUMA),
+ babl_component_from_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_from_id (BABL_GRAY_GAMMA_2_2_ALPHA_PREMULTIPLIED),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_LUMA_MUL_ALPHA),
+ babl_component_from_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_from_id (BABL_GRAY_GAMMA_2_2),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_LUMA),
+ NULL);
+
babl_format_new (
babl_model_from_id (BABL_GRAY_ALPHA),
babl_type_from_id (BABL_U32),
diff --git a/babl/base/model-rgb.c b/babl/base/model-rgb.c
index 2d72343..4ba6f7d 100644
--- a/babl/base/model-rgb.c
+++ b/babl/base/model-rgb.c
@@ -570,6 +570,59 @@ formats (void)
babl_component_from_id (BABL_ALPHA),
NULL);
+ /******/
+ babl_format_new (
+ babl_model_from_id (BABL_RGB),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_RED),
+ babl_component_from_id (BABL_GREEN),
+ babl_component_from_id (BABL_BLUE),
+ NULL);
+
+ babl_format_new (
+ babl_model_from_id (BABL_RGBA),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_RED),
+ babl_component_from_id (BABL_GREEN),
+ babl_component_from_id (BABL_BLUE),
+ babl_component_from_id (BABL_ALPHA),
+ NULL);
+
+ babl_format_new (
+ babl_model_from_id (BABL_RGBA_PREMULTIPLIED),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_RED_MUL_ALPHA),
+ babl_component_from_id (BABL_GREEN_MUL_ALPHA),
+ babl_component_from_id (BABL_BLUE_MUL_ALPHA),
+ babl_component_from_id (BABL_ALPHA),
+ NULL);
+
+ babl_format_new (
+ babl_model_from_id (BABL_RGB_GAMMA_2_2),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_RED_GAMMA_2_2),
+ babl_component_from_id (BABL_GREEN_GAMMA_2_2),
+ babl_component_from_id (BABL_BLUE_GAMMA_2_2),
+ NULL);
+
+ babl_format_new (
+ babl_model_from_id (BABL_RGBA_GAMMA_2_2),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_RED_GAMMA_2_2),
+ babl_component_from_id (BABL_GREEN_GAMMA_2_2),
+ babl_component_from_id (BABL_BLUE_GAMMA_2_2),
+ babl_component_from_id (BABL_ALPHA),
+ NULL);
+
+ babl_format_new (
+ babl_model_from_id (BABL_RGBA_GAMMA_2_2_PREMULTIPLIED),
+ babl_type ("u15"),
+ babl_component_from_id (BABL_RED_GAMMA_2_2_MUL_ALPHA),
+ babl_component_from_id (BABL_GREEN_GAMMA_2_2_MUL_ALPHA),
+ babl_component_from_id (BABL_BLUE_GAMMA_2_2_MUL_ALPHA),
+ babl_component_from_id (BABL_ALPHA),
+ NULL);
+
babl_format_new (
babl_model_from_id (BABL_RGB),
diff --git a/babl/base/type-u15.c b/babl/base/type-u15.c
new file mode 100644
index 0000000..47e3878
--- /dev/null
+++ b/babl/base/type-u15.c
@@ -0,0 +1,136 @@
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Ãyvind KolÃs.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <string.h>
+#include <stdint.h>
+#include <assert.h>
+#include <math.h>
+
+#include "babl-internal.h"
+#include "babl-base.h"
+
+
+static inline long
+convert_double_u15_scaled (double min_val,
+ double max_val,
+ uint16_t min,
+ uint16_t max,
+ char *src,
+ char *dst,
+ int src_pitch,
+ int dst_pitch,
+ long n)
+{
+ while (n--)
+ {
+ double dval = *(double *) src;
+ uint16_t u15val;
+
+ if (dval < min_val)
+ u15val = min;
+ else if (dval > max_val)
+ u15val = max;
+ else
+ u15val = rint ((dval - min_val) / (max_val - min_val) * (max - min) + min);
+
+ *(uint16_t *) dst = u15val;
+ dst += dst_pitch;
+ src += src_pitch;
+ }
+ return n;
+}
+
+static inline long
+convert_u15_double_scaled (double min_val,
+ double max_val,
+ uint16_t min,
+ uint16_t max,
+ char *src,
+ char *dst,
+ int src_pitch,
+ int dst_pitch,
+ long n)
+{
+ while (n--)
+ {
+ int u15val = *(uint16_t *) src;
+ double dval;
+
+ if (u15val < min)
+ dval = min_val;
+ else if (u15val > max)
+ dval = max_val;
+ else
+ dval = (u15val - min) / (double) (max - min) * (max_val - min_val) + min_val;
+
+ (*(double *) dst) = dval;
+ dst += dst_pitch;
+ src += src_pitch;
+ }
+ return n;
+}
+
+#define MAKE_CONVERSIONS(name, min_val, max_val, min, max) \
+ static long \
+ convert_ ## name ## _double (void *src, \
+ void *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_u15_double_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ } \
+ static long \
+ convert_double_ ## name (void *src, \
+ void *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_double_u15_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ }
+
+MAKE_CONVERSIONS (u15, 0.0, 1.0, 0, (1<<15))
+
+void
+babl_base_type_u15 (void)
+{
+ babl_hmpf_on_name_lookups--;
+ babl_type_new (
+ "u15",
+ "bits", 16,
+ NULL);
+
+ babl_conversion_new (
+ babl_type ("u15"),
+ babl_type_from_id (BABL_DOUBLE),
+ "plane", convert_u15_double,
+ NULL
+ );
+
+ babl_conversion_new (
+ babl_type_from_id (BABL_DOUBLE),
+ babl_type ("u15"),
+ "plane", convert_double_u15,
+ NULL
+ );
+ babl_hmpf_on_name_lookups++;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]