• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSBitmapImageRep problem (I think)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: NSBitmapImageRep problem (I think) (From: email@hidden)

  • Prev by Date: Re: NSStepper - How can I tell which arrow has been clicked?
  • Next by Date: NSDistributedNotificationCenter
  • Previous by thread: Re: NSBitmapImageRep problem (I think)
  • Next by thread: Re: NSBitmapImageRep problem (I think)
  • Index(es):
    • Date
    • Thread