From 03f5e11e6bcf9487e396403041f84009ff4eb900 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 11 Oct 2013 12:52:43 +0300 Subject: [PATCH] Avoid the unpadding loop with kCGImageAlphaNoneSkipFirst The data looks like this: X RGB X RGB X RGB X RGB ... Ignoring the first padding byte allows treating it as RGBX. The padding bytes move to different RGB triplets, but they're going to get ignored anyway. --- source/graphics/quartz/quartzloader.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/source/graphics/quartz/quartzloader.cpp b/source/graphics/quartz/quartzloader.cpp index 3447f5f..1fc93ad 100644 --- a/source/graphics/quartz/quartzloader.cpp +++ b/source/graphics/quartz/quartzloader.cpp @@ -104,9 +104,9 @@ void QuartzLoader::load(Image::Data &data) { 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"); @@ -117,26 +117,12 @@ void QuartzLoader::load(Image::Data &data) 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(data.data)); + unsigned offset = (alpha==kCGImageAlphaNoneSkipFirst); + CFRange range = CFRangeMake(offset, CFDataGetLength(image_data)-offset); + CFDataGetBytes(image_data, range, reinterpret_cast(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