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