| 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 "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkColorSpace.h" | 11 #include "SkColorSpace.h" |
| 12 #include "SkColorSpace_Base.h" | 12 #include "SkColorSpace_Base.h" |
| 13 #include "SkColorSpaceXform.h" | 13 #include "SkColorSpaceXform.h" |
| 14 #include "Test.h" | 14 #include "Test.h" |
| 15 | 15 |
| 16 class ColorSpaceXformTest { | 16 class ColorSpaceXformTest { |
| 17 public: | 17 public: |
| 18 static std::unique_ptr<SkColorSpaceXform> CreateDefaultXform(const sk_sp<SkG
ammas>& srcGamma, | 18 static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<Sk
Gammas>& gammas) { |
| 19 const SkMatrix44& srcToDst, const sk_sp<SkGammas>& dstGamma) { | 19 // Logically we can pass any matrix here. For simplicty, pass I(), i.e.
D50 XYZ gamut. |
| 20 | 20 sk_sp<SkColorSpace> space(new SkColorSpace_Base(nullptr, gammas, SkMatri
x::I(), nullptr)); |
| 21 sk_sp<SkColorSpace> srcSpace( | 21 return SkColorSpaceXform::New(space, space); |
| 22 new SkColorSpace_Base(nullptr, srcGamma, SkMatrix::I(), nullptr)
); | |
| 23 sk_sp<SkColorSpace> dstSpace( | |
| 24 new SkColorSpace_Base(nullptr, dstGamma, SkMatrix::I(), nullptr)
); | |
| 25 | |
| 26 return SkColorSpaceXform::New(srcSpace, dstSpace); | |
| 27 } | 22 } |
| 28 }; | 23 }; |
| 29 | 24 |
| 30 static bool almost_equal(int x, int y) { | 25 static bool almost_equal(int x, int y) { |
| 31 return SkTAbs(x - y) <= 1; | 26 return SkTAbs(x - y) <= 1; |
| 32 } | 27 } |
| 33 | 28 |
| 34 static void test_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& gammas) { | 29 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga
mmas) { |
| 35 // Arbitrary set of 10 pixels | 30 // Arbitrary set of 10 pixels |
| 36 constexpr int width = 10; | 31 constexpr int width = 10; |
| 37 constexpr uint32_t srcPixels[width] = { | 32 constexpr uint32_t srcPixels[width] = { |
| 38 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271, | 33 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271, |
| 39 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, }; | 34 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, }; |
| 40 uint32_t dstPixels[width]; | 35 uint32_t dstPixels[width]; |
| 41 | 36 |
| 42 // Identity matrix | 37 // Create and perform an identity xform. |
| 43 SkMatrix44 srcToDst = SkMatrix44::I(); | 38 std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdenti
tyXform(gammas); |
| 44 | |
| 45 // Create and perform xform | |
| 46 std::unique_ptr<SkColorSpaceXform> xform = | |
| 47 ColorSpaceXformTest::CreateDefaultXform(gammas, srcToDst, gammas); | |
| 48 xform->applyTo8888(dstPixels, srcPixels, width); | 39 xform->applyTo8888(dstPixels, srcPixels, width); |
| 49 | 40 |
| 50 // Since the matrix is the identity, and the gamma curves match, the pixels | 41 // Since the src->dst matrix is the identity, and the gamma curves match, |
| 51 // should be unchanged. | 42 // the pixels should be unchanged. |
| 52 for (int i = 0; i < width; i++) { | 43 for (int i = 0; i < width; i++) { |
| 53 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF), | 44 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF), |
| 54 SkGetPackedR32(dstPixels[i]))); | 45 SkGetPackedR32(dstPixels[i]))); |
| 55 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF), | 46 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF), |
| 56 SkGetPackedG32(dstPixels[i]))); | 47 SkGetPackedG32(dstPixels[i]))); |
| 57 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF), | 48 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF), |
| 58 SkGetPackedB32(dstPixels[i]))); | 49 SkGetPackedB32(dstPixels[i]))); |
| 59 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF), | 50 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF), |
| 60 SkGetPackedA32(dstPixels[i]))); | 51 SkGetPackedA32(dstPixels[i]))); |
| 61 } | 52 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 74 red.fTable[2] = green.fTable[2] = blue.fTable[2] = 0.10f; | 65 red.fTable[2] = green.fTable[2] = blue.fTable[2] = 0.10f; |
| 75 red.fTable[3] = green.fTable[3] = blue.fTable[3] = 0.15f; | 66 red.fTable[3] = green.fTable[3] = blue.fTable[3] = 0.15f; |
| 76 red.fTable[4] = green.fTable[4] = blue.fTable[4] = 0.25f; | 67 red.fTable[4] = green.fTable[4] = blue.fTable[4] = 0.25f; |
| 77 red.fTable[5] = green.fTable[5] = blue.fTable[5] = 0.35f; | 68 red.fTable[5] = green.fTable[5] = blue.fTable[5] = 0.35f; |
| 78 red.fTable[6] = green.fTable[6] = blue.fTable[6] = 0.45f; | 69 red.fTable[6] = green.fTable[6] = blue.fTable[6] = 0.45f; |
| 79 red.fTable[7] = green.fTable[7] = blue.fTable[7] = 0.60f; | 70 red.fTable[7] = green.fTable[7] = blue.fTable[7] = 0.60f; |
| 80 red.fTable[8] = green.fTable[8] = blue.fTable[8] = 0.75f; | 71 red.fTable[8] = green.fTable[8] = blue.fTable[8] = 0.75f; |
| 81 red.fTable[9] = green.fTable[9] = blue.fTable[9] = 1.00f; | 72 red.fTable[9] = green.fTable[9] = blue.fTable[9] = 1.00f; |
| 82 sk_sp<SkGammas> gammas = | 73 sk_sp<SkGammas> gammas = |
| 83 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu
e)); | 74 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu
e)); |
| 84 test_xform(r, gammas); | 75 test_identity_xform(r, gammas); |
| 85 } | 76 } |
| 86 | 77 |
| 87 DEF_TEST(ColorSpaceXform_ParametricGamma, r) { | 78 DEF_TEST(ColorSpaceXform_ParametricGamma, r) { |
| 88 // Parametric gamma curves | 79 // Parametric gamma curves |
| 89 SkGammaCurve red, green, blue; | 80 SkGammaCurve red, green, blue; |
| 90 | 81 |
| 91 // Interval, switch xforms at 0.0031308f | 82 // Interval, switch xforms at 0.0031308f |
| 92 red.fD = green.fD = blue.fD = 0.04045f; | 83 red.fD = green.fD = blue.fD = 0.04045f; |
| 93 | 84 |
| 94 // First equation: | 85 // First equation: |
| 95 red.fE = green.fE = blue.fE = 1.0f / 12.92f; | 86 red.fE = green.fE = blue.fE = 1.0f / 12.92f; |
| 96 | 87 |
| 97 // Second equation: | 88 // Second equation: |
| 98 // Note that the function is continuous (it's actually sRGB). | 89 // Note that the function is continuous (it's actually sRGB). |
| 99 red.fA = green.fA = blue.fA = 1.0f / 1.055f; | 90 red.fA = green.fA = blue.fA = 1.0f / 1.055f; |
| 100 red.fB = green.fB = blue.fB = 0.055f / 1.055f; | 91 red.fB = green.fB = blue.fB = 0.055f / 1.055f; |
| 101 red.fC = green.fC = blue.fC = 0.0f; | 92 red.fC = green.fC = blue.fC = 0.0f; |
| 102 red.fG = green.fG = blue.fG = 2.4f; | 93 red.fG = green.fG = blue.fG = 2.4f; |
| 103 sk_sp<SkGammas> gammas = | 94 sk_sp<SkGammas> gammas = |
| 104 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu
e)); | 95 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu
e)); |
| 105 test_xform(r, gammas); | 96 test_identity_xform(r, gammas); |
| 106 } | 97 } |
| 107 | 98 |
| 108 DEF_TEST(ColorSpaceXform_ExponentialGamma, r) { | 99 DEF_TEST(ColorSpaceXform_ExponentialGamma, r) { |
| 109 // Exponential gamma curves | 100 // Exponential gamma curves |
| 110 SkGammaCurve red, green, blue; | 101 SkGammaCurve red, green, blue; |
| 111 red.fValue = green.fValue = blue.fValue = 1.4f; | 102 red.fValue = green.fValue = blue.fValue = 1.4f; |
| 112 sk_sp<SkGammas> gammas = | 103 sk_sp<SkGammas> gammas = |
| 113 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu
e)); | 104 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu
e)); |
| 114 test_xform(r, gammas); | 105 test_identity_xform(r, gammas); |
| 115 } | 106 } |
| OLD | NEW |