summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/image-decoders/png/PNGImageDecoder.cpp')
-rw-r--r--WebCore/platform/image-decoders/png/PNGImageDecoder.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp b/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
index d14333f..ad79fc8 100644
--- a/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2006 Apple Computer, Inc.
+ * Copyright (C) 2007-2009 Torch Mobile, Inc.
*
* Portions are Copyright (C) 2001 mozilla.org
*
@@ -242,6 +243,9 @@ void PNGImageDecoder::headerAvailable()
longjmp(png->jmpbuf, 1);
return;
}
+#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
+ prepareScaleDataIfNecessary();
+#endif
}
int bitDepth, colorType, interlaceType, compressionType, filterType, channels;
@@ -313,7 +317,14 @@ void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
// Initialize the framebuffer if needed.
RGBA32Buffer& buffer = m_frameBufferCache[0];
if (buffer.status() == RGBA32Buffer::FrameEmpty) {
- if (!buffer.setSize(size().width(), size().height())) {
+#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
+ int width = m_scaled ? m_scaledColumns.size() : size().width();
+ int height = m_scaled ? m_scaledRows.size() : size().height();
+#else
+ int width = size().width();
+ int height = size().height();
+#endif
+ if (!buffer.setSize(width, height)) {
static_cast<PNGImageDecoder*>(png_get_progressive_ptr(reader()->pngPtr()))->decodingFailed();
longjmp(reader()->pngPtr()->jmpbuf, 1);
return;
@@ -358,7 +369,7 @@ void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
* to pass the current row, and the function will combine the
* old row and the new row.
*/
-
+
png_structp png = reader()->pngPtr();
bool hasAlpha = reader()->hasAlpha();
unsigned colorChannels = hasAlpha ? 4 : 3;
@@ -372,8 +383,27 @@ void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
row = rowBuffer;
// Copy the data into our buffer.
+#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
+ if (m_scaled) {
+ int destY = scaledY(rowIndex);
+ if (destY < 0)
+ return;
+ int columns = m_scaledColumns.size();
+ bool sawAlpha = buffer.hasAlpha();
+ for (int x = 0; x < columns; ++x) {
+ png_bytep pixel = row + m_scaledColumns[x] * 4;
+ unsigned alpha = pixel[3];
+ buffer.setRGBA(x, destY, pixel[0], pixel[1], pixel[2], alpha);
+ if (!sawAlpha && alpha < 255) {
+ sawAlpha = true;
+ buffer.setHasAlpha(true);
+ }
+ }
+ return;
+ }
+#endif
int width = size().width();
- bool sawAlpha = false;
+ bool sawAlpha = buffer.hasAlpha();
for (int x = 0; x < width; x++) {
unsigned red = *row++;
unsigned green = *row++;