Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1373)

Side by Side Diff: tests/ColorSpaceTest.cpp

Issue 2377763002: Added kSRGBLinear_Named color space, along with tests (Closed)
Patch Set: Update assert. Better comment. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 SkColorSpace::NewRGB(SkColorSpace::kSRGB_RenderTargetGamma, srgbToxy zD50); 108 SkColorSpace::NewRGB(SkColorSpace::kSRGB_RenderTargetGamma, srgbToxy zD50);
109 REPORTER_ASSERT(r, rgbColorSpace == namedColorSpace); 109 REPORTER_ASSERT(r, rgbColorSpace == namedColorSpace);
110 110
111 // Change a single value from the sRGB matrix 111 // Change a single value from the sRGB matrix
112 srgbToxyzD50.set(2, 2, 0.5f); 112 srgbToxyzD50.set(2, 2, 0.5f);
113 sk_sp<SkColorSpace> strangeColorSpace = 113 sk_sp<SkColorSpace> strangeColorSpace =
114 SkColorSpace::NewRGB(SkColorSpace::kSRGB_RenderTargetGamma, srgbToxy zD50); 114 SkColorSpace::NewRGB(SkColorSpace::kSRGB_RenderTargetGamma, srgbToxy zD50);
115 REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace); 115 REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace);
116 } 116 }
117 117
118 DEF_TEST(ColorSpaceSRGBLinearCompare, r) {
119 // Create the linear sRGB color space by name
120 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k SRGBLinear_Named);
121
122 // Create the linear sRGB color space via the sRGB color space's makeLinearG amma()
123 sk_sp<SkColorSpace> viaSrgbColorSpace =
124 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)->makeLinearGamma();
125 REPORTER_ASSERT(r, namedColorSpace == viaSrgbColorSpace);
126
127 // Create a linear sRGB color space by value
128 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
129 srgbToxyzD50.set3x3RowMajorf(g_sRGB_XYZ);
130 sk_sp<SkColorSpace> rgbColorSpace =
131 SkColorSpace::NewRGB(SkColorSpace::kLinear_RenderTargetGamma, srgbToxyzD 50);
132 REPORTER_ASSERT(r, rgbColorSpace == namedColorSpace);
133
134 // Change a single value from the sRGB matrix
135 srgbToxyzD50.set(2, 2, 0.5f);
136 sk_sp<SkColorSpace> strangeColorSpace =
137 SkColorSpace::NewRGB(SkColorSpace::kLinear_RenderTargetGamma, srgbToxyzD 50);
138 REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace);
139 }
140
118 class ColorSpaceTest { 141 class ColorSpaceTest {
119 public: 142 public:
120 static sk_sp<SkData> WriteToICC(SkColorSpace* space) { 143 static sk_sp<SkData> WriteToICC(SkColorSpace* space) {
121 return as_CSB(space)->writeToICC(); 144 return as_CSB(space)->writeToICC();
122 } 145 }
123 }; 146 };
124 147
125 DEF_TEST(ColorSpaceWriteICC, r) { 148 DEF_TEST(ColorSpaceWriteICC, r) {
126 // Test writing a new ICC profile 149 // Test writing a new ICC profile
127 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k SRGB_Named); 150 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k SRGB_Named);
(...skipping 15 matching lines...) Expand all
143 sk_sp<SkData> newMonitorData = ColorSpaceTest::WriteToICC(monitorSpace.get() ); 166 sk_sp<SkData> newMonitorData = ColorSpaceTest::WriteToICC(monitorSpace.get() );
144 sk_sp<SkColorSpace> newMonitorSpace = SkColorSpace::NewICC(newMonitorData->d ata(), 167 sk_sp<SkColorSpace> newMonitorSpace = SkColorSpace::NewICC(newMonitorData->d ata(),
145 newMonitorData->s ize()); 168 newMonitorData->s ize());
146 REPORTER_ASSERT(r, monitorSpace->toXYZD50() == newMonitorSpace->toXYZD50()); 169 REPORTER_ASSERT(r, monitorSpace->toXYZD50() == newMonitorSpace->toXYZD50());
147 REPORTER_ASSERT(r, as_CSB(monitorSpace)->gammaNamed() == as_CSB(newMonitorSp ace)->gammaNamed()); 170 REPORTER_ASSERT(r, as_CSB(monitorSpace)->gammaNamed() == as_CSB(newMonitorSp ace)->gammaNamed());
148 } 171 }
149 172
150 DEF_TEST(ColorSpace_Named, r) { 173 DEF_TEST(ColorSpace_Named, r) {
151 const struct { 174 const struct {
152 SkColorSpace::Named fNamed; 175 SkColorSpace::Named fNamed;
153 bool fIsSRGB; 176 SkGammaNamed fExpectedGamma;
154 } recs[] { 177 } recs[] {
155 { SkColorSpace::kSRGB_Named, true }, 178 { SkColorSpace::kSRGB_Named, kSRGB_SkGammaNamed },
156 { SkColorSpace::kAdobeRGB_Named, false }, 179 { SkColorSpace::kAdobeRGB_Named, k2Dot2Curve_SkGammaNamed },
180 { SkColorSpace::kSRGBLinear_Named, kLinear_SkGammaNamed },
157 }; 181 };
158 182
159 for (auto rec : recs) { 183 for (auto rec : recs) {
160 auto cs = SkColorSpace::NewNamed(rec.fNamed); 184 auto cs = SkColorSpace::NewNamed(rec.fNamed);
161 REPORTER_ASSERT(r, cs); 185 REPORTER_ASSERT(r, cs);
162 if (cs) { 186 if (cs) {
163 if (rec.fIsSRGB) { 187 REPORTER_ASSERT(r, rec.fExpectedGamma == as_CSB(cs)->gammaNamed());
164 REPORTER_ASSERT(r, kSRGB_SkGammaNamed == as_CSB(cs)->gammaNamed( ));
165 } else {
166 REPORTER_ASSERT(r, k2Dot2Curve_SkGammaNamed == as_CSB(cs)->gamma Named());
167 }
168 } 188 }
169 } 189 }
170 190
171 SkImageInfo info = SkImageInfo::MakeS32(10, 10, kPremul_SkAlphaType); 191 SkImageInfo info = SkImageInfo::MakeS32(10, 10, kPremul_SkAlphaType);
172 REPORTER_ASSERT(r, info.gammaCloseToSRGB()); 192 REPORTER_ASSERT(r, info.gammaCloseToSRGB());
173 } 193 }
174 194
175 static void test_serialize(skiatest::Reporter* r, SkColorSpace* space, bool isNa med) { 195 static void test_serialize(skiatest::Reporter* r, SkColorSpace* space, bool isNa med) {
176 sk_sp<SkData> data1 = space->serialize(); 196 sk_sp<SkData> data1 = space->serialize();
177 197
178 size_t bytes = space->writeToMemory(nullptr); 198 size_t bytes = space->writeToMemory(nullptr);
179 sk_sp<SkData> data2 = SkData::MakeUninitialized(bytes); 199 sk_sp<SkData> data2 = SkData::MakeUninitialized(bytes);
180 space->writeToMemory(data2->writable_data()); 200 space->writeToMemory(data2->writable_data());
181 201
182 sk_sp<SkColorSpace> newSpace1 = SkColorSpace::Deserialize(data1->data(), dat a1->size()); 202 sk_sp<SkColorSpace> newSpace1 = SkColorSpace::Deserialize(data1->data(), dat a1->size());
183 sk_sp<SkColorSpace> newSpace2 = SkColorSpace::Deserialize(data2->data(), dat a2->size()); 203 sk_sp<SkColorSpace> newSpace2 = SkColorSpace::Deserialize(data2->data(), dat a2->size());
184 204
185 if (isNamed) { 205 if (isNamed) {
186 REPORTER_ASSERT(r, space == newSpace1.get()); 206 REPORTER_ASSERT(r, space == newSpace1.get());
187 REPORTER_ASSERT(r, space == newSpace2.get()); 207 REPORTER_ASSERT(r, space == newSpace2.get());
188 } else { 208 } else {
189 REPORTER_ASSERT(r, SkColorSpace::Equals(space, newSpace1.get())); 209 REPORTER_ASSERT(r, SkColorSpace::Equals(space, newSpace1.get()));
190 REPORTER_ASSERT(r, SkColorSpace::Equals(space, newSpace2.get())); 210 REPORTER_ASSERT(r, SkColorSpace::Equals(space, newSpace2.get()));
191 } 211 }
192 } 212 }
193 213
194 DEF_TEST(ColorSpace_Serialize, r) { 214 DEF_TEST(ColorSpace_Serialize, r) {
195 test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), t rue); 215 test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), t rue);
196 test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named).get( ), true); 216 test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named).get( ), true);
217 test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kSRGBLinear_Named).ge t(), true);
197 218
198 sk_sp<SkData> monitorData = SkData::MakeFromFileName( 219 sk_sp<SkData> monitorData = SkData::MakeFromFileName(
199 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); 220 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
200 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false); 221 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false);
201 monitorData = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32 x.icc").c_str()); 222 monitorData = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32 x.icc").c_str());
202 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false); 223 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false);
203 monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLe ft.icc").c_str()); 224 monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLe ft.icc").c_str());
204 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false); 225 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false);
205 monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRi ght.icc").c_str()); 226 monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRi ght.icc").c_str());
206 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false); 227 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr)); 264 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr));
244 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get())); 265 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get()));
245 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get())); 266 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get()));
246 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get())); 267 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get()));
247 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get())); 268 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get()));
248 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get())) ; 269 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get())) ;
249 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get())); 270 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get()));
250 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get())); 271 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get()));
251 REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get())); 272 REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get()));
252 } 273 }
OLDNEW
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698