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

@ -806,7 +806,7 @@ void Remap_brush(void)
// ne seront pas utilisées par Remap_brush_LOWLEVEL.
for (color=0;color<=255;color++)
if (used[color] != 0)
used[color]=Best_color(Spare_palette[color].R,Spare_palette[color].G,Spare_palette[color].B);
used[color]=Best_color_perceptual(Spare_palette[color].R,Spare_palette[color].G,Spare_palette[color].B);
// Il reste une couleur non calculée dans la table qu'il faut mettre à
// jour: c'est la couleur de fond. On l'avait inhibée pour éviter son

View File

@ -673,13 +673,16 @@ void Remap_spare(void)
// ne seront pas utilisées par Remap_general_lowlevel.
for (color=0;color<=255;color++)
if (used[color])
used[color]=Best_color(Spare_palette[color].R,Spare_palette[color].G,Spare_palette[color].B);
used[color]=Best_color_perceptual(Spare_palette[color].R,Spare_palette[color].G,Spare_palette[color].B);
// Maintenant qu'on a une super table de conversion qui n'a que le nom
// qui craint un peu, on peut faire l'échange dans la brosse de toutes les
// teintes.
for (layer=0; layer<Spare_backups->Pages->Nb_layers; layer++)
Remap_general_lowlevel(used,Spare_backups->Pages->Image[layer],Spare_image_width,Spare_image_height,Spare_image_width);
// Change transparent color index
Spare_backups->Pages->Transparent_color=used[Spare_backups->Pages->Transparent_color];
}

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;

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_nonexcluded(byte red,byte green,byte blue);
byte Best_color_perceptual(byte r,byte g,byte b);
void Horizontal_XOR_line_zoom(short x_pos, short y_pos, short width);
void Vertical_XOR_line_zoom(short x_pos, short y_pos, short height);