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" | |
12 #include "SkColorSpace_Base.h" | |
13 #include "SkImageInfo.h" | 11 #include "SkImageInfo.h" |
14 | 12 |
13 class SkColorSpace; | |
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(SkColorSpace* srcSpace, SkColo rSpace* dstSpace); | 25 static std::unique_ptr<SkColorSpaceXform> New(SkColorSpace* srcSpace, SkColo rSpace* dstSpace); |
reed1
2016/10/04 14:54:43
Do you copy or ref or neither these two pointers (
msarett
2016/10/04 23:21:58
Neither. I actually used to make this take sk_sps
| |
26 | 26 |
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 * F16 and F32 are only supported as dst color formats, and only when the d st color space | |
38 * is linear. This function will assert on invalid or unsupported uses. | |
39 * | |
37 * @param dst Stored in the format described by |dstColorFormat| | 40 * @param dst Stored in the format described by |dstColorFormat| |
38 * @param src Stored in the format described by |srcColorFormat| | 41 * @param src Stored in the format described by |srcColorFormat| |
39 * @param len Number of pixels in the buffers | 42 * @param len Number of pixels in the buffers |
40 * @param dstColorFormat Describes color format of |dst| | 43 * @param dstColorFormat Describes color format of |dst| |
41 * @param srcColorFormat Describes color format of |src| | 44 * @param srcColorFormat Describes color format of |src| |
42 * Must be kRGBA_8888 or kBGRA_8888 | 45 * Must be kRGBA_8888 or kBGRA_8888 |
43 * @param alphaType Describes alpha properties of the |dst| (and |src| ) | 46 * @param alphaType Describes alpha properties of the |dst| (and |src| ) |
44 * kUnpremul preserves input alpha values | 47 * kUnpremul preserves input alpha values |
45 * kPremul performs a premultiplication and also pr eserves alpha values | 48 * kPremul performs a premultiplication and also pr eserves alpha values |
46 * kOpaque optimization hint, |dst| alphas set to 1 | 49 * kOpaque optimization hint, |dst| alphas set to 1 |
47 * | 50 * |
48 */ | 51 */ |
reed1
2016/10/04 14:54:43
consider making apply non-virtual, and just dispat
msarett
2016/10/04 23:21:58
Done.
| |
49 virtual void apply(void* dst, const uint32_t* src, int len, ColorFormat dstC olorFormat, | 52 virtual void apply(void* dst, const uint32_t* src, int len, ColorFormat dstC olorFormat, |
reed1
2016/10/04 14:54:43
why is src uint32* and dst void* if both have a fo
reed1
2016/10/04 14:54:43
nit: more common is use "count" when counting logi
msarett
2016/10/04 23:21:58
I think it is cleaner to make both void*. I'm cha
msarett
2016/10/04 23:21:58
Done.
| |
50 ColorFormat srcColorFormat, SkAlphaType alphaType) const = 0; | 53 ColorFormat srcColorFormat, SkAlphaType alphaType) const = 0; |
reed1
2016/10/04 14:54:43
Its tricky to see how the params group... what abo
msarett
2016/10/04 23:21:58
Done.
| |
51 | 54 |
52 virtual ~SkColorSpaceXform() {} | 55 virtual ~SkColorSpaceXform() {} |
53 }; | 56 }; |
54 | 57 |
55 enum SrcGamma { | |
56 kLinear_SrcGamma, | |
57 kTable_SrcGamma, | |
58 }; | |
59 | |
60 enum DstGamma { | |
61 kLinear_DstGamma, | |
62 kSRGB_DstGamma, | |
63 k2Dot2_DstGamma, | |
64 kTable_DstGamma, | |
65 }; | |
66 | |
67 enum ColorSpaceMatch { | |
68 kNone_ColorSpaceMatch, | |
69 kGamut_ColorSpaceMatch, | |
70 kFull_ColorSpaceMatch, | |
71 }; | |
72 | |
73 template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM> | |
74 class SkColorSpaceXform_Base : public SkColorSpaceXform { | |
75 public: | |
76 | |
77 void apply(void* dst, const uint32_t* src, int len, ColorFormat dstColorForm at, | |
78 ColorFormat srcColorFormat, SkAlphaType alphaType) const override ; | |
79 | |
80 static constexpr int kDstGammaTableSize = 1024; | |
81 | |
82 private: | |
83 SkColorSpaceXform_Base(SkColorSpace* srcSpace, const SkMatrix44& srcToDst, | |
84 SkColorSpace* dstSpace); | |
85 | |
86 sk_sp<SkColorLookUpTable> fColorLUT; | |
87 | |
88 // Contain pointers into storage or pointers into precomputed tables. | |
89 const float* fSrcGammaTables[3]; | |
90 const uint8_t* fDstGammaTables[3]; | |
91 SkAutoMalloc fStorage; | |
92 | |
93 float fSrcToDst[16]; | |
94 | |
95 friend class SkColorSpaceXform; | |
96 friend std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace* sp ace); | |
97 }; | |
98 | |
99 // For testing. Bypasses opts for when src and dst color spaces are equal. | |
100 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace* space); | |
101 | |
102 #endif | 58 #endif |
OLD | NEW |