• 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: Copying raw RGBA image data to NSBitmapImageRep coming out funny
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copying raw RGBA image data to NSBitmapImageRep coming out funny


  • Subject: Re: Copying raw RGBA image data to NSBitmapImageRep coming out funny
  • From: "E. Wing" <email@hidden>
  • Date: Wed, 10 Jan 2007 15:18:32 -0800

Thanks for the detailed reply. It got me thinking about some things
that I wasn't but should have been.

> My data comes from OpenGL and I essentially use a glReadPixels with
> GL_RGBA and GL_UNSIGNED_BYTE. To make sure it is not a glReadPixels

Why GL_UNSIGNED_BYTE? I use GL_UNSIGNED_INT_8_8_8_8_REV on big
endian, and GL_UNSIGNED_INT_8_8_8_8 on intel.


So I was using GL_UNSIGNED_BYTE because I thought it would always be in big endian (endian-independent) format. Does NSBitmapImageRep not want this, but a platform native endian order?

I am currently running on PowerPC and don't have an Intel to test on.
But at least on PowerPC, the RGB order seems to have been coming out
okay (because blue is not coming out red).

I think you should flip the image. You can use:

- Core Image - CIAffineTransform
- vImage - vImageVerticalReflect_ARGB8888
- Just switch pixels rows yourself

Okay, I have a pixel flipper routine, but I was just expecting more from the NSImage setFlipped: I guess.

Try NSAlphaFirstBitmapFormat
This didn't seem to help. Depending on whether I used
GL_UNSIGNED_BYTE, GL_UNSIGNED_INT_8_8_8_8 or
GL_UNSIGNED_INT_8_8_8_8_REV, the results would range (not in order)
from no better than before, to blue coming out red, to definitely
alpha being in the wrong place (everything colored wrong and strongly
translucent).

But this did get me thinking about trying just RGB instead of RGBA.
Using the following code instead:

 osg_image->readPixels(0, 0, viewport_width, viewport_height, GL_RGB,
GL_UNSIGNED_BYTE);
 image_rep = [[[NSBitmapImageRep alloc]
   initWithBitmapDataPlanes:NULL
   pixelsWide:viewport_width
   pixelsHigh:viewport_height
   bitsPerSample:8
   samplesPerPixel:3
   hasAlpha:NO
   isPlanar:NO
   colorSpaceName:NSCalibratedRGBColorSpace
   bitmapFormat:0
   bytesPerRow:viewport_width*3
   bitsPerPixel:24] autorelease];

This fixed all my funny color problems. But now I'm really curious,
what is it about the alpha and my settings that was causing the
problem? (And what is the fix so I can use alpha?)



You can create the bitmap before you read the pixels, then read the
pixels directly into [image_rep bitmapData].

Yeah, I probably should be doing that. Thanks for pointing that out.

You don't need to create NSImage for the clipboard, just use
[image_rep TIFFRepresentation]

I used the NSImage for the printer rendering. I originally had what you suggested for the pasteboard, but it was coming out upside-down so I moved it to NSImage hoping setFlipped would work (which it didn't).

Thanks,
Eric
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Copying raw RGBA image data to NSBitmapImageRep coming out funny
      • From: Nir Soffer <email@hidden>
References: 
 >Copying raw RGBA image data to NSBitmapImageRep coming out funny (From: "E. Wing" <email@hidden>)
 >Re: Copying raw RGBA image data to NSBitmapImageRep coming out funny (From: Nir Soffer <email@hidden>)

  • Prev by Date: Re: fast bitmap image scaling
  • Next by Date: QTKit quick question
  • Previous by thread: Re: Copying raw RGBA image data to NSBitmapImageRep coming out funny
  • Next by thread: Re: Copying raw RGBA image data to NSBitmapImageRep coming out funny
  • Index(es):
    • Date
    • Thread