Chromium Code Reviews| 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); |
| } |