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 #include "SkColorSpace.h" | 8 #include "SkColorSpace.h" |
9 #include "SkColorSpace_Base.h" | 9 #include "SkColorSpace_Base.h" |
10 #include "SkColorSpacePriv.h" | 10 #include "SkColorSpacePriv.h" |
11 #include "SkOnce.h" | 11 #include "SkOnce.h" |
12 | 12 |
13 SkColorSpace::SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50) | 13 SkColorSpace::SkColorSpace(const SkMatrix44& toXYZD50) |
14 : fGammaNamed(gammaNamed) | 14 : fToXYZD50(toXYZD50) |
15 , fToXYZD50(toXYZD50) | |
16 {} | 15 {} |
17 | 16 |
18 SkColorSpace_Base::SkColorSpace_Base(GammaNamed gammaNamed, const SkMatrix44& to
XYZD50) | 17 SkColorSpace_Base::SkColorSpace_Base(SkGammaNamed gammaNamed, const SkMatrix44&
toXYZD50) |
19 : INHERITED(gammaNamed, toXYZD50) | 18 : INHERITED(toXYZD50) |
| 19 , fGammaNamed(gammaNamed) |
20 , fGammas(nullptr) | 20 , fGammas(nullptr) |
21 , fProfileData(nullptr) | 21 , fProfileData(nullptr) |
22 {} | 22 {} |
23 | 23 |
24 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, GammaNa
med gammaNamed, | 24 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, SkGamma
Named gammaNamed, |
25 sk_sp<SkGammas> gammas, const SkMatrix44& t
oXYZD50, | 25 sk_sp<SkGammas> gammas, const SkMatrix44& t
oXYZD50, |
26 sk_sp<SkData> profileData) | 26 sk_sp<SkData> profileData) |
27 : INHERITED(gammaNamed, toXYZD50) | 27 : INHERITED(toXYZD50) |
28 , fColorLUT(std::move(colorLUT)) | 28 , fColorLUT(std::move(colorLUT)) |
| 29 , fGammaNamed(gammaNamed) |
29 , fGammas(std::move(gammas)) | 30 , fGammas(std::move(gammas)) |
30 , fProfileData(std::move(profileData)) | 31 , fProfileData(std::move(profileData)) |
31 {} | 32 {} |
32 | 33 |
33 static constexpr float gSRGB_toXYZD50[] { | 34 static constexpr float gSRGB_toXYZD50[] { |
34 0.4358f, 0.2224f, 0.0139f, // * R | 35 0.4358f, 0.2224f, 0.0139f, // * R |
35 0.3853f, 0.7170f, 0.0971f, // * G | 36 0.3853f, 0.7170f, 0.0971f, // * G |
36 0.1430f, 0.0606f, 0.7139f, // * B | 37 0.1430f, 0.0606f, 0.7139f, // * B |
37 }; | 38 }; |
38 | 39 |
(...skipping 26 matching lines...) Expand all Loading... |
65 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) && | 66 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) && |
66 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) && | 67 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) && |
67 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f); | 68 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f); |
68 } | 69 } |
69 | 70 |
70 sk_sp<SkColorSpace> SkColorSpace_Base::NewRGB(const float values[3], const SkMat
rix44& toXYZD50) { | 71 sk_sp<SkColorSpace> SkColorSpace_Base::NewRGB(const float values[3], const SkMat
rix44& toXYZD50) { |
71 if (0.0f > values[0] || 0.0f > values[1] || 0.0f > values[2]) { | 72 if (0.0f > values[0] || 0.0f > values[1] || 0.0f > values[2]) { |
72 return nullptr; | 73 return nullptr; |
73 } | 74 } |
74 | 75 |
75 GammaNamed gammaNamed = kNonStandard_GammaNamed; | 76 SkGammaNamed gammaNamed = kNonStandard_SkGammaNamed; |
76 if (color_space_almost_equal(2.2f, values[0]) && | 77 if (color_space_almost_equal(2.2f, values[0]) && |
77 color_space_almost_equal(2.2f, values[1]) && | 78 color_space_almost_equal(2.2f, values[1]) && |
78 color_space_almost_equal(2.2f, values[2])) { | 79 color_space_almost_equal(2.2f, values[2])) { |
79 gammaNamed = k2Dot2Curve_GammaNamed; | 80 gammaNamed = k2Dot2Curve_SkGammaNamed; |
80 } else if (color_space_almost_equal(1.0f, values[0]) && | 81 } else if (color_space_almost_equal(1.0f, values[0]) && |
81 color_space_almost_equal(1.0f, values[1]) && | 82 color_space_almost_equal(1.0f, values[1]) && |
82 color_space_almost_equal(1.0f, values[2])) { | 83 color_space_almost_equal(1.0f, values[2])) { |
83 gammaNamed = kLinear_GammaNamed; | 84 gammaNamed = kLinear_SkGammaNamed; |
84 } | 85 } |
85 | 86 |
86 if (kNonStandard_GammaNamed == gammaNamed) { | 87 if (kNonStandard_SkGammaNamed == gammaNamed) { |
87 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas()); | 88 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas()); |
88 gammas->fRedType = SkGammas::Type::kValue_Type; | 89 gammas->fRedType = SkGammas::Type::kValue_Type; |
89 gammas->fGreenType = SkGammas::Type::kValue_Type; | 90 gammas->fGreenType = SkGammas::Type::kValue_Type; |
90 gammas->fBlueType = SkGammas::Type::kValue_Type; | 91 gammas->fBlueType = SkGammas::Type::kValue_Type; |
91 gammas->fRedData.fValue = values[0]; | 92 gammas->fRedData.fValue = values[0]; |
92 gammas->fGreenData.fValue = values[1]; | 93 gammas->fGreenData.fValue = values[1]; |
93 gammas->fBlueData.fValue = values[2]; | 94 gammas->fBlueData.fValue = values[2]; |
94 return sk_sp<SkColorSpace>(new SkColorSpace_Base(nullptr, kNonStandard_G
ammaNamed, gammas, | 95 return sk_sp<SkColorSpace>(new SkColorSpace_Base(nullptr, kNonStandard_S
kGammaNamed, gammas, |
95 toXYZD50, nullptr)); | 96 toXYZD50, nullptr)); |
96 } | 97 } |
97 | 98 |
98 return SkColorSpace_Base::NewRGB(gammaNamed, toXYZD50); | 99 return SkColorSpace_Base::NewRGB(gammaNamed, toXYZD50); |
99 } | 100 } |
100 | 101 |
101 sk_sp<SkColorSpace> SkColorSpace_Base::NewRGB(GammaNamed gammaNamed, const SkMat
rix44& toXYZD50) { | 102 sk_sp<SkColorSpace> SkColorSpace_Base::NewRGB(SkGammaNamed gammaNamed, const SkM
atrix44& toXYZD50) { |
102 switch (gammaNamed) { | 103 switch (gammaNamed) { |
103 case kSRGB_GammaNamed: | 104 case kSRGB_SkGammaNamed: |
104 if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) { | 105 if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) { |
105 return SkColorSpace::NewNamed(kSRGB_Named); | 106 return SkColorSpace::NewNamed(kSRGB_Named); |
106 } | 107 } |
107 break; | 108 break; |
108 case k2Dot2Curve_GammaNamed: | 109 case k2Dot2Curve_SkGammaNamed: |
109 if (xyz_almost_equal(toXYZD50, gAdobeRGB_toXYZD50)) { | 110 if (xyz_almost_equal(toXYZD50, gAdobeRGB_toXYZD50)) { |
110 return SkColorSpace::NewNamed(kAdobeRGB_Named); | 111 return SkColorSpace::NewNamed(kAdobeRGB_Named); |
111 } | 112 } |
112 break; | 113 break; |
113 case kNonStandard_GammaNamed: | 114 case kNonStandard_SkGammaNamed: |
114 // This is not allowed. | 115 // This is not allowed. |
115 return nullptr; | 116 return nullptr; |
116 default: | 117 default: |
117 break; | 118 break; |
118 } | 119 } |
119 | 120 |
120 return sk_sp<SkColorSpace>(new SkColorSpace_Base(gammaNamed, toXYZD50)); | 121 return sk_sp<SkColorSpace>(new SkColorSpace_Base(gammaNamed, toXYZD50)); |
121 } | 122 } |
122 | 123 |
123 sk_sp<SkColorSpace> SkColorSpace::NewRGB(GammaNamed gammaNamed, const SkMatrix44
& toXYZD50) { | 124 sk_sp<SkColorSpace> SkColorSpace::NewRGB(GammaNamed gammaNamed, const SkMatrix44
& toXYZD50) { |
124 return SkColorSpace_Base::NewRGB(gammaNamed, toXYZD50); | 125 return SkColorSpace_Base::NewRGB((SkGammaNamed) gammaNamed, toXYZD50); |
125 } | 126 } |
126 | 127 |
127 static SkColorSpace* gAdobeRGB; | 128 static SkColorSpace* gAdobeRGB; |
128 static SkColorSpace* gSRGB; | 129 static SkColorSpace* gSRGB; |
129 | 130 |
130 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { | 131 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { |
131 static SkOnce sRGBOnce; | 132 static SkOnce sRGBOnce; |
132 static SkOnce adobeRGBOnce; | 133 static SkOnce adobeRGBOnce; |
133 | 134 |
134 switch (named) { | 135 switch (named) { |
135 case kSRGB_Named: { | 136 case kSRGB_Named: { |
136 sRGBOnce([] { | 137 sRGBOnce([] { |
137 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); | 138 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); |
138 srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50); | 139 srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50); |
139 | 140 |
140 // Force the mutable type mask to be computed. This avoids race
s. | 141 // Force the mutable type mask to be computed. This avoids race
s. |
141 (void)srgbToxyzD50.getType(); | 142 (void)srgbToxyzD50.getType(); |
142 gSRGB = new SkColorSpace_Base(kSRGB_GammaNamed, srgbToxyzD50); | 143 gSRGB = new SkColorSpace_Base(kSRGB_SkGammaNamed, srgbToxyzD50); |
143 }); | 144 }); |
144 return sk_ref_sp<SkColorSpace>(gSRGB); | 145 return sk_ref_sp<SkColorSpace>(gSRGB); |
145 } | 146 } |
146 case kAdobeRGB_Named: { | 147 case kAdobeRGB_Named: { |
147 adobeRGBOnce([] { | 148 adobeRGBOnce([] { |
148 SkMatrix44 adobergbToxyzD50(SkMatrix44::kUninitialized_Construct
or); | 149 SkMatrix44 adobergbToxyzD50(SkMatrix44::kUninitialized_Construct
or); |
149 adobergbToxyzD50.set3x3RowMajorf(gAdobeRGB_toXYZD50); | 150 adobergbToxyzD50.set3x3RowMajorf(gAdobeRGB_toXYZD50); |
150 | 151 |
151 // Force the mutable type mask to be computed. This avoids race
s. | 152 // Force the mutable type mask to be computed. This avoids race
s. |
152 (void)adobergbToxyzD50.getType(); | 153 (void)adobergbToxyzD50.getType(); |
153 gAdobeRGB = new SkColorSpace_Base(k2Dot2Curve_GammaNamed, adober
gbToxyzD50); | 154 gAdobeRGB = new SkColorSpace_Base(k2Dot2Curve_SkGammaNamed, adob
ergbToxyzD50); |
154 }); | 155 }); |
155 return sk_ref_sp<SkColorSpace>(gAdobeRGB); | 156 return sk_ref_sp<SkColorSpace>(gAdobeRGB); |
156 } | 157 } |
157 default: | 158 default: |
158 break; | 159 break; |
159 } | 160 } |
160 return nullptr; | 161 return nullptr; |
161 } | 162 } |
162 | 163 |
163 sk_sp<SkColorSpace> SkColorSpace::makeLinearGamma() { | 164 sk_sp<SkColorSpace> SkColorSpace::makeLinearGamma() { |
164 return SkColorSpace_Base::NewRGB(kLinear_GammaNamed, fToXYZD50); | 165 return SkColorSpace_Base::NewRGB(kLinear_SkGammaNamed, fToXYZD50); |
| 166 } |
| 167 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 168 |
| 169 bool SkColorSpace::gammaCloseToSRGB() const { |
| 170 return kSRGB_SkGammaNamed == as_CSB(this)->fGammaNamed || |
| 171 k2Dot2Curve_SkGammaNamed == as_CSB(this)->fGammaNamed; |
| 172 } |
| 173 |
| 174 bool SkColorSpace::gammaIsLinear() const { |
| 175 return kLinear_SkGammaNamed == as_CSB(this)->fGammaNamed; |
165 } | 176 } |
166 | 177 |
167 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 178 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
168 | 179 |
169 enum Version { | 180 enum Version { |
170 k0_Version, // Initial version, header + flags for matrix and profile | 181 k0_Version, // Initial version, header + flags for matrix and profile |
171 }; | 182 }; |
172 | 183 |
173 struct ColorSpaceHeader { | 184 struct ColorSpaceHeader { |
174 /** | 185 /** |
(...skipping 21 matching lines...) Expand all Loading... |
196 static ColorSpaceHeader Pack(Version version, uint8_t named, uint8_t gammaNa
med, uint8_t flags) | 207 static ColorSpaceHeader Pack(Version version, uint8_t named, uint8_t gammaNa
med, uint8_t flags) |
197 { | 208 { |
198 ColorSpaceHeader header; | 209 ColorSpaceHeader header; |
199 | 210 |
200 SkASSERT(k0_Version == version); | 211 SkASSERT(k0_Version == version); |
201 header.fVersion = (uint8_t) version; | 212 header.fVersion = (uint8_t) version; |
202 | 213 |
203 SkASSERT(named <= SkColorSpace::kAdobeRGB_Named); | 214 SkASSERT(named <= SkColorSpace::kAdobeRGB_Named); |
204 header.fNamed = (uint8_t) named; | 215 header.fNamed = (uint8_t) named; |
205 | 216 |
206 SkASSERT(gammaNamed <= SkColorSpace::kNonStandard_GammaNamed); | 217 SkASSERT(gammaNamed <= kNonStandard_SkGammaNamed); |
207 header.fGammaNamed = (uint8_t) gammaNamed; | 218 header.fGammaNamed = (uint8_t) gammaNamed; |
208 | 219 |
209 SkASSERT(flags <= kFloatGamma_Flag); | 220 SkASSERT(flags <= kFloatGamma_Flag); |
210 header.fFlags = flags; | 221 header.fFlags = flags; |
211 return header; | 222 return header; |
212 } | 223 } |
213 | 224 |
214 uint8_t fVersion; // Always zero | 225 uint8_t fVersion; // Always zero |
215 uint8_t fNamed; // Must be a SkColorSpace::Named | 226 uint8_t fNamed; // Must be a SkColorSpace::Named |
216 uint8_t fGammaNamed; // Must be a SkColorSpace::GammaNamed | 227 uint8_t fGammaNamed; // Must be a SkGammaNamed |
217 uint8_t fFlags; // Some combination of the flags listed above | 228 uint8_t fFlags; // Some combination of the flags listed above |
218 }; | 229 }; |
219 | 230 |
220 size_t SkColorSpace::writeToMemory(void* memory) const { | 231 size_t SkColorSpace::writeToMemory(void* memory) const { |
221 // Start by trying the serialization fast path. If we haven't saved ICC pro
file data, | 232 // Start by trying the serialization fast path. If we haven't saved ICC pro
file data, |
222 // we must have a profile that we can serialize easily. | 233 // we must have a profile that we can serialize easily. |
223 if (!as_CSB(this)->fProfileData) { | 234 if (!as_CSB(this)->fProfileData) { |
224 // If we have a named profile, only write the enum. | 235 // If we have a named profile, only write the enum. |
225 if (this == gSRGB) { | 236 if (this == gSRGB) { |
226 if (memory) { | 237 if (memory) { |
227 *((ColorSpaceHeader*) memory) = | 238 *((ColorSpaceHeader*) memory) = |
228 ColorSpaceHeader::Pack(k0_Version, kSRGB_Named, fGammaNa
med, 0); | 239 ColorSpaceHeader::Pack(k0_Version, kSRGB_Named, |
| 240 as_CSB(this)->fGammaNamed, 0); |
229 } | 241 } |
230 return sizeof(ColorSpaceHeader); | 242 return sizeof(ColorSpaceHeader); |
231 } else if (this == gAdobeRGB) { | 243 } else if (this == gAdobeRGB) { |
232 if (memory) { | 244 if (memory) { |
233 *((ColorSpaceHeader*) memory) = | 245 *((ColorSpaceHeader*) memory) = |
234 ColorSpaceHeader::Pack(k0_Version, kAdobeRGB_Named, fGam
maNamed, 0); | 246 ColorSpaceHeader::Pack(k0_Version, kAdobeRGB_Named, |
| 247 as_CSB(this)->fGammaNamed, 0); |
235 } | 248 } |
236 } | 249 } |
237 | 250 |
238 // If we have a named gamma, write the enum and the matrix. | 251 // If we have a named gamma, write the enum and the matrix. |
239 switch (fGammaNamed) { | 252 switch (as_CSB(this)->fGammaNamed) { |
240 case kSRGB_GammaNamed: | 253 case kSRGB_SkGammaNamed: |
241 case k2Dot2Curve_GammaNamed: | 254 case k2Dot2Curve_SkGammaNamed: |
242 case kLinear_GammaNamed: { | 255 case kLinear_SkGammaNamed: { |
243 if (memory) { | 256 if (memory) { |
244 *((ColorSpaceHeader*) memory) = | 257 *((ColorSpaceHeader*) memory) = |
245 ColorSpaceHeader::Pack(k0_Version, 0, fGammaNamed, | 258 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)->
fGammaNamed, |
246 ColorSpaceHeader::kMatrix_Fla
g); | 259 ColorSpaceHeader::kMatrix_Fla
g); |
247 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
); | 260 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
); |
248 fToXYZD50.as4x3ColMajorf((float*) memory); | 261 fToXYZD50.as4x3ColMajorf((float*) memory); |
249 } | 262 } |
250 return sizeof(ColorSpaceHeader) + 12 * sizeof(float); | 263 return sizeof(ColorSpaceHeader) + 12 * sizeof(float); |
251 } | 264 } |
252 default: | 265 default: |
253 // Otherwise, write the gamma values and the matrix. | 266 // Otherwise, write the gamma values and the matrix. |
254 if (memory) { | 267 if (memory) { |
255 *((ColorSpaceHeader*) memory) = | 268 *((ColorSpaceHeader*) memory) = |
256 ColorSpaceHeader::Pack(k0_Version, 0, fGammaNamed, | 269 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)->
fGammaNamed, |
257 ColorSpaceHeader::kFloatGamma
_Flag); | 270 ColorSpaceHeader::kFloatGamma
_Flag); |
258 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
); | 271 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
); |
259 | 272 |
260 const SkGammas* gammas = as_CSB(this)->gammas(); | 273 const SkGammas* gammas = as_CSB(this)->gammas(); |
261 SkASSERT(gammas); | 274 SkASSERT(gammas); |
262 SkASSERT(SkGammas::Type::kValue_Type == gammas->fRedType && | 275 SkASSERT(SkGammas::Type::kValue_Type == gammas->fRedType && |
263 SkGammas::Type::kValue_Type == gammas->fGreenType &
& | 276 SkGammas::Type::kValue_Type == gammas->fGreenType &
& |
264 SkGammas::Type::kValue_Type == gammas->fBlueType); | 277 SkGammas::Type::kValue_Type == gammas->fBlueType); |
265 *(((float*) memory) + 0) = gammas->fRedData.fValue; | 278 *(((float*) memory) + 0) = gammas->fRedData.fValue; |
266 *(((float*) memory) + 1) = gammas->fGreenData.fValue; | 279 *(((float*) memory) + 1) = gammas->fGreenData.fValue; |
267 *(((float*) memory) + 2) = gammas->fBlueData.fValue; | 280 *(((float*) memory) + 2) = gammas->fBlueData.fValue; |
268 memory = SkTAddOffset<void>(memory, 3 * sizeof(float)); | 281 memory = SkTAddOffset<void>(memory, 3 * sizeof(float)); |
269 | 282 |
270 fToXYZD50.as4x3ColMajorf((float*) memory); | 283 fToXYZD50.as4x3ColMajorf((float*) memory); |
271 } | 284 } |
272 return sizeof(ColorSpaceHeader) + 15 * sizeof(float); | 285 return sizeof(ColorSpaceHeader) + 15 * sizeof(float); |
273 } | 286 } |
274 } | 287 } |
275 | 288 |
276 // Otherwise, serialize the ICC data. | 289 // Otherwise, serialize the ICC data. |
277 size_t profileSize = as_CSB(this)->fProfileData->size(); | 290 size_t profileSize = as_CSB(this)->fProfileData->size(); |
278 if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) { | 291 if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) { |
279 return 0; | 292 return 0; |
280 } | 293 } |
281 | 294 |
282 if (memory) { | 295 if (memory) { |
283 *((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(k0_Version, 0, | 296 *((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(k0_Version, 0, |
284 kNonStandard_Gamm
aNamed, | 297 kNonStandard_SkGa
mmaNamed, |
285 ColorSpaceHeader:
:kICC_Flag); | 298 ColorSpaceHeader:
:kICC_Flag); |
286 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)); | 299 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)); |
287 | 300 |
288 *((uint32_t*) memory) = (uint32_t) SkAlign4(profileSize); | 301 *((uint32_t*) memory) = (uint32_t) SkAlign4(profileSize); |
289 memory = SkTAddOffset<void>(memory, sizeof(uint32_t)); | 302 memory = SkTAddOffset<void>(memory, sizeof(uint32_t)); |
290 | 303 |
291 memcpy(memory, as_CSB(this)->fProfileData->data(), profileSize); | 304 memcpy(memory, as_CSB(this)->fProfileData->data(), profileSize); |
292 memset(SkTAddOffset<void>(memory, profileSize), 0, SkAlign4(profileSize)
- profileSize); | 305 memset(SkTAddOffset<void>(memory, profileSize), 0, SkAlign4(profileSize)
- profileSize); |
293 } | 306 } |
294 return sizeof(ColorSpaceHeader) + sizeof(uint32_t) + SkAlign4(profileSize); | 307 return sizeof(ColorSpaceHeader) + sizeof(uint32_t) + SkAlign4(profileSize); |
(...skipping 15 matching lines...) Expand all Loading... |
310 return nullptr; | 323 return nullptr; |
311 } | 324 } |
312 | 325 |
313 ColorSpaceHeader header = *((const ColorSpaceHeader*) data); | 326 ColorSpaceHeader header = *((const ColorSpaceHeader*) data); |
314 data = SkTAddOffset<const void>(data, sizeof(ColorSpaceHeader)); | 327 data = SkTAddOffset<const void>(data, sizeof(ColorSpaceHeader)); |
315 length -= sizeof(ColorSpaceHeader); | 328 length -= sizeof(ColorSpaceHeader); |
316 if (0 == header.fFlags) { | 329 if (0 == header.fFlags) { |
317 return NewNamed((Named) header.fNamed); | 330 return NewNamed((Named) header.fNamed); |
318 } | 331 } |
319 | 332 |
320 switch ((GammaNamed) header.fGammaNamed) { | 333 switch ((SkGammaNamed) header.fGammaNamed) { |
321 case kSRGB_GammaNamed: | 334 case kSRGB_SkGammaNamed: |
322 case k2Dot2Curve_GammaNamed: | 335 case k2Dot2Curve_SkGammaNamed: |
323 case kLinear_GammaNamed: { | 336 case kLinear_SkGammaNamed: { |
324 if (ColorSpaceHeader::kMatrix_Flag != header.fFlags || length < 12 *
sizeof(float)) { | 337 if (ColorSpaceHeader::kMatrix_Flag != header.fFlags || length < 12 *
sizeof(float)) { |
325 return nullptr; | 338 return nullptr; |
326 } | 339 } |
327 | 340 |
328 SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); | 341 SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); |
329 toXYZ.set4x3ColMajorf((const float*) data); | 342 toXYZ.set4x3ColMajorf((const float*) data); |
330 return NewRGB((GammaNamed) header.fGammaNamed, toXYZ); | 343 return NewRGB((GammaNamed) header.fGammaNamed, toXYZ); |
331 } | 344 } |
332 default: | 345 default: |
333 break; | 346 break; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 if (srcData && dstData) { | 396 if (srcData && dstData) { |
384 return srcData->size() == dstData->size() && | 397 return srcData->size() == dstData->size() && |
385 0 == memcmp(srcData->data(), dstData->data(), srcData->size()
); | 398 0 == memcmp(srcData->data(), dstData->data(), srcData->size()
); |
386 } | 399 } |
387 | 400 |
388 return false; | 401 return false; |
389 } | 402 } |
390 | 403 |
391 // It's important to check fProfileData before named gammas. Some profiles
may have named | 404 // It's important to check fProfileData before named gammas. Some profiles
may have named |
392 // gammas, but also include other wacky features that cause us to save the d
ata. | 405 // gammas, but also include other wacky features that cause us to save the d
ata. |
393 switch (src->fGammaNamed) { | 406 switch (as_CSB(src)->fGammaNamed) { |
394 case kSRGB_GammaNamed: | 407 case kSRGB_SkGammaNamed: |
395 case k2Dot2Curve_GammaNamed: | 408 case k2Dot2Curve_SkGammaNamed: |
396 case kLinear_GammaNamed: | 409 case kLinear_SkGammaNamed: |
397 return (src->fGammaNamed == dst->fGammaNamed) && (src->fToXYZD50 ==
dst->fToXYZD50); | 410 return (as_CSB(src)->fGammaNamed == as_CSB(dst)->fGammaNamed) && |
| 411 (src->fToXYZD50 == dst->fToXYZD50); |
398 default: | 412 default: |
399 if (src->fGammaNamed != dst->fGammaNamed) { | 413 if (as_CSB(src)->fGammaNamed != as_CSB(dst)->fGammaNamed) { |
400 return false; | 414 return false; |
401 } | 415 } |
402 | 416 |
403 // It is unlikely that we will reach this case. | 417 // It is unlikely that we will reach this case. |
404 sk_sp<SkData> srcData = src->serialize(); | 418 sk_sp<SkData> srcData = src->serialize(); |
405 sk_sp<SkData> dstData = dst->serialize(); | 419 sk_sp<SkData> dstData = dst->serialize(); |
406 return srcData->size() == dstData->size() && | 420 return srcData->size() == dstData->size() && |
407 0 == memcmp(srcData->data(), dstData->data(), srcData->size()
); | 421 0 == memcmp(srcData->data(), dstData->data(), srcData->size()
); |
408 } | 422 } |
409 } | 423 } |
410 | |
411 bool SkColorSpace::gammasAreMatching() const { | |
412 const SkGammas* gammas = as_CSB(this)->gammas(); | |
413 SkASSERT(gammas); | |
414 return gammas->fRedType == gammas->fGreenType && gammas->fGreenType == gamma
s->fBlueType && | |
415 gammas->fRedData == gammas->fGreenData && gammas->fGreenData == gamma
s->fBlueData; | |
416 } | |
417 | |
418 bool SkColorSpace::gammasAreNamed() const { | |
419 const SkGammas* gammas = as_CSB(this)->gammas(); | |
420 SkASSERT(gammas); | |
421 return gammas->fRedType == SkGammas::Type::kNamed_Type && | |
422 gammas->fGreenType == SkGammas::Type::kNamed_Type && | |
423 gammas->fBlueType == SkGammas::Type::kNamed_Type; | |
424 } | |
425 | |
426 bool SkColorSpace::gammasAreValues() const { | |
427 const SkGammas* gammas = as_CSB(this)->gammas(); | |
428 SkASSERT(gammas); | |
429 return gammas->fRedType == SkGammas::Type::kValue_Type && | |
430 gammas->fGreenType == SkGammas::Type::kValue_Type && | |
431 gammas->fBlueType == SkGammas::Type::kValue_Type; | |
432 } | |
433 | |
434 bool SkColorSpace::gammasAreTables() const { | |
435 const SkGammas* gammas = as_CSB(this)->gammas(); | |
436 SkASSERT(gammas); | |
437 return gammas->fRedType == SkGammas::Type::kTable_Type && | |
438 gammas->fGreenType == SkGammas::Type::kTable_Type && | |
439 gammas->fBlueType == SkGammas::Type::kTable_Type; | |
440 } | |
441 | |
442 bool SkColorSpace::gammasAreParams() const { | |
443 const SkGammas* gammas = as_CSB(this)->gammas(); | |
444 SkASSERT(gammas); | |
445 return gammas->fRedType == SkGammas::Type::kParam_Type && | |
446 gammas->fGreenType == SkGammas::Type::kParam_Type && | |
447 gammas->fBlueType == SkGammas::Type::kParam_Type; | |
448 } | |
OLD | NEW |