Permalink
Browse files

add n-pages metadata to gifload

gifload was not setting the n-pages metadata item.

n-pages is supposed to be the number of pages in the original file (not
the number of pages libvips loaded), but we don't always know this for
gif, since you have to decode the entire file to count the pages.

As a compromise, set it to the page number of the final page we read.

See lovell/sharp#1566
  • Loading branch information...
jcupitt committed Feb 8, 2019
1 parent 06d71f6 commit 2968bee3fa933f08a0f0bd4686eff43ee9176c55
Showing with 14 additions and 5 deletions.
  1. +12 −3 libvips/foreign/gifload.c
  2. +2 −2 libvips/foreign/webp2vips.c
@@ -653,7 +653,8 @@ vips_foreign_load_gif_extension( VipsForeignLoadGif *gif )

VIPS_DEBUG_MSG( "gifload: EXTENSION_RECORD_TYPE\n" );

if( DGifGetExtension( gif->file, &ext_code, &extension ) == GIF_ERROR ) {
if( DGifGetExtension( gif->file, &ext_code, &extension ) ==
GIF_ERROR ) {
vips_foreign_load_gif_error( gif );
return( -1 );
}
@@ -927,8 +928,16 @@ vips_foreign_load_gif_pages( VipsForeignLoadGif *gif, VipsImage **out )

unref_array( frames );

if( n_frames > 1 )
if( n_frames > 1 ) {
vips_image_set_int( *out, VIPS_META_PAGE_HEIGHT, t[0]->Ysize );

/* n-pages is supposed to be the number of pages in the file,
* but we'd need to scan the entire image to find that :( so
* just set it to the number of pages we've read so far.
*/
vips_image_set_int( *out, VIPS_META_N_PAGES,
gif->current_page );
}
vips_image_set_int( *out, "gif-delay", gif->delay );
vips_image_set_int( *out, "gif-loop", gif->loop );
if( gif->comment )
@@ -1201,7 +1210,7 @@ vips_foreign_load_gif_buffer_init( VipsForeignLoadGifBuffer *buffer )
* * @page: %gint, page (frame) to read
* * @n: %gint, load this many pages
*
* Read a GIF file into a VIPS image. Rendering uses the giflib library.
* Read a GIF file into a VIPS image.
*
* Use @page to select a page to render, numbering from zero.
*
@@ -108,7 +108,7 @@ typedef struct {
*/
int alpha;

/* Number of frames we will decode.
/* Number of frames in file.
*/
int frame_count;

@@ -477,7 +477,7 @@ read_header( Read *read, VipsImage *out )
/* Note that n-pages is the number of pages in the original,
* not the number of pages in the image we are writing.
*/
vips_image_set_int( out, "n-pages", read->frame_count );
vips_image_set_int( out, VIPS_META_N_PAGES, read->frame_count );

read->width = read->frame_width;
read->height = read->n * read->frame_height;

0 comments on commit 2968bee

Please sign in to comment.