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 SkColorLookUpTable { |
| 39 static const uint8_t kMaxChannels = 16; |
| 40 |
| 41 uint8_t fInputChannels; |
| 42 uint8_t fOutputChannels; |
| 43 uint8_t fGridPoints[kMaxChannels]; |
| 44 std::unique_ptr<float[]> fTable; |
| 45 |
| 46 SkColorLookUpTable() { |
| 47 memset(this, 0, sizeof(struct SkColorLookUpTable)); |
| 48 } |
| 49 |
| 50 SkColorLookUpTable(SkColorLookUpTable&& that) |
| 51 : fInputChannels(that.fInputChannels) |
| 52 , fOutputChannels(that.fOutputChannels) |
| 53 , fTable(std::move(that.fTable)) |
| 54 { |
| 55 memcpy(fGridPoints, that.fGridPoints, kMaxChannels); |
| 56 } |
| 57 }; |
| 58 |
38 class SkColorSpace : public SkRefCnt { | 59 class SkColorSpace : public SkRefCnt { |
39 private: | |
40 struct SkGammaCurve { | |
41 bool isValue() const { | |
42 bool result = (0.0f != fValue); | |
43 SkASSERT(!result || (0 == fTableSize)); | |
44 return result; | |
45 } | |
46 | |
47 bool isTable() const { | |
48 bool result = (0 != fTableSize); | |
49 SkASSERT(!result || (0.0f == fValue)); | |
50 SkASSERT(!result || fTable); | |
51 return result; | |
52 } | |
53 | |
54 bool isParametric() const { return false; } | |
55 | |
56 // We have three different ways to represent gamma. | |
57 // (1) A single value: | |
58 float fValue; | |
59 | |
60 // (2) A lookup table: | |
61 uint32_t fTableSize; | |
62 std::unique_ptr<float[]> fTable; | |
63 | |
64 // (3) Parameters for a curve: | |
65 // FIXME (msarett): Handle parametric curves. | |
66 | |
67 SkGammaCurve() { | |
68 memset(this, 0, sizeof(struct SkGammaCurve)); | |
69 } | |
70 | |
71 SkGammaCurve(float value) | |
72 : fValue(value) | |
73 , fTableSize(0) | |
74 , fTable(nullptr) | |
75 {} | |
76 }; | |
77 | |
78 struct SkColorLookUpTable { | |
79 static const uint8_t kMaxChannels = 16; | |
80 | |
81 uint8_t fInputChannels; | |
82 uint8_t fOutputChannels; | |
83 uint8_t fGridPoints[kMaxChannels]; | |
84 std::unique_ptr<float[]> fTable; | |
85 | |
86 SkColorLookUpTable() { | |
87 memset(this, 0, sizeof(struct SkColorLookUpTable)); | |
88 } | |
89 }; | |
90 | |
91 public: | 60 public: |
92 enum Named { | 61 enum Named { |
93 kUnknown_Named, | 62 kUnknown_Named, |
94 kSRGB_Named, | 63 kSRGB_Named, |
95 }; | 64 }; |
96 | 65 |
97 struct SkGammas { | |
98 public: | |
99 SkGammas(float red, float green, float blue) | |
100 : fRed(red) | |
101 , fGreen(green) | |
102 , fBlue(blue) | |
103 {} | |
104 | |
105 SkGammas() {} | |
106 | |
107 SkDEBUGCODE(float red() const { return fRed.fValue; }) | |
108 SkDEBUGCODE(float green() const { return fGreen.fValue; }) | |
109 SkDEBUGCODE(float blue() const { return fBlue.fValue; }) | |
110 | |
111 private: | |
112 SkGammaCurve fRed; | |
113 SkGammaCurve fGreen; | |
114 SkGammaCurve fBlue; | |
115 | |
116 friend class SkColorSpace; | |
117 }; | |
118 | |
119 /** | 66 /** |
120 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D
50_XYZ | 67 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D
50_XYZ |
121 * and the src-gamma, return a ColorSpace | 68 * and the src-gamma, return a ColorSpace |
122 */ | 69 */ |
123 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, SkGammas gamma
s); | 70 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, const SkFloat3
& gamma); |
124 | 71 |
125 static sk_sp<SkColorSpace> NewNamed(Named); | 72 static sk_sp<SkColorSpace> NewNamed(Named); |
126 static sk_sp<SkColorSpace> NewICC(const void*, size_t); | 73 static sk_sp<SkColorSpace> NewICC(const void*, size_t); |
127 | 74 |
128 const SkGammas& gammas() const { return fGammas; } | 75 SkFloat3 gamma() const { return fGamma; } |
129 SkFloat3x3 xyz() const { return fToXYZD50; } | 76 SkFloat3x3 xyz() const { return fToXYZD50; } |
130 SkFloat3 xyzOffset() const { return fToXYZOffset; } | 77 SkFloat3 xyzOffset() const { return fToXYZOffset; } |
131 Named named() const { return fNamed; } | 78 Named named() const { return fNamed; } |
132 uint32_t uniqueID() const { return fUniqueID; } | 79 uint32_t uniqueID() const { return fUniqueID; } |
133 | 80 |
134 private: | 81 private: |
| 82 SkColorSpace(const SkFloat3& gamma, const SkFloat3x3& toXYZ, Named); |
135 | 83 |
136 static bool LoadGammas(SkGammaCurve* gammas, uint32_t num, const uint8_t* sr
c, size_t len); | 84 SkColorSpace(SkColorLookUpTable colorLUT, const SkFloat3& gamma, const SkFlo
at3x3& toXYZ, |
137 | 85 const SkFloat3& toXYZOffset); |
138 | |
139 static bool LoadColorLUT(SkColorLookUpTable* colorLUT, uint32_t inputChannel
s, | |
140 uint32_t outputChannels, const uint8_t* src, size_t
len); | |
141 | |
142 | |
143 static bool LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkFloat
3x3* toXYZ, | |
144 SkFloat3* toXYZOffset, const uint8_t* src, size_t len); | |
145 | |
146 SkColorSpace(SkGammas gammas, const SkFloat3x3& toXYZ, Named); | |
147 | |
148 SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas, | |
149 const SkFloat3x3& toXYZ, const SkFloat3& toXYZOffset); | |
150 | 86 |
151 const SkColorLookUpTable fColorLUT; | 87 const SkColorLookUpTable fColorLUT; |
152 const SkGammas fGammas; | 88 const SkFloat3 fGamma; |
153 const SkFloat3x3 fToXYZD50; | 89 const SkFloat3x3 fToXYZD50; |
154 const SkFloat3 fToXYZOffset; | 90 const SkFloat3 fToXYZOffset; |
155 | 91 |
156 const uint32_t fUniqueID; | 92 const uint32_t fUniqueID; |
157 const Named fNamed; | 93 const Named fNamed; |
158 }; | 94 }; |
159 | 95 |
160 #endif | 96 #endif |
OLD | NEW |