Refactored SkColorSpace and added in a Lab PCS GM
The refactoring breaks off A2B0 tag support into a separate
subclass of SkColorSpace_Base, while keeping the current
(besides CLUT) functionality in a XYZTRC subclass.
ICC profile loading is now aware of this and creates the A2B0
subclass when SkColorSpace::NewICC() is called on a profile
in need of the A2B0 functionality.
The LabPCSDemo GM loads a .icc profile containing a LAB PCS and
then runs a Lab->XYZ conversion on an image using it so we can
display it and test out the A2B0 SkColorSpace functionality,
sans a/b/m-curves, as well as the Lab->XYZ conversion code.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2389983002
Review-Url: https://codereview.chromium.org/2389983002
diff --git a/tests/ColorSpaceXformTest.cpp b/tests/ColorSpaceXformTest.cpp
index 6cf0dbe..477e61a 100644
--- a/tests/ColorSpaceXformTest.cpp
+++ b/tests/ColorSpaceXformTest.cpp
@@ -11,6 +11,7 @@
#include "SkColorPriv.h"
#include "SkColorSpace.h"
#include "SkColorSpace_Base.h"
+#include "SkColorSpace_XYZ.h"
#include "SkColorSpaceXform_Base.h"
#include "Test.h"
@@ -18,11 +19,11 @@
public:
static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<SkGammas>& gammas) {
// Logically we can pass any matrix here. For simplicty, pass I(), i.e. D50 XYZ gamut.
- sk_sp<SkColorSpace> space(new SkColorSpace_Base(
- nullptr, kNonStandard_SkGammaNamed, gammas, SkMatrix::I(), nullptr));
+ sk_sp<SkColorSpace> space(new SkColorSpace_XYZ(
+ kNonStandard_SkGammaNamed, gammas, SkMatrix::I(), nullptr));
// Use special testing entry point, so we don't skip the xform, even though src == dst.
- return SlowIdentityXform(space.get());
+ return SlowIdentityXform(static_cast<SkColorSpace_XYZ*>(space.get()));
}
};
@@ -175,25 +176,3 @@
test_identity_xform(r, gammas, true);
}
-DEF_TEST(ColorSpaceXform_applyCLUTMemoryAccess, r) {
- // buffers larger than 1024 (or 256 in GOOGLE3) will force ColorSpaceXform_Base::apply()
- // to heap-allocate a buffer that is used for CLUT application, and this test is here to
- // ensure that it no longer causes potential invalid memory accesses when this happens
- const size_t len = 2048;
- SkAutoTMalloc<uint32_t> src(len);
- SkAutoTMalloc<uint32_t> dst(len);
- for (uint32_t i = 0; i < len; ++i) {
- src[i] = i;
- }
- // this ICC profile has a CLUT in it
- const SkString filename(GetResourcePath("icc_profiles/upperRight.icc"));
- sk_sp<SkData> iccData = SkData::MakeFromFileName(filename.c_str());
- REPORTER_ASSERT_MESSAGE(r, iccData, "upperRight.icc profile required for test");
- sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(iccData->bytes(), iccData->size());
- sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
- auto xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get());
- bool result = xform->apply(SkColorSpaceXform::kRGBA_8888_ColorFormat, dst.get(),
- SkColorSpaceXform::kRGBA_8888_ColorFormat, src.get(), len,
- kUnpremul_SkAlphaType);
- REPORTER_ASSERT(r, result);
-}