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 #ifndef SkColorSpaceXform_Base_DEFINED 9 #define SkColorSpaceXform_Base_DEFINED 10 11 #include "SkColorSpace.h" 12 #include "SkColorSpace_Base.h" 13 #include "SkColorSpaceXform.h" 14 #include "SkResourceCache.h" 15 16 class SkColorSpace_XYZ; 17 18 class SkColorSpaceXform_Base : public SkColorSpaceXform { 19 public: 20 static constexpr int kDstGammaTableSize = 1024; 21 22 static std::unique_ptr<SkColorSpaceXform> New(SkColorSpace* srcSpace, SkColorSpace* dstSpace, 23 SkTransferFunctionBehavior premulBehavior); 24 25 protected: 26 virtual bool onApply(ColorFormat dstFormat, void* dst, ColorFormat srcFormat, const void* src, 27 int count, SkAlphaType alphaType) const = 0; 28 29 private: 30 static void BuildDstGammaTables(const uint8_t* outGammaTables[3], uint8_t* gammaTableStorage, 31 const SkColorSpace_XYZ* space, bool gammasAreMatching); 32 33 friend class SkColorSpaceXform; 34 friend class SkColorSpace_XYZ; 35 }; 36 37 enum SrcGamma { 38 kLinear_SrcGamma, 39 kTable_SrcGamma, 40 kSRGB_SrcGamma, 41 }; 42 43 enum DstGamma { 44 kLinear_DstGamma, 45 kSRGB_DstGamma, 46 k2Dot2_DstGamma, 47 kTable_DstGamma, 48 }; 49 50 enum ColorSpaceMatch { 51 kNone_ColorSpaceMatch, 52 kGamut_ColorSpaceMatch, 53 kFull_ColorSpaceMatch, 54 }; 55 56 template <ColorSpaceMatch kCSM> 57 class SkColorSpaceXform_XYZ : public SkColorSpaceXform_Base { 58 protected: 59 bool onApply(ColorFormat dstFormat, void* dst, ColorFormat srcFormat, const void* src, 60 int count, SkAlphaType alphaType) const override; 61 62 private: 63 bool applyPipeline(ColorFormat dstFormat, void* dst, ColorFormat srcFormat, const void* src, 64 int count, SkAlphaType alphaType) const; 65 66 SkColorSpaceXform_XYZ(SkColorSpace_XYZ* srcSpace, const SkMatrix44& srcToDst, 67 SkColorSpace_XYZ* dstSpace, SkTransferFunctionBehavior premulBehavior); 68 69 // Contain pointers into storage or pointers into precomputed tables. 70 const float* fSrcGammaTables[3]; 71 SkAutoTMalloc<float> fSrcStorage; 72 const uint8_t* fDstGammaTables[3]; 73 sk_sp<SkData> fDstStorage; 74 75 // Holds a 3x4 matrix. Padding is useful for vector loading. 76 float fSrcToDst[13]; 77 78 SrcGamma fSrcGamma; 79 DstGamma fDstGamma; 80 SkTransferFunctionBehavior fPremulBehavior; 81 82 friend class SkColorSpaceXform_Base; 83 friend std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace_XYZ* space); 84 }; 85 86 struct LoadTablesContext { 87 const void* fSrc; 88 const float* fR; 89 const float* fG; 90 const float* fB; 91 }; 92 93 // Must be kept in sync with "Tables" struct in RasterPipeline_opts byte_tables_rgb. 94 struct TablesContext { 95 const uint8_t* fR; 96 const uint8_t* fG; 97 const uint8_t* fB; 98 int fCount; 99 }; 100 101 // For testing. Bypasses opts for when src and dst color spaces are equal. 102 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace_XYZ* space); 103 104 #endif 105