diff options
-rw-r--r-- | lib/colord/cd-it8-utils.c | 12 | ||||
-rw-r--r-- | lib/colord/cd-math.c | 27 | ||||
-rw-r--r-- | lib/colord/cd-math.h | 2 |
3 files changed, 31 insertions, 10 deletions
diff --git a/lib/colord/cd-it8-utils.c b/lib/colord/cd-it8-utils.c index 90f57f0..38ae042 100644 --- a/lib/colord/cd-it8-utils.c +++ b/lib/colord/cd-it8-utils.c @@ -183,10 +183,8 @@ cd_it8_utils_calculate_ccmx (CdIt8 *it8_reference, CdMat3x3 m_rgb; CdMat3x3 m_rgb_inv; CdMat3x3 n_rgb; - const gdouble *data; gdouble m_lumi = 0.0f; gdouble n_lumi = 0.0f; - guint i; g_autofree gchar *tmp = NULL; /* read reference matrix */ @@ -217,14 +215,8 @@ cd_it8_utils_calculate_ccmx (CdIt8 *it8_reference, g_debug ("device calibration = %s", tmp); /* check there are no nan's or inf's */ - data = cd_mat33_get_data (&calibration); - for (i = 0; i < 9; i++) { - if (fpclassify (data[i]) != FP_NORMAL) { - g_set_error (error, 1, 0, - "Matrix value %u non-normal: %f", i, data[i]); - return FALSE; - } - } + if (!cd_mat33_is_finite (&calibration, error)) + return FALSE; /* save to ccmx file */ cd_it8_set_matrix (it8_ccmx, &calibration); diff --git a/lib/colord/cd-math.c b/lib/colord/cd-math.c index 2eacaae..db98b08 100644 --- a/lib/colord/cd-math.c +++ b/lib/colord/cd-math.c @@ -453,3 +453,30 @@ cd_mat33_copy (const CdMat3x3 *src, CdMat3x3 *dest) g_return_if_fail (src != dest); memcpy (dest, src, sizeof (CdMat3x3)); } + +/** + * cd_mat33_is_finite: + * @mat: the matrix to test + * @error: (out): A #GError, or %NULL + * + * Determine whether all entries in the specified matrix are finite and not + * NaNs. + * + * Return value: %TRUE if isfinite() returns %TRUE for all values. + */ +gboolean +cd_mat33_is_finite (const CdMat3x3 *mat, GError **error) +{ + const gdouble *data = cd_mat33_get_data (mat); + + for (guint i = 0; i < 9; i++) { + if (!isfinite (data[i])) { + g_set_error (error, 1, 0, + "Matrix value %u non-normal: %f", + i, data[i]); + return FALSE; + } + } + + return TRUE; +} diff --git a/lib/colord/cd-math.h b/lib/colord/cd-math.h index 5f6c39c..70492b4 100644 --- a/lib/colord/cd-math.h +++ b/lib/colord/cd-math.h @@ -88,6 +88,8 @@ void cd_mat33_normalize (const CdMat3x3 *src, CdMat3x3 *dest); void cd_mat33_copy (const CdMat3x3 *src, CdMat3x3 *dest); +gboolean cd_mat33_is_finite (const CdMat3x3 *mat, + GError **error); #undef __CD_MATH_H_INSIDE__ |