| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga
mmas) { | 30 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga
mmas) { |
| 31 // Arbitrary set of 10 pixels | 31 // Arbitrary set of 10 pixels |
| 32 constexpr int width = 10; | 32 constexpr int width = 10; |
| 33 constexpr uint32_t srcPixels[width] = { | 33 constexpr uint32_t srcPixels[width] = { |
| 34 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271, | 34 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271, |
| 35 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, }; | 35 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, }; |
| 36 uint32_t dstPixels[width]; | 36 uint32_t dstPixels[width]; |
| 37 | 37 |
| 38 // Create and perform an identity xform. | 38 // Create and perform an identity xform. |
| 39 std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdenti
tyXform(gammas); | 39 std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdenti
tyXform(gammas); |
| 40 xform->applyTo8888(dstPixels, srcPixels, width); | 40 xform->applyToRGBA(dstPixels, srcPixels, width); |
| 41 | 41 |
| 42 // Since the src->dst matrix is the identity, and the gamma curves match, | 42 // Since the src->dst matrix is the identity, and the gamma curves match, |
| 43 // the pixels should be unchanged. | 43 // the pixels should be unchanged. |
| 44 for (int i = 0; i < width; i++) { | 44 for (int i = 0; i < width; i++) { |
| 45 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF), | 45 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF), |
| 46 SkGetPackedR32(dstPixels[i]))); | 46 ((dstPixels[i] >> 0) & 0xFF))); |
| 47 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF), | 47 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF), |
| 48 SkGetPackedG32(dstPixels[i]))); | 48 ((dstPixels[i] >> 8) & 0xFF))); |
| 49 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF), | 49 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF), |
| 50 SkGetPackedB32(dstPixels[i]))); | 50 ((dstPixels[i] >> 16) & 0xFF))); |
| 51 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF), | 51 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF), |
| 52 SkGetPackedA32(dstPixels[i]))); | 52 ((dstPixels[i] >> 24) & 0xFF))); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 DEF_TEST(ColorSpaceXform_TableGamma, r) { | 56 DEF_TEST(ColorSpaceXform_TableGamma, r) { |
| 57 // Lookup-table based gamma curves | 57 // Lookup-table based gamma curves |
| 58 constexpr size_t tableSize = 10; | 58 constexpr size_t tableSize = 10; |
| 59 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize)
; | 59 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize)
; |
| 60 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas()); | 60 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas()); |
| 61 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type::
kTable_Type; | 61 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type::
kTable_Type; |
| 62 gammas->fRedData.fTable.fSize = gammas->fGreenData.fTable.fSize = | 62 gammas->fRedData.fTable.fSize = gammas->fGreenData.fTable.fSize = |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 gammas->fGreenType = SkGammas::Type::kTable_Type; | 145 gammas->fGreenType = SkGammas::Type::kTable_Type; |
| 146 gammas->fGreenData.fTable.fSize = tableSize; | 146 gammas->fGreenData.fTable.fSize = tableSize; |
| 147 gammas->fGreenData.fTable.fOffset = 0; | 147 gammas->fGreenData.fTable.fOffset = 0; |
| 148 | 148 |
| 149 gammas->fBlueType = SkGammas::Type::kParam_Type; | 149 gammas->fBlueType = SkGammas::Type::kParam_Type; |
| 150 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize; | 150 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize; |
| 151 | 151 |
| 152 test_identity_xform(r, gammas); | 152 test_identity_xform(r, gammas); |
| 153 } | 153 } |
| OLD | NEW |