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 | 14 |
14 class SkColorSpaceXform : SkNoncopyable { | 15 class SkColorSpaceXform : SkNoncopyable { |
15 public: | 16 public: |
16 | 17 |
17 typedef uint32_t RGBA32; | |
18 typedef uint32_t BGRA32; | |
19 typedef uint64_t RGBAF16; | |
20 | |
21 /** | 18 /** |
22 * Create an object to handle color space conversions. | 19 * Create an object to handle color space conversions. |
23 * | 20 * |
24 * @param srcSpace The encoded color space. | 21 * @param srcSpace The encoded color space. |
25 * @param dstSpace The destination color space. | 22 * @param dstSpace The destination color space. |
26 * | 23 * |
27 */ | 24 */ |
28 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, |
29 const sk_sp<SkColorSpace>& dst
Space); | 26 const sk_sp<SkColorSpace>& dst
Space); |
30 | 27 |
31 /** | 28 /** |
32 * 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 ds
t buffer. |
33 * The src is stored as RGBA (8888) and is treated as opaque. | 30 * The src is stored as RGBA (8888). The dst is stored in the format indic
ated by |
34 * TODO (msarett): Support non-opaque srcs. | 31 * |dstColorType| and is premultiplied by alpha if |premul| is set. |
35 */ | 32 */ |
36 virtual void applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const = 0; | 33 virtual void apply(void* dst, const uint32_t* src, int len, SkColorType dstC
olorType, |
37 virtual void applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const = 0; | 34 SkAlphaType dstAlphaType) const = 0; |
38 virtual void applyToF16(RGBAF16* dst, const RGBA32* src, int len) const = 0; | |
39 | 35 |
40 virtual ~SkColorSpaceXform() {} | 36 virtual ~SkColorSpaceXform() {} |
41 }; | 37 }; |
42 | 38 |
43 template <SkColorSpace::GammaNamed Dst> | 39 template <SkColorSpace::GammaNamed kDst> |
44 class SkColorSpaceXform_Base : public SkColorSpaceXform { | 40 class SkColorSpaceXform_Base : public SkColorSpaceXform { |
45 public: | 41 public: |
46 | 42 |
47 void applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const override; | 43 void apply(void* dst, const uint32_t* src, int len, SkColorType dstColorType
, |
48 void applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const override; | 44 SkAlphaType dstAlphaType) const override; |
49 void applyToF16(RGBAF16* dst, const RGBA32* src, int len) const override; | |
50 | 45 |
51 static constexpr int kDstGammaTableSize = 1024; | 46 static constexpr int kDstGammaTableSize = 1024; |
52 | 47 |
53 private: | 48 private: |
54 SkColorSpaceXform_Base(const sk_sp<SkColorSpace>& srcSpace, const SkMatrix44
& srcToDst, | 49 SkColorSpaceXform_Base(const sk_sp<SkColorSpace>& srcSpace, const SkMatrix44
& srcToDst, |
55 const sk_sp<SkColorSpace>& dstSpace); | 50 const sk_sp<SkColorSpace>& dstSpace); |
56 | 51 |
57 sk_sp<SkColorLookUpTable> fColorLUT; | 52 sk_sp<SkColorLookUpTable> fColorLUT; |
58 | 53 |
59 // May contain pointers into storage or pointers into precomputed tables. | 54 // May contain pointers into storage or pointers into precomputed tables. |
60 const float* fSrcGammaTables[3]; | 55 const float* fSrcGammaTables[3]; |
61 float fSrcGammaTableStorage[3 * 256]; | 56 float fSrcGammaTableStorage[3 * 256]; |
62 | 57 |
63 float fSrcToDst[16]; | 58 float fSrcToDst[16]; |
64 | 59 |
65 // May contain pointers into storage or pointers into precomputed tables. | 60 // May contain pointers into storage or pointers into precomputed tables. |
66 const uint8_t* fDstGammaTables[3]; | 61 const uint8_t* fDstGammaTables[3]; |
67 uint8_t fDstGammaTableStorage[3 * kDstGammaTableSize]; | 62 uint8_t fDstGammaTableStorage[3 * kDstGammaTableSize]; |
68 | 63 |
69 friend class SkColorSpaceXform; | 64 friend class SkColorSpaceXform; |
70 }; | 65 }; |
71 | 66 |
72 #endif | 67 #endif |
OLD | NEW |