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:
/**
// 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();
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;
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);
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;
}
///////////////////////////////////////////////////////////////////////////////