X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fpng%2Fpngloader.cpp;h=16ad36bbeb4bd3e7e53463d1ab056340e4a7dfe4;hb=2ebdf45974a0a7649b3488f9da4b8cf90a1db584;hp=35e6a971de3981bbd7b3deb501b5359bea3199fb;hpb=dc16f33663ae51be2966aba81848c4d139149f60;p=libs%2Fgui.git diff --git a/source/graphics/png/pngloader.cpp b/source/graphics/png/pngloader.cpp index 35e6a97..16ad36b 100644 --- a/source/graphics/png/pngloader.cpp +++ b/source/graphics/png/pngloader.cpp @@ -31,7 +31,6 @@ struct PngLoader::Private png_info *info; }; -ImageLoader::Register PngLoader::reg; PngLoader::PngLoader(IO::Base &io, unsigned sig_bytes): priv(new Private) @@ -55,17 +54,23 @@ bool PngLoader::detect(const std::string &sig) return !png_sig_cmp(reinterpret_cast(const_cast(sig.data())), 0, sig.size()); } -void PngLoader::load(Image::Data &data) +void PngLoader::load_(Image::Data &data) { + png_byte **rows = 0; + if(setjmp(png_jmpbuf(priv->png))) + { + delete[] rows; throw bad_image_data(priv->message); + } png_read_info(priv->png, priv->info); png_uint_32 width; png_uint_32 height; int depth; int color; - png_get_IHDR(priv->png, priv->info, &width, &height, &depth, &color, 0, 0, 0); + int interlace; + png_get_IHDR(priv->png, priv->info, &width, &height, &depth, &color, &interlace, 0, 0); unsigned nchans = png_get_channels(priv->png, priv->info); if(depth!=8) @@ -85,9 +90,27 @@ void PngLoader::load(Image::Data &data) default: throw unsupported_image_format("unknown color type"); } - data.data = new char[data.stride*data.height]; - for(unsigned y=0; ypng, reinterpret_cast(data.data+data.stride*(data.height-1-y)), 0); + data.pixels = new char[data.stride*data.height]; + + if(interlace==PNG_INTERLACE_ADAM7) + { + // ADAM7 requires all rows to be loaded at once + unsigned n_passes = png_set_interlace_handling(priv->png); + rows = new png_byte *[data.height]; + for(unsigned y=0; y(data.pixels+data.stride*(data.height-1-y)); + + for(unsigned i=0; ipng, rows, 0, data.height); + + delete[] rows; + rows = 0; + } + else + { + for(unsigned y=0; ypng, reinterpret_cast(data.pixels+data.stride*(data.height-1-y)), 0); + } png_read_end(priv->png, 0); }