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
diff --git a/src/images/SkImageDecoder_libgif.cpp b/src/images/SkImageDecoder_libgif.cpp
index 81071c9..fb5d18f 100644
--- a/src/images/SkImageDecoder_libgif.cpp
+++ b/src/images/SkImageDecoder_libgif.cpp
@@ -24,7 +24,7 @@
}
protected:
- virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE;
+ virtual Result onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE;
private:
typedef SkImageDecoder INHERITED;
@@ -152,14 +152,15 @@
return transpIndex;
}
-static bool error_return(const SkBitmap& bm, const char msg[]) {
+static SkImageDecoder::Result error_return(const SkBitmap& bm, const char msg[]) {
if (!c_suppressGIFImageDecoderWarnings) {
SkDebugf("libgif error [%s] bitmap [%d %d] pixels %p colortable %p\n",
msg, bm.width(), bm.height(), bm.getPixels(),
bm.getColorTable());
}
- return false;
+ return SkImageDecoder::kFailure;
}
+
static void gif_warning(const SkBitmap& bm, const char msg[]) {
if (!c_suppressGIFImageDecoderWarnings) {
SkDebugf("libgif warning [%s] bitmap [%d %d] pixels %p colortable %p\n",
@@ -228,7 +229,7 @@
}
}
-bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, Mode mode) {
+SkImageDecoder::Result SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, Mode mode) {
#if GIFLIB_MAJOR < 5
GifFileType* gif = DGifOpen(sk_stream, DecodeCallBackProc);
#else
@@ -322,7 +323,7 @@
kIndex_8_SkColorType, kPremul_SkAlphaType));
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
- return true;
+ return kSuccess;
}
@@ -423,7 +424,7 @@
sampler.sampleInterlaced(scanline, iter.currY());
iter.next();
}
- return true;
+ return kPartialSuccess;
}
sampler.sampleInterlaced(scanline, iter.currY());
iter.next();
@@ -439,7 +440,7 @@
for (; y < outHeight; y++) {
sampler.next(scanline);
}
- return true;
+ return kPartialSuccess;
}
// scanline now contains the raw data. Sample it.
sampler.next(scanline);
@@ -453,7 +454,7 @@
skip_src_rows(gif, scanline, innerWidth, innerHeight - read);
}
sanitize_indexed_bitmap(bm);
- return true;
+ return kSuccess;
} break;
case EXTENSION_RECORD_TYPE:
@@ -498,7 +499,7 @@
} while (recType != TERMINATE_RECORD_TYPE);
sanitize_indexed_bitmap(bm);
- return true;
+ return kSuccess;
}
///////////////////////////////////////////////////////////////////////////////