<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Use magenta as transparent color</title>
		<link>http://www.allegro.cc/forums/view/616212</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 26 Apr 2016 22:19:27 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello everyone!</p><p>Is there a way to specify color to use as a transparency mask for a bitmap in Allegro 5? </p><p>I&#39;m creating some bitmaps at run-time and based on a previously acquired image with no alpha channel (these images are also acquired at run-time). So, I use magenta (255, 0, 255) as a key color and I&#39;m trying to replace this for alpha == 0.</p><p>This gives me the expected effect, but it&#39;s very slow. Is it possible by any means to tell Allegro to always use magenta as transparency?</p><p>al_convert_mask_to_alpha(buffer, al_map_rgb(255, 0, 255));</p><p>Thanks in advance,<br />Diego
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Diego Barboza)</author>
		<pubDate>Wed, 20 Apr 2016 00:38:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="http://liballeg.org/a5docs/trunk/graphics.html#al_convert_mask_to_alpha">http://liballeg.org/a5docs/trunk/graphics.html#al_convert_mask_to_alpha</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Wed, 20 Apr 2016 01:49:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>jmasterx, thanks for the link, but as I said on my initial post, I&#39;ve already tested this function and it&#39;s too slow to use every time I create a new bitmap.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Diego Barboza)</author>
		<pubDate>Wed, 20 Apr 2016 02:00:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You should probably create your bitmaps as ALLEGRO_MEMORY bitmaps, apply the mask conversion, then convert to video.  If they are created as video, then to alter it, you have to do a lot of extra work.</p><p>If none of that works, the more modern solution might be to apply a shader when you render these bitmaps. The shader logic is:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span>pixelcolor <span class="k3">=</span><span class="k3">=</span> magic pink<span class="k2">)</span>
<span class="k1">return</span> color<span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span>
<span class="k1">else</span>
<span class="k1">return</span> pixelcolor
</pre></div></div><p>

The other option is, if you can, before creating the allegro bitmaps, remove the pink from whatever memory buffer you&#39;re creating them from.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Wed, 20 Apr 2016 02:37:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How slow is too slow? I did some quick checking and it takes about 4 milliseconds on my laptop to call <span class="source-code"><a href="http://www.allegro.cc/manual/al_convert_mask_to_alpha"><span class="a">al_convert_mask_to_alpha</span></a><span class="k2">(</span>buffer, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">255</span>, <span class="n">0</span>, <span class="n">255</span><span class="k2">)</span><span class="k2">)</span></span> on a 256x256 bitmap. </p><p>You may be able to get quicker if you use <span class="source-code"><a href="http://www.allegro.cc/manual/al_lock_bitmap"><span class="a">al_lock_bitmap</span></a></span> and roll your own conversion.</p><p>Pete
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Wed, 20 Apr 2016 14:58:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>At &quot;run-time&quot; is quite vague. Are you generating them in real-time or something?<br />How often are you calling <span class="source-code"><a href="http://www.allegro.cc/manual/al_convert_mask_to_alpha"><span class="a">al_convert_mask_to_alpha</span></a></span>?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (l j)</author>
		<pubDate>Wed, 20 Apr 2016 18:32:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/616212/1021954#target">Diego Barboza</a> said:</div><div class="quote"><p>This gives me the expected effect, but it&#39;s very slow.</p></div></div><p>
That&#39;s why I use a set of helper functions I wrote (in C):</p><p><a href="https://github.com/drcouzelis/colorwandcastle/blob/master/src/resources.h">https://github.com/drcouzelis/colorwandcastle/blob/master/src/resources.h</a></p><p><a href="https://github.com/drcouzelis/colorwandcastle/blob/master/src/resources.c">https://github.com/drcouzelis/colorwandcastle/blob/master/src/resources.c</a></p><p>The code <tt>IMG(&quot;filename.png&quot;);</tt> will return a pointer to an ALLEGRO_BITMAP. The first time you use that filename it is loaded from the hard drive into memory. After that, every time you load the same filename it just reuses the bitmap that&#39;s already been loaded into memory.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (David Couzelis)</author>
		<pubDate>Thu, 21 Apr 2016 17:22:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/616212/1021982#target">David Couzelis</a> said:</div><div class="quote"><p> The first time you use that filename it is loaded from the hard drive
</p></div></div><p>good, apart from...
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/616212/1021954#target">Diego Barboza</a> said:</div><div class="quote"><p> I&#39;m creating some bitmaps at run-time</p></div></div><p>DB could you give us some more detail on how, and how often, these bitmaps are created?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Thu, 21 Apr 2016 18:05:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh wow, I totally misunderstood the situation.</p><p>Please consider disregarding me! <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (David Couzelis)</author>
		<pubDate>Thu, 21 Apr 2016 19:15:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi everyone,</p><p>I&#39;m making a video streaming application, so these bitmaps are generated every frame. I followed jmasterx&#39;s advice and used a shader. It&#39;s pretty easy to implement and it&#39;s very fast! Thank you all!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Diego Barboza)</author>
		<pubDate>Tue, 26 Apr 2016 22:19:27 +0000</pubDate>
	</item>
</rss>
