From ab7ef2c2bc71394f084098c85a74ffa104ef856d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Szabo?= Date: Mon, 8 Jul 2019 14:28:48 +0200 Subject: [PATCH 1/4] fix: make gif-loop consistent between GIF and WEBP --- libvips/foreign/gifload.c | 9 ++++++--- libvips/foreign/magicksave.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libvips/foreign/gifload.c b/libvips/foreign/gifload.c index 4f8ceec8ba..a34ed8bbca 100644 --- a/libvips/foreign/gifload.c +++ b/libvips/foreign/gifload.c @@ -471,8 +471,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 ); @@ -1142,7 +1145,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; } diff --git a/libvips/foreign/magicksave.c b/libvips/foreign/magicksave.c index 68a80e31f8..5eee1a209e 100644 --- a/libvips/foreign/magicksave.c +++ b/libvips/foreign/magicksave.c @@ -169,7 +169,7 @@ vips_foreign_save_magick_next_image( VipsForeignSaveMagick *magick ) */ if( vips_image_get_typeof( im, "gif-loop" ) && !vips_image_get_int( im, "gif-loop", &number ) ) - image->iterations = (size_t) (number ? number + 1 : 0); + image->iterations = (size_t) (number ? number : 0); if( vips_image_get_typeof( im, "gif-comment" ) && !vips_image_get_string( im, "gif-comment", &str ) ) From d14e0d5c9790637c0b5310ed4298751b1ddb9dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Szabo?= Date: Tue, 17 Dec 2019 07:28:28 +0100 Subject: [PATCH 2/4] feat: add normalized `loop` field --- libvips/foreign/gifload.c | 9 ++++++++- libvips/foreign/magicksave.c | 17 ++++++++++++----- libvips/foreign/vips2webp.c | 18 ++++++++++++++---- libvips/foreign/webp2vips.c | 10 +++++++++- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/libvips/foreign/gifload.c b/libvips/foreign/gifload.c index a34ed8bbca..04e51f5ee7 100644 --- a/libvips/foreign/gifload.c +++ b/libvips/foreign/gifload.c @@ -590,7 +590,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. diff --git a/libvips/foreign/magicksave.c b/libvips/foreign/magicksave.c index 5eee1a209e..8e47f16b8e 100644 --- a/libvips/foreign/magicksave.c +++ b/libvips/foreign/magicksave.c @@ -163,13 +163,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 ) ) + 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 ) ) diff --git a/libvips/foreign/vips2webp.c b/libvips/foreign/vips2webp.c index a1dda93961..ca0df25c46 100644 --- a/libvips/foreign/vips2webp.c +++ b/libvips/foreign/vips2webp.c @@ -478,13 +478,23 @@ vips_webp_add_metadata( VipsWebPWrite *write, VipsImage *image, gboolean strip ) return( -1 ); } - if( vips_image_get_typeof( image, "gif-loop" ) ) { - int gif_loop; + if( vips_image_get_typeof( image, "loop" ) ) { + int loop; - if( vips_image_get_int( image, "gif-loop", &gif_loop ) ) + if( vips_image_get_int( image, "loop", &loop ) ) return( -1 ); - vips_webp_set_count( write, gif_loop ); + vips_webp_set_count( write, loop ); + } + /* DEPRECATED "gif-loop" + */ + else if ( vips_image_get_typeof( image, "gif-loop" ) ) { + int loop; + + if( vips_image_get_int( image, "gif-loop", &loop ) ) + return( -1 ); + + vips_webp_set_count( write, loop == 0 ? 0 : loop + 1 ); } /* Add extra metadata. diff --git a/libvips/foreign/webp2vips.c b/libvips/foreign/webp2vips.c index 7e28015e46..bf03555eff 100644 --- a/libvips/foreign/webp2vips.c +++ b/libvips/foreign/webp2vips.c @@ -473,7 +473,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 ); From bff5e6a78d5103f3c62a5bb3a796e8d477a38065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Szabo?= Date: Tue, 17 Dec 2019 07:28:40 +0100 Subject: [PATCH 3/4] chore: add .editorconfig --- .editorconfig | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..45858a8dff --- /dev/null +++ b/.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 From 982e323c71aff765ccc770075f432ce30df31893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Szabo?= Date: Tue, 17 Dec 2019 16:28:04 +0100 Subject: [PATCH 4/4] docs: replace `gif-loop` with `loop` --- libvips/foreign/webpsave.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvips/foreign/webpsave.c b/libvips/foreign/webpsave.c index 49f9308109..5b945a6094 100644 --- a/libvips/foreign/webpsave.c +++ b/libvips/foreign/webpsave.c @@ -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