handle interlacing
git-svn-id: http://skia.googlecode.com/svn/trunk@161 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index b616eee..1d1dd34 100644
--- a/src/images/SkImageDecoder_libpng.cpp
+++ b/src/images/SkImageDecoder_libpng.cpp
@@ -387,15 +387,32 @@
} else {
sc = SkScaledBitmapSampler::kRGBX;
}
-
- SkAutoMalloc storage(origWidth * srcBytesPerPixel);
+ if (!sampler.begin(decodedBitmap, sc, doDither)) {
+ return false;
+ }
const int height = decodedBitmap->height();
- for (int i = 0; i < number_passes; i++) {
- if (!sampler.begin(decodedBitmap, sc, doDither)) {
- return false;
+ if (number_passes > 1) {
+ SkAutoMalloc storage(origWidth * origHeight * srcBytesPerPixel);
+ uint8_t* base = (uint8_t*)storage.get();
+ size_t rb = origWidth * srcBytesPerPixel;
+
+ for (int i = 0; i < number_passes; i++) {
+ uint8_t* row = base;
+ for (png_uint_32 y = 0; y < origHeight; y++) {
+ uint8_t* bmRow = row;
+ png_read_rows(png_ptr, &bmRow, png_bytepp_NULL, 1);
+ row += rb;
+ }
}
-
+ // now sample it
+ base += sampler.srcY0() * rb;
+ for (int y = 0; y < height; y++) {
+ reallyHasAlpha |= sampler.next(base);
+ base += sampler.srcDY() * rb;
+ }
+ } else {
+ SkAutoMalloc storage(origWidth * srcBytesPerPixel);
uint8_t* srcRow = (uint8_t*)storage.get();
skip_src_rows(png_ptr, srcRow, sampler.srcY0());
@@ -407,20 +424,13 @@
skip_src_rows(png_ptr, srcRow, sampler.srcDY() - 1);
}
}
-
+
// skip the rest of the rows (if any)
png_uint_32 read = (height - 1) * sampler.srcDY() +
sampler.srcY0() + 1;
SkASSERT(read <= origHeight);
skip_src_rows(png_ptr, srcRow, origHeight - read);
}
-
- if (hasAlpha && !reallyHasAlpha) {
-#if 0
- SkDEBUGF(("Image doesn't really have alpha [%d %d]\n",
- origWidth, origHeight));
-#endif
- }
}
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */