Author: abrander
Date: 2009-10-15 17:25:29 +0200 (Thu, 15 Oct 2009)
New Revision: 2719

Added:
   trunk/librawstudio/rs-color-space.c
   trunk/librawstudio/rs-color-space.h
Modified:
   trunk/librawstudio/Makefile.am
   trunk/librawstudio/rawstudio.h
Log:
Added RSColorSpace.

Modified: trunk/librawstudio/Makefile.am
===================================================================
--- trunk/librawstudio/Makefile.am      2009-10-15 15:04:14 UTC (rev 2718)
+++ trunk/librawstudio/Makefile.am      2009-10-15 15:25:29 UTC (rev 2719)
@@ -14,6 +14,7 @@
        rs-exif.h \
        rs-1d-function.h \
        rs-icc-profile.h \
+       rs-color-space.h \
        rs-image.h \
        rs-image16.h \
        rs-lens.h \
@@ -49,6 +50,7 @@
        rs-exif.cc rs-exif.h \
        rs-1d-function.c rs-1d-function.h \
        rs-icc-profile.c rs-icc-profile.h \
+       rs-color-space.c rs-color-space.h \
        rs-image.c rs-image.h \
        rs-image16.c rs-image16.h \
        rs-lens.c rs-lens.h \

Modified: trunk/librawstudio/rawstudio.h
===================================================================
--- trunk/librawstudio/rawstudio.h      2009-10-15 15:04:14 UTC (rev 2718)
+++ trunk/librawstudio/rawstudio.h      2009-10-15 15:25:29 UTC (rev 2719)
@@ -34,6 +34,7 @@
 #include "rs-exif.h"
 #include "rs-1d-function.h"
 #include "rs-icc-profile.h"
+#include "rs-color-space.h"
 #include "rs-image.h"
 #include "rs-image16.h"
 #include "rs-metadata.h"

