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 * | |
113 * Most of our codecs support the same conversions: | 110 * Most of our codecs support the same conversions: |
114 * - opaque to any alpha type | 111 * - opaque to any alpha type |
115 * - 565 only if opaque | 112 * - 565 only if opaque |
116 * - premul to unpremul and vice versa | 113 * - premul to unpremul and vice versa |
117 * - always support RGBA, BGRA | 114 * - always support N32 |
118 * - otherwise match the src color type | 115 * - otherwise match the src color type |
119 */ | 116 */ |
120 static inline bool conversion_possible_ignore_color_space(const SkImageInfo& dst
, | 117 static inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo
& src) { |
121 const SkImageInfo& src
) { | |
122 // Ensure the alpha type is valid | 118 // Ensure the alpha type is valid |
123 if (!valid_alpha(dst.alphaType(), src.alphaType())) { | 119 if (!valid_alpha(dst.alphaType(), src.alphaType())) { |
124 return false; | 120 return false; |
125 } | 121 } |
126 | 122 |
127 // Check for supported color types | 123 // Check for supported color types |
128 switch (dst.colorType()) { | 124 switch (dst.colorType()) { |
129 case kRGBA_8888_SkColorType: | 125 case kRGBA_8888_SkColorType: |
130 case kBGRA_8888_SkColorType: | 126 case kBGRA_8888_SkColorType: |
131 return true; | 127 return true; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 // We never perform a color xform in legacy mode. | 328 // We never perform a color xform in legacy mode. |
333 bool isLegacy = nullptr == dstInfo.colorSpace(); | 329 bool isLegacy = nullptr == dstInfo.colorSpace(); |
334 | 330 |
335 return !isLegacy && (needsPremul || isF16 || srcDstNotEqual); | 331 return !isLegacy && (needsPremul || isF16 || srcDstNotEqual); |
336 } | 332 } |
337 | 333 |
338 static inline SkAlphaType select_alpha_xform(SkAlphaType dstAlphaType, SkAlphaTy
pe srcAlphaType) { | 334 static inline SkAlphaType select_alpha_xform(SkAlphaType dstAlphaType, SkAlphaTy
pe srcAlphaType) { |
339 return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlph
aType; | 335 return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlph
aType; |
340 } | 336 } |
341 | 337 |
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, kGray8 if kOpaque and color correction is not required | |
352 */ | |
353 static inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo
& src) { | |
354 // Ensure the alpha type is valid. | |
355 if (!valid_alpha(dst.alphaType(), src.alphaType())) { | |
356 return false; | |
357 } | |
358 | |
359 // Check for supported color types. | |
360 switch (dst.colorType()) { | |
361 case kRGBA_8888_SkColorType: | |
362 case kBGRA_8888_SkColorType: | |
363 return true; | |
364 case kRGBA_F16_SkColorType: | |
365 return dst.colorSpace() && dst.colorSpace()->gammaIsLinear(); | |
366 case kIndex_8_SkColorType: | |
367 return kIndex_8_SkColorType == src.colorType(); | |
368 case kRGB_565_SkColorType: | |
369 case kGray_8_SkColorType: | |
370 return kOpaque_SkAlphaType == src.alphaType() && !needs_color_xform(
dst, src); | |
371 default: | |
372 return false; | |
373 } | |
374 } | |
375 | |
376 #endif // SkCodecPriv_DEFINED | 338 #endif // SkCodecPriv_DEFINED |
OLD | NEW |