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" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 return header; | 194 return header; |
195 } | 195 } |
196 | 196 |
197 uint8_t fVersion; // Always zero | 197 uint8_t fVersion; // Always zero |
198 uint8_t fNamed; // Must be a SkColorSpace::Named | 198 uint8_t fNamed; // Must be a SkColorSpace::Named |
199 uint8_t fGammaNamed; // Must be a SkColorSpace::GammaNamed | 199 uint8_t fGammaNamed; // Must be a SkColorSpace::GammaNamed |
200 uint8_t fFlags; // Some combination of the flags listed above | 200 uint8_t fFlags; // Some combination of the flags listed above |
201 }; | 201 }; |
202 | 202 |
203 size_t SkColorSpace::writeToMemory(void* memory) const { | 203 size_t SkColorSpace::writeToMemory(void* memory) const { |
204 // If we have a named profile, only write the enum. | 204 // Start by trying the serialization fast path. If we haven't saved ICC pro
file data, |
205 switch (fNamed) { | 205 // we must have a profile that we can serialize easily. |
206 case kSRGB_Named: | 206 if (!as_CSB(this)->fProfileData) { |
207 case kAdobeRGB_Named: { | 207 // If we have a named profile, only write the enum. |
208 if (memory) { | 208 switch (fNamed) { |
209 *((ColorSpaceHeader*) memory) = | 209 case kSRGB_Named: |
210 ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNamed,
0); | 210 case kAdobeRGB_Named: { |
| 211 if (memory) { |
| 212 *((ColorSpaceHeader*) memory) = |
| 213 ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNam
ed, 0); |
| 214 } |
| 215 return sizeof(ColorSpaceHeader); |
211 } | 216 } |
212 return sizeof(ColorSpaceHeader); | 217 default: |
| 218 break; |
213 } | 219 } |
214 default: | 220 |
215 break; | 221 // If we have a named gamma, write the enum and the matrix. |
| 222 switch (fGammaNamed) { |
| 223 case kSRGB_GammaNamed: |
| 224 case k2Dot2Curve_GammaNamed: |
| 225 case kLinear_GammaNamed: { |
| 226 if (memory) { |
| 227 *((ColorSpaceHeader*) memory) = |
| 228 ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNam
ed, |
| 229 ColorSpaceHeader::kMatrix_Fla
g); |
| 230 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
); |
| 231 fToXYZD50.as4x3ColMajorf((float*) memory); |
| 232 } |
| 233 return sizeof(ColorSpaceHeader) + 12 * sizeof(float); |
| 234 } |
| 235 default: |
| 236 SkASSERT(false); |
| 237 return 0; |
| 238 } |
216 } | 239 } |
217 | 240 |
218 // If we have a named gamma, write the enum and the matrix. | 241 // Otherwise, serialize the ICC data. |
219 switch (fGammaNamed) { | |
220 case kSRGB_GammaNamed: | |
221 case k2Dot2Curve_GammaNamed: | |
222 case kLinear_GammaNamed: { | |
223 if (memory) { | |
224 *((ColorSpaceHeader*) memory) = | |
225 ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNamed, | |
226 ColorSpaceHeader::kMatrix_Flag); | |
227 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)); | |
228 fToXYZD50.as4x3ColMajorf((float*) memory); | |
229 } | |
230 return sizeof(ColorSpaceHeader) + 12 * sizeof(float); | |
231 } | |
232 default: | |
233 break; | |
234 } | |
235 | |
236 // If we do not have a named gamma, this must have been created from an ICC
profile. | |
237 // Since we were unable to recognize the gamma, we will have saved the ICC d
ata. | |
238 SkASSERT(as_CSB(this)->fProfileData); | |
239 | |
240 size_t profileSize = as_CSB(this)->fProfileData->size(); | 242 size_t profileSize = as_CSB(this)->fProfileData->size(); |
241 if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) { | 243 if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) { |
242 return 0; | 244 return 0; |
243 } | 245 } |
244 | 246 |
245 if (memory) { | 247 if (memory) { |
246 *((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(k0_Version, fName
d, fGammaNamed, | 248 *((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(k0_Version, kUnkn
own_Named, |
| 249 kNonStandard_Gamm
aNamed, |
247 ColorSpaceHeader:
:kICC_Flag); | 250 ColorSpaceHeader:
:kICC_Flag); |
248 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)); | 251 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)); |
249 | 252 |
250 *((uint32_t*) memory) = (uint32_t) SkAlign4(profileSize); | 253 *((uint32_t*) memory) = (uint32_t) SkAlign4(profileSize); |
251 memory = SkTAddOffset<void>(memory, sizeof(uint32_t)); | 254 memory = SkTAddOffset<void>(memory, sizeof(uint32_t)); |
252 | 255 |
253 memcpy(memory, as_CSB(this)->fProfileData->data(), profileSize); | 256 memcpy(memory, as_CSB(this)->fProfileData->data(), profileSize); |
254 memset(SkTAddOffset<void>(memory, profileSize), 0, SkAlign4(profileSize)
- profileSize); | 257 memset(SkTAddOffset<void>(memory, profileSize), 0, SkAlign4(profileSize)
- profileSize); |
255 } | 258 } |
256 return sizeof(ColorSpaceHeader) + sizeof(uint32_t) + SkAlign4(profileSize); | 259 return sizeof(ColorSpaceHeader) + sizeof(uint32_t) + SkAlign4(profileSize); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 if (length < profileSize) { | 312 if (length < profileSize) { |
310 return nullptr; | 313 return nullptr; |
311 } | 314 } |
312 | 315 |
313 return NewICC(data, profileSize); | 316 return NewICC(data, profileSize); |
314 } | 317 } |
315 | 318 |
316 bool SkColorSpace::gammasAreMatching() const { | 319 bool SkColorSpace::gammasAreMatching() const { |
317 const SkGammas* gammas = as_CSB(this)->gammas(); | 320 const SkGammas* gammas = as_CSB(this)->gammas(); |
318 SkASSERT(gammas); | 321 SkASSERT(gammas); |
319 return gammas->fRedData == gammas->fGreenData && gammas->fGreenData == gamma
s->fBlueData; | 322 return gammas->fRedType == gammas->fGreenType && gammas->fGreenType == gamma
s->fBlueType && |
| 323 gammas->fRedData == gammas->fGreenData && gammas->fGreenData == gamma
s->fBlueData; |
320 } | 324 } |
321 | 325 |
322 bool SkColorSpace::gammasAreNamed() const { | 326 bool SkColorSpace::gammasAreNamed() const { |
323 const SkGammas* gammas = as_CSB(this)->gammas(); | 327 const SkGammas* gammas = as_CSB(this)->gammas(); |
324 SkASSERT(gammas); | 328 SkASSERT(gammas); |
325 return gammas->fRedType == SkGammas::Type::kNamed_Type && | 329 return gammas->fRedType == SkGammas::Type::kNamed_Type && |
326 gammas->fGreenType == SkGammas::Type::kNamed_Type && | 330 gammas->fGreenType == SkGammas::Type::kNamed_Type && |
327 gammas->fBlueType == SkGammas::Type::kNamed_Type; | 331 gammas->fBlueType == SkGammas::Type::kNamed_Type; |
328 } | 332 } |
329 | 333 |
(...skipping 13 matching lines...) Expand all Loading... |
343 gammas->fBlueType == SkGammas::Type::kTable_Type; | 347 gammas->fBlueType == SkGammas::Type::kTable_Type; |
344 } | 348 } |
345 | 349 |
346 bool SkColorSpace::gammasAreParams() const { | 350 bool SkColorSpace::gammasAreParams() const { |
347 const SkGammas* gammas = as_CSB(this)->gammas(); | 351 const SkGammas* gammas = as_CSB(this)->gammas(); |
348 SkASSERT(gammas); | 352 SkASSERT(gammas); |
349 return gammas->fRedType == SkGammas::Type::kParam_Type && | 353 return gammas->fRedType == SkGammas::Type::kParam_Type && |
350 gammas->fGreenType == SkGammas::Type::kParam_Type && | 354 gammas->fGreenType == SkGammas::Type::kParam_Type && |
351 gammas->fBlueType == SkGammas::Type::kParam_Type; | 355 gammas->fBlueType == SkGammas::Type::kParam_Type; |
352 } | 356 } |
OLD | NEW |