feat: add normalized `loop` field

This commit is contained in:
Tomáš Szabo 2019-12-17 07:28:28 +01:00
parent ab7ef2c2bc
commit d14e0d5c97
No known key found for this signature in database
GPG Key ID: 96F1E84929851783
4 changed files with 43 additions and 11 deletions

View File

@ -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.

View File

@ -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 ) )

View File

@ -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.

View File

@ -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 );