Move calls to conversion_possible to SkCodec
Move common code into the base class, so subclasses need not call
conversion_possible.
Use SkEncodedInfo rather than SkImageInfo, and use the proper frame.
API Changes:
- SkAndroidCodec:
- Add getEncodedInfo(), for SkBitmapRegionCodec
- SkEncodedInfo:
- Add opaque() helper
- SkBitmapRegionDecoder:
- Remove unused conversionSupported
(Split off from skia-review.googlesource.com/c/25746)
Bug: skia:5601
Change-Id: If4a40d4b98a3dd0afde2b6058f92315a393a5baf
Reviewed-on: https://skia-review.googlesource.com/34361
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h
index cb7cd94..a737fb7 100644
--- a/src/codec/SkCodecPriv.h
+++ b/src/codec/SkCodecPriv.h
@@ -82,31 +82,20 @@
return ((srcCoord - startCoord) % sampleFactor) == 0;
}
-static inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) {
+static inline bool valid_alpha(SkAlphaType dstAlpha, bool srcIsOpaque) {
if (kUnknown_SkAlphaType == dstAlpha) {
return false;
}
- if (srcAlpha != dstAlpha) {
- if (kOpaque_SkAlphaType == srcAlpha) {
- // If the source is opaque, we can support any.
+ if (srcIsOpaque) {
+ if (kOpaque_SkAlphaType != dstAlpha) {
SkCodecPrintf("Warning: an opaque image should be decoded as opaque "
"- it is being decoded as non-opaque, which will draw slower\n");
- return true;
}
-
- // The source is not opaque
- switch (dstAlpha) {
- case kPremul_SkAlphaType:
- case kUnpremul_SkAlphaType:
- // The source is not opaque, so either of these is okay
- break;
- default:
- // We cannot decode a non-opaque image to opaque (or unknown)
- return false;
- }
+ return true;
}
- return true;
+
+ return dstAlpha != kOpaque_SkAlphaType;
}
/*
@@ -287,7 +276,7 @@
SkEncodedInfo::kUnpremul_Alpha == encodedInfo.alpha();
}
-static inline bool needs_color_xform(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo,
+static inline bool needs_color_xform(const SkImageInfo& dstInfo, const SkColorSpace* srcCS,
bool needsColorCorrectPremul) {
// We never perform a color xform in legacy mode.
if (!dstInfo.colorSpace()) {
@@ -298,7 +287,7 @@
bool isF16 = kRGBA_F16_SkColorType == dstInfo.colorType();
// Need a color xform when dst space does not match the src.
- bool srcDstNotEqual = !SkColorSpace::Equals(srcInfo.colorSpace(), dstInfo.colorSpace());
+ bool srcDstNotEqual = !SkColorSpace::Equals(srcCS, dstInfo.colorSpace());
return needsColorCorrectPremul || isF16 || srcDstNotEqual;
}
@@ -307,38 +296,4 @@
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 k565 if kOpaque and color correction is not required
- * - Support k565 if it matches the src, 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 kRGB_565_SkColorType:
- return kOpaque_SkAlphaType == src.alphaType();
- case kGray_8_SkColorType:
- return kGray_8_SkColorType == src.colorType() &&
- kOpaque_SkAlphaType == src.alphaType() && !needs_color_xform(dst, src, false);
- default:
- return false;
- }
-}
-
#endif // SkCodecPriv_DEFINED