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 23 matching lines...) Expand all Loading... |
34 }; | 34 }; |
35 float dst[4]; | 35 float dst[4]; |
36 for (int i = 0; i < 3; ++i) { | 36 for (int i = 0; i < 3; ++i) { |
37 mat.mapScalars(&src[i*4], dst); | 37 mat.mapScalars(&src[i*4], dst); |
38 REPORTER_ASSERT(r, almost_equal(red[i], dst[0])); | 38 REPORTER_ASSERT(r, almost_equal(red[i], dst[0])); |
39 REPORTER_ASSERT(r, almost_equal(green[i], dst[1])); | 39 REPORTER_ASSERT(r, almost_equal(green[i], dst[1])); |
40 REPORTER_ASSERT(r, almost_equal(blue[i], dst[2])); | 40 REPORTER_ASSERT(r, almost_equal(blue[i], dst[2])); |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
| 44 const float g_sRGB_XYZ[] = { 0.4358f, 0.2224f, 0.0139f, // R |
| 45 0.3853f, 0.7170f, 0.0971f, // G |
| 46 0.1430f, 0.0606f, 0.7139f }; // B |
| 47 |
44 DEF_TEST(ColorSpace_sRGB, r) { | 48 DEF_TEST(ColorSpace_sRGB, r) { |
45 const float srgb_r[] = { 0.4358f, 0.2224f, 0.0139f }; | |
46 const float srgb_g[] = { 0.3853f, 0.7170f, 0.0971f }; | |
47 const float srgb_b[] = { 0.1430f, 0.0606f, 0.7139f }; | |
48 const float srgb_gamma[] = { 2.2f, 2.2f, 2.2f }; | 49 const float srgb_gamma[] = { 2.2f, 2.2f, 2.2f }; |
49 test_space(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), | 50 test_space(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), |
50 srgb_r, srgb_g, srgb_b, srgb_gamma); | 51 g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], srgb_gamma); |
51 | 52 |
52 } | 53 } |
53 | 54 |
54 static SkStreamAsset* resource(const char path[]) { | 55 static SkStreamAsset* resource(const char path[]) { |
55 SkString fullPath = GetResourcePath(path); | 56 SkString fullPath = GetResourcePath(path); |
56 return SkStream::NewFromFile(fullPath.c_str()); | 57 return SkStream::NewFromFile(fullPath.c_str()); |
57 } | 58 } |
58 | 59 |
59 DEF_TEST(ColorSpaceParsePngICCProfile, r) { | 60 DEF_TEST(ColorSpaceParsePngICCProfile, r) { |
60 SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png")); | 61 SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png")); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 94 |
94 SkColorSpace* colorSpace = codec->getColorSpace(); | 95 SkColorSpace* colorSpace = codec->getColorSpace(); |
95 REPORTER_ASSERT(r, nullptr != colorSpace); | 96 REPORTER_ASSERT(r, nullptr != colorSpace); |
96 | 97 |
97 const float red[] = { 0.385117f, 0.716904f, 0.0970612f }; | 98 const float red[] = { 0.385117f, 0.716904f, 0.0970612f }; |
98 const float green[] = { 0.143051f, 0.0606079f, 0.713913f }; | 99 const float green[] = { 0.143051f, 0.0606079f, 0.713913f }; |
99 const float blue[] = { 0.436035f, 0.222488f, 0.013916f }; | 100 const float blue[] = { 0.436035f, 0.222488f, 0.013916f }; |
100 const float gamma[] = { 2.2f, 2.2f, 2.2f }; | 101 const float gamma[] = { 2.2f, 2.2f, 2.2f }; |
101 test_space(r, colorSpace, red, green, blue, gamma); | 102 test_space(r, colorSpace, red, green, blue, gamma); |
102 } | 103 } |
| 104 |
| 105 DEF_TEST(ColorSpaceSRGBCompare, r) { |
| 106 // Create an sRGB color space by name |
| 107 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k
SRGB_Named); |
| 108 |
| 109 // Create an sRGB color space by value |
| 110 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); |
| 111 srgbToxyzD50.set3x3ColMajorf(g_sRGB_XYZ); |
| 112 sk_sp<SkColorSpace> rgbColorSpace = SkColorSpace::NewRGB( |
| 113 SkColorSpace::SkGammas(2.2f, 2.2f, 2.2f), srgbToxyzD50); |
| 114 REPORTER_ASSERT(r, namedColorSpace == namedColorSpace); |
| 115 |
| 116 // Change a single value from the sRGB matrix |
| 117 srgbToxyzD50.set(2, 2, 0.5f); |
| 118 sk_sp<SkColorSpace> strangeColorSpace = SkColorSpace::NewRGB( |
| 119 SkColorSpace::SkGammas(2.2f, 2.2f, 2.2f), srgbToxyzD50); |
| 120 REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace); |
| 121 } |
OLD | NEW |