Problem/error with the result from al_color_rgb_to_html()?
TeaRDoWN

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 "00" in the hex color. I've tested sending in everything from 0 to 1 but the result is always "00".

Reading the example at http://alleg.sourceforge.net/a5docs/refman/color.html#al_color_html

Example: al_color_rgb_to_html(1, 0, 0, html);

The result is: #ff0000

But if I change red color value from 0 to 1: al_color_rgb_to_html(1, 0, 1, html);

Result is still: #ff0000, instead of #ff00ff

Changing the green (or red) color value will however work as intended.

Anyone got this function to work?

Jeff Bernard

The code for the function is wrong. It is casting blue before multiplying:

void al_color_rgb_to_html(float red, float green, float blue,
    char *string)
{
   sprintf(string, "#%02x%02x%02x", (int)(red * 255),
      (int)(green * 255), (int)blue * 255); // <-- Wrong
}

There's another bug where it accepts color components greater than 1 or less than zero, it should be probably be changed to something like:

void al_color_rgb_to_html(float red, float green, float blue,
    char *string)
{
   // if you expect people might provide bad input:
   if (sizeof(string) > 7) {
      red = 0 > red ? 0 : 1 < red ? 1 : red;
      green = 0 > green ? 0 : 1 < green ? 1 : green;
      blue = 0 > blue ? 0 : 1 < blue ? 1 : blue;
   //---
      snprintf(string, 8, "#%02x%02x%02x", (int)(red * 255),
         (int)(green * 255), (int)(blue * 255)); // <-- Fix the cast, at least
   //---
   }
}

Arthur Kalliokoski

Good catch!

TeaRDoWN

I guess we are not talking "day 1 patch" for this. If/when fixed, when could a that version of Allegro be available?

pkrcel

latest GIT will almost surely take care of this bug very soon (i.e. as soon as a dev picks this up), but you'll have to compile allegro yourself.....for an official release you'll have to wait word of the devs.

On the other hand....wow I guess this function was not really used huh?

Peter Wang

This function should never have made it into 5.0. Actually, the whole color addon.

SiegeLord
pkrcel said:

On the other hand....wow I guess this function was not really used huh?

I think I used it's inverse once.

Actually, the whole color addon.

Aww... The HSL/HSV functions are pretty useful I find.

Elias

I find the X11 color names most useful myself - but that's little surprise I guess :)

pkrcel

This function should never have made it into 5.0. Actually, the whole color addon.

the two following posts let me wonder....does this mean that there should be (have been) NO color addon at all?

Peter Wang

It'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' initial commit wrote:

Quote:

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.

And there it stayed - and will stay.

Thread #612464. Printed from Allegro.cc