Added: trunk/librawstudio/rs-color-space.c
===================================================================
--- trunk/librawstudio/rs-color-space.c                         (rev 0)
+++ trunk/librawstudio/rs-color-space.c 2009-10-15 15:25:29 UTC (rev 2719)
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2006-2009 Anders Brander <[email protected]> and 
+ * Anders Kvist <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA.
+ */
+
+#include "rs-color-space.h"
+
+G_DEFINE_TYPE (RSColorSpace, rs_color_space, G_TYPE_OBJECT)
+
+static void
+rs_color_space_class_init(RSColorSpaceClass *klass)
+{
+}
+
+static void
+rs_color_space_init(RSColorSpace *color_space)
+{
+}
+
+/**
+ * Get a color space definition
+ * @param name The GType name for the colorspace (not the registered name)
+ * @return A colorspace singleton if found, NULL otherwise. This should not be 
unreffed.
+ */
+const RSColorSpace *
+rs_color_space_new_singleton(const gchar *name)
+{
+       RSColorSpace *color_space = NULL;
+       static GHashTable *singletons = NULL;
+       static GStaticMutex lock = G_STATIC_MUTEX_INIT;
+
+       g_assert(name != NULL);
+
+       g_static_mutex_lock(&lock);
+
+       if (!singletons)
+               singletons = g_hash_table_new(g_str_hash, g_str_equal);
+
+       color_space = g_hash_table_lookup(singletons, name);
+       if (!color_space)
+       {
+               GType type = g_type_from_name(name);
+               if (g_type_is_a (type, RS_TYPE_COLOR_SPACE))
+                       color_space = g_object_new(type, NULL);
+
+               if (!RS_IS_COLOR_SPACE(color_space))
+                       g_warning("Could not instantiate color space of type 
\"%s\"", name);
+               else
+                       g_hash_table_insert(singletons, (gpointer) name, 
color_space);
+       }
+
+       g_static_mutex_unlock(&lock);
+
+       return color_space;
+}
+
+/**
+ * Set (RGB) to PCS matrix
+ * @note This is only interesting for color space implementations
+ * @param color_space A RSColorSpace
+ * @param matrix A matrix, xyz2rgb will be the inverse of this
+ */
+void
+rs_color_space_set_matrix_to_pcs(RSColorSpace *color_space, const RS_MATRIX3 * 
const matrix)
+{
+       g_assert(RS_IS_COLOR_SPACE(color_space));
+
+       /* Could this be replaced by bradford? */
+       const RS_VECTOR3 identity = {1.0, 1.0, 1.0};
+       const RS_VECTOR3 w1 = vector3_multiply_matrix(&identity, matrix);
+       const RS_VECTOR3 w2 = XYZ_WP_D50;
+
+       const RS_VECTOR3 scale_vector = { w2.x/w1.x, w2.y/w1.y, w2.z/w2.z };
+       const RS_MATRIX3 scale = vector3_as_diagonal(&scale_vector);
+
+       matrix3_multiply(&scale, matrix, &color_space->matrix_to_pcs);
+       color_space->matrix_from_pcs = 
matrix3_invert(&color_space->matrix_to_pcs);
+}
+
+/**
+ * Get a matrix that will transform this color space to PCS
+ * @param color_space A RSColorSpace
+ * @return from_pcs matrix
+ */
+RS_MATRIX3
+rs_color_space_get_matrix_to_pcs(const RSColorSpace *color_space)
+{
+       g_assert(RS_IS_COLOR_SPACE(color_space));
+
+       return color_space->matrix_from_pcs;
+}
+
+/**
+ * Get a matrix that will transform PCS to this color space
+ * @param color_space A RSColorSpace
+ * @return to_pcs matrix
+ */
+RS_MATRIX3
+rs_color_space_get_matrix_from_pcs(const RSColorSpace *color_space)
+{
+       g_assert(RS_IS_COLOR_SPACE(color_space));
+
+       return color_space->matrix_to_pcs;
+}
+
+/**
+ * Get the ICC profile for this colorspace if any
+ * @param color_space A RSColorSpace
+ * @return A RSIccProfile (or NULL) that should not be unreffed
+ */
+const RSIccProfile *
+rs_color_space_get_icc_profile(const RSColorSpace *color_space)
+{
+       RSColorSpaceClass *klass = RS_COLOR_SPACE_GET_CLASS(color_space);
+
+       if (klass->get_icc_profile)
+               return klass->get_icc_profile(color_space);
+       else
+               return NULL;
+}
+
+/**
+ * Get the gamma transfer function for this color space
+ * @param color_space A RSColorSpace
+ * @return A RS1dFunction that should not be unreffed
+ */
+const RS1dFunction *
+rs_color_space_get_gamma_function(const RSColorSpace *color_space)
+{
+       RSColorSpaceClass *klass = RS_COLOR_SPACE_GET_CLASS(color_space);
+
+       if (klass->get_gamma_function)
+               return klass->get_gamma_function(color_space);
+       else
+               return rs_1d_function_new_singleton();
+}

