<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>re: 4.2.1 seems to be fooked with font grabbing</title>
		<link>http://www.allegro.cc/forums/view/590554</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 15 Mar 2007 14:29:47 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello,<br />Apologies for the rather long delay in <a href="http://www.allegro.cc/forums/thread/589885">http://www.allegro.cc/forums/thread/589885</a></p><p>Evert/anyone else,<br />I&#39;ve recompiled and tested the patch supplied in the above thread and it makes no difference at all sadly.</p><p>Just to recap: run grab_font_from_bitmap on a 32bpp video bitmap and you get a rather long delay.</p><p>6 bitmap files of average size 350x150 pixels and 32bpp</p><p>as memory bitmaps: sub second<br />as video bitmaps but at 16bpp: 2 seconds in total<br />as system bitmap: 50 seconds per bitmap, 5 minutes in total<br />as video bitmaps: 3 minutes per bitmap, 18 minutes in total</p><p>I know grabbing from video bitmaps is a bit daft, but it&#39;s fine with 16bpp, only 32bpp is bad, which it wasn&#39;t before the change to check for aliased or transparent fonts.</p><p>But to put it in context I can start off the program to process 6 small bitmaps, put on my trainers, run a round trip of two miles, have a quick shower, grab a beer from the fridge and sit down before it finishes, despite the cpu being able to process 2.5 billion instructions a second and the graphics card being able to draw 25 million triangles a second.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Thu, 15 Mar 2007 03:59:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I just tried grabbing a 961 x 409 bitmap, and it finishes in an instant. So I tried grabbing it 100 times, and it takes a few seconds only. This is with the SVN version of 4.2 and a memory bitmap.</p><p>I&#39;m too lazy to look at the code, but oprofile says this:
</p><div class="source-code snippet"><div class="inner"><pre><span class="n">27767</span>    <span class="n">35</span>.<span class="n">3783</span>  _linear_getpixel32
<span class="n">11718</span>    <span class="n">14</span>.<span class="n">9301</span>  <a href="http://www.allegro.cc/manual/getpixel" target="_blank"><span class="a">getpixel</span></a>
<span class="n">11398</span>    <span class="n">14</span>.<span class="n">5223</span>  font_find_character
<span class="n">9569</span>     <span class="n">12</span>.<span class="n">1920</span>  <a href="http://www.allegro.cc/manual/bmp_read_line" target="_blank"><span class="a">bmp_read_line</span></a>
<span class="n">8599</span>     <span class="n">10</span>.<span class="n">9561</span>  <a href="http://www.allegro.cc/manual/bmp_unwrite_line" target="_blank"><span class="a">bmp_unwrite_line</span></a>
</pre></div></div><p>
and the callgraph for getpixel:
</p><div class="source-code snippet"><div class="inner"><pre>  <span class="n">9</span>         <span class="n">0</span>.<span class="n">0142</span>  _bitmap_has_alpha
  <span class="n">15</span>        <span class="n">0</span>.<span class="n">0237</span>  <a href="http://www.allegro.cc/manual/grab_font_from_bitmap" target="_blank"><span class="a">grab_font_from_bitmap</span></a>
  <span class="n">415</span>       <span class="n">0</span>.<span class="n">6569</span>  bitmap_font_ismono
  <span class="n">1242</span>      <span class="n">1</span>.<span class="n">9661</span>  import_bitmap_font_color
  <span class="n">1685</span>      <span class="n">2</span>.<span class="n">6673</span>  bitmap_font_count
  <span class="n">59806</span>    <span class="n">94</span>.<span class="n">6717</span>  font_find_character
<span class="n">11718</span>    <span class="n">14</span>.<span class="n">9301</span>  <a href="http://www.allegro.cc/manual/getpixel" target="_blank"><span class="a">getpixel</span></a>
  <span class="n">45754</span>    <span class="n">72</span>.<span class="n">4426</span>  _linear_getpixel32
  <span class="n">11718</span>    <span class="n">18</span>.<span class="n">5532</span>  <a href="http://www.allegro.cc/manual/getpixel" target="_blank"><span class="a">getpixel</span></a> <span class="k2">[</span>self<span class="k2">]</span>
  <span class="n">2911</span>      <span class="n">4</span>.<span class="n">6090</span>  <a href="http://www.allegro.cc/manual/bmp_unwrite_line" target="_blank"><span class="a">bmp_unwrite_line</span></a>
  <span class="n">2776</span>      <span class="n">4</span>.<span class="n">3953</span>  <a href="http://www.allegro.cc/manual/bmp_read_line" target="_blank"><span class="a">bmp_read_line</span></a>
</pre></div></div><p>

