Improved Spare remapping and Brush recolorizing, with new color-matching formula provided by DawnBringer (Perceptual color-distance with 25 brightness weigth-in). Fix in 'Copy to spare/Palette & remap' : Transparent color of the spare wasn't renumbered accordingly.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1613 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud
2010-09-12 19:09:27 +00:00
parent 32f85909ef
commit b0d2f9741d
4 changed files with 54 additions and 15 deletions

View File

@@ -2584,22 +2584,14 @@ void Display_all_screen(void)
byte Best_color(byte r,byte g,byte b)
{
// This "static" allows the loop to start on the last successful match.
// If the same color is requested again (and it happens often) and the match
// was perfect, it allows an early exit that avoids
// 255 computations of color distance.
// This system still works with no bad effects when the palette changes.
static byte col=0;
byte end_color;
int col;
int delta_r,delta_g,delta_b;
int dist;
int best_dist=0x7FFFFFFF;
int rmean;
byte best_color=0;
end_color=col;
do
for (col=0; col<256; col++)
{
if (!Exclude_color[col])
{
@@ -2619,9 +2611,7 @@ byte Best_color(byte r,byte g,byte b)
best_color=col;
}
}
// Loop
col++;
} while(col!=end_color);
}
return best_color;
}
@@ -2658,6 +2648,51 @@ byte Best_color_nonexcluded(byte red,byte green,byte blue)
}
byte Best_color_perceptual(byte r,byte g,byte b)
{
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<256; 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 Old_black;
byte Old_dark;
byte Old_light;