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:
parent
abadd59b12
commit
1b0141367e
76
src/graph.c
76
src/graph.c
@ -693,32 +693,79 @@ void Get_colors_from_brush(void)
|
|||||||
{
|
{
|
||||||
short x_pos; // Variable de balayage de la brosse
|
short x_pos; // Variable de balayage de la brosse
|
||||||
short y_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 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 with unchanged layers, only palette is modified
|
||||||
Backup_layers(0);
|
Backup_layers(0);
|
||||||
|
|
||||||
// On commence par initialiser le tableau de booléen à faux
|
// Init array of new colors
|
||||||
for (color=0;color<=255;color++)
|
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 (y_pos=0;y_pos<Brush_height;y_pos++)
|
||||||
for (x_pos=0;x_pos<Brush_width;x_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
|
// Check used colors in picture (to know which palette entries are free)
|
||||||
// dans la palette du brouillon
|
Count_used_colors(usage);
|
||||||
for (color=0;color<=255;color++)
|
|
||||||
if (used[color])
|
// First pass : omit colors that are already in palette
|
||||||
|
for (color=0; color<256; color++)
|
||||||
{
|
{
|
||||||
Main_palette[color].R=Spare_palette[color].R;
|
// For each color used in brush (to add in palette)
|
||||||
Main_palette[color].G=Spare_palette[color].G;
|
if (brush_used[color])
|
||||||
Main_palette[color].B=Spare_palette[color].B;
|
{
|
||||||
|
// 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);
|
Set_palette(Main_palette);
|
||||||
Compute_optimal_menu_colors(Main_palette);
|
Compute_optimal_menu_colors(Main_palette);
|
||||||
@ -729,7 +776,6 @@ void Get_colors_from_brush(void)
|
|||||||
End_of_modification();
|
End_of_modification();
|
||||||
|
|
||||||
Main_image_is_modified=1;
|
Main_image_is_modified=1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user