Skip to content

Commit

Permalink
Merge pull request #1362 from deftomat/master
Browse files Browse the repository at this point in the history
fix: make gif-loop consistent between GIF and WEBP
  • Loading branch information
jcupitt committed Dec 18, 2019
2 parents 7906c12 + 982e323 commit 501fc38
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 14 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
@@ -0,0 +1,9 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
indent_size = 2
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
18 changes: 14 additions & 4 deletions libvips/foreign/gifload.c
Expand Up @@ -572,8 +572,11 @@ vips_foreign_load_gif_scan_application_ext( VipsForeignLoadGif *gif,
if( have_netscape &&
extension &&
extension[0] == 3 &&
extension[1] == 1 )
gif->loop = extension[2] | (extension[3] << 8);
extension[1] == 1 ) {
gif->loop = extension[2] | (extension[3] << 8);
if (gif->loop != 0)
gif->loop = gif->loop + 1;
}
}

return( 0 );
Expand Down Expand Up @@ -676,7 +679,14 @@ vips_foreign_load_gif_set_header( VipsForeignLoadGif *gif, VipsImage *image )
vips_image_set_int( image,
VIPS_META_PAGE_HEIGHT, gif->file->SHeight );
vips_image_set_int( image, VIPS_META_N_PAGES, gif->n_pages );
vips_image_set_int( image, "gif-loop", gif->loop );
vips_image_set_int( image, "loop", gif->loop );

/* DEPRECATED "gif-loop"
*
* Not the correct behavior as loop=1 became gif-loop=0
* but we want to keep the old behavior untouched!
*/
vips_image_set_int( image, "gif-loop", gif->loop == 0 ? 0 : gif->loop - 1 );

if( gif->delays ) {
/* The deprecated gif-delay field is in centiseconds.
Expand Down Expand Up @@ -1284,7 +1294,7 @@ vips_foreign_load_gif_init( VipsForeignLoadGif *gif )
gif->transparency = -1;
gif->delays = NULL;
gif->delays_length = 0;
gif->loop = 0;
gif->loop = 1;
gif->comment = NULL;
gif->dispose = 0;

Expand Down
19 changes: 13 additions & 6 deletions libvips/foreign/magicksave.c
Expand Up @@ -167,13 +167,20 @@ vips_foreign_save_magick_next_image( VipsForeignSaveMagick *magick )
* 1 - don't write the netscape extension block
* 2 - loop once
* 3 - loop twice etc.
*
* We have the simple gif meaning, so we must add one unless it's
* zero.
*/
if( vips_image_get_typeof( im, "gif-loop" ) &&
!vips_image_get_int( im, "gif-loop", &number ) )
image->iterations = (size_t) (number ? number + 1 : 0);
if( vips_image_get_typeof( im, "loop" ) &&
!vips_image_get_int( im, "loop", &number ) ) {
image->iterations = (size_t) (number ? number : 0);
}
else {
/* DEPRECATED "gif-loop"
*
* We have the simple gif meaning, so we must add one unless it's zero.
*/
if( vips_image_get_typeof( im, "gif-loop" ) &&
!vips_image_get_int( im, "gif-loop", &number ) )
image->iterations = (size_t) (number ? number + 1 : 0);
}

if( vips_image_get_typeof( im, "gif-comment" ) &&
!vips_image_get_string( im, "gif-comment", &str ) )
Expand Down
14 changes: 12 additions & 2 deletions libvips/foreign/vips2webp.c
Expand Up @@ -484,13 +484,23 @@ vips_webp_add_metadata( VipsWebPWrite *write )
return( -1 );
}

if( vips_image_get_typeof( write->image, "gif-loop" ) ) {
if( vips_image_get_typeof( write->image, "loop" ) ) {
int loop;

if( vips_image_get_int( write->image, "loop", &loop ) )
return( -1 );

vips_webp_set_count( write, loop );
}
/* DEPRECATED "gif-loop"
*/
else if ( vips_image_get_typeof( write->image, "gif-loop" ) ) {
int gif_loop;

if( vips_image_get_int( write->image, "gif-loop", &gif_loop ) )
return( -1 );

vips_webp_set_count( write, gif_loop );
vips_webp_set_count( write, gif_loop == 0 ? 0 : gif_loop + 1 );
}

/* Add extra metadata.
Expand Down
10 changes: 9 additions & 1 deletion libvips/foreign/webp2vips.c
Expand Up @@ -432,7 +432,15 @@ read_header( Read *read, VipsImage *out )
printf( "webp2vips: frame_count = %d\n", read->frame_count );
#endif /*DEBUG*/

vips_image_set_int( out, "gif-loop", loop_count );
vips_image_set_int( out, "loop", loop_count );

/* DEPRECATED "gif-loop"
*
* Not the correct behavior as loop=1 became gif-loop=0
* but we want to keep the old behavior untouched!
*/
vips_image_set_int( out, "gif-loop", loop_count == 0 ? 0 : loop_count - 1 );

vips_image_set_int( out,
VIPS_META_PAGE_HEIGHT, read->frame_height );

Expand Down
2 changes: 1 addition & 1 deletion libvips/foreign/webpsave.c
Expand Up @@ -548,7 +548,7 @@ vips_foreign_save_webp_mime_init( VipsForeignSaveWebpMime *mime )
* frames between frames. Setting 0 means no keyframes. By default, keyframes
* are disabled.
*
* Use the metadata items `gif-loop` and `delay` to set the number of
* Use the metadata items `loop` and `delay` to set the number of
* loops for the animation and the frame delays.
*
* The writer will attach ICC, EXIF and XMP metadata, unless @strip is set to
Expand Down

0 comments on commit 501fc38

Please sign in to comment.