On Jan 7, 2009, at 11:31 AM, Daniel Kennett wrote:

To further support this theory, take a look at this NSImage where I mistakenly only flipped half of my data - the garbled half of the image is from data with the wrong endian-ness:

Well, I wrote the code to change the pixel format from BGRA to ARGB.

Running the code:

if ( (**pixMapHandle).pixelFormat == k32BGRAPixelFormat ) {
    NSInteger   x;
    NSInteger   y;
    Ptr         currentRow = (**pixMapHandle).baseAddr;

    for ( y = 0; y < pixels_high; y++ ) {
        Uint32 *currentPixel = (Uint32*)currentRow;

        for ( x = 0; x < pixels_wide; x++ ) {
            Uint8 *components = (Uint8*)currentPixel;
            Uint8 temp;

            temp          = components[3];
            components[3] = components[0];
            components[0] = temp;

            temp          = components[1];
            components[1] = components[2];
            components[2] = temp;

            currentPixel++;
        }

        currentRow += rowBytes;
    }
}

over the pixel data to swap the components around allowed everything to draw correctly.

I have a feeling there is a better way to do this and, if so, I am interested.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to