diff --git a/src/png_reader.cpp b/src/png_reader.cpp index 5e82013a2..fd5dc08e0 100644 --- a/src/png_reader.cpp +++ b/src/png_reader.cpp @@ -195,22 +195,43 @@ void png_reader::read(unsigned x0, unsigned y0,image_data_32& image) if (png_get_gAMA(png_ptr, info_ptr, &gamma)) png_set_gamma(png_ptr, 2.2, gamma); - png_read_update_info(png_ptr, info_ptr); - - //START read image rows - unsigned w=std::min(unsigned(image.width()),width_); - unsigned h=std::min(unsigned(image.height()),height_); - unsigned rowbytes=png_get_rowbytes(png_ptr, info_ptr); - boost::scoped_array row(new png_byte[rowbytes]); - for (unsigned i=0;i= width_ && image.height() >= height_) { - png_read_row(png_ptr,row.get(),0); - if (i>=y0 && i(&row[x0]),w); + png_set_interlace_handling(png_ptr); // FIXME: libpng bug? + // according to docs png_read_image + // "..automatically handles interlacing, + // so you don't need to call png_set_interlace_handling()" } + png_read_update_info(png_ptr, info_ptr); + // we can read whole image at once + // alloc row pointers + boost::scoped_array rows(new png_bytep[height_]); + for (unsigned i=0; i row(new png_byte[rowbytes]); + //START read image rows + for (unsigned i=0;i=y0 && i(&row[x0]),w); + } + } + //END + } + png_read_end(png_ptr,0); png_destroy_read_struct(&png_ptr, &info_ptr,0); fclose(fp);