[gnome-color-manager] Use the pregenerated ti1 files rather than using targen each time



commit 9101a744959275131bf127186b7908c519dd52c4
Author: Richard Hughes <richard hughsie com>
Date:   Mon Nov 7 20:00:08 2011 +0000

    Use the pregenerated ti1 files rather than using targen each time

 src/gcm-calibrate-argyll.c |  172 --------------------------------------------
 src/gcm-calibrate-main.c   |    8 +-
 src/gcm-calibrate.c        |  156 +++++++++++++++++++++++++++++++++++-----
 src/gcm-calibrate.h        |    8 --
 4 files changed, 141 insertions(+), 203 deletions(-)
---
diff --git a/src/gcm-calibrate-argyll.c b/src/gcm-calibrate-argyll.c
index 39a29b7..51f7d55 100644
--- a/src/gcm-calibrate-argyll.c
+++ b/src/gcm-calibrate-argyll.c
@@ -109,63 +109,6 @@ gcm_calibrate_argyll_get_quality_arg (GcmCalibrateArgyll *calibrate_argyll)
 	return "-qm";
 }
 
-/**
- * gcm_calibrate_argyll_display_get_patches:
- **/
-static guint
-gcm_calibrate_argyll_display_get_patches (GcmCalibrateArgyll *calibrate_argyll)
-{
-	guint patches = 250;
-	GcmCalibratePrecision precision;
-
-	/* get kind */
-	g_object_get (calibrate_argyll,
-		      "precision", &precision,
-		      NULL);
-
-	if (precision == GCM_CALIBRATE_PRECISION_SHORT)
-		patches = 100;
-	else if (precision == GCM_CALIBRATE_PRECISION_NORMAL)
-		patches = 250;
-	else if (precision == GCM_CALIBRATE_PRECISION_LONG)
-		patches = 500;
-	return patches;
-}
-
-/**
- * gcm_calibrate_argyll_printer_get_patches:
- **/
-static guint
-gcm_calibrate_argyll_printer_get_patches (GcmCalibrateArgyll *calibrate_argyll)
-{
-	guint patches = 180;
-	CdSensorKind sensor_kind;
-	GcmCalibratePrecision precision;
-
-	/* we care about the kind */
-	g_object_get (calibrate_argyll,
-		      "sensor-kind", &sensor_kind,
-		      "precision", &precision,
-		      NULL);
-
-	if (precision == GCM_CALIBRATE_PRECISION_SHORT)
-		patches = 90;
-	else if (precision == GCM_CALIBRATE_PRECISION_NORMAL)
-		patches = 180;
-	else if (precision == GCM_CALIBRATE_PRECISION_LONG)
-		patches = 360;
-
-#ifdef USE_DOUBLE_DENSITY
-	/* using double density, so we can double the patch count */
-	if (sensor_kind == CD_SENSOR_KIND_COLOR_MUNKI ||
-	    sensor_kind == CD_SENSOR_KIND_SPECTRO_SCAN) {
-		patches *= 2;
-	}
-#endif
-
-	return patches;
-}
-
 #ifdef HAVE_VTE
 /**
  * gcm_calibrate_argyll_get_sensor_image_attach:
@@ -587,108 +530,6 @@ out:
 }
 
 /**
- * gcm_calibrate_argyll_display_generate_patches:
- **/
-static gboolean
-gcm_calibrate_argyll_display_generate_patches (GcmCalibrateArgyll *calibrate_argyll, GError **error)
-{
-	gboolean ret = TRUE;
-	GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
-	gchar *command = NULL;
-	gchar **argv = NULL;
-	GPtrArray *array = NULL;
-	gchar *basename = NULL;
-	CdDeviceKind device_kind;
-
-	/* get shared data */
-	g_object_get (calibrate_argyll,
-		      "basename", &basename,
-		      "device-kind", &device_kind,
-		      NULL);
-
-	/* get correct name of the command */
-	command = gcm_calibrate_argyll_get_tool_filename ("targen", error);
-	if (command == NULL) {
-		ret = FALSE;
-		goto out;
-	}
-
-	/* TRANSLATORS: title, patches are specific colours used in calibration */
-	gcm_calibrate_set_title (GCM_CALIBRATE (calibrate_argyll),
-				 _("Generating the patches"));
-	/* TRANSLATORS: dialog message */
-	gcm_calibrate_set_message (GCM_CALIBRATE (calibrate_argyll),
-				   _("Generating the patches that will be measured with the color instrument."));
-
-	/* argument array */
-	array = g_ptr_array_new_with_free_func (g_free);
-
-	/* setup the command */
-#ifdef FIXED_ARGYLL
-	g_ptr_array_add (array, g_strdup (command));
-#endif
-	g_ptr_array_add (array, g_strdup ("-v"));
-	if (device_kind == CD_DEVICE_KIND_PRINTER) {
-		/* print RGB */
-		g_ptr_array_add (array, g_strdup ("-d2"));
-
-		/* Grey axis RGB steps */
-		g_ptr_array_add (array, g_strdup ("-g20"));
-	} else {
-		/* video RGB */
-		g_ptr_array_add (array, g_strdup ("-d3"));
-	}
-
-	/* get number of patches */
-	if (device_kind == CD_DEVICE_KIND_DISPLAY)
-		g_ptr_array_add (array, g_strdup_printf ("-f%i", gcm_calibrate_argyll_display_get_patches (calibrate_argyll)));
-	else if (device_kind == CD_DEVICE_KIND_PRINTER)
-		g_ptr_array_add (array, g_strdup_printf ("-f%i", gcm_calibrate_argyll_printer_get_patches (calibrate_argyll)));
-
-	g_ptr_array_add (array, g_strdup (basename));
-	argv = gcm_utils_ptr_array_to_strv (array);
-	gcm_calibrate_argyll_debug_argv (command, argv);
-
-	/* start up the command */
-	ret = gcm_calibrate_argyll_fork_command (calibrate_argyll, argv, error);
-	if (!ret)
-		goto out;
-
-	/* wait until finished */
-	g_main_loop_run (priv->loop);
-
-	/* get result */
-	if (priv->response == GTK_RESPONSE_CANCEL) {
-		g_set_error_literal (error,
-				     GCM_CALIBRATE_ERROR,
-				     GCM_CALIBRATE_ERROR_USER_ABORT,
-				     "calibration was cancelled");
-		ret = FALSE;
-		goto out;
-	}
-#ifdef HAVE_VTE
-	if (priv->response == GTK_RESPONSE_REJECT) {
-		gchar *vte_text;
-		vte_text = vte_terminal_get_text (VTE_TERMINAL(priv->terminal), NULL, NULL, NULL);
-		g_set_error (error,
-			     GCM_CALIBRATE_ERROR,
-			     GCM_CALIBRATE_ERROR_INTERNAL,
-			     "command failed to run successfully: %s", vte_text);
-		g_free (vte_text);
-		ret = FALSE;
-		goto out;
-	}
-#endif
-out:
-	if (array != NULL)
-		g_ptr_array_unref (array);
-	g_free (basename);
-	g_free (command);
-	g_strfreev (argv);
-	return ret;
-}
-
-/**
  * gcm_calibrate_argyll_display_draw_and_measure:
  **/
 static gboolean
