|
4 | 4 | * - from gifload.c
|
5 | 5 | * 3/3/22 tlsa
|
6 | 6 | * - update libnsgif API
|
| 7 | + *9/5/22 |
| 8 | + - attach GIF palette as metadata |
7 | 9 | */
|
8 | 10 |
|
9 | 11 | /*
|
@@ -127,6 +129,10 @@ typedef struct _VipsForeignLoadNsgif {
|
127 | 129 | */
|
128 | 130 | gboolean has_transparency;
|
129 | 131 |
|
| 132 | + /* If the GIF has any local palettes. |
| 133 | + */ |
| 134 | + gboolean local_palette; |
| 135 | + |
130 | 136 | /* The current frame bitmap and the frame number for it.
|
131 | 137 | */
|
132 | 138 | nsgif_bitmap_t *bitmap;
|
@@ -289,6 +295,18 @@ vips_foreign_load_nsgif_set_header( VipsForeignLoadNsgif *gif,
|
289 | 295 | */
|
290 | 296 | vips_image_set_int( image, "gif-delay", gif->gif_delay );
|
291 | 297 |
|
| 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 | + |
292 | 310 | return( 0 );
|
293 | 311 | }
|
294 | 312 |
|
@@ -342,10 +360,11 @@ vips_foreign_load_nsgif_header( VipsForeignLoad *load )
|
342 | 360 | for( i = 0; i < gif->info->frame_count; i++ ) {
|
343 | 361 | const nsgif_frame_info_t *frame_info;
|
344 | 362 |
|
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; |
349 | 368 | }
|
350 | 369 | }
|
351 | 370 |
|
|
0 commit comments