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

Side by Side Diff: tests/ColorSpaceTest.cpp

Issue 2221983002: Fix Equals and serialization for rare pngs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments Created 4 years, 4 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/core/SkColorSpace_Base.h ('k') | no next file » | 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } else { 166 } else {
167 REPORTER_ASSERT(r, SkColorSpace::k2Dot2Curve_GammaNamed == cs->g ammaNamed()); 167 REPORTER_ASSERT(r, SkColorSpace::k2Dot2Curve_GammaNamed == cs->g ammaNamed());
168 } 168 }
169 } 169 }
170 } 170 }
171 171
172 SkImageInfo info = SkImageInfo::MakeS32(10, 10, kPremul_SkAlphaType); 172 SkImageInfo info = SkImageInfo::MakeS32(10, 10, kPremul_SkAlphaType);
173 REPORTER_ASSERT(r, info.gammaCloseToSRGB()); 173 REPORTER_ASSERT(r, info.gammaCloseToSRGB());
174 } 174 }
175 175
176 static void matrix_equals(skiatest::Reporter* r, SkColorSpace* space1, SkColorSp ace* space2) {
177 REPORTER_ASSERT(r, space1->xyz().getFloat(0, 0) == space2->xyz().getFloat(0, 0));
178 REPORTER_ASSERT(r, space1->xyz().getFloat(0, 1) == space2->xyz().getFloat(0, 1));
179 REPORTER_ASSERT(r, space1->xyz().getFloat(0, 2) == space2->xyz().getFloat(0, 2));
180 REPORTER_ASSERT(r, space1->xyz().getFloat(0, 3) == space2->xyz().getFloat(0, 3));
181 REPORTER_ASSERT(r, space1->xyz().getFloat(1, 0) == space2->xyz().getFloat(1, 0));
182 REPORTER_ASSERT(r, space1->xyz().getFloat(1, 1) == space2->xyz().getFloat(1, 1));
183 REPORTER_ASSERT(r, space1->xyz().getFloat(1, 2) == space2->xyz().getFloat(1, 2));
184 REPORTER_ASSERT(r, space1->xyz().getFloat(1, 3) == space2->xyz().getFloat(1, 3));
185 REPORTER_ASSERT(r, space1->xyz().getFloat(2, 0) == space2->xyz().getFloat(2, 0));
186 REPORTER_ASSERT(r, space1->xyz().getFloat(2, 1) == space2->xyz().getFloat(2, 1));
187 REPORTER_ASSERT(r, space1->xyz().getFloat(2, 2) == space2->xyz().getFloat(2, 2));
188 REPORTER_ASSERT(r, space1->xyz().getFloat(2, 3) == space2->xyz().getFloat(2, 3));
189 REPORTER_ASSERT(r, space1->xyz().getFloat(3, 0) == space2->xyz().getFloat(3, 0));
190 REPORTER_ASSERT(r, space1->xyz().getFloat(3, 1) == space2->xyz().getFloat(3, 1));
191 REPORTER_ASSERT(r, space1->xyz().getFloat(3, 2) == space2->xyz().getFloat(3, 2));
192 REPORTER_ASSERT(r, space1->xyz().getFloat(3, 3) == space2->xyz().getFloat(3, 3));
193 }
194
195 static void test_serialize(skiatest::Reporter* r, SkColorSpace* space, bool isNa med) { 176 static void test_serialize(skiatest::Reporter* r, SkColorSpace* space, bool isNa med) {
196 sk_sp<SkData> data1 = space->serialize(); 177 sk_sp<SkData> data1 = space->serialize();
197 178
198 size_t bytes = space->writeToMemory(nullptr); 179 size_t bytes = space->writeToMemory(nullptr);
199 sk_sp<SkData> data2 = SkData::MakeUninitialized(bytes); 180 sk_sp<SkData> data2 = SkData::MakeUninitialized(bytes);
200 space->writeToMemory(data2->writable_data()); 181 space->writeToMemory(data2->writable_data());
201 182
202 sk_sp<SkColorSpace> newSpace1 = SkColorSpace::Deserialize(data1->data(), dat a1->size()); 183 sk_sp<SkColorSpace> newSpace1 = SkColorSpace::Deserialize(data1->data(), dat a1->size());
203 sk_sp<SkColorSpace> newSpace2 = SkColorSpace::Deserialize(data2->data(), dat a2->size()); 184 sk_sp<SkColorSpace> newSpace2 = SkColorSpace::Deserialize(data2->data(), dat a2->size());
204 185
205 if (isNamed) { 186 if (isNamed) {
206 REPORTER_ASSERT(r, space == newSpace1.get()); 187 REPORTER_ASSERT(r, space == newSpace1.get());
207 REPORTER_ASSERT(r, space == newSpace2.get()); 188 REPORTER_ASSERT(r, space == newSpace2.get());
208 } else { 189 } else {
209 REPORTER_ASSERT(r, space->gammaNamed() == newSpace1->gammaNamed()); 190 REPORTER_ASSERT(r, SkColorSpace::Equals(space, newSpace1.get()));
210 REPORTER_ASSERT(r, space->gammaNamed() == newSpace2->gammaNamed()); 191 REPORTER_ASSERT(r, SkColorSpace::Equals(space, newSpace2.get()));
211 matrix_equals(r, space, newSpace1.get());
212 matrix_equals(r, space, newSpace2.get());
213 } 192 }
214 } 193 }
215 194
216 DEF_TEST(ColorSpace_Serialize, r) { 195 DEF_TEST(ColorSpace_Serialize, r) {
217 test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), t rue); 196 test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), t rue);
218 test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named).get( ), true); 197 test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named).get( ), true);
219 198
220 sk_sp<SkData> monitorData = SkData::MakeFromFileName( 199 sk_sp<SkData> monitorData = SkData::MakeFromFileName(
221 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); 200 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
222 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false); 201 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false);
223 monitorData = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32 x.icc").c_str()); 202 monitorData = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32 x.icc").c_str());
224 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false); 203 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false);
225 monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLe ft.icc").c_str()); 204 monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLe ft.icc").c_str());
226 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false); 205 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false);
227 monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRi ght.icc").c_str()); 206 monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRi ght.icc").c_str());
228 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false); 207 test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->siz e()).get(), false);
208
209 const float gammas[] = { 1.1f, 1.2f, 1.7f, };
210 SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor);
211 test_serialize(r, SkColorSpace_Base::NewRGB(gammas, toXYZ).get(), false);
229 } 212 }
230 213
231 DEF_TEST(ColorSpace_Equals, r) { 214 DEF_TEST(ColorSpace_Equals, r) {
232 sk_sp<SkColorSpace> srgb = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) ; 215 sk_sp<SkColorSpace> srgb = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) ;
233 sk_sp<SkColorSpace> adobe = SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_N amed); 216 sk_sp<SkColorSpace> adobe = SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_N amed);
234 sk_sp<SkData> data = SkData::MakeFromFileName( 217 sk_sp<SkData> data = SkData::MakeFromFileName(
235 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); 218 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
236 sk_sp<SkColorSpace> z30 = SkColorSpace::NewICC(data->data(), data->size()); 219 sk_sp<SkColorSpace> z30 = SkColorSpace::NewICC(data->data(), data->size());
237 data = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc") .c_str()); 220 data = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc") .c_str());
238 sk_sp<SkColorSpace> z32 = SkColorSpace::NewICC(data->data(), data->size()); 221 sk_sp<SkColorSpace> z32 = SkColorSpace::NewICC(data->data(), data->size());
239 data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc" ).c_str()); 222 data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc" ).c_str());
240 sk_sp<SkColorSpace> upperLeft = SkColorSpace::NewICC(data->data(), data->siz e()); 223 sk_sp<SkColorSpace> upperLeft = SkColorSpace::NewICC(data->data(), data->siz e());
241 data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc ").c_str()); 224 data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc ").c_str());
242 sk_sp<SkColorSpace> upperRight = SkColorSpace::NewICC(data->data(), data->si ze()); 225 sk_sp<SkColorSpace> upperRight = SkColorSpace::NewICC(data->data(), data->si ze());
226 const float gammas1[] = { 1.1f, 1.2f, 1.3f, };
227 const float gammas2[] = { 1.1f, 1.2f, 1.7f, };
228 SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor);
229 sk_sp<SkColorSpace> rgb1 = SkColorSpace_Base::NewRGB(gammas1, toXYZ);
230 sk_sp<SkColorSpace> rgb2 = SkColorSpace_Base::NewRGB(gammas2, toXYZ);
231 sk_sp<SkColorSpace> rgb3 = SkColorSpace_Base::NewRGB(gammas1, toXYZ);
243 232
244 REPORTER_ASSERT(r, SkColorSpace::Equals(nullptr, nullptr)); 233 REPORTER_ASSERT(r, SkColorSpace::Equals(nullptr, nullptr));
245 REPORTER_ASSERT(r, SkColorSpace::Equals(srgb.get(), srgb.get())); 234 REPORTER_ASSERT(r, SkColorSpace::Equals(srgb.get(), srgb.get()));
246 REPORTER_ASSERT(r, SkColorSpace::Equals(adobe.get(), adobe.get())); 235 REPORTER_ASSERT(r, SkColorSpace::Equals(adobe.get(), adobe.get()));
247 REPORTER_ASSERT(r, SkColorSpace::Equals(z30.get(), z30.get())); 236 REPORTER_ASSERT(r, SkColorSpace::Equals(z30.get(), z30.get()));
248 REPORTER_ASSERT(r, SkColorSpace::Equals(z32.get(), z32.get())); 237 REPORTER_ASSERT(r, SkColorSpace::Equals(z32.get(), z32.get()));
249 REPORTER_ASSERT(r, SkColorSpace::Equals(upperLeft.get(), upperLeft.get())); 238 REPORTER_ASSERT(r, SkColorSpace::Equals(upperLeft.get(), upperLeft.get()));
250 REPORTER_ASSERT(r, SkColorSpace::Equals(upperRight.get(), upperRight.get())) ; 239 REPORTER_ASSERT(r, SkColorSpace::Equals(upperRight.get(), upperRight.get())) ;
240 REPORTER_ASSERT(r, SkColorSpace::Equals(rgb1.get(), rgb1.get()));
241 REPORTER_ASSERT(r, SkColorSpace::Equals(rgb1.get(), rgb3.get()));
251 242
252 REPORTER_ASSERT(r, !SkColorSpace::Equals(nullptr, srgb.get())); 243 REPORTER_ASSERT(r, !SkColorSpace::Equals(nullptr, srgb.get()));
253 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr)); 244 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr));
254 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get())); 245 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get()));
255 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get())); 246 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get()));
256 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get())); 247 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get()));
257 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get())); 248 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get()));
258 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get())) ; 249 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get())) ;
259 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get())); 250 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get()));
260 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get())); 251 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get()));
252 REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get()));
261 } 253 }
OLDNEW
« no previous file with comments | « src/core/SkColorSpace_Base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698