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 |
11 #include "SkColorSpace.h" | 11 #include "SkColorSpace.h" |
12 #include "SkColorSpace_Base.h" | 12 #include "SkColorSpace_Base.h" |
13 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
14 | 14 |
15 class SkColorSpaceXform : SkNoncopyable { | 15 class SkColorSpaceXform : SkNoncopyable { |
16 public: | 16 public: |
17 | 17 |
18 /** | 18 /** |
19 * Create an object to handle color space conversions. | 19 * Create an object to handle color space conversions. |
20 * | 20 * |
21 * @param srcSpace The encoded color space. | 21 * @param srcSpace The encoded color space. |
22 * @param dstSpace The destination color space. | 22 * @param dstSpace The destination color space. |
23 * | 23 * |
24 */ | 24 */ |
25 static std::unique_ptr<SkColorSpaceXform> New(const sk_sp<SkColorSpace>& src
Space, | 25 static std::unique_ptr<SkColorSpaceXform> New(const sk_sp<SkColorSpace>& src
Space, |
26 const sk_sp<SkColorSpace>& dst
Space); | 26 const sk_sp<SkColorSpace>& dst
Space); |
27 | 27 |
| 28 enum ColorFormat : uint8_t { |
| 29 kRGBA_8888_ColorFormat, |
| 30 kBGRA_8888_ColorFormat, |
| 31 kRGBA_F16_ColorFormat, |
| 32 kRGBA_F32_ColorFormat, |
| 33 }; |
| 34 |
28 /** | 35 /** |
29 * Apply the color conversion to a |src| buffer, storing the output in the
|dst| buffer. | 36 * Apply the color conversion to a |src| buffer, storing the output in the
|dst| buffer. |
30 * | 37 * |
31 * @param dst Stored in the format described by |dstColorType| and
|dstAlphaType| | 38 * @param dst Stored in the format described by |dstColorType| a
nd |dstAlphaType| |
32 * @param src Stored as RGBA_8888, kUnpremul (note kOpaque is a fo
rm of kUnpremul) | 39 * @param src Stored as RGBA_8888, kUnpremul (note kOpaque is a
form of kUnpremul) |
33 * @param len Number of pixels in the buffers | 40 * @param len Number of pixels in the buffers |
34 * @param dstColorType Describes color type of |dst| | 41 * @param dstColorFormat Describes color format of |dst| |
35 * @param dstAlphaType Describes alpha type of |dst| | 42 * @param dstAlphaType Describes alpha type of |dst| |
36 * kUnpremul preserves input alpha values | 43 * kUnpremul preserves input alpha values |
37 * kPremul performs a premultiplication and also pres
erves alpha values | 44 * kPremul performs a premultiplication and also pr
eserves alpha values |
38 * kOpaque optimization hint, |dst| alphas set to 1 | 45 * kOpaque optimization hint, |dst| alphas set to 1 |
39 * | 46 * |
40 */ | 47 */ |
41 virtual void apply(void* dst, const uint32_t* src, int len, SkColorType dstC
olorType, | 48 virtual void apply(void* dst, const uint32_t* src, int len, ColorFormat dstC
olorFormat, |
42 SkAlphaType dstAlphaType) const = 0; | 49 SkAlphaType dstAlphaType) const = 0; |
43 | 50 |
44 virtual ~SkColorSpaceXform() {} | 51 virtual ~SkColorSpaceXform() {} |
45 }; | 52 }; |
46 | 53 |
47 enum SrcGamma { | 54 enum SrcGamma { |
48 kLinear_SrcGamma, | 55 kLinear_SrcGamma, |
49 kTable_SrcGamma, | 56 kTable_SrcGamma, |
50 }; | 57 }; |
51 | 58 |
52 enum DstGamma { | 59 enum DstGamma { |
53 kLinear_DstGamma, | 60 kLinear_DstGamma, |
54 kSRGB_DstGamma, | 61 kSRGB_DstGamma, |
55 k2Dot2_DstGamma, | 62 k2Dot2_DstGamma, |
56 kTable_DstGamma, | 63 kTable_DstGamma, |
57 }; | 64 }; |
58 | 65 |
59 enum ColorSpaceMatch { | 66 enum ColorSpaceMatch { |
60 kNone_ColorSpaceMatch, | 67 kNone_ColorSpaceMatch, |
61 kGamut_ColorSpaceMatch, | 68 kGamut_ColorSpaceMatch, |
62 kFull_ColorSpaceMatch, | 69 kFull_ColorSpaceMatch, |
63 }; | 70 }; |
64 | 71 |
65 template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM> | 72 template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM> |
66 class SkColorSpaceXform_Base : public SkColorSpaceXform { | 73 class SkColorSpaceXform_Base : public SkColorSpaceXform { |
67 public: | 74 public: |
68 | 75 |
69 void apply(void* dst, const uint32_t* src, int len, SkColorType dstColorType
, | 76 void apply(void* dst, const uint32_t* src, int len, ColorFormat dstColorForm
at, |
70 SkAlphaType dstAlphaType) const override; | 77 SkAlphaType dstAlphaType) const override; |
71 | 78 |
72 static constexpr int kDstGammaTableSize = 1024; | 79 static constexpr int kDstGammaTableSize = 1024; |
73 | 80 |
74 private: | 81 private: |
75 SkColorSpaceXform_Base(const sk_sp<SkColorSpace>& srcSpace, const SkMatrix44
& srcToDst, | 82 SkColorSpaceXform_Base(const sk_sp<SkColorSpace>& srcSpace, const SkMatrix44
& srcToDst, |
76 const sk_sp<SkColorSpace>& dstSpace); | 83 const sk_sp<SkColorSpace>& dstSpace); |
77 | 84 |
78 sk_sp<SkColorLookUpTable> fColorLUT; | 85 sk_sp<SkColorLookUpTable> fColorLUT; |
79 | 86 |
80 // Contain pointers into storage or pointers into precomputed tables. | 87 // Contain pointers into storage or pointers into precomputed tables. |
81 const float* fSrcGammaTables[3]; | 88 const float* fSrcGammaTables[3]; |
82 const uint8_t* fDstGammaTables[3]; | 89 const uint8_t* fDstGammaTables[3]; |
83 SkAutoMalloc fStorage; | 90 SkAutoMalloc fStorage; |
84 | 91 |
85 float fSrcToDst[16]; | 92 float fSrcToDst[16]; |
86 | 93 |
87 friend class SkColorSpaceXform; | 94 friend class SkColorSpaceXform; |
88 friend std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkCo
lorSpace>& space); | 95 friend std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkCo
lorSpace>& space); |
89 }; | 96 }; |
90 | 97 |
91 // For testing. Bypasses opts for when src and dst color spaces are equal. | 98 // For testing. Bypasses opts for when src and dst color spaces are equal. |
92 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>&
space); | 99 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>&
space); |
93 | 100 |
94 #endif | 101 #endif |
OLD | NEW |