From e4461ae1f95df230db8fb5f50b0be456ef7bf078 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 12 Sep 2014 10:51:49 +0100 Subject: [PATCH] fix vipsthumbnail with broken embedded profiles if the embedded profile is broken or incompatible with the specified output profile, retry with the specified input profile see https://github.com/jcupitt/libvips/issues/178 --- ChangeLog | 2 ++ tools/vipsthumbnail.c | 52 +++++++++++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 394f2ecb..ccef284f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ - support GRAY as an input and output ICC space - fix a read loop with setjmp() in png read, if the png file is broken - fix vipsthumbnail with both input cmyk and output rgb profiles specified +- vipsthumbnail retries with specified input profile if embedded profile is + broken 8/9/14 started 7.40.8 - fix configure on rhel6 [Lovell] diff --git a/tools/vipsthumbnail.c b/tools/vipsthumbnail.c index 164cf598..6ebb8e99 100644 --- a/tools/vipsthumbnail.c +++ b/tools/vipsthumbnail.c @@ -58,6 +58,9 @@ * - add an anti-alias filter between shrink and affine * - support CMYK * - use SEQ_UNBUF for a memory saving + * 12/9/14 + * - try with embedded profile first, if that fails retry with fallback + * profile */ #ifdef HAVE_CONFIG_H @@ -567,23 +570,48 @@ thumbnail_shrink( VipsObject *process, VipsImage *in, else if( export_profile && (vips_image_get_typeof( in, VIPS_META_ICC_NAME ) || import_profile) ) { - if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) - vips_info( "vipsthumbnail", - "importing with embedded profile" ); - else - vips_info( "vipsthumbnail", - "importing with profile %s", import_profile ); + VipsImage *out; vips_info( "vipsthumbnail", "exporting with profile %s", export_profile ); - if( vips_icc_transform( in, &t[7], export_profile, - "input_profile", import_profile, - "embedded", TRUE, - NULL ) ) - return( NULL ); + /* We first try with the embedded profile, if any, then if + * that fails try again with the supplied fallback profile. + */ + out = NULL; + if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) { + vips_info( "vipsthumbnail", + "importing with embedded profile" ); - in = t[7]; + if( vips_icc_transform( in, &t[7], export_profile, + "embedded", TRUE, + NULL ) ) { + vips_warn( "vipsthumbnail", + _( "unable to import with " + "embedded profile: %s" ), + vips_error_buffer() ); + + vips_error_clear(); + } + else + out = t[7]; + } + + if( !out && + import_profile ) { + vips_info( "vipsthumbnail", + "importing with fallback profile" ); + + if( vips_icc_transform( in, &t[7], export_profile, + "input_profile", import_profile, + "embedded", FALSE, + NULL ) ) + return( NULL ); + + out = t[7]; + } + + in = out; } /* If we are upsampling, don't sharpen, since nearest looks dumb