[gnome-color-manager] Remove the native calibration code



commit 88e70c1b98401ab54e4db239b2a7f904243dbbcd
Author: Richard Hughes <richard hughsie com>
Date:   Tue Jan 15 23:26:06 2013 +0000

    Remove the native calibration code
    
    It's never been enabled, and it's been superceeded by the colord session helper.

 src/gcm-calibrate.c |  942 ---------------------------------------------------
 src/gcm-calibrate.h |   14 -
 2 files changed, 0 insertions(+), 956 deletions(-)
---
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index b08c293..b5e0e5e 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -297,18 +297,6 @@ out:
 	return ret;
 }
 
-#if 0
-	/* can this device support projectors? */
-	if (priv->display_kind == GCM_CALIBRATE_DEVICE_KIND_PROJECTOR &&
-	    !cd_sensor_has_cap (priv->sensor, CD_SENSOR_CAP_PROJECTOR)) {
-		/* TRANSLATORS: title, the hardware calibration device does not support projectors */
-		title = _("Could not calibrate and profile using this color measuring instrument");
-
-		/* TRANSLATORS: dialog message */
-		message = _("This color measuring instrument is not designed to support calibration and profiling projectors.");
-	}
-#endif
-
 void
 gcm_calibrate_set_sensor (GcmCalibrate *calibrate, CdSensor *sensor)
 {
@@ -407,41 +395,6 @@ gcm_calibrate_copy_file (const gchar *src,
 }
 
 /**
- * gcm_calibrate_lcms_error_cb:
- **/
-static void
-gcm_calibrate_lcms_error_cb (cmsContext ContextID,
-			     cmsUInt32Number error_code,
-			     const char *text)
-{
-	g_warning ("LCMS: %s", text);
-}
-
-/**
- * gcm_calibrate_delay_cb:
- **/
-static gboolean
-gcm_calibrate_delay_cb (gpointer user_data)
-{
-	GMainLoop *loop = (GMainLoop *) user_data;
-	g_main_loop_quit (loop);
-	return FALSE;
-}
-
-/**
- * gcm_calibrate_delay:
- **/
-static void
-gcm_calibrate_delay (guint ms)
-{
-	GMainLoop *loop;
-	loop = g_main_loop_new (NULL, FALSE);
-	g_timeout_add (ms, gcm_calibrate_delay_cb, loop);
-	g_main_loop_run (loop);
-	g_main_loop_unref (loop);
-}
-
-/**
  * gcm_calibrate_interaction_attach:
  **/
 void
@@ -570,876 +523,6 @@ gcm_calibrate_interaction_calibrate (GcmCalibrate *calibrate)
 }
 
 /**
- * gcm_calibrate_get_samples:
- **/
-static gboolean
-gcm_calibrate_get_samples (GcmCalibrate *calibrate,
-			   GPtrArray *samples_rgb,
-			   GPtrArray *samples_xyz,
-			   GError **error)
-{
-	CdColorRGB *rgb;
-	CdColorRGB rgb_tmp;
-	CdColorXYZ *xyz;
-	gboolean ret;
-	guint i;
-	GcmCalibratePrivate *priv = calibrate->priv;
-
-	/* setup the measure window */
-	cd_color_rgb_set (&rgb_tmp, 1.0f, 1.0f, 1.0f);
-	cd_sample_window_set_color (CD_SAMPLE_WINDOW (priv->sample_window), &rgb_tmp);
-	cd_sample_window_set_fraction (CD_SAMPLE_WINDOW (priv->sample_window), 0.0f);
-	gtk_window_set_modal (priv->sample_window, TRUE);
-	gtk_window_stick (priv->sample_window);
-	gtk_window_present (priv->sample_window);
-
-	/* lock the sensor */
-	ret = cd_sensor_lock_sync (calibrate->priv->sensor,
-				   NULL,
-				   error);
-	if (!ret)
-		goto out;
-
-	/* capture all the source colors */
-	for (i = 0; i < samples_rgb->len; i++) {
-
-		/* get the source color */
-		rgb = g_ptr_array_index (samples_rgb, i);
-		xyz = g_ptr_array_index (samples_xyz, i);
-
-		g_debug ("Using source color %f,%f,%f",
-			 rgb->R, rgb->G, rgb->B);
-
-		/* set the window color */
-		cd_sample_window_set_color (CD_SAMPLE_WINDOW (priv->sample_window), rgb);
-		cd_sample_window_set_fraction (CD_SAMPLE_WINDOW (priv->sample_window),
-					       i / samples_rgb->len);
-
-		/* wait for the refresh to set the new color */
-		if (i == 0 && !priv->sensor_on_screen) {
-			gcm_calibrate_interaction_attach (calibrate);
-			//FIXME
-			gcm_calibrate_delay (3000);
-			priv->sensor_on_screen = TRUE;
-		}
-		gcm_calibrate_delay (100);
-
-		/* get the sample from the hardware */
-		xyz = cd_sensor_get_sample_sync (priv->sensor,
-						 CD_SENSOR_CAP_LCD,
-						 NULL,
-						 error);
-		if (xyz == NULL) {
-			ret = FALSE;
-			goto out;
-		}
-		g_debug ("sampled %f,%f,%f as %f,%f,%f",
-			 rgb->R, rgb->G, rgb->B,
-			 xyz->X, xyz->Y, xyz->Z);
-		g_ptr_array_add (samples_xyz, xyz);
-	}
-
-	/* unlock the sensor */
-	ret = cd_sensor_unlock_sync (calibrate->priv->sensor,
-				     NULL,
-				     error);
-	if (!ret)
-		goto out;
-out:
-	/* hide the sample window */
-	gtk_widget_hide (GTK_WIDGET (priv->sample_window));
-	return ret;
-}
-
-/**
- * gcm_calibrate_normalize_to_y:
- **/
-static void
-gcm_calibrate_normalize_to_y (GPtrArray *samples_xyz, gdouble scale)
-{
-	CdColorXYZ *xyz;
-	guint i;
-	gdouble normalize = 0.0f;
-
-	/* first, find largest */
-	for (i = 0; i < samples_xyz->len; i++) {
-		xyz = g_ptr_array_index (samples_xyz, i);
-		if (xyz->Y > normalize)
-			normalize = xyz->Y;
-	}
-
-	/* scale all the readings to 100 */
-	normalize = scale / normalize;
-	for (i = 0; i < samples_xyz->len; i++) {
-		xyz = g_ptr_array_index (samples_xyz, i);
-		xyz->X *= normalize;
-		xyz->Y *= normalize;
-		xyz->Z *= normalize;
-	}
-}
-
-/**
- * gcm_calibrate_set_calibration_to_device:
- **/
-static gboolean
-gcm_calibrate_set_calibration_to_device (const gchar *cal_fn,
-					 CdDevice *device,
-					 GError **error)
-{
-	CdColorRGB *rgb;
-	cmsHANDLE cal = NULL;
-	const gchar *tmp;
-	gboolean ret;
-	gchar *cal_data = NULL;
-	GnomeRRCrtc *crtc;
-	GnomeRROutput *output;
-	GnomeRRScreen *screen = NULL;
-	GPtrArray *samples_rgb = NULL;
-	gsize cal_size;
-	guint col;
-	guint i;
-	guint number_of_sets = 0;
-	gushort blue[256];
-	gushort green[256];
-	gushort red[256];
-
-	/* open .cal file */
-	g_debug ("loading %s", cal_fn);
-	ret = g_file_get_contents (cal_fn, &cal_data, &cal_size, error);
-	if (!ret)
-		goto out;
-
-	/* load the cal data */
-	cal = cmsIT8LoadFromMem (NULL, cal_data, cal_size);
-	if (cal == NULL) {
-		ret = FALSE;
-		g_set_error (error, 1, 0, "Cannot open %s", cal_fn);
-		goto out;
-	}
-
-	/* check color format */
-	tmp = cmsIT8GetProperty (cal, "COLOR_REP");
-	if (g_strcmp0 (tmp, "RGB") != 0) {
-		ret = FALSE;
-		g_set_error (error, 1, 0, "Invalid format: %s", tmp);
-		goto out;
-	}
-	number_of_sets = cmsIT8GetPropertyDbl (cal, "NUMBER_OF_SETS");
-	if (number_of_sets != 256) {
-		ret = FALSE;
-		g_set_error (error, 1, 0, "Invalid cal size: %i", number_of_sets);
-		goto out;
-	}
-
-	/* get data */
-	samples_rgb = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_color_rgb_free);
-	for (i = 0; i < number_of_sets; i++) {
-		rgb = cd_color_rgb_new ();
-		col = cmsIT8FindDataFormat(cal, "RGB_R");
-		rgb->R = cmsIT8GetDataRowColDbl(cal, i, col) / 100.0f;
-		col = cmsIT8FindDataFormat(cal, "RGB_G");
-		rgb->G = cmsIT8GetDataRowColDbl(cal, i, col) / 100.0f;
-		col = cmsIT8FindDataFormat(cal, "RGB_B");
-		rgb->B = cmsIT8GetDataRowColDbl(cal, i, col) / 100.0f;
-		g_ptr_array_add (samples_rgb, rgb);
-	}
-
-	/* send it to the screen */
-	screen = gnome_rr_screen_new (gdk_screen_get_default (), error);
-	if (screen == NULL) {
-		ret = FALSE;
-		goto out;
-	}
-	output = gnome_rr_screen_get_output_by_name (screen, "LVDS1");
-	if (output == NULL) {
-		ret = FALSE;
-		g_set_error (error, 1, 0,
-			     "No display with name %s",
-			     "LVDS1");
-	}
-	crtc = gnome_rr_output_get_crtc (output);
-	if (crtc == NULL) {
-		ret = FALSE;
-		g_set_error (error, 1, 0,
-			     "No crtc with for output %s",
-			     gnome_rr_output_get_name (output));
-	}
-	for (i = 0; i < samples_rgb->len; i++) {
-		rgb = g_ptr_array_index (samples_rgb, i);
-		red[0] = rgb->R * 0xffff;
-		green[0] = rgb->G * 0xffff;
-		blue[0] = rgb->B * 0xffff;
-	}
-	gnome_rr_crtc_set_gamma (crtc,
-				 samples_rgb->len,
-				 red,
-				 green,
-				 blue);
-out:
-	g_free (cal_data);
-	if (cal != NULL)
-		cmsIT8Free (cal);
-	if (samples_rgb != NULL)
-		g_ptr_array_unref (samples_rgb);
-	if (screen != NULL)
-		g_object_unref (screen);
-	return ret;
-}
-
-/**
- * gcm_calibrate_display_characterize:
- **/
-gboolean
-gcm_calibrate_display_characterize (GcmCalibrate *calibrate,
-				    const gchar *ti1_fn,
-				    const gchar *cal_fn,
-				    const gchar *ti3_fn,
-				    CdDevice *device,
-				    GtkWindow *window,
-				    GError **error)
-{
-	CdColorRGB *rgb;
-	CdColorXYZ *xyz;
-	cmsHANDLE ti1 = NULL;
-	cmsHANDLE ti3 = NULL;
-	const gchar *tmp;
-	gboolean is_spectral;
-	gboolean ret;
-	gchar *data_cal = NULL;
-	gchar *data_patches = NULL;
-	gchar *found_lcms2_bodge;
-	gchar *ti1_data = NULL;
-	GPtrArray *samples_rgb = NULL;
-	GPtrArray *samples_xyz = NULL;
-	gsize ti1_size;
-	GString *string = NULL;
-	guint col;
-	guint i;
-	guint number_of_sets = 0;
-	guint table_count;
-	GcmCalibratePrivate *priv = calibrate->priv;
-
-	/* need to set cal to the gamma ramps */
-	ret = gcm_calibrate_set_calibration_to_device (cal_fn,
-						       device,
-						       error);
-	if (!ret)
-		goto out;
-
-	/* open ti1 file as input */
-	g_debug ("loading %s", ti1_fn);
-	ret = g_file_get_contents (ti1_fn, &ti1_data, &ti1_size, error);
-	if (!ret)
-		goto out;
-
-	/* hack to fix lcms2 */
-	found_lcms2_bodge = g_strstr_len (ti1_data, ti1_size, "END_DATA\n");
-	if (found_lcms2_bodge != NULL)
-		found_lcms2_bodge[9] = '\0';
-
-	/* load the ti1 data */
-	cmsSetLogErrorHandler (gcm_calibrate_lcms_error_cb);
-	ti1 = cmsIT8LoadFromMem (NULL, ti1_data, ti1_size);
-	if (ti1 == NULL) {
-		ret = FALSE;
-		g_set_error (error, 1, 0, "Cannot open %s", ti1_fn);
-		goto out;
-	}
-
-	/* select correct sheet */
-	table_count = cmsIT8TableCount (ti1);
-	g_debug ("selecting sheet %i of %i (%s)",
-		 0, table_count,
-		 cmsIT8GetSheetType (ti1));
-	cmsIT8SetTable (ti1, 0);
-
-	/* check color format */
-	tmp = cmsIT8GetProperty (ti1, "COLOR_REP");
-	if (g_strcmp0 (tmp, "RGB") != 0) {
-		ret = FALSE;
-		g_set_error (error, 1, 0, "Invalid format: %s", tmp);
-		goto out;
-	}
-	number_of_sets = cmsIT8GetPropertyDbl (ti1, "NUMBER_OF_SETS");
-
-	/* write to a ti3 file as output */
-	ti3 = cmsIT8Alloc (NULL);
-	cmsIT8SetSheetType (ti3, "CTI3");
-	cmsIT8SetPropertyStr (ti3, "DESCRIPTOR",
-			      "Calibration Target chart information 3");
-	cmsIT8SetPropertyStr (ti3, "ORIGINATOR",
-			      "GNOME Color Manager");
-	cmsIT8SetPropertyStr (ti3, "DEVICE_CLASS",
-			      "DISPLAY");
-	cmsIT8SetPropertyStr (ti3, "COLOR_REP",
-			      "RGB_XYZ");
-	cmsIT8SetPropertyStr (ti3, "TARGET_INSTRUMENT",
-			      cd_sensor_get_model (priv->sensor));
-	is_spectral = cd_sensor_has_cap (priv->sensor,
-					 CD_SENSOR_CAP_SPOT);
-	cmsIT8SetPropertyStr (ti3, "INSTRUMENT_TYPE_SPECTRAL",
-			      is_spectral ? "YES" : "NO");
-	cmsIT8SetPropertyStr (ti3, "LUMINANCE_XYZ_CDM2",
-			      "132.922451 129.524179 165.093861");
-	cmsIT8SetPropertyStr (ti3, "NORMALIZED_TO_Y_100", "YES");
-	cmsIT8SetPropertyDbl (ti3, "NUMBER_OF_FIELDS", 7);
-	cmsIT8SetPropertyDbl (ti3, "NUMBER_OF_SETS", number_of_sets);
-	cmsIT8SetDataFormat (ti3, 0, "SAMPLE_ID");
-	cmsIT8SetDataFormat (ti3, 1, "RGB_R");
-	cmsIT8SetDataFormat (ti3, 2, "RGB_G");
-	cmsIT8SetDataFormat (ti3, 3, "RGB_B");
-	cmsIT8SetDataFormat (ti3, 4, "XYZ_X");
-	cmsIT8SetDataFormat (ti3, 5, "XYZ_Y");
-	cmsIT8SetDataFormat (ti3, 6, "XYZ_Z");
-
-	/* work out what colors to show */
-	samples_rgb = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_color_rgb_free);
-	for (i = 0; i < number_of_sets; i++) {
-		rgb = cd_color_rgb_new ();
-		col = cmsIT8FindDataFormat(ti1, "RGB_R");
-		rgb->R = cmsIT8GetDataRowColDbl(ti1, i, col) / 100.0f;
-		col = cmsIT8FindDataFormat(ti1, "RGB_G");
-		rgb->G = cmsIT8GetDataRowColDbl(ti1, i, col) / 100.0f;
-		col = cmsIT8FindDataFormat(ti1, "RGB_B");
-		rgb->B = cmsIT8GetDataRowColDbl(ti1, i, col) / 100.0f;
-		g_ptr_array_add (samples_rgb, rgb);
-	}
-
-	/* actually get samples from the hardware */
-	samples_xyz = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_color_xyz_free);
-	ret = gcm_calibrate_get_samples (calibrate,
-					 samples_rgb,
-					 samples_xyz,
-					 error);
-	if (!ret)
-		goto out;
-
-	/* normalize */
-	gcm_calibrate_normalize_to_y (samples_xyz, 100.0f);
-
-	/* write to the ti3 file */
-	for (i = 0; i < samples_rgb->len; i++) {
-		rgb = g_ptr_array_index (samples_rgb, i);
-		xyz = g_ptr_array_index (samples_xyz, i);
-		cmsIT8SetDataRowColDbl(ti3, i, 0, i + 1);
-		cmsIT8SetDataRowColDbl(ti3, i, 1, rgb->R * 100.0f);
-		cmsIT8SetDataRowColDbl(ti3, i, 2, rgb->G * 100.0f);
-		cmsIT8SetDataRowColDbl(ti3, i, 3, rgb->B * 100.0f);
-		cmsIT8SetDataRowColDbl(ti3, i, 4, xyz->X);
-		cmsIT8SetDataRowColDbl(ti3, i, 5, xyz->Y);
-		cmsIT8SetDataRowColDbl(ti3, i, 6, xyz->Z);
-	}
-
-	/* write the file */
-	ret = cmsIT8SaveToFile (ti3, ti3_fn);
-	if (!ret)
-		g_assert_not_reached ();
-
-	/* get the patches data */
-	ret = g_file_get_contents (ti3_fn, &data_patches, NULL, error);
-	if (!ret)
-		goto out;
-
-	/* get the cal data */
-	ret = g_file_get_contents (cal_fn, &data_cal, NULL, error);
-	if (!ret)
-		goto out;
-
-	/* write new ti3 file with cal file appended */
-	string = g_string_new ("");
-	g_string_append (string, data_patches);
-	g_string_append (string, data_cal);
-	ret = g_file_set_contents (ti3_fn, string->str, -1, error);
-	if (!ret)
-		goto out;
-out:
-	if (ti1 != NULL)
-		cmsIT8Free (ti1);
-	if (ti3 != NULL)
-		cmsIT8Free (ti3);
-	if (samples_rgb != NULL)
-		g_ptr_array_unref (samples_rgb);
-	if (samples_xyz != NULL)
-		g_ptr_array_unref (samples_xyz);
-	if (string != NULL)
-		g_string_free (string, TRUE);
-	g_free (ti1_data);
-	g_free (data_patches);
-	g_free (data_cal);
-	return ret;
-}
-
-/**
- * gcm_calibrate_calculate_native_gamma:
- **/
-static gboolean
-gcm_calibrate_calculate_native_gamma (GPtrArray *samples_xyz,
-				      gdouble *native_gamma,
-				      GError **error)
-{
-	CdColorXYZ *xyz;
-	cmsFloat32Number values[256];
-	cmsToneCurve *curve;
-	gboolean ret = TRUE;
-	gdouble largest = G_MINDOUBLE;
-	gdouble smallest = G_MAXDOUBLE;
-	gdouble tmp;
-	guint i;
-
-	/* scale from 0.0 to 1.0 */
-	for (i = 0; i < samples_xyz->len; i++) {
-		xyz = g_ptr_array_index (samples_xyz, i);
-		if (xyz->Y < smallest)
-			smallest = xyz->Y;
-		if (xyz->Y > largest)
-			largest = xyz->Y;
-	}
-	for (i = 0; i < samples_xyz->len; i++) {
-		xyz = g_ptr_array_index (samples_xyz, i);
-		values[i] = (xyz->Y - smallest) * 1.0f / (largest - smallest);
-	}
-
-	/* find estimate */
-	curve = cmsBuildTabulatedToneCurveFloat (NULL,
-						 samples_xyz->len,
-						 values);
-	tmp = cmsEstimateGamma (curve, 1000.1f);
-	if (tmp < 0) {
-		ret = FALSE;
-		g_set_error_literal (error, 1, 0,
-				     "Failed to calculate native gamma");
-		goto out;
-	}
-
-	/* success */
-	ret = TRUE;
-	if (native_gamma != NULL)
-		*native_gamma = tmp;
-out:
-	cmsFreeToneCurve (curve);
-	return ret;
-}
-
-/**
- * gcm_calibrate_convert_xyz_to_rgb:
- **/
-static gboolean
-gcm_calibrate_convert_xyz_to_rgb (GPtrArray *samples_xyz,
-				  GPtrArray *samples_primaries,
-				  GPtrArray *results_rgb,
-				  GError **error)
-{
-	CdColorRGB *rgb;
-	CdColorXYZ *xyz;
-	cmsCIExyYTRIPLE primaries;
-	cmsCIExyY whitepoint;
-	cmsHPROFILE conversion_profile = NULL;
-	cmsHPROFILE xyz_profile = NULL;
-	cmsHTRANSFORM transform = NULL;
-	cmsToneCurve *transfer_curve[3] = { NULL, NULL, NULL };
-	gdouble target_gamma;
-	gboolean ret = TRUE;
-	gdouble temperature;
-	guint i;
-
-	/* hardcode the gamma */
-	target_gamma = 2.4f;
-
-	/* calculate the native whitepoint */
-	xyz = g_ptr_array_index (samples_primaries, 3);
-	cmsXYZ2xyY (&whitepoint, (cmsCIEXYZ*) xyz);
-	cmsTempFromWhitePoint (&temperature, &whitepoint);
-	g_debug ("native whitepoint=%f,%f [scale:%f] (%fK)",
-		 whitepoint.x, whitepoint.y, whitepoint.Y, temperature);
-
-	/* get the primaries */
-	xyz = g_ptr_array_index (samples_primaries, 0);
-	cmsXYZ2xyY (&primaries.Red, (cmsCIEXYZ*) xyz);
-	xyz = g_ptr_array_index (samples_primaries, 1);
-	cmsXYZ2xyY (&primaries.Green, (cmsCIEXYZ*) xyz);
-	xyz = g_ptr_array_index (samples_primaries, 2);
-	cmsXYZ2xyY (&primaries.Blue, (cmsCIEXYZ*) xyz);
-	g_debug ("red=%f,%f green=%f,%f blue=%f,%f",
-		 primaries.Red.x, primaries.Red.y,
-		 primaries.Green.x, primaries.Green.y,
-		 primaries.Blue.x, primaries.Blue.y);
-
-	/* setup transform */
-	transfer_curve[0] = transfer_curve[1] = transfer_curve[2] = cmsBuildGamma (NULL, target_gamma);
-	conversion_profile = cmsCreateRGBProfile (&whitepoint,
-						  &primaries,
-						  transfer_curve);
-	if (conversion_profile == NULL) {
-		ret = FALSE;
-		g_set_error_literal (error, 1, 0,
-				     "Failed to create conversion profile");
-		goto out;
-	}
-	xyz_profile = cmsCreateXYZProfile ();
-	transform = cmsCreateTransform (xyz_profile, TYPE_XYZ_DBL,
-					conversion_profile, TYPE_RGB_DBL,
-					INTENT_RELATIVE_COLORIMETRIC, 0);
-	if (transform == NULL) {
-		ret = FALSE;
-		g_set_error_literal (error, 1, 0,
-				     "Failed to create transform");
-		goto out;
-	}
-
-	/* convert samples */
-	for (i = 0; i < samples_xyz->len; i++) {
-		xyz = g_ptr_array_index (samples_xyz, i);
-		rgb = cd_color_rgb_new ();
-		cmsDoTransform (transform, xyz, rgb, 1);
-		g_debug ("%f,%f,%f -> %f,%f,%f",
-			 xyz->X, xyz->Y, xyz->Z,
-			 rgb->R, rgb->G, rgb->B);
-		g_ptr_array_add (results_rgb, rgb);
-	}
-
-	/* done */
-out:
-	cmsFreeToneCurve (*transfer_curve);
-	cmsCloseProfile (xyz_profile);
-	cmsCloseProfile (conversion_profile);
-	if (transform != NULL)
-		cmsDeleteTransform (transform);
-	return ret;
-}
-
-/**
- * gcm_calibrate_get_primaries:
- **/
-static gboolean
-gcm_calibrate_get_primaries (GcmCalibrate *calibrate,
-			     GPtrArray *samples_primaries,
-			     GError **error)
-{
-	CdColorRGB *rgb;
-	gboolean ret;
-	GPtrArray *samples_rgb = NULL;
-
-	/* add primaries to array */
-	samples_rgb = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_color_rgb_free);
-
-	/* red */
-	rgb = cd_color_rgb_new ();
-	cd_color_rgb_set (rgb, 1.0f, 0.0f, 0.0f);
-	g_ptr_array_add (samples_rgb, rgb);
-
-	/* green */
-	rgb = cd_color_rgb_new ();
-	cd_color_rgb_set (rgb, 0.0f, 1.0f, 0.0f);
-	g_ptr_array_add (samples_rgb, rgb);
-
-	/* blue */
-	rgb = cd_color_rgb_new ();
-	cd_color_rgb_set (rgb, 0.0f, 0.0f, 1.0f);
-	g_ptr_array_add (samples_rgb, rgb);
-
-	/* white */
-	rgb = cd_color_rgb_new ();
-	cd_color_rgb_set (rgb, 1.0f, 1.0f, 1.0f);
-	g_ptr_array_add (samples_rgb, rgb);
-
-	/* black */
-	rgb = cd_color_rgb_new ();
-	cd_color_rgb_set (rgb, 0.0f, 0.0f, 0.0f);
-	g_ptr_array_add (samples_rgb, rgb);
-
-	/* measure */
-	ret = gcm_calibrate_get_samples (calibrate,
-					 samples_rgb,
-					 samples_primaries,
-					 error);
-	if (!ret)
-		goto out;
-out:
-	if (samples_rgb != NULL)
-		g_ptr_array_unref (samples_rgb);
-	return ret;
-}
-
-/**
- * gcm_calibrate_resize_results:
- *
- * Linearly interpolate an array of data into a differently sized array.
- **/
-static void
-gcm_calibrate_resize_results (GPtrArray *src_array,
-			      GPtrArray *dest_array,
-			      guint new_size)
-{
-	gdouble amount;
-	gdouble div;
-	guint i;
-	guint reg1, reg2;
-	CdColorRGB *dest;
-	CdColorRGB *src1;
-	CdColorRGB *src2;
-
-	/* gcm_calibrate_native_ */
-	for (i = 0; i < new_size; i++) {
-		div = i * ((src_array->len - 1) / (gdouble) (new_size - 1));
-		reg1 = floor (div);
-		reg2 = ceil (div);
-		dest = cd_color_rgb_new ();
-		if (reg1 == reg2) {
-			/* no interpolation reqd */
-			src1 = g_ptr_array_index (src_array, reg1);
-			cd_color_rgb_copy (src1, dest);
-		} else {
-			amount = div - (gdouble) reg1;
-			src1 = g_ptr_array_index (src_array, reg1);
-			src2 = g_ptr_array_index (src_array, reg2);
-			dest->R = src1->R * (1.0f - amount) + src2->R * amount;
-			dest->G = src1->G * (1.0f - amount) + src2->G * amount;
-			dest->B = src1->B * (1.0f - amount) + src2->B * amount;
-		}
-		g_ptr_array_add (dest_array, dest);
-	}
-}
-
-/**
- * gcm_calibrate_array_remove_offset:
- **/
-static void
-gcm_calibrate_array_remove_offset (GPtrArray *array)
-{
-	CdColorRGB offset;
-	CdColorRGB *rgb;
-	guint i;
-
-	/* remove the backlight leakage */
-	cd_color_rgb_set (&offset,
-			  G_MAXDOUBLE,
-			  G_MAXDOUBLE,
-			  G_MAXDOUBLE);
-	for (i = 0; i < array->len; i++) {
-		rgb = g_ptr_array_index (array, i);
-		if (rgb->R < offset.R)
-			offset.R = rgb->R;
-		if (rgb->G < offset.G)
-			offset.G = rgb->G;
-		if (rgb->B < offset.B)
-			offset.B = rgb->B;
-	}
-	for (i = 0; i < array->len; i++) {
-		rgb = g_ptr_array_index (array, i);
-		rgb->R -= offset.R;
-		rgb->G -= offset.G;
-		rgb->B -= offset.B;
-		if (rgb->R < 0.0f)
-			rgb->R = 0.0f;
-		if (rgb->G < 0.0f)
-			rgb->G = 0.0f;
-		if (rgb->B < 0.0f)
-			rgb->B = 0.0f;
-	}
-	g_debug ("removed offset = %f,%f,%f",
-		 offset.R, offset.G, offset.B);
-}
-
-/**
- * gcm_calibrate_array_scale:
- **/
-static void
-gcm_calibrate_array_scale (GPtrArray *array, gdouble value)
-{
-	CdColorRGB *rgb;
-	CdColorRGB scale;
-	guint i;
-
-	/* scale all values */
-	cd_color_rgb_set (&scale,
-			  G_MINDOUBLE,
-			  G_MINDOUBLE,
-			  G_MINDOUBLE);
-	for (i = 0; i < array->len; i++) {
-		rgb = g_ptr_array_index (array, i);
-		if (rgb->R > scale.R)
-			scale.R = rgb->R;
-		if (rgb->G > scale.G)
-			scale.G = rgb->G;
-		if (rgb->B > scale.B)
-			scale.B = rgb->B;
-	}
-	for (i = 0; i < array->len; i++) {
-		rgb = g_ptr_array_index (array, i);
-		rgb->R /= scale.R;
-		rgb->G /= scale.G;
-		rgb->B /= scale.B;
-	}
-	g_debug ("scaled to 1.0 using = %f,%f,%f",
-		 scale.R, scale.G, scale.B);
-}
-
-/**
- * gcm_calibrate_array_ensure_monotonic:
- **/
-static void
-gcm_calibrate_array_ensure_monotonic (GPtrArray *array)
-{
-	CdColorRGB *rgb;
-	CdColorRGB *rgb_last;
-	guint i;
-
-	/* check each is going up compared to last reading */
-	for (i = 1; i <array->len; i++) {
-		rgb_last = g_ptr_array_index (array, i - 1);
-		rgb = g_ptr_array_index (array, i);
-		if (rgb->R < rgb_last->R)
-			rgb->R = rgb_last->R;
-		if (rgb->G < rgb_last->G)
-			rgb->G = rgb_last->G;
-		if (rgb->B < rgb_last->B)
-			rgb->B = rgb_last->B;
-	}
-}
-
-/**
- * gcm_calibrate_display_calibration:
- **/
-gboolean
-gcm_calibrate_display_calibration (GcmCalibrate *calibrate,
-				   const gchar *cal_fn,
-				   CdDevice *device,
-				   GtkWindow *window,
-				   GError **error)
-{
-	CdColorRGB *rgb;
-	CdColorXYZ *xyz_black;
-	CdColorXYZ *xyz_white;
-	cmsHANDLE cal = NULL;
-	gboolean ret;
-	gdouble frac = 0.0f;
-	gdouble native_gamma = 0.0f;
-	GPtrArray *results_rgb = NULL;
-	GPtrArray *results_vcgt = NULL;
-	GPtrArray *samples_rgb = NULL;
-	GPtrArray *samples_primaries = NULL;
-	GPtrArray *samples_xyz = NULL;
-	guint i;
-	guint vcgt_size = 32;
-
-	/* this is global, ick */
-	cmsSetLogErrorHandler (gcm_calibrate_lcms_error_cb);
-
-	/* get the primaries */
-	samples_primaries = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_color_yxy_free);
-	ret = gcm_calibrate_get_primaries (calibrate,
-					   samples_primaries,
-					   error);
-	if (!ret)
-		goto out;
-
-	/* check this was sane */
-	xyz_white = g_ptr_array_index (samples_primaries, 3);
-	xyz_black = g_ptr_array_index (samples_primaries, 4);
-	if (xyz_white->X / xyz_black->X < 3) {
-		ret = FALSE;
-		g_set_error_literal (error, 1, 0,
-				     "Invalid read, is sensor attached to the screen?");
-		goto out;
-	}
-
-	/* get the gamma values */
-	samples_rgb = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_color_rgb_free);
-	for (i = 0; i < vcgt_size; i++) {
-		rgb = cd_color_rgb_new ();
-		frac = (1.0f * (gdouble) i) / (gdouble) (vcgt_size - 1);
-		rgb->R = frac;
-		rgb->G = frac;
-		rgb->B = frac;
-		g_ptr_array_add (samples_rgb, rgb);
-	}
-
-	/* actually get samples from the hardware */
-	samples_xyz = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_color_xyz_free);
-	ret = gcm_calibrate_get_samples (calibrate,
-					 samples_rgb,
-					 samples_xyz,
-					 error);
-	if (!ret)
-		goto out;
-
-	/* calculate the native gamma */
-	ret = gcm_calibrate_calculate_native_gamma (samples_xyz,
-						    &native_gamma,
-						    error);
-	if (!ret)
-		goto out;
-	g_debug ("Native Gamma: %f", native_gamma);
-
-	/* convert from XYZ to RGB */
-	results_rgb = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_color_rgb_free);
-	ret = gcm_calibrate_convert_xyz_to_rgb (samples_xyz,
-						samples_primaries,
-						results_rgb,
-						error);
-	if (!ret)
-		goto out;
-
-	/* bias the values to zero */
-	gcm_calibrate_array_remove_offset (results_rgb);
-
-	/* scale the largest number to 1.0 */
-	gcm_calibrate_array_scale (results_rgb, 1.0f);
-
-	/* ensure results are monotonic */
-	gcm_calibrate_array_ensure_monotonic (results_rgb);
-
-	/* interpolate new array with correct size */
-	results_vcgt = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_color_rgb_free);
-	gcm_calibrate_resize_results (results_rgb, results_vcgt, 256);
-
-	/* write to a cal file as calibration */
-	cal = cmsIT8Alloc (NULL);
-	cmsIT8SetSheetType (cal, "CAL");
-	cmsIT8SetPropertyStr (cal, "DESCRIPTOR",
-			      "Device Calibration State");
-	cmsIT8SetPropertyStr (cal, "ORIGINATOR",
-			      "GNOME Color Manager");
-	cmsIT8SetPropertyStr (cal, "DEVICE_CLASS",
-			      "DISPLAY");
-	cmsIT8SetPropertyStr (cal, "COLOR_REP",
-			      "RGB");
-	cmsIT8SetPropertyDbl (cal, "NUMBER_OF_FIELDS", 4);
-	cmsIT8SetPropertyDbl (cal, "NUMBER_OF_SETS", results_vcgt->len);
-	cmsIT8SetDataFormat (cal, 0, "RGB_I");
-	cmsIT8SetDataFormat (cal, 1, "RGB_R");
-	cmsIT8SetDataFormat (cal, 2, "RGB_G");
-	cmsIT8SetDataFormat (cal, 3, "RGB_B");
-	for (i = 0; i < results_vcgt->len; i++) {
-		frac = (1.0f * (gdouble) i) / (gdouble) (results_vcgt->len - 1);
-		rgb = g_ptr_array_index (results_vcgt, i);
-		cmsIT8SetDataRowColDbl(cal, i, 0, frac);
-		cmsIT8SetDataRowColDbl(cal, i, 1, rgb->R);
-		cmsIT8SetDataRowColDbl(cal, i, 2, rgb->G);
-		cmsIT8SetDataRowColDbl(cal, i, 3, rgb->B);
-	}
-
-	/* write the file */
-	ret = cmsIT8SaveToFile (cal, cal_fn);
-	if (!ret)
-		g_assert_not_reached ();
-out:
-	if (cal != NULL)
-		cmsIT8Free (cal);
-	if (results_rgb != NULL)
-		g_ptr_array_unref (results_rgb);
-	if (results_vcgt != NULL)
-		g_ptr_array_unref (results_vcgt);
-	if (samples_rgb != NULL)
-		g_ptr_array_unref (samples_rgb);
-	if (samples_primaries != NULL)
-		g_ptr_array_unref (samples_primaries);
-	if (samples_xyz != NULL)
-		g_ptr_array_unref (samples_xyz);
-	return ret;
-}
-
-/**
  * gcm_calibrate_set_brightness:
  **/
 static void
