Chromium Code Reviews| Index: Source/core/platform/image-decoders/png/PNGImageDecoder.cpp |
| diff --git a/Source/core/platform/image-decoders/png/PNGImageDecoder.cpp b/Source/core/platform/image-decoders/png/PNGImageDecoder.cpp |
| index 828328b956c2bb0c8d8d8de534228c2abee60223..e2bd53dc124a194128f8673275019c11138bba9b 100644 |
| --- a/Source/core/platform/image-decoders/png/PNGImageDecoder.cpp |
| +++ b/Source/core/platform/image-decoders/png/PNGImageDecoder.cpp |
| @@ -489,18 +489,30 @@ 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(); |
| + // Do not merge the loops below. They are hand rolled for each case for maximal performance. |
| 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 + x, pixel[0], pixel[1], pixel[2], pixel[3]); |
| + alphaMask &= pixel[3]; |
| + } |
| + } else { |
| + for (int x = 0; x < width; ++x, pixel += 4) { |
| + buffer.setRGBARaw(address + x, pixel[0], pixel[1], pixel[2], pixel[3]); |
| + alphaMask &= pixel[3]; |
| + } |
| + } |
| + } else { |
| + for (int x = 0; x < width; ++x, pixel += 3) |
| + buffer.setRGB(address + x, pixel[0], pixel[1], pixel[2]); |
| } |
| - if (nonTrivialAlpha && !buffer.hasAlpha()) |
| - buffer.setHasAlpha(nonTrivialAlpha); |
| + bool hasNonTrivialAlpha = alphaMask != 255; |
| + buffer.setHasAlpha(hasNonTrivialAlpha); |
|
kbalazs_
2013/06/25 13:20:18
Oops, this war wrong, we cannot make !hasAlpha() j
|
| } |
| void PNGImageDecoder::pngComplete() |