[gnome-color-manager] Show the TRC curves in the UI, rather than the vcgt curves
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Show the TRC curves in the UI, rather than the vcgt curves
- Date: Mon, 14 Dec 2009 10:21:55 +0000 (UTC)
commit 6256bd4f9c510edce55b1c08c44ec0c878af5fc1
Author: Richard Hughes <richard hughsie com>
Date: Mon Dec 14 10:21:17 2009 +0000
Show the TRC curves in the UI, rather than the vcgt curves
src/gcm-prefs.c | 21 +++++---
src/gcm-profile.c | 124 +++++++++++++++++++++++++++++++++++++++++++++----
src/gcm-profile.h | 4 +-
src/gcm-trc-widget.c | 2 +-
src/gcm-utils.c | 2 +-
5 files changed, 131 insertions(+), 22 deletions(-)
---
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 7f9cd63..182d14c 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -1413,7 +1413,7 @@ gcm_prefs_profiles_treeview_clicked_cb (GtkTreeSelection *selection, gpointer us
GtkTreeIter iter;
GtkWidget *widget;
GcmProfile *profile;
- GcmClut *clut;
+ GcmClut *clut = NULL;
GcmXyz *white;
GcmXyz *red;
GcmXyz *green;
@@ -1430,7 +1430,7 @@ gcm_prefs_profiles_treeview_clicked_cb (GtkTreeSelection *selection, gpointer us
const gchar *profile_type_text;
const gchar *profile_colorspace_text;
gboolean ret;
- guint size;
+ guint size = 0;
guint filesize;
/* This will only work in single or browse selection mode! */
@@ -1467,11 +1467,15 @@ gcm_prefs_profiles_treeview_clicked_cb (GtkTreeSelection *selection, gpointer us
"blue", blue,
NULL);
- /* get CLUT for profile */
- clut = gcm_profile_generate (profile, 256);
- g_object_get (clut,
- "size", &size,
- NULL);
+ /* get curve data */
+ clut = gcm_profile_generate_curve (profile, 256);
+
+ /* get size */
+ if (clut != NULL) {
+ g_object_get (clut,
+ "size", &size,
+ NULL);
+ }
/* only show if there is useful information */
if (size > 0) {
@@ -1570,11 +1574,12 @@ gcm_prefs_profiles_treeview_clicked_cb (GtkTreeSelection *selection, gpointer us
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_profile_delete"));
gtk_widget_set_sensitive (widget, ret);
+ if (clut != NULL)
+ g_object_unref (clut);
g_object_unref (white);
g_object_unref (red);
g_object_unref (green);
g_object_unref (blue);
- g_object_unref (clut);
g_free (size_text);
g_free (filename);
g_free (basename);
diff --git a/src/gcm-profile.c b/src/gcm-profile.c
index 0abfb35..c60d023 100644
--- a/src/gcm-profile.c
+++ b/src/gcm-profile.c
@@ -849,12 +849,12 @@ out:
}
/**
- * gcm_profile_generate:
+ * gcm_profile_generate_vcgt:
*
- * Free with g_free();
+ * Free with g_object_unref();
**/
GcmClut *
-gcm_profile_generate (GcmProfile *profile, guint size)
+gcm_profile_generate_vcgt (GcmProfile *profile, guint size)
{
guint i;
guint ratio;
@@ -865,8 +865,8 @@ gcm_profile_generate (GcmProfile *profile, guint size)
gfloat gamma_green, min_green, max_green;
gfloat gamma_blue, min_blue, max_blue;
guint num_entries;
- GcmClut *clut;
- GPtrArray *array;
+ GcmClut *clut = NULL;
+ GPtrArray *array = NULL;
gfloat inverse_ratio;
guint idx;
gfloat frac;
@@ -878,12 +878,11 @@ gcm_profile_generate (GcmProfile *profile, guint size)
vcgt_data = profile->priv->vcgt_data;
mlut_data = profile->priv->mlut_data;
- /* create new output array */
- clut = gcm_clut_new ();
- array = g_ptr_array_new_with_free_func (g_free);
-
if (profile->priv->has_vcgt_table) {
+ /* create array */
+ array = g_ptr_array_new_with_free_func (g_free);
+
/* simply subsample if the LUT is smaller than the number of entries in the file */
num_entries = profile->priv->vcgt_data_size;
if (num_entries >= size) {
@@ -920,6 +919,9 @@ gcm_profile_generate (GcmProfile *profile, guint size)
if (profile->priv->has_vcgt_formula) {
+ /* create array */
+ array = g_ptr_array_new_with_free_func (g_free);
+
gamma_red = (gfloat) vcgt_data[0].red / 65536.0;
gamma_green = (gfloat) vcgt_data[0].green / 65536.0;
gamma_blue = (gfloat) vcgt_data[0].blue / 65536.0;
@@ -944,6 +946,9 @@ gcm_profile_generate (GcmProfile *profile, guint size)
if (profile->priv->has_mlut) {
+ /* create array */
+ array = g_ptr_array_new_with_free_func (g_free);
+
/* roughly interpolate table */
ratio = (guint) (256 / (size));
for (i=0; i<size; i++) {
@@ -960,8 +965,105 @@ gcm_profile_generate (GcmProfile *profile, guint size)
/* bugger */
egg_debug ("no LUT to generate");
out:
- gcm_clut_set_source_array (clut, array);
- g_ptr_array_unref (array);
+ if (array != NULL) {
+ /* create new output array */
+ clut = gcm_clut_new ();
+ gcm_clut_set_source_array (clut, array);
+ g_ptr_array_unref (array);
+ }
+ return clut;
+}
+
+/**
+ * gcm_profile_generate_curve:
+ *
+ * Free with g_object_unref();
+ **/
+GcmClut *
+gcm_profile_generate_curve (GcmProfile *profile, guint size)
+{
+ GcmClut *clut = NULL;
+ gdouble *values_in = NULL;
+ gdouble *values_out = NULL;
+ guint i;
+ GcmClutData *data;
+ GPtrArray *array = NULL;
+ gfloat divamount;
+ gfloat divadd;
+ guint component_width;
+ cmsHPROFILE srgb_profile = NULL;
+ cmsHTRANSFORM transform = NULL;
+ GcmProfilePrivate *priv = profile->priv;
+ guint type;
+
+ /* run through the profile */
+ if (priv->colorspace == GCM_PROFILE_COLORSPACE_RGB) {
+
+ /* RGB */
+ component_width = 3;
+ type = TYPE_RGB_DBL;
+
+ /* create input array */
+ values_in = g_new0 (gdouble, size * 3 * component_width);
+ divamount = 1.0f / (gfloat) size;
+ for (i=0; i<size; i++) {
+ divadd = divamount * (gfloat) i;
+
+ /* red component */
+ values_in[(i * 3 * component_width)+0] = divadd;
+ values_in[(i * 3 * component_width)+1] = 0.0f;
+ values_in[(i * 3 * component_width)+2] = 0.0f;
+
+ /* green component */
+ values_in[(i * 3 * component_width)+3] = 0.0f;
+ values_in[(i * 3 * component_width)+4] = divadd;
+ values_in[(i * 3 * component_width)+5] = 0.0f;
+
+ /* blue component */
+ values_in[(i * 3 * component_width)+6] = 0.0f;
+ values_in[(i * 3 * component_width)+7] = 0.0f;
+ values_in[(i * 3 * component_width)+8] = divadd;
+ }
+ }
+
+ /* do each transform */
+ if (values_in != NULL) {
+ /* create output array */
+ values_out = g_new0 (gdouble, size * 3 * component_width);
+
+ /* create a transform from profile to sRGB */
+ srgb_profile = cmsCreate_sRGBProfile ();
+ transform = cmsCreateTransform (priv->lcms_profile, type, srgb_profile, TYPE_RGB_DBL, INTENT_PERCEPTUAL, 0);
+ if (transform == NULL)
+ goto out;
+
+ /* do transform */
+ cmsDoTransform (transform, values_in, values_out, size * 3);
+
+ /* create output array */
+ array = g_ptr_array_new_with_free_func (g_free);
+
+ for (i=0; i<size; i++) {
+ data = g_new0 (GcmClutData, 1);
+
+ data->red = values_out[(i * 3 * component_width)+0] * (gfloat) 0xffff;
+ data->green = values_out[(i * 3 * component_width)+4] * (gfloat) 0xffff;
+ data->blue = values_out[(i * 3 * component_width)+8] * (gfloat) 0xffff;
+ g_ptr_array_add (array, data);
+ }
+ clut = gcm_clut_new ();
+ gcm_clut_set_source_array (clut, array);
+ }
+
+out:
+ g_free (values_in);
+ g_free (values_out);
+ if (array != NULL)
+ g_ptr_array_unref (array);
+ if (transform != NULL)
+ cmsDeleteTransform (transform);
+ if (srgb_profile != NULL)
+ cmsCloseProfile (srgb_profile);
return clut;
}
diff --git a/src/gcm-profile.h b/src/gcm-profile.h
index 4ea7513..3c17b5f 100644
--- a/src/gcm-profile.h
+++ b/src/gcm-profile.h
@@ -89,7 +89,9 @@ gboolean gcm_profile_parse_data (GcmProfile *profile,
const guint8 *data,
gsize length,
GError **error);
-GcmClut *gcm_profile_generate (GcmProfile *profile,
+GcmClut *gcm_profile_generate_vcgt (GcmProfile *profile,
+ guint size);
+GcmClut *gcm_profile_generate_curve (GcmProfile *profile,
guint size);
const gchar *gcm_profile_type_to_text (GcmProfileType type);
const gchar *gcm_profile_colorspace_to_text (GcmProfileColorspace type);
diff --git a/src/gcm-trc-widget.c b/src/gcm-trc-widget.c
index f5a59dc..0c32f81 100644
--- a/src/gcm-trc-widget.c
+++ b/src/gcm-trc-widget.c
@@ -434,7 +434,7 @@ gcm_trc_widget_test (EggTest *test)
profile = gcm_profile_new ();
gcm_profile_parse (profile, filename_profile, NULL);
- clut = gcm_profile_generate (profile, 256);
+ clut = gcm_profile_generate_vcgt (profile, 256);
g_object_set (widget,
"clut", clut,
NULL);
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 76e5b24..1aa86f5 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -296,7 +296,7 @@ gcm_utils_set_gamma_for_device (GcmDevice *device, GError **error)
goto out;
/* create a CLUT from the profile */
- clut = gcm_profile_generate (profile, size);
+ clut = gcm_profile_generate_vcgt (profile, size);
} else {
/* create dummy CLUT */
clut = gcm_clut_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]