Skip to content

Commit 6a3d770

Browse files
committed
save GIF palette as metadata
... if there are no local colour tables. See #2576
1 parent ceaa2d2 commit 6a3d770

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

libvips/foreign/nsgifload.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* - from gifload.c
55
* 3/3/22 tlsa
66
* - update libnsgif API
7+
*9/5/22
8+
- attach GIF palette as metadata
79
*/
810

911
/*
@@ -127,6 +129,10 @@ typedef struct _VipsForeignLoadNsgif {
127129
*/
128130
gboolean has_transparency;
129131

132+
/* If the GIF has any local palettes.
133+
*/
134+
gboolean local_palette;
135+
130136
/* The current frame bitmap and the frame number for it.
131137
*/
132138
nsgif_bitmap_t *bitmap;
@@ -289,6 +295,18 @@ vips_foreign_load_nsgif_set_header( VipsForeignLoadNsgif *gif,
289295
*/
290296
vips_image_set_int( image, "gif-delay", gif->gif_delay );
291297

298+
/* If there are no local palettes, we can attach the global palette as
299+
* metadata.
300+
*/
301+
if( !gif->local_palette ) {
302+
size_t entries;
303+
uint32_t table[NSGIF_MAX_COLOURS];
304+
305+
nsgif_global_palette( gif->anim, table, &entries );
306+
vips_image_set_array_int( image, "gif-palette",
307+
(const int *) table, entries );
308+
}
309+
292310
return( 0 );
293311
}
294312

@@ -342,10 +360,11 @@ vips_foreign_load_nsgif_header( VipsForeignLoad *load )
342360
for( i = 0; i < gif->info->frame_count; i++ ) {
343361
const nsgif_frame_info_t *frame_info;
344362

345-
frame_info = nsgif_get_frame_info( gif->anim, i );
346-
if( frame_info != NULL && frame_info->transparency ) {
347-
gif->has_transparency = TRUE;
348-
break;
363+
if( (frame_info = nsgif_get_frame_info( gif->anim, i )) ) {
364+
if( frame_info->transparency )
365+
gif->has_transparency = TRUE;
366+
if( frame_info->local_palette )
367+
gif->local_palette = TRUE;
349368
}
350369
}
351370

0 commit comments

Comments
 (0)