So the blame seems to be in font_find_character.. but anyway, it seems to be really fast here. Can you try the SVN version? (Else I&#39;ll try it here with an older version and see if it gets slower.) And did you post some minimal test code and the bitmap you are using? Maybe something specific is triggering the problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 15 Mar 2007 04:35:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
This is with the SVN version of 4.2 and a memory bitmap.
</p></div></div><p>It is only slow with 32bpp system or video bitmaps, memory bitmaps are fine.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
And did you post some minimal test code
</p></div></div><p>	<span class="source-code"><a href="http://www.allegro.cc/manual/FONT" target="_blank"><span class="a">FONT</span></a><span class="k3">*</span> MainFont<span class="k3">=</span><a href="http://www.allegro.cc/manual/grab_font_from_bitmap" target="_blank"><span class="a">grab_font_from_bitmap</span></a><span class="k2">(</span>FontMainBmp<span class="k2">)</span><span class="k2">;</span></span></p><p>Is that small enough <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>I can post a sample, but really it&#39;s simply you start a standard allegro program with 32bpp depth, create a video bitmap and populate it with a bitmap font - the attached font is only 8bpp but is converted to 32bpp when you read it into the created video bitmap.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Maybe something specific is triggering the problem.
</p></div></div><p>I don&#39;t know what else to say really, the fault is at grab_font_from_bitmap on a 32bpp bitmap. The fault seems to be the new bit of code to handle alpha-channels. I can try and work out how to profile it if you want, but I&#39;ve never compiled against the profiler before...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Thu, 15 Mar 2007 05:09:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh, had not seen that it&#39;s fine with memory bitmaps. Hm, I&#39;d say, getpixel is known to be slow on video/system bitmaps, without locking. So maybe a single call to _bitmap_has_alpha is enough for the slowdown. Do you notice a difference if you put acquire_bitmap/release_bitmap around grab_font_from_bitmap?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 15 Mar 2007 05:17:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I thought you were only supposed to lock non-video bitmaps?</p><p>How do you use the profiling information? I compiled with -pg, got my gmon.out file and ran &#39;gprof game.exe &gt; log.txt&#39;. It generated shed loads of stuff but there wasn&#39;t  a single entry for &#39;grab_font_from_bitmap&#39;, the function it was called from - setupgame() - was there but I couldn&#39;t find anything useful.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
getpixel is known to be slow on video/system bitmaps, without locking.
</p></div></div><p>I know, but 18 minutes is rather taking the piss isn&#39;t it? I say dump the alpha channel check (or whatever it is that was added to the grab funciton) and/or add it as an optional parameter to do the transparency check, or even add a &#39;grab_font_from_bitmap_ex()&#39; function?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Thu, 15 Mar 2007 05:41:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;ve recompiled and tested the patch supplied in the above thread and it makes no difference at all sadly.
</p></div></div><p>
Forgive me for being pedantic, but did you make sure that it&#39;s actually using the patched version?<br />I don&#39;t remember if I commited the patch yet, but it should be anyway (since the check for the alpha channel should really only be done once).<br />Also, do note: the new version that checks for alpha channels is always going to be slower than the version that didn&#39;t care about them anyway. However, it doesn&#39;t need to be as slow as stock 4.2.1.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I know grabbing from video bitmaps is a bit daft, but it&#39;s fine with 16bpp, only 32bpp is bad, which it wasn&#39;t before the change to check for aliased or transparent fonts.
</p></div></div><p>
That&#39;s because the code has to check every pixel in the bitmap to determine wether there&#39;s an alpha channel or not in 32bpp mode. Again, are you absolutely sure that it&#39;s only checking for the alpha channel once?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I can post a sample, but really it&#39;s simply you start a standard allegro program with 32bpp depth, create a video bitmap and populate it with a bitmap font
</p></div></div><p>
Do. And provide the sample font bitmap. I don&#39;t care if it&#39;s simple, I&#39;m not going to bother writing the test program to test this with as well as do the test, especially if you already have the test program and especially if I have to do it in Windows (doesn&#39;t make sense to do the check in X11 anyway).<br />I may have a little time this evening or on saturday to boot into Windows and try it, though I don&#39;t think I have anything installed at the moment.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
the graphics card being able to draw 25 million triangles a second.
</p></div></div><p>
Yeah, but can it <i>read</i> from the same surface area at that rate (and no, it can&#39;t). Actually, drawing with an alpha channel enabled shouldn&#39;t be done with Allegro&#39;s video bitmaps anyway, since that requires a read operation.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I thought you were only supposed to lock non-video bitmaps?
</p></div></div><p>
The oposite. You need to lock <s>memory</s> video bitmaps if you&#39;re doing <b>non accelerated</b> operations on them.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I say dump the alpha channel check (or whatever it is that was added to the grab funciton) and/or add it as an optional parameter to do the transparency check, or even add a &#39;grab_font_from_bitmap_ex()&#39; function?
</p></div></div><p>
No. It just adds more complexity to the API and more functions that need to go into the compatibility layer, just to play nice with something that you should not be doing in the first place.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 15 Mar 2007 13:47:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Forgive me for being pedantic, but did you make sure that it&#39;s actually using the patched version?
</p></div></div><p>Yes, I patched it myself and created new dll&#39;s and ensured they were being used by writing a log file at allegro startup.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Do. And provide the sample font bitmap. I don&#39;t care if it&#39;s simple
</p></div></div><p>ok, font is already attached above. I&#39;ll knock out some simple code later.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
The oposite. You need to lock memory bitmaps
</p></div></div><p>Reading the manual there seems to be two cases when you don&#39;t use acquire_bitmap: 1) video to video operations, 2) when your target bitmap for writing is a memory bitmap regardless of anything else. Anything else you should? My example of grab font from bitmap is video to video so locking shouldn&#39;t be used.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Thu, 15 Mar 2007 14:10:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>See my edit above, I sometimes write faster than I think.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Reading the manual there seems to be two cases when you don&#39;t use acquire_bitmap: 1) video to video operations, 2) when your target bitmap for writing is a memory bitmap regardless of anything else. Anything else you should?
</p></div></div><p>
You don&#39;t use acquire_bitmap on accelerated video operations. That includes accelerated video-&gt;video blits. acquire_bitmap() doesn&#39;t do anything on memory bitmaps.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
My example of grab font from bitmap is video to video so locking shouldn&#39;t be used.
</p></div></div><p>
The blit operation is, the alpha channel check uses getpixel(), which isn&#39;t.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 15 Mar 2007 14:29:47 +0000</pubDate>
	</item>
</rss>
