Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkAtomics.h" | 8 #include "SkAtomics.h" |
| 9 #include "SkColorSpace.h" | 9 #include "SkColorSpace.h" |
| 10 #include "SkOnce.h" | 10 #include "SkOnce.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 } | 329 } |
| 330 | 330 |
| 331 // Check for frequently occurring curves and use a fast approxim ation. | 331 // Check for frequently occurring curves and use a fast approxim ation. |
| 332 // We do this by sampling a few values and see if they match our expectation. | 332 // We do this by sampling a few values and see if they match our expectation. |
| 333 // A more robust solution would be to compare each value in this curve against | 333 // A more robust solution would be to compare each value in this curve against |
| 334 // a 2.2f curve see if we remain below an error threshold. At t his time, | 334 // a 2.2f curve see if we remain below an error threshold. At t his time, |
| 335 // we haven't seen any images in the wild that make this kind of | 335 // we haven't seen any images in the wild that make this kind of |
| 336 // calculation necessary. We encounter identical gamma curves o ver and | 336 // calculation necessary. We encounter identical gamma curves o ver and |
| 337 // over again, but relatively few variations. | 337 // over again, but relatively few variations. |
| 338 if (1024 == count) { | 338 if (1024 == count) { |
| 339 // The magic values were chosen because they match a very co mmon sRGB | |
| 340 // gamma table and the less common Canon sRGB gamma table (w hich use | |
| 341 // different rounding rules). | |
| 339 if (0 == read_big_endian_short((const uint8_t*) &table[0]) & & | 342 if (0 == read_big_endian_short((const uint8_t*) &table[0]) & & |
| 340 3341 == read_big_endian_short((const uint8_t*) &tabl e[256]) && | 343 3366 == read_big_endian_short((const uint8_t*) &tabl e[257]) && |
|
scroggo
2016/05/13 12:45:24
Does still correctly identify images that were rec
msarett
2016/05/13 12:51:48
Yes!
| |
| 341 14057 == read_big_endian_short((const uint8_t*) &tab le[512]) && | 344 14116 == read_big_endian_short((const uint8_t*) &tab le[513]) && |
| 342 34318 == read_big_endian_short((const uint8_t*) &tab le[768]) && | 345 34318 == read_big_endian_short((const uint8_t*) &tab le[768]) && |
| 343 65535 == read_big_endian_short((const uint8_t*) &tab le[1023])) { | 346 65535 == read_big_endian_short((const uint8_t*) &tab le[1023])) { |
| 344 gammas[i].fValue = 2.2f; | 347 gammas[i].fValue = 2.2f; |
| 345 break; | 348 break; |
| 346 } | 349 } |
| 347 } else if (26 == count) { | 350 } else if (26 == count) { |
| 351 // The magic values were chosen because they match a very co mmon sRGB | |
| 352 // gamma table. | |
| 348 if (0 == read_big_endian_short((const uint8_t*) &table[0]) & & | 353 if (0 == read_big_endian_short((const uint8_t*) &table[0]) & & |
| 349 3062 == read_big_endian_short((const uint8_t*) &tabl e[6]) && | 354 3062 == read_big_endian_short((const uint8_t*) &tabl e[6]) && |
| 350 12824 == read_big_endian_short((const uint8_t*) &tab le[12]) && | 355 12824 == read_big_endian_short((const uint8_t*) &tab le[12]) && |
| 351 31237 == read_big_endian_short((const uint8_t*) &tab le[18]) && | 356 31237 == read_big_endian_short((const uint8_t*) &tab le[18]) && |
| 352 65535 == read_big_endian_short((const uint8_t*) &tab le[25])) { | 357 65535 == read_big_endian_short((const uint8_t*) &tab le[25])) { |
| 353 gammas[i].fValue = 2.2f; | 358 gammas[i].fValue = 2.2f; |
| 354 break; | 359 break; |
| 355 } | 360 } |
| 361 } else if (4096 == count) { | |
| 362 // The magic values were chosen because they match Nikon, Ep son, and | |
| 363 // LCMS sRGB gamma tables (all of which use different roundi ng rules). | |
| 364 if (0 == read_big_endian_short((const uint8_t*) &table[0]) & & | |
|
scroggo
2016/05/13 12:45:24
As we add more of these, it makes me wonder if we
msarett
2016/05/13 12:51:48
I think this is a really good idea.
| |
| 365 950 == read_big_endian_short((const uint8_t*) &table [515]) && | |
| 366 3342 == read_big_endian_short((const uint8_t*) &tabl e[1025]) && | |
| 367 14079 == read_big_endian_short((const uint8_t*) &tab le[2051]) && | |
| 368 65535 == read_big_endian_short((const uint8_t*) &tab le[4095])) { | |
| 369 gammas[i].fValue = 2.2f; | |
| 370 break; | |
| 371 } | |
| 356 } | 372 } |
| 357 | 373 |
| 358 // Otherwise, fill in the interpolation table. | 374 // Otherwise, fill in the interpolation table. |
| 359 gammas[i].fTableSize = count; | 375 gammas[i].fTableSize = count; |
| 360 gammas[i].fTable = std::unique_ptr<float[]>(new float[count]); | 376 gammas[i].fTable = std::unique_ptr<float[]>(new float[count]); |
| 361 for (uint32_t j = 0; j < count; j++) { | 377 for (uint32_t j = 0; j < count; j++) { |
| 362 gammas[i].fTable[j] = | 378 gammas[i].fTable[j] = |
| 363 (read_big_endian_short((const uint8_t*) &table[j])) / 65535.0f; | 379 (read_big_endian_short((const uint8_t*) &table[j])) / 65535.0f; |
| 364 } | 380 } |
| 365 break; | 381 break; |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 toXYZ)); | 675 toXYZ)); |
| 660 } | 676 } |
| 661 | 677 |
| 662 } | 678 } |
| 663 default: | 679 default: |
| 664 break; | 680 break; |
| 665 } | 681 } |
| 666 | 682 |
| 667 return_null("ICC profile contains unsupported colorspace"); | 683 return_null("ICC profile contains unsupported colorspace"); |
| 668 } | 684 } |
| OLD | NEW |