Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Flood Fill and NSBitmapImageRep

Flood Fill and NSBitmapImageRep
Thread Tools
TheoCryst
Mac Elite
Join Date: Nov 2005
Location: Seattle, WA, USA
Status: Offline
Reply With Quote
Sep 12, 2007, 04:36 PM
 
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
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Sep 12, 2007, 05:41 PM
 
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'."
     
PBG4 User
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status: Offline
Reply With Quote
Sep 13, 2007, 08:56 AM
 
If you're not married to floodfill techniques I'd suggest you check out Bezier paths.
20" iMac G5! :D AND MacBook 1.83GHz!
Canon Digital Rebel Kit + 75 - 300mm lens. Yum Yum! :D
Check out my OS X Musical Scales program
     
00101001
Mac Enthusiast
Join Date: Jan 2001
Status: Offline
Reply With Quote
Sep 25, 2007, 07:34 PM
 
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.
     
TheoCryst  (op)
Mac Elite
Join Date: Nov 2005
Location: Seattle, WA, USA
Status: Offline
Reply With Quote
Sep 25, 2007, 11:06 PM
 
Originally Posted by 00101001 View Post
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 Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 03:40 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,