• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convert GWorldPtr into a NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Convert GWorldPtr into a NSImage
      • From: Michael Vannorsdel <email@hidden>
    • Re: Convert GWorldPtr into a NSImage
      • From: Graham Cox <email@hidden>
References: 
 >Convert GWorldPtr into a NSImage (From: Eric Gorr <email@hidden>)
 >Re: Convert GWorldPtr into a NSImage (From: Graham Cox <email@hidden>)
 >Re: Convert GWorldPtr into a NSImage (From: Eric Gorr <email@hidden>)
 >Re: Convert GWorldPtr into a NSImage (From: Graham Cox <email@hidden>)
 >Re: Convert GWorldPtr into a NSImage (From: Daniel Kennett <email@hidden>)

  • Prev by Date: Custom tracking in a NSTextFieldCell
  • Next by Date: re: Large Core Data memory allocations for small rows
  • Previous by thread: Re: Convert GWorldPtr into a NSImage
  • Next by thread: Re: Convert GWorldPtr into a NSImage
  • Index(es):
    • Date
    • Thread