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

Side by Side Diff: tests/ColorSpaceTest.cpp

Issue 2381553002: Move toXYZD50() to SkColorSpace_Base (Closed)
Patch Set: Rebase 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/gpu/GrColorSpaceXform.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"
11 #include "SkColorSpace_Base.h" 11 #include "SkColorSpace_Base.h"
12 #include "Test.h" 12 #include "Test.h"
13 13
14 #include "png.h" 14 #include "png.h"
15 15
16 static bool almost_equal(float a, float b) { 16 static bool almost_equal(float a, float b) {
17 return SkTAbs(a - b) < 0.001f; 17 return SkTAbs(a - b) < 0.001f;
18 } 18 }
19 19
20 static void test_space(skiatest::Reporter* r, SkColorSpace* space, 20 static void test_space(skiatest::Reporter* r, SkColorSpace* space,
21 const float red[], const float green[], const float blue[ ], 21 const float red[], const float green[], const float blue[ ],
22 const SkGammaNamed expectedGamma) { 22 const SkGammaNamed expectedGamma) {
23 23
24 REPORTER_ASSERT(r, nullptr != space); 24 REPORTER_ASSERT(r, nullptr != space);
25 REPORTER_ASSERT(r, expectedGamma == as_CSB(space)->gammaNamed()); 25 REPORTER_ASSERT(r, expectedGamma == as_CSB(space)->gammaNamed());
26 26
27 const SkMatrix44& mat = space->toXYZD50(); 27 const SkMatrix44& mat = as_CSB(space)->toXYZD50();
28 const float src[] = { 28 const float src[] = {
29 1, 0, 0, 1, 29 1, 0, 0, 1,
30 0, 1, 0, 1, 30 0, 1, 0, 1,
31 0, 0, 1, 1, 31 0, 0, 1, 1,
32 }; 32 };
33 const float* ref[3] = { red, green, blue }; 33 const float* ref[3] = { red, green, blue };
34 float dst[4]; 34 float dst[4];
35 for (int i = 0; i < 3; ++i) { 35 for (int i = 0; i < 3; ++i) {
36 mat.mapScalars(&src[i*4], dst); 36 mat.mapScalars(&src[i*4], dst);
37 REPORTER_ASSERT(r, almost_equal(ref[i][0], dst[0])); 37 REPORTER_ASSERT(r, almost_equal(ref[i][0], dst[0]));
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); 159 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
160 REPORTER_ASSERT(r, monitorData); 160 REPORTER_ASSERT(r, monitorData);
161 if (!monitorData) { 161 if (!monitorData) {
162 return; 162 return;
163 } 163 }
164 sk_sp<SkColorSpace> monitorSpace = SkColorSpace::NewICC(monitorData->data(), 164 sk_sp<SkColorSpace> monitorSpace = SkColorSpace::NewICC(monitorData->data(),
165 monitorData->size()) ; 165 monitorData->size()) ;
166 sk_sp<SkData> newMonitorData = ColorSpaceTest::WriteToICC(monitorSpace.get() ); 166 sk_sp<SkData> newMonitorData = ColorSpaceTest::WriteToICC(monitorSpace.get() );
167 sk_sp<SkColorSpace> newMonitorSpace = SkColorSpace::NewICC(newMonitorData->d ata(), 167 sk_sp<SkColorSpace> newMonitorSpace = SkColorSpace::NewICC(newMonitorData->d ata(),
168 newMonitorData->s ize()); 168 newMonitorData->s ize());
169 REPORTER_ASSERT(r, monitorSpace->toXYZD50() == newMonitorSpace->toXYZD50()); 169 REPORTER_ASSERT(r, as_CSB(monitorSpace)->toXYZD50() == as_CSB(newMonitorSpac e)->toXYZD50());
170 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());
171 } 171 }
172 172
173 DEF_TEST(ColorSpace_Named, r) { 173 DEF_TEST(ColorSpace_Named, r) {
174 const struct { 174 const struct {
175 SkColorSpace::Named fNamed; 175 SkColorSpace::Named fNamed;
176 SkGammaNamed fExpectedGamma; 176 SkGammaNamed fExpectedGamma;
177 } recs[] { 177 } recs[] {
178 { SkColorSpace::kSRGB_Named, kSRGB_SkGammaNamed }, 178 { SkColorSpace::kSRGB_Named, kSRGB_SkGammaNamed },
179 { SkColorSpace::kAdobeRGB_Named, k2Dot2Curve_SkGammaNamed }, 179 { SkColorSpace::kAdobeRGB_Named, k2Dot2Curve_SkGammaNamed },
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr)); 264 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr));
265 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get())); 265 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get()));
266 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get())); 266 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get()));
267 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get())); 267 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get()));
268 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get())); 268 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get()));
269 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get())) ; 269 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get())) ;
270 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get())); 270 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get()));
271 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get())); 271 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get()));
272 REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get())); 272 REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get()));
273 } 273 }
OLDNEW
« no previous file with comments | « src/gpu/GrColorSpaceXform.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698