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

Side by Side Diff: tests/ColorSpaceXformTest.cpp

Issue 2389983002: Refactored SkColorSpace and added in a Lab PCS GM (Closed)
Patch Set: migrated call from SkColorSpace_Base::makeLinearGamma() to SkColorSpace_XYZ::makeLinearGamma() 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 | « tests/ColorSpaceTest.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 "SkCodecPriv.h" 10 #include "SkCodecPriv.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkColorSpace.h" 12 #include "SkColorSpace.h"
13 #include "SkColorSpace_Base.h" 13 #include "SkColorSpace_Base.h"
14 #include "SkColorSpace_XYZ.h"
14 #include "SkColorSpaceXform_Base.h" 15 #include "SkColorSpaceXform_Base.h"
15 #include "Test.h" 16 #include "Test.h"
16 17
17 class ColorSpaceXformTest { 18 class ColorSpaceXformTest {
18 public: 19 public:
19 static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<Sk Gammas>& gammas) { 20 static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<Sk Gammas>& gammas) {
20 // Logically we can pass any matrix here. For simplicty, pass I(), i.e. D50 XYZ gamut. 21 // Logically we can pass any matrix here. For simplicty, pass I(), i.e. D50 XYZ gamut.
21 sk_sp<SkColorSpace> space(new SkColorSpace_Base( 22 sk_sp<SkColorSpace> space(new SkColorSpace_XYZ(
22 nullptr, kNonStandard_SkGammaNamed, gammas, SkMatrix::I(), nullp tr)); 23 kNonStandard_SkGammaNamed, gammas, SkMatrix::I(), nullptr));
23 24
24 // Use special testing entry point, so we don't skip the xform, even tho ugh src == dst. 25 // Use special testing entry point, so we don't skip the xform, even tho ugh src == dst.
25 return SlowIdentityXform(space.get()); 26 return SlowIdentityXform(static_cast<SkColorSpace_XYZ*>(space.get()));
26 } 27 }
27 }; 28 };
28 29
29 static bool almost_equal(int x, int y) { 30 static bool almost_equal(int x, int y) {
30 return SkTAbs(x - y) <= 1; 31 return SkTAbs(x - y) <= 1;
31 } 32 }
32 33
33 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga mmas, 34 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga mmas,
34 bool repeat) { 35 bool repeat) {
35 // Arbitrary set of 10 pixels 36 // Arbitrary set of 10 pixels
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 gammas->fGreenType = SkGammas::Type::kTable_Type; 169 gammas->fGreenType = SkGammas::Type::kTable_Type;
169 gammas->fGreenData.fTable.fSize = tableSize; 170 gammas->fGreenData.fTable.fSize = tableSize;
170 gammas->fGreenData.fTable.fOffset = 0; 171 gammas->fGreenData.fTable.fOffset = 0;
171 172
172 gammas->fBlueType = SkGammas::Type::kParam_Type; 173 gammas->fBlueType = SkGammas::Type::kParam_Type;
173 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize; 174 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize;
174 175
175 test_identity_xform(r, gammas, true); 176 test_identity_xform(r, gammas, true);
176 } 177 }
177 178
178 DEF_TEST(ColorSpaceXform_applyCLUTMemoryAccess, r) {
179 // buffers larger than 1024 (or 256 in GOOGLE3) will force ColorSpaceXform_B ase::apply()
180 // to heap-allocate a buffer that is used for CLUT application, and this tes t is here to
181 // ensure that it no longer causes potential invalid memory accesses when th is happens
182 const size_t len = 2048;
183 SkAutoTMalloc<uint32_t> src(len);
184 SkAutoTMalloc<uint32_t> dst(len);
185 for (uint32_t i = 0; i < len; ++i) {
186 src[i] = i;
187 }
188 // this ICC profile has a CLUT in it
189 const SkString filename(GetResourcePath("icc_profiles/upperRight.icc"));
190 sk_sp<SkData> iccData = SkData::MakeFromFileName(filename.c_str());
191 REPORTER_ASSERT_MESSAGE(r, iccData, "upperRight.icc profile required for tes t");
192 sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(iccData->bytes(), iccDat a->size());
193 sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Na med);
194 auto xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get());
195 bool result = xform->apply(SkColorSpaceXform::kRGBA_8888_ColorFormat, dst.ge t(),
196 SkColorSpaceXform::kRGBA_8888_ColorFormat, src.ge t(), len,
197 kUnpremul_SkAlphaType);
198 REPORTER_ASSERT(r, result);
199 }
OLDNEW
« no previous file with comments | « tests/ColorSpaceTest.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698