<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>sizeof() for BITMAP data</title>
		<link>http://www.allegro.cc/forums/view/589600</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 18 Jan 2007 18:05:19 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How should I get the total size of the memory occupied by the BITMAP pixels themselves? Can I do it with one call to sizeof(), or should I do something like this:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">sizeof</span><span class="k2">(</span><span class="c">/*pixel size*/</span><span class="k2">)</span><span class="k3">*</span>WIDTH<span class="k3">*</span>HEIGHT<span class="k2">;</span>
</pre></div></div><p>

Anyway, thanks in advance!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kikaru)</author>
		<pubDate>Wed, 17 Jan 2007 07:44:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>sizeof(pixel_type)*bmp-&gt;w*bmp-&gt;h sounds good to me.  </p><p>If you want something different, you could try <br />bmp-&gt;h * abs((int)(bmp-&gt;line[1] - bmp-&gt;line[0])), assuming that your bitmap has a height of at least 2.  </p><p>Of course, there&#39;s also the memory for the BITMAP struct itself, and conceivably for other metadata for some BITMAPs on some platforms.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (orz)</author>
		<pubDate>Wed, 17 Jan 2007 08:05:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can use BYTES_PER_PIXEL(bpp) from aintern.h.  But you&#39;d have trouble getting  an <i>exact</i> value as there could be padding between lines.  We currently don&#39;t do that for memory bitmaps, although there is a single byte of padding at the end for 24-bit bitmaps.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Wed, 17 Jan 2007 08:37:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is to copy, using memcpy() to transfer one BITMAP to another, when both are the same size. It should be really fast. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kikaru)</author>
		<pubDate>Wed, 17 Jan 2007 21:11:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I would recommend that you only use that approach on ordinary memory bitmaps, never sub-bitmaps, video bitmaps, system bitmaps, etc.  Also, on further thought, my recommended method for determining the size for that purpose is:<br />((int)(bmp-&gt;line[bmp-&gt;h-1] - bmp-&gt;line[0]) + bmp-&gt;w * sizeof(/*pixel size*/))</p><p>Really, I&#39;d suggest just blitting.  It&#39;s about the same speed unless your bitmaps are 24bpp.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (orz)</author>
		<pubDate>Wed, 17 Jan 2007 21:55:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Did you check the Allegro sources to make sure the &quot;lines&quot; are contiguous in memory?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Wed, 17 Jan 2007 22:58:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What&#39;s wrong with blit() again?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob)</author>
		<pubDate>Wed, 17 Jan 2007 23:04:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, blit() is probably implemented as:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> y <span class="k3">=</span> start_y<span class="k2">;</span> y <span class="k3">&lt;</span> end_y<span class="k2">;</span> y<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
   <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> x <span class="k3">=</span> start_x<span class="k2">;</span> x <span class="k3">&lt;</span> end_x<span class="k2">;</span> x<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
      <a href="http://www.allegro.cc/manual/putpixel" target="_blank"><span class="a">putpixel</span></a><span class="k2">(</span>dest, x <span class="k3">+</span> off_x, y <span class="k3">+</span> off_y, <a href="http://www.allegro.cc/manual/getpixel" target="_blank"><span class="a">getpixel</span></a><span class="k2">(</span>orig, x, y<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Ohh wait I forgot <s>the clipping check (redundant)</s> in the loop!<br />and acquire_bitmap() and release_bitmap()!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Wed, 17 Jan 2007 23:39:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Blit (between memory bitmaps of the same color depth) is generally a lot faster than that.  It&#39;s comparable to a memcopy per (horizontal) line region being overwritten.  A single set of rectangle clippings is done at the start of the function, not per-pixel or anything stupid like that.  Checks are also done to make sure the destination and source bitmap are the same color depth, but again, those checks are all per-blit, not per-pixel or anything stupid.  </p><p>In sum, blits between same-color-depth memory bitmaps are comparable to memcopy in speed unless you&#39;re doing many extremely tiny blits or your bitmaps are 24bpp.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (orz)</author>
		<pubDate>Wed, 17 Jan 2007 23:47:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I like this &quot;is-probably-implemented-as&quot; approach to figuring out whether the existing solution is good or not.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Wed, 17 Jan 2007 23:50:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Well, blit() is probably implemented as:
</p></div></div><p>
Do you have any idea how increadibly slow the code you posted would be?<br />Had you actually checked the source, you would have found that blit() is special cased for each colour depth, for each bitmap type and for each blit between different colour depths and image formats (this sounds worse than it actually is, since a lot of code is similar and put into macros).<br />In fact, the normal blit() function workhorse is implemented as
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">void</span> FUNC_LINEAR_BLIT<span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>src, <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>dst, <span class="k1">int</span> sx, <span class="k1">int</span> sy,</td></tr><tr><td class="number">2</td><td>          <span class="k1">int</span> dx, <span class="k1">int</span> dy, <span class="k1">int</span> w, <span class="k1">int</span> h<span class="k2">)</span></td></tr><tr><td class="number">3</td><td><span class="k2">{</span></td></tr><tr><td class="number">4</td><td>   <span class="k1">int</span> y<span class="k2">;</span></td></tr><tr><td class="number">5</td><td>&#160;</td></tr><tr><td class="number">6</td><td>   <a href="http://www.allegro.cc/manual/ASSERT" target="_blank"><span class="a">ASSERT</span></a><span class="k2">(</span>src<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">7</td><td>   <a href="http://www.allegro.cc/manual/ASSERT" target="_blank"><span class="a">ASSERT</span></a><span class="k2">(</span>dst<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td>   <span class="k1">for</span> <span class="k2">(</span>y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> y <span class="k3">&lt;</span> h<span class="k2">;</span> y<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">10</td><td>      PIXEL_PTR s <span class="k3">=</span> OFFSET_PIXEL_PTR<span class="k2">(</span><a href="http://www.allegro.cc/manual/bmp_read_line" target="_blank"><span class="a">bmp_read_line</span></a><span class="k2">(</span>src, sy <span class="k3">+</span> y<span class="k2">)</span>, sx<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>      PIXEL_PTR d <span class="k3">=</span> OFFSET_PIXEL_PTR<span class="k2">(</span><a href="http://www.allegro.cc/manual/bmp_write_line" target="_blank"><span class="a">bmp_write_line</span></a><span class="k2">(</span>dst, dy <span class="k3">+</span> y<span class="k2">)</span>, dx<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>&#160;</td></tr><tr><td class="number">13</td><td>      <a href="http://www.delorie.com/djgpp/doc/libc/libc_568.html" target="_blank">memmove</a><span class="k2">(</span>d, s, w <span class="k3">*</span> <span class="k1">sizeof</span><span class="k2">(</span><span class="k3">*</span>s<span class="k2">)</span> <span class="k3">*</span> PTR_PER_PIXEL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>   <span class="k2">}</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td>   <a href="http://www.allegro.cc/manual/bmp_unwrite_line" target="_blank"><span class="a">bmp_unwrite_line</span></a><span class="k2">(</span>src<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>   <a href="http://www.allegro.cc/manual/bmp_unwrite_line" target="_blank"><span class="a">bmp_unwrite_line</span></a><span class="k2">(</span>dst<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>
(OFFSET_PIXEL_PTR and PTR_PER_PIXEL are helper macros that are different for each colour depth), although hardware accelerated blits are again special cased.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 18 Jan 2007 00:12:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Aww, my apologies... When posting, I considered putting &lt;SARCASTIC&gt; tags, but I thought it was obvious enough from the multiple levels of inefficiency in the 3 three lines of pseudocode <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /><br />I mean, acquire_bitmap() per pixel! dual-buffering a 1024x768 screen would mean 788736 times locking and releasing the screen... crazy!</p><p>I&#39;m impressed by the patience of whoever thought I talked seriously !
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Thu, 18 Jan 2007 01:25:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The sudden onslaught of übernoobs has dulled our sarcasm-senses.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jonatan Hedborg)</author>
		<pubDate>Thu, 18 Jan 2007 01:36:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ya whats up with that?  This last few months its been non-stop.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Thu, 18 Jan 2007 02:56:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think it may be a sign for us dinosaurs to go the way of the dodo. Figuratively speaking.<br /><img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 18 Jan 2007 03:10:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So the n00bs will inherit the Earth ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Thu, 18 Jan 2007 03:55:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>We were all n00bs at some point.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 18 Jan 2007 04:03:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>But Al Gore hadn&#39;t invented the Internet yet, so we couldn&#39;t advertise our noobiness as readily, so more likely than not, we actually learned <i>on our own</i> how to do things.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Thu, 18 Jan 2007 04:32:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Point taken <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>though I didn&#39;t start this computer stuff till 1997 or so (could have been as late as 1998-1999, can&#39;t right recall). I thought that was after al gore invented the web <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 18 Jan 2007 05:14:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
though I didn&#39;t start this computer stuff till 1997 or so
</p></div></div><p>

n00b. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Thu, 18 Jan 2007 06:50:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, I got it working. All memory go! <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /><br />It works about the same speed as <tt>blit()</tt>.<br />Thanks! <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kikaru)</author>
		<pubDate>Thu, 18 Jan 2007 08:53:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
It works about the same speed as blit().
</p></div></div><p>
That&#39;s hardly surprising. Did you look at the source I posted above?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 18 Jan 2007 12:27:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
n00b. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div></div><p>I know eh? But I think I did all right <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>Actually, I had used some computers previously in school and whatnot, but I didn&#39;t get a &quot;decent&quot; computer till 1997 or so. P1 233 with windows 95 OSR2, which got ditched for linux after a year and a half of trying to learn how to program on windows with no budget, a dialup connection, and somewhat of a conscience.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 18 Jan 2007 16:02:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
n00b.
</p></div></div><p>
I know eh? But I think I did all right
</p></div></div><p>

I think so too.  </p><p>I got credit just for calling you a n00b. <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Thu, 18 Jan 2007 18:05:19 +0000</pubDate>
	</item>
</rss>
