diff options
author | scroggo <scroggo@google.com> | 2014-10-22 12:07:00 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-22 12:07:00 -0700 |
commit | 2a1208017dd676f94a53bbb228197c3978dbdd8a (patch) | |
tree | c19f32da3e4187f459e526f13aab58cc24d8aa7d /src/images/SkImageDecoder_libwebp.cpp | |
parent | 7a2df0c672d05301362b5ad13e01bfc62871200a (diff) |
Qualify the return value of SkImageDecoder::decode
Add a new enum to differentiate between a complete decode and a
partial decode (with the third value being failure). Return this
value from SkImageDecoder::onDecode (in all subclasses, plus
SkImageDecoder_empty) and ::decode.
For convenience, if the enum is treated as a boolean, success and
partial success are both considered true.
Note that the static helper functions (DecodeFile etc) still return
true and false (for one thing, this allows us to continue to use
SkImageDecoder::DecodeMemory as an SkPicture::InstallPixelRefProc in
SkPicture::CreateFromStream).
Also correctly report failure in SkASTCImageDecoder::onDecode when
SkTextureCompressor::DecompressBufferFromFormat fails.
BUG=skia:3037
BUG:b/17419670
Review URL: https://codereview.chromium.org/647023006
Diffstat (limited to 'src/images/SkImageDecoder_libwebp.cpp')
-rw-r--r-- | src/images/SkImageDecoder_libwebp.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp index f32587ddcc..8bf15c92e6 100644 --- a/src/images/SkImageDecoder_libwebp.cpp +++ b/src/images/SkImageDecoder_libwebp.cpp @@ -111,7 +111,7 @@ public: protected: virtual bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) SK_OVERRIDE; virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) SK_OVERRIDE; - virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; + virtual Result onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; private: /** @@ -162,11 +162,22 @@ private: // This guy exists just to aid in debugging, as it allows debuggers to just // set a break-point in one place to see all error exists. -static bool return_false(const SkBitmap& bm, const char msg[]) { +static void print_webp_error(const SkBitmap& bm, const char msg[]) { SkDEBUGF(("libwebp error %s [%d %d]", msg, bm.width(), bm.height())); +} + +static bool return_false(const SkBitmap& bm, const char msg[]) { + print_webp_error(bm, msg); return false; // must always return false } +static SkImageDecoder::Result return_failure(const SkBitmap& bm, const char msg[]) { + print_webp_error(bm, msg); + return SkImageDecoder::kFailure; // must always return kFailure +} + +/////////////////////////////////////////////////////////////////////////////// + static WEBP_CSP_MODE webp_decode_mode(const SkBitmap* decodedBitmap, bool premultiply) { WEBP_CSP_MODE mode = MODE_LAST; const SkColorType ct = decodedBitmap->colorType(); @@ -409,15 +420,15 @@ bool SkWEBPImageDecoder::onDecodeSubset(SkBitmap* decodedBitmap, return true; } -bool SkWEBPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap, - Mode mode) { +SkImageDecoder::Result SkWEBPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap, + Mode mode) { #ifdef TIME_DECODE AutoTimeMillis atm("WEBP Decode"); #endif int origWidth, origHeight, hasAlpha; if (!webp_parse_header(stream, &origWidth, &origHeight, &hasAlpha)) { - return false; + return kFailure; } this->fHasAlpha = hasAlpha; @@ -425,16 +436,16 @@ bool SkWEBPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap, SkScaledBitmapSampler sampler(origWidth, origHeight, sampleSize); if (!setDecodeConfig(decodedBitmap, sampler.scaledWidth(), sampler.scaledHeight())) { - return false; + return kFailure; } // If only bounds are requested, done if (SkImageDecoder::kDecodeBounds_Mode == mode) { - return true; + return kSuccess; } if (!this->allocPixelRef(decodedBitmap, NULL)) { - return return_false(*decodedBitmap, "allocPixelRef"); + return return_failure(*decodedBitmap, "allocPixelRef"); } SkAutoLockPixels alp(*decodedBitmap); @@ -442,11 +453,11 @@ bool SkWEBPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap, WebPDecoderConfig config; if (!webp_get_config_resize(&config, decodedBitmap, origWidth, origHeight, this->shouldPremultiply())) { - return false; + return kFailure; } // Decode the WebP image data stream using WebP incremental decoding. - return webp_idecode(stream, &config); + return webp_idecode(stream, &config) ? kSuccess : kFailure; } /////////////////////////////////////////////////////////////////////////////// |