summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-10-13 10:49:22 +0100
committerRichard Hughes <richard@hughsie.com>2015-10-13 10:49:22 +0100
commit458e7779b41c4f58164dcdb52b7bd1ff3e9e210e (patch)
treec246426e3bd61480313259e2e293eb4ad3f1b087
parentce88ff07ebf1b6500c542f82fe07b36554be6ca3 (diff)
downloadcolord-458e7779b41c4f58164dcdb52b7bd1ff3e9e210e.tar.gz
libcolord: Return an error when we fail to estimate the gamma value
-rw-r--r--lib/colord/cd-it8-utils.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/colord/cd-it8-utils.c b/lib/colord/cd-it8-utils.c
index fd55713..dc2786b 100644
--- a/lib/colord/cd-it8-utils.c
+++ b/lib/colord/cd-it8-utils.c
@@ -493,6 +493,7 @@ cd_it8_utils_calculate_gamma (CdIt8 *it8, gdouble *gamma_y, GError **error)
gdouble max = 0.f;
guint cnt = 0;
guint i;
+ gdouble gamma_tmp = 0.f;
_cleanup_free_ cmsFloat32Number *data_y = NULL;
/* find the grey gamma ramp */
@@ -534,8 +535,21 @@ cd_it8_utils_calculate_gamma (CdIt8 *it8, gdouble *gamma_y, GError **error)
/* use lcms2 to calculate the gamma */
curve = cmsBuildTabulatedToneCurveFloat (NULL, cnt, data_y);
+ gamma_tmp = cmsEstimateGamma (curve, 0.1);
+ if (gamma_tmp < 0) {
+ _cleanup_string_free_ GString *str = NULL;
+ str = g_string_new ("Unable to calculate gamma from: ");
+ for (i = 0; i < cnt; i++)
+ g_string_append_printf (str, "%f, ", data_y[i]);
+ g_string_truncate (str, str->len - 2);
+ g_set_error_literal (error,
+ CD_IT8_ERROR,
+ CD_IT8_ERROR_FAILED,
+ str->str);
+ return FALSE;
+ }
if (gamma_y != NULL)
- *gamma_y = cmsEstimateGamma (curve, 0.1);
+ *gamma_y = gamma_tmp;
cmsFreeToneCurve (curve);
return TRUE;
}