aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec/SkWebpCodec.cpp
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2016-09-08 10:54:34 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-08 10:54:34 -0700
commit85c922acec37726ac64e9be9a79de697c677f35d (patch)
treece407f846cdad8e4cf71c6d0479a1588b45d5cf6 /src/codec/SkWebpCodec.cpp
parent7a9900d6d34e437bb24beb5524a1f6488ae138c9 (diff)
Revert of Checking for valid colorType, alphaType, colorSpace in SkCodec (patchset #2 id:100001 of https://codereview.chromium.org/2319293003/ )
Reason for revert: Broken perf bots Original issue's description: > 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 > > Committed: https://skia.googlesource.com/skia/+/7a9900d6d34e437bb24beb5524a1f6488ae138c9 TBR=scroggo@google.com,brianosman@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review-Url: https://codereview.chromium.org/2328663002
Diffstat (limited to 'src/codec/SkWebpCodec.cpp')
-rw-r--r--src/codec/SkWebpCodec.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index e8b27b2178..0c3aa402bd 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -144,6 +144,25 @@ 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
@@ -193,15 +212,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()));
- SkASSERT(colorXform);
+ }
+
+ if (!webp_conversion_possible(dstInfo, this->getInfo(), colorXform.get())) {
+ return kInvalidConversion;
}
WebPDecoderConfig config;