]> git.tdb.fi Git - libs/gui.git/commitdiff
Allow images to have padding between rows
authorMikko Rasa <tdb@tdb.fi>
Thu, 10 Oct 2013 17:36:14 +0000 (20:36 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 10 Oct 2013 17:55:04 +0000 (20:55 +0300)
source/graphics/devil/devilloader.cpp
source/graphics/image.h
source/graphics/png/pngloader.cpp
source/graphics/quartz/quartzloader.cpp

index cb6a1b6251764a29fd90cc7c0a36c3e509e9a991..131b6ba1dcfbcebbf1bda7d4e50589dd42ca6033 100644 (file)
@@ -126,7 +126,8 @@ void DevilLoader::load(Image::Data &data)
 
        data.width = ilGetInteger(IL_IMAGE_WIDTH);
        data.height = ilGetInteger(IL_IMAGE_HEIGHT);
-       unsigned data_size = data.width*data.height*ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
+       data.stride = data.width*ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
+       unsigned data_size = data.stride*data.height;
        data.data = new char[data_size];
        ILubyte *il_data = ilGetData();
        copy(il_data, il_data+data_size, data.data);
index 6905461a49557ed64df428902e538d85a9d271fc..29fd288c5634ca96a0b26c604b0cb56968ee89a3 100644 (file)
@@ -19,6 +19,7 @@ public:
                PixelFormat fmt;
                unsigned width;
                unsigned height;
+               unsigned stride;
                char *data;
 
                Data();
@@ -36,6 +37,7 @@ public:
        PixelFormat get_format() const { return data.fmt; }
        unsigned get_width() const { return data.width; }
        unsigned get_height() const { return data.height; }
+       unsigned get_stride() const { return data.stride; }
        const void *get_data() const { return data.data; }
 };
 
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);
 }
index 23f7abbed319031ff0e3b23f99b096bf9159174d..a7c610d4ab62094fa88c8969ea8bdb5fe6e76cdf 100644 (file)
@@ -93,6 +93,7 @@ void QuartzLoader::load(Image::Data &data)
        {
                data.width = CGImageGetWidth(image);
                data.height = CGImageGetHeight(image);
+               data.stride = CGImageGetBytesPerRow(image);
 
                CGColorSpaceRef color = CGImageGetColorSpace(image);
                CGColorSpaceModel model = CGColorSpaceGetModel(color);
@@ -109,11 +110,9 @@ void QuartzLoader::load(Image::Data &data)
                else
                        throw unsupported_image_format("unknown colorspace");
 
-               unsigned bytes_per_pixel = (CGImageGetBitsPerPixel(image)+7)/8;
-
                CGDataProviderRef dp = CGImageGetDataProvider(image);
                CFDataRef image_data = CGDataProviderCopyData(dp);
-               data.data = new char[data.width*data.height*bytes_per_pixel];
+               data.data = new char[data.height*data.stride];
                CFDataGetBytes(image_data, CFRangeMake(0, CFDataGetLength(image_data)), reinterpret_cast<UInt8 *>(data.data));
                CFRelease(image_data);