diff --git a/libvips/iofuncs/cache.c b/libvips/iofuncs/cache.c index d8db2e3a..9129b152 100644 --- a/libvips/iofuncs/cache.c +++ b/libvips/iofuncs/cache.c @@ -445,16 +445,22 @@ vips_operation_equal( VipsOperation *a, VipsOperation *b ) return( FALSE ); } +void * +vips__cache_once_init( void ) +{ + vips_cache_lock = vips_g_mutex_new(); + + vips_cache_table = g_hash_table_new( + (GHashFunc) vips_operation_hash, + (GEqualFunc) vips_operation_equal ); +} + void vips__cache_init( void ) { - if( !vips_cache_table ) { - vips_cache_lock = vips_g_mutex_new(); + static GOnce once = G_ONCE_INIT; - vips_cache_table = g_hash_table_new( - (GHashFunc) vips_operation_hash, - (GEqualFunc) vips_operation_equal ); - } + g_once( &once, (GThreadFunc) vips__cache_once_init, NULL ); } static void * diff --git a/libvips/resample/thumbnail.c b/libvips/resample/thumbnail.c index 53d35a11..672c7b1a 100644 --- a/libvips/resample/thumbnail.c +++ b/libvips/resample/thumbnail.c @@ -281,8 +281,7 @@ vips_thumbnail_open( VipsThumbnail *thumbnail ) } else if( vips_isprefix( "VipsForeignLoadPdf", thumbnail->loader ) || vips_isprefix( "VipsForeignLoadSvg", thumbnail->loader ) ) { - scale = 1.0 / - vips_thumbnail_calculate_common_shrink( thumbnail, + scale = 1.0 / vips_thumbnail_calculate_common_shrink( thumbnail, thumbnail->input_width, thumbnail->input_height ); g_info( "loading PDF/SVG with factor %g pre-scale", scale ); @@ -698,6 +697,11 @@ vips_thumbnail_file_open( VipsThumbnail *thumbnail, int shrink, double scale ) { VipsThumbnailFile *file = (VipsThumbnailFile *) thumbnail; + /* If both shrink and scale have been set, something is wrong. It + * should be one or the other (or neither). + */ + g_assert( shrink == 1 || scale == 1.0 ); + if( shrink != 1 ) return( vips_image_new_from_file( file->filename, "access", VIPS_ACCESS_SEQUENTIAL,