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

Unified Diff: Source/platform/image-decoders/png/PNGImageDecoder.cpp

Issue 18099004: Improve PNG decode performance: avoid branching in the row write loop (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: template patch. Created 6 years, 7 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: Source/platform/image-decoders/png/PNGImageDecoder.cpp
diff --git a/Source/platform/image-decoders/png/PNGImageDecoder.cpp b/Source/platform/image-decoders/png/PNGImageDecoder.cpp
index bfef5bec810e6ac8eb4a2d883333e4b57956689d..f82a2c64efb3d2216d559590fa0b2fd0b33058c8 100644
--- a/Source/platform/image-decoders/png/PNGImageDecoder.cpp
+++ b/Source/platform/image-decoders/png/PNGImageDecoder.cpp
@@ -491,18 +491,29 @@ void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
// Write the decoded row pixels to the frame buffer.
ImageFrame::PixelData* address = buffer.getAddr(0, y);
- bool nonTrivialAlpha = false;
+ unsigned alphaMask = 255;
int width = size().width();
png_bytep pixel = row;
- for (int x = 0; x < width; ++x, pixel += colorChannels) {
- unsigned alpha = hasAlpha ? pixel[3] : 255;
- buffer.setRGBA(address++, pixel[0], pixel[1], pixel[2], alpha);
- nonTrivialAlpha |= alpha < 255;
+ if (hasAlpha) {
Peter Kasting 2014/05/12 19:36:11 Nit: Consider adding a comment here about how we w
Noel Gordon 2014/05/13 01:56:32 Added a comment.
+ if (buffer.premultiplyAlpha()) {
+ for (int x = 0; x < width; ++x, pixel += 4) {
+ buffer.setRGBA<true>(address++, pixel[0], pixel[1], pixel[2], pixel[3]);
+ alphaMask &= pixel[3];
+ }
+ } else {
+ for (int x = 0; x < width; ++x, pixel += 4) {
+ buffer.setRGBARaw(address++, pixel[0], pixel[1], pixel[2], pixel[3]);
+ alphaMask &= pixel[3];
+ }
+ }
+ } else {
+ for (int x = 0; x < width; ++x, pixel += 3)
+ buffer.setRGBARaw(address++, pixel[0], pixel[1], pixel[2], 255);
}
- if (nonTrivialAlpha && !buffer.hasAlpha())
- buffer.setHasAlpha(nonTrivialAlpha);
+ if (alphaMask != 255 && !buffer.hasAlpha())
+ buffer.setHasAlpha(true);
buffer.setPixelsChanged(true);
}
« Source/platform/image-decoders/ImageFrame.h ('K') | « Source/platform/image-decoders/ImageFrame.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698