Bug 498245. Profiles with negative colorant tristiumlus values are bogus. r=bholley
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Thu, 02 Jul 2009 11:34:06 -0400
changeset 29964 b95e64e9431e35365bcc82c9695ee89e95c5d6ce
parent 29963 8a3cfb3a4c216e5da6b515e23a2aba80b36b538b
child 29965 a59ff49215b54a52455abc36cd14cd3d29303b17
push id7847
push userjmuizelaar@mozilla.com
push dateThu, 02 Jul 2009 15:36:15 +0000
treeherdermozilla-central@a59ff49215b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs498245
milestone1.9.2a1pre
Bug 498245. Profiles with negative colorant tristiumlus values are bogus. r=bholley Make sure we reject these profiles.
gfx/qcms/iccread.c
--- a/gfx/qcms/iccread.c
+++ b/gfx/qcms/iccread.c
@@ -218,28 +218,47 @@ static struct tag_index read_tag_table(q
 }
 
 // Checks a profile for obvious inconsistencies and returns
 // true if the profile looks bogus and should probably be
 // ignored.
 qcms_bool qcms_profile_is_bogus(qcms_profile *profile)
 {
        float sum[3], target[3], tolerance[3];
+       float rX, rY, rZ, gX, gY, gZ, bX, bY, bZ;
+       bool negative;
        unsigned i;
 
-       // Sum the values
-       sum[0] = s15Fixed16Number_to_float(profile->redColorant.X) +
-	       s15Fixed16Number_to_float(profile->greenColorant.X) +
-	       s15Fixed16Number_to_float(profile->blueColorant.X);
-       sum[1] = s15Fixed16Number_to_float(profile->redColorant.Y) +
-	       s15Fixed16Number_to_float(profile->greenColorant.Y) +
-	       s15Fixed16Number_to_float(profile->blueColorant.Y);
-       sum[2] = s15Fixed16Number_to_float(profile->redColorant.Z) +
-	       s15Fixed16Number_to_float(profile->greenColorant.Z) +
-	       s15Fixed16Number_to_float(profile->blueColorant.Z);
+       rX = s15Fixed16Number_to_float(profile->redColorant.X);
+       rY = s15Fixed16Number_to_float(profile->redColorant.Y);
+       rZ = s15Fixed16Number_to_float(profile->redColorant.Z);
+
+       gX = s15Fixed16Number_to_float(profile->greenColorant.X);
+       gY = s15Fixed16Number_to_float(profile->greenColorant.Y);
+       gZ = s15Fixed16Number_to_float(profile->greenColorant.Z);
+
+       bX = s15Fixed16Number_to_float(profile->blueColorant.X);
+       bY = s15Fixed16Number_to_float(profile->blueColorant.Y);
+       bZ = s15Fixed16Number_to_float(profile->blueColorant.Z);
+
+       // Check if any of the XYZ values are negative (see mozilla bug 498245)
+       // CIEXYZ tristimulus values cannot be negative according to the spec.
+       negative =
+	       (rX < 0) || (rY < 0) || (rZ < 0) ||
+	       (gX < 0) || (gY < 0) || (gZ < 0) ||
+	       (bX < 0) || (bY < 0) || (bZ < 0);
+
+       if (negative)
+	       return true;
+
+
+       // Sum the values; they should add up to something close to white
+       sum[0] = rX + gX + bX;
+       sum[1] = rY + gY + bY;
+       sum[2] = rZ + gZ + bZ;
 
        // Build our target vector (see mozilla bug 460629)
        target[0] = 0.96420;
        target[1] = 1.00000;
        target[2] = 0.82491;
 
        // Our tolerance vector - Recommended by Chris Murphy based on
        // conversion from the LAB space criterion of no more than 3 in any one