From ce31c04cd28ab4d2c2872dd94d69b8e337ad0738 Mon Sep 17 00:00:00 2001 From: Sergey Alexandrovich Date: Fri, 9 Sep 2022 00:05:42 +0600 Subject: [PATCH] nsgifload: choose tile-height based on page height (#2996) --- libvips/foreign/nsgifload.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/libvips/foreign/nsgifload.c b/libvips/foreign/nsgifload.c index dc915af1..ac6deaac 100644 --- a/libvips/foreign/nsgifload.c +++ b/libvips/foreign/nsgifload.c @@ -487,6 +487,26 @@ vips_foreign_load_nsgif_generate( VipsRegion *or, return( 0 ); } +int +vips_foreign_load_nsgif_tile_height(VipsForeignLoadNsgif *gif) { + int i; + int height = gif->info->height; + + // First, check the perfect size + if (height % 16 == 0) + return 16; + + // Next, check larger and smaller sizes + for (i = 1; i < 16; i++) { + if (height % (16 + i) == 0) + return (16 + i); + if (height % (16 - i) == 0) + return (16 - i); + } + + return 1; +} + static int vips_foreign_load_nsgif_load( VipsForeignLoad *load ) { @@ -507,7 +527,7 @@ vips_foreign_load_nsgif_load( VipsForeignLoad *load ) if( vips_image_generate( t[0], NULL, vips_foreign_load_nsgif_generate, NULL, gif, NULL ) || vips_sequential( t[0], &t[1], - "tile_height", VIPS__FATSTRIP_HEIGHT, + "tile_height", vips_foreign_load_nsgif_tile_height(gif), NULL ) || vips_image_write( t[1], load->real ) ) return( -1 );