Merge branch '8.10'

This commit is contained in:
John Cupitt 2021-03-14 11:03:40 +00:00
commit 8d6f90c060
2 changed files with 15 additions and 3 deletions

View File

@ -328,11 +328,18 @@ write_webp_anim( VipsWebPWrite *write, VipsImage *image, int page_height )
/* There might just be the old gif-delay field. This is centiseconds. /* There might just be the old gif-delay field. This is centiseconds.
*/ */
gif_delay = 4; gif_delay = 10;
if( vips_image_get_typeof( image, "gif-delay" ) && if( vips_image_get_typeof( image, "gif-delay" ) &&
vips_image_get_int( image, "gif-delay", &gif_delay ) ) vips_image_get_int( image, "gif-delay", &gif_delay ) )
return( -1 ); return( -1 );
/* Force frames with a small or no duration to 100ms
* to be consistent with web browsers and other
* transcoding tools.
*/
if( gif_delay <= 1 )
gif_delay = 10;
/* New images have an array of ints instead. /* New images have an array of ints instead.
*/ */
delay = NULL; delay = NULL;
@ -371,7 +378,8 @@ write_webp_anim( VipsWebPWrite *write, VipsImage *image, int page_height )
page_index = top / page_height; page_index = top / page_height;
if( delay && if( delay &&
page_index < delay_length ) page_index < delay_length )
timestamp_ms += delay[page_index]; timestamp_ms += delay[page_index] <= 10 ?
100 : delay[page_index];
else else
timestamp_ms += gif_delay * 10; timestamp_ms += gif_delay * 10;
} }

View File

@ -681,10 +681,14 @@ class TestForeign:
x1 = pyvips.Image.new_from_file(GIF_ANIM_FILE, n=-1) x1 = pyvips.Image.new_from_file(GIF_ANIM_FILE, n=-1)
w1 = x1.webpsave_buffer(Q=10) w1 = x1.webpsave_buffer(Q=10)
# our test gif has delay 0 for the first frame set in error,
# when converting to WebP this should result in a 100ms delay.
expected_delay = [100 if d <= 10 else d for d in x1.get("delay")]
x2 = pyvips.Image.new_from_buffer(w1, "", n=-1) x2 = pyvips.Image.new_from_buffer(w1, "", n=-1)
assert x1.width == x2.width assert x1.width == x2.width
assert x1.height == x2.height assert x1.height == x2.height
assert x1.get("delay") == x2.get("delay") assert expected_delay == x2.get("delay")
assert x1.get("page-height") == x2.get("page-height") assert x1.get("page-height") == x2.get("page-height")
assert x1.get("gif-loop") == x2.get("gif-loop") assert x1.get("gif-loop") == x2.get("gif-loop")