Added: trunk/librawstudio/rs-color-space.h
===================================================================
--- trunk/librawstudio/rs-color-space.h                         (rev 0)
+++ trunk/librawstudio/rs-color-space.h 2009-10-15 15:25:29 UTC (rev 2719)
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2006-2009 Anders Brander <[email protected]> and 
+ * Anders Kvist <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA.
+ */
+
+#ifndef RS_COLOR_SPACE_H
+#define RS_COLOR_SPACE_H
+
+#include <glib-object.h>
+#include "rawstudio.h"
+
+G_BEGIN_DECLS
+
+#define RS_DEFINE_COLOR_SPACE(type_name, TypeName) \
+static GType type_name##_get_type (GTypeModule *module); \
+static void type_name##_class_init(TypeName##Class *klass); \
+static void type_name##_init(TypeName *color_space); \
+static GType type_name##_type = 0; \
+static GType \
+type_name##_get_type(GTypeModule *module) \
+{ \
+       if (!type_name##_type) \
+       { \
+               static const GTypeInfo color_space_info = \
+               { \
+                       sizeof (TypeName##Class), \
+                       (GBaseInitFunc) NULL, \
+                       (GBaseFinalizeFunc) NULL, \
+                       (GClassInitFunc) type_name##_class_init, \
+                       NULL, \
+                       NULL, \
+                       sizeof (TypeName), \
+                       0, \
+                       (GInstanceInitFunc) type_name##_init \
+               }; \
+ \
+               type_name##_type = g_type_module_register_type( \
+                       module, \
+                       RS_TYPE_COLOR_SPACE, \
+                       #TypeName, \
+                       &color_space_info, \
+                       0); \
+       } \
+       return type_name##_type; \
+}
+
+#define RS_TYPE_COLOR_SPACE rs_color_space_get_type()
+#define RS_COLOR_SPACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
RS_TYPE_COLOR_SPACE, RSColorSpace))
+#define RS_COLOR_SPACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), 
RS_TYPE_COLOR_SPACE, RSColorSpaceClass))
+#define RS_IS_COLOR_SPACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
RS_TYPE_COLOR_SPACE))
+#define RS_IS_COLOR_SPACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
RS_TYPE_COLOR_SPACE))
+#define RS_COLOR_SPACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), 
RS_TYPE_COLOR_SPACE, RSColorSpaceClass))
+
+typedef struct {
+       GObject parent;
+
+       RS_MATRIX3 matrix_to_pcs;
+       RS_MATRIX3 matrix_from_pcs;
+} RSColorSpace;
+
+typedef struct {
+       GObjectClass parent_class;
+
+       const gchar *name;
+       const gchar *description;
+
+       RS_MATRIX3 (*get_to_pcs)(const RSColorSpace *color_space);
+       RS_MATRIX3 (*get_from_pcs)(const RSColorSpace *color_space);
+       const RSIccProfile *(*get_icc_profile)(const RSColorSpace *color_space);
+       const RS1dFunction *(*get_gamma_function)(const RSColorSpace 
*color_space);
+} RSColorSpaceClass;
+
+GType rs_color_space_get_type(void);
+
+/**
+ * Get a color space definition
+ * @param name The GType name for the colorspace (not the registered name)
+ * @return A colorspace singleton if found, NULL otherwise. This should not be 
unreffed.
+ */
+const RSColorSpace *
+rs_color_space_new_singleton(const gchar *name);
+
+/**
+ * Set (RGB) to PCS matrix
+ * @note This is only interesting for color space implementations
+ * @param color_space A RSColorSpace
+ * @param matrix A matrix, xyz2rgb will be the inverse of this
+ */
+void
+rs_color_space_set_matrix_to_pcs(RSColorSpace *color_space, const RS_MATRIX3 * 
const matrix);
+
+/**
+ * Get a matrix that will transform this color space to PCS
+ * @param color_space A RSColorSpace
+ * @return from_pcs matrix
+ */
+RS_MATRIX3
+rs_color_space_get_matrix_to_pcs(const RSColorSpace *color_space);
+
+/**
+ * Get a matrix that will transform PCS to this color space
+ * @param color_space A RSColorSpace
+ * @return to_pcs matrix
+ */
+RS_MATRIX3
+rs_color_space_get_matrix_from_pcs(const RSColorSpace *color_space);
+
+/**
+ * Get the ICC profile for this colorspace if any
+ * @param color_space A RSColorSpace
+ * @return A RSIccProfile (or NULL) that should not be unreffed
+ */
+const RSIccProfile *
+rs_color_space_get_icc_profile(const RSColorSpace *color_space);
+
+/**
+ * Get the gamma transfer function for this color space
+ * @param color_space A RSColorSpace
+ * @return A RS1dFunction that should not be unreffed
+ */
+const RS1dFunction *
+rs_color_space_get_gamma_function(const RSColorSpace *color_space);
+
+G_END_DECLS
+
+#endif /* RS_COLOR_SPACE_H */


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to