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 12 matching lines...) Expand all Loading... |
23 | 23 |
24 REPORTER_ASSERT(r, nullptr != space); | 24 REPORTER_ASSERT(r, nullptr != space); |
25 REPORTER_ASSERT(r, expectedGamma == as_CSB(space)->gammaNamed()); | 25 REPORTER_ASSERT(r, expectedGamma == as_CSB(space)->gammaNamed()); |
26 | 26 |
27 const SkMatrix44& mat = space->toXYZD50(); | 27 const SkMatrix44& mat = space->toXYZD50(); |
28 const float src[] = { | 28 const float src[] = { |
29 1, 0, 0, 1, | 29 1, 0, 0, 1, |
30 0, 1, 0, 1, | 30 0, 1, 0, 1, |
31 0, 0, 1, 1, | 31 0, 0, 1, 1, |
32 }; | 32 }; |
| 33 const float* ref[3] = { red, green, blue }; |
33 float dst[4]; | 34 float dst[4]; |
34 for (int i = 0; i < 3; ++i) { | 35 for (int i = 0; i < 3; ++i) { |
35 mat.mapScalars(&src[i*4], dst); | 36 mat.mapScalars(&src[i*4], dst); |
36 REPORTER_ASSERT(r, almost_equal(red[i], dst[0])); | 37 REPORTER_ASSERT(r, almost_equal(ref[i][0], dst[0])); |
37 REPORTER_ASSERT(r, almost_equal(green[i], dst[1])); | 38 REPORTER_ASSERT(r, almost_equal(ref[i][1], dst[1])); |
38 REPORTER_ASSERT(r, almost_equal(blue[i], dst[2])); | 39 REPORTER_ASSERT(r, almost_equal(ref[i][2], dst[2])); |
39 } | 40 } |
40 } | 41 } |
41 | 42 |
42 static SkStreamAsset* resource(const char path[]) { | 43 static SkStreamAsset* resource(const char path[]) { |
43 SkString fullPath = GetResourcePath(path); | 44 SkString fullPath = GetResourcePath(path); |
44 return SkStream::NewFromFile(fullPath.c_str()); | 45 return SkStream::NewFromFile(fullPath.c_str()); |
45 } | 46 } |
46 | 47 |
47 static void test_path(skiatest::Reporter* r, const char* path, | 48 static void test_path(skiatest::Reporter* r, const char* path, |
48 const float red[], const float green[], const float blue[]
, | 49 const float red[], const float green[], const float blue[]
, |
49 const SkGammaNamed expectedGamma) { | 50 const SkGammaNamed expectedGamma) { |
50 SkAutoTDelete<SkStream> stream(resource(path)); | 51 SkAutoTDelete<SkStream> stream(resource(path)); |
51 REPORTER_ASSERT(r, nullptr != stream); | 52 REPORTER_ASSERT(r, nullptr != stream); |
52 if (!stream) { | 53 if (!stream) { |
53 return; | 54 return; |
54 } | 55 } |
55 | 56 |
56 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); | 57 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
57 REPORTER_ASSERT(r, nullptr != codec); | 58 REPORTER_ASSERT(r, nullptr != codec); |
58 if (!codec) { | 59 if (!codec) { |
59 return; | 60 return; |
60 } | 61 } |
61 | 62 |
62 SkColorSpace* colorSpace = codec->getInfo().colorSpace(); | 63 SkColorSpace* colorSpace = codec->getInfo().colorSpace(); |
63 test_space(r, colorSpace, red, green, blue, expectedGamma); | 64 test_space(r, colorSpace, red, green, blue, expectedGamma); |
64 } | 65 } |
65 | 66 |
66 const float g_sRGB_XYZ[] = { 0.4358f, 0.2224f, 0.0139f, // R | 67 static constexpr float g_sRGB_XYZ[]{ |
67 0.3853f, 0.7170f, 0.0971f, // G | 68 0.4358f, 0.3853f, 0.1430f, // Rx, Gx, Bx |
68 0.1430f, 0.0606f, 0.7139f }; // B | 69 0.2224f, 0.7170f, 0.0606f, // Ry, Gy, Gz |
| 70 0.0139f, 0.0971f, 0.7139f, // Rz, Gz, Bz |
| 71 }; |
| 72 |
| 73 static constexpr float g_sRGB_R[]{ 0.4358f, 0.2224f, 0.0139f }; |
| 74 static constexpr float g_sRGB_G[]{ 0.3853f, 0.7170f, 0.0971f }; |
| 75 static constexpr float g_sRGB_B[]{ 0.1430f, 0.0606f, 0.7139f }; |
69 | 76 |
70 DEF_TEST(ColorSpace_sRGB, r) { | 77 DEF_TEST(ColorSpace_sRGB, r) { |
71 test_space(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), | 78 test_space(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), |
72 g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], kSRGB_SkGammaNamed); | 79 g_sRGB_R, g_sRGB_G, g_sRGB_B, kSRGB_SkGammaNamed); |
73 | 80 |
74 } | 81 } |
75 | 82 |
76 DEF_TEST(ColorSpaceParseICCProfiles, r) { | 83 DEF_TEST(ColorSpaceParseICCProfiles, r) { |
77 | 84 |
78 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M
INOR >= 6) | 85 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M
INOR >= 6) |
79 test_path(r, "color_wheel_with_profile.png", &g_sRGB_XYZ[0], &g_sRGB_XYZ[3],
&g_sRGB_XYZ[6], | 86 test_path(r, "color_wheel_with_profile.png", g_sRGB_R, g_sRGB_G, g_sRGB_B, |
80 kSRGB_SkGammaNamed); | 87 kSRGB_SkGammaNamed); |
81 #endif | 88 #endif |
82 | 89 |
83 const float red[] = { 0.385117f, 0.716904f, 0.0970612f }; | 90 const float red[] = { 0.385117f, 0.716904f, 0.0970612f }; |
84 const float green[] = { 0.143051f, 0.0606079f, 0.713913f }; | 91 const float green[] = { 0.143051f, 0.0606079f, 0.713913f }; |
85 const float blue[] = { 0.436035f, 0.222488f, 0.013916f }; | 92 const float blue[] = { 0.436035f, 0.222488f, 0.013916f }; |
86 test_path(r, "icc-v2-gbr.jpg", red, green, blue, k2Dot2Curve_SkGammaNamed); | 93 test_path(r, "icc-v2-gbr.jpg", red, green, blue, k2Dot2Curve_SkGammaNamed); |
87 | 94 |
88 test_path(r, "webp-color-profile-crash.webp", | 95 test_path(r, "webp-color-profile-crash.webp", |
89 red, green, blue, kNonStandard_SkGammaNamed); | 96 red, green, blue, kNonStandard_SkGammaNamed); |
(...skipping 28 matching lines...) Expand all Loading... |
118 static sk_sp<SkData> WriteToICC(SkColorSpace* space) { | 125 static sk_sp<SkData> WriteToICC(SkColorSpace* space) { |
119 return as_CSB(space)->writeToICC(); | 126 return as_CSB(space)->writeToICC(); |
120 } | 127 } |
121 }; | 128 }; |
122 | 129 |
123 DEF_TEST(ColorSpaceWriteICC, r) { | 130 DEF_TEST(ColorSpaceWriteICC, r) { |
124 // Test writing a new ICC profile | 131 // Test writing a new ICC profile |
125 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k
SRGB_Named); | 132 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k
SRGB_Named); |
126 sk_sp<SkData> namedData = ColorSpaceTest::WriteToICC(namedColorSpace.get()); | 133 sk_sp<SkData> namedData = ColorSpaceTest::WriteToICC(namedColorSpace.get()); |
127 sk_sp<SkColorSpace> iccColorSpace = SkColorSpace::NewICC(namedData->data(),
namedData->size()); | 134 sk_sp<SkColorSpace> iccColorSpace = SkColorSpace::NewICC(namedData->data(),
namedData->size()); |
128 test_space(r, iccColorSpace.get(), g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6
], | 135 test_space(r, iccColorSpace.get(), g_sRGB_R, g_sRGB_G, g_sRGB_B, k2Dot2Curve
_SkGammaNamed); |
129 k2Dot2Curve_SkGammaNamed); | |
130 // FIXME (msarett): Test disabled. sRGB profiles are written approximately
as 2.2f curves. | 136 // FIXME (msarett): Test disabled. sRGB profiles are written approximately
as 2.2f curves. |
131 // REPORTER_ASSERT(r, iccColorSpace == namedColorSpace); | 137 // REPORTER_ASSERT(r, iccColorSpace == namedColorSpace); |
132 | 138 |
133 // Test saving the original ICC data | 139 // Test saving the original ICC data |
134 sk_sp<SkData> monitorData = SkData::MakeFromFileName( | 140 sk_sp<SkData> monitorData = SkData::MakeFromFileName( |
135 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); | 141 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); |
136 REPORTER_ASSERT(r, monitorData); | 142 REPORTER_ASSERT(r, monitorData); |
137 if (!monitorData) { | 143 if (!monitorData) { |
138 return; | 144 return; |
139 } | 145 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr)); | 248 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr)); |
243 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get())); | 249 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get())); |
244 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get())); | 250 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get())); |
245 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get())); | 251 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get())); |
246 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get())); | 252 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get())); |
247 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get()))
; | 253 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get()))
; |
248 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get())); | 254 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get())); |
249 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get())); | 255 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get())); |
250 REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get())); | 256 REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get())); |
251 } | 257 } |
OLD | NEW |