diff --git a/ChangeLog b/ChangeLog index b9546743..32a76e18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,10 @@ - add vips_thumbnail_image() - better prefix guessing on Windows, thanks tumagonx +12/6/17 started 8.5.7 +- transform cmyk->rgb automatically on write if there's an embedded profile + and the saver does not support cmyk + 19/5/17 started 8.5.6 - tiff read with start page > 0 could break edge tiles or strips - raise b64 limit to allow for huge profiles (thanks jaume) diff --git a/libvips/colour/icc_transform.c b/libvips/colour/icc_transform.c index f41c12c9..bd92d52a 100644 --- a/libvips/colour/icc_transform.c +++ b/libvips/colour/icc_transform.c @@ -596,6 +596,7 @@ static int vips_icc_import_build( VipsObject *object ) { VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); + VipsColour *colour = (VipsColour *) object; VipsColourCode *code = (VipsColourCode *) object; VipsIcc *icc = (VipsIcc *) object; VipsIccImport *import = (VipsIccImport *) object; diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index bed64b7c..9452401b 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -14,6 +14,8 @@ * - forward progress signals from load * 23/5/16 * - remove max-alpha stuff, this is now automatic + * 12/6/17 + * - transform cmyk->rgb if there's an embedded profile */ /* @@ -1190,6 +1192,37 @@ vips__foreign_convert_saveable( VipsImage *in, VipsImage **ready, } } + /* If this image is CMYK and the saver is RGB-only, use lcms to try to + * import to XYZ. This will only work if the image has an embedded + * profile. + */ + if( in->Type == VIPS_INTERPRETATION_CMYK && + in->Bands >= 4 && + (saveable == VIPS_SAVEABLE_RGB || + saveable == VIPS_SAVEABLE_RGBA || + saveable == VIPS_SAVEABLE_RGBA_ONLY) ) { + VipsImage *out; + + if( vips_icc_import( in, &out, + "pcs", VIPS_PCS_XYZ, + NULL ) ) { + g_object_unref( in ); + return( -1 ); + } + g_object_unref( in ); + + in = out; + + /* We've imported to PCS, we must remove the embedded profile, + * since it no longer matches the image. + * + * For example, when converting CMYK JPG to RGB PNG, we need + * to remove the CMYK profile on import, or the png writer will + * try to attach it when we write the image as RGB. + */ + vips_image_remove( in, VIPS_META_ICC_NAME ); + } + /* If this is something other than CMYK or RAD, eg. maybe a LAB image, * we need to transform to RGB. */