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?
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 //--- } }
Good catch!
I guess we are not talking "day 1 patch" for this. If/when fixed, when could a that version of Allegro be available?
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?
This function should never have made it into 5.0. Actually, the whole color addon.
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.
I find the X11 color names most useful myself - but that's little surprise I guess
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?
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:
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.