From 2c3b218f74aa0ccd544a73feb506a0be56d90abe Mon Sep 17 00:00:00 2001 From: scroggo Date: Fri, 9 Oct 2015 08:40:59 -0700 Subject: Focus SkScaledCodec on BitmapRegionDecoder The primary goal of SkScaledCodec is to replace the current implementation of BitmapRegionDecoder, which depends on modified versions of libjpeg and libpng, with an implementation that uses standard versions of the libaries. Since BitmapRegionDecoder only supports PNG, WEBP and JPEG, limit SkScaledCodec to those classes. We will focus on those three until we complete this primary goal. Then we can continue to make SkScaledCodec work for other formats. Fix some bugs in SkScaledCodec::NewFromStream: - Handle a NULL input stream properly - Ensure that the input stream is deleted as expected on bad data Add tests for these error cases. BUG=skia:4428 Review URL: https://codereview.chromium.org/1389053002 --- src/codec/SkScaledCodec.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/codec') diff --git a/src/codec/SkScaledCodec.cpp b/src/codec/SkScaledCodec.cpp index 65fd93c8c0..fc51613f31 100644 --- a/src/codec/SkScaledCodec.cpp +++ b/src/codec/SkScaledCodec.cpp @@ -12,22 +12,25 @@ SkCodec* SkScaledCodec::NewFromStream(SkStream* stream) { - bool isWebp = SkWebpCodec::IsWebp(stream); - if (!stream->rewind()) { - return nullptr; - } - if (isWebp) { - // Webp codec supports scaling and subsetting natively - return SkWebpCodec::NewFromStream(stream); - } - SkAutoTDelete codec(SkCodec::NewFromStream(stream)); if (nullptr == codec) { return nullptr; } - // wrap in new SkScaledCodec - return new SkScaledCodec(codec.detach()); + switch (codec->getEncodedFormat()) { + case kWEBP_SkEncodedFormat: + // Webp codec supports scaling and subsetting natively + return codec.detach(); + case kPNG_SkEncodedFormat: + case kJPEG_SkEncodedFormat: + // wrap in new SkScaledCodec + return new SkScaledCodec(codec.detach()); + default: + // FIXME: SkScaledCodec is temporarily disabled for other formats + // while focusing on the formats that are supported by + // BitmapRegionDecoder. + return nullptr; + } } SkCodec* SkScaledCodec::NewFromData(SkData* data) { -- cgit v1.2.3