|
|
Flood Fill and NSBitmapImageRep
|
|
|
|
Mac Elite
Join Date: Nov 2005
Location: Seattle, WA, USA
Status:
Offline
|
|
Hey all. As part of my recent Cocoa MS Paint-knockoff project, I have found the need to implement a basic flood fill algorithm to fill an arbitrary shape. Using NSBitmapImageRep and its methods (setColor:atX:y: and colorAtX:y:), I've designed and refined an implementation of the algorithm found here. Unfortunately, due to the overhead of these two methods (particularly colorAtX:y:), the algorithm takes up to three seconds to fill a 640x480 area on my MacBook CD @1.83GHz. Clearly this is desperately in need of modification... but I just don't know what to do next. Any tips would be greatly appreciated.
EDIT: I've also come across this little app, but it's not Universal (built against 10.3, from what I can tell) and the given email address bounces. It's proof that it can be done, at the very least!
|
Any ramblings are entirely my own, and do not represent those of my employers, coworkers, friends, or species
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
You could cache the imps for those methods to get a moderate speedup (presumably you're not going to be running into several distinct color classes), or you could directly manipulate the bits yourself.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status:
Offline
|
|
If you're not married to floodfill techniques I'd suggest you check out Bezier paths.
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Jan 2001
Status:
Offline
|
|
You don't want to be going through a method lookup (or even a cached function pointer) on a pixel by pixel basis *at all*. If you already have an NSBitmapImageRep, you are in good shape... check out the -bitmapData method.
NSBitmapImageRep Class Reference
If you know the width, height, stride, and pixel format, you can index into this array and update pixels by hand. Remember to stride through in a cache-coherent manner for best performance.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Nov 2005
Location: Seattle, WA, USA
Status:
Offline
|
|
Originally Posted by 00101001
You don't want to be going through a method lookup (or even a cached function pointer) on a pixel by pixel basis *at all*. If you already have an NSBitmapImageRep, you are in good shape... check out the -bitmapData method.
Yeah, I was afraid of that. Looks like I have some research to do...
|
Any ramblings are entirely my own, and do not represent those of my employers, coworkers, friends, or species
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|