Re: 1-bit NSBitmapImageRep?
Re: 1-bit NSBitmapImageRep?
- Subject: Re: 1-bit NSBitmapImageRep?
- From: Graham Cox <email@hidden>
- Date: Fri, 18 Apr 2008 10:41:56 +1000
If only life were that simple...
The requirement is to hit-test a stroked or filled path to pixel-
perfect accuracy. Yes there is containsPoint: and that other one in CG
for hit-testing a stroke, but these are blunt instruments when it
comes to all the possible stylistic variations that can be applied to
a path, including shadows, images arranged along the path, text and so
forth. (I use these methods as a first "weed out" of the hit). There
is also no built-in way to test whether a rect intersects the pixels
in a path.
So, each graphic object currently caches an offscreen image of itself
(created lazily when an accurate hit test is needed) and tests the
pixel at the given point (or scans within a given rect) for pixels
that are turned on. This only *needs* to be a 1-bit image, because
either a point hits or it doesn't. But because the pixels themselves
are drawn using Quartz, the offscreen context needs to be writable by
Quartz, which a 1-bit rep isn't, as I have discovered. Thus the
smallest supported bit depth is 8 bits, leading to the eightfold
overkill in terms of memory storage - and given that there can be
thousands of graphic objects this does add up.
Heinrich's suggestion would work, but each time the offscreen cache
needs to be updated (which can be often in an interactive editing
situation) a temporary 8-bit image needs to be made then hand-copied
and thresholded down to the 1-bit version. While this is going to save
the memory in the long run the penalty is likely to be much more
sluggish interaction - the classic trade-off. That said I might try it
and see if the performance is acceptable.
If I'm missing anything obvious, I hope someone will point it out!
------
On 17 Apr 2008, at 10:59 pm, Uli Kusterer wrote:
Am 17.04.2008 um 03:57 schrieb Graham Cox:
Is it possible to create a 1-bit (black and white)
NSBitMapImageRep? If so, what are the magic parameters? If not,
what is the smallest number of bits per pixel supported?
Others have already given you options, but what I'm wondering is
what you need this for? Maybe you could just use an NSBezierPath
instead? That essentially consists of on/off areas just the same,
and can be applied as a clipping path to all sorts of objects. When
you need to draw it, you can still draw it in black or whatever.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden