aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/images/SkWebpEncoder.cpp
diff options
context:
space:
mode:
authorGravatar Matt Sarett <msarett@google.com>2017-05-16 17:06:52 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-17 02:24:29 +0000
commitd5a16911bb0da6b03daee6e9dd896429c7f8e8a1 (patch)
tree1aae55437f046079641a7519e5702af01d311518 /src/images/SkWebpEncoder.cpp
parent1cdbdda91748d5a3fece595e07de5efb662aaaad (diff)
Add support for webp lossless compression
Bug: 713862 Change-Id: I8dcc6506338f3c54fb14a78620e7daaadadfedde Reviewed-on: https://skia-review.googlesource.com/17073 Reviewed-by: Mike Reed <reed@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com> Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'src/images/SkWebpEncoder.cpp')
-rw-r--r--src/images/SkWebpEncoder.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/images/SkWebpEncoder.cpp b/src/images/SkWebpEncoder.cpp
index 5c26111040..b6c6212314 100644
--- a/src/images/SkWebpEncoder.cpp
+++ b/src/images/SkWebpEncoder.cpp
@@ -124,8 +124,7 @@ static int stream_writer(const uint8_t* data, size_t data_size,
return stream->write(data, data_size) ? 1 : 0;
}
-static bool do_encode(SkWStream* stream, const SkPixmap& pixmap, const SkWebpEncoder::Options& opts)
-{
+bool SkWebpEncoder::Encode(SkWStream* stream, const SkPixmap& pixmap, const Options& opts) {
if (!SkPixmapIsValid(pixmap, opts.fUnpremulBehavior)) {
return false;
}
@@ -168,6 +167,16 @@ static bool do_encode(SkWStream* stream, const SkPixmap& pixmap, const SkWebpEnc
return false;
}
+ // The choice of |webp_config.method| currently just match Chrome's defaults. We
+ // could potentially expose this to the client.
+ if (Compression::kLossy == opts.fCompression) {
+ webp_config.lossless = 0;
+ webp_config.method = 3;
+ } else {
+ webp_config.lossless = 1;
+ webp_config.method = 0;
+ }
+
WebPPicture pic;
WebPPictureInit(&pic);
SkAutoTCallVProc<WebPPicture, WebPPictureFree> autoPic(&pic);
@@ -236,8 +245,4 @@ static bool do_encode(SkWStream* stream, const SkPixmap& pixmap, const SkWebpEnc
return true;
}
-bool SkWebpEncoder::Encode(SkWStream* dst, const SkPixmap& src, const Options& opts) {
- return do_encode(dst, src, opts);
-}
-
#endif