Bug 489133 - Fix handling of bad whitepoints in PNGs. r=joe
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Tue, 21 Apr 2009 22:21:13 -0400
changeset 27597 f517a1635447b31545e8f020be60a71b6e7a330d
parent 27596 91d04ba2a833996d805a186b862f14be60e8b12e
child 27598 2c04f555a23b5b49e58fd5a4a8e32980d82e563d
push id6639
push userjdrew@mozilla.com
push dateWed, 22 Apr 2009 02:23:11 +0000
treeherdermozilla-central@3c1e1b765d31 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs489133
milestone1.9.2a1pre
Bug 489133 - Fix handling of bad whitepoints in PNGs. r=joe
gfx/qcms/transform.c
--- a/gfx/qcms/transform.c
+++ b/gfx/qcms/transform.c
@@ -177,16 +177,24 @@ struct matrix matrix_identity(void)
 	i.m[1][2] = 0;
 	i.m[2][0] = 0;
 	i.m[2][1] = 0;
 	i.m[2][2] = 1;
 	i.invalid = false;
 	return i;
 }
 
+static struct matrix matrix_invalid(void)
+{
+	struct matrix inv = matrix_identity();
+	inv.invalid = true;
+	return inv;
+}
+
+
 /* from pixman */
 /* MAT3per... */
 struct matrix matrix_multiply(struct matrix a, struct matrix b)
 {
 	struct matrix result;
 	int dx, dy;
 	int o;
 	for (dy = 0; dy < 3; dy++) {
@@ -368,16 +376,19 @@ static struct matrix build_RGB_to_XYZ_tr
 	double xn, yn;
 	double xr, yr;
 	double xg, yg;
 	double xb, yb;
 
 	xn = white.x;
 	yn = white.y;
 
+	if (yn == 0.0)
+		return matrix_invalid();
+
 	xr = primrs.red.x;
 	yr = primrs.red.y;
 	xg = primrs.green.x;
 	yg = primrs.green.y;
 	xb = primrs.blue.x;
 	yb = primrs.blue.y;
 
 	primaries.m[0][0] = xr;
@@ -496,16 +507,20 @@ adaption_matrix(struct CIE_XYZ source_il
 	return compute_chromatic_adaption(source_illumination, target_illumination, lam_rigg);
 }
 
 /* from lcms: cmsAdaptMatrixToD50 */
 static struct matrix adapt_matrix_to_D50(struct matrix r, qcms_CIE_xyY source_white_pt)
 {
 	struct CIE_XYZ Dn;
 	struct matrix Bradford;
+
+	if (source_white_pt.y == 0.0)
+		return matrix_invalid();
+
 	Dn = xyY2XYZ(source_white_pt);
 
 	Bradford = adaption_matrix(Dn, D50_XYZ);
 	return matrix_multiply(Bradford, r);
 }
 
 void set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries)
 {