<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: How to implement a magic wand tool</title>
	<atom:link href="http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/</link>
	<description>personal weblog of a mac geek</description>
	<pubDate>Wed, 20 Aug 2008 14:18:54 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Jay</title>
		<link>http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-33183</link>
		<dc:creator>Jay</dc:creator>
		<pubDate>Thu, 13 Mar 2008 18:15:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-33183</guid>
		<description>Andy, very nice tutorial. It works well with a shape that has only one boundary. What if I have two circles, one inside of other  and a pixel is picked between two circles. In this case, there’ll be 2 paths , one for inside circle and one or outside circle. The algorithm seems only generates the path for outside circle.</description>
		<content:encoded><![CDATA[<p>Andy, very nice tutorial. It works well with a shape that has only one boundary. What if I have two circles, one inside of other  and a pixel is picked between two circles. In this case, there’ll be 2 paths , one for inside circle and one or outside circle. The algorithm seems only generates the path for outside circle.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sds</title>
		<link>http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-30428</link>
		<dc:creator>sds</dc:creator>
		<pubDate>Mon, 11 Feb 2008 14:21:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-30428</guid>
		<description>sdsd</description>
		<content:encoded><![CDATA[<p>sdsd</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Great Cocoa Tutorial on The Magic Wand Tool &#187; Dustin Bachrach Blog</title>
		<link>http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-29547</link>
		<dc:creator>Great Cocoa Tutorial on The Magic Wand Tool &#187; Dustin Bachrach Blog</dc:creator>
		<pubDate>Fri, 01 Feb 2008 01:08:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-29547</guid>
		<description>[...] Cocoa Tutorial on The Magic Wand Tool January 30th, 2008 &#124; Posted in: Tech, Mac, Programming &#124; Save to del.icio.us  Reading through my overflowing RSS feed in NetNewsWire, I came across a relatively old article byAndy Finnell on his blog Safe From Losing Fight. The article, entitled How to implement a magic wand tool, goes into thorough discussion about the algorithm behind the magic wand tool. Andy then goes on to walk you through (with great explanation) all the Cocoa code that gets this to work. I found the article very interesting in two regards. Firstly, I&#8217;ve always been amazed at the Magic Wand tool. It seems so impressive and so complex. Now I finally see how to implement it, and it&#8217;s surprisingly simple in the scheme of things. Secondly, I found Andy&#8217;s approach at the tutorial to be a great model for future tutorials I plan on writing. His work seemed well thought out and well presented. If you ever have wondered how the Photoshop developers made the Magic Wand do its thing or just have a fascination with Cocoa, be sure to check out Andy&#8217;s tutorial. [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Cocoa Tutorial on The Magic Wand Tool January 30th, 2008 | Posted in: Tech, Mac, Programming | Save to del.icio.us  Reading through my overflowing RSS feed in NetNewsWire, I came across a relatively old article byAndy Finnell on his blog Safe From Losing Fight. The article, entitled How to implement a magic wand tool, goes into thorough discussion about the algorithm behind the magic wand tool. Andy then goes on to walk you through (with great explanation) all the Cocoa code that gets this to work. I found the article very interesting in two regards. Firstly, I&#8217;ve always been amazed at the Magic Wand tool. It seems so impressive and so complex. Now I finally see how to implement it, and it&#8217;s surprisingly simple in the scheme of things. Secondly, I found Andy&#8217;s approach at the tutorial to be a great model for future tutorials I plan on writing. His work seemed well thought out and well presented. If you ever have wondered how the Photoshop developers made the Magic Wand do its thing or just have a fascination with Cocoa, be sure to check out Andy&#8217;s tutorial. [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Graham</title>
		<link>http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-24807</link>
		<dc:creator>Graham</dc:creator>
		<pubDate>Wed, 17 Oct 2007 06:11:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-24807</guid>
		<description>Nice job. I was involved in answering a question over at Cocoadev about a replacement for QuickDraw's CalcCMask, and it occurred to several of us that this code is almost exactly what you need. So I had a quick hack around in your source and indeed it does a good job of masking out an image's background if you build the mask inversely - in fact making your demo code do this interactively was trivial and a very good demo! The next step was to think about how to duplicate the "instant alpha" effect used in iWork '08, etc. However in this repect your code is more difficult to adapt, because it builds a hard-edged 1/0 mask - what's needed is a mask that anti-aliases or tails off at the edges. Unfortunately the current organisation of the objects makes it a bit hard to get at those edge cases. So I thought I'd let you know what I was up to to see if the idea interests you - you might feel it's worthwhile investigating making a soft-edged mask for image masking purposes as part of your image editor. For an even more complete implementation of "instant alpha", it would also be necessary to consider some arbitrary set of matching colours rather than based on a single seed pixel and a tolerance - for example all pixels within a given seed rect. I know lots of people are asking for this functionality - but if it doesn't fire your engine maybe I'll pull your code apart and have a shot myself. Looking forward to the next installment!</description>
		<content:encoded><![CDATA[<p>Nice job. I was involved in answering a question over at Cocoadev about a replacement for QuickDraw&#8217;s CalcCMask, and it occurred to several of us that this code is almost exactly what you need. So I had a quick hack around in your source and indeed it does a good job of masking out an image&#8217;s background if you build the mask inversely - in fact making your demo code do this interactively was trivial and a very good demo! The next step was to think about how to duplicate the &#8220;instant alpha&#8221; effect used in iWork &#8216;08, etc. However in this repect your code is more difficult to adapt, because it builds a hard-edged 1/0 mask - what&#8217;s needed is a mask that anti-aliases or tails off at the edges. Unfortunately the current organisation of the objects makes it a bit hard to get at those edge cases. So I thought I&#8217;d let you know what I was up to to see if the idea interests you - you might feel it&#8217;s worthwhile investigating making a soft-edged mask for image masking purposes as part of your image editor. For an even more complete implementation of &#8220;instant alpha&#8221;, it would also be necessary to consider some arbitrary set of matching colours rather than based on a single seed pixel and a tolerance - for example all pixels within a given seed rect. I know lots of people are asking for this functionality - but if it doesn&#8217;t fire your engine maybe I&#8217;ll pull your code apart and have a shot myself. Looking forward to the next installment!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hans</title>
		<link>http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23679</link>
		<dc:creator>hans</dc:creator>
		<pubDate>Wed, 12 Sep 2007 18:50:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23679</guid>
		<description>Someone knows if there is a web-based image editor that has a magic wand tool?</description>
		<content:encoded><![CDATA[<p>Someone knows if there is a web-based image editor that has a magic wand tool?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23195</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 30 Aug 2007 12:35:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23195</guid>
		<description>@Andy:
"I’ve always wondered how the OG Fireworks engineers figured out how all this stuff work. Not all of this stuff isn’t in graphics books."

The vector techniques weren't an issue with everyone's FreeHand background. Getting deep into the raster techniques was a different story. Books helped a bit, but a lot of it was just figured out through experimentation (like brushing). Live effects (especially beveling) took me a while to get working well. And it is still dog slow. I came up with a technique to significantly speed it up but give the same results, but never had time to implement it. :-)</description>
		<content:encoded><![CDATA[<p>@Andy:<br />
&#8220;I’ve always wondered how the OG Fireworks engineers figured out how all this stuff work. Not all of this stuff isn’t in graphics books.&#8221;</p>
<p>The vector techniques weren&#8217;t an issue with everyone&#8217;s FreeHand background. Getting deep into the raster techniques was a different story. Books helped a bit, but a lot of it was just figured out through experimentation (like brushing). Live effects (especially beveling) took me a while to get working well. And it is still dog slow. I came up with a technique to significantly speed it up but give the same results, but never had time to implement it. <img src='http://www.losingfight.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23169</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Wed, 29 Aug 2007 19:47:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23169</guid>
		<description>@Marc:

Yes, I think you're right. I'll go make that clarification now.

Thanks.</description>
		<content:encoded><![CDATA[<p>@Marc:</p>
<p>Yes, I think you&#8217;re right. I&#8217;ll go make that clarification now.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc Driftmeyer</title>
		<link>http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23168</link>
		<dc:creator>Marc Driftmeyer</dc:creator>
		<pubDate>Wed, 29 Aug 2007 18:32:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23168</guid>
		<description>I'd suggest emphasizing and embolden that ``pseudo-code'' reference with a footnote like any reference work would do to explicitly declare to novice developers that this isn't a working model, but your thoughts on how you algorithm to accomplish this would center around.</description>
		<content:encoded><![CDATA[<p>I&#8217;d suggest emphasizing and embolden that &#8220;pseudo-code&#8221; reference with a footnote like any reference work would do to explicitly declare to novice developers that this isn&#8217;t a working model, but your thoughts on how you algorithm to accomplish this would center around.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23158</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Wed, 29 Aug 2007 10:57:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23158</guid>
		<description>@Max:

&lt;blockquote&gt;Actually, it wouldn’t just be exceptionally slow: it wouldn’t halt at all if not for the limited stack size.&lt;/blockquote&gt;

It's &lt;em&gt;pseudo-code&lt;/em&gt;. It would obviously loop back on itself in infinite recursion, and it obviously doesn't check for the bounds of the image. Also, GetColor() and SetPixelOnInMask() are totally fictional, and don't even take an image or mask to pull or set data on. I don't even know if isEqual on NSColor would do something smart.

My point is it is pseudocode, and as such, it left out details that did not highlight how the algorithm works, and that I felt would be obvious to the reader. Futhermore, as I stated in the article, it is merely a logical representation of what needs to be done when implementing a magic wand, not an actual implementation.</description>
		<content:encoded><![CDATA[<p>@Max:</p>
<blockquote><p>Actually, it wouldn’t just be exceptionally slow: it wouldn’t halt at all if not for the limited stack size.</p></blockquote>
<p>It&#8217;s <em>pseudo-code</em>. It would obviously loop back on itself in infinite recursion, and it obviously doesn&#8217;t check for the bounds of the image. Also, GetColor() and SetPixelOnInMask() are totally fictional, and don&#8217;t even take an image or mask to pull or set data on. I don&#8217;t even know if isEqual on NSColor would do something smart.</p>
<p>My point is it is pseudocode, and as such, it left out details that did not highlight how the algorithm works, and that I felt would be obvious to the reader. Futhermore, as I stated in the article, it is merely a logical representation of what needs to be done when implementing a magic wand, not an actual implementation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Max Rabkin</title>
		<link>http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23153</link>
		<dc:creator>Max Rabkin</dc:creator>
		<pubDate>Wed, 29 Aug 2007 08:02:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/#comment-23153</guid>
		<description>"void Select(float x, float y, NSColor* colorToMatch)
{
	NSColor* color = GetColor(x, y);
	if ( [color isEqual:colorToMatch] ) {
		SetPixelOnInMask(x, y);

		Select(x - 1, y, colorToMatch);
		Select(x + 1, y, colorToMatch);
		Select(x, y - 1, colorToMatch);
		Select(x, y + 1, colorToMatch);
	}
}

This algorithm will work as is, except that it would be exceptionally slow and possibly blow the top off of the stack from all the recursion."

Actually, it wouldn't just be exceptionally slow: it wouldn't halt at all if not for the limited stack size. Or Cocoa might give an error when you go off the edge of the image (I don't know how Cocoa handles this).</description>
		<content:encoded><![CDATA[<p>&#8220;void Select(float x, float y, NSColor* colorToMatch)<br />
{<br />
	NSColor* color = GetColor(x, y);<br />
	if ( [color isEqual:colorToMatch] ) {<br />
		SetPixelOnInMask(x, y);</p>
<p>		Select(x - 1, y, colorToMatch);<br />
		Select(x + 1, y, colorToMatch);<br />
		Select(x, y - 1, colorToMatch);<br />
		Select(x, y + 1, colorToMatch);<br />
	}<br />
}</p>
<p>This algorithm will work as is, except that it would be exceptionally slow and possibly blow the top off of the stack from all the recursion.&#8221;</p>
<p>Actually, it wouldn&#8217;t just be exceptionally slow: it wouldn&#8217;t halt at all if not for the limited stack size. Or Cocoa might give an error when you go off the edge of the image (I don&#8217;t know how Cocoa handles this).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.534 seconds -->
