Re: NSBitmapImageRep problem (I think)
Re: NSBitmapImageRep problem (I think)
- Subject: Re: NSBitmapImageRep problem (I think)
- From: Brian Williams <email@hidden>
- Date: Fri, 19 Apr 2002 23:18:55 -0700 (PDT)
You are right it makes no sense! I was useing a boolean array before but had
trouble with stability so I thought would try the image rep like people had
suggested. I went back to useing an array and it works fine now
Thanks for the help Tom
Brian
--- email@hidden wrote:
>
I'm not sure why you are using an imageRep to store your simple 2D
>
boolean array...
>
>
unless you were planning on making an NSImage out of it later, it makes
>
no sense at all.
>
>
what's wrong with:
>
>
w = frame.size.width;
>
h = frame.size.height;
>
boardData = malloc(w * h);
>
>
Or if you want to save memory, since you're only using 1 bit...
>
>
assert(w&7 == 0); // make sure the width is a multiple of 8...
>
(probably will be for a screen saver)
>
bpsl = w >> 3; // bytes per scanline
>
boardData = malloc(bpsl * h);
>
>
and write a couple of accessors:
>
>
- (BOOL)isSet:(int)x y:(int)y
>
{
>
unsigned char val = boardData[y * bpsl + (x >> 3)];
>
unsigned char mask = 0x80 >> (x & 7);
>
return ((val & mask) != 0);
>
}
>
- (void)set:(int)x y:(int)y val:(BOOL)on
>
{
>
unsigned char *val = boardData + y * bpsl + (x >> 3);
>
unsigned char mask = 0x80 >> (x & 7);
>
if (on)
>
*val |= mask;
>
else
>
*val &= !mask;
>
}
>
>
>
then in dealloc
>
>
free(board);
>
>
On Friday, April 19, 2002, at 04:08 AM, Brian Williams wrote:
=====
Brian Williams
homepage == <
http://chromaticgray.com>
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/
_______________________________________________
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.