Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 501fc38

Browse files
authored
Merge pull request #1362 from deftomat/master
fix: make gif-loop consistent between GIF and WEBP
2 parents 7906c12 + 982e323 commit 501fc38

File tree

6 files changed

+58
-14
lines changed

6 files changed

+58
-14
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = tab
6+
indent_size = 2
7+
charset = utf-8
8+
trim_trailing_whitespace = false
9+
insert_final_newline = true

libvips/foreign/gifload.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,11 @@ vips_foreign_load_gif_scan_application_ext( VipsForeignLoadGif *gif,
572572
if( have_netscape &&
573573
extension &&
574574
extension[0] == 3 &&
575-
extension[1] == 1 )
576-
gif->loop = extension[2] | (extension[3] << 8);
575+
extension[1] == 1 ) {
576+
gif->loop = extension[2] | (extension[3] << 8);
577+
if (gif->loop != 0)
578+
gif->loop = gif->loop + 1;
579+
}
577580
}
578581

579582
return( 0 );
@@ -676,7 +679,14 @@ vips_foreign_load_gif_set_header( VipsForeignLoadGif *gif, VipsImage *image )
676679
vips_image_set_int( image,
677680
VIPS_META_PAGE_HEIGHT, gif->file->SHeight );
678681
vips_image_set_int( image, VIPS_META_N_PAGES, gif->n_pages );
679-
vips_image_set_int( image, "gif-loop", gif->loop );
682+
vips_image_set_int( image, "loop", gif->loop );
683+
684+
/* DEPRECATED "gif-loop"
685+
*
686+
* Not the correct behavior as loop=1 became gif-loop=0
687+
* but we want to keep the old behavior untouched!
688+
*/
689+
vips_image_set_int( image, "gif-loop", gif->loop == 0 ? 0 : gif->loop - 1 );
680690

681691
if( gif->delays ) {
682692
/* The deprecated gif-delay field is in centiseconds.
@@ -1284,7 +1294,7 @@ vips_foreign_load_gif_init( VipsForeignLoadGif *gif )
12841294
gif->transparency = -1;
12851295
gif->delays = NULL;
12861296
gif->delays_length = 0;
1287-
gif->loop = 0;
1297+
gif->loop = 1;
12881298
gif->comment = NULL;
12891299
gif->dispose = 0;
12901300

libvips/foreign/magicksave.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,20 @@ vips_foreign_save_magick_next_image( VipsForeignSaveMagick *magick )
167167
* 1 - don't write the netscape extension block
168168
* 2 - loop once
169169
* 3 - loop twice etc.
170-
*
171-
* We have the simple gif meaning, so we must add one unless it's
172-
* zero.
173170
*/
174-
if( vips_image_get_typeof( im, "gif-loop" ) &&
175-
!vips_image_get_int( im, "gif-loop", &number ) )
176-
image->iterations = (size_t) (number ? number + 1 : 0);
171+
if( vips_image_get_typeof( im, "loop" ) &&
172+
!vips_image_get_int( im, "loop", &number ) ) {
173+
image->iterations = (size_t) (number ? number : 0);
174+
}
175+
else {
176+
/* DEPRECATED "gif-loop"
177+
*
178+
* We have the simple gif meaning, so we must add one unless it's zero.
179+
*/
180+
if( vips_image_get_typeof( im, "gif-loop" ) &&
181+
!vips_image_get_int( im, "gif-loop", &number ) )
182+
image->iterations = (size_t) (number ? number + 1 : 0);
183+
}
177184

178185
if( vips_image_get_typeof( im, "gif-comment" ) &&
179186
!vips_image_get_string( im, "gif-comment", &str ) )

libvips/foreign/vips2webp.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,23 @@ vips_webp_add_metadata( VipsWebPWrite *write )
484484
return( -1 );
485485
}
486486

487-
if( vips_image_get_typeof( write->image, "gif-loop" ) ) {
487+
if( vips_image_get_typeof( write->image, "loop" ) ) {
488+
int loop;
489+
490+
if( vips_image_get_int( write->image, "loop", &loop ) )
491+
return( -1 );
492+
493+
vips_webp_set_count( write, loop );
494+
}
495+
/* DEPRECATED "gif-loop"
496+
*/
497+
else if ( vips_image_get_typeof( write->image, "gif-loop" ) ) {
488498
int gif_loop;
489499

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

493-
vips_webp_set_count( write, gif_loop );
503+
vips_webp_set_count( write, gif_loop == 0 ? 0 : gif_loop + 1 );
494504
}
495505

496506
/* Add extra metadata.

libvips/foreign/webp2vips.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,15 @@ read_header( Read *read, VipsImage *out )
432432
printf( "webp2vips: frame_count = %d\n", read->frame_count );
433433
#endif /*DEBUG*/
434434

435-
vips_image_set_int( out, "gif-loop", loop_count );
435+
vips_image_set_int( out, "loop", loop_count );
436+
437+
/* DEPRECATED "gif-loop"
438+
*
439+
* Not the correct behavior as loop=1 became gif-loop=0
440+
* but we want to keep the old behavior untouched!
441+
*/
442+
vips_image_set_int( out, "gif-loop", loop_count == 0 ? 0 : loop_count - 1 );
443+
436444
vips_image_set_int( out,
437445
VIPS_META_PAGE_HEIGHT, read->frame_height );
438446

libvips/foreign/webpsave.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ vips_foreign_save_webp_mime_init( VipsForeignSaveWebpMime *mime )
548548
* frames between frames. Setting 0 means no keyframes. By default, keyframes
549549
* are disabled.
550550
*
551-
* Use the metadata items `gif-loop` and `delay` to set the number of
551+
* Use the metadata items `loop` and `delay` to set the number of
552552
* loops for the animation and the frame delays.
553553
*
554554
* The writer will attach ICC, EXIF and XMP metadata, unless @strip is set to

0 commit comments

Comments
 (0)