Issue 490: color 255 selected FG by default

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@2021 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2012-09-30 16:25:52 +00:00
parent 919357ab46
commit fbdde8d16c
3 changed files with 50 additions and 2 deletions

View File

@ -707,8 +707,8 @@ int Init_program(int argc,char * argv[])
memcpy(Main_palette, Gfx->Default_palette, sizeof(T_Palette)); memcpy(Main_palette, Gfx->Default_palette, sizeof(T_Palette));
Fore_color=Best_color_nonexcluded(255,255,255); Fore_color=Best_color_range(255,255,255,Config.Palette_cells_X*Config.Palette_cells_Y);
Back_color=Best_color_nonexcluded(0,0,0); Back_color=Best_color_range(0,0,0,Config.Palette_cells_X*Config.Palette_cells_Y);
// Allocation de mémoire pour la brosse // Allocation de mémoire pour la brosse
if (!(Brush =(byte *)malloc( 1* 1))) Error(ERROR_MEMORY); if (!(Brush =(byte *)malloc( 1* 1))) Error(ERROR_MEMORY);
@ -878,6 +878,12 @@ int Init_program(int argc,char * argv[])
Hide_cursor(); Hide_cursor();
Compute_optimal_menu_colors(Main_palette); Compute_optimal_menu_colors(Main_palette);
Back_color=Main_backups->Pages->Background_transparent ?
Main_backups->Pages->Transparent_color :
Best_color_range(0,0,0,Config.Palette_cells_X*Config.Palette_cells_Y);
Fore_color=Main_palette[Back_color].R+Main_palette[Back_color].G+Main_palette[Back_color].B < 3*127 ?
Best_color_range(255,255,255,Config.Palette_cells_X*Config.Palette_cells_Y) :
Best_color_range(0,0,0,Config.Palette_cells_X*Config.Palette_cells_Y);
Check_menu_mode(); Check_menu_mode();
Display_all_screen(); Display_all_screen();
Display_menu(); Display_menu();

View File

@ -2702,7 +2702,48 @@ byte Best_color_nonexcluded(byte red,byte green,byte blue)
return best_color; return best_color;
} }
byte Best_color_range(byte r, byte g, byte b, byte max)
{
int col;
float best_diff=255.0*1.56905;
byte best_color=0;
float target_bri;
float bri;
float diff_b, diff_c, diff;
// Similar to Perceptual_lightness();
target_bri = sqrt(0.26*r*0.26*r + 0.55*g*0.55*g + 0.19*b*0.19*b);
for (col=0; col<max; col++)
{
if (Exclude_color[col])
continue;
diff_c = sqrt(
(0.26*(Main_palette[col].R-r))*
(0.26*(Main_palette[col].R-r))+
(0.55*(Main_palette[col].G-g))*
(0.55*(Main_palette[col].G-g))+
(0.19*(Main_palette[col].B-b))*
(0.19*(Main_palette[col].B-b)));
// Exact match
if (diff_c==0)
return col;
bri = sqrt(0.26*Main_palette[col].R*0.26*Main_palette[col].R + 0.55*Main_palette[col].G*0.55*Main_palette[col].G + 0.19*Main_palette[col].B*0.19*Main_palette[col].B);
diff_b = abs(target_bri-bri);
diff=0.25*(diff_b-diff_c)+diff_c;
if (diff<best_diff)
{
best_diff=diff;
best_color=col;
}
}
return best_color;
}
byte Best_color_perceptual(byte r,byte g,byte b) byte Best_color_perceptual(byte r,byte g,byte b)
{ {

View File

@ -99,6 +99,7 @@ void Window_display_icon_sprite(word x_pos,word y_pos,byte type);
byte Best_color(byte red,byte green,byte blue); byte Best_color(byte red,byte green,byte blue);
byte Best_color_nonexcluded(byte red,byte green,byte blue); byte Best_color_nonexcluded(byte red,byte green,byte blue);
byte Best_color_range(byte red,byte green,byte blue,byte max);
byte Best_color_perceptual(byte r,byte g,byte b); byte Best_color_perceptual(byte r,byte g,byte b);
byte Best_color_perceptual_except(byte r,byte g,byte b, byte except); byte Best_color_perceptual_except(byte r,byte g,byte b, byte except);
byte Best_color_perceptual_weighted(byte r,byte g,byte b, float weight); byte Best_color_perceptual_weighted(byte r,byte g,byte b, float weight);