[gnome-color-manager] Add gcm_image_set_abstract_profile() so we can set LAB abstract profiles



commit a821eb8b3d81bfc1187ab324cb6f0d61de1bc16a
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jun 24 14:45:39 2010 +0100

    Add gcm_image_set_abstract_profile() so we can set LAB abstract profiles

 src/gcm-image.c |   90 +++++++++++++++++++++++++++++++++++++++++++++++--------
 src/gcm-image.h |    2 +
 2 files changed, 79 insertions(+), 13 deletions(-)
---
diff --git a/src/gcm-image.c b/src/gcm-image.c
index f13b9aa..c7651be 100644
--- a/src/gcm-image.c
+++ b/src/gcm-image.c
@@ -50,6 +50,7 @@ struct _GcmImagePrivate
 	gboolean			 use_embedded_profile;
 	GcmProfile			*output_profile;
 	GcmProfile			*input_profile;
+	GcmProfile			*abstract_profile;
 	GdkPixbuf			*original_pixbuf;
 };
 
@@ -59,6 +60,7 @@ enum {
 	PROP_USE_EMBEDDED_PROFILE,
 	PROP_OUTPUT_PROFILE,
 	PROP_INPUT_PROFILE,
+	PROP_ABSTRACT_PROFILE,
 	PROP_LAST
 };
 
@@ -117,9 +119,10 @@ gcm_image_cms_convert_pixbuf (GcmImage *image)
 	gint width, height, rowstride;
 	guchar *p_in;
 	guchar *p_out;
-	cmsHPROFILE profile_in;
-	cmsHPROFILE profile_out;
-	cmsHTRANSFORM transform;
+	cmsHPROFILE profile_in = NULL;
+	cmsHPROFILE profile_out = NULL;
+	cmsHPROFILE profile_abstract = NULL;
+	cmsHTRANSFORM transform = NULL;
 	GdkPixbuf *pixbuf_cms;
 	guchar *profile_data = NULL;
 	gsize profile_size;
@@ -203,8 +206,30 @@ gcm_image_cms_convert_pixbuf (GcmImage *image)
 		profile_close_output = TRUE;
 	}
 
-	/* create transform */
-	transform = cmsCreateTransform (profile_in, format, profile_out, format, INTENT_PERCEPTUAL, 0);
+	/* get abstract profile */
+	if (priv->abstract_profile != NULL) {
+		cmsHPROFILE profiles[3];
+
+		/* not LAB */
+		if (gcm_profile_get_colorspace (priv->abstract_profile) != GCM_COLORSPACE_LAB) {
+			egg_warning ("abstract profile has to be LAB!");
+			goto out;
+		}
+
+		/* generate a devicelink */
+		profiles[0] = profile_in;
+		profiles[1] = gcm_profile_get_handle (priv->abstract_profile);
+		profiles[2] = profile_out;
+		transform = cmsCreateMultiprofileTransform (profiles, 3, format, format, INTENT_PERCEPTUAL, 0);
+
+	} else {
+		/* create basic transform */
+		transform = cmsCreateTransform (profile_in, format, profile_out, format, INTENT_PERCEPTUAL, 0);
+	}
+
+	/* failed? */
+	if (transform == NULL)
+		goto out;
 
 	/* process each row */
 	height = gdk_pixbuf_get_height (priv->original_pixbuf);
@@ -218,17 +243,22 @@ gcm_image_cms_convert_pixbuf (GcmImage *image)
 		p_out += rowstride;
 	}
 
+	/* refresh widget */
+	if (gtk_widget_get_visible (GTK_WIDGET(image))) {
+		gtk_widget_set_visible (GTK_WIDGET(image), FALSE);
+		gtk_widget_set_visible (GTK_WIDGET(image), TRUE);
+	}
+out:
 	/* destroy lcms state */
-	cmsDeleteTransform (transform);
-	if (profile_close_input)
+	if (transform != NULL)
+		cmsDeleteTransform (transform);
+	if (profile_in != NULL && profile_close_input)
 		cmsCloseProfile (profile_in);
