Index: tests/ColorSpaceXformTest.cpp |
diff --git a/tests/ColorSpaceXformTest.cpp b/tests/ColorSpaceXformTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e206d828d1556d5ecd480886a932d353364d1de3 |
--- /dev/null |
+++ b/tests/ColorSpaceXformTest.cpp |
@@ -0,0 +1,98 @@ |
+/* |
+ * 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" |
+#include "SkColorPriv.h" |
+#include "SkColorSpace.h" |
+#include "SkColorSpace_Base.h" |
+#include "SkColorSpaceXform.h" |
+#include "Test.h" |
+ |
+class ColorSpaceXformTest { |
+public: |
+ static SkDefaultXform* CreateDefaultXform(const sk_sp<SkGammas>& srcGamma, |
+ const SkMatrix44& srcToDst, const sk_sp<SkGammas>& dstGamma) { |
+ return new SkDefaultXform(srcGamma, srcToDst, dstGamma); |
+ } |
+}; |
+ |
+static void test_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& gammas) { |
+ // Arbitrary set of 10 pixels |
+ constexpr int width = 10; |
+ const uint32_t srcPixels[width] = { |
scroggo
2016/06/06 14:06:45
can this be constexpr too?
msarett
2016/06/06 17:33:44
Yes I think so.
|
+ 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271, |
+ 0xFF32AB52, 0xFF0383BC, 0xFF000000, 0xFFFFFFFF, 0xFFDDEEFF, }; |
+ uint32_t dstPixels[width]; |
+ |
+ // Identity matrix |
+ SkMatrix44 srcToDst = SkMatrix44::I(); |
+ |
+ // Create and perform xform |
+ std::unique_ptr<SkColorSpaceXform> xform( |
+ ColorSpaceXformTest::CreateDefaultXform(gammas, srcToDst, gammas)); |
+ xform->xform_RGBA_8888(dstPixels, srcPixels, width); |
+ |
+ // Since the matrix is the identity, and the gamma curves match, the pixels |
+ // should be unchanged. |
+ for (int i = 0; i < width; i++) { |
+ // TODO (msarett): |
+ // As the implementation changes, we may want to use a tolerance here. |
+ REPORTER_ASSERT(r, ((srcPixels[i] >> 0) & 0xFF) == SkGetPackedR32(dstPixels[i])); |
+ REPORTER_ASSERT(r, ((srcPixels[i] >> 8) & 0xFF) == SkGetPackedG32(dstPixels[i])); |
+ REPORTER_ASSERT(r, ((srcPixels[i] >> 16) & 0xFF) == SkGetPackedB32(dstPixels[i])); |
+ REPORTER_ASSERT(r, ((srcPixels[i] >> 24) & 0xFF) == SkGetPackedA32(dstPixels[i])); |
+ } |
+} |
+ |
+DEF_TEST(ColorSpaceXform_Gamma, r) { |
+ // Lookup-table based gamma curves |
+ SkGammaCurve r0, g0, b0; |
+ constexpr size_t tableSize = 10; |
+ r0.fTable = std::unique_ptr<float[]>(new float[tableSize]); |
+ g0.fTable = std::unique_ptr<float[]>(new float[tableSize]); |
+ b0.fTable = std::unique_ptr<float[]>(new float[tableSize]); |
+ r0.fTableSize = g0.fTableSize = b0.fTableSize = 10; |
+ r0.fTable[0] = g0.fTable[0] = b0.fTable[0] = 0.00f; |
+ r0.fTable[1] = g0.fTable[1] = b0.fTable[1] = 0.05f; |
+ r0.fTable[2] = g0.fTable[2] = b0.fTable[2] = 0.10f; |
+ r0.fTable[3] = g0.fTable[3] = b0.fTable[3] = 0.15f; |
+ r0.fTable[4] = g0.fTable[4] = b0.fTable[4] = 0.25f; |
+ r0.fTable[5] = g0.fTable[5] = b0.fTable[5] = 0.35f; |
+ r0.fTable[6] = g0.fTable[6] = b0.fTable[6] = 0.45f; |
+ r0.fTable[7] = g0.fTable[7] = b0.fTable[7] = 0.60f; |
+ r0.fTable[8] = g0.fTable[8] = b0.fTable[8] = 0.75f; |
+ r0.fTable[9] = g0.fTable[9] = b0.fTable[9] = 1.00f; |
+ sk_sp<SkGammas> gammas = sk_make_sp<SkGammas>(std::move(r0), std::move(g0), std::move(b0)); |
+ test_xform(r, gammas); |
+ |
+ // Parametric gamma curves |
scroggo
2016/06/06 14:06:45
Since this appears to be a whole new test that doe
msarett
2016/06/06 17:33:44
SGTM
|
+ SkGammaCurve r1, g1, b1; |
+ |
+ // Interval, switch xforms at 0.5f |
+ r1.fD = g1.fD = b1.fD = 0.5f; |
+ |
+ // First equation, Y = 0.5f * X |
+ r1.fE = g1.fE = b1.fE = 0.5f; |
+ |
+ // Second equation, Y = ((1.0f * X) + 0.0f) ^ 3.0f + 0.125f |
+ // Note that the function is continuous: |
+ // 0.5f * 0.5f = ((1.0f * 0.5f) + 0.0f) ^ 3.0f + 0.125f = 0.25f |
+ r1.fA = g1.fA = b1.fA = 1.0f; |
+ r1.fB = g1.fB = b1.fB = 0.0f; |
+ r1.fC = g1.fC = b1.fC = 0.125f; |
+ r1.fG = g1.fG = b1.fG = 3.0f; |
+ gammas = sk_make_sp<SkGammas>(std::move(r1), std::move(g1), std::move(b1)); |
+ test_xform(r, gammas); |
+ |
+ |
+ // Exponential gamma curves |
scroggo
2016/06/06 14:06:45
Again, this could probably be a new DEF_TEST.
msarett
2016/06/06 17:33:44
SGTM
|
+ SkGammaCurve r2, g2, b2; |
+ r2.fValue = g2.fValue = b2.fValue = 4.0f; |
+ gammas = sk_make_sp<SkGammas>(std::move(r2), std::move(g2), std::move(b2)); |
+ test_xform(r, gammas); |
+} |