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

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: Refresh trys. Created 6 years, 6 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 | « Source/platform/image-decoders/ImageFrame.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c62a4e1bb0031f7680529e51ecdb0f57d8d05e87 100644
--- a/Source/platform/image-decoders/png/PNGImageDecoder.cpp
+++ b/Source/platform/image-decoders/png/PNGImageDecoder.cpp
@@ -489,20 +489,33 @@ void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
}
#endif
- // Write the decoded row pixels to the frame buffer.
+ // Write the decoded row pixels to the frame buffer. The repetitive
+ // form of the row write loops is for speed.
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) {
+ if (buffer.premultiplyAlpha()) {
+ for (int x = 0; x < width; ++x, pixel += 4) {
+ buffer.setRGBAPremultiply(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);
}
« no previous file with comments | « Source/platform/image-decoders/ImageFrame.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698