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" |
11 #include "Test.h" | 11 #include "Test.h" |
12 | 12 |
| 13 #include "png.h" |
| 14 |
13 static SkStreamAsset* resource(const char path[]) { | 15 static SkStreamAsset* resource(const char path[]) { |
14 SkString fullPath = GetResourcePath(path); | 16 SkString fullPath = GetResourcePath(path); |
15 return SkStream::NewFromFile(fullPath.c_str()); | 17 return SkStream::NewFromFile(fullPath.c_str()); |
16 } | 18 } |
17 | 19 |
| 20 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M
INOR >= 6) |
18 static bool almost_equal(float a, float b) { | 21 static bool almost_equal(float a, float b) { |
19 return SkTAbs(a - b) < 0.0001f; | 22 return SkTAbs(a - b) < 0.0001f; |
20 } | 23 } |
| 24 #endif |
21 | 25 |
22 DEF_TEST(ColorSpaceParseICCProfile, r) { | 26 DEF_TEST(ColorSpaceParseICCProfile, r) { |
23 SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png")); | 27 SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png")); |
24 REPORTER_ASSERT(r, nullptr != stream); | 28 REPORTER_ASSERT(r, nullptr != stream); |
25 | 29 |
26 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); | 30 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); |
27 REPORTER_ASSERT(r, nullptr != codec); | 31 REPORTER_ASSERT(r, nullptr != codec); |
28 | 32 |
| 33 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M
INOR >= 6) |
29 SkColorSpace* colorSpace = codec->getColorSpace(); | 34 SkColorSpace* colorSpace = codec->getColorSpace(); |
30 REPORTER_ASSERT(r, nullptr != colorSpace); | 35 REPORTER_ASSERT(r, nullptr != colorSpace); |
31 | 36 |
32 // No need to use almost equal here. The color profile that we have extract
ed | 37 // No need to use almost equal here. The color profile that we have extract
ed |
33 // actually has a table of gammas. And our current implementation guesses 2
.2f. | 38 // actually has a table of gammas. And our current implementation guesses 2
.2f. |
34 SkFloat3 gammas = colorSpace->gamma(); | 39 SkFloat3 gammas = colorSpace->gamma(); |
35 REPORTER_ASSERT(r, 2.2f == gammas.fVec[0]); | 40 REPORTER_ASSERT(r, 2.2f == gammas.fVec[0]); |
36 REPORTER_ASSERT(r, 2.2f == gammas.fVec[1]); | 41 REPORTER_ASSERT(r, 2.2f == gammas.fVec[1]); |
37 REPORTER_ASSERT(r, 2.2f == gammas.fVec[2]); | 42 REPORTER_ASSERT(r, 2.2f == gammas.fVec[2]); |
38 | 43 |
39 // These nine values were extracted from the color profile in isolation (bef
ore | 44 // These nine values were extracted from the color profile in isolation (bef
ore |
40 // we embedded it in the png). Here we check that we still extract the same
values. | 45 // we embedded it in the png). Here we check that we still extract the same
values. |
41 SkFloat3x3 xyz = colorSpace->xyz(); | 46 SkFloat3x3 xyz = colorSpace->xyz(); |
42 REPORTER_ASSERT(r, almost_equal(0.436066f, xyz.fMat[0])); | 47 REPORTER_ASSERT(r, almost_equal(0.436066f, xyz.fMat[0])); |
43 REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[1])); | 48 REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[1])); |
44 REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[2])); | 49 REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[2])); |
45 REPORTER_ASSERT(r, almost_equal(0.385147f, xyz.fMat[3])); | 50 REPORTER_ASSERT(r, almost_equal(0.385147f, xyz.fMat[3])); |
46 REPORTER_ASSERT(r, almost_equal(0.716873f, xyz.fMat[4])); | 51 REPORTER_ASSERT(r, almost_equal(0.716873f, xyz.fMat[4])); |
47 REPORTER_ASSERT(r, almost_equal(0.0970764f, xyz.fMat[5])); | 52 REPORTER_ASSERT(r, almost_equal(0.0970764f, xyz.fMat[5])); |
48 REPORTER_ASSERT(r, almost_equal(0.143066f, xyz.fMat[6])); | 53 REPORTER_ASSERT(r, almost_equal(0.143066f, xyz.fMat[6])); |
49 REPORTER_ASSERT(r, almost_equal(0.0606079f, xyz.fMat[7])); | 54 REPORTER_ASSERT(r, almost_equal(0.0606079f, xyz.fMat[7])); |
50 REPORTER_ASSERT(r, almost_equal(0.714096f, xyz.fMat[8])); | 55 REPORTER_ASSERT(r, almost_equal(0.714096f, xyz.fMat[8])); |
| 56 #endif |
51 } | 57 } |
OLD | NEW |