<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>pixel format</title>
		<link>http://www.allegro.cc/forums/view/608426</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 23 Sep 2011 22:56:14 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA - Let the driver choose a 32 bit format with alpha.<br />ALLEGRO_PIXEL_FORMAT_ARGB_8888 - 32 bit<br />ALLEGRO_PIXEL_FORMAT_RGBA_8888 - 32 bit
</p></div></div><p>


When using ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA I suppose when writing to a locked bitmap - the effects will depend on whether ARGB or BGRA was chosen ?</p><p>Is this correct ? ...and if so is there a way to get the pixel format chosen ?</p><p>Would it be a good idea to write to the data of an ALLEGRO_BITMAP by taking this into account ? - ie is it just a plain bad idea or is it okay because it means portability is enhanced ?</p><p>Would be grateful for some guidance here.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Fri, 23 Sep 2011 21:20:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>ALLEGRO_LOCKED_REGION has a format variable that will tell you the format. You have several options:</p><p>1) Easiest but not optimally quick. Pass whatever format you want to al_lock_bitmap and the data will be in that format.</p><p>2) Pass ALLEGRO_PIXEL_FORMAT_ANY and it will automatically choose the format that the bitmap data is already stored in. Faster because there is no conversion.</p><p>As for how to read/write the different formats, every pixel format in Allegro specifies in its name the order of the bits/bytes such that the most significant bits are mentioned first. Example: ARGB_8888 means each component is 8 bits, therefore the whole thing is 32 bits, and would fit in an int like this: 0xAARRGGBB. So to create a pixel out of 4 bytes for example you would do <span class="source-code">pixel <span class="k3">=</span> b <span class="k3">|</span> <span class="k2">(</span>g <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="n">8</span><span class="k2">)</span> <span class="k3">|</span> <span class="k2">(</span>r <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="n">16</span><span class="k2">)</span> <span class="k3">|</span> <span class="k2">(</span>a <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="n">24</span><span class="k2">)</span><span class="k2">;</span></span>.</p><p>The problem you might encounter is that some machines may use big endian byte ordering but that&#39;s rare. So even though &#39;A&#39; comes first, if you were writing a byte at a time into the locked region data buffer, on little endian machines you need to write the &#39;B&#39; byte, then the &#39;G&#39; byte etc. This leads to unportable code, and that&#39;s why the pixel format RGBA_8888_LE was created. With that format, you should always write the bytes out in little endian (the LE stands for it) despite the byte order of the machine. So if you&#39;re using OpenGL, RGBA_8888_LE is a good choice for bitmaps. If you&#39;re also using d3d, well, it only runs on little endian hardware anyway, but you&#39;ll have to pick something else like ARGB_8888 when using it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Fri, 23 Sep 2011 21:42:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for all that Trent.</p><p>If I was to use ALLEGRO_PIXEL_FORMAT_ANY for al_lock_bitmap - I would get the format<br />the bitmap was created in.</p><p>To know that could I call al_get_new_bitmap_format() ?</p><p>If I&#39;d used </p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_set_new_bitmap_format"><span class="a">al_set_new_bitmap_format</span></a><span class="k2">(</span>ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA<span class="k2">)</span><span class="k2">;</span></span></p><p>previously,</p><p>would al_get_new_bitmap_format() return ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA or would it be a specific one like ALLEGRO_PIXEL_FORMAT_****_8888?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Fri, 23 Sep 2011 21:54:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>To get the format before locking, use al_get_bitmap_format(bmp), after locking use int format = locked_region-&gt;format.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Fri, 23 Sep 2011 22:41:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Brilliant. Thanks again.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Fri, 23 Sep 2011 22:56:14 +0000</pubDate>
	</item>
</rss>
