Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2016 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "Resources.h" | |
| 9 #include "SkCodec.h" | |
| 10 #include "SkColorPriv.h" | |
| 11 #include "SkColorSpace.h" | |
| 12 #include "SkColorSpace_Base.h" | |
| 13 #include "SkColorSpaceXform.h" | |
| 14 #include "Test.h" | |
| 15 | |
| 16 class ColorSpaceXformTest { | |
| 17 public: | |
| 18 static SkDefaultXform* CreateDefaultXform(const sk_sp<SkGammas>& srcGamma, | |
| 19 const SkMatrix44& srcToDst, const sk_sp<SkGammas>& dstGamma) { | |
| 20 return new SkDefaultXform(srcGamma, srcToDst, dstGamma); | |
| 21 } | |
| 22 }; | |
| 23 | |
| 24 static void test_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& gammas) { | |
| 25 // Arbitrary set of 10 pixels | |
| 26 constexpr int width = 10; | |
| 27 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.
| |
| 28 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271, | |
| 29 0xFF32AB52, 0xFF0383BC, 0xFF000000, 0xFFFFFFFF, 0xFFDDEEFF, }; | |
| 30 uint32_t dstPixels[width]; | |
| 31 | |
| 32 // Identity matrix | |
| 33 SkMatrix44 srcToDst = SkMatrix44::I(); | |
| 34 | |
| 35 // Create and perform xform | |
| 36 std::unique_ptr<SkColorSpaceXform> xform( | |
| 37 ColorSpaceXformTest::CreateDefaultXform(gammas, srcToDst, gammas)); | |
| 38 xform->xform_RGBA_8888(dstPixels, srcPixels, width); | |
| 39 | |
| 40 // Since the matrix is the identity, and the gamma curves match, the pixels | |
| 41 // should be unchanged. | |
| 42 for (int i = 0; i < width; i++) { | |
| 43 // TODO (msarett): | |
| 44 // As the implementation changes, we may want to use a tolerance here. | |
| 45 REPORTER_ASSERT(r, ((srcPixels[i] >> 0) & 0xFF) == SkGetPackedR32(dstPi xels[i])); | |
| 46 REPORTER_ASSERT(r, ((srcPixels[i] >> 8) & 0xFF) == SkGetPackedG32(dstPi xels[i])); | |
| 47 REPORTER_ASSERT(r, ((srcPixels[i] >> 16) & 0xFF) == SkGetPackedB32(dstPi xels[i])); | |
| 48 REPORTER_ASSERT(r, ((srcPixels[i] >> 24) & 0xFF) == SkGetPackedA32(dstPi xels[i])); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 DEF_TEST(ColorSpaceXform_Gamma, r) { | |
| 53 // Lookup-table based gamma curves | |
| 54 SkGammaCurve r0, g0, b0; | |
| 55 constexpr size_t tableSize = 10; | |
| 56 r0.fTable = std::unique_ptr<float[]>(new float[tableSize]); | |
| 57 g0.fTable = std::unique_ptr<float[]>(new float[tableSize]); | |
| 58 b0.fTable = std::unique_ptr<float[]>(new float[tableSize]); | |
| 59 r0.fTableSize = g0.fTableSize = b0.fTableSize = 10; | |
| 60 r0.fTable[0] = g0.fTable[0] = b0.fTable[0] = 0.00f; | |
| 61 r0.fTable[1] = g0.fTable[1] = b0.fTable[1] = 0.05f; | |
| 62 r0.fTable[2] = g0.fTable[2] = b0.fTable[2] = 0.10f; | |
| 63 r0.fTable[3] = g0.fTable[3] = b0.fTable[3] = 0.15f; | |
| 64 r0.fTable[4] = g0.fTable[4] = b0.fTable[4] = 0.25f; | |
| 65 r0.fTable[5] = g0.fTable[5] = b0.fTable[5] = 0.35f; | |
| 66 r0.fTable[6] = g0.fTable[6] = b0.fTable[6] = 0.45f; | |
| 67 r0.fTable[7] = g0.fTable[7] = b0.fTable[7] = 0.60f; | |
| 68 r0.fTable[8] = g0.fTable[8] = b0.fTable[8] = 0.75f; | |
| 69 r0.fTable[9] = g0.fTable[9] = b0.fTable[9] = 1.00f; | |
| 70 sk_sp<SkGammas> gammas = sk_make_sp<SkGammas>(std::move(r0), std::move(g0), std::move(b0)); | |
| 71 test_xform(r, gammas); | |
| 72 | |
| 73 // 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
| |
| 74 SkGammaCurve r1, g1, b1; | |
| 75 | |
| 76 // Interval, switch xforms at 0.5f | |
| 77 r1.fD = g1.fD = b1.fD = 0.5f; | |
| 78 | |
| 79 // First equation, Y = 0.5f * X | |
| 80 r1.fE = g1.fE = b1.fE = 0.5f; | |
| 81 | |
| 82 // Second equation, Y = ((1.0f * X) + 0.0f) ^ 3.0f + 0.125f | |
| 83 // Note that the function is continuous: | |
| 84 // 0.5f * 0.5f = ((1.0f * 0.5f) + 0.0f) ^ 3.0f + 0.125f = 0.25f | |
| 85 r1.fA = g1.fA = b1.fA = 1.0f; | |
| 86 r1.fB = g1.fB = b1.fB = 0.0f; | |
| 87 r1.fC = g1.fC = b1.fC = 0.125f; | |
| 88 r1.fG = g1.fG = b1.fG = 3.0f; | |
| 89 gammas = sk_make_sp<SkGammas>(std::move(r1), std::move(g1), std::move(b1)); | |
| 90 test_xform(r, gammas); | |
| 91 | |
| 92 | |
| 93 // 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
| |
| 94 SkGammaCurve r2, g2, b2; | |
| 95 r2.fValue = g2.fValue = b2.fValue = 4.0f; | |
| 96 gammas = sk_make_sp<SkGammas>(std::move(r2), std::move(g2), std::move(b2)); | |
| 97 test_xform(r, gammas); | |
| 98 } | |
| OLD | NEW |