<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Mukund's Blog</title>
	<atom:link href="http://www.mukund.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mukund.org/blog</link>
	<description>My personal blog</description>
	<pubDate>Fri, 12 Sep 2008 17:24:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
	<language>en</language>
			<item>
		<title>Tinyproxy 1.6.4 released</title>
		<link>http://www.mukund.org/blog/2008/09/12/tinyproxy-164-released/</link>
		<comments>http://www.mukund.org/blog/2008/09/12/tinyproxy-164-released/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 17:24:00 +0000</pubDate>
		<dc:creator>muks</dc:creator>
		
		<category><![CDATA[Tinyproxy]]></category>

		<guid isPermaLink="false">https://www.banu.com/blog/?p=14</guid>
		<description><![CDATA[Tinyproxy 1.6.4 was released recently, after a gap of nearly 4 years since the last release. It contains several bug fixes and current users are encouraged to upgrade to it.
For those who haven’t heard of Tinyproxy, it is a light-weight HTTP proxy daemon for POSIX operating systems, written with special consideration for users with low [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://www.banu.com/tinyproxy/">Tinyproxy</a> 1.6.4 was <a href="https://www.banu.com/pipermail/tinyproxy-developers-list/2008-August/000645.html">released recently</a>, after a gap of nearly 4 years since the last release. It contains several bug fixes and current users are encouraged to upgrade to it.</p>
<p>For those who haven’t heard of Tinyproxy, it is a light-weight HTTP proxy daemon for POSIX operating systems, written with special consideration for users with low resources such as embedded applications. It can be modified easily too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mukund.org/blog/2008/09/12/tinyproxy-164-released/feed/</wfw:commentRss>
		</item>
		<item>
		<title>State of Transmission on Windows</title>
		<link>http://www.mukund.org/blog/2008/09/11/state-of-transmission-on-windows/</link>
		<comments>http://www.mukund.org/blog/2008/09/11/state-of-transmission-on-windows/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 06:29:12 +0000</pubDate>
		<dc:creator>muks</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">https://www.banu.com/blog/?p=9</guid>
		<description><![CDATA[I’ve been working on getting Transmission up and running on Windows. After a ton of patching, it now builds and works to an extent under Wine. There are still some bugs in the libevent and I/O code which need to be ironed out. However, I don’t have the mojo to complete it in a hurry. [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been working on getting <a href="http://www.transmissionbt.com/">Transmission</a> up and running on Windows. After a ton of patching, it now builds and <a href="http://people.banu.com/~muks/blogdata/2008/09/11/state-of-transmission-on-windows/transmission-win32.txt">works to an extent</a> under Wine. There are still some bugs in the libevent and I/O code which need to be ironed out. However, I don’t have the mojo to complete it in a hurry. Debugging issues under Windows sucks. And doing things differently for Windows sucks.</p>
<div id="attachment_10" class="wp-caption alignnone" style="width: 310px"><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/trgtk-win32.png"><img class="size-medium wp-image-10" title="WIP screenshot of Transmission GTK UI on Windows" src="https://www.banu.com/blog/wp-content/uploads/2008/10/trgtk-win32-300x177.png" alt="WIP screenshot of Transmission GTK UI on Windows" width="300" height="177" /></a><p class="wp-caption-text">WIP screenshot of Transmission GTK UI on Windows</p></div>
<p>On a related note, it’s easy to build a GCC cross compiler under Linux to build win32 apps. One can build GTK+ apps and make installers for them, all from the comfort and elegance of Linux. However, an up-to-date document of the process and some gotchas to help the programmer would be helpful and I’ll post a link to such a document shortly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mukund.org/blog/2008/09/11/state-of-transmission-on-windows/feed/</wfw:commentRss>
		</item>
		<item>
		<title>New Banu logo</title>
		<link>http://www.mukund.org/blog/2008/07/25/new-banu-logo/</link>
		<comments>http://www.mukund.org/blog/2008/07/25/new-banu-logo/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 05:48:24 +0000</pubDate>
		<dc:creator>muks</dc:creator>
		
		<category><![CDATA[Banu]]></category>

		<guid isPermaLink="false">https://www.banu.com/blog/?p=3</guid>
		<description><![CDATA[
Hylke Bons drew a new logo for Banu yesterday. I had requested him for a cuddly brown bear, and adapting Linus&#8217;s words for Tux, said the bear should look contented and happy, as if it&#8217;s just had a lot of honey  Hylke replied within 2 hours with this logo image which is the sweetest [...]]]></description>
			<content:encoded><![CDATA[<p><em></em></p>
<p><a href="http://bomahy.nl/hylke/blog/">Hylke Bons</a> drew a new logo for Banu yesterday. I had requested him for a cuddly brown bear, and adapting Linus&#8217;s words for Tux, said the bear should look contented and happy, as if it&#8217;s just had a lot of honey <img src='http://www.mukund.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Hylke replied within 2 hours with this logo image which is the sweetest bear I&#8217;ve ever seen. It even seems to be hiding a jar of honey behind it <img src='http://www.mukund.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> It&#8217;s amazing he created it in so little time. Thank you Hylke!</p>
<div id="attachment_6" class="wp-caption alignnone" style="width: 266px"><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/banu-the-bear.png"><img class="size-medium wp-image-6" title="Banu bear hiding honey" src="https://www.banu.com/blog/wp-content/uploads/2008/10/banu-the-bear.png" alt="" width="256" height="256" /></a><p class="wp-caption-text">Banu bear hiding honey</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.mukund.org/blog/2008/07/25/new-banu-logo/feed/</wfw:commentRss>
		</item>
		<item>
		<title>history meme</title>
		<link>http://www.mukund.org/blog/2008/04/16/history-meme/</link>
		<comments>http://www.mukund.org/blog/2008/04/16/history-meme/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 08:42:48 +0000</pubDate>
		<dc:creator>muks</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">https://www.banu.com/blog/?p=21</guid>
		<description><![CDATA[On my workstation, which is one of two machines I use:
[muks@jurassic ~]$ uname -a
Linux jurassic 2.6.24.4-64.fc8 #1 SMP Sat Mar 29 09:15:49 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
[muks@jurassic ~]$ history &#124; awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' &#124; sort -rn &#124; head
326 ls
168 cd
92 git
74 clear
66 joe
30 grep
28 svn
15 ssh
15 cat
13 cp
[muks@jurassic ~]$
I [...]]]></description>
			<content:encoded><![CDATA[<p>On my workstation, which is one of two machines I use:</p>
<pre>[muks@jurassic ~]$ uname -a
Linux jurassic 2.6.24.4-64.fc8 #1 SMP Sat Mar 29 09:15:49 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
[muks@jurassic ~]$ history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
326 ls
168 cd
92 git
74 clear
66 joe
30 grep
28 svn
15 ssh
15 cat
13 cp
[muks@jurassic ~]$</pre>
<p>I seem to use clear a lot!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mukund.org/blog/2008/04/16/history-meme/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What is this code?</title>
		<link>http://www.mukund.org/blog/2007/07/25/what-is-this-code/</link>
		<comments>http://www.mukund.org/blog/2007/07/25/what-is-this-code/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 18:21:14 +0000</pubDate>
		<dc:creator>muks</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">https://www.banu.com/blog/?p=51</guid>
		<description><![CDATA[char*a=" $#,.';:\n\t",*s="\0000\a\t\031\r1\020\021\005",*d="\215\266\333\
S3\032\004\321\232L\32176\233\346;\346\030J~G\200\317\251\373O\001\237h\
\3371C\233\317\211\274\317\371\023\364\235\033\314\377\221\276a\360\371\
\f~\341\342\303\326\361\277\353~O\207\307h\337\365\277\"\034o\304yg\b\
\3146\317\333&#124;\033\355\003\016\033\306\377\3411\264\004\375\0336\202a\
\242~\3061",i,j,r=0,b=0;main(){for(i=0;i&#60;98;i++){for(;;){r&#60;&#60;=1;r&#124;=(*(d+i)
&#62;&#62;(7-b++))&#38;1;for(j=0;j&#60;10;j++) if(*(s+j)==r){putchar(*(a+j));r=0;break;}
if(b&#62;=8){b=0;break;}}}}
Eek! Look at all that terrible code. Anyway, main() implements a well-known algorithm. Can you figure out what it is?
]]></description>
			<content:encoded><![CDATA[<pre>char*a=" $#,.';:\n\t",*s="\0000\a\t\031\r1\020\021\005",*d="\215\266\333\
S3\032\004\321\232L\32176\233\346;\346\030J~G\200\317\251\373O\001\237h\
\3371C\233\317\211\274\317\371\023\364\235\033\314\377\221\276a\360\371\
\f~\341\342\303\326\361\277\353~O\207\307h\337\365\277\"\034o\304yg\b\
\3146\317\333|\033\355\003\016\033\306\377\3411\264\004\375\0336\202a\
\242~\3061",i,j,r=0,b=0;main(){for(i=0;i&lt;98;i++){for(;;){r&lt;&lt;=1;r|=(*(d+i)
&gt;&gt;(7-b++))&amp;1;for(j=0;j&lt;10;j++) if(*(s+j)==r){putchar(*(a+j));r=0;break;}
if(b&gt;=8){b=0;break;}}}}</pre>
<p>Eek! Look at all that terrible code. Anyway, <tt>main()</tt> implements a well-known algorithm. Can you figure out what it is?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mukund.org/blog/2007/07/25/what-is-this-code/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C and modulus</title>
		<link>http://www.mukund.org/blog/2007/04/28/c-and-modulus/</link>
		<comments>http://www.mukund.org/blog/2007/04/28/c-and-modulus/#comments</comments>
		<pubDate>Sat, 28 Apr 2007 12:36:53 +0000</pubDate>
		<dc:creator>muks</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">https://www.banu.com/blog/?p=49</guid>
		<description><![CDATA[It’s because the % operation is implementation defined over negative integers in C. It was originally written by nomis, pippin, and me for a GIMP patch many moons ago, but we decided not to put the patch in. As this code took a while to arrive at, here it is for your pleasure and so [...]]]></description>
			<content:encoded><![CDATA[<p>It’s because the <tt>%</tt> operation is implementation defined over negative integers in C. It was originally written by <a href="http://www.home.unix-ag.org/simon/">nomis</a>, <a href="http://codecave.org/">pippin</a>, and me for a GIMP patch many moons ago, but we decided not to put the patch in. As this code took a while to arrive at, here it is for your pleasure and so that we may never have to rewrite it.</p>
<pre>#define REMAINDER(dividend, divisor)
                   (((dividend) &lt; 0) ?
                    (divisor) - 1 - ((-(dividend) - 1) % (divisor)) :
                    (dividend) % (divisor))</pre>
<p><strong>Update:</strong> The macro assumes a positive <var>divisor</var>. Our divisor was always a constant positive integer literal.</p>
<p><a href="http://blogs.gnome.org/view/mortenw">Morten Welinder</a> found an underflow situation in the code above when INT_MIN is used as the dividend, which may fall in yet another undefined part of the C specification. Basically in the sub-expression <tt>(-(dividend) - 1)</tt>, <tt>-(dividend) == (dividend)</tt> when <tt>dividend == INT_MIN</tt>. And <tt>INT_MIN - 1</tt> will underflow (and wrap-around to <tt>INT_MAX</tt> in the case of most microprocessors’ two’s complement registers), and this behaviour is not defined in C. Although it’ll work fine on most general purpose CPUs, because this is undocumented, there may be issues if <tt>gcc</tt> tries to reduce it at <tt>-O2</tt> if both <var>dividend</var> and <var>divisor</var> are constants. More correct code with Morten’s patch is:</p>
<pre>#define REMAINDER(dividend, divisor)
                   (((dividend) &lt; 0) ?
                    (divisor) - 1 - ((-((dividend) + 1)) % (divisor)) :
                    (dividend) % (divisor))</pre>
<p>It won’t overflow over INT_MAX in this case, as dividend is less than 0 when that sub-expression is used. So now, we have 4 authors. <img src='http://www.mukund.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mukund.org/blog/2007/04/28/c-and-modulus/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Auto-clipping after transformations in GIMP</title>
		<link>http://www.mukund.org/blog/2006/12/23/auto-clipping-after-transformations-in-gimp/</link>
		<comments>http://www.mukund.org/blog/2006/12/23/auto-clipping-after-transformations-in-gimp/#comments</comments>
		<pubDate>Sat, 23 Dec 2006 23:47:30 +0000</pubDate>
		<dc:creator>muks</dc:creator>
		
		<category><![CDATA[GIMP]]></category>

		<category><![CDATA[Graphics]]></category>

		<guid isPermaLink="false">https://www.banu.com/blog/?p=63</guid>
		<description><![CDATA[Following my last post on this subject where only the raw algorithm for finding the largest rectangle was completed, the UI and PDB changes for using this functionality are also done now (and several edge cases were fixed in the process). I’ll commit it once it gets some external testing from some of our esteemed [...]]]></description>
			<content:encoded><![CDATA[<p>Following my <a href="https://www.banu.com/blog/2006/12/16/largest-rectangle-in-a-polygon/">last post</a> on this subject where only the raw algorithm for finding the largest rectangle was completed, the UI and PDB changes for using this functionality are also done now (and several edge cases were fixed in the process). I’ll commit it once it gets some external testing from some of our esteemed customers ;). All affine transformations now present a combo box with clipping modes:</p>
<div id="attachment_64" class="wp-caption alignnone" style="width: 174px"><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/gimp-clipping.png"><img class="size-medium wp-image-64" title="GIMP toolbox" src="https://www.banu.com/blog/wp-content/uploads/2008/10/gimp-clipping-164x300.png" alt="GIMP toolbox" width="164" height="300" /></a><p class="wp-caption-text">GIMP toolbox</p></div>
<p>Here is an example with rotation, using the excellent <a href="http://lists.xcf.berkeley.edu/lists/gimp-developer/2006-December/016831.html">Wilber splash draft</a> by <a href="http://mattahan.deviantart.com/">Paul Davey</a> and <a href="http://jimmac.musichall.cz/">Jimmac</a> (still no window decoration in the screenshots):</p>
<div id="attachment_65" class="wp-caption alignnone" style="width: 268px"><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/wilber-before.png"><img class="size-medium wp-image-65" title="Wilber before" src="https://www.banu.com/blog/wp-content/uploads/2008/10/wilber-before-258x300.png" alt="Wilber before" width="258" height="300" /></a><p class="wp-caption-text">Wilber before</p></div>
<div id="attachment_66" class="wp-caption alignnone" style="width: 268px"><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/wilber-during.png"><img class="size-medium wp-image-66" title="Wilber during" src="https://www.banu.com/blog/wp-content/uploads/2008/10/wilber-during-258x300.png" alt="Wilber during" width="258" height="300" /></a><p class="wp-caption-text">Wilber during</p></div>
<div id="attachment_67" class="wp-caption alignnone" style="width: 268px"><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/wilber-after.png"><img class="size-medium wp-image-67" title="Wilber after" src="https://www.banu.com/blog/wp-content/uploads/2008/10/wilber-after-258x300.png" alt="Wilber after" width="258" height="300" /></a><p class="wp-caption-text">Wilber after</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.mukund.org/blog/2006/12/23/auto-clipping-after-transformations-in-gimp/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Largest rectangle in a polygon</title>
		<link>http://www.mukund.org/blog/2006/12/16/largest-rectangle-in-a-polygon/</link>
		<comments>http://www.mukund.org/blog/2006/12/16/largest-rectangle-in-a-polygon/#comments</comments>
		<pubDate>Sat, 16 Dec 2006 21:17:24 +0000</pubDate>
		<dc:creator>muks</dc:creator>
		
		<category><![CDATA[GIMP]]></category>

		<category><![CDATA[Graphics]]></category>

		<guid isPermaLink="false">https://www.banu.com/blog/?p=56</guid>
		<description><![CDATA[GIMP now has working code to find the largest rectangle in the quadrilateral (aligned with the XY axes) which results after a transform (rotate, perspective, etc.). As an example, when a user rotates an image, she can decide to automatically crop the image to an rectangle aligned with the canvas so that no transparent areas [...]]]></description>
			<content:encoded><![CDATA[<p>GIMP now has working code to find the <a href="http://svenfoo.geekheim.de/index.php/2005-04-24/computational-geometry/">largest rectangle in the quadrilateral</a> (aligned with the XY axes) which results after a transform (rotate, perspective, etc.). As an example, when a user rotates an image, she can decide to automatically crop the image to an rectangle aligned with the canvas so that no transparent areas are introduced (an often used use-case which is used usually often <img src='http://www.mukund.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ). A UI for using this feature will be available soon.</p>
<p>The shapes below are from a GTK+ test program which uses Cairo to draw, but when I took screenshots, the window decoration disappeared (maybe because of desktop effects). The black polygon is the transformed quadrilateral and the green rectangle is the computed result. The function also accepts an aspect ratio to provide a properly sized rectangle.</p>
<p><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/quad1.png"><img class="alignnone size-medium wp-image-57" title="quad1" src="https://www.banu.com/blog/wp-content/uploads/2008/10/quad1-300x300.png" alt="" width="300" height="300" /></a><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/quad2.png"><img class="alignnone size-medium wp-image-58" title="quad2" src="https://www.banu.com/blog/wp-content/uploads/2008/10/quad2-300x300.png" alt="" width="300" height="300" /></a><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/quad3.png"><img class="alignnone size-medium wp-image-59" title="quad3" src="https://www.banu.com/blog/wp-content/uploads/2008/10/quad3-300x300.png" alt="" width="300" height="300" /></a><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/quad4.png"><img class="alignnone size-medium wp-image-60" title="quad4" src="https://www.banu.com/blog/wp-content/uploads/2008/10/quad4-300x300.png" alt="" width="300" height="300" /></a><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/quad5.png"><img class="alignnone size-medium wp-image-61" title="quad5" src="https://www.banu.com/blog/wp-content/uploads/2008/10/quad5-300x300.png" alt="" width="300" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mukund.org/blog/2006/12/16/largest-rectangle-in-a-polygon/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Smooth smoothing :)</title>
		<link>http://www.mukund.org/blog/2006/11/13/smooth-smoothing/</link>
		<comments>http://www.mukund.org/blog/2006/11/13/smooth-smoothing/#comments</comments>
		<pubDate>Mon, 13 Nov 2006 18:57:32 +0000</pubDate>
		<dc:creator>muks</dc:creator>
		
		<category><![CDATA[GIMP]]></category>

		<category><![CDATA[Graphics]]></category>

		<guid isPermaLink="false">https://www.banu.com/blog/?p=41</guid>
		<description><![CDATA[Following up on the last post, we now have smoother loglog smoothing, for the Fractal Explorer plug-in of GIMP. Mmmm. Will be committed after some cleanups of the plug-in code though.
]]></description>
			<content:encoded><![CDATA[<p>Following up on the <a href="https://www.banu.com/blog/2006/11/13/on-finding-bugs/">last post</a>, we now have smoother loglog smoothing, for the <a href="http://docs.gimp.org/en/plug-in-fractalexplorer.html">Fractal Explorer</a> plug-in of <a href="http://www.gimp.org/">GIMP</a>. Mmmm. Will be committed after some cleanups of the plug-in code though.</p>
<div id="attachment_44" class="wp-caption alignnone" style="width: 310px"><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/mandel-nosmooth.png"><img class="size-medium wp-image-44" title="Classic smoothing (or lack of it)" src="https://www.banu.com/blog/wp-content/uploads/2008/10/mandel-nosmooth-300x225.png" alt="Classic smoothing (or lack of it)" width="300" height="225" /></a><p class="wp-caption-text">Classic smoothing (or lack of it)</p></div>
<div id="attachment_45" class="wp-caption alignnone" style="width: 310px"><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/mandel-smooth.png"><img class="size-medium wp-image-45" title="loglog smoothing" src="https://www.banu.com/blog/wp-content/uploads/2008/10/mandel-smooth-300x225.png" alt="loglog smoothing" width="300" height="225" /></a><p class="wp-caption-text">loglog smoothing</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.mukund.org/blog/2006/11/13/smooth-smoothing/feed/</wfw:commentRss>
		</item>
		<item>
		<title>On finding bugs</title>
		<link>http://www.mukund.org/blog/2006/11/13/on-finding-bugs/</link>
		<comments>http://www.mukund.org/blog/2006/11/13/on-finding-bugs/#comments</comments>
		<pubDate>Mon, 13 Nov 2006 14:04:35 +0000</pubDate>
		<dc:creator>muks</dc:creator>
		
		<category><![CDATA[GIMP]]></category>

		<category><![CDATA[Graphics]]></category>

		<guid isPermaLink="false">https://www.banu.com/blog/?p=34</guid>
		<description><![CDATA[I often tell my friends that cooking, unless one’s doing it for recreation, is crazy as one spends way too much time cooking and cleaning up than eating the result. Fixing bugs is something like this, but worse. It’s probably someone else’s code who wrote it back in 1999 and somehow the bug has been [...]]]></description>
			<content:encoded><![CDATA[<p>I often tell my friends that cooking, unless one’s doing it for recreation, is crazy as one spends way too much time cooking and cleaning up than eating the result. Fixing bugs is something like this, but worse. It’s probably someone else’s code who wrote it back in 1999 and somehow the bug has been there all along undiscovered; you know where the bug is; you probably even know how to quick-fix it; but to <em>really</em> fix the bug knowing what you’re doing means having to understand the code. Take a graphics application and you spend more time following the code. You spend a few hours doing that, and then the patch to fix it is 6 lines long, and it’s something very very simple. You put an <tt>if</tt> somewhere to handle a condition.</p>
<p>Last week, the <a href="http://docs.gimp.org/en/plug-in-fractalexplorer.html">Fractal Explorer</a> plug-in of <a href="http://www.gimp.org/">GIMP</a> had a bug like this. The code for handling the <tt>loglog</tt> checkbox was added back in 1999. It has never worked on the complete classic Mandelbrot set (or if it ever did work, that must have been due to a bug in some other product). Looks like nobody used it like that. <a href="http://pages.interlog.com/%7Ekcozens/">Kevin Cozens</a> was porting the plug-in to <a href="http://www.gegl.org/">GEGL</a> when he discovered that it crashed with the loglog setting (<a href="http://bugzilla.gnome.org/show_bug.cgi?id=372671">#372671</a>).</p>
<div id="attachment_35" class="wp-caption alignnone" style="width: 310px"><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/gimp-loglog.png"><img class="size-medium wp-image-35" title="GIMP Fractal Explorer plug-in" src="https://www.banu.com/blog/wp-content/uploads/2008/10/gimp-loglog-300x273.png" alt="GIMP Fractal Explorer plug-in" width="300" height="273" /></a><p class="wp-caption-text">GIMP Fractal Explorer plug-in</p></div>
<p>For a Mandelbrot set, the classic method of rendering the set is to map the escape loop counter (once the modulus has escaped) directly to a colormap. This counter is an integer and the method causes banding due to non-smooth shading. The loglog implementation uses a method by Linas Vepstas to <a href="http://linas.org/art-gallery/escape/escape.html">renormalize the escape loop counter</a> by finding out how far away the integer counter has strayed outside the escape radius. It involves calculating a double log to map <var>z^(2^i)</var> to <var>i</var>, i.e., <tt>log (log (|z|^(2^i))) / log (2)</tt>. The final divide by <tt>log (2)</tt> is so that the outer logarithm is done to the base 2 to reduce the <tt>2^i</tt> to <var>i</var>. For reference, the end-result normalized loop counter is calculated as: <tt>mu = N - log (log  (|Z(N)|)) / log (2)</tt> where <var>N</var> is the integer escape counter.</p>
<p>The problem with this method was that in the “inner lake” of the Mandelbrot set, where for example <var>c</var> can be <tt>0 + 0i</tt>, the loop always exits after a full run with the loop counter at the maximum value, and <tt>|z| &lt; 2.0</tt>. When <tt>|z| &lt; e</tt>, the double log starts returning negative values. When <tt>|z| &lt; 1</tt>, the double log returns <tt>inf</tt>. This is then subtracted from <var>N</var> and the resulting value <var>mu</var> is used to lookup RGB values for the point from the colormap array. This caused the plug-in to crash (when <tt>inf</tt> is used or <var>mu</var> exceeds the length of the colormap array).</p>
<p>So what we did to fix this was check to see if <tt>|z| &lt; e</tt> at the end of the escape loop and clamp <var>mu</var> to <var>N - 1</var> in that case. The result:</p>
<div id="attachment_38" class="wp-caption alignnone" style="width: 310px"><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/mandel-plain.png"><img class="size-medium wp-image-38" title="Classic smoothing (or lack of it)" src="https://www.banu.com/blog/wp-content/uploads/2008/10/mandel-plain-300x225.png" alt="Classic smoothing (or lack of it)" width="300" height="225" /></a><p class="wp-caption-text">Classic smoothing (or lack of it)</p></div>
<div id="attachment_39" class="wp-caption alignnone" style="width: 310px"><a href="https://www.banu.com/blog/wp-content/uploads/2008/10/mandel-loglog.png"><img class="size-medium wp-image-39" title="loglog smoothing" src="https://www.banu.com/blog/wp-content/uploads/2008/10/mandel-loglog-300x225.png" alt="loglog smoothing" width="300" height="225" /></a><p class="wp-caption-text">loglog smoothing</p></div>
<p>Open them in two tabs to see how they differ. Of course, as we still use entries directly from a colormap (after rounding), it isn’t as smooth as we’d really like, but interpolation using the real values should be an exercise for another day. Now fixing the actual bug was a 2-line <tt>if</tt> condition. Imagine hours spent studying the algorithm used, and a 2-line fix (and perhaps this lousy blog post). The plug-in still needs to be fixed as it’s got the code for the fractal algorithms repeated for the actual filter and for the dialog’s preview, which needs to be moved to a common function, and we’d like to implement the really smooth shading as well.</p>
<p>Do you find all this cooking interesting? Do you want to be a GIMP developer? Come and participate by <a href="http://bugzilla.gnome.org/buglist.cgi?product=GIMP&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED">picking an open bug</a> and <a href="http://developer.gimp.org/HACKING">hacking it into submission</a>. Join <tt>#gimp</tt> on <tt>irc.gimp.org</tt> to talk to developers, or the <a href="http://www.gimp.org/mail_lists.html">gimp-developer mailing list</a>. Or you may want to try <tt>#gegl</tt> if you think you’ve got the skills.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mukund.org/blog/2006/11/13/on-finding-bugs/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
