Current_layer_count_used_colors() for use with Save_xxx functions

This commit is contained in:
Thomas Bernard 2020-12-22 22:58:45 +01:00
parent 9ed89cc860
commit 28a20734d9
3 changed files with 27 additions and 1 deletions

View File

@ -373,7 +373,7 @@ void Save_SGX(T_IO_Context * context)
int i; int i;
File_error = 1; File_error = 1;
n_colors = Count_used_colors(color_usage); n_colors = Current_layer_count_used_colors(context, color_usage);
for (i = 16; i < 256; i++) for (i = 16; i < 256; i++)
{ {
if (color_usage[i] != 0) if (color_usage[i] != 0)

View File

@ -324,3 +324,27 @@ void Palette_64_to_256(T_Palette palette)
palette[i].B = (palette[i].B << 2)|(palette[i].B >> 4); palette[i].B = (palette[i].B << 2)|(palette[i].B >> 4);
} }
} }
word Current_layer_count_used_colors(T_IO_Context *context, dword *usage)
{
dword nb_colors = 0;
int i;
word x, y;
for (i = 0; i < 256; i++) usage[i] = 0;
for (y = 0; y < context->Height; y++)
{
for (x = 0; x < context->Width; x++)
usage[Get_pixel(context, x, y)]++;
}
// count the total number of unique used colors
for (i = 0; i < 256; i++)
{
if (usage[i] != 0)
nb_colors++;
}
return nb_colors;
}

View File

@ -45,4 +45,6 @@ FILE * Open_file_write_with_alternate_ext(T_IO_Context *context, const char * ex
void Palette_256_to_64(T_Palette palette); void Palette_256_to_64(T_Palette palette);
void Palette_64_to_256(T_Palette palette); void Palette_64_to_256(T_Palette palette);
word Current_layer_count_used_colors(T_IO_Context *context, dword *usage);
#endif #endif