Import colors from brush now works (F11)

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1703 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2011-01-30 00:59:52 +00:00
parent abadd59b12
commit 1b0141367e

View File

@ -693,32 +693,79 @@ void Get_colors_from_brush(void)
{
short x_pos; // Variable de balayage de la brosse
short y_pos; // Variable de balayage de la brosse
byte used[256]; // Tableau de booléens "La couleur est utilisée"
byte brush_used[256]; // Tableau de booléens "La couleur est utilisée"
dword usage[256];
int color;
int image_color;
//if (Confirmation_box("Modify current palette ?"))
if (Confirmation_box("Modify current palette ?"))
{
// Backup with unchanged layers, only palette is modified
Backup_layers(0);
// On commence par initialiser le tableau de booléen à faux
// Init array of new colors
for (color=0;color<=255;color++)
used[color]=0;
brush_used[color]=0;
// On calcule la table d'utilisation des couleurs
// Tag used colors
for (y_pos=0;y_pos<Brush_height;y_pos++)
for (x_pos=0;x_pos<Brush_width;x_pos++)
used[Read_pixel_from_brush(x_pos,y_pos)]=1;
brush_used[*(Brush_original_pixels + y_pos * Brush_width + x_pos)]=1;
// On recopie dans la palette principale les teintes des couleurs utilisées
// dans la palette du brouillon
for (color=0;color<=255;color++)
if (used[color])
// Check used colors in picture (to know which palette entries are free)
Count_used_colors(usage);
// First pass : omit colors that are already in palette
for (color=0; color<256; color++)
{
Main_palette[color].R=Spare_palette[color].R;
Main_palette[color].G=Spare_palette[color].G;
Main_palette[color].B=Spare_palette[color].B;
// For each color used in brush (to add in palette)
if (brush_used[color])
{
// Try locate it in current palette
for (image_color=0; image_color<256; image_color++)
{
if (Brush_original_palette[color].R==Main_palette[image_color].R
&& Brush_original_palette[color].G==Main_palette[image_color].G
&& Brush_original_palette[color].B==Main_palette[image_color].B)
{
// Color already in main palette:
// Tag as used, so that no new color will overwrite it
usage[image_color]=1;
// Tag as non-new, to avoid it in pass 2
brush_used[color]=0;
break;
}
}
}
}
// Second pass : For each color to add, find an empty slot in
// main palette to add it
image_color=0;
for (color=0; color<256 && image_color<256; color++)
{
// For each color used in brush
if (brush_used[color])
{
for (; image_color<256; image_color++)
{
if (!usage[image_color])
{
// Copy from color to image_color
Main_palette[image_color].R=Brush_original_palette[color].R;
Main_palette[image_color].G=Brush_original_palette[color].G;
Main_palette[image_color].B=Brush_original_palette[color].B;
image_color++;
break;
}
}
}
}
Remap_brush();
Set_palette(Main_palette);
Compute_optimal_menu_colors(Main_palette);
@ -730,7 +777,6 @@ void Get_colors_from_brush(void)
Main_image_is_modified=1;
}
}