Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* vim: set ts=8 sw=8 noexpandtab: */ | 1 /* vim: set ts=8 sw=8 noexpandtab: */ |
| 2 // qcms | 2 // qcms |
| 3 // Copyright (C) 2009 Mozilla Foundation | 3 // Copyright (C) 2009 Mozilla Foundation |
| 4 // Copyright (C) 1998-2007 Marti Maria | 4 // Copyright (C) 1998-2007 Marti Maria |
| 5 // | 5 // |
| 6 // Permission is hereby granted, free of charge, to any person obtaining | 6 // Permission is hereby granted, free of charge, to any person obtaining |
| 7 // a copy of this software and associated documentation files (the "Software"), | 7 // a copy of this software and associated documentation files (the "Software"), |
| 8 // to deal in the Software without restriction, including without limitation | 8 // to deal in the Software without restriction, including without limitation |
| 9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, | 9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 // and/or sell copies of the Software, and to permit persons to whom the Softwar e | 10 // and/or sell copies of the Software, and to permit persons to whom the Softwar e |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 } | 251 } |
| 252 | 252 |
| 253 return index; | 253 return index; |
| 254 } | 254 } |
| 255 | 255 |
| 256 // Checks a profile for obvious inconsistencies and returns | 256 // Checks a profile for obvious inconsistencies and returns |
| 257 // true if the profile looks bogus and should probably be | 257 // true if the profile looks bogus and should probably be |
| 258 // ignored. | 258 // ignored. |
| 259 qcms_bool qcms_profile_is_bogus(qcms_profile *profile) | 259 qcms_bool qcms_profile_is_bogus(qcms_profile *profile) |
| 260 { | 260 { |
| 261 float sum[3], target[3], tolerance[3]; | 261 float rX, rY, rZ, gX, gY, gZ, bX, bY, bZ; |
| 262 float rX, rY, rZ, gX, gY, gZ, bX, bY, bZ; | 262 float target[3], tolerance[3], sum[3]; |
| 263 bool negative; | 263 unsigned i; |
| 264 unsigned i; | |
| 265 | 264 |
| 266 // We currently only check the bogosity of RGB profiles | 265 // We currently only check the bogosity of RGB profiles. |
| 267 if (profile->color_space != RGB_SIGNATURE) | 266 if (profile->color_space != RGB_SIGNATURE) |
| 268 » return false; | |
| 269 | |
| 270 if (qcms_supports_iccv4 && (profile->A2B0 || profile->B2A0)) | |
| 271 return false; | 267 return false; |
| 272 | 268 |
| 273 rX = s15Fixed16Number_to_float(profile->redColorant.X); | 269 if (qcms_supports_iccv4 && (profile->A2B0 || profile->B2A0)) |
| 274 rY = s15Fixed16Number_to_float(profile->redColorant.Y); | 270 return false; |
| 275 rZ = s15Fixed16Number_to_float(profile->redColorant.Z); | |
| 276 | 271 |
| 277 gX = s15Fixed16Number_to_float(profile->greenColorant.X); | 272 rX = s15Fixed16Number_to_float(profile->redColorant.X); |
| 278 gY = s15Fixed16Number_to_float(profile->greenColorant.Y); | 273 rY = s15Fixed16Number_to_float(profile->redColorant.Y); |
| 279 gZ = s15Fixed16Number_to_float(profile->greenColorant.Z); | 274 rZ = s15Fixed16Number_to_float(profile->redColorant.Z); |
| 280 | 275 |
| 281 bX = s15Fixed16Number_to_float(profile->blueColorant.X); | 276 gX = s15Fixed16Number_to_float(profile->greenColorant.X); |
| 282 bY = s15Fixed16Number_to_float(profile->blueColorant.Y); | 277 gY = s15Fixed16Number_to_float(profile->greenColorant.Y); |
| 283 bZ = s15Fixed16Number_to_float(profile->blueColorant.Z); | 278 gZ = s15Fixed16Number_to_float(profile->greenColorant.Z); |
| 284 | 279 |
| 285 // Check if any of the XYZ values are negative (see mozilla bug 498245) | 280 bX = s15Fixed16Number_to_float(profile->blueColorant.X); |
| 286 // CIEXYZ tristimulus values cannot be negative according to the spec. | 281 bY = s15Fixed16Number_to_float(profile->blueColorant.Y); |
| 287 negative = | 282 bZ = s15Fixed16Number_to_float(profile->blueColorant.Z); |
| 288 » (rX < 0) || (rY < 0) || (rZ < 0) || | |
| 289 » (gX < 0) || (gY < 0) || (gZ < 0) || | |
| 290 » (bX < 0) || (bY < 0) || (bZ < 0); | |
| 291 | 283 |
| 292 if (negative) | 284 // Build our target vector: CIE D50 white. See also mozilla bug 460629, |
| 293 » return true; | 285 // and http://www.color.org/whyd50.xalter "Why is the media white point |
| 286 // of a display profile always D50?" | |
| 294 | 287 |
| 288 target[0] = (float) 0.96420; | |
| 289 target[1] = (float) 1.00000; | |
| 290 target[2] = (float) 0.82491; | |
| 295 | 291 |
| 296 // Sum the values; they should add up to something close to white | 292 // Our tolerance vector - Recommended by Chris Murphy based on |
| 297 sum[0] = rX + gX + bX; | 293 // conversion from the LAB space criterion of no more than 3 in any one |
| 298 sum[1] = rY + gY + bY; | 294 // channel. This is similar to, but slightly more tolerant than Adobe's |
| 299 sum[2] = rZ + gZ + bZ; | 295 // criterion. |
| 300 | 296 |
| 301 #if defined (_MSC_VER) | 297 tolerance[0] = (float) 0.02; |
| 302 #pragma warning(push) | 298 tolerance[1] = (float) 0.02; |
| 303 /* Disable double to float truncation warning 4305 */ | 299 tolerance[2] = (float) 0.04; |
| 304 #pragma warning(disable:4305) | 300 |
| 301 // Sum the XYZ values: they should add up D50 white, within tolerance. | |
|
Noel Gordon
2015/12/01 04:00:16
Note to self: change to "should add to" on submit.
| |
| 302 // FIXME: this test assumes the TRC RGB curves equal 1.0 for the white | |
| 303 // input (255,255,255) test RGB color. For user displays and screens, | |
| 304 // that is indeed the normal case. | |
| 305 | |
| 306 sum[0] = rX + gX + bX; | |
| 307 sum[1] = rY + gY + bY; | |
| 308 sum[2] = rZ + gZ + bZ; | |
| 309 | |
| 310 for (i = 0; i < 3; ++i) { | |
| 311 if (!(((sum[i] - tolerance[i]) <= target[i]) && | |
| 312 ((sum[i] + tolerance[i]) >= target[i]))) { | |
| 313 return true; // out of tolerance: bogus | |
| 314 } | |
| 315 } | |
| 316 | |
| 317 #ifndef __APPLE__ | |
| 318 | |
| 319 // Check if any of the XYZ values are negative (see mozilla bug 498245) | |
| 320 // CIEXYZ tristimulus values cannot be negative according to the spec. | |
| 321 | |
| 322 bool negative = | |
| 323 (rX < 0) || (rY < 0) || (rZ < 0) || | |
| 324 (gX < 0) || (gY < 0) || (gZ < 0) || | |
| 325 (bX < 0) || (bY < 0) || (bZ < 0); | |
| 326 | |
| 327 if (negative) | |
| 328 return true; // bogus | |
| 329 #else | |
| 330 // Chromatic adaption to D50 can result in negative XYZ, but the white- | |
| 331 // point D50 tolerance test has passed. Herein, accept negative values. | |
| 332 // See https://bugzilla.mozilla.org/show_bug.cgi?id=498245#c18 onwards | |
| 333 // for discussion about whether or not XZY can or can't be negative per | |
| 334 // the spec. Also https://bugzilla.mozilla.org/show_bug.cgi?id=450923 | |
| 335 | |
| 336 // FIXME: allow this relaxation on all ports? | |
|
Justin Novosad
2015/12/01 03:29:55
FIXME is deprecated, use TODO(noel)
| |
| 305 #endif | 337 #endif |
| 306 // Build our target vector (see mozilla bug 460629) | 338 // All good. |
| 307 target[0] = 0.96420; | 339 return false; |
| 308 target[1] = 1.00000; | |
| 309 target[2] = 0.82491; | |
| 310 | |
| 311 // Our tolerance vector - Recommended by Chris Murphy based on | |
| 312 // conversion from the LAB space criterion of no more than 3 in any one | |
| 313 // channel. This is similar to, but slightly more tolerant than Adobe's | |
| 314 // criterion. | |
| 315 tolerance[0] = 0.02; | |
| 316 tolerance[1] = 0.02; | |
| 317 tolerance[2] = 0.04; | |
| 318 | |
| 319 #if defined (_MSC_VER) | |
| 320 /* Restore warnings */ | |
| 321 #pragma warning(pop) | |
| 322 #endif | |
| 323 // Compare with our tolerance | |
| 324 for (i = 0; i < 3; ++i) { | |
| 325 if (!(((sum[i] - tolerance[i]) <= target[i]) && | |
| 326 ((sum[i] + tolerance[i]) >= target[i]))) | |
| 327 return true; | |
| 328 } | |
| 329 | |
| 330 // All Good | |
| 331 return false; | |
| 332 } | 340 } |
| 333 | 341 |
| 334 #define TAG_bXYZ 0x6258595a | 342 #define TAG_bXYZ 0x6258595a |
| 335 #define TAG_gXYZ 0x6758595a | 343 #define TAG_gXYZ 0x6758595a |
| 336 #define TAG_rXYZ 0x7258595a | 344 #define TAG_rXYZ 0x7258595a |
| 337 #define TAG_rTRC 0x72545243 | 345 #define TAG_rTRC 0x72545243 |
| 338 #define TAG_bTRC 0x62545243 | 346 #define TAG_bTRC 0x62545243 |
| 339 #define TAG_gTRC 0x67545243 | 347 #define TAG_gTRC 0x67545243 |
| 340 #define TAG_kTRC 0x6b545243 | 348 #define TAG_kTRC 0x6b545243 |
| 341 #define TAG_A2B0 0x41324230 | 349 #define TAG_A2B0 0x41324230 |
| (...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1546 { | 1554 { |
| 1547 qcms_profile *profile = NULL; | 1555 qcms_profile *profile = NULL; |
| 1548 FILE *file = _wfopen(path, L"rb"); | 1556 FILE *file = _wfopen(path, L"rb"); |
| 1549 if (file) { | 1557 if (file) { |
| 1550 profile = qcms_profile_from_file(file); | 1558 profile = qcms_profile_from_file(file); |
| 1551 fclose(file); | 1559 fclose(file); |
| 1552 } | 1560 } |
| 1553 return profile; | 1561 return profile; |
| 1554 } | 1562 } |
| 1555 #endif | 1563 #endif |
| OLD | NEW |