NSBitmapImageRep TIFFRepresentation crashes :(
NSBitmapImageRep TIFFRepresentation crashes :(
- Subject: NSBitmapImageRep TIFFRepresentation crashes :(
- From: daniel oberhoff <email@hidden>
- Date: Tue, 18 Mar 2003 02:42:29 +0100
hi,
its 2:30 and i just dont get it:
i have an NSBitmapImageRep around for buffering a framegrabber. I alloc
its data and fill it using glReadPixels(). when i want its
TIFFRepresentation it crashes. the data is there and the bitmap also. i
alloc it here:
NSRect bounds = [self bounds];
unsigned int w = (unsigned int)bounds.size.width;
unsigned int h = (unsigned int)bounds.size.height;
m_grabcount = 0;
int *grabbuffer = new int[w * h];
NSBitmapImageRep *bitmapimage = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:(unsigned char **)(&grabbuffer) pixelsWide:w
pixelsHigh:w bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:w * 4 bitsPerPixel:32]
retain];
m_grabtimer = [[NSTimer timerWithTimeInterval:0.07 target:self
selector:@selector(grab:) userInfo:bitmapimage repeats:YES] retain];
[[NSRunLoop currentRunLoop] addTimer:m_grabtimer
forMode:NSDefaultRunLoopMode];
[m_grabtimer fire];
and use it here:
-(void) grab:(id)timer {
[[self openGLContext] makeCurrentContext];
NSBitmapImageRep *bitmap = (NSBitmapImageRep *)[timer userInfo];
if (!bitmap) {
NSLog(@"no bitmap for grabbing");
return;
}
else
NSLog(@"bitmap :%@", bitmap);
glReadPixels(0, 0, (GLint) [bitmap pixelsWide], (GLint) [bitmap
pixelsHigh],
GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, [bitmap
bitmapData]);
NSLog(@"read pixels");
NSData *bdata = [bitmap TIFFRepresentation];
if (!bdata) {
NSLog(@"no tiff data!");
return;
}
[bdata retain];
if (![bdata writeToFile:[[NSString
stringWithFormat:@"~/Desktop/grabbed%d.tif", m_grabcount++]
stringByExpandingTildeInPath] atomically:NO]) NSLog(@"failed to write
grabbed");
[bdata release];
}
i dont resize the window so the dimensions should be the same (unless
anynoe can explain me how rounding to the exactly same type, as GLfloat
= float on my system, can give different values...))
the logging output is
2003-03-18 02:35:36.152 object3dtestbed[2841] bitmap :NSBitmapImageRep
0x15b8ae0 Size={504, 504} ColorSpace=NSDeviceRGBColorSpace BPS=8
Pixels=504x504 Alpha=YES
2003-03-18 02:35:36.201 object3dtestbed[2841] read pixels
and the debug trace:
#0 0x90074518 in memmove
#1 0x933693bc in DPSgsave
#2 0x930e58d0 in _NXTIFFWriteScanline
#3 0x9310882c in _NXTIFFWrite
#4 0x931458ac in -[NSBitmapImageRep _writeTIFF:usingCompression:factor:]
#5 0x93243258 in -[NSBitmapImageRep
TIFFRepresentationUsingCompression:factor:]
#6 0x93243344 in -[NSBitmapImageRep TIFFRepresentation]
#7 0x00005640 in -[MyOpenGLView grab:] at MyOpenGLView.mm:189
i noticed that the field _tiffdata of the bitmap is 0x0 in the debug
inspector, but on the other hand thats not that speacial since i expect
it to get constructed on demand....
_______________________________________________
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.