OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The Android Open Source Project | 2 * Copyright 2015 The Android Open Source Project |
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 SkCodecPriv_DEFINED | 8 #ifndef SkCodecPriv_DEFINED |
9 #define SkCodecPriv_DEFINED | 9 #define SkCodecPriv_DEFINED |
10 | 10 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 break; | 100 break; |
101 default: | 101 default: |
102 // We cannot decode a non-opaque image to opaque (or unknown) | 102 // We cannot decode a non-opaque image to opaque (or unknown) |
103 return false; | 103 return false; |
104 } | 104 } |
105 } | 105 } |
106 return true; | 106 return true; |
107 } | 107 } |
108 | 108 |
109 /* | 109 /* |
| 110 * Original version of conversion_possible that does not account for color space
s. |
| 111 * Used by codecs that have not been updated to support color spaces. |
| 112 * |
110 * Most of our codecs support the same conversions: | 113 * Most of our codecs support the same conversions: |
111 * - opaque to any alpha type | 114 * - opaque to any alpha type |
112 * - 565 only if opaque | 115 * - 565 only if opaque |
113 * - premul to unpremul and vice versa | 116 * - premul to unpremul and vice versa |
114 * - always support N32 | 117 * - always support RGBA, BGRA |
115 * - otherwise match the src color type | 118 * - otherwise match the src color type |
116 */ | 119 */ |
117 static inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo
& src) { | 120 static inline bool conversion_possible_ignore_color_space(const SkImageInfo& dst
, |
| 121 const SkImageInfo& src
) { |
118 // Ensure the alpha type is valid | 122 // Ensure the alpha type is valid |
119 if (!valid_alpha(dst.alphaType(), src.alphaType())) { | 123 if (!valid_alpha(dst.alphaType(), src.alphaType())) { |
120 return false; | 124 return false; |
121 } | 125 } |
122 | 126 |
123 // Check for supported color types | 127 // Check for supported color types |
124 switch (dst.colorType()) { | 128 switch (dst.colorType()) { |
125 case kRGBA_8888_SkColorType: | 129 case kRGBA_8888_SkColorType: |
126 case kBGRA_8888_SkColorType: | 130 case kBGRA_8888_SkColorType: |
127 return true; | 131 return true; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 // We never perform a color xform in legacy mode. | 332 // We never perform a color xform in legacy mode. |
329 bool isLegacy = nullptr == dstInfo.colorSpace(); | 333 bool isLegacy = nullptr == dstInfo.colorSpace(); |
330 | 334 |
331 return !isLegacy && (needsPremul || isF16 || srcDstNotEqual); | 335 return !isLegacy && (needsPremul || isF16 || srcDstNotEqual); |
332 } | 336 } |
333 | 337 |
334 static inline SkAlphaType select_alpha_xform(SkAlphaType dstAlphaType, SkAlphaTy
pe srcAlphaType) { | 338 static inline SkAlphaType select_alpha_xform(SkAlphaType dstAlphaType, SkAlphaTy
pe srcAlphaType) { |
335 return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlph
aType; | 339 return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlph
aType; |
336 } | 340 } |
337 | 341 |
| 342 /* |
| 343 * Alpha Type Conversions |
| 344 * - kOpaque to kOpaque, kUnpremul, kPremul is valid |
| 345 * - kUnpremul to kUnpremul, kPremul is valid |
| 346 * |
| 347 * Color Type Conversions |
| 348 * - Always support kRGBA_8888, kBGRA_8888 |
| 349 * - Support kRGBA_F16 when there is a linear dst color space |
| 350 * - Support kIndex8 if it matches the src |
| 351 * - Support k565 if kOpaque and color correction is not required |
| 352 * - Support k565 if it matches the src, kOpaque, and color correction is not re
quired |
| 353 */ |
| 354 static inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo
& src) { |
| 355 // Ensure the alpha type is valid. |
| 356 if (!valid_alpha(dst.alphaType(), src.alphaType())) { |
| 357 return false; |
| 358 } |
| 359 |
| 360 // Check for supported color types. |
| 361 switch (dst.colorType()) { |
| 362 case kRGBA_8888_SkColorType: |
| 363 case kBGRA_8888_SkColorType: |
| 364 return true; |
| 365 case kRGBA_F16_SkColorType: |
| 366 return dst.colorSpace() && dst.colorSpace()->gammaIsLinear(); |
| 367 case kIndex_8_SkColorType: |
| 368 return kIndex_8_SkColorType == src.colorType(); |
| 369 case kRGB_565_SkColorType: |
| 370 return kOpaque_SkAlphaType == src.alphaType() && !needs_color_xform(
dst, src); |
| 371 case kGray_8_SkColorType: |
| 372 return kGray_8_SkColorType == src.colorType() && |
| 373 kOpaque_SkAlphaType == src.alphaType() && !needs_color_xform(
dst, src); |
| 374 default: |
| 375 return false; |
| 376 } |
| 377 } |
| 378 |
338 #endif // SkCodecPriv_DEFINED | 379 #endif // SkCodecPriv_DEFINED |
OLD | NEW |