Re: Convert GWorldPtr into a NSImage
Re: Convert GWorldPtr into a NSImage
- Subject: Re: Convert GWorldPtr into a NSImage
- From: Eric Gorr <email@hidden>
- Date: Wed, 7 Jan 2009 18:27:04 -0500
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 (email@hidden)
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:
This email sent to email@hidden