<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Problem/error with the result from al_color_rgb_to_html()?</title>
		<link>http://www.allegro.cc/forums/view/612464</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 25 Apr 2013 07:13:21 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Trying to use the void al_color_rgb_to_html(float,float,float,char*) function but the output hex color code is incorrect. It appears that no matter what the third parameter is (red color) the result is &quot;00&quot; in the hex color. I&#39;ve tested sending in everything from 0 to 1 but the result is always &quot;00&quot;.</p><p>Reading the example at <a href="http://alleg.sourceforge.net/a5docs/refman/color.html#al_color_html">http://alleg.sourceforge.net/a5docs/refman/color.html#al_color_html</a></p><p>Example: al_color_rgb_to_html(1, 0, 0, html);</p><p>The result is: #ff0000</p><p>But if I change red color value from 0 to 1: al_color_rgb_to_html(1, 0, 1, html);</p><p>Result is still: #ff0000, instead of #ff00ff</p><p>Changing the green (or red) color value will however work as intended.</p><p>Anyone got this function to work?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeaRDoWN)</author>
		<pubDate>Tue, 23 Apr 2013 12:18:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The code for the function is wrong. It is casting blue before multiplying:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> <a href="http://www.allegro.cc/manual/al_color_rgb_to_html"><span class="a">al_color_rgb_to_html</span></a><span class="k2">(</span><span class="k1">float</span> red, <span class="k1">float</span> green, <span class="k1">float</span> blue,
    <span class="k1">char</span> <span class="k3">*</span>string<span class="k2">)</span>
<span class="k2">{</span>
   <a href="http://www.delorie.com/djgpp/doc/libc/libc_737.html" target="_blank">sprintf</a><span class="k2">(</span>string, <span class="s">"#%02x%02x%02x"</span>, <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>red <span class="k3">*</span> <span class="n">255</span><span class="k2">)</span>,
      <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>green <span class="k3">*</span> <span class="n">255</span><span class="k2">)</span>, <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span>blue <span class="k3">*</span> <span class="n">255</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// &lt;-- Wrong</span>
<span class="k2">}</span>
</pre></div></div><p>

There&#39;s another bug where it accepts color components greater than 1 or less than zero, it should be probably be changed to something like:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> <a href="http://www.allegro.cc/manual/al_color_rgb_to_html"><span class="a">al_color_rgb_to_html</span></a><span class="k2">(</span><span class="k1">float</span> red, <span class="k1">float</span> green, <span class="k1">float</span> blue,
    <span class="k1">char</span> <span class="k3">*</span>string<span class="k2">)</span>
<span class="k2">{</span>
   <span class="c">// if you expect people might provide bad input:</span>
   <span class="k1">if</span> <span class="k2">(</span><span class="k1">sizeof</span><span class="k2">(</span>string<span class="k2">)</span> <span class="k3">&gt;</span> <span class="n">7</span><span class="k2">)</span> <span class="k2">{</span>
      red <span class="k3">=</span> <span class="n">0</span> <span class="k3">&gt;</span> red ? <span class="n">0</span> <span class="k2">:</span> <span class="n">1</span> <span class="k3">&lt;</span> red ? <span class="n">1</span> <span class="k2">:</span> red<span class="k2">;</span>
      green <span class="k3">=</span> <span class="n">0</span> <span class="k3">&gt;</span> green ? <span class="n">0</span> <span class="k2">:</span> <span class="n">1</span> <span class="k3">&lt;</span> green ? <span class="n">1</span> <span class="k2">:</span> green<span class="k2">;</span>
      blue <span class="k3">=</span> <span class="n">0</span> <span class="k3">&gt;</span> blue ? <span class="n">0</span> <span class="k2">:</span> <span class="n">1</span> <span class="k3">&lt;</span> blue ? <span class="n">1</span> <span class="k2">:</span> blue<span class="k2">;</span>
   <span class="c">//---</span>
      <a href="http://www.delorie.com/djgpp/doc/libc/libc_732.html" target="_blank">snprintf</a><span class="k2">(</span>string, <span class="n">8</span>, <span class="s">"#%02x%02x%02x"</span>, <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>red <span class="k3">*</span> <span class="n">255</span><span class="k2">)</span>,
         <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>green <span class="k3">*</span> <span class="n">255</span><span class="k2">)</span>, <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>blue <span class="k3">*</span> <span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// &lt;-- Fix the cast, at least</span>
   <span class="c">//---</span>
   <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jeff Bernard)</author>
		<pubDate>Tue, 23 Apr 2013 12:42:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Good catch!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Tue, 23 Apr 2013 12:51:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I guess we are not talking &quot;day 1 patch&quot; for this. If/when fixed, when could a that version of Allegro be available?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeaRDoWN)</author>
		<pubDate>Tue, 23 Apr 2013 16:10:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>latest GIT will almost surely take care of this bug very soon (i.e. as soon as a dev picks this up), but you&#39;ll have to compile allegro yourself.....for an official release you&#39;ll have to wait word of the devs.</p><p>On the other hand....wow I guess this function was not really used huh?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (pkrcel)</author>
		<pubDate>Tue, 23 Apr 2013 16:34:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This function should never have made it into 5.0. Actually, the whole color addon.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Tue, 23 Apr 2013 17:16:02 +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/612464/981320#target">pkrcel</a> said:</div><div class="quote"><p> On the other hand....wow I guess this function was not really used huh?
</p></div></div><p>I think I used it&#39;s inverse once.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/612464/981325#target">Peter Wang</a> said:</div><div class="quote"><p> Actually, the whole color addon.
</p></div></div><p>Aww... The HSL/HSV functions are pretty useful I find.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 23 Apr 2013 22:30:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I find the X11 color names most useful myself - but that&#39;s little surprise I guess <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 24 Apr 2013 16:38:03 +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/612464/981325#target">Peter Wang</a> said:</div><div class="quote"><p> This function should never have made it into 5.0. Actually, the whole color addon.</p></div></div><p>the two following posts let me wonder....does this mean that there should be (have been) NO color addon at all?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (pkrcel)</author>
		<pubDate>Wed, 24 Apr 2013 19:23:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s just my personal opinion that most, if not all, the functionality provided by the color addon did not need to be provided by the Allegro core library or an official addon. Elias&#39; initial commit wrote:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Added a color addon for now, but this represents no decision to keep it in the official SVN repository, as its general usefulness is a bit borderline.
</p></div></div><p>
And there it stayed - and will stay.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Thu, 25 Apr 2013 07:13:21 +0000</pubDate>
	</item>
</rss>
