• 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
NSImage vs. NSBitmapImageRep color differences?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSImage vs. NSBitmapImageRep color differences?


  • Subject: NSImage vs. NSBitmapImageRep color differences?
  • From: Christopher Nagel <email@hidden>
  • Date: Mon, 30 Jun 2003 11:10:59 -0400

I am using an NSImage to create an OpenGL texture but I'm getting color differences depending on how I do it. Using an NSBitmapImageRep yields the correct image, whereas using [NSImage TIFFRepresentation] yields a yellow-hued image. --Yet NSBitmapImageRep is initialized with TIFFRepresentation.

I was trying to avoid the overhead of creating the NSBitmapImageRep, just for kicks.

Can anyone help me understand what's going on behind the scenes here? Could the return signatures of the methods make a difference? -bitmapData returns (unsigned char *) whereas -bytes returns (const void *). Casting -bytes to (unsigned char *) had no effect.

Thanks,
Chris

- (void) loadPicture:(NSString *)name
{
NSImage *image;
NSBitmapImageRep *bitmap;

image = [NSImage imageNamed:name];
if( !image ) {
NSLog( @"couldn't load image named %@", name ) ;
return;
}
// Ensure the image is a GL-compatible size
if( YES ) {
NSSize sz = { 128.0, 128.0 };
[image setScalesWhenResized: YES];
[image setSize:sz];
}
bitmap = [[NSBitmapImageRep alloc] initWithData:[image TIFFRepresentation]];

glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

if( YES ) {
// This comes out perfect
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, [bitmap size].width,
[bitmap size].height, 0, GL_RGB, GL_UNSIGNED_BYTE,
[bitmap bitmapData] );
} else {
// This yields a yellowish image
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, [image size].width,
[image size].height, 0, GL_RGB, GL_UNSIGNED_BYTE,
[[image TIFFRepresentation] bytes] );
}

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

[bitmap release];

return;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSImage vs. NSBitmapImageRep color differences?
      • From: Marcel Weiher <email@hidden>
    • Re: NSImage vs. NSBitmapImageRep color differences?
      • From: Thomas Finley <email@hidden>
  • Prev by Date: NSProgressIdicator Image Problems
  • Next by Date: Re: Calloc for Cocoa?
  • Previous by thread: Re: NSProgressIdicator Image Problems
  • Next by thread: Re: NSImage vs. NSBitmapImageRep color differences?
  • Index(es):
    • Date
    • Thread