• 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: Nir Soffer <email@hidden>
  • Date: Wed, 10 Jan 2007 19:45:50 +0200


On Jan 10, 2007, at 07:43, E. Wing wrote:

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.


See http://developer.apple.com/documentation/MacOSX/Conceptual/ universal_binary/universal_binary_tips/chapter_5_section_25.html

Can somebody tell me what I'm doing wrong? (Also, I noticed that my
pasteboard image is inverted even though I set isFlipped:YES. Is the
only way to fix this to manually invert my raw OpenGL data?) Below is
an excerpt of my code.

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

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

For my app, flipping the pixel rows gives the best results.

// This block of code is called when not rendering to the screen (e.g. printing)
if(![[NSGraphicsContext currentContext] isDrawingToScreen])
{
...
// wrapper around glReadPixels
osg_image->readPixels(0, 0, viewport_width, viewport_height,
GL_RGBA, GL_UNSIGNED_BYTE);
// I probably misunderstood one or some of the values here
NSBitmapImageRep* image_rep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:viewport_width
pixelsHigh:viewport_height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bitmapFormat:0

Try NSAlphaFirstBitmapFormat

   bytesPerRow:viewport_width*4
   bitsPerPixel:32] autorelease];		

// Copy the data into the NSBitmapImageRep so my osg_image can be cleaned up
memcpy([image_rep bitmapData], osg_image->data(),
osg_image->getTotalSizeInBytes());

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



NSImage* ns_image = [[[NSImage alloc] initWithSize:NSMakeSize(viewport_width,viewport_height)] autorelease]; [ns_image addRepresentation:image_rep]; [ns_image setFlipped:YES];

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


See file:///Developer/ADC Reference Library/documentation/Cocoa/ Reference/ApplicationKit/Classes/NSBitmapImageRep_Class/index.html


// Copy to pasteboard
NSPasteboard* pb = [NSPasteboard generalPasteboard];
[pb declareTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil];
[pb setData:[ns_image TIFFRepresentation] forType:NSTIFFPboardType];

// Render to Printer
[ns_image drawAtPoint:NSMakePoint(0.0, 0.0)
fromRect: NSMakeRect(0.0, 0.0, viewport_width, viewport_height)
operation: NSCompositeCopy
fraction: 1.0];
}
_______________________________________________


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


Best Regards,

Nir Soffer

_______________________________________________

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

  • Prev by Date: Re: coredata: relationship between NSManagedObjectModel
  • Next by Date: Parsing PDF Content
  • Previous by thread: 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