Permalink
Browse files

Merge branch 'master' of github.com:mapnik/mapnik

  • Loading branch information...
2 parents 47e847c + 330504e commit 0cc1dfdf4423ed33c800fd45fbe6f80922416740 @kunitoki kunitoki committed Apr 10, 2012
Showing with 34 additions and 13 deletions.
  1. +1 −1 SConstruct
  2. +33 −12 src/png_reader.cpp
View
@@ -1732,7 +1732,7 @@ if not HELP_REQUESTED:
# devtools not ready for public
#SConscript('utils/ogrindex/build.py')
- #SConscript('utils/svg2png/build.py')
+ SConscript('utils/svg2png/build.py')
env['LIBS'].remove('boost_program_options%s' % env['BOOST_APPEND'])
else :
color_print(1,"WARNING: Cannot find boost_program_options. 'shapeindex' won't be available")
View
@@ -190,22 +190,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<png_byte> row(new png_byte[rowbytes]);
- for (unsigned i=0;i<height_;++i)
+ if (x0 == 0 && y0 == 0 && image.width() >= width_ && image.height() >= height_)
{
- png_read_row(png_ptr,row.get(),0);
- if (i>=y0 && i<h)
+
+ if (png_get_interlace_type(png_ptr,info_ptr) == PNG_INTERLACE_ADAM7)
+ {
+ 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<png_byte*> rows(new png_bytep[height_]);
+ for (unsigned i=0; i<height_; ++i)
+ rows[i] = (png_bytep)image.getRow(i);
+ png_read_image(png_ptr, rows.get());
+ }
+ else
+ {
+ png_read_update_info(png_ptr, info_ptr);
+ 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<png_byte> row(new png_byte[rowbytes]);
+ //START read image rows
+ for (unsigned i=0;i<height_;++i)
{
- image.setRow(i-y0,reinterpret_cast<unsigned*>(&row[x0]),w);
+ png_read_row(png_ptr,row.get(),0);
+ if (i>=y0 && i<h)
+ {
+ image.setRow(i-y0,reinterpret_cast<unsigned*>(&row[x0]),w);
+ }
}
+ //END
}
- //END
+
png_read_end(png_ptr,0);
png_destroy_read_struct(&png_ptr, &info_ptr,0);
fclose(fp);

0 comments on commit 0cc1dfd

Please sign in to comment.