| 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 "SkColorSpace_XYZTRC.h" | 
|   14 #include "SkColorSpaceXform_Base.h" |   15 #include "SkColorSpaceXform_Base.h" | 
|   15 #include "Test.h" |   16 #include "Test.h" | 
|   16  |   17  | 
|   17 class ColorSpaceXformTest { |   18 class ColorSpaceXformTest { | 
|   18 public: |   19 public: | 
|   19     static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<Sk
     Gammas>& gammas) { |   20     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. |   21         // Logically we can pass any matrix here.  For simplicty, pass I(), i.e.
      D50 XYZ gamut. | 
|   21         sk_sp<SkColorSpace> space(new SkColorSpace_Base( |   22         sk_sp<SkColorSpace> space(new SkColorSpace_XYZTRC( | 
|   22                 nullptr, kNonStandard_SkGammaNamed, gammas, SkMatrix::I(), nullp
     tr)); |   23                 kNonStandard_SkGammaNamed, gammas, SkMatrix::I(), nullptr)); | 
|   23  |   24  | 
|   24         // Use special testing entry point, so we don't skip the xform, even tho
     ugh src == dst. |   25         // Use special testing entry point, so we don't skip the xform, even tho
     ugh src == dst. | 
|   25         return SlowIdentityXform(space.get()); |   26         return SlowIdentityXform(static_cast<SkColorSpace_XYZTRC*>(space.get()))
     ; | 
|   26     } |   27     } | 
|   27 }; |   28 }; | 
|   28  |   29  | 
|   29 static bool almost_equal(int x, int y) { |   30 static bool almost_equal(int x, int y) { | 
|   30     return SkTAbs(x - y) <= 1; |   31     return SkTAbs(x - y) <= 1; | 
|   31 } |   32 } | 
|   32  |   33  | 
|   33 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga
     mmas) { |   34 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga
     mmas) { | 
|   34     // Arbitrary set of 10 pixels |   35     // Arbitrary set of 10 pixels | 
|   35     constexpr int width = 10; |   36     constexpr int width = 10; | 
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  161     gammas->fGreenType = SkGammas::Type::kTable_Type; |  162     gammas->fGreenType = SkGammas::Type::kTable_Type; | 
|  162     gammas->fGreenData.fTable.fSize = tableSize; |  163     gammas->fGreenData.fTable.fSize = tableSize; | 
|  163     gammas->fGreenData.fTable.fOffset = 0; |  164     gammas->fGreenData.fTable.fOffset = 0; | 
|  164  |  165  | 
|  165     gammas->fBlueType = SkGammas::Type::kParam_Type; |  166     gammas->fBlueType = SkGammas::Type::kParam_Type; | 
|  166     gammas->fBlueData.fParamOffset = sizeof(float) * tableSize; |  167     gammas->fBlueData.fParamOffset = sizeof(float) * tableSize; | 
|  167  |  168  | 
|  168     test_identity_xform(r, gammas); |  169     test_identity_xform(r, gammas); | 
|  169 } |  170 } | 
|  170  |  171  | 
|  171 DEF_TEST(ColorSpaceXform_applyCLUTMemoryAccess, r) { |  | 
|  172     // buffers larger than 1024 (or 256 in GOOGLE3) will force ColorSpaceXform_B
     ase::apply() |  | 
|  173     // to heap-allocate a buffer that is used for CLUT application, and this tes
     t is here to |  | 
|  174     // ensure that it no longer causes potential invalid memory accesses when th
     is happens |  | 
|  175     const size_t len = 2048; |  | 
|  176     SkAutoTMalloc<uint32_t> src(len); |  | 
|  177     SkAutoTMalloc<uint32_t> dst(len); |  | 
|  178     for (uint32_t i = 0; i < len; ++i) { |  | 
|  179         src[i] = i; |  | 
|  180     } |  | 
|  181     // this ICC profile has a CLUT in it |  | 
|  182     const SkString filename(GetResourcePath("icc_profiles/upperRight.icc")); |  | 
|  183     sk_sp<SkData> iccData = SkData::MakeFromFileName(filename.c_str()); |  | 
|  184     REPORTER_ASSERT_MESSAGE(r, iccData, "upperRight.icc profile required for tes
     t"); |  | 
|  185     sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(iccData->bytes(), iccDat
     a->size()); |  | 
|  186     sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Na
     med); |  | 
|  187     auto xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get()); |  | 
|  188     bool result = xform->apply(SkColorSpaceXform::kRGBA_8888_ColorFormat, dst.ge
     t(), |  | 
|  189                                SkColorSpaceXform::kRGBA_8888_ColorFormat, src.ge
     t(), len, |  | 
|  190                                kUnpremul_SkAlphaType); |  | 
|  191     REPORTER_ASSERT(r, result); |  | 
|  192 } |  | 
| OLD | NEW |