]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/png/pngloader.cpp
Allow images to have padding between rows
[libs/gui.git] / source / graphics / png / pngloader.cpp
index 15684b1ea5e57dfd678ef91de6d0db0304384c21..50d58b3e3d9fabef282e1f2bf6574ba228f00998 100644 (file)
@@ -66,10 +66,15 @@ void PngLoader::load(Image::Data &data)
        int depth;
        int color;
        png_get_IHDR(priv->png, priv->info, &width, &height, &depth, &color, 0, 0, 0);
-       data.width = width;
-       data.height = height;
+       unsigned nchans = png_get_channels(priv->png, priv->info);
+
        if(depth!=8)
                throw unsupported_image_format("depth!=8");
+
+       data.width = width;
+       data.height = height;
+       data.stride = data.width*nchans;
+
        switch(color)
        {
        case PNG_COLOR_TYPE_PALETTE:    data.fmt = COLOR_INDEX; break;
@@ -80,14 +85,12 @@ void PngLoader::load(Image::Data &data)
        default: throw unsupported_image_format("unknown color type");
        }
 
-       unsigned nchans = png_get_channels(priv->png, priv->info);
        if(nchans==4 && data.fmt==RGB)
                png_set_strip_alpha(priv->png);
 
-       unsigned rowstride = data.width*nchans;
-       data.data = new char[rowstride*data.height];
+       data.data = new char[data.stride*data.height];
        for(unsigned y=0; y<data.height; ++y)
-               png_read_row(priv->png, reinterpret_cast<png_byte *>(data.data+rowstride*(data.height-1-y)), 0);
+               png_read_row(priv->png, reinterpret_cast<png_byte *>(data.data+data.stride*(data.height-1-y)), 0);
 
        png_read_end(priv->png, 0);
 }