Skip to content

Commit

Permalink
nsgifload: add "palette-bit-depth" header (libvips#2828)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthSim authored Jun 1, 2022
1 parent 6260a37 commit c9b5b8c
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions libvips/foreign/nsgifload.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ vips_foreign_load_nsgif_set_header( VipsForeignLoadNsgif *gif,
{
double array[3];
const uint8_t *bg;
size_t entries;
uint32_t table[NSGIF_MAX_COLOURS];
int colours;

VIPS_DEBUG_MSG( "vips_foreign_load_nsgif_set_header:\n" );

Expand Down Expand Up @@ -299,14 +302,32 @@ vips_foreign_load_nsgif_set_header( VipsForeignLoadNsgif *gif,
* metadata.
*/
if( !gif->local_palette ) {
size_t entries;
uint32_t table[NSGIF_MAX_COLOURS];

nsgif_global_palette( gif->anim, table, &entries );
vips_image_set_array_int( image, "gif-palette",
(const int *) table, entries );
(const int *) table, entries );

colours = entries;
} else {
int i;

colours = 0;

if( gif->info->global_palette ) {
nsgif_global_palette( gif->anim, table, &entries );
colours = entries;
}

for( i = 0; i < gif->info->frame_count; i++ ) {
if( nsgif_local_palette( gif->anim, i, table,
&entries) ) {
colours = VIPS_MAX(colours, entries);
}
}
}

vips_image_set_int( image, "palette-bit-depth",
ceil( log2( colours ) ) );

return( 0 );
}

Expand Down

0 comments on commit c9b5b8c

Please sign in to comment.