2016-06-06 19:02:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Resources.h"
|
|
|
|
#include "SkCodec.h"
|
2016-09-16 18:45:58 +00:00
|
|
|
#include "SkCodecPriv.h"
|
2016-06-06 19:02:31 +00:00
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkColorSpace.h"
|
2016-11-11 23:27:39 +00:00
|
|
|
#include "SkColorSpace_A2B.h"
|
2016-06-06 19:02:31 +00:00
|
|
|
#include "SkColorSpace_Base.h"
|
2016-10-18 17:02:51 +00:00
|
|
|
#include "SkColorSpace_XYZ.h"
|
2016-10-11 19:15:03 +00:00
|
|
|
#include "SkColorSpaceXform_Base.h"
|
2016-06-06 19:02:31 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2016-12-01 18:44:07 +00:00
|
|
|
static constexpr int kChannels = 3;
|
|
|
|
|
2016-06-06 19:02:31 +00:00
|
|
|
class ColorSpaceXformTest {
|
|
|
|
public:
|
2016-07-18 18:16:14 +00:00
|
|
|
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.
|
2016-10-18 17:02:51 +00:00
|
|
|
sk_sp<SkColorSpace> space(new SkColorSpace_XYZ(
|
2017-03-24 14:06:03 +00:00
|
|
|
kNonStandard_SkGammaNamed, gammas, SkMatrix::I(), nullptr));
|
2016-08-24 00:53:06 +00:00
|
|
|
|
|
|
|
// Use special testing entry point, so we don't skip the xform, even though src == dst.
|
2016-10-18 17:02:51 +00:00
|
|
|
return SlowIdentityXform(static_cast<SkColorSpace_XYZ*>(space.get()));
|
2016-06-06 19:02:31 +00:00
|
|
|
}
|
2016-11-11 23:27:39 +00:00
|
|
|
|
|
|
|
static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform_A2B(
|
|
|
|
SkGammaNamed gammaNamed, const sk_sp<SkGammas>& gammas) {
|
|
|
|
std::vector<SkColorSpace_A2B::Element> srcElements;
|
|
|
|
// sRGB
|
|
|
|
const float values[16] = {
|
|
|
|
0.4358f, 0.3853f, 0.1430f, 0.0f,
|
|
|
|
0.2224f, 0.7170f, 0.0606f, 0.0f,
|
|
|
|
0.0139f, 0.0971f, 0.7139f, 0.0f,
|
|
|
|
0.0000f, 0.0000f, 0.0000f, 1.0f
|
|
|
|
};
|
|
|
|
SkMatrix44 arbitraryMatrix{SkMatrix44::kUninitialized_Constructor};
|
|
|
|
arbitraryMatrix.setRowMajorf(values);
|
|
|
|
if (kNonStandard_SkGammaNamed == gammaNamed) {
|
2016-12-01 18:44:07 +00:00
|
|
|
SkASSERT(gammas);
|
2016-11-11 23:27:39 +00:00
|
|
|
srcElements.push_back(SkColorSpace_A2B::Element(gammas));
|
|
|
|
} else {
|
2016-12-01 18:44:07 +00:00
|
|
|
srcElements.push_back(SkColorSpace_A2B::Element(gammaNamed, kChannels));
|
2016-11-11 23:27:39 +00:00
|
|
|
}
|
|
|
|
srcElements.push_back(SkColorSpace_A2B::Element(arbitraryMatrix));
|
2016-12-01 18:44:07 +00:00
|
|
|
auto srcSpace =
|
|
|
|
ColorSpaceXformTest::CreateA2BSpace(SkColorSpace_A2B::PCS::kXYZ,
|
2017-01-12 23:36:38 +00:00
|
|
|
SkColorSpace_Base::kRGB_ICCTypeFlag,
|
2016-12-01 18:44:07 +00:00
|
|
|
std::move(srcElements));
|
2016-11-11 23:27:39 +00:00
|
|
|
sk_sp<SkColorSpace> dstSpace(new SkColorSpace_XYZ(gammaNamed, gammas, arbitraryMatrix,
|
2017-03-24 14:06:03 +00:00
|
|
|
nullptr));
|
2016-11-11 23:27:39 +00:00
|
|
|
|
|
|
|
return SkColorSpaceXform::New(static_cast<SkColorSpace_A2B*>(srcSpace.get()),
|
|
|
|
static_cast<SkColorSpace_XYZ*>(dstSpace.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkColorSpace> CreateA2BSpace(SkColorSpace_A2B::PCS pcs,
|
2017-01-12 23:36:38 +00:00
|
|
|
SkColorSpace_Base::ICCTypeFlag iccType,
|
2016-11-11 23:27:39 +00:00
|
|
|
std::vector<SkColorSpace_A2B::Element> elements) {
|
2017-01-12 23:36:38 +00:00
|
|
|
return sk_sp<SkColorSpace>(new SkColorSpace_A2B(iccType, std::move(elements),
|
2016-12-01 18:44:07 +00:00
|
|
|
pcs, nullptr));
|
2016-11-11 23:27:39 +00:00
|
|
|
}
|
2016-06-06 19:02:31 +00:00
|
|
|
};
|
|
|
|
|
2017-04-17 18:43:59 +00:00
|
|
|
static bool almost_equal(int x, int y, int tol=1) {
|
|
|
|
return SkTAbs(x-y) <= tol;
|
2016-06-22 21:07:48 +00:00
|
|
|
}
|
|
|
|
|
2016-10-16 14:20:41 +00:00
|
|
|
static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& gammas,
|
|
|
|
bool repeat) {
|
2016-06-06 19:02:31 +00:00
|
|
|
// Arbitrary set of 10 pixels
|
|
|
|
constexpr int width = 10;
|
|
|
|
constexpr uint32_t srcPixels[width] = {
|
|
|
|
0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271,
|
2016-06-22 21:07:48 +00:00
|
|
|
0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, };
|
2016-06-06 19:02:31 +00:00
|
|
|
uint32_t dstPixels[width];
|
|
|
|
|
2016-07-18 18:16:14 +00:00
|
|
|
// Create and perform an identity xform.
|
|
|
|
std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdentityXform(gammas);
|
2016-10-11 19:15:03 +00:00
|
|
|
bool result = xform->apply(select_xform_format(kN32_SkColorType), dstPixels,
|
|
|
|
SkColorSpaceXform::kBGRA_8888_ColorFormat, srcPixels, width,
|
|
|
|
kOpaque_SkAlphaType);
|
|
|
|
REPORTER_ASSERT(r, result);
|
2016-06-06 19:02:31 +00:00
|
|
|
|
2016-07-18 18:16:14 +00:00
|
|
|
// Since the src->dst matrix is the identity, and the gamma curves match,
|
|
|
|
// the pixels should be unchanged.
|
2016-06-06 19:02:31 +00:00
|
|
|
for (int i = 0; i < width; i++) {
|
2016-06-22 21:07:48 +00:00
|
|
|
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF),
|
2016-09-22 19:37:04 +00:00
|
|
|
SkGetPackedB32(dstPixels[i])));
|
2016-06-22 21:07:48 +00:00
|
|
|
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF),
|
2016-08-24 00:53:06 +00:00
|
|
|
SkGetPackedG32(dstPixels[i])));
|
2016-06-22 21:07:48 +00:00
|
|
|
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF),
|
2016-09-22 19:37:04 +00:00
|
|
|
SkGetPackedR32(dstPixels[i])));
|
2016-06-22 21:07:48 +00:00
|
|
|
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF),
|
2016-08-24 00:53:06 +00:00
|
|
|
SkGetPackedA32(dstPixels[i])));
|
2016-06-06 19:02:31 +00:00
|
|
|
}
|
2016-10-16 14:20:41 +00:00
|
|
|
|
|
|
|
if (repeat) {
|
|
|
|
// We should cache part of the transform after the run. So it is interesting
|
|
|
|
// to make sure it still runs correctly the second time.
|
|
|
|
test_identity_xform(r, gammas, false);
|
|
|
|
}
|
2016-06-06 19:02:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 23:27:39 +00:00
|
|
|
static void test_identity_xform_A2B(skiatest::Reporter* r, SkGammaNamed gammaNamed,
|
2017-04-17 18:43:59 +00:00
|
|
|
const sk_sp<SkGammas>& gammas, int tol=1) {
|
2016-11-11 23:27:39 +00:00
|
|
|
// Arbitrary set of 10 pixels
|
|
|
|
constexpr int width = 10;
|
|
|
|
constexpr uint32_t srcPixels[width] = {
|
|
|
|
0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271,
|
|
|
|
0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, };
|
|
|
|
uint32_t dstPixels[width];
|
|
|
|
|
|
|
|
// Create and perform an identity xform.
|
|
|
|
auto xform = ColorSpaceXformTest::CreateIdentityXform_A2B(gammaNamed, gammas);
|
|
|
|
bool result = xform->apply(select_xform_format(kN32_SkColorType), dstPixels,
|
|
|
|
SkColorSpaceXform::kBGRA_8888_ColorFormat, srcPixels, width,
|
|
|
|
kOpaque_SkAlphaType);
|
|
|
|
REPORTER_ASSERT(r, result);
|
|
|
|
|
|
|
|
// Since the src->dst matrix is the identity, and the gamma curves match,
|
2017-04-17 18:43:59 +00:00
|
|
|
// the pixels should be ~unchanged.
|
2016-11-11 23:27:39 +00:00
|
|
|
for (int i = 0; i < width; i++) {
|
|
|
|
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF),
|
2017-04-17 18:43:59 +00:00
|
|
|
SkGetPackedB32(dstPixels[i]), tol));
|
2016-11-11 23:27:39 +00:00
|
|
|
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF),
|
2017-04-17 18:43:59 +00:00
|
|
|
SkGetPackedG32(dstPixels[i]), tol));
|
2016-11-11 23:27:39 +00:00
|
|
|
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF),
|
2017-04-17 18:43:59 +00:00
|
|
|
SkGetPackedR32(dstPixels[i]), tol));
|
2016-11-11 23:27:39 +00:00
|
|
|
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF),
|
2017-04-17 18:43:59 +00:00
|
|
|
SkGetPackedA32(dstPixels[i]), tol));
|
2016-11-11 23:27:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-06 19:02:31 +00:00
|
|
|
DEF_TEST(ColorSpaceXform_TableGamma, r) {
|
|
|
|
// Lookup-table based gamma curves
|
|
|
|
constexpr size_t tableSize = 10;
|
2016-07-21 14:11:26 +00:00
|
|
|
void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize);
|
2016-12-01 18:44:07 +00:00
|
|
|
sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas(kChannels));
|
|
|
|
for (int i = 0; i < kChannels; ++i) {
|
|
|
|
gammas->fType[i] = SkGammas::Type::kTable_Type;
|
|
|
|
gammas->fData[i].fTable.fSize = tableSize;
|
|
|
|
gammas->fData[i].fTable.fOffset = 0;
|
|
|
|
}
|
|
|
|
|
2016-07-21 14:11:26 +00:00
|
|
|
float* table = SkTAddOffset<float>(memory, sizeof(SkGammas));
|
|
|
|
table[0] = 0.00f;
|
|
|
|
table[1] = 0.05f;
|
|
|
|
table[2] = 0.10f;
|
|
|
|
table[3] = 0.15f;
|
|
|
|
table[4] = 0.25f;
|
|
|
|
table[5] = 0.35f;
|
|
|
|
table[6] = 0.45f;
|
|
|
|
table[7] = 0.60f;
|
|
|
|
table[8] = 0.75f;
|
|
|
|
table[9] = 1.00f;
|
2017-04-17 18:43:59 +00:00
|
|
|
// This table's pretty small compared to real ones in the wild (think 256),
|
|
|
|
// so we give test_identity_xform_A2B a wide tolerance.
|
|
|
|
// This lets us implement table transfer functions with a single lookup.
|
|
|
|
const int tolerance = 13;
|
|
|
|
|
2016-10-16 14:20:41 +00:00
|
|
|
test_identity_xform(r, gammas, true);
|
2017-04-17 18:43:59 +00:00
|
|
|
test_identity_xform_A2B(r, kNonStandard_SkGammaNamed, gammas, tolerance);
|
2016-06-06 19:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(ColorSpaceXform_ParametricGamma, r) {
|
|
|
|
// Parametric gamma curves
|
2016-10-11 20:57:50 +00:00
|
|
|
void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkColorSpaceTransferFn));
|
2016-12-01 18:44:07 +00:00
|
|
|
sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas(kChannels));
|
|
|
|
for (int i = 0; i < kChannels; ++i) {
|
|
|
|
gammas->fType[i] = SkGammas::Type::kParam_Type;
|
|
|
|
gammas->fData[i].fParamOffset = 0;
|
|
|
|
}
|
|
|
|
|
2016-10-11 20:57:50 +00:00
|
|
|
SkColorSpaceTransferFn* params = SkTAddOffset<SkColorSpaceTransferFn>
|
|
|
|
(memory, sizeof(SkGammas));
|
2016-06-06 19:02:31 +00:00
|
|
|
|
2016-12-19 19:33:35 +00:00
|
|
|
// Interval.
|
2016-07-21 14:11:26 +00:00
|
|
|
params->fD = 0.04045f;
|
2016-06-06 19:02:31 +00:00
|
|
|
|
2016-06-22 21:07:48 +00:00
|
|
|
// First equation:
|
2016-12-19 19:33:35 +00:00
|
|
|
params->fC = 1.0f / 12.92f;
|
2016-07-21 14:11:26 +00:00
|
|
|
params->fF = 0.0f;
|
2016-06-06 19:02:31 +00:00
|
|
|
|
2016-06-22 21:07:48 +00:00
|
|
|
// Second equation:
|
|
|
|
// Note that the function is continuous (it's actually sRGB).
|
2016-07-21 14:11:26 +00:00
|
|
|
params->fA = 1.0f / 1.055f;
|
|
|
|
params->fB = 0.055f / 1.055f;
|
2016-12-19 19:33:35 +00:00
|
|
|
params->fE = 0.0f;
|
2016-07-21 14:11:26 +00:00
|
|
|
params->fG = 2.4f;
|
2016-10-16 14:20:41 +00:00
|
|
|
test_identity_xform(r, gammas, true);
|
2016-12-01 18:44:07 +00:00
|
|
|
test_identity_xform_A2B(r, kNonStandard_SkGammaNamed, gammas);
|
2016-06-06 19:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(ColorSpaceXform_ExponentialGamma, r) {
|
|
|
|
// Exponential gamma curves
|
2016-12-01 18:44:07 +00:00
|
|
|
sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas(kChannels));
|
|
|
|
for (int i = 0; i < kChannels; ++i) {
|
|
|
|
gammas->fType[i] = SkGammas::Type::kValue_Type;
|
|
|
|
gammas->fData[i].fValue = 1.4f;
|
|
|
|
}
|
2016-10-16 14:20:41 +00:00
|
|
|
test_identity_xform(r, gammas, true);
|
2016-12-01 18:44:07 +00:00
|
|
|
test_identity_xform_A2B(r, kNonStandard_SkGammaNamed, gammas);
|
2016-07-21 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
2016-09-09 14:48:05 +00:00
|
|
|
DEF_TEST(ColorSpaceXform_NamedGamma, r) {
|
2016-12-01 18:44:07 +00:00
|
|
|
sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas(kChannels));
|
|
|
|
gammas->fType[0] = gammas->fType[1] = gammas->fType[2] = SkGammas::Type::kNamed_Type;
|
|
|
|
gammas->fData[0].fNamed = kSRGB_SkGammaNamed;
|
|
|
|
gammas->fData[1].fNamed = k2Dot2Curve_SkGammaNamed;
|
|
|
|
gammas->fData[2].fNamed = kLinear_SkGammaNamed;
|
2016-10-16 14:20:41 +00:00
|
|
|
test_identity_xform(r, gammas, true);
|
2016-12-01 18:44:07 +00:00
|
|
|
test_identity_xform_A2B(r, kNonStandard_SkGammaNamed, gammas);
|
|
|
|
test_identity_xform_A2B(r, kSRGB_SkGammaNamed, nullptr);
|
|
|
|
test_identity_xform_A2B(r, k2Dot2Curve_SkGammaNamed, nullptr);
|
|
|
|
test_identity_xform_A2B(r, kLinear_SkGammaNamed, nullptr);
|
2016-09-09 14:48:05 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 14:11:26 +00:00
|
|
|
DEF_TEST(ColorSpaceXform_NonMatchingGamma, r) {
|
|
|
|
constexpr size_t tableSize = 10;
|
|
|
|
void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize +
|
2016-10-11 20:57:50 +00:00
|
|
|
sizeof(SkColorSpaceTransferFn));
|
2016-12-01 18:44:07 +00:00
|
|
|
sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas(kChannels));
|
2016-07-21 14:11:26 +00:00
|
|
|
|
|
|
|
float* table = SkTAddOffset<float>(memory, sizeof(SkGammas));
|
|
|
|
table[0] = 0.00f;
|
|
|
|
table[1] = 0.15f;
|
|
|
|
table[2] = 0.20f;
|
|
|
|
table[3] = 0.25f;
|
|
|
|
table[4] = 0.35f;
|
|
|
|
table[5] = 0.45f;
|
|
|
|
table[6] = 0.55f;
|
|
|
|
table[7] = 0.70f;
|
|
|
|
table[8] = 0.85f;
|
|
|
|
table[9] = 1.00f;
|
|
|
|
|
2016-10-11 20:57:50 +00:00
|
|
|
SkColorSpaceTransferFn* params = SkTAddOffset<SkColorSpaceTransferFn>(memory,
|
|
|
|
sizeof(SkGammas) + sizeof(float) * tableSize);
|
2016-07-21 14:11:26 +00:00
|
|
|
params->fA = 1.0f / 1.055f;
|
|
|
|
params->fB = 0.055f / 1.055f;
|
2016-12-19 19:33:35 +00:00
|
|
|
params->fC = 1.0f / 12.92f;
|
2016-07-21 14:11:26 +00:00
|
|
|
params->fD = 0.04045f;
|
2016-12-19 19:33:35 +00:00
|
|
|
params->fE = 0.0f;
|
2016-07-21 14:11:26 +00:00
|
|
|
params->fF = 0.0f;
|
|
|
|
params->fG = 2.4f;
|
|
|
|
|
2016-12-01 18:44:07 +00:00
|
|
|
gammas->fType[0] = SkGammas::Type::kValue_Type;
|
|
|
|
gammas->fData[0].fValue = 1.2f;
|
2016-07-21 14:11:26 +00:00
|
|
|
|
jumper, parametric_{r,g,b,a}
I've tried a couple of ideas for approx_powf():
1) accumulate integer powers of x, then 4th roots, then 16th roots
2) continue 1) all the way to 256th roots
3) decompose into pow2 and log2, exploiting IEEE float layout
4) slightly tune constants used in 3)
5) accumulate integer powers of x, then 3+4) with different tuning
6) follow a source online, basically 5 with finesse
7) a new source quoting and improving on the method in 6).
7) seems perfect, enough that maybe we can explore improving its speed
at cost of precision. Might be nice to get rid of those divides. If we
allow a small tolerance (2-5) in our tests, we could use the very simple
fast forms from 3) (e.g. PS 5). I wish I had some images to look at!
Anything involving roots seems to be subverted by poor rsqrt precision.
This change of course affects the pipelines created by the tests for
exponential and full parametric gamma curves. What's less obvious is
that it also means SkJumper can now for the first time run the pipeline
created by the mixed gamma curves test. This means we now need to relax
our tolerance for the table-based channel, just like we did when
implementing table_{r,g,b,a}.
This took me an embarassingly long time to figure out. *face palm*
Change-Id: I451ee3c970a0a4a4e285f8aa8f6ef709a654d247
Reviewed-on: https://skia-review.googlesource.com/13656
Commit-Queue: Mike Klein <mtklein@chromium.org>
Reviewed-by: Matt Sarett <msarett@google.com>
Reviewed-by: Herb Derby <herb@google.com>
2017-04-17 23:32:05 +00:00
|
|
|
// See ColorSpaceXform_TableGamma... we've decided to allow some tolerance
|
|
|
|
// for SkJumper's implementation of tables.
|
|
|
|
const int tolerance = 12;
|
2016-12-01 18:44:07 +00:00
|
|
|
gammas->fType[1] = SkGammas::Type::kTable_Type;
|
|
|
|
gammas->fData[1].fTable.fSize = tableSize;
|
|
|
|
gammas->fData[1].fTable.fOffset = 0;
|
2016-07-21 14:11:26 +00:00
|
|
|
|
2016-12-01 18:44:07 +00:00
|
|
|
gammas->fType[2] = SkGammas::Type::kParam_Type;
|
|
|
|
gammas->fData[2].fParamOffset = sizeof(float) * tableSize;
|
2016-07-21 14:11:26 +00:00
|
|
|
|
2016-10-16 14:20:41 +00:00
|
|
|
test_identity_xform(r, gammas, true);
|
jumper, parametric_{r,g,b,a}
I've tried a couple of ideas for approx_powf():
1) accumulate integer powers of x, then 4th roots, then 16th roots
2) continue 1) all the way to 256th roots
3) decompose into pow2 and log2, exploiting IEEE float layout
4) slightly tune constants used in 3)
5) accumulate integer powers of x, then 3+4) with different tuning
6) follow a source online, basically 5 with finesse
7) a new source quoting and improving on the method in 6).
7) seems perfect, enough that maybe we can explore improving its speed
at cost of precision. Might be nice to get rid of those divides. If we
allow a small tolerance (2-5) in our tests, we could use the very simple
fast forms from 3) (e.g. PS 5). I wish I had some images to look at!
Anything involving roots seems to be subverted by poor rsqrt precision.
This change of course affects the pipelines created by the tests for
exponential and full parametric gamma curves. What's less obvious is
that it also means SkJumper can now for the first time run the pipeline
created by the mixed gamma curves test. This means we now need to relax
our tolerance for the table-based channel, just like we did when
implementing table_{r,g,b,a}.
This took me an embarassingly long time to figure out. *face palm*
Change-Id: I451ee3c970a0a4a4e285f8aa8f6ef709a654d247
Reviewed-on: https://skia-review.googlesource.com/13656
Commit-Queue: Mike Klein <mtklein@chromium.org>
Reviewed-by: Matt Sarett <msarett@google.com>
Reviewed-by: Herb Derby <herb@google.com>
2017-04-17 23:32:05 +00:00
|
|
|
test_identity_xform_A2B(r, kNonStandard_SkGammaNamed, gammas, tolerance);
|
2016-11-11 23:27:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(ColorSpaceXform_A2BCLUT, r) {
|
|
|
|
constexpr int inputChannels = 3;
|
|
|
|
constexpr int gp = 4; // # grid points
|
|
|
|
|
|
|
|
constexpr int numEntries = gp*gp*gp*3;
|
2016-12-01 18:44:07 +00:00
|
|
|
const uint8_t gridPoints[3] = {gp, gp, gp};
|
2016-11-11 23:27:39 +00:00
|
|
|
void* memory = sk_malloc_throw(sizeof(SkColorLookUpTable) + sizeof(float) * numEntries);
|
|
|
|
sk_sp<SkColorLookUpTable> colorLUT(new (memory) SkColorLookUpTable(inputChannels, gridPoints));
|
|
|
|
// make a CLUT that rotates R, G, and B ie R->G, G->B, B->R
|
|
|
|
float* table = SkTAddOffset<float>(memory, sizeof(SkColorLookUpTable));
|
|
|
|
for (int r = 0; r < gp; ++r) {
|
|
|
|
for (int g = 0; g < gp; ++g) {
|
|
|
|
for (int b = 0; b < gp; ++b) {
|
|
|
|
table[3*(gp*gp*r + gp*g + b) + 0] = g * (1.f / (gp - 1.f));
|
|
|
|
table[3*(gp*gp*r + gp*g + b) + 1] = b * (1.f / (gp - 1.f));
|
|
|
|
table[3*(gp*gp*r + gp*g + b) + 2] = r * (1.f / (gp - 1.f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// build an even distribution of pixels every (7 / 255) steps
|
|
|
|
// to test the xform on
|
|
|
|
constexpr int pixelgp = 7;
|
|
|
|
constexpr int numPixels = pixelgp*pixelgp*pixelgp;
|
|
|
|
SkAutoTMalloc<uint32_t> srcPixels(numPixels);
|
|
|
|
int srcIndex = 0;
|
|
|
|
for (int r = 0; r < pixelgp; ++r) {
|
|
|
|
for (int g = 0; g < pixelgp; ++g) {
|
|
|
|
for (int b = 0; b < pixelgp; ++b) {
|
|
|
|
const int red = (int) (r * (255.f / (pixelgp - 1.f)));
|
|
|
|
const int green = (int) (g * (255.f / (pixelgp - 1.f)));
|
|
|
|
const int blue = (int) (b * (255.f / (pixelgp - 1.f)));
|
|
|
|
srcPixels[srcIndex] = SkColorSetRGB(red, green, blue);
|
|
|
|
++srcIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkAutoTMalloc<uint32_t> dstPixels(numPixels);
|
|
|
|
|
|
|
|
// src space is identity besides CLUT
|
|
|
|
std::vector<SkColorSpace_A2B::Element> srcElements;
|
|
|
|
srcElements.push_back(SkColorSpace_A2B::Element(std::move(colorLUT)));
|
|
|
|
auto srcSpace = ColorSpaceXformTest::CreateA2BSpace(SkColorSpace_A2B::PCS::kXYZ,
|
2017-01-12 23:36:38 +00:00
|
|
|
SkColorSpace_Base::kRGB_ICCTypeFlag,
|
2016-11-11 23:27:39 +00:00
|
|
|
std::move(srcElements));
|
|
|
|
// dst space is entirely identity
|
|
|
|
auto dstSpace = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, SkMatrix44::I());
|
|
|
|
auto xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get());
|
|
|
|
bool result = xform->apply(SkColorSpaceXform::kRGBA_8888_ColorFormat, dstPixels.get(),
|
|
|
|
SkColorSpaceXform::kRGBA_8888_ColorFormat, srcPixels.get(),
|
|
|
|
numPixels, kOpaque_SkAlphaType);
|
|
|
|
REPORTER_ASSERT(r, result);
|
|
|
|
|
|
|
|
for (int i = 0; i < numPixels; ++i) {
|
|
|
|
REPORTER_ASSERT(r, almost_equal(SkColorGetR(srcPixels[i]),
|
|
|
|
SkColorGetG(dstPixels[i])));
|
|
|
|
REPORTER_ASSERT(r, almost_equal(SkColorGetG(srcPixels[i]),
|
|
|
|
SkColorGetB(dstPixels[i])));
|
|
|
|
REPORTER_ASSERT(r, almost_equal(SkColorGetB(srcPixels[i]),
|
|
|
|
SkColorGetR(dstPixels[i])));
|
|
|
|
}
|
2016-06-06 19:02:31 +00:00
|
|
|
}
|
2016-09-29 18:31:44 +00:00
|
|
|
|
2017-01-13 18:58:57 +00:00
|
|
|
DEF_TEST(SkColorSpaceXform_LoadTail, r) {
|
2017-01-13 20:42:45 +00:00
|
|
|
std::unique_ptr<uint64_t[]> srcPixel(new uint64_t[1]);
|
2017-01-13 18:58:57 +00:00
|
|
|
srcPixel[0] = 0;
|
|
|
|
uint32_t dstPixel;
|
2017-02-07 18:56:11 +00:00
|
|
|
sk_sp<SkColorSpace> adobe = SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named);
|
|
|
|
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
|
2017-01-13 18:58:57 +00:00
|
|
|
std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(adobe.get(), srgb.get());
|
|
|
|
|
|
|
|
// ASAN will catch us if we read past the tail.
|
|
|
|
bool success = xform->apply(SkColorSpaceXform::kRGBA_8888_ColorFormat, &dstPixel,
|
2017-01-13 20:42:45 +00:00
|
|
|
SkColorSpaceXform::kRGBA_U16_BE_ColorFormat, srcPixel.get(), 1,
|
2017-01-13 18:58:57 +00:00
|
|
|
kUnpremul_SkAlphaType);
|
|
|
|
REPORTER_ASSERT(r, success);
|
|
|
|
}
|
|
|
|
|