Index: src/codec/SkCodecPriv.h |
diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h |
index 9a8a43e8352a7d9a783ba9a6a343bf278266eb8a..04763a87ed445f0268ed6fb3f2f14b07fd957186 100644 |
--- a/src/codec/SkCodecPriv.h |
+++ b/src/codec/SkCodecPriv.h |
@@ -107,14 +107,20 @@ static inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) { |
} |
/* |
+ * Original version of conversion_possible that does not account for color spaces. |
+ * Used by codecs that have not been updated to support color spaces. |
+ * 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
|
+ * to support decodes in "legacy mode" and in "color correct modes". Codecs that |
+ * still use this function ignore color spaces and always decode in "legacy mode". |
+ * |
* Most of our codecs support the same conversions: |
* - opaque to any alpha type |
* - 565 only if opaque |
* - premul to unpremul and vice versa |
- * - always support N32 |
+ * - always support RGBA, BGRA |
* - otherwise match the src color type |
*/ |
-static inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) { |
+static inline bool legacy_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) { |
// Ensure the alpha type is valid |
if (!valid_alpha(dst.alphaType(), src.alphaType())) { |
return false; |
@@ -335,4 +341,38 @@ static inline SkAlphaType select_alpha_xform(SkAlphaType dstAlphaType, SkAlphaTy |
return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlphaType; |
} |
+/* |
+ * Alpha Type Conversions |
+ * - kOpaque to kOpaque, kUnpremul, kPremul is valid |
+ * - kUnpremul to kUnpremul, kPremul is valid |
+ * |
+ * Color Type Conversions |
+ * - Always support kRGBA_8888, kBGRA_8888 |
+ * - Support kRGBA_F16 when there is a linear dst color space |
+ * - Support kIndex8 if it matches the src |
+ * - Support k565, kGray8 if kOpaque and color correction is not required |
+ */ |
+static inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) { |
+ // Ensure the alpha type is valid. |
+ if (!valid_alpha(dst.alphaType(), src.alphaType())) { |
+ return false; |
+ } |
+ |
+ // Check for supported color types. |
+ switch (dst.colorType()) { |
+ case kRGBA_8888_SkColorType: |
+ case kBGRA_8888_SkColorType: |
+ return true; |
+ case kRGBA_F16_SkColorType: |
+ return dst.colorSpace() && dst.colorSpace()->gammaIsLinear(); |
+ case kIndex_8_SkColorType: |
+ return kIndex_8_SkColorType == src.colorType(); |
+ case kRGB_565_SkColorType: |
+ case kGray_8_SkColorType: |
+ return kOpaque_SkAlphaType == src.alphaType() && !needs_color_xform(dst, src); |
+ default: |
+ return false; |
+ } |
+} |
+ |
#endif // SkCodecPriv_DEFINED |