<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alice and Bob in Cryptoland &#187; freeimage</title>
	<atom:link href="http://alicebob.cryptoland.net/tag/freeimage/feed/" rel="self" type="application/rss+xml" />
	<link>http://alicebob.cryptoland.net</link>
	<description></description>
	<lastBuildDate>Mon, 14 Feb 2011 13:29:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The black magic of GDI+</title>
		<link>http://alicebob.cryptoland.net/the-black-magic-of-gdi/</link>
		<comments>http://alicebob.cryptoland.net/the-black-magic-of-gdi/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 06:52:16 +0000</pubDate>
		<dc:creator>Conrado</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cairo]]></category>
		<category><![CDATA[freeimage]]></category>
		<category><![CDATA[gdi]]></category>
		<category><![CDATA[pil]]></category>
		<category><![CDATA[quivi]]></category>

		<guid isPermaLink="false">http://alicebob.cryptoland.net/?p=188</guid>
		<description><![CDATA[One of the things I am most ashamed of on Quivi is its speed when opening large images (which are not uncommon nowadays, specially with digital photos). It&#8217;s embarrassing that the lame Windows Picture and Fax Viewer is lightning fast when opening those images! I&#8217;ve always wondered how the Viewer did that. I&#8217;ve searched about [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I am most ashamed of on <a href="http://quivi.sourceforge.net/">Quivi</a> is its speed when opening large images (which are not uncommon nowadays, specially with digital photos). It&#8217;s embarrassing that the lame Windows Picture and Fax Viewer is lightning fast when opening those images!</p>
<p>I&#8217;ve always wondered how the Viewer did that. I&#8217;ve searched about it in the past but could never find anything about it. Then one of these days I was browsing the <a href="http://en.wikipedia.org/wiki/Windows_Picture_and_Fax_Viewer">Wikipedia page about the Viewer</a> and there I learned that it uses <a href="http://en.wikipedia.org/wiki/GDI%2B#GDI.2B">GDI+</a>.</p>
<p>GDI+ is a C++ library, but it is built upon <a href="http://msdn.microsoft.com/en-us/library/ms533969(VS.85).aspx">a flat C API</a> which I could easily use in Python via <a href="http://docs.python.org/library/ctypes.html">ctypes</a>. Long story short, I was able to modify Quivi to add support for viewing images with GDI+. And the result was amazing!</p>
<p>What about Linux? Well, something &#8220;equivalent&#8221; to GDI+ would be <a href="http://cairographics.org/">Cairo</a>, so I did some tests with it too (luckily, support for it was included in wxPython recently).</p>
<p>Here are the results for the time to load a huge 5704px x 5659px PNG image and rescale it to 1/20 of its size:</p>
<table class="booktabs">
<caption>Time to load and scale a PNG image</caption>
<thead>
<tr>
<th>Library</th>
<th>Time (s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>FreeImage</td>
<td class="table-number">10.38</td>
</tr>
<tr>
<td>PIL</td>
<td class="table-number">9.90</td>
</tr>
<tr>
<td>GDI+</td>
<td class="table-number">2.22</td>
</tr>
<tr>
<td>Cairo (from FreeImage)</td>
<td class="table-number">3.60</td>
</tr>
<tr>
<td>Cairo (direct)</td>
<td class="table-number">3.28</td>
</tr>
</tbody>
</table>
<p>The reason for the two Cairo timings is that it supports reading directly from a PNG file but for e.g. JPG files you need to read the image with another library and to the format Cairo uses. I&#8217;ve used FreeImage to load the image and converted it to a Cairo surface.</p>
<p>Here are the results for the time to load and scaling the same image, but as a JPG:</p>
<table class="booktabs">
<caption>Time to load and scale a JPG image</caption>
<thead>
<tr>
<th>Library</th>
<th>Time (s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>FreeImage</td>
<td class="table-number">6.91</td>
</tr>
<tr>
<td>PIL</td>
<td class="table-number">8.38</td>
</tr>
<tr>
<td>GDI+</td>
<td class="table-number">0.19</td>
</tr>
<tr>
<td>Cairo (from FreeImage)</td>
<td class="table-number">1.43</td>
</tr>
</tbody>
</table>
<p>Scary! How does GDI+ manages to do that? According to <a href="http://en.wikipedia.org/wiki/GDI%2B#GDI.2B">Wikipedia</a> it uses hardware acceleration&#8230; Cairo doesn&#8217;t lag begind considering that the scaling only takes 0.015 (!) but I did notice that even its best quality scaling isn&#8217;t so good in comparison to the others, which is kinda odd.</p>
<p>Anyway, I&#8217;ll try to release a new version of Quivi with GDI+ and Cairo support soon. Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://alicebob.cryptoland.net/the-black-magic-of-gdi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

