diff options
author | 2016-09-08 10:14:04 -0700 | |
---|---|---|
committer | 2016-09-08 10:14:05 -0700 | |
commit | 7a9900d6d34e437bb24beb5524a1f6488ae138c9 (patch) | |
tree | 3b81bb6369d1cb9a6d9bbf2282f730cdf8482bff /src/codec/SkWebpCodec.cpp | |
parent | 971cd496b9e25f87f3a75a0015c203322907136a (diff) |
Checking for valid colorType, alphaType, colorSpace in SkCodec
* Refactor to share code between SkPngCodec and SkWebpCodec
* Didn't end up sharing with SkJpegCodec but did refactor
that code a bit
* Disallow conversions to F16 with non-linear color spaces
* Fail to decode if we fail to create a SkColorSpaceXform
(should be an assert soon). We used to fallback on a
legacy decode if we failed to create the transform.
* A bunch of name changes
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2319293003
Review-Url: https://codereview.chromium.org/2319293003
Diffstat (limited to 'src/codec/SkWebpCodec.cpp')
-rw-r--r-- | src/codec/SkWebpCodec.cpp | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp index 0c3aa402bd..e8b27b2178 100644 --- a/src/codec/SkWebpCodec.cpp +++ b/src/codec/SkWebpCodec.cpp @@ -144,25 +144,6 @@ SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { streamDeleter.release(), demux.release(), std::move(data)); } -static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src, - SkColorSpaceXform* colorXform) { - if (!valid_alpha(dst.alphaType(), src.alphaType())) { - return false; - } - - switch (dst.colorType()) { - case kRGBA_F16_SkColorType: - return nullptr != colorXform; - case kBGRA_8888_SkColorType: - case kRGBA_8888_SkColorType: - return true; - case kRGB_565_SkColorType: - return nullptr == colorXform && src.alphaType() == kOpaque_SkAlphaType; - default: - return false; - } -} - SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const { SkISize dim = this->getInfo().dimensions(); // SkCodec treats zero dimensional images as errors, so the minimum size @@ -212,15 +193,15 @@ bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const { SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, const Options& options, SkPMColor*, int*, int* rowsDecodedPtr) { + if (!conversion_possible(dstInfo, this->getInfo())) { + return kInvalidConversion; + } std::unique_ptr<SkColorSpaceXform> colorXform = nullptr; if (needs_color_xform(dstInfo, this->getInfo())) { colorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()), sk_ref_sp(dstInfo.colorSpace())); - } - - if (!webp_conversion_possible(dstInfo, this->getInfo(), colorXform.get())) { - return kInvalidConversion; + SkASSERT(colorXform); } WebPDecoderConfig config; |