Chromium Code Reviews| 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 * This is not synonymous with decoding in "legacy mode". Codecs should be able | |
|
scroggo
2016/09/08 16:33:11
I vote we use a different name. Conversion possibl
msarett
2016/09/08 16:49:45
Works for me - also removed this part of the comme
| |
| 113 * to support decodes in "legacy mode" and in "color correct modes". Codecs tha t | |
| 114 * still use this function ignore color spaces and always decode in "legacy mode ". | |
| 115 * | |
| 110 * Most of our codecs support the same conversions: | 116 * Most of our codecs support the same conversions: |
| 111 * - opaque to any alpha type | 117 * - opaque to any alpha type |
| 112 * - 565 only if opaque | 118 * - 565 only if opaque |
| 113 * - premul to unpremul and vice versa | 119 * - premul to unpremul and vice versa |
| 114 * - always support N32 | 120 * - always support RGBA, BGRA |
| 115 * - otherwise match the src color type | 121 * - otherwise match the src color type |
| 116 */ | 122 */ |
| 117 static inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo & src) { | 123 static inline bool legacy_conversion_possible(const SkImageInfo& dst, const SkIm ageInfo& src) { |
| 118 // Ensure the alpha type is valid | 124 // Ensure the alpha type is valid |
| 119 if (!valid_alpha(dst.alphaType(), src.alphaType())) { | 125 if (!valid_alpha(dst.alphaType(), src.alphaType())) { |
| 120 return false; | 126 return false; |
| 121 } | 127 } |
| 122 | 128 |
| 123 // Check for supported color types | 129 // Check for supported color types |
| 124 switch (dst.colorType()) { | 130 switch (dst.colorType()) { |
| 125 case kRGBA_8888_SkColorType: | 131 case kRGBA_8888_SkColorType: |
| 126 case kBGRA_8888_SkColorType: | 132 case kBGRA_8888_SkColorType: |
| 127 return true; | 133 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. | 334 // We never perform a color xform in legacy mode. |
| 329 bool isLegacy = nullptr == dstInfo.colorSpace(); | 335 bool isLegacy = nullptr == dstInfo.colorSpace(); |
| 330 | 336 |
| 331 return !isLegacy && (needsPremul || isF16 || srcDstNotEqual); | 337 return !isLegacy && (needsPremul || isF16 || srcDstNotEqual); |
| 332 } | 338 } |
| 333 | 339 |
| 334 static inline SkAlphaType select_alpha_xform(SkAlphaType dstAlphaType, SkAlphaTy pe srcAlphaType) { | 340 static inline SkAlphaType select_alpha_xform(SkAlphaType dstAlphaType, SkAlphaTy pe srcAlphaType) { |
| 335 return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlph aType; | 341 return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlph aType; |
| 336 } | 342 } |
| 337 | 343 |
| 344 /* | |
| 345 * Alpha Type Conversions | |
| 346 * - kOpaque to kOpaque, kUnpremul, kPremul is valid | |
| 347 * - kUnpremul to kUnpremul, kPremul is valid | |
| 348 * | |
| 349 * Color Type Conversions | |
| 350 * - Always support kRGBA_8888, kBGRA_8888 | |
| 351 * - Support kRGBA_F16 when there is a linear dst color space | |
| 352 * - Support kIndex8 if it matches the src | |
| 353 * - Support k565, kGray8 if kOpaque and color correction is not required | |
| 354 */ | |
| 355 static inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo & src) { | |
| 356 // Ensure the alpha type is valid. | |
| 357 if (!valid_alpha(dst.alphaType(), src.alphaType())) { | |
| 358 return false; | |
| 359 } | |
| 360 | |
| 361 // Check for supported color types. | |
| 362 switch (dst.colorType()) { | |
| 363 case kRGBA_8888_SkColorType: | |
| 364 case kBGRA_8888_SkColorType: | |
| 365 return true; | |
| 366 case kRGBA_F16_SkColorType: | |
| 367 return dst.colorSpace() && dst.colorSpace()->gammaIsLinear(); | |
| 368 case kIndex_8_SkColorType: | |
| 369 return kIndex_8_SkColorType == src.colorType(); | |
| 370 case kRGB_565_SkColorType: | |
| 371 case kGray_8_SkColorType: | |
| 372 return kOpaque_SkAlphaType == src.alphaType() && !needs_color_xform( dst, src); | |
| 373 default: | |
| 374 return false; | |
| 375 } | |
| 376 } | |
| 377 | |
| 338 #endif // SkCodecPriv_DEFINED | 378 #endif // SkCodecPriv_DEFINED |
| OLD | NEW |