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

Unified Diff: blimp/common/compositor/blimp_image_serialization_processor.cc

Issue 1868053002: [Blimp Engine] BlimpImageSerializationProcessor handles kOpaque_SkAlphaType and kUnpremul_SkAlphaTy… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/common/compositor/blimp_image_serialization_processor.cc
diff --git a/blimp/common/compositor/blimp_image_serialization_processor.cc b/blimp/common/compositor/blimp_image_serialization_processor.cc
index 24564e4b144f51e860d2a32384ef6095093d0d4e..62571f42930e83dbb84b2611eefaf400c09d67e2 100644
--- a/blimp/common/compositor/blimp_image_serialization_processor.cc
+++ b/blimp/common/compositor/blimp_image_serialization_processor.cc
@@ -50,9 +50,8 @@ class WebPImageEncoder : public SkPixelSerializer {
picture.height = pixmap.height();
// Import picture from raw pixels.
- DCHECK(pixmap.alphaType() == kPremul_SkAlphaType);
auto pixel_chars = static_cast<const unsigned char*>(pixmap.addr());
- if (!PlatformPictureImport(pixel_chars, &picture))
+ if (!PlatformPictureImport(pixel_chars, &picture, pixmap.alphaType()))
return nullptr;
// Create a buffer for where to store the output data.
@@ -65,6 +64,7 @@ class WebPImageEncoder : public SkPixelSerializer {
// Setup the configuration for the output WebP picture. This is currently
// the same as the default configuration for WebP, but since any change in
// the WebP defaults would invalidate all caches they are hard coded.
+ config.lossless = 0;
config.quality = 75.0; // between 0 (smallest file) and 100 (biggest).
config.method = 4; // quality/speed trade-off (0=fast, 6=slower-better).
@@ -121,18 +121,24 @@ class WebPImageEncoder : public SkPixelSerializer {
}
bool PlatformPictureImport(const unsigned char* pixels,
- WebPPicture* picture) {
- // Need to unpremultiply each pixel, each pixel using 4 bytes (RGBA).
- size_t pixel_count = picture->height * picture->width;
- std::vector<unsigned char> unpremul_pixels(pixel_count * 4);
- UnPremultiply(pixels, unpremul_pixels.data(), pixel_count);
-
+ WebPPicture* picture,
+ SkAlphaType alphaType) {
// Each pixel uses 4 bytes (RGBA) which affects the stride per row.
int row_stride = picture->width * 4;
+ if (alphaType == kPremul_SkAlphaType) {
+ // Need to unpremultiply each pixel, each pixel using 4 bytes (RGBA).
+ size_t pixel_count = picture->height * picture->width;
+ std::vector<unsigned char> unpremul_pixels(pixel_count * 4);
+ UnPremultiply(pixels, unpremul_pixels.data(), pixel_count);
+ if (SK_B32_SHIFT) // Android
+ return WebPPictureImportRGBA(picture, unpremul_pixels.data(),
+ row_stride);
+ return WebPPictureImportBGRA(picture, unpremul_pixels.data(), row_stride);
+ }
if (SK_B32_SHIFT) // Android
- return WebPPictureImportRGBA(picture, unpremul_pixels.data(), row_stride);
- return WebPPictureImportBGRA(picture, unpremul_pixels.data(), row_stride);
+ return WebPPictureImportRGBA(picture, pixels, row_stride);
+ return WebPPictureImportBGRA(picture, pixels, row_stride);
}
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698