Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: src/codec/SkWebpCodec.cpp

Issue 1178013008: Use the upstream version of libwebp, v0.4.3. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixes for SkWebpImageDecoder and SkWebpCodec. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/libwebp.gyp ('k') | src/images/SkImageDecoder_libwebp.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkWebpCodec.cpp
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index b02015c7a7684ca10ae9ce802762c104feab954a..7299d14cc248a2b8546c9de993e9fe2cfd3c1e22 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -18,6 +18,7 @@
// If moving libwebp out of skia source tree, path for webp headers must be
// updated accordingly. Here, we enforce using local copy in webp sub-directory.
#include "webp/decode.h"
+#include "webp/demux.h"
#include "webp/encode.h"
bool SkWebpCodec::IsWebp(SkStream* stream) {
@@ -43,15 +44,31 @@ static bool webp_parse_header(SkStream* stream, SkImageInfo* info) {
return false;
}
- WebPBitstreamFeatures features;
- VP8StatusCode status = WebPGetFeatures(buffer, WEBP_VP8_HEADER_SIZE, &features);
- if (VP8_STATUS_OK != status) {
- return false; // Invalid WebP file.
+ WebPData demuxData = { buffer, WEBP_VP8_HEADER_SIZE };
+ WebPDemuxState demuxState;
+ WebPDemuxer* demuxer = WebPDemuxPartial(&demuxData, &demuxState);
+ if (!demuxer) {
+ return false;
}
+ SkAutoTCallVProc<WebPDemuxer, WebPDemuxDelete> autoDeleter(demuxer);
+ switch (demuxState) {
+ case WEBP_DEMUX_PARSE_ERROR:
+ case WEBP_DEMUX_PARSING_HEADER:
+ return false;
+ default:
+ // Header parsed.
+ break;
+ }
+
+ uint32_t width = WebPDemuxGetI(demuxer, WEBP_FF_CANVAS_WIDTH);
+ uint32_t height = WebPDemuxGetI(demuxer, WEBP_FF_CANVAS_HEIGHT);
+ uint32_t formatFlags = WebPDemuxGetI(demuxer, WEBP_FF_FORMAT_FLAGS);
+ bool hasAlpha = SkToBool(formatFlags & ALPHA_FLAG) ? 1 : 0;
msarett 2015/06/19 12:07:46 Can this be simpler? bool hasAlpha = SkToBool(form
scroggo 2015/06/19 18:59:58 Lol yes. This was copied from SkImageDecoder_libwe
+
// sanity check for image size that's about to be decoded.
{
- const int64_t size = sk_64_mul(features.width, features.height);
+ const int64_t size = sk_64_mul(width, height);
if (!sk_64_isS32(size)) {
return false;
}
@@ -66,9 +83,9 @@ static bool webp_parse_header(SkStream* stream, SkImageInfo* info) {
// Is unpremul the right type? Clients of SkImageGenerator may assume it's the
// best type, when Skia currently cannot draw unpremul (and raster is faster
// with premul).
- *info = SkImageInfo::Make(features.width, features.height, kN32_SkColorType,
- SkToBool(features.has_alpha) ? kUnpremul_SkAlphaType
- : kOpaque_SkAlphaType);
+ *info = SkImageInfo::Make(width, height, kN32_SkColorType,
+ hasAlpha ? kUnpremul_SkAlphaType
+ : kOpaque_SkAlphaType);
}
return true;
}
« no previous file with comments | « gyp/libwebp.gyp ('k') | src/images/SkImageDecoder_libwebp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698