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 "SkColorSpacePriv.h" |
11 #include "Test.h" | 12 #include "Test.h" |
12 | 13 |
13 #include "png.h" | 14 #include "png.h" |
14 | 15 |
15 static bool almost_equal(float a, float b) { | 16 static bool almost_equal(float a, float b) { |
16 return SkTAbs(a - b) < 0.001f; | 17 return SkTAbs(a - b) < 0.001f; |
17 } | 18 } |
18 | 19 |
19 static void test_space(skiatest::Reporter* r, SkColorSpace* space, | 20 static void test_space(skiatest::Reporter* r, SkColorSpace* space, |
20 const float red[], const float green[], const float blue[
], | 21 const float red[], const float green[], const float blue[
], |
21 const float expectedGammas[]) { | 22 const float expectedGammas[]) { |
22 #ifdef SK_DEBUG | 23 |
23 const SkColorSpace::SkGammas& gammas = space->gammas(); | 24 SkGammas* gammas = space->gammas(); |
24 REPORTER_ASSERT(r, almost_equal(expectedGammas[0], gammas.red())); | 25 REPORTER_ASSERT(r, almost_equal(expectedGammas[0], gammas->fRed.fValue)); |
25 REPORTER_ASSERT(r, almost_equal(expectedGammas[1], gammas.green())); | 26 REPORTER_ASSERT(r, almost_equal(expectedGammas[1], gammas->fGreen.fValue)); |
26 REPORTER_ASSERT(r, almost_equal(expectedGammas[2], gammas.blue())); | 27 REPORTER_ASSERT(r, almost_equal(expectedGammas[2], gammas->fBlue.fValue)); |
27 #endif | 28 |
28 | 29 |
29 SkMatrix44 mat = space->xyz(); | 30 SkMatrix44 mat = space->xyz(); |
30 const float src[] = { | 31 const float src[] = { |
31 1, 0, 0, 1, | 32 1, 0, 0, 1, |
32 0, 1, 0, 1, | 33 0, 1, 0, 1, |
33 0, 0, 1, 1, | 34 0, 0, 1, 1, |
34 }; | 35 }; |
35 float dst[4]; | 36 float dst[4]; |
36 for (int i = 0; i < 3; ++i) { | 37 for (int i = 0; i < 3; ++i) { |
37 mat.mapScalars(&src[i*4], dst); | 38 mat.mapScalars(&src[i*4], dst); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 const float green[] = { 0.143051f, 0.0606079f, 0.713913f }; | 100 const float green[] = { 0.143051f, 0.0606079f, 0.713913f }; |
100 const float blue[] = { 0.436035f, 0.222488f, 0.013916f }; | 101 const float blue[] = { 0.436035f, 0.222488f, 0.013916f }; |
101 const float gamma[] = { 2.2f, 2.2f, 2.2f }; | 102 const float gamma[] = { 2.2f, 2.2f, 2.2f }; |
102 test_space(r, colorSpace, red, green, blue, gamma); | 103 test_space(r, colorSpace, red, green, blue, gamma); |
103 } | 104 } |
104 | 105 |
105 DEF_TEST(ColorSpaceSRGBCompare, r) { | 106 DEF_TEST(ColorSpaceSRGBCompare, r) { |
106 // Create an sRGB color space by name | 107 // Create an sRGB color space by name |
107 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k
SRGB_Named); | 108 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k
SRGB_Named); |
108 | 109 |
| 110 |
109 // Create an sRGB color space by value | 111 // Create an sRGB color space by value |
110 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); | 112 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); |
| 113 float sRGBGammas[3] = { 2.2f, 2.2f, 2.2f }; |
111 srgbToxyzD50.set3x3ColMajorf(g_sRGB_XYZ); | 114 srgbToxyzD50.set3x3ColMajorf(g_sRGB_XYZ); |
112 sk_sp<SkColorSpace> rgbColorSpace = SkColorSpace::NewRGB( | 115 sk_sp<SkColorSpace> rgbColorSpace = SkColorSpace::NewRGB(sRGBGammas, srgbTox
yzD50); |
113 SkColorSpace::SkGammas(2.2f, 2.2f, 2.2f), srgbToxyzD50); | |
114 REPORTER_ASSERT(r, namedColorSpace == namedColorSpace); | 116 REPORTER_ASSERT(r, namedColorSpace == namedColorSpace); |
115 | 117 |
116 // Change a single value from the sRGB matrix | 118 // Change a single value from the sRGB matrix |
117 srgbToxyzD50.set(2, 2, 0.5f); | 119 srgbToxyzD50.set(2, 2, 0.5f); |
118 sk_sp<SkColorSpace> strangeColorSpace = SkColorSpace::NewRGB( | 120 sk_sp<SkColorSpace> strangeColorSpace = SkColorSpace::NewRGB(sRGBGammas, srg
bToxyzD50); |
119 SkColorSpace::SkGammas(2.2f, 2.2f, 2.2f), srgbToxyzD50); | |
120 REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace); | 121 REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace); |
121 } | 122 } |
OLD | NEW |