<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>doubt about load_bitmap(const char *filename, RGB *pal)</title>
		<link>http://www.allegro.cc/forums/view/587448</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 06 Sep 2006 11:55:17 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I read from allegro manual, I found before a bitmap is loaded to the program,We&#39;ll <br />call set_color_depth(int depth) and set_gfx_mode();<br />If we set 8 bits as the color_depth, when we use load_bitmap(filename, pal), the pal can&#39;t been passed as NULL , it must been a pointer points to a PALETTE type variable, after load_bitmap, we&#39;ll call set_palette(pal), if we doesn&#39;t do so,the last display reust is NOT right; <br />on the other way ,if we set 15,16,24,or 32 bits as the color_detph, the parameter passed to load_bitmap can be NULL, and we don&#39;t need to call set_palette(pal), and the last display result is right.<br />who can tell me what&#39;s the difference between them ?</p><p>by the way : after display the image to screen, I tried to get the bitmap color_depth, if we set 8 bits as the color_depth , the bitmap&#39;s color_depth is 8;<br />if we set 32 bits as the color_depth, the bitmap&#39;s color_depth is 32, I think the color_depth of the bitmap file is a const value, why does it change along with color_depth value?</p><p>here is the code :
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/set_color_depth" target="_blank"><span class="a">set_color_depth</span></a><span class="k2">(</span><span class="n">8</span><span class="k2">)</span><span class="k2">;</span>
   <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_AUTODETECTED, w, h, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span> <span class="k3">!</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">{</span>
      <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"Unable to set mode %ix%i with 8bpp\n"</span>, w, h<span class="k2">)</span><span class="k2">;</span>
     <span class="k2">}</span>
    <span class="c">/* load the image */</span>
   background <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap" target="_blank"><span class="a">load_bitmap</span></a><span class="k2">(</span>filename, pal<span class="k2">)</span><span class="k2">;</span> <span class="k3">&lt;</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span> here
   <span class="k1">if</span> <span class="k2">(</span>background <span class="k3">!</span><span class="k3">=</span> NULL<span class="k2">)</span> <span class="k2">{</span>
      <a href="http://www.allegro.cc/manual/set_palette" target="_blank"><span class="a">set_palette</span></a><span class="k2">(</span>pal<span class="k2">)</span><span class="k2">;</span> <span class="k3">&lt;</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span> here
   <span class="k2">}</span><span class="k2">;</span>
</pre></div></div><p>
another :
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/set_color_depth" target="_blank"><span class="a">set_color_depth</span></a><span class="k2">(</span><span class="n">32</span><span class="k2">)</span><span class="k2">;</span>
   <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_AUTODETECTED, w, h, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span> <span class="k3">!</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">{</span>
      <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"Unable to set mode %ix%i with 32bpp\n"</span>, w, h<span class="k2">)</span><span class="k2">;</span>
     <span class="k2">}</span>
    <span class="c">/* load the image */</span>
   background <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap" target="_blank"><span class="a">load_bitmap</span></a><span class="k2">(</span>filename, NULL<span class="k2">)</span><span class="k2">;</span> <span class="k3">&lt;</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span> here
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (sj971059)</author>
		<pubDate>Wed, 06 Sep 2006 06:51:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>8 bit is only 255 colors so for it to be right you need a pallette to tell it what colors are which. On higher bit modes, you have &quot;nearly unlimited&quot; colors, so pallettes arne&#39;t used.</p><p>The color depth changes because when you load the bitmap, Allegro converts it to the current color depth automagically.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Wed, 06 Sep 2006 07:08:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
If we set 8 bits as the color_depth, when we use load_bitmap(filename, pal), the pal can&#39;t been passed as NULL , it must been a pointer points to a PALETTE type variable, after load_bitmap, we&#39;ll call set_palette(pal), if we doesn&#39;t do so,the last display reust is NOT right;<br />on the other way ,if we set 15,16,24,or 32 bits as the color_detph, the parameter passed to load_bitmap can be NULL, and we don&#39;t need to call set_palette(pal), and the last display result is right.
</p></div></div><p>
You&#39;re over complicating. You can always pass NULL for the pal argument, in which case the palette of the bitmap will be ignored (if there is one). Only 8 bit bitmaps have palettes anyway, so if you&#39;re loading a high or true colour image, the pal argument will be ignored anyway.<br />If you load an 8 bit image, you have to specify the palette of colours to use with it, because 8 bit images actually store the index into a 255 colour palette rather than the RGB value of a particular colour.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I tried to get the bitmap color_depth, if we set 8 bits as the color_depth , the bitmap&#39;s color_depth is 8;<br />if we set 32 bits as the color_depth, the bitmap&#39;s color_depth is 32, I think the color_depth of the bitmap file is a const value, why does it change along with color_depth value?
</p></div></div><p>
You&#39;re converting the colour depth to the current colourdepth when the file is loaded; see <a href="http://www.allegro.cc/manual/set_color_conversion">set_color_conversion()</a>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 06 Sep 2006 11:55:17 +0000</pubDate>
	</item>
</rss>
