diff --git a/src/engine.c b/src/engine.c index 82258e00..07c3b41d 100644 --- a/src/engine.c +++ b/src/engine.c @@ -53,6 +53,7 @@ #include "io.h" #include "pxsimple.h" #include "oldies.h" +#include "palette.h" #if defined(__GP2X__) || defined(__WIZ__) || defined(__CAANOO__) || defined(__SWITCH__) // We don't want to underline the keyboard shortcuts as there is no keyboard @@ -589,7 +590,9 @@ void Status_print_palette_color(byte color) i = snprintf(str, sizeof(str), "%s%d (%d,%d,%d)", Buttons_Pool[BUTTON_CHOOSE_COL].Tooltip, color, - Main.palette[color].R,Main.palette[color].G,Main.palette[color].B); + Encode_component(Main.palette[color].R), + Encode_component(Main.palette[color].G), + Encode_component(Main.palette[color].B)); // Pad spaces while(i<24) str[i++]=' '; diff --git a/src/palette.c b/src/palette.c index e307db7b..82b4f3fc 100644 --- a/src/palette.c +++ b/src/palette.c @@ -40,6 +40,8 @@ #include "palette.h" #include "shade.h" +static void Component_unit(int count); + static byte Palette_view_is_RGB = 1; // Indique si on est en HSL ou en RGB static float Gamma = 1.0; @@ -67,7 +69,10 @@ int Color_halfstep=0; void Set_palette_RGB_scale(int scale) { if (scale>= 2 && scale <= 256) + { RGB_scale = scale; + Component_unit(RGB_scale); + } } int Get_palette_RGB_scale(void) @@ -108,16 +113,16 @@ byte Round_palette_component(byte comp) /// otherwise the rounding will be "down". static int Decode_component(int comp) { - float res = pow((float)comp/Color_max,1/Gamma)*255; + double res = pow((double)comp/Color_max, 1.0/Gamma) * 255.0; return (int)res; } /// Turns a RGB component from 0-255 to 0-(RGB_scale-1) and apply Gamma correction. -static int Encode_component(int comp) +int Encode_component(int comp) { - float res = pow(comp/255.0,Gamma)*Color_max; - return ceil(res); + double res = pow(comp/255.0, Gamma) * (double)Color_max; + return (int)ceil(res); } @@ -135,7 +140,7 @@ static int Add_encoded(int comp, int offset) // Définir les unités pour les graduations R G B ou H S V -void Component_unit(int count) +static void Component_unit(int count) { Color_count = count; Color_max = count-1; diff --git a/src/palette.h b/src/palette.h index 2eb80ddc..709a537b 100644 --- a/src/palette.h +++ b/src/palette.h @@ -41,6 +41,10 @@ void Set_palette_Gamma(int); /// Returns the resulting value, in the [0-255] range. byte Round_palette_component(byte comp); +/// Turns a RGB component from 0-255 to 0-(RGB_scale-1) +/// with Gamma correction. +int Encode_component(int comp); + /*! Adds 4 menu colors in the current palette. @param color_usage An up-to-date color usage table (byte[256]) (read only)