]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/png/pngloader.cpp
Split image loading into headers and pixels
[libs/gui.git] / source / graphics / png / pngloader.cpp
index 16ad36bbeb4bd3e7e53463d1ab056340e4a7dfe4..190d3cf297488e10977884080c5ad847b8645099 100644 (file)
@@ -29,6 +29,7 @@ struct PngLoader::Private
        std::string message;
        png_struct *png;
        png_info *info;
+       int interlace;
 };
 
 
@@ -54,13 +55,10 @@ bool PngLoader::detect(const std::string &sig)
        return !png_sig_cmp(reinterpret_cast<png_byte *>(const_cast<char*>(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, 0, 0);
        unsigned nchans = png_get_channels(priv->png, priv->info);
 
        if(depth!=8)
@@ -89,10 +86,21 @@ 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 = 0;
+
+       if(setjmp(png_jmpbuf(priv->png)))
+       {
+               delete[] rows;
+               throw bad_image_data(priv->message);
+       }
 
        data.pixels = new char[data.stride*data.height];
 
-       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);