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

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: Merge to ToT 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
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..b6855cdd3e97956e337a0c79aa1f781ccd638b57 100644
--- a/third_party/WebKit/Source/platform/image-encoders/skia/WEBPImageEncoder.cpp
+++ b/third_party/WebKit/Source/platform/image-encoders/skia/WEBPImageEncoder.cpp
@@ -34,40 +34,11 @@
#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)
{
- static_cast<Vector<unsigned char>*>(picture->custom_ptr)->append(data, size);
- 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);
+ return static_cast<Vector<unsigned char>*>(picture->custom_ptr)->append(data, size), 1;
urvang 2016/05/03 17:28:19 My first impression was "What sorcery is this?" :P
Noel Gordon 2016/05/04 01:10:30 :P done.
}
static bool encodePixels(const IntSize& imageSize, const unsigned char* pixels, int quality, Vector<unsigned char>* output)
@@ -87,13 +58,22 @@ static bool encodePixels(const IntSize& imageSize, const unsigned char* pixels,
picture.width = imageSize.width();
picture.height = imageSize.height();
- if (!rgbPictureImport(pixels, &WebPPictureImportRGB, &picture))
+ if (quality >= 100)
urvang 2016/05/03 17:28:19 Create and use a variable "bool use_lossless_encod
Noel Gordon 2016/05/04 01:10:30 Done: 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 (quality >= 100) {
+ config.lossless = 1;
+ config.quality = 75;
+ config.method = 0;
+ } else {
+ config.quality = quality;
+ config.method = 3;
+ }
bool success = WebPEncode(&config, &picture);
WebPPictureFree(&picture);

Powered by Google App Engine
This is Rietveld 408576698