@@ -1558,31 +641,6 @@ gcm_calibrate_display (GcmCalibrate *calibrate,
 	if (!ret)
 		goto out;
 
-	/* if sensor is native, then take some measurements */
-	if (FALSE && cd_sensor_get_native (calibrate->priv->sensor)) {
-		cal_fn = g_strdup_printf ("%s/%s.cal",
-					  priv->working_path,
-					  priv->basename);
-		ret = gcm_calibrate_display_calibration (calibrate,
-							 cal_fn,
-							 device,
-							 window,
-							 error);
-		if (!ret)
-			goto out;
-		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,
-							  error);
-		goto out;
-	}
-
 	/* coldplug source */
 	if (klass->calibrate_display == NULL) {
 		ret = FALSE;
diff --git a/src/gcm-calibrate.h b/src/gcm-calibrate.h
index 98554fc..b3d9d95 100644
--- a/src/gcm-calibrate.h
+++ b/src/gcm-calibrate.h
@@ -176,20 +176,6 @@ const gchar	*gcm_calibrate_get_filename_result	(GcmCalibrate	*calibrate);
 const gchar	*gcm_calibrate_get_working_path		(GcmCalibrate	*calibrate);
 const gchar	*gcm_calibrate_get_basename		(GcmCalibrate	*calibrate);
 guint		 gcm_calibrate_get_screen_brightness	(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,
-							 GError		**error);
-gboolean	 gcm_calibrate_display_calibration	(GcmCalibrate	*calibrate,
-							 const gchar	*cal_fn,
-							 CdDevice	*device,
-							 GtkWindow	*window,
-							 GError		**error);
 gboolean	 gcm_calibrate_get_enabled		(GcmCalibrate	*calibrate);
 
 G_END_DECLS



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