Is this a bug in Tiger's NSBitmapImageRep?
Is this a bug in Tiger's NSBitmapImageRep?
- Subject: Is this a bug in Tiger's NSBitmapImageRep?
- From: Marc Liyanage <email@hidden>
- Date: Tue, 3 May 2005 00:06:55 +0200
I noticed today that a piece of code I wrote for Jaguar/Panther no
longer works right in Tiger. I didn't change anything, and the exact
same code still works flawlessly on Panther.
I am using the method
initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerP
ixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:
to create the NSBitmapImageRep, and then I fetch the bitmap base
address and fill it with data. On Tiger, the resulting image looks
like garbage when displayed or serialized to TIFF. It looks like
there's something wrong with the data length calculations, depending
on the target width the rows are skewed. It seems to work correctly
when the image width in pixels is a multiple of 24 which is the
number of bits per sample times the number of channels.
The test case below produces correct results on Panther, and the
exact same binary run on Tiger will show the problem. For comparison,
the ".raw" file can be opened in Photoshop.
Is this a bug in Tiger or have I been doing something wrong all along
without getting into trouble?
I see there's a new, similar method in Tiger but I'd rather not use
that one because my code needs to run on Jaguar and Panther too.
#import <Cocoa/Cocoa.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int width = 100, height = 100;
int datalength = width * height * 3;
NSBitmapImageRep *imageRep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL pixelsWide:width pixelsHigh:height
bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:0]
autorelease];
char *destbuffer = [imageRep bitmapData];
unsigned char c = 0;
char *p = destbuffer;
while (p < destbuffer + datalength) {
*p++ = c;
*p++ = c;
*p++ = c;
c++;
}
[[NSData dataWithBytes:destbuffer length:datalength]
writeToFile:@"/tmp/out_pixels.raw" atomically:YES];
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(0.0,
0.0)];
[image addRepresentation:imageRep];
[[image TIFFRepresentation] writeToFile:@"/tmp/out_pixels.tiff"
atomically:YES];
[pool release];
return 0;
}
_________________________________________________________________
Marc Liyanage http://www.entropy.ch
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden