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 SkColorSpace_DEFINED | 8 #ifndef SkColorSpace_DEFINED |
9 #define SkColorSpace_DEFINED | 9 #define SkColorSpace_DEFINED |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 void dump() const; | 29 void dump() const; |
30 }; | 30 }; |
31 | 31 |
32 struct SkFloat3x3 { | 32 struct SkFloat3x3 { |
33 float fMat[9]; | 33 float fMat[9]; |
34 | 34 |
35 void dump() const; | 35 void dump() const; |
36 }; | 36 }; |
37 | 37 |
| 38 struct SkGamma { |
| 39 static const uint32_t kGammaUseValueFlag = 0x1; |
| 40 static const uint32_t kGammaUseTableFlag = 0x2; |
| 41 static const uint32_t kGammaUseParametricFlag = 0x4; |
| 42 |
| 43 bool isValue() const { return kGammaUseValueFlag & fFlag; } |
| 44 bool isTable() const { return kGammaUseTableFlag & fFlag; } |
| 45 bool isParametric() const { return kGammaUseParametricFlag & fFlag; } |
| 46 |
| 47 uint32_t fFlag; |
| 48 |
| 49 // Values |
| 50 float fValue; |
| 51 |
| 52 // Table |
| 53 uint32_t fTableSize; |
| 54 std::unique_ptr<float[]> fTable; |
| 55 |
| 56 // Parametric |
| 57 // FIXME (msarett): Handle parametric curves. |
| 58 |
| 59 SkGamma() { |
| 60 memset(this, 0, sizeof(struct SkGamma)); |
| 61 } |
| 62 |
| 63 static SkGamma sRGB() { |
| 64 SkGamma gamma; |
| 65 gamma.fFlag = kGammaUseValueFlag; |
| 66 gamma.fValue = 2.2f; |
| 67 return std::move(gamma); |
| 68 } |
| 69 }; |
| 70 |
| 71 struct SkGammas { |
| 72 SkGamma fGammas[3]; |
| 73 |
| 74 static SkGammas sRGB() { |
| 75 SkGammas gammas; |
| 76 gammas.fGammas[0] = std::move(SkGamma::sRGB()); |
| 77 gammas.fGammas[1] = std::move(SkGamma::sRGB()); |
| 78 gammas.fGammas[2] = std::move(SkGamma::sRGB()); |
| 79 return std::move(gammas); |
| 80 } |
| 81 }; |
| 82 |
38 struct SkColorLookUpTable { | 83 struct SkColorLookUpTable { |
39 static const uint8_t kMaxChannels = 16; | 84 static const uint8_t kMaxChannels = 16; |
40 | 85 |
41 uint8_t fInputChannels; | 86 uint8_t fInputChannels; |
42 uint8_t fOutputChannels; | 87 uint8_t fOutputChannels; |
43 uint8_t fGridPoints[kMaxChannels]; | 88 uint8_t fGridPoints[kMaxChannels]; |
44 std::unique_ptr<float[]> fTable; | 89 std::unique_ptr<float[]> fTable; |
45 | 90 |
46 SkColorLookUpTable() { | 91 SkColorLookUpTable() { |
47 memset(this, 0, sizeof(struct SkColorLookUpTable)); | 92 memset(this, 0, sizeof(struct SkColorLookUpTable)); |
48 } | 93 } |
49 }; | 94 }; |
50 | 95 |
51 struct SkPM4f; | 96 struct SkPM4f; |
52 void SkApply3x3ToPM4f(const SkFloat3x3&, const SkPM4f src[], SkPM4f dst[], int c
ount); | 97 void SkApply3x3ToPM4f(const SkFloat3x3&, const SkPM4f src[], SkPM4f dst[], int c
ount); |
53 | 98 |
54 class SkColorSpace : public SkRefCnt { | 99 class SkColorSpace : public SkRefCnt { |
55 public: | 100 public: |
56 enum Named { | 101 enum Named { |
57 kUnknown_Named, | 102 kUnknown_Named, |
58 kDevice_Named, | 103 kDevice_Named, |
59 kSRGB_Named, | 104 kSRGB_Named, |
60 }; | 105 }; |
61 | 106 |
62 /** | 107 /** |
63 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D
50_XYZ | 108 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D
50_XYZ |
64 * and the src-gamma, return a ColorSpace | 109 * and the src-gamma, return a ColorSpace |
65 */ | 110 */ |
66 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, const SkFloat3
& gamma); | 111 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, SkGammas gamma
s); |
67 | 112 |
68 static sk_sp<SkColorSpace> NewNamed(Named); | 113 static sk_sp<SkColorSpace> NewNamed(Named); |
69 static sk_sp<SkColorSpace> NewICC(const void*, size_t); | 114 static sk_sp<SkColorSpace> NewICC(const void*, size_t); |
70 | 115 |
71 SkFloat3 gamma() const { return fGamma; } | 116 const SkGammas& gammas() const { return fGammas; } |
72 SkFloat3x3 xyz() const { return fToXYZD50; } | 117 SkFloat3x3 xyz() const { return fToXYZD50; } |
73 Named named() const { return fNamed; } | 118 Named named() const { return fNamed; } |
74 uint32_t uniqueID() const { return fUniqueID; } | 119 uint32_t uniqueID() const { return fUniqueID; } |
75 | 120 |
76 enum Result { | 121 enum Result { |
77 kFailure_Result, | 122 kFailure_Result, |
78 kIdentity_Result, | 123 kIdentity_Result, |
79 kNormal_Result, | 124 kNormal_Result, |
80 }; | 125 }; |
81 | 126 |
82 /** | 127 /** |
83 * Given a src and dst colorspace, return the 3x3 matrix that will convert
src_linear_RGB | 128 * Given a src and dst colorspace, return the 3x3 matrix that will convert
src_linear_RGB |
84 * values into dst_linear_RGB values. | 129 * values into dst_linear_RGB values. |
85 */ | 130 */ |
86 static Result Concat(const SkColorSpace* src, const SkColorSpace* dst, SkFlo
at3x3* result); | 131 static Result Concat(const SkColorSpace* src, const SkColorSpace* dst, SkFlo
at3x3* result); |
87 | 132 |
88 static void Test(); | 133 static void Test(); |
89 void dump() const; | 134 void dump() const; |
90 | 135 |
91 private: | 136 private: |
92 SkColorSpace(const SkFloat3& gamma, const SkFloat3x3& toXYZ, Named); | 137 SkColorSpace(SkGammas gammas, const SkFloat3x3& toXYZ, Named); |
93 | 138 |
94 SkColorSpace(SkColorLookUpTable colorLUT, const SkFloat3& gamma, const SkFlo
at3x3& toXYZ, | 139 SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas, const SkFloat3x3&
toXYZ, |
95 const SkFloat3& toXYZOffset); | 140 const SkFloat3& toXYZOffset); |
96 | 141 |
97 const SkColorLookUpTable fColorLUT; | 142 const SkColorLookUpTable fColorLUT; |
98 const SkFloat3 fGamma; | 143 const SkGammas fGammas; |
99 const SkFloat3x3 fToXYZD50; | 144 const SkFloat3x3 fToXYZD50; |
100 const SkFloat3 fToXYZOffset; | 145 const SkFloat3 fToXYZOffset; |
101 | 146 |
102 const uint32_t fUniqueID; | 147 const uint32_t fUniqueID; |
103 const Named fNamed; | 148 const Named fNamed; |
104 }; | 149 }; |
105 | 150 |
106 #endif | 151 #endif |
OLD | NEW |