summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2013-04-09 21:47:10 +0100
committerRichard Hughes <richard@hughsie.com>2013-04-09 21:47:10 +0100
commit5d19bc568d1b6eb45842f3dfe4d034b2f805ec02 (patch)
tree5d0624ae63bd8dc6f0ff24b20d7219b6d6c3ae01
parent84804cfa08ddbda4be6998eea7d0c8921163bd1b (diff)
downloadcolord-5d19bc568d1b6eb45842f3dfe4d034b2f805ec02.tar.gz
Check the generated CCMX matrix for invalid data
We never want to write a CCMX with -nan or +inf values.
-rw-r--r--lib/colord/cd-it8-utils.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/colord/cd-it8-utils.c b/lib/colord/cd-it8-utils.c
index e62d1ff..1ca1b63 100644
--- a/lib/colord/cd-it8-utils.c
+++ b/lib/colord/cd-it8-utils.c
@@ -29,6 +29,7 @@
#include "config.h"
#include <glib-object.h>
+#include <math.h>
#include "cd-color.h"
#include "cd-it8-utils.h"
@@ -193,10 +194,12 @@ cd_it8_utils_calculate_ccmx (CdIt8 *it8_reference,
CdMat3x3 m_rgb;
CdMat3x3 m_rgb_inv;
CdMat3x3 n_rgb;
+ const gdouble *data;
gboolean ret;
gchar *tmp = NULL;
gdouble m_lumi = 0.0f;
gdouble n_lumi = 0.0f;
+ guint i;
/* read reference matrix */
ret = ch_it8_utils_4color_decompose (it8_reference, &n_rgb, &n_lumi, error);
@@ -228,6 +231,17 @@ cd_it8_utils_calculate_ccmx (CdIt8 *it8_reference,
tmp = cd_mat33_to_string (&calibration);
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) {
+ ret = FALSE;
+ g_set_error (error, 1, 0,
+ "Matrix value %i non-normal: %f", i, data[i]);
+ goto out;
+ }
+ }
+
/* save to ccmx file */
cd_it8_set_matrix (it8_ccmx, &calibration);
cd_it8_set_instrument (it8_ccmx, cd_it8_get_instrument (it8_measured));