[gnome-color-manager] When converting from a .ti1 to a .ti3 file we need a calibration file



commit afac31e07ed2f1549e5d697d818ba69fd56d23c7
Author: Richard Hughes <richard hughsie com>
Date:   Mon Nov 28 16:01:23 2011 +0000

    When converting from a .ti1 to a .ti3 file we need a calibration file

 src/gcm-calibrate-helper.c |  126 +++++++++++++++++++++++++++++---------------
 src/gcm-calibrate.c        |    7 +++
 src/gcm-calibrate.h        |    1 +
 3 files changed, 92 insertions(+), 42 deletions(-)
---
diff --git a/src/gcm-calibrate-helper.c b/src/gcm-calibrate-helper.c
index 63a8dc0..5697d58 100644
--- a/src/gcm-calibrate-helper.c
+++ b/src/gcm-calibrate-helper.c
@@ -29,26 +29,18 @@
 #include "gcm-calibrate.h"
 
 /**
- * gcm_calibrate_helper_ti1_to_ti3:
+ * gcm_calibrate_setup_sensor:
  **/
 static gboolean
-gcm_calibrate_helper_ti1_to_ti3 (const gchar *device_id,
-				 const gchar *ti1_fn,
-				 const gchar *ti3_fn,
-				 GError **error)
+gcm_calibrate_setup_sensor (CdClient *client,
+			    GcmCalibrate *calibrate,
+			    GError **error)
 {
-	CdClient *client = NULL;
 	CdSensor *sensor_tmp;
 	gboolean ret;
-	GcmCalibrate *calibrate = NULL;
 	GPtrArray *sensors = NULL;
 
 	/* get sensor */
-	client = cd_client_new ();
-	ret = cd_client_connect_sync (client, NULL, error);
-	if (!ret)
-		goto out;
-
 	sensors = cd_client_get_sensors_sync (client, NULL, error);
 	if (sensors == NULL) {
 		ret = FALSE;
@@ -57,7 +49,7 @@ gcm_calibrate_helper_ti1_to_ti3 (const gchar *device_id,
 	if (sensors->len == 0) {
 		ret = FALSE;
 		g_set_error_literal (error, 1, 0,
-				     "No sensors plugged in!");
+				     "No native sensors plugged in!");
 		goto out;
 	}
 	sensor_tmp = g_ptr_array_index (sensors, 0);
@@ -66,26 +58,10 @@ gcm_calibrate_helper_ti1_to_ti3 (const gchar *device_id,
 		goto out;
 
 	/* set sensor */
-	calibrate = gcm_calibrate_new ();
 	gcm_calibrate_set_sensor (calibrate, sensor_tmp);
-
-	/* convert the ti1 file to a ti3 file */
-	ret = gcm_calibrate_display_characterize (calibrate,
-						  ti1_fn,
-						  ti3_fn,
-						  NULL, /* device */
-						  NULL, /* window */
-						  error);
-	if (!ret)
-		goto out;
-
-	/* success */
-	g_print ("%s: %s\n", _("Wrote file"), ti3_fn);
 out:
 	if (sensors != NULL)
 		g_ptr_array_unref (sensors);
-	if (calibrate != NULL)
-		g_object_unref (calibrate);
 	return ret;
 }
 
@@ -95,15 +71,18 @@ out:
 int
 main (int argc, char **argv)
 {
+	CdClient *client = NULL;
+	CdDevice *device = NULL;
 	gboolean ret;
 	gchar *device_id = NULL;
+	GcmCalibrate *calibrate = NULL;
 	GError *error = NULL;
 	GOptionContext *context;
 	guint retval = 1;
 	guint xid = 0;
 
 	const GOptionEntry options[] = {
-		{ "device", '\0', 0, G_OPTION_ARG_INT, &device_id,
+		{ "device", '\0', 0, G_OPTION_ARG_STRING, &device_id,
 			/* TRANSLATORS: command line option */
 			_("Use this device for profiling"), NULL },
 		{ "xid", '\0', 0, G_OPTION_ARG_INT, &xid,
@@ -125,33 +104,96 @@ main (int argc, char **argv)
 	g_option_context_add_main_entries (context, options, NULL);
 	g_option_context_add_group (context, gcm_debug_get_option_group ());
 	g_option_context_add_group (context, gtk_get_option_group (TRUE));
-	g_option_context_parse (context, &argc, &argv, NULL);
-	g_option_context_free (context);
+	ret = g_option_context_parse (context, &argc, &argv, &error);
+	if (!ret)
+		goto out;
+
+	/* get client */
+	client = cd_client_new ();
+	ret = cd_client_connect_sync (client, NULL, &error);
+	if (!ret)
+		goto out;
+
+	/* check device */
+	if (device_id == NULL) {
+		g_print ("No device-id specified\n");
+		goto out;
+	}
+	device = cd_client_find_device_sync (client,
+					     device_id,
+					     NULL,
+					     &error);
+	if (device == NULL) {
+		ret = FALSE;
+		goto out;
+	}
+	ret = cd_device_connect_sync (device,
+				      NULL,
+				      &error);
+	if (!ret)
+		goto out;
 
 	/* correct arguments */
-	if (argc == 3 &&
+	if (argc == 4 &&
 	    g_str_has_suffix (argv[1], "ti1") &&
-	    g_str_has_suffix (argv[2], "ti3")) {
-		ret = gcm_calibrate_helper_ti1_to_ti3 (device_id,
-						       argv[1],
-						       argv[2],
-						       &error);
+	    g_str_has_suffix (argv[2], "cal") &&
+	    g_str_has_suffix (argv[3], "ti3")) {
+
+		/* setup calibration */
+		calibrate = gcm_calibrate_new ();
+		ret = gcm_calibrate_setup_sensor (client,
+						  calibrate,
+						  &error);
+		if (!ret)
+			goto out;
+
+		/* mark device to be profiled in colord */
+		ret = cd_device_profiling_inhibit_sync (device,
+							NULL,
+							&error);
+		if (!ret)
+			goto out;
+
+		/* convert the ti1 file to a ti3 file */
+		ret = gcm_calibrate_display_characterize (calibrate,
+							  argv[1],
+							  argv[2],
+							  argv[3],
+							  device,
+							  NULL, /* window */
+							  &error);
+		if (!ret)
+			goto out;
+
+		/* success */
+		g_print ("%s: %s\n", _("Wrote file"), argv[2]);
+
 	} else {
 		ret = FALSE;
-		g_print ("%s\n", _("Specify one of:"));
-		g_print ("file.ti1 file.ti3\n");
+		g_set_error_literal (&error, 1, 0,
+				     "Specify one of:\n"
+				     "file.ti1 file.ti3\n"
+				     "file.cal");
 		goto out;
 	}
+out:
 	if (!ret) {
 		g_print ("%s: %s\n",
 			 _("Failed to calibrate"),
 			 error->message);
 		g_error_free (error);
-		goto out;
 	}
 
+	/* success */
 	retval = 0;
-out:
+
+	g_option_context_free (context);
+	if (device != NULL)
+		g_object_unref (device);
+	if (client != NULL)
+		g_object_unref (client);
+	if (calibrate != NULL)
+		g_object_unref (calibrate);
 	g_free (device_id);
 	return retval;
 }
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index 2b40157..7368fbb 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -520,6 +520,7 @@ gcm_calibrate_normalize_to_y (GPtrArray *samples_xyz, gdouble scale)
 gboolean
 gcm_calibrate_display_characterize (GcmCalibrate *calibrate,
 				    const gchar *ti1_fn,
+				    const gchar *cal_fn,
 				    const gchar *ti3_fn,
 				    CdDevice *device,
 				    GtkWindow *window,
@@ -748,6 +749,7 @@ gcm_calibrate_display (GcmCalibrate *calibrate,
 {
 	const gchar *filename_tmp;
 	gboolean ret = TRUE;
+	gchar *cal_fn = NULL;
 	gchar *ti1_dest_fn = NULL;
 	gchar *ti1_src_fn = NULL;
 	gchar *ti3_fn = NULL;
@@ -784,11 +786,15 @@ gcm_calibrate_display (GcmCalibrate *calibrate,
 	/* if sensor is native, then take some measurements */
 	if (cd_sensor_get_native (calibrate->priv->sensor) &&
 	    cd_sensor_get_kind (calibrate->priv->sensor) == CD_SENSOR_KIND_COLORHUG) {
+		cal_fn = g_strdup_printf ("%s/%s.cal",
+					  priv->working_path,
+					  priv->basename);
 		ti3_fn = g_strdup_printf ("%s/%s.ti3",
 					  priv->working_path,
 					  priv->basename);
 		ret = gcm_calibrate_display_characterize (calibrate,
 							  ti1_dest_fn,
+							  cal_fn,
 							  ti3_fn,
 							  device,
 							  window,
@@ -813,6 +819,7 @@ gcm_calibrate_display (GcmCalibrate *calibrate,
 out:
 	/* unset brightness */
 	gcm_calibrate_unset_brightness (calibrate, device);
+	g_free (cal_fn);
 	g_free (ti1_src_fn);
 	g_free (ti1_dest_fn);
 	g_free (ti3_fn);
diff --git a/src/gcm-calibrate.h b/src/gcm-calibrate.h
index 48ae66b..cd090f1 100644
--- a/src/gcm-calibrate.h
+++ b/src/gcm-calibrate.h
@@ -165,6 +165,7 @@ const gchar	*gcm_calibrate_get_basename		(GcmCalibrate	*calibrate);
 /* for gcm-calibrate-helper */
 gboolean	 gcm_calibrate_display_characterize	(GcmCalibrate	*calibrate,
 							 const gchar	*ti1_fn,
+							 const gchar	*cal_fn,
 							 const gchar	*ti3_fn,
 							 CdDevice	*device,
 							 GtkWindow	*window,



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