[gnome-color-manager] trivial: more fixups to make the TRC widget sane
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] trivial: more fixups to make the TRC widget sane
- Date: Wed, 9 Dec 2009 20:42:58 +0000 (UTC)
commit f04af5c3072983e9b5113628f7782dc346c75b18
Author: Richard Hughes <richard hughsie com>
Date: Wed Dec 9 20:40:29 2009 +0000
trivial: more fixups to make the TRC widget sane
src/Makefile.am | 3 +-
src/gcm-clut.c | 31 ++-----------------
src/gcm-clut.h | 1 +
src/gcm-profile.c | 30 +++++++++---------
src/gcm-self-test.c | 2 +-
src/gcm-trc-widget.c | 82 +++++++++++++++++++++++++------------------------
src/gcm-utils.c | 3 +-
7 files changed, 65 insertions(+), 87 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index f819361..c53e4c5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,6 +40,8 @@ libgcmshared_a_SOURCES = \
gcm-device.h \
gcm-cie-widget.c \
gcm-cie-widget.h \
+ gcm-trc-widget.c \
+ gcm-trc-widget.h \
gcm-profile.c \
gcm-profile.h
@@ -192,7 +194,6 @@ gcm_self_test_SOURCES = \
gcm-xyz.c \
gcm-cie-widget.c \
gcm-trc-widget.c \
- gcm-trc-widget.h \
egg-test.h \
egg-test.c \
$(NULL)
diff --git a/src/gcm-clut.c b/src/gcm-clut.c
index 2c3d895..28bf25b 100644
--- a/src/gcm-clut.c
+++ b/src/gcm-clut.c
@@ -56,7 +56,6 @@ struct _GcmClutPrivate
gfloat gamma;
gfloat brightness;
gfloat contrast;
- gchar *profile;
GConfClient *gconf_client;
};
@@ -67,7 +66,6 @@ enum {
PROP_GAMMA,
PROP_BRIGHTNESS,
PROP_CONTRAST,
- PROP_PROFILE,
PROP_COPYRIGHT,
PROP_DESCRIPTION,
PROP_LAST
@@ -116,7 +114,7 @@ gcm_clut_reset (GcmClut *clut)
* gcm_clut_load_from_profile:
**/
gboolean
-gcm_clut_load_from_profile (GcmClut *clut, GError **error)
+gcm_clut_load_from_profile (GcmClut *clut, const gchar *filename, GError **error)
{
gboolean ret = TRUE;
GcmProfile *profile = NULL;
@@ -124,19 +122,13 @@ gcm_clut_load_from_profile (GcmClut *clut, GError **error)
GError *error_local = NULL;
g_return_val_if_fail (GCM_IS_CLUT (clut), FALSE);
-
- /* no profile to load */
- if (clut->priv->profile == NULL) {
- egg_debug ("no profile to load");
- gcm_clut_reset (clut);
- goto out;
- }
+ g_return_val_if_fail (filename != NULL, FALSE);
/* create new profile instance */
profile = gcm_profile_new ();
/* load the profile */
- ret = gcm_profile_parse (profile, clut->priv->profile, &error_local);
+ ret = gcm_profile_parse (profile, filename, &error_local);
if (!ret) {
if (error != NULL)
*error = g_error_new (1, 0, "failed to set from profile: %s", error_local->message);
@@ -260,9 +252,6 @@ gcm_clut_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec
case PROP_CONTRAST:
g_value_set_float (value, priv->contrast);
break;
- case PROP_PROFILE:
- g_value_set_string (value, priv->profile);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -282,10 +271,6 @@ gcm_clut_set_property (GObject *object, guint prop_id, const GValue *value, GPar
case PROP_SIZE:
priv->size = g_value_get_uint (value);
break;
- case PROP_PROFILE:
- g_free (priv->profile);
- priv->profile = g_strdup (g_value_get_string (value));
- break;
case PROP_GAMMA:
priv->gamma = g_value_get_float (value);
break;
@@ -345,14 +330,6 @@ gcm_clut_class_init (GcmClutClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CONTRAST, pspec);
- /**
- * GcmClut:profile:
- */
- pspec = g_param_spec_string ("profile", NULL, NULL,
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_PROFILE, pspec);
-
g_type_class_add_private (klass, sizeof (GcmClutPrivate));
}
@@ -365,7 +342,6 @@ gcm_clut_init (GcmClut *clut)
GError *error = NULL;
clut->priv = GCM_CLUT_GET_PRIVATE (clut);
clut->priv->array = g_ptr_array_new_with_free_func (g_free);
- clut->priv->profile = NULL;
clut->priv->gconf_client = gconf_client_get_default ();
clut->priv->gamma = gconf_client_get_float (clut->priv->gconf_client, GCM_SETTINGS_DEFAULT_GAMMA, &error);
if (error != NULL) {
@@ -387,7 +363,6 @@ gcm_clut_finalize (GObject *object)
GcmClut *clut = GCM_CLUT (object);
GcmClutPrivate *priv = clut->priv;
- g_free (clut->priv->profile);
g_ptr_array_unref (priv->array);
g_object_unref (clut->priv->gconf_client);
diff --git a/src/gcm-clut.h b/src/gcm-clut.h
index 0d7438e..7f7a0ef 100644
--- a/src/gcm-clut.h
+++ b/src/gcm-clut.h
@@ -63,6 +63,7 @@ typedef struct {
GType gcm_clut_get_type (void);
GcmClut *gcm_clut_new (void);
gboolean gcm_clut_load_from_profile (GcmClut *clut,
+ const gchar *filename,
GError **error);
GPtrArray *gcm_clut_get_array (GcmClut *clut);
gboolean gcm_clut_reset (GcmClut *clut);
diff --git a/src/gcm-profile.c b/src/gcm-profile.c
index 2571182..22ed75c 100644
--- a/src/gcm-profile.c
+++ b/src/gcm-profile.c
@@ -1227,21 +1227,6 @@ gcm_profile_generate (GcmProfile *profile, guint size)
mlut_data = profile->priv->mlut_data;
trc_data = profile->priv->trc_data;
- if (profile->priv->has_mlut) {
-
- /* create new output array */
- gamma_data = g_new0 (GcmClutData, size);
-
- /* roughly interpolate table */
- ratio = (guint) (256 / (size));
- for (i = 0; i<size; i++) {
- gamma_data[i].red = mlut_data[ratio*i].red;
- gamma_data[i].green = mlut_data[ratio*i].green;
- gamma_data[i].blue = mlut_data[ratio*i].blue;
- }
- goto out;
- }
-
if (profile->priv->has_vcgt_formula) {
/* create new output array */
@@ -1265,6 +1250,21 @@ gcm_profile_generate (GcmProfile *profile, guint size)
}
}
+ if (profile->priv->has_mlut) {
+
+ /* create new output array */
+ gamma_data = g_new0 (GcmClutData, size);
+
+ /* roughly interpolate table */
+ ratio = (guint) (256 / (size));
+ for (i = 0; i<size; i++) {
+ gamma_data[i].red = mlut_data[ratio*i].red;
+ gamma_data[i].green = mlut_data[ratio*i].green;
+ gamma_data[i].blue = mlut_data[ratio*i].blue;
+ }
+ goto out;
+ }
+
if (profile->priv->has_vcgt_table) {
/* create new output array */
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index c3d42a7..314ee60 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -48,7 +48,6 @@ main (int argc, char **argv)
egg_debug_init (&argc, &argv);
/* components */
- gcm_trc_widget_test (test);
gcm_edid_test (test);
gcm_tables_test (test);
gcm_utils_test (test);
@@ -58,6 +57,7 @@ main (int argc, char **argv)
gcm_clut_test (test);
gcm_dmi_test (test);
gcm_xyz_test (test);
+ gcm_trc_widget_test (test);
gcm_cie_widget_test (test);
return (egg_test_finish (test));
diff --git a/src/gcm-trc-widget.c b/src/gcm-trc-widget.c
index 4bfe05b..2aa6b33 100644
--- a/src/gcm-trc-widget.c
+++ b/src/gcm-trc-widget.c
@@ -37,12 +37,11 @@ G_DEFINE_TYPE (GcmTrcWidget, gcm_trc_widget, GTK_TYPE_DRAWING_AREA);
struct GcmTrcWidgetPrivate
{
gboolean use_grid;
+ GcmClut *clut;
guint chart_width;
guint chart_height;
cairo_t *cr;
PangoLayout *layout;
- GPtrArray *clut_data;
- GcmClutData *data;
guint x_offset;
guint y_offset;
};
@@ -54,10 +53,7 @@ enum
{
PROP_0,
PROP_USE_GRID,
- PROP_RED,
- PROP_GREEN,
- PROP_BLUE,
- PROP_WHITE,
+ PROP_CLUT,
PROP_LAST
};
@@ -90,6 +86,11 @@ dkp_trc_set_property (GObject *object, guint prop_id, const GValue *value, GPara
case PROP_USE_GRID:
trc->priv->use_grid = g_value_get_boolean (value);
break;
+ case PROP_CLUT:
+ if (trc->priv->clut != NULL)
+ g_object_unref (trc->priv->clut);
+ trc->priv->clut = g_value_dup_object (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -123,9 +124,9 @@ gcm_trc_widget_class_init (GcmTrcWidgetClass *class)
TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
- PROP_RED,
- g_param_spec_object ("red", NULL, NULL,
- G_TYPE_OBJECT,
+ PROP_CLUT,
+ g_param_spec_object ("clut", NULL, NULL,
+ GCM_TYPE_CLUT,
G_PARAM_WRITABLE));
}
@@ -141,7 +142,7 @@ gcm_trc_widget_init (GcmTrcWidget *trc)
trc->priv = GCM_TRC_WIDGET_GET_PRIVATE (trc);
trc->priv->use_grid = TRUE;
- trc->priv->clut_data = g_ptr_array_new_with_free_func (g_free);
+ trc->priv->clut = NULL;
/* do pango stuff */
fontmap = pango_cairo_font_map_get_default ();
@@ -166,7 +167,8 @@ gcm_trc_widget_finalize (GObject *object)
context = pango_layout_get_context (trc->priv->layout);
g_object_unref (trc->priv->layout);
g_object_unref (context);
- g_ptr_array_unref (trc->priv->clut_data);
+ if (trc->priv->clut != NULL)
+ g_object_unref (trc->priv->clut);
G_OBJECT_CLASS (gcm_trc_widget_parent_class)->finalize (object);
}
@@ -221,18 +223,6 @@ gcm_trc_widget_map_to_display (GcmTrcWidget *trc, gdouble x, gdouble y, gdouble
}
/**
- * gcm_trc_widget_map_from_display:
- **/
-static void
-gcm_trc_widget_map_from_display (GcmTrcWidget *trc, gdouble x, gdouble y, gdouble *x_retval, gdouble *y_retval)
-{
- GcmTrcWidgetPrivate *priv = trc->priv;
-
- *x_retval = ((gdouble) x - priv->x_offset) / (priv->chart_width - 1);
- *y_retval = 1.0 - ((gdouble) y + priv->y_offset) / (priv->chart_height - 1);
-}
-
-/**
* gcm_trc_widget_draw_line:
**/
static void
@@ -240,20 +230,28 @@ gcm_trc_widget_draw_line (GcmTrcWidget *trc, cairo_t *cr)
{
gdouble wx, wy;
GcmTrcWidgetPrivate *priv = trc->priv;
- GcmClutData tmp;
+ GPtrArray *array;
+ GcmClutData *tmp;
gfloat i;
gfloat value;
- const gfloat size = 256.0f;
+ gfloat size;
- cairo_save (cr);
+ /* nothing set yet */
+ if (priv->clut == NULL)
+ return;
+ /* get data */
+ array = gcm_clut_get_array (priv->clut);
+ size = array->len;
+
+ cairo_save (cr);
/* do red */
cairo_set_line_width (cr, 3);
cairo_set_source_rgb (cr, 0.5f, 0.0f, 0.0f);
for (i=0; i<size; i++) {
- tmp = priv->data[(guint)i];
- value = tmp.red/65536.0f;
+ tmp = g_ptr_array_index (array, (guint) i);
+ value = tmp->red/65536.0f;
gcm_trc_widget_map_to_display (trc, i/size, value, &wx, &wy);
if (i == 0)
cairo_move_to (cr, wx, wy);
@@ -269,8 +267,8 @@ gcm_trc_widget_draw_line (GcmTrcWidget *trc, cairo_t *cr)
cairo_set_line_width (cr, 3);
cairo_set_source_rgb (cr, 0.0f, 0.5f, 0.0f);
for (i=0; i<size; i++) {
- tmp = priv->data[(guint)i];
- value = tmp.green/65536.0f;
+ tmp = g_ptr_array_index (array, (guint) i);
+ value = tmp->green/65536.0f;
gcm_trc_widget_map_to_display (trc, i/size, value, &wx, &wy);
if (i == 0)
cairo_move_to (cr, wx, wy);
@@ -286,8 +284,8 @@ gcm_trc_widget_draw_line (GcmTrcWidget *trc, cairo_t *cr)
cairo_set_line_width (cr, 3);
cairo_set_source_rgb (cr, 0.0f, 0.0f, 0.5f);
for (i=0; i<size; i++) {
- tmp = priv->data[(guint)i];
- value = tmp.blue/65536.0f;
+ tmp = g_ptr_array_index (array, (guint) i);
+ value = tmp->blue/65536.0f;
gcm_trc_widget_map_to_display (trc, i/size, value, &wx, &wy);
if (i == 0)
cairo_move_to (cr, wx, wy);
@@ -299,6 +297,8 @@ gcm_trc_widget_draw_line (GcmTrcWidget *trc, cairo_t *cr)
cairo_set_source_rgb (cr, 0.0f, 0.0f, 1.0f);
cairo_stroke (cr);
+ g_ptr_array_unref (array);
+
cairo_restore (cr);
}
@@ -393,9 +393,6 @@ gcm_trc_widget_new (void)
#ifdef EGG_TEST
#include "egg-test.h"
-#include "gcm-profile.h"
-#include "gcm-xyz.h"
-
void
gcm_trc_widget_test (EggTest *test)
{
@@ -405,7 +402,7 @@ gcm_trc_widget_test (EggTest *test)
GtkWidget *vbox;
gboolean ret;
GError *error = NULL;
- GcmProfile *profile;
+ GcmClut *clut;
gint response;
gchar *filename_profile;
gchar *filename_image;
@@ -429,10 +426,15 @@ gcm_trc_widget_test (EggTest *test)
filename_profile = egg_test_get_data_file ("AdobeGammaTest.icm");
egg_test_assert (test, (filename_profile != NULL));
- profile = gcm_profile_new ();
- gcm_profile_parse (profile, filename_profile, NULL);
+ clut = gcm_clut_new ();
+ g_object_set (clut,
+ "size", 256,
+ NULL);
- ((GcmTrcWidget*)widget)->priv->data = gcm_profile_generate (profile, 256);
+ gcm_clut_load_from_profile (clut, filename_profile, NULL);
+ g_object_set (widget,
+ "clut", clut,
+ NULL);
/* show in a dialog as an example */
dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Does TRC widget match\nthe picture below?");
@@ -453,7 +455,7 @@ gcm_trc_widget_test (EggTest *test)
gtk_widget_destroy (dialog);
- g_object_unref (profile);
+ g_object_unref (clut);
g_free (filename_profile);
g_free (filename_image);
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 995b9eb..223193a 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -292,7 +292,6 @@ gcm_utils_set_gamma_for_device (GcmDevice *device, GError **error)
use_global = gconf_client_get_bool (gconf_client, GCM_SETTINGS_GLOBAL_DISPLAY_CORRECTION, NULL);
if (use_global) {
g_object_set (clut,
- "profile", profile,
"gamma", gamma,
"brightness", brightness,
"contrast", contrast,
@@ -300,7 +299,7 @@ gcm_utils_set_gamma_for_device (GcmDevice *device, GError **error)
NULL);
/* load this new profile */
- ret = gcm_clut_load_from_profile (clut, error);
+ ret = gcm_clut_load_from_profile (clut, profile, error);
if (!ret)
goto out;
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]