Re: Finding out size of NSBitmapImageRep data pointer?
Re: Finding out size of NSBitmapImageRep data pointer?
- Subject: Re: Finding out size of NSBitmapImageRep data pointer?
- From: John Stiles <email@hidden>
- Date: Mon, 19 Jul 2004 18:01:38 -0700
Is "offset" a byte offset?
Remember that if pBits is an unsigned long*, "pBits+1" advances the
pointer by FOUR bytes (the size of an unsigned long). "pBits+offset"
is the same as ((BYTE*)pBits) + (offset * sizeof(unsigned long))
On Jul 19, 2004, at 3:43 PM, Andrew Duncan wrote:
>
In brief: can I get the size of the memory pointed to by an
>
NSBitmapImageRep data pointer?
>
>
In slightly more depth: I create an NSBitmapImageRep, get its data
>
pointer, and fill in the data directly. This works fine in my test app,
>
but in the full app I get a memory exception. Roughly, I'm doing this:
>
>
NSBitmapImageRep* _bitmap =
>
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
>
pixelsWide:_width
>
pixelsHigh:_height
>
bitsPerSample:8
>
samplesPerPixel:3
>
hasAlpha:NO
>
isPlanar:NO
>
colorSpaceName:NSCalibratedRGBColorSpace
>
bytesPerRow:_width * _bitsPerPixel / 8
>
bitsPerPixel:_bitsPerPixel];
>
>
// For the record, _width = 1680, _height = 1050, _bitsPerPixel = 32.
>
>
unsigned long* pBits = [_bitmap bitmapData];
>
>
... calculate pixel data ...
>
>
*((unsigned long*)(pBits + offset)) = newPixel; // Crashes
>
EXC_BAD_ACCESS
>
>
The crash happens with offset just a bit past 1/4 of the way into the
>
image. Of course, I am checking all my bit/byte/word etc. counts to
>
find my off-by-4 error, but it would sure help if I could find out what
>
Cocoa thinks is the size of the bitmap.
>
_______________________________________________
>
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.
_______________________________________________
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.