@@ -1376,11 +1217,6 @@ gcm_calibrate_argyll_display (GcmCalibrate *calibrate, CdDevice *device, CdSenso
 	if (!ret)
 		goto out;
 
-	/* step 2 */
-	ret = gcm_calibrate_argyll_display_generate_patches (calibrate_argyll, error);
-	if (!ret)
-		goto out;
-
 	/* step 3 */
 	ret = gcm_calibrate_argyll_display_draw_and_measure (calibrate_argyll, error);
 	if (!ret)
@@ -1814,14 +1650,6 @@ gcm_calibrate_argyll_printer (GcmCalibrate *calibrate, CdDevice *device, CdSenso
 		      NULL);
 	working_path = gcm_calibrate_get_working_path (GCM_CALIBRATE (calibrate_argyll));
 
-	/* step 1 */
-	if (print_kind == GCM_CALIBRATE_PRINT_KIND_LOCAL ||
-	    print_kind == GCM_CALIBRATE_PRINT_KIND_GENERATE) {
-		ret = gcm_calibrate_argyll_display_generate_patches (calibrate_argyll, error);
-		if (!ret)
-			goto out;
-	}
-
 	/* print */
 	if (print_kind == GCM_CALIBRATE_PRINT_KIND_LOCAL) {
 		ret = gcm_print_with_render_callback (priv->print, window, (GcmPrintRenderCb) gcm_calibrate_argyll_render_cb, calibrate, error);
diff --git a/src/gcm-calibrate-main.c b/src/gcm-calibrate-main.c
index cdf25ac..2508f30 100644
--- a/src/gcm-calibrate-main.c
+++ b/src/gcm-calibrate-main.c
@@ -432,10 +432,10 @@ gcm_calib_start_idle_cb (gpointer user_data)
 
 	/* actuall do the action */
 	calib->started_calibration = TRUE;
-	ret = gcm_calibrate_display (calib->calibrate,
-				     calib->device,
-				     calib->main_window,
-				     &error);
+	ret = gcm_calibrate_device (calib->calibrate,
+				    calib->device,
+				    calib->main_window,
+				    &error);
 	if (!ret) {
 		gcm_calibrate_set_title (calib->calibrate, _("Failed to calibrate"));
 		gcm_calibrate_set_message (calib->calibrate, error->message);
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index e01cc40..35fa51b 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -336,17 +336,68 @@ gcm_calibrate_interaction (GcmCalibrate *calibrate, GtkResponseType response)
 }
 
 /**
+ * gcm_calibrate_copy_file:
+ **/
+static gboolean
+gcm_calibrate_copy_file (const gchar *src,
+			 const gchar *dest,
+			 GError **error)
+{
+	gboolean ret;
+	GFile *file_src;
+	GFile *file_dest;
+
+	g_debug ("copying from %s to %s", src, dest);
+	file_src = g_file_new_for_path (src);
+	file_dest = g_file_new_for_path (dest);
+	ret = g_file_copy (file_src,
+			   file_dest,
+			   G_FILE_COPY_NONE,
+			   NULL,
+			   NULL,
+			   NULL,
+			   error);
+	g_object_unref (file_src);
+	g_object_unref (file_dest);
+	return ret;
+}
+
+/**
  * gcm_calibrate_display:
  **/
-gboolean
+static gboolean
 gcm_calibrate_display (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *window, GError **error)
 {
+	const gchar *filename_tmp;
 	gboolean ret = TRUE;
+	gchar *dest_ti1;
+	gchar *src_ti1;
 	GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
 	GcmCalibratePrivate *priv = calibrate->priv;
 
-	/* set basename */
-	gcm_calibrate_set_basename (calibrate);
+	/* get a ti1 file suitable for the calibration */
+	dest_ti1 = g_strdup_printf ("%s/%s.ti1",
+				    calibrate->priv->working_path,
+				    calibrate->priv->basename);
+
+	/* copy a pre-generated file into the working path */
+	switch (priv->precision) {
+	case GCM_CALIBRATE_PRECISION_SHORT:
+		filename_tmp = "display-short.ti1";
+		break;
+	case GCM_CALIBRATE_PRECISION_NORMAL:
+		filename_tmp = "display-normal.ti1";
+		break;
+	case GCM_CALIBRATE_PRECISION_LONG:
+		filename_tmp = "display-long.ti1";
+		break;
+	default:
+		g_assert_not_reached ();
+	}
+	src_ti1 = g_build_filename (GCM_DATA, "ti1", filename_tmp, NULL);
+	ret = gcm_calibrate_copy_file (src_ti1, dest_ti1, error);
+	if (!ret)
+		goto out;
 
 	/* coldplug source */
 	if (klass->calibrate_display == NULL) {
@@ -361,14 +412,16 @@ gcm_calibrate_display (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *win
 	/* proxy */
 	ret = klass->calibrate_display (calibrate, device, priv->sensor, window, error);
 out:
+	g_free (src_ti1);
+	g_free (dest_ti1);
 	return ret;
 }
 
 /**
- * gcm_calibrate_device_get_reference_image:
+ * gcm_calibrate_camera_get_reference_image:
  **/
 static gchar *
-gcm_calibrate_device_get_reference_image (const gchar *directory, GtkWindow *window)
+gcm_calibrate_camera_get_reference_image (const gchar *directory, GtkWindow *window)
 {
 	gchar *filename = NULL;
 	GtkWidget *dialog;
@@ -412,10 +465,10 @@ gcm_calibrate_device_get_reference_image (const gchar *directory, GtkWindow *win
 }
 
 /**
- * gcm_calibrate_device_get_reference_data:
+ * gcm_calibrate_camera_get_reference_data:
  **/
 static gchar *
-gcm_calibrate_device_get_reference_data (const gchar *directory, GtkWindow *window)
+gcm_calibrate_camera_get_reference_data (const gchar *directory, GtkWindow *window)
 {
 	gchar *filename = NULL;
 	GtkWidget *dialog;
@@ -540,25 +593,47 @@ gcm_calibrate_file_chooser_get_working_path (GcmCalibrate *calibrate, GtkWindow
 /**
  * gcm_calibrate_printer:
  **/
-gboolean
+static gboolean
 gcm_calibrate_printer (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *window, GError **error)
 {
 	gboolean ret = FALSE;
 	gchar *ptr;
 	GtkWindow *window_tmp = NULL;
 	gchar *precision = NULL;
+	const gchar *filename_tmp;
+	gchar *dest_ti1;
+	gchar *src_ti1;
 	GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
 	GcmCalibratePrivate *priv = calibrate->priv;
 
+	/* get a ti1 file suitable for the calibration */
+	dest_ti1 = g_strdup_printf ("%s/%s.ti1",
+				    calibrate->priv->working_path,
+				    calibrate->priv->basename);
+
+	/* copy a pre-generated file into the working path */
+	switch (priv->precision) {
+	case GCM_CALIBRATE_PRECISION_SHORT:
+		filename_tmp = "printer-short.ti1";
+		break;
+	case GCM_CALIBRATE_PRECISION_NORMAL:
+		filename_tmp = "printer-normal.ti1";
+		break;
+	case GCM_CALIBRATE_PRECISION_LONG:
+		filename_tmp = "printer-long.ti1";
+		break;
+	default:
+		g_assert_not_reached ();
+	}
+	src_ti1 = g_build_filename (GCM_DATA, "ti1", filename_tmp, NULL);
+	ret = gcm_calibrate_copy_file (src_ti1, dest_ti1, error);
+	if (!ret)
+		goto out;
+
 	/* copy */
 	g_object_get (NULL, "print-kind", &priv->print_kind, NULL);
 
-	if (priv->print_kind != GCM_CALIBRATE_PRINT_KIND_ANALYZE) {
-		/* set the per-profile filename */
-		ret = gcm_calibrate_set_working_path (calibrate, error);
-		if (!ret)
-			goto out;
-	} else {
+	if (priv->print_kind == GCM_CALIBRATE_PRINT_KIND_ANALYZE) {
 
 		/* remove previously set value (if any) */
 		g_free (priv->working_path);
@@ -597,15 +672,17 @@ gcm_calibrate_printer (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *win
 	/* proxy */
 	ret = klass->calibrate_printer (calibrate, device, priv->sensor, window, error);
 out:
+	g_free (src_ti1);
+	g_free (dest_ti1);
 	g_free (precision);
 	return ret;
 }
 
 /**
- * gcm_calibrate_device:
+ * gcm_calibrate_camera:
  **/
-gboolean
-gcm_calibrate_device (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *window, GError **error)
+static gboolean
+gcm_calibrate_camera (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *window, GError **error)
 {
 	gboolean ret = FALSE;
 	gboolean has_shared_targets = TRUE;
@@ -623,7 +700,7 @@ gcm_calibrate_device (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *wind
 
 	/* get scanned image */
 	directory = g_get_home_dir ();
-	reference_image = gcm_calibrate_device_get_reference_image (directory, window_tmp);
+	reference_image = gcm_calibrate_camera_get_reference_image (directory, window_tmp);
 	if (reference_image == NULL) {
 		g_set_error_literal (error,
 				     GCM_CALIBRATE_ERROR,
@@ -640,7 +717,7 @@ gcm_calibrate_device (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *wind
 
 	/* get reference data */
 	directory = has_shared_targets ? "/usr/share/color/targets" : "/media";
-	reference_data = gcm_calibrate_device_get_reference_data (directory, window_tmp);
+	reference_data = gcm_calibrate_camera_get_reference_data (directory, window_tmp);
 	if (reference_data == NULL) {
 		g_set_error_literal (error,
 				     GCM_CALIBRATE_ERROR,
@@ -683,6 +760,47 @@ out:
 	return ret;
 }
 
+/**
+ * gcm_calibrate_device:
+ **/
+gboolean
+gcm_calibrate_device (GcmCalibrate *calibrate,
+		      CdDevice *device,
+		      GtkWindow *window,
+		      GError **error)
+{
+	gboolean ret = TRUE;
+
+	/* set up some initial parameters */
+	gcm_calibrate_set_basename (calibrate);
+	ret = gcm_calibrate_set_working_path (calibrate, error);
+	if (!ret)
+		goto out;
+
+	switch (cd_device_get_kind (device)) {
+	case CD_DEVICE_KIND_DISPLAY:
+		ret = gcm_calibrate_display (calibrate,
+					     device,
+					     window,
+					     error);
+		break;
+	case CD_DEVICE_KIND_PRINTER:
+		ret = gcm_calibrate_printer (calibrate,
+					     device,
+					     window,
+					     error);
+		break;
+	default:
+		ret = gcm_calibrate_camera (calibrate,
+					    device,
+					    window,
+					    error);
+		break;
+	}
+out:
+	return ret;
+}
+
 void
 gcm_calibrate_set_title (GcmCalibrate *calibrate, const gchar *title)
 {
diff --git a/src/gcm-calibrate.h b/src/gcm-calibrate.h
index 9267b8a..caf7e1b 100644
--- a/src/gcm-calibrate.h
+++ b/src/gcm-calibrate.h
@@ -127,18 +127,10 @@ GType		 gcm_calibrate_get_type			(void);
 GcmCalibrate	*gcm_calibrate_new			(void);
 
 /* designed for gcm-calibrate to call */
-gboolean	 gcm_calibrate_display			(GcmCalibrate	*calibrate,
-							 CdDevice	*device,
-							 GtkWindow	*window,
-							 GError		**error);
 gboolean	 gcm_calibrate_device			(GcmCalibrate	*calibrate,
 							 CdDevice	*device,
 							 GtkWindow	*window,
 							 GError		**error);
-gboolean	 gcm_calibrate_printer			(GcmCalibrate	*calibrate,
-							 CdDevice	*device,
-							 GtkWindow	*window,
-							 GError		**error);
 void		 gcm_calibrate_set_content_widget	(GcmCalibrate	*calibrate,
 							 GtkWidget	*widget);
 void		 gcm_calibrate_interaction		(GcmCalibrate	*calibrate,



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