]> git.tdb.fi Git - libs/gui.git/commitdiff
Avoid the unpadding loop with kCGImageAlphaNoneSkipFirst
authorMikko Rasa <tdb@tdb.fi>
Fri, 11 Oct 2013 09:52:43 +0000 (12:52 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 11 Oct 2013 13:54:24 +0000 (16:54 +0300)
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

index 3447f5f0672100e3318214f0392c4db2d4ca5c03..1fc93ad2b3d36252a1e487e40ac82ad04d80c676 100644 (file)
@@ -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<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(...)
        {