NSImage vs. NSBitmapImageRep color differences?
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] initWith
Data:[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.