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

Unified Diff: third_party/WebKit/Source/platform/image-encoders/skia/WEBPImageEncoder.cpp

Issue 1937433002: HTML <canvas>: add WEBP lossless encoding support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch for landing. Created 4 years, 8 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 | « third_party/WebKit/LayoutTests/fast/canvas/toDataURL-supportedTypes.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/image-encoders/skia/WEBPImageEncoder.cpp
diff --git a/third_party/WebKit/Source/platform/image-encoders/skia/WEBPImageEncoder.cpp b/third_party/WebKit/Source/platform/image-encoders/skia/WEBPImageEncoder.cpp
index 47711ba6320d5f987c06529ca63780ef472eae30..a6ce021b0f1d4aa5ca5d33eadaea417d3e7c3ba0 100644
--- a/third_party/WebKit/Source/platform/image-encoders/skia/WEBPImageEncoder.cpp
+++ b/third_party/WebKit/Source/platform/image-encoders/skia/WEBPImageEncoder.cpp
@@ -34,8 +34,6 @@
#include "platform/graphics/ImageBuffer.h"
#include "webp/encode.h"
-typedef int (*WebPImporter)(WebPPicture* const, const uint8_t* const data, int rowStride);
-
namespace blink {
static int writeOutput(const uint8_t* data, size_t size, const WebPPicture* const picture)
@@ -44,32 +42,6 @@ static int writeOutput(const uint8_t* data, size_t size, const WebPPicture* cons
return 1;
}
-static bool rgbPictureImport(const unsigned char* pixels, WebPImporter importRGB, WebPPicture* picture)
-{
- // Write the RGB pixels to an rgb data buffer, alpha premultiplied, then import the rgb data.
-
- size_t pixelCount = picture->height * picture->width;
-
- OwnPtr<unsigned char[]> rgb = adoptArrayPtr(new unsigned char[pixelCount * 3]);
- if (!rgb.get())
- return false;
-
- for (unsigned char* data = rgb.get(); pixelCount-- > 0; pixels += 4) {
- unsigned char alpha = pixels[3];
- if (alpha != 255) {
- *data++ = SkMulDiv255Round(pixels[0], alpha);
- *data++ = SkMulDiv255Round(pixels[1], alpha);
- *data++ = SkMulDiv255Round(pixels[2], alpha);
- } else {
- *data++ = pixels[0];
- *data++ = pixels[1];
- *data++ = pixels[2];
- }
- }
-
- return importRGB(picture, rgb.get(), picture->width * 3);
-}
-
static bool encodePixels(const IntSize& imageSize, const unsigned char* pixels, int quality, Vector<unsigned char>* output)
{
if (imageSize.width() <= 0 || imageSize.width() > WEBP_MAX_DIMENSION)
@@ -87,13 +59,23 @@ static bool encodePixels(const IntSize& imageSize, const unsigned char* pixels,
picture.width = imageSize.width();
picture.height = imageSize.height();
- if (!rgbPictureImport(pixels, &WebPPictureImportRGB, &picture))
+ bool useLosslessEncoding = (quality >= 100);
+ if (useLosslessEncoding)
+ picture.use_argb = 1;
+ if (!WebPPictureImportRGBA(&picture, pixels, picture.width * 4))
return false;
picture.custom_ptr = output;
picture.writer = &writeOutput;
- config.quality = quality;
- config.method = 3;
+
+ if (useLosslessEncoding) {
+ config.lossless = 1;
+ config.quality = 75;
Noel Gordon 2016/05/04 01:15:58 Note urvang@: the config.{quality,method} values u
+ config.method = 0;
+ } else {
+ config.quality = quality;
+ config.method = 3;
+ }
bool success = WebPEncode(&config, &picture);
WebPPictureFree(&picture);
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/canvas/toDataURL-supportedTypes.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698