Paste in Text tool: fix a graphic overflow.

Palette reduce: use DawnBringer's formula for color likeness

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1837 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud
2011-10-01 19:26:13 +00:00
parent db3293060f
commit 775ee56ed0
3 changed files with 41 additions and 18 deletions

View File

@@ -559,8 +559,8 @@ void Reduce_palette(short * used_colors,int nb_colors_asked,T_Palette palette,dw
int color_2; // | de la palette
int best_color_1=0;
int best_color_2=0;
int difference;
int best_difference;
long difference;
long best_difference;
dword used;
dword best_used;
@@ -621,16 +621,19 @@ void Reduce_palette(short * used_colors,int nb_colors_asked,T_Palette palette,dw
// une seule couleur qui est la moyenne pondérée de ces 2 couleurs
// en fonction de leur utilisation dans l'image.
best_difference =0x7FFF;
best_difference =26*255*26*255+55*255*255+19*255*19*255;
best_used=0x7FFFFFFF;
for (color_1=0;color_1<(*used_colors);color_1++)
for (color_2=color_1+1;color_2<(*used_colors);color_2++)
if (color_1!=color_2)
{
difference =abs((short)palette[color_1].R-palette[color_2].R)+
abs((short)palette[color_1].G-palette[color_2].G)+
abs((short)palette[color_1].B-palette[color_2].B);
difference =26*abs((long)palette[color_1].R-palette[color_2].R)*
26*abs((long)palette[color_1].R-palette[color_2].R)+
55*abs((long)palette[color_1].G-palette[color_2].G)*
55*abs((long)palette[color_1].G-palette[color_2].G)+
19*abs((long)palette[color_1].B-palette[color_2].B)*
19*abs((long)palette[color_1].B-palette[color_2].B);
if (difference<=best_difference)
{
@@ -2673,11 +2676,11 @@ void Button_Palette(void)
// Close (confirm)
clicked_button=14;
}
else if (Key == (SDLK_c|MOD_CTRL)) // Ctrl-C
else if (Key == SHORTCUT_COPY)
{
Set_clipboard_colors(block_end+1-block_start,working_palette + block_start);
}
else if (Key == (SDLK_v|MOD_CTRL)) // Ctrl-V
else if (Key == SHORTCUT_PASTE)
{
int nb_colors;