[gnome-color-manager] Calculate the native gamma from the XYZ readings
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Calculate the native gamma from the XYZ readings
- Date: Mon, 28 Nov 2011 21:35:39 +0000 (UTC)
commit fa5b6b2cd5f3132e4b884cf58279ab70697b594b
Author: Richard Hughes <richard hughsie com>
Date: Mon Nov 28 21:16:23 2011 +0000
Calculate the native gamma from the XYZ readings
src/gcm-calibrate.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index 922138c..25f0e4f 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -892,6 +892,57 @@ out:
}
/**
+ * 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_get_primaries:
**/
static gboolean
@@ -959,6 +1010,7 @@ gcm_calibrate_display_calibration (GcmCalibrate *calibrate,
CdColorXYZ *xyz_white;
gboolean ret;
gdouble frac = 0.0f;
+ gdouble native_gamma = 0.0f;
GPtrArray *samples_rgb = NULL;
GPtrArray *samples_primaries = NULL;
GPtrArray *samples_xyz = NULL;
@@ -1005,6 +1057,15 @@ gcm_calibrate_display_calibration (GcmCalibrate *calibrate,
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);
+
out:
if (samples_rgb != NULL)
g_ptr_array_unref (samples_rgb);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]