Re: NSBitmapImageRep problem (I think)
Re: NSBitmapImageRep problem (I think)
- Subject: Re: NSBitmapImageRep problem (I think)
- From: Marcel Weiher <email@hidden>
- Date: Fri, 19 Apr 2002 22:18:26 +0200
On Friday, April 19, 2002, at 01:08 Uhr, Brian Williams wrote:
board = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:frame.size.width
pixelsHigh:frame.size.height
bitsPerSample:1
samplesPerPixel:1
1 bit per sample, 1 sample per pixel = 1 bit per pixel.
[snip]
//be sure the bit map is clear
for(i=0; i<frame.size.width*frame.size.height; i++)
boardData[i]=0;
Right here you're assuming 1 byte per pixel. So you're clearing 8 times
the memory allocated to your bitmap, meaning that in addition to
clearing the bitmap data you allocated you're also smashing 7 times that
amount. Also, you're using float multiplication for the limit and not
asking the NSBitmapImageRep.
Use
memset( boardData, 0, [board bytesPerRow] * [board pixelsHigh] );
instead. Also, you will need to take the 1-bitness of your bitmap into
account when setting pixels later on.
That, or use bitsPerSample = 8. However, you should still ask the
NSBitmapImageRep what exactly the values for bytesPerRow are, because
the NSBitmapImageRep is free to allocate more than you requested for
better alignment.
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
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.