| 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 "SkCodecPriv.h" | 10 #include "SkCodecPriv.h" |
| 11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 12 #include "SkColorSpace.h" | 12 #include "SkColorSpace.h" |
| 13 #include "SkColorSpace_Base.h" | 13 #include "SkColorSpace_Base.h" |
| 14 #include "SkColorSpaceXform.h" | 14 #include "SkColorSpaceXform_Base.h" |
| 15 #include "Test.h" | 15 #include "Test.h" |
| 16 | 16 |
| 17 class ColorSpaceXformTest { | 17 class ColorSpaceXformTest { |
| 18 public: | 18 public: |
| 19 static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<Sk
Gammas>& gammas) { | 19 static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<Sk
Gammas>& gammas) { |
| 20 // Logically we can pass any matrix here. For simplicty, pass I(), i.e.
D50 XYZ gamut. | 20 // Logically we can pass any matrix here. For simplicty, pass I(), i.e.
D50 XYZ gamut. |
| 21 sk_sp<SkColorSpace> space(new SkColorSpace_Base( | 21 sk_sp<SkColorSpace> space(new SkColorSpace_Base( |
| 22 nullptr, kNonStandard_SkGammaNamed, gammas, SkMatrix::I(), nullp
tr)); | 22 nullptr, kNonStandard_SkGammaNamed, gammas, SkMatrix::I(), nullp
tr)); |
| 23 | 23 |
| 24 // Use special testing entry point, so we don't skip the xform, even tho
ugh src == dst. | 24 // Use special testing entry point, so we don't skip the xform, even tho
ugh src == dst. |
| 25 return SlowIdentityXform(space.get()); | 25 return SlowIdentityXform(space.get()); |
| 26 } | 26 } |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 static bool almost_equal(int x, int y) { | 29 static bool almost_equal(int x, int y) { |
| 30 return SkTAbs(x - y) <= 1; | 30 return SkTAbs(x - y) <= 1; |
| 31 } | 31 } |
| 32 | 32 |
| 33 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga
mmas) { | 33 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga
mmas) { |
| 34 // Arbitrary set of 10 pixels | 34 // Arbitrary set of 10 pixels |
| 35 constexpr int width = 10; | 35 constexpr int width = 10; |
| 36 constexpr uint32_t srcPixels[width] = { | 36 constexpr uint32_t srcPixels[width] = { |
| 37 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271, | 37 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271, |
| 38 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, }; | 38 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, }; |
| 39 uint32_t dstPixels[width]; | 39 uint32_t dstPixels[width]; |
| 40 | 40 |
| 41 // Create and perform an identity xform. | 41 // Create and perform an identity xform. |
| 42 std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdenti
tyXform(gammas); | 42 std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdenti
tyXform(gammas); |
| 43 xform->apply(dstPixels, srcPixels, width, select_xform_format(kN32_SkColorTy
pe), | 43 bool result = xform->apply(select_xform_format(kN32_SkColorType), dstPixels, |
| 44 SkColorSpaceXform::kBGRA_8888_ColorFormat, kOpaque_SkAlphaType)
; | 44 SkColorSpaceXform::kBGRA_8888_ColorFormat, srcPix
els, width, |
| 45 kOpaque_SkAlphaType); |
| 46 REPORTER_ASSERT(r, result); |
| 45 | 47 |
| 46 // Since the src->dst matrix is the identity, and the gamma curves match, | 48 // Since the src->dst matrix is the identity, and the gamma curves match, |
| 47 // the pixels should be unchanged. | 49 // the pixels should be unchanged. |
| 48 for (int i = 0; i < width; i++) { | 50 for (int i = 0; i < width; i++) { |
| 49 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF), | 51 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF), |
| 50 SkGetPackedB32(dstPixels[i]))); | 52 SkGetPackedB32(dstPixels[i]))); |
| 51 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF), | 53 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF), |
| 52 SkGetPackedG32(dstPixels[i]))); | 54 SkGetPackedG32(dstPixels[i]))); |
| 53 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF), | 55 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF), |
| 54 SkGetPackedR32(dstPixels[i]))); | 56 SkGetPackedR32(dstPixels[i]))); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 for (uint32_t i = 0; i < len; ++i) { | 177 for (uint32_t i = 0; i < len; ++i) { |
| 176 src[i] = i; | 178 src[i] = i; |
| 177 } | 179 } |
| 178 // this ICC profile has a CLUT in it | 180 // this ICC profile has a CLUT in it |
| 179 const SkString filename(GetResourcePath("icc_profiles/upperRight.icc")); | 181 const SkString filename(GetResourcePath("icc_profiles/upperRight.icc")); |
| 180 sk_sp<SkData> iccData = SkData::MakeFromFileName(filename.c_str()); | 182 sk_sp<SkData> iccData = SkData::MakeFromFileName(filename.c_str()); |
| 181 REPORTER_ASSERT_MESSAGE(r, iccData, "upperRight.icc profile required for tes
t"); | 183 REPORTER_ASSERT_MESSAGE(r, iccData, "upperRight.icc profile required for tes
t"); |
| 182 sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(iccData->bytes(), iccDat
a->size()); | 184 sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(iccData->bytes(), iccDat
a->size()); |
| 183 sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Na
med); | 185 sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Na
med); |
| 184 auto xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get()); | 186 auto xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get()); |
| 185 xform->apply(dst.get(), src.get(), len, SkColorSpaceXform::kRGBA_8888_ColorF
ormat, | 187 bool result = xform->apply(SkColorSpaceXform::kRGBA_8888_ColorFormat, dst.ge
t(), |
| 186 SkColorSpaceXform::kRGBA_8888_ColorFormat, kUnpremul_SkAlphaTyp
e); | 188 SkColorSpaceXform::kRGBA_8888_ColorFormat, src.ge
t(), len, |
| 189 kUnpremul_SkAlphaType); |
| 190 REPORTER_ASSERT(r, result); |
| 187 } | 191 } |
| OLD | NEW |