prevent over-pre-shrink in thumbnail

We could pre-shrink so much that an axis went to 0.

See https://github.com/lovell/sharp/issues/1782#issuecomment-525249430
This commit is contained in:
John Cupitt 2019-08-27 14:47:36 +01:00
parent 32e944349d
commit d61a85f6c9
2 changed files with 15 additions and 19 deletions

View File

@ -13,6 +13,7 @@
- better feof() handling in GIF load
- clip coding and interpretation on vips image read
- check image bounds for GIF load
- prevent over-pre-shrink in thumbnail [kleisauke]
24/5/19 started 8.8.1
- improve realpath() use on older libc

View File

@ -22,6 +22,8 @@
* - don't force import CMYK, since colourspace knows about it now
* 24/4/19
* - support multi-page (animated) images
* 27/8/19 kleisauke
* - prevent over-pre-shrink in thumbnail
*/
/*
@ -464,36 +466,24 @@ vips_thumbnail_open( VipsThumbnail *thumbnail )
factor = 1.0;
if( vips_isprefix( "VipsForeignLoadJpeg", thumbnail->loader ) ) {
if( vips_isprefix( "VipsForeignLoadJpeg", thumbnail->loader ) )
factor = vips_thumbnail_find_jpegshrink( thumbnail,
thumbnail->input_width, thumbnail->input_height );
g_info( "loading jpeg with factor %g pre-shrink", factor );
}
else if( vips_isprefix( "VipsForeignLoadTiff", thumbnail->loader ) ||
vips_isprefix( "VipsForeignLoadOpenslide",
thumbnail->loader ) ) {
thumbnail->loader ) )
factor = vips_thumbnail_find_pyrlevel( thumbnail,
thumbnail->input_width, thumbnail->input_height );
g_info( "loading pyr level %g", factor );
}
else if( vips_isprefix( "VipsForeignLoadPdf", thumbnail->loader ) ) {
else if( vips_isprefix( "VipsForeignLoadPdf", thumbnail->loader ) )
factor = 1.0 /
vips_thumbnail_calculate_common_shrink( thumbnail,
thumbnail->input_width,
thumbnail->page_height );
g_info( "loading PDF with factor %g pre-scale", factor );
}
else if( vips_isprefix( "VipsForeignLoadSvg", thumbnail->loader ) ) {
else if( vips_isprefix( "VipsForeignLoadSvg", thumbnail->loader ) )
factor = 1.0 /
vips_thumbnail_calculate_common_shrink( thumbnail,
thumbnail->input_width,
thumbnail->input_height );
g_info( "loading SVG with factor %g pre-scale", factor );
}
else if( vips_isprefix( "VipsForeignLoadHeif", thumbnail->loader ) ) {
/* 'factor' is a gboolean which enables thumbnail load instead
* of image load.
@ -507,14 +497,19 @@ vips_thumbnail_open( VipsThumbnail *thumbnail )
factor = 0.0;
}
else if( vips_isprefix( "VipsForeignLoadWebp", thumbnail->loader ) ) {
else if( vips_isprefix( "VipsForeignLoadWebp", thumbnail->loader ) )
factor = 1.0 /
vips_thumbnail_calculate_common_shrink( thumbnail,
thumbnail->input_width,
thumbnail->page_height );
g_info( "loading webp with factor %g pre-scale", factor );
}
/* We don't want to pre-shrink so much that we send an axis to 0.
*/
if( factor > thumbnail->input_width ||
factor > thumbnail->input_height )
factor = 1.0;
g_info( "loading with factor %g pre-shrink", factor );
if( !(im = class->open( thumbnail, factor )) )
return( NULL );