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 28 matching lines...) Expand all Loading... | |
39 REPORTER_ASSERT(r, almost_equal(red[i], dst[0])); | 39 REPORTER_ASSERT(r, almost_equal(red[i], dst[0])); |
40 REPORTER_ASSERT(r, almost_equal(green[i], dst[1])); | 40 REPORTER_ASSERT(r, almost_equal(green[i], dst[1])); |
41 REPORTER_ASSERT(r, almost_equal(blue[i], dst[2])); | 41 REPORTER_ASSERT(r, almost_equal(blue[i], dst[2])); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 const float g_sRGB_XYZ[] = { 0.4358f, 0.2224f, 0.0139f, // R | 45 const float g_sRGB_XYZ[] = { 0.4358f, 0.2224f, 0.0139f, // R |
46 0.3853f, 0.7170f, 0.0971f, // G | 46 0.3853f, 0.7170f, 0.0971f, // G |
47 0.1430f, 0.0606f, 0.7139f }; // B | 47 0.1430f, 0.0606f, 0.7139f }; // B |
48 | 48 |
49 const float g_sRGB_gamma[] = { 2.2f, 2.2f, 2.2f }; | |
50 | |
49 DEF_TEST(ColorSpace_sRGB, r) { | 51 DEF_TEST(ColorSpace_sRGB, r) { |
50 const float srgb_gamma[] = { 2.2f, 2.2f, 2.2f }; | |
51 test_space(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), | 52 test_space(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), |
52 g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], srgb_gamma); | 53 g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], g_sRGB_gamma); |
53 | 54 |
54 } | 55 } |
55 | 56 |
56 static SkStreamAsset* resource(const char path[]) { | 57 static SkStreamAsset* resource(const char path[]) { |
57 SkString fullPath = GetResourcePath(path); | 58 SkString fullPath = GetResourcePath(path); |
58 return SkStream::NewFromFile(fullPath.c_str()); | 59 return SkStream::NewFromFile(fullPath.c_str()); |
59 } | 60 } |
60 | 61 |
61 DEF_TEST(ColorSpaceParsePngICCProfile, r) { | 62 DEF_TEST(ColorSpaceParsePngICCProfile, r) { |
62 SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png")); | 63 SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png")); |
63 REPORTER_ASSERT(r, nullptr != stream); | 64 REPORTER_ASSERT(r, nullptr != stream); |
64 if (!stream) { | 65 if (!stream) { |
65 return; | 66 return; |
66 } | 67 } |
67 | 68 |
68 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); | 69 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
69 REPORTER_ASSERT(r, nullptr != codec); | 70 REPORTER_ASSERT(r, nullptr != codec); |
70 | 71 |
71 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M INOR >= 6) | 72 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M INOR >= 6) |
72 SkColorSpace* colorSpace = codec->getColorSpace(); | 73 SkColorSpace* colorSpace = codec->getColorSpace(); |
73 REPORTER_ASSERT(r, nullptr != colorSpace); | 74 REPORTER_ASSERT(r, nullptr != colorSpace); |
74 | 75 |
75 const float red[] = { 0.436066f, 0.222488f, 0.013916f }; | 76 test_space(r, colorSpace, &g_sRGB_XYZ[0], &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], g_ sRGB_gamma); |
76 const float green[] = { 0.385147f, 0.716873f, 0.0970764f }; | |
77 const float blue[] = { 0.143066f, 0.0606079f, 0.714096f }; | |
78 const float gamma[] = { 2.2f, 2.2f, 2.2f }; | |
79 test_space(r, colorSpace, red, green, blue, gamma); | |
80 #endif | 77 #endif |
81 } | 78 } |
82 | 79 |
83 DEF_TEST(ColorSpaceParseJpegICCProfile, r) { | 80 DEF_TEST(ColorSpaceParseJpegICCProfile, r) { |
84 SkAutoTDelete<SkStream> stream(resource("icc-v2-gbr.jpg")); | 81 SkAutoTDelete<SkStream> stream(resource("icc-v2-gbr.jpg")); |
85 REPORTER_ASSERT(r, nullptr != stream); | 82 REPORTER_ASSERT(r, nullptr != stream); |
86 if (!stream) { | 83 if (!stream) { |
87 return; | 84 return; |
88 } | 85 } |
89 | 86 |
90 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); | 87 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
91 REPORTER_ASSERT(r, nullptr != codec); | 88 REPORTER_ASSERT(r, nullptr != codec); |
92 if (!codec) { | 89 if (!codec) { |
93 return; | 90 return; |
94 } | 91 } |
95 | 92 |
96 SkColorSpace* colorSpace = codec->getColorSpace(); | 93 SkColorSpace* colorSpace = codec->getColorSpace(); |
97 REPORTER_ASSERT(r, nullptr != colorSpace); | 94 REPORTER_ASSERT(r, nullptr != colorSpace); |
98 | 95 |
99 const float red[] = { 0.385117f, 0.716904f, 0.0970612f }; | 96 const float red[] = { 0.385117f, 0.716904f, 0.0970612f }; |
100 const float green[] = { 0.143051f, 0.0606079f, 0.713913f }; | 97 const float green[] = { 0.143051f, 0.0606079f, 0.713913f }; |
101 const float blue[] = { 0.436035f, 0.222488f, 0.013916f }; | 98 const float blue[] = { 0.436035f, 0.222488f, 0.013916f }; |
102 const float gamma[] = { 2.2f, 2.2f, 2.2f }; | 99 test_space(r, colorSpace, red, green, blue, g_sRGB_gamma); |
103 test_space(r, colorSpace, red, green, blue, gamma); | |
104 } | 100 } |
105 | 101 |
106 DEF_TEST(ColorSpaceSRGBCompare, r) { | 102 DEF_TEST(ColorSpaceSRGBCompare, r) { |
107 // Create an sRGB color space by name | 103 // Create an sRGB color space by name |
108 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k SRGB_Named); | 104 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k SRGB_Named); |
109 | 105 |
110 | |
111 // Create an sRGB color space by value | 106 // Create an sRGB color space by value |
112 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); | 107 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); |
113 float sRGBGammas[3] = { 2.2f, 2.2f, 2.2f }; | |
114 srgbToxyzD50.set3x3ColMajorf(g_sRGB_XYZ); | 108 srgbToxyzD50.set3x3ColMajorf(g_sRGB_XYZ); |
115 sk_sp<SkColorSpace> rgbColorSpace = SkColorSpace::NewRGB(sRGBGammas, srgbTox yzD50); | 109 sk_sp<SkColorSpace> rgbColorSpace = SkColorSpace::NewRGB(g_sRGB_gamma, srgbT oxyzD50); |
116 REPORTER_ASSERT(r, namedColorSpace == namedColorSpace); | 110 REPORTER_ASSERT(r, rgbColorSpace == namedColorSpace); |
117 | 111 |
118 // Change a single value from the sRGB matrix | 112 // Change a single value from the sRGB matrix |
119 srgbToxyzD50.set(2, 2, 0.5f); | 113 srgbToxyzD50.set(2, 2, 0.5f); |
120 sk_sp<SkColorSpace> strangeColorSpace = SkColorSpace::NewRGB(sRGBGammas, srg bToxyzD50); | 114 sk_sp<SkColorSpace> strangeColorSpace = SkColorSpace::NewRGB(g_sRGB_gamma, s rgbToxyzD50); |
121 REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace); | 115 REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace); |
122 } | 116 } |
117 | |
118 DEF_TEST(ColorSpaceWriteICC, r) { | |
119 // Test writing a new ICC profile | |
120 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k SRGB_Named); | |
121 sk_sp<SkData> namedData = as_CSB(namedColorSpace)->writeToICC(); | |
122 sk_sp<SkColorSpace> iccColorSpace = SkColorSpace::NewICC(namedData->data(), namedData->size()); | |
123 test_space(r, iccColorSpace.get(), g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6 ], g_sRGB_gamma); | |
124 REPORTER_ASSERT(r, iccColorSpace == namedColorSpace); | |
125 | |
126 // Test saving the original ICC data | |
127 sk_sp<SkData> monitorData = SkData::MakeFromFileName( | |
128 GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str()); | |
129 REPORTER_ASSERT(r, monitorData); | |
130 if (!monitorData) { | |
131 return; | |
scroggo
2016/05/24 19:12:20
This should probably fail the test or print someth
msarett
2016/05/24 19:14:27
It should fail the statement above "REPORTER_ASSER
scroggo
2016/05/24 19:14:59
D'oh! Yes it should. Nvm...
| |
132 } | |
133 sk_sp<SkColorSpace> monitorSpace = SkColorSpace::NewICC(monitorData->data(), | |
134 monitorData->size()) ; | |
135 sk_sp<SkData> newMonitorData = as_CSB(monitorSpace)->writeToICC(); | |
136 sk_sp<SkColorSpace> newMonitorSpace = SkColorSpace::NewICC(newMonitorData->d ata(), | |
137 newMonitorData->s ize()); | |
138 REPORTER_ASSERT(r, monitorSpace->xyz() == newMonitorSpace->xyz()); | |
139 REPORTER_ASSERT(r, as_CSB(monitorSpace)->gammas() == as_CSB(newMonitorSpace) ->gammas()); | |
140 } | |
OLD | NEW |