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 /** | 28 /** |
29 * Apply the color conversion to a src buffer, storing the output in the ds
t buffer. | 29 * Apply the color conversion to a |src| buffer, storing the output in the
|dst| buffer. |
30 * The src is stored as RGBA (8888). The dst is stored in the format indic
ated by | 30 * |
31 * |dstColorType| and is premultiplied by alpha if |premul| is set. | 31 * @param dst Stored in the format described by |dstColorType| and
|dstAlphaType| |
| 32 * @param src Stored as RGBA_8888, kUnpremul (note kOpaque is a fo
rm of kUnpremul) |
| 33 * @param len Number of pixels in the buffers |
| 34 * @param dstColorType Describes color type of |dst| |
| 35 * @param dstAlphaType Describes alpha type of |dst| |
| 36 * kUnpremul preserves input alpha values |
| 37 * kPremul performs a premultiplication and also pres
erves alpha values |
| 38 * kOpaque optimization hint, |dst| alphas set to 1 |
| 39 * |
32 */ | 40 */ |
33 virtual void apply(void* dst, const uint32_t* src, int len, SkColorType dstC
olorType, | 41 virtual void apply(void* dst, const uint32_t* src, int len, SkColorType dstC
olorType, |
34 SkAlphaType dstAlphaType) const = 0; | 42 SkAlphaType dstAlphaType) const = 0; |
35 | 43 |
36 virtual ~SkColorSpaceXform() {} | 44 virtual ~SkColorSpaceXform() {} |
37 }; | 45 }; |
38 | 46 |
| 47 enum SrcGamma { |
| 48 kLinear_SrcGamma, |
| 49 kTable_SrcGamma, |
| 50 }; |
| 51 |
| 52 enum DstGamma { |
| 53 kLinear_DstGamma, |
| 54 kSRGB_DstGamma, |
| 55 k2Dot2_DstGamma, |
| 56 kTable_DstGamma, |
| 57 }; |
| 58 |
39 enum ColorSpaceMatch { | 59 enum ColorSpaceMatch { |
40 kNone_ColorSpaceMatch, | 60 kNone_ColorSpaceMatch, |
41 kGamut_ColorSpaceMatch, | 61 kGamut_ColorSpaceMatch, |
42 kFull_ColorSpaceMatch, | 62 kFull_ColorSpaceMatch, |
43 }; | 63 }; |
44 | 64 |
45 template <SkGammaNamed kDst, ColorSpaceMatch kCSM> | 65 template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM> |
46 class SkColorSpaceXform_Base : public SkColorSpaceXform { | 66 class SkColorSpaceXform_Base : public SkColorSpaceXform { |
47 public: | 67 public: |
48 | 68 |
49 void apply(void* dst, const uint32_t* src, int len, SkColorType dstColorType
, | 69 void apply(void* dst, const uint32_t* src, int len, SkColorType dstColorType
, |
50 SkAlphaType dstAlphaType) const override; | 70 SkAlphaType dstAlphaType) const override; |
51 | 71 |
52 static constexpr int kDstGammaTableSize = 1024; | 72 static constexpr int kDstGammaTableSize = 1024; |
53 | 73 |
54 private: | 74 private: |
55 SkColorSpaceXform_Base(const sk_sp<SkColorSpace>& srcSpace, const SkMatrix44
& srcToDst, | 75 SkColorSpaceXform_Base(const sk_sp<SkColorSpace>& srcSpace, const SkMatrix44
& srcToDst, |
(...skipping 12 matching lines...) Expand all Loading... |
68 uint8_t fDstGammaTableStorage[3 * kDstGammaTableSize]; | 88 uint8_t fDstGammaTableStorage[3 * kDstGammaTableSize]; |
69 | 89 |
70 friend class SkColorSpaceXform; | 90 friend class SkColorSpaceXform; |
71 friend std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkCo
lorSpace>& space); | 91 friend std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkCo
lorSpace>& space); |
72 }; | 92 }; |
73 | 93 |
74 // For testing. Bypasses opts for when src and dst color spaces are equal. | 94 // For testing. Bypasses opts for when src and dst color spaces are equal. |
75 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>&
space); | 95 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>&
space); |
76 | 96 |
77 #endif | 97 #endif |
OLD | NEW |