| 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 "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkCodec.h" | 9 #include "SkCodec.h" |
| 10 #include "SkColorSpace.h" | 10 #include "SkColorSpace.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 return; | 28 return; |
| 29 } | 29 } |
| 30 | 30 |
| 31 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); | 31 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
| 32 REPORTER_ASSERT(r, nullptr != codec); | 32 REPORTER_ASSERT(r, nullptr != codec); |
| 33 | 33 |
| 34 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M
INOR >= 6) | 34 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M
INOR >= 6) |
| 35 SkColorSpace* colorSpace = codec->getColorSpace(); | 35 SkColorSpace* colorSpace = codec->getColorSpace(); |
| 36 REPORTER_ASSERT(r, nullptr != colorSpace); | 36 REPORTER_ASSERT(r, nullptr != colorSpace); |
| 37 | 37 |
| 38 // The color profile that we have extracted has represents gamma with a look
up table. | 38 // No need to use almost equal here. The color profile that we have extract
ed |
| 39 // So we expect the gamma value to be zero. | 39 // actually has a table of gammas. And our current implementation guesses 2
.2f. |
| 40 #ifdef SK_DEBUG | 40 SkFloat3 gammas = colorSpace->gamma(); |
| 41 const SkColorSpace::SkGammas& gammas = colorSpace->gammas(); | 41 REPORTER_ASSERT(r, 2.2f == gammas.fVec[0]); |
| 42 REPORTER_ASSERT(r, 0.0f == gammas.red()); | 42 REPORTER_ASSERT(r, 2.2f == gammas.fVec[1]); |
| 43 REPORTER_ASSERT(r, 0.0f == gammas.green()); | 43 REPORTER_ASSERT(r, 2.2f == gammas.fVec[2]); |
| 44 REPORTER_ASSERT(r, 0.0f == gammas.blue()); | |
| 45 #endif | |
| 46 | 44 |
| 47 // These nine values were extracted from the color profile in isolation (bef
ore | 45 // These nine values were extracted from the color profile in isolation (bef
ore |
| 48 // we embedded it in the png). Here we check that we still extract the same
values. | 46 // we embedded it in the png). Here we check that we still extract the same
values. |
| 49 SkFloat3x3 xyz = colorSpace->xyz(); | 47 SkFloat3x3 xyz = colorSpace->xyz(); |
| 50 REPORTER_ASSERT(r, almost_equal(0.436066f, xyz.fMat[0])); | 48 REPORTER_ASSERT(r, almost_equal(0.436066f, xyz.fMat[0])); |
| 51 REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[1])); | 49 REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[1])); |
| 52 REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[2])); | 50 REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[2])); |
| 53 REPORTER_ASSERT(r, almost_equal(0.385147f, xyz.fMat[3])); | 51 REPORTER_ASSERT(r, almost_equal(0.385147f, xyz.fMat[3])); |
| 54 REPORTER_ASSERT(r, almost_equal(0.716873f, xyz.fMat[4])); | 52 REPORTER_ASSERT(r, almost_equal(0.716873f, xyz.fMat[4])); |
| 55 REPORTER_ASSERT(r, almost_equal(0.0970764f, xyz.fMat[5])); | 53 REPORTER_ASSERT(r, almost_equal(0.0970764f, xyz.fMat[5])); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 70 REPORTER_ASSERT(r, nullptr != codec); | 68 REPORTER_ASSERT(r, nullptr != codec); |
| 71 if (!codec) { | 69 if (!codec) { |
| 72 return; | 70 return; |
| 73 } | 71 } |
| 74 | 72 |
| 75 SkColorSpace* colorSpace = codec->getColorSpace(); | 73 SkColorSpace* colorSpace = codec->getColorSpace(); |
| 76 REPORTER_ASSERT(r, nullptr != colorSpace); | 74 REPORTER_ASSERT(r, nullptr != colorSpace); |
| 77 | 75 |
| 78 // It's important to use almost equal here. This profile sets gamma as | 76 // It's important to use almost equal here. This profile sets gamma as |
| 79 // 563 / 256, which actually comes out to about 2.19922. | 77 // 563 / 256, which actually comes out to about 2.19922. |
| 80 #ifdef SK_DEBUG | 78 SkFloat3 gammas = colorSpace->gamma(); |
| 81 const SkColorSpace::SkGammas& gammas = colorSpace->gammas(); | 79 REPORTER_ASSERT(r, almost_equal(2.2f, gammas.fVec[0])); |
| 82 REPORTER_ASSERT(r, almost_equal(2.2f, gammas.red())); | 80 REPORTER_ASSERT(r, almost_equal(2.2f, gammas.fVec[1])); |
| 83 REPORTER_ASSERT(r, almost_equal(2.2f, gammas.green())); | 81 REPORTER_ASSERT(r, almost_equal(2.2f, gammas.fVec[2])); |
| 84 REPORTER_ASSERT(r, almost_equal(2.2f, gammas.blue())); | |
| 85 #endif | |
| 86 | 82 |
| 87 // These nine values were extracted from the color profile. Until we know a
ny | 83 // These nine values were extracted from the color profile. Until we know a
ny |
| 88 // better, we'll assume these are the right values and test that we continue | 84 // better, we'll assume these are the right values and test that we continue |
| 89 // to extract them properly. | 85 // to extract them properly. |
| 90 SkFloat3x3 xyz = colorSpace->xyz(); | 86 SkFloat3x3 xyz = colorSpace->xyz(); |
| 91 REPORTER_ASSERT(r, almost_equal(0.385117f, xyz.fMat[0])); | 87 REPORTER_ASSERT(r, almost_equal(0.385117f, xyz.fMat[0])); |
| 92 REPORTER_ASSERT(r, almost_equal(0.716904f, xyz.fMat[1])); | 88 REPORTER_ASSERT(r, almost_equal(0.716904f, xyz.fMat[1])); |
| 93 REPORTER_ASSERT(r, almost_equal(0.0970612f, xyz.fMat[2])); | 89 REPORTER_ASSERT(r, almost_equal(0.0970612f, xyz.fMat[2])); |
| 94 REPORTER_ASSERT(r, almost_equal(0.143051f, xyz.fMat[3])); | 90 REPORTER_ASSERT(r, almost_equal(0.143051f, xyz.fMat[3])); |
| 95 REPORTER_ASSERT(r, almost_equal(0.0606079f, xyz.fMat[4])); | 91 REPORTER_ASSERT(r, almost_equal(0.0606079f, xyz.fMat[4])); |
| 96 REPORTER_ASSERT(r, almost_equal(0.713913f, xyz.fMat[5])); | 92 REPORTER_ASSERT(r, almost_equal(0.713913f, xyz.fMat[5])); |
| 97 REPORTER_ASSERT(r, almost_equal(0.436035f, xyz.fMat[6])); | 93 REPORTER_ASSERT(r, almost_equal(0.436035f, xyz.fMat[6])); |
| 98 REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[7])); | 94 REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[7])); |
| 99 REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[8])); | 95 REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[8])); |
| 100 } | 96 } |
| OLD | NEW |