<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Color Condundrum</title>
		<link>http://www.allegro.cc/forums/view/617235</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 24 Jan 2018 05:31:20 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, here&#39;s an interesting thing to ponder.</p><p>I porting a game that originally had 16 colors, but had some spiffy color functions I&#39;m trying to duplicate in Allegro 5 with 24 bit color.</p><p>The prototype that I&#39;m currently trying to implement is thus:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> DoColorMask<span class="k2">(</span><span class="k1">int</span> d, <span class="k1">int</span> s, <span class="k1">int</span> dx, <span class="k1">int</span> dy, <span class="k1">int</span> sx, <span class="k1">int</span> sy, <span class="k1">int</span> w,<span class="k1">int</span> h, <span class="k1">int</span> col<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

d - destination bitmap <br />s - source bitmap <br />dx - destination x<br />dy - destination y<br />sx - source x<br />sy - source y<br />w - source width<br />h -source height<br />col - color</p><p>The function was a poor man&#39;s &quot;tint&quot; function, and behaves a little like al_draw_tinted_bitmap_region().... Kind of</p><p>The is how the DoColorMask() function works:<br />While the source bitmap region is pixel-for-pixel copied to the destination, it will check the color of the pixel being copied. If the pixel isn&#39;t black, then change the pixel color to &quot;col&quot;. This means that if you have a solid red colored button with black text, you can use the function to make the button white with black text.</p><p>I&#39;ve been doing some experiments with al_draw_tinted_bitmap_region() that&#39;s promising, except there are issues I&#39;m not sure how to resolve yet.</p><p><a href="https://i.imgur.com/5BP2p28.png">This</a> was an experiment that was generated with the following code.</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//white</span>
  <a href="http://www.allegro.cc/manual/al_draw_tinted_scaled_bitmap"><span class="a">al_draw_tinted_scaled_bitmap</span></a><span class="k2">(</span>test, al_premul_rgba_f<span class="k2">(</span><span class="n">1</span>, <span class="n">1</span>, <span class="n">1</span>, <span class="n">1</span><span class="k2">)</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">1024</span>, <span class="n">768</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">512</span>, <span class="n">384</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>  <span class="c">//normal</span>
  <span class="c">//red</span>
  <a href="http://www.allegro.cc/manual/al_draw_tinted_scaled_bitmap"><span class="a">al_draw_tinted_scaled_bitmap</span></a><span class="k2">(</span>test, al_premul_rgba_f<span class="k2">(</span><span class="n">1</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">1</span><span class="k2">)</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">1024</span>, <span class="n">768</span>, <span class="n">512</span>, <span class="n">0</span>, <span class="n">512</span>, <span class="n">384</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/al_draw_tinted_scaled_bitmap"><span class="a">al_draw_tinted_scaled_bitmap</span></a><span class="k2">(</span>test, al_premul_rgba_f<span class="k2">(</span><span class="n">1</span>, <span class="n">1</span>, <span class="n">1</span>, .<span class="n">5</span><span class="k2">)</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">1024</span>, <span class="n">768</span>, <span class="n">512</span>, <span class="n">0</span>, <span class="n">512</span>, <span class="n">384</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//normal</span>
  <span class="c">//green</span>
  <a href="http://www.allegro.cc/manual/al_draw_tinted_scaled_bitmap"><span class="a">al_draw_tinted_scaled_bitmap</span></a><span class="k2">(</span>test, al_premul_rgba_f<span class="k2">(</span><span class="n">0</span>, <span class="n">1</span>, <span class="n">0</span>, <span class="n">1</span><span class="k2">)</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">1024</span>, <span class="n">768</span>, <span class="n">0</span>, <span class="n">384</span>, <span class="n">512</span>, <span class="n">384</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/al_draw_tinted_scaled_bitmap"><span class="a">al_draw_tinted_scaled_bitmap</span></a><span class="k2">(</span>test, al_premul_rgba_f<span class="k2">(</span><span class="n">1</span>, <span class="n">1</span>, <span class="n">1</span>, .<span class="n">5</span><span class="k2">)</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">1024</span>, <span class="n">768</span>, <span class="n">0</span>, <span class="n">384</span>, <span class="n">512</span>, <span class="n">384</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//normal</span>
  <span class="c">//blue</span>
  <a href="http://www.allegro.cc/manual/al_draw_tinted_scaled_bitmap"><span class="a">al_draw_tinted_scaled_bitmap</span></a><span class="k2">(</span>test, al_premul_rgba_f<span class="k2">(</span><span class="n">0</span>, <span class="n">0</span>, <span class="n">1</span>, <span class="n">1</span><span class="k2">)</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">1024</span>, <span class="n">768</span>, <span class="n">512</span>, <span class="n">384</span>, <span class="n">512</span>, <span class="n">384</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/al_draw_tinted_scaled_bitmap"><span class="a">al_draw_tinted_scaled_bitmap</span></a><span class="k2">(</span>test, al_premul_rgba_f<span class="k2">(</span><span class="n">1</span>, <span class="n">1</span>, <span class="n">1</span>, .<span class="n">5</span><span class="k2">)</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">1024</span>, <span class="n">768</span>, <span class="n">512</span>, <span class="n">384</span>, <span class="n">512</span>, <span class="n">384</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//normal</span>
</pre></div></div><p>

Upper left is the &quot;normal&quot; color bars, upper right is red tint, lower left is green tint and lower right is blue tint</p><p>What I did was lay down the color channel I wanted for tint and then overlayed the &quot;normal&quot; color at 50% alpha. This is a good 24 bit color approximation of what I&#39;d like to do, but I have two problems.</p><p>1) I can&#39;t turn anything &quot;white&quot; just a tint of color. Overlying a full color channel with a full color alpha results in the same color.</p><p>2) I can&#39;t make a color brighter then it&#39;s base, for the same reason above.</p><p>Now what I <b>really</b> need is a function that duplicates GIMP&#39;s &quot;Colorize&quot; function. (you can see an example of this function <a href="https://i.imgur.com/jCrp5UO.png">here.</a>) How that works is that you give it a picture, and it will strip everything out but the luminosity channel (Makes it black and white). Then it applies a color tint to that channel. From there you adjust three sliders for Hue, Saturation, and Lightness.</p><p>Any ideas on how to apply that concept to Allegro? How would you convert a bitmap to just B&amp;W, and after you do that when you apply the hue, it shouldn&#39;t effect black <b>or</b> white. (Unless I change the lightness) For example, if I was to use al_draw_tinted_bitmap_region() that would make the white tint to that color like the above, right That&#39;s not what I want.</p><p>Bonus:</p><p>I don&#39;t know what a &quot;shader&quot; is other then a thingy in my GPU that makes special effects. As the program is going to be cross platform anyway, assume that using a &quot;shader&quot; is off the table.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nshade)</author>
		<pubDate>Wed, 24 Jan 2018 03:42:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not quite sure what you&#39;re trying to achieve.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/617235/1034762#target">nshade</a> said:</div><div class="quote"><p>
The is how the DoColorMask() function works:<br />The while the source bitmap region is pixel-for-pixel copied to the destination, it will check the color of the pixel being copied. If the pixel isn&#39;t black, then change the pixel color to &quot;col&quot;. This means that if you have a solid red colored button with black text, you can use the function to make the button white with black text.
</p></div></div><p>
I understand what you mean when you say colorize, but every color that&#39;s not black?</p><p>How often do you need this effect? Is it on every frame? Or can you do it once?</p><p>You&#39;ll probably want to check out <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_blender"><span class="a">al_set_blender</span></a></span> and <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_separate_blender"><span class="a">al_set_separate_blender</span></a></span>.</p><p>If you want to &#39;tint&#39; a bitmap white, you need to draw the white over the top with varying alpha.</p><p>You can lock a bitmap region with <span class="source-code"><a href="http://www.allegro.cc/manual/al_lock_bitmap"><span class="a">al_lock_bitmap</span></a></span> and change the data, but you&#39;ll probably need a shader if you want real time colorization.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 24 Jan 2018 03:53:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The function is most often used used to &quot;flash&quot; buttons a different color when you click it. Keep in mind this program doesn&#39;t use &quot;frames&quot; in the modern sense. It updates parts of the screen arbitrarily because it&#39;s largely a GUI. For example, when it flashes a button, it doesn&#39;t render the whole screen on a backbuffer with updated data and flips. It copies the button from the screen, updates the color, and then puts it back. (Then it waits about a tenth of a second, colors it back to the original color, an then repeats for about 5 flashes) all without flipping a page.</p><p>I updated the code so the backbuffer is a little more sane. Now it will flip when display is altered, but I&#39;m kind of a slave the machine states.</p><p>Is there a slick way you can make a color bitmap black and white maybe. I mean short of doing a X,Y for loop and changing every pixel. I can assume it gets a little slow with a 1280x800 array.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nshade)</author>
		<pubDate>Wed, 24 Jan 2018 04:33:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There is no way to make it black and white except for shaders or going through the pixel data.</p><p>The imgur picture is not clear to me, which part is the original picture? Can you maybe post your original picture, then the effect you want (from gimp I suppose), and the effect you currently get?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 24 Jan 2018 05:14:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What you&#39;re asking for is a mask color and color replacement. I don&#39;t think you can do that with a blender alone. Elias is right, you will need to process the pixel data yourself, either through a lock or a shader.</p><p>However, what you can do is take a black and white image and colorize the white portion. It would mean changing all your graphics, but it would be more flexible. However, I can&#39;t believe all your art is simply monochrome, and I think you&#39;re asking to replace only certain colors with the &#39;tint&#39; color. What you&#39;re doing there is altering the hue and saturation.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 24 Jan 2018 05:31:20 +0000</pubDate>
	</item>
</rss>
