diff options
-rw-r--r-- | src/images/SkWebpEncoder.cpp | 22 | ||||
-rw-r--r-- | tests/EncodeTest.cpp | 2 |
2 files changed, 14 insertions, 10 deletions
diff --git a/src/images/SkWebpEncoder.cpp b/src/images/SkWebpEncoder.cpp index 276837cb12..38e6773d92 100644 --- a/src/images/SkWebpEncoder.cpp +++ b/src/images/SkWebpEncoder.cpp @@ -167,25 +167,29 @@ bool SkWebpEncoder::Encode(SkWStream* stream, const SkPixmap& pixmap, const Opti return false; } - // The choice of |webp_config.method| currently just match Chrome's defaults. We - // could potentially expose this to the client. + WebPPicture pic; + WebPPictureInit(&pic); + SkAutoTCallVProc<WebPPicture, WebPPictureFree> autoPic(&pic); + pic.width = pixmap.width(); + pic.height = pixmap.height(); + pic.writer = stream_writer; + + // Set compression, method, and pixel format. + // libwebp recommends using BGRA for lossless and YUV for lossy. + // The choices of |webp_config.method| currently just match Chrome's defaults. We + // could potentially expose this decision to the client. if (Compression::kLossy == opts.fCompression) { webp_config.lossless = 0; #ifndef SK_WEBP_ENCODER_USE_DEFAULT_METHOD webp_config.method = 3; #endif + pic.use_argb = 0; } else { webp_config.lossless = 1; webp_config.method = 0; + pic.use_argb = 1; } - WebPPicture pic; - WebPPictureInit(&pic); - SkAutoTCallVProc<WebPPicture, WebPPictureFree> autoPic(&pic); - pic.width = pixmap.width(); - pic.height = pixmap.height(); - pic.writer = stream_writer; - // If there is no need to embed an ICC profile, we write directly to the input stream. // Otherwise, we will first encode to |tmp| and use a mux to add the ICC chunk. libwebp // forces us to have an encoded image before we can add a profile. diff --git a/tests/EncodeTest.cpp b/tests/EncodeTest.cpp index 102b4cd3a6..4d0ade1ac5 100644 --- a/tests/EncodeTest.cpp +++ b/tests/EncodeTest.cpp @@ -255,6 +255,6 @@ DEF_TEST(Encode_WebpOptions, r) { SkImage::MakeFromEncoded(data2)->asLegacyBitmap(&bm2, SkImage::kRO_LegacyBitmapMode); SkImage::MakeFromEncoded(data3)->asLegacyBitmap(&bm3, SkImage::kRO_LegacyBitmapMode); REPORTER_ASSERT(r, almost_equals(bm0, bm1, 0)); - REPORTER_ASSERT(r, almost_equals(bm0, bm2, 6)); + REPORTER_ASSERT(r, almost_equals(bm0, bm2, 90)); REPORTER_ASSERT(r, almost_equals(bm2, bm3, 45)); } |