X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fgraphics%2Fpng%2Fpngloader.cpp;h=9c2e1ae339213c2f3cc5a2ad5965ecebb759bf33;hb=HEAD;hp=c2691bd5c30522a51843bc7774d4ab8453c6db1e;hpb=69aaca13ae0949acf12056e390cbd1009a8487b2;p=libs%2Fgui.git diff --git a/source/graphics/png/pngloader.cpp b/source/graphics/png/pngloader.cpp index c2691bd..9c2e1ae 100644 --- a/source/graphics/png/pngloader.cpp +++ b/source/graphics/png/pngloader.cpp @@ -1,5 +1,5 @@ -#include #include "pngloader.h" +#include using namespace std; @@ -26,16 +26,17 @@ namespace Graphics { struct PngLoader::Private { - std::string message; - png_struct *png; - png_info *info; + string message; + png_struct *png = nullptr; + png_info *info = nullptr; + int interlace = PNG_INTERLACE_NONE; }; PngLoader::PngLoader(IO::Base &io, unsigned sig_bytes): priv(new Private) { - priv->png = png_create_read_struct(PNG_LIBPNG_VER_STRING, &priv->message, error, 0); + priv->png = png_create_read_struct(PNG_LIBPNG_VER_STRING, &priv->message, error, nullptr); priv->info = png_create_info_struct(priv->png); // These probably won't give any errors @@ -45,22 +46,19 @@ PngLoader::PngLoader(IO::Base &io, unsigned sig_bytes): PngLoader::~PngLoader() { - png_destroy_read_struct(&priv->png, &priv->info, 0); + png_destroy_read_struct(&priv->png, &priv->info, nullptr); delete priv; } -bool PngLoader::detect(const std::string &sig) +bool PngLoader::detect(const string &sig) { return !png_sig_cmp(reinterpret_cast(const_cast(sig.data())), 0, sig.size()); } -void PngLoader::load(Image::Data &data) +void PngLoader::load_headers_(Image::Data &data) { - png_byte **rows = 0; - if(setjmp(png_jmpbuf(priv->png))) { - delete[] rows; throw bad_image_data(priv->message); } @@ -69,8 +67,7 @@ void PngLoader::load(Image::Data &data) png_uint_32 height; int depth; int color; - int interlace; - png_get_IHDR(priv->png, priv->info, &width, &height, &depth, &color, &interlace, 0, 0); + png_get_IHDR(priv->png, priv->info, &width, &height, &depth, &color, &priv->interlace, nullptr, nullptr); unsigned nchans = png_get_channels(priv->png, priv->info); if(depth!=8) @@ -89,30 +86,38 @@ void PngLoader::load(Image::Data &data) case PNG_COLOR_TYPE_RGB_ALPHA: data.fmt = RGBA; break; default: throw unsupported_image_format("unknown color type"); } +} + +void PngLoader::load_pixels_(Image::Data &data) +{ + png_byte **rows = nullptr; - data.data = new char[data.stride*data.height]; + if(setjmp(png_jmpbuf(priv->png))) + { + delete[] rows; + throw bad_image_data(priv->message); + } - if(interlace==PNG_INTERLACE_ADAM7) + if(priv->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.data+data.stride*(data.height-1-y)); + rows[y] = reinterpret_cast(data.pixels+data.stride*(data.height-1-y)); for(unsigned i=0; ipng, rows, 0, data.height); + png_read_rows(priv->png, rows, nullptr, data.height); delete[] rows; - rows = 0; } else { for(unsigned y=0; ypng, reinterpret_cast(data.data+data.stride*(data.height-1-y)), 0); + png_read_row(priv->png, reinterpret_cast(data.pixels+data.stride*(data.height-1-y)), nullptr); } - png_read_end(priv->png, 0); + png_read_end(priv->png, nullptr); } } // namespace Graphics