Bug 1463424 - Fix divide by zeroes in qcms. r=Bas

This commit is contained in:
Nicolas Silva 2018-05-28 11:34:03 +02:00
parent 84ed3147e4
commit b2c558ac48
2 changed files with 14 additions and 3 deletions

View File

@ -64,10 +64,11 @@ struct matrix matrix_invert(struct matrix mat)
if (det == 0) {
dest_mat.invalid = true;
} else {
dest_mat.invalid = false;
return dest_mat;
}
dest_mat.invalid = false;
det = 1/det;
for (j = 0; j < 3; j++) {

View File

@ -168,6 +168,9 @@ static struct matrix build_RGB_to_XYZ_transfer_matrix(qcms_CIE_xyY white, qcms_C
white_point.v[2] = (1.0-xn-yn)/yn;
primaries_invert = matrix_invert(primaries);
if (primaries_invert.invalid) {
return matrix_invalid();
}
coefs = matrix_eval(primaries_invert, white_point);
@ -225,6 +228,9 @@ compute_chromatic_adaption(struct CIE_XYZ source_white_point,
tmp = chad;
chad_inv = matrix_invert(tmp);
if (chad_inv.invalid) {
return matrix_invalid();
}
cone_source_XYZ.v[0] = source_white_point.X;
cone_source_XYZ.v[1] = source_white_point.Y;
@ -272,12 +278,16 @@ static struct matrix adapt_matrix_to_D50(struct matrix r, qcms_CIE_xyY source_wh
struct CIE_XYZ Dn;
struct matrix Bradford;
if (source_white_pt.y == 0.0)
if (source_white_pt.y == 0.0) {
return matrix_invalid();
}
Dn = xyY2XYZ(source_white_pt);
Bradford = adaption_matrix(Dn, D50_XYZ);
if (Bradford.invalid) {
return matrix_invalid();
}
return matrix_multiply(Bradford, r);
}