-	if (profile_close_output)
+	if (profile_out != NULL && profile_close_output)
 		cmsCloseProfile (profile_out);
+	if (profile_abstract != NULL)
+		cmsCloseProfile (profile_abstract);
 
-	/* refresh widget */
-	gtk_widget_set_visible (GTK_WIDGET(image), FALSE);
-	gtk_widget_set_visible (GTK_WIDGET(image), TRUE);
-out:
 	g_free (profile_data);
 	return;
 }
@@ -281,8 +311,10 @@ gcm_image_set_input_profile (GcmImage *image, GcmProfile *profile)
 		g_object_unref (priv->input_profile);
 		priv->input_profile = NULL;
 	}
-	if (profile != NULL)
+	if (profile != NULL) {
 		priv->input_profile = g_object_ref (profile);
+		gcm_image_use_embedded_profile (image, FALSE);
+	}
 	gcm_image_cms_convert_pixbuf (image);
 }
 
@@ -303,6 +335,22 @@ gcm_image_set_output_profile (GcmImage *image, GcmProfile *profile)
 }
 
 /**
+ * gcm_image_set_abstract_profile:
+ **/
+void
+gcm_image_set_abstract_profile (GcmImage *image, GcmProfile *profile)
+{
+	GcmImagePrivate *priv = image->priv;
+	if (priv->abstract_profile != NULL) {
+		g_object_unref (priv->abstract_profile);
+		priv->abstract_profile = NULL;
+	}
+	if (profile != NULL)
+		priv->abstract_profile = g_object_ref (profile);
+	gcm_image_cms_convert_pixbuf (image);
+}
+
+/**
  * gcm_image_has_embedded_profile:
  **/
 gboolean
@@ -343,6 +391,9 @@ gcm_image_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe
 	case PROP_INPUT_PROFILE:
 		g_value_set_object (value, priv->input_profile);
 		break;
+	case PROP_ABSTRACT_PROFILE:
+		g_value_set_object (value, priv->abstract_profile);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -367,6 +418,9 @@ gcm_image_set_property (GObject *object, guint prop_id, const GValue *value, GPa
 	case PROP_INPUT_PROFILE:
 		gcm_image_set_input_profile (image, g_value_get_object (value));
 		break;
+	case PROP_ABSTRACT_PROFILE:
+		gcm_image_set_abstract_profile (image, g_value_get_object (value));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -417,6 +471,14 @@ gcm_image_class_init (GcmImageClass *klass)
 				     G_PARAM_READWRITE);
 	g_object_class_install_property (object_class, PROP_INPUT_PROFILE, pspec);
 
+	/**
+	 * GcmImage:abstract-profile:
+	 */
+	pspec = g_param_spec_object ("abstract-profile", NULL, NULL,
+				     GCM_TYPE_PROFILE,
+				     G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_ABSTRACT_PROFILE, pspec);
+
 	g_type_class_add_private (klass, sizeof (GcmImagePrivate));
 }
 
@@ -454,6 +516,8 @@ gcm_image_finalize (GObject *object)
 		g_object_unref (priv->output_profile);
 	if (priv->input_profile != NULL)
 		g_object_unref (priv->input_profile);
+	if (priv->abstract_profile != NULL)
+		g_object_unref (priv->abstract_profile);
 
 	G_OBJECT_CLASS (gcm_image_parent_class)->finalize (object);
 }
diff --git a/src/gcm-image.h b/src/gcm-image.h
index 412171f..5c6a216 100644
--- a/src/gcm-image.h
+++ b/src/gcm-image.h
@@ -64,6 +64,8 @@ void		 gcm_image_set_input_profile	(GcmImage	*image,
 						 GcmProfile	*profile);
 void		 gcm_image_set_output_profile	(GcmImage	*image,
 						 GcmProfile	*profile);
+void		 gcm_image_set_abstract_profile	(GcmImage	*image,
+						 GcmProfile	*profile);
 gboolean	 gcm_image_has_embedded_profile	(GcmImage	*image);
 void		 gcm_image_use_embedded_profile	(GcmImage	*image,
 						 gboolean	 use_embedded_profile);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]