| 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 #ifndef SkColorSpaceXform_DEFINED | 8 #ifndef SkColorSpaceXform_DEFINED |
| 9 #define SkColorSpaceXform_DEFINED | 9 #define SkColorSpaceXform_DEFINED |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 enum ColorFormat : uint8_t { | 27 enum ColorFormat : uint8_t { |
| 28 kRGBA_8888_ColorFormat, | 28 kRGBA_8888_ColorFormat, |
| 29 kBGRA_8888_ColorFormat, | 29 kBGRA_8888_ColorFormat, |
| 30 kRGBA_F16_ColorFormat, | 30 kRGBA_F16_ColorFormat, |
| 31 kRGBA_F32_ColorFormat, | 31 kRGBA_F32_ColorFormat, |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Apply the color conversion to a |src| buffer, storing the output in the
|dst| buffer. | 35 * Apply the color conversion to a |src| buffer, storing the output in the
|dst| buffer. |
| 36 * | 36 * |
| 37 * @param dst Stored in the format described by |dstColorType| a
nd |dstAlphaType| | 37 * @param dst Stored in the format described by |dstColorFormat| |
| 38 * @param src Stored as RGBA_8888, kUnpremul (note kOpaque is a
form of kUnpremul) | 38 * @param src Stored in the format described by |srcColorFormat| |
| 39 * @param len Number of pixels in the buffers | 39 * @param len Number of pixels in the buffers |
| 40 * @param dstColorFormat Describes color format of |dst| | 40 * @param dstColorFormat Describes color format of |dst| |
| 41 * @param dstAlphaType Describes alpha type of |dst| | 41 * @param srcColorFormat Describes color format of |src| |
| 42 * Must be kRGBA_8888 or kBGRA_8888 |
| 43 * @param alphaType Describes alpha properties of the |dst| (and |src|
) |
| 42 * kUnpremul preserves input alpha values | 44 * kUnpremul preserves input alpha values |
| 43 * kPremul performs a premultiplication and also pr
eserves alpha values | 45 * kPremul performs a premultiplication and also pr
eserves alpha values |
| 44 * kOpaque optimization hint, |dst| alphas set to 1 | 46 * kOpaque optimization hint, |dst| alphas set to 1 |
| 45 * | 47 * |
| 46 */ | 48 */ |
| 47 virtual void apply(void* dst, const uint32_t* src, int len, ColorFormat dstC
olorFormat, | 49 virtual void apply(void* dst, const uint32_t* src, int len, ColorFormat dstC
olorFormat, |
| 48 SkAlphaType dstAlphaType) const = 0; | 50 ColorFormat srcColorFormat, SkAlphaType alphaType) const
= 0; |
| 49 | 51 |
| 50 virtual ~SkColorSpaceXform() {} | 52 virtual ~SkColorSpaceXform() {} |
| 51 }; | 53 }; |
| 52 | 54 |
| 53 enum SrcGamma { | 55 enum SrcGamma { |
| 54 kLinear_SrcGamma, | 56 kLinear_SrcGamma, |
| 55 kTable_SrcGamma, | 57 kTable_SrcGamma, |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 enum DstGamma { | 60 enum DstGamma { |
| 59 kLinear_DstGamma, | 61 kLinear_DstGamma, |
| 60 kSRGB_DstGamma, | 62 kSRGB_DstGamma, |
| 61 k2Dot2_DstGamma, | 63 k2Dot2_DstGamma, |
| 62 kTable_DstGamma, | 64 kTable_DstGamma, |
| 63 }; | 65 }; |
| 64 | 66 |
| 65 enum ColorSpaceMatch { | 67 enum ColorSpaceMatch { |
| 66 kNone_ColorSpaceMatch, | 68 kNone_ColorSpaceMatch, |
| 67 kGamut_ColorSpaceMatch, | 69 kGamut_ColorSpaceMatch, |
| 68 kFull_ColorSpaceMatch, | 70 kFull_ColorSpaceMatch, |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM> | 73 template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM> |
| 72 class SkColorSpaceXform_Base : public SkColorSpaceXform { | 74 class SkColorSpaceXform_Base : public SkColorSpaceXform { |
| 73 public: | 75 public: |
| 74 | 76 |
| 75 void apply(void* dst, const uint32_t* src, int len, ColorFormat dstColorForm
at, | 77 void apply(void* dst, const uint32_t* src, int len, ColorFormat dstColorForm
at, |
| 76 SkAlphaType dstAlphaType) const override; | 78 ColorFormat srcColorFormat, SkAlphaType alphaType) const override
; |
| 77 | 79 |
| 78 static constexpr int kDstGammaTableSize = 1024; | 80 static constexpr int kDstGammaTableSize = 1024; |
| 79 | 81 |
| 80 private: | 82 private: |
| 81 SkColorSpaceXform_Base(SkColorSpace* srcSpace, const SkMatrix44& srcToDst, | 83 SkColorSpaceXform_Base(SkColorSpace* srcSpace, const SkMatrix44& srcToDst, |
| 82 SkColorSpace* dstSpace); | 84 SkColorSpace* dstSpace); |
| 83 | 85 |
| 84 sk_sp<SkColorLookUpTable> fColorLUT; | 86 sk_sp<SkColorLookUpTable> fColorLUT; |
| 85 | 87 |
| 86 // Contain pointers into storage or pointers into precomputed tables. | 88 // Contain pointers into storage or pointers into precomputed tables. |
| 87 const float* fSrcGammaTables[3]; | 89 const float* fSrcGammaTables[3]; |
| 88 const uint8_t* fDstGammaTables[3]; | 90 const uint8_t* fDstGammaTables[3]; |
| 89 SkAutoMalloc fStorage; | 91 SkAutoMalloc fStorage; |
| 90 | 92 |
| 91 float fSrcToDst[16]; | 93 float fSrcToDst[16]; |
| 92 | 94 |
| 93 friend class SkColorSpaceXform; | 95 friend class SkColorSpaceXform; |
| 94 friend std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace* sp
ace); | 96 friend std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace* sp
ace); |
| 95 }; | 97 }; |
| 96 | 98 |
| 97 // For testing. Bypasses opts for when src and dst color spaces are equal. | 99 // For testing. Bypasses opts for when src and dst color spaces are equal. |
| 98 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace* space); | 100 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace* space); |
| 99 | 101 |
| 100 #endif | 102 #endif |
| OLD | NEW |