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);
PixelFormat fmt;
unsigned width;
unsigned height;
+ unsigned stride;
char *data;
Data();
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; }
};
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;
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);
}
{
data.width = CGImageGetWidth(image);
data.height = CGImageGetHeight(image);
+ data.stride = CGImageGetBytesPerRow(image);
CGColorSpaceRef color = CGImageGetColorSpace(image);
CGColorSpaceModel model = CGColorSpaceGetModel(color);
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);