{
if(alpha==kCGImageAlphaLast)
data.fmt = RGBA;
- else if(alpha==kCGImageAlphaNoneSkipLast)
+ else if(alpha==kCGImageAlphaNoneSkipLast || alpha==kCGImageAlphaNoneSkipFirst)
data.fmt = RGBX;
- else if(alpha==kCGImageAlphaNone || alpha==kCGImageAlphaNoneSkipFirst)
+ else if(alpha==kCGImageAlphaNone)
data.fmt = RGB;
else
throw unsupported_image_format("unknown alpha mode");
CGDataProviderRef dp = CGImageGetDataProvider(image);
CFDataRef image_data = CGDataProviderCopyData(dp);
data.data = new char[data.height*data.stride];
- CFDataGetBytes(image_data, CFRangeMake(0, CFDataGetLength(image_data)), reinterpret_cast<UInt8 *>(data.data));
+ unsigned offset = (alpha==kCGImageAlphaNoneSkipFirst);
+ CFRange range = CFRangeMake(offset, CFDataGetLength(image_data)-offset);
+ CFDataGetBytes(image_data, range, reinterpret_cast<UInt8 *>(data.data));
CFRelease(image_data);
CFRelease(image);
-
- if(alpha==kCGImageAlphaNoneSkipFirst)
- {
- const char *src = data.data;
- if(alpha==kCGImageAlphaNoneSkipFirst)
- ++src;
- char *dest = data.data;
- for(unsigned y=0; y<data.height; ++y)
- for(unsigned x=0; x<data.width; ++x)
- {
- for(unsigned i=0; i<3; ++i)
- dest[i] = src[i];
- dest += 3;
- src += 4;
- }
- }
}
catch(...)
{