From 3d29daf553adbe24d4375fb7ad487bc60d7b3cf3 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 3 Nov 2022 14:18:38 +0000 Subject: [PATCH] block use of RGB profiles with CMYK images Detect and block a common error. See https://github.com/libvips/libvips/issues/3139 --- libvips/colour/icc_transform.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/libvips/colour/icc_transform.c b/libvips/colour/icc_transform.c index efae0d57..003ce426 100644 --- a/libvips/colour/icc_transform.c +++ b/libvips/colour/icc_transform.c @@ -478,16 +478,16 @@ static void vips_icc_print_profile( const char *name, cmsHPROFILE profile ) { static const cmsInfoType info_types[] = { - cmsInfoDescription, - cmsInfoManufacturer, - cmsInfoModel, - cmsInfoCopyright + cmsInfoDescription, + cmsInfoManufacturer, + cmsInfoModel, + cmsInfoCopyright }; static const char *info_names[] = { - "description", - "manufacturer", - "model", - "copyright" + "description", + "manufacturer", + "model", + "copyright" }; int i; @@ -589,6 +589,16 @@ vips_icc_load_profile_blob( VipsBlob *blob, return( NULL ); } + /* Spot the common error of an RGB profile and a CMYK image. + */ + if( image && + image->Type == VIPS_INTERPRETATION_CMYK && + info->bands == 3 ) { + VIPS_FREEF( cmsCloseProfile, profile ); + g_warning( "%s", _( "profile incompatible with image" ) ); + return( NULL ); + } + if( !cmsIsIntentSupported( profile, intent, direction ) ) { VIPS_FREEF( cmsCloseProfile, profile ); g_warning( _( "profile does not support %s %s intent" ),