summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Plattner <aplattner@nvidia.com>2020-02-21 08:32:35 -0800
committerRichard Hughes <richard@hughsie.com>2020-03-23 19:52:27 +0000
commit78365e9b5ecf6352ed95f46d8dde0313e10c5796 (patch)
tree2fe6e2af93d5e32375255ed6e761fd3e6c43b21c
parent1572d92bb69de7632841bf17f3cb81534881c3c6 (diff)
downloadcolord-78365e9b5ecf6352ed95f46d8dde0313e10c5796.tar.gz
libcolord: Add cd_mat33_is_finite
Move the logic to check whether any entries in a matrix are NaN or infinite from cd_it8_utils_calculate_ccmx into a helper function in cd-math.c. In addition, fix a bug in this code: if any entries of the matrix are exactly zero, then fpclassify will return FP_ZERO instead of FP_NORMAL. Don't treat this as a failure: only FP_NAN and FP_INFINITE are errors.
-rw-r--r--lib/colord/cd-it8-utils.c12
-rw-r--r--lib/colord/cd-math.c27
-rw-r--r--lib/colord/cd-math.h2
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__