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 "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_XYZTRC.h" |
14 #include "SkColorSpaceXform.h" | 15 #include "SkColorSpaceXform.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_XYZTRC( |
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(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 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 gammas->fGreenType = SkGammas::Type::kTable_Type; | 159 gammas->fGreenType = SkGammas::Type::kTable_Type; |
159 gammas->fGreenData.fTable.fSize = tableSize; | 160 gammas->fGreenData.fTable.fSize = tableSize; |
160 gammas->fGreenData.fTable.fOffset = 0; | 161 gammas->fGreenData.fTable.fOffset = 0; |
161 | 162 |
162 gammas->fBlueType = SkGammas::Type::kParam_Type; | 163 gammas->fBlueType = SkGammas::Type::kParam_Type; |
163 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize; | 164 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize; |
164 | 165 |
165 test_identity_xform(r, gammas); | 166 test_identity_xform(r, gammas); |
166 } | 167 } |
167 | 168 |
168 DEF_TEST(ColorSpaceXform_applyCLUTMemoryAccess, r) { | |
169 // buffers larger than 1024 (or 256 in GOOGLE3) will force ColorSpaceXform_B
ase::apply() | |
170 // to heap-allocate a buffer that is used for CLUT application, and this tes
t is here to | |
171 // ensure that it no longer causes potential invalid memory accesses when th
is happens | |
172 const size_t len = 2048; | |
173 SkAutoTMalloc<uint32_t> src(len); | |
174 SkAutoTMalloc<uint32_t> dst(len); | |
175 for (uint32_t i = 0; i < len; ++i) { | |
176 src[i] = i; | |
177 } | |
178 // this ICC profile has a CLUT in it | |
179 const SkString filename(GetResourcePath("icc_profiles/upperRight.icc")); | |
180 sk_sp<SkData> iccData = SkData::MakeFromFileName(filename.c_str()); | |
181 REPORTER_ASSERT_MESSAGE(r, iccData, "upperRight.icc profile required for tes
t"); | |
182 sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(iccData->bytes(), iccDat
a->size()); | |
183 sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Na
med); | |
184 auto xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get()); | |
185 xform->apply(dst.get(), src.get(), len, SkColorSpaceXform::kRGBA_8888_ColorF
ormat, | |
186 SkColorSpaceXform::kRGBA_8888_ColorFormat, kUnpremul_SkAlphaTyp
e); | |
187 } | |
OLD | NEW |