From 535be32236a5a1e383e69e0ccdc72bbf1378cf97 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 28 Jan 2025 12:01:31 +0100 Subject: [PATCH 1/2] colour: add support for auto-selecting the rendering intent Via the `VIPS_INTENT_AUTO` enum value. Resolves: #3475. --- ChangeLog | 1 + libvips/colour/icc_transform.c | 7 +++++-- libvips/include/vips/colour.h | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 18cb56c99c..55109778fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ - tiffload: add support for fail_on flag [lovell] - tiffload: add support for unlimited flag (requires libtiff 4.7.0+) [lovell] - much more reliable operation caching +- colour: add support for auto-selecting the rendering intent [kleisauke] 8.16.1 diff --git a/libvips/colour/icc_transform.c b/libvips/colour/icc_transform.c index 81e4a42469..6f0660a159 100644 --- a/libvips/colour/icc_transform.c +++ b/libvips/colour/icc_transform.c @@ -106,6 +106,7 @@ * @VIPS_INTENT_RELATIVE: relative colorimetric rendering intent * @VIPS_INTENT_SATURATION: saturation rendering intent * @VIPS_INTENT_ABSOLUTE: absolute colorimetric rendering intent + * @VIPS_INTENT_AUTO: the rendering intent that the profile suggests * * The rendering intent. #VIPS_INTENT_ABSOLUTE is best for * scientific work, #VIPS_INTENT_RELATIVE is usually best for @@ -620,16 +621,18 @@ vips_icc_load_profile_blob(VipsIcc *icc, VipsBlob *blob, } icc->selected_intent = icc->intent; - if (!cmsIsIntentSupported(profile, icc->intent, direction)) { + if (icc->intent == VIPS_INTENT_AUTO || + !cmsIsIntentSupported(profile, icc->intent, direction)) icc->selected_intent = (VipsIntent) cmsGetHeaderRenderingIntent( profile); + if (icc->intent != VIPS_INTENT_AUTO && + icc->selected_intent != icc->intent) g_warning(_("fallback to suggested %s intent, as profile " "does not support %s %s intent"), vips_enum_nick(VIPS_TYPE_INTENT, icc->selected_intent), vips_enum_nick(VIPS_TYPE_INTENT, icc->intent), direction == LCMS_USED_AS_INPUT ? _("input") : _("output")); - } #ifdef DEBUG vips_icc_print_profile("loaded from blob to make", profile); diff --git a/libvips/include/vips/colour.h b/libvips/include/vips/colour.h index ed52ccfe56..f9d03f6567 100644 --- a/libvips/include/vips/colour.h +++ b/libvips/include/vips/colour.h @@ -93,13 +93,15 @@ extern "C" { #define VIPS_D3250_Y0 (100.0) #define VIPS_D3250_Z0 (45.8501) -/* Note: constants align with those defined in lcms2.h. +/* Note: constants align with those defined in lcms2.h, except for + * VIPS_INTENT_AUTO, which is libvips-specific. */ typedef enum { VIPS_INTENT_PERCEPTUAL = 0, VIPS_INTENT_RELATIVE, VIPS_INTENT_SATURATION, VIPS_INTENT_ABSOLUTE, + VIPS_INTENT_AUTO, VIPS_INTENT_LAST } VipsIntent; From ff961875cc514ba763a166a39dfa338e1c146de2 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Wed, 29 Jan 2025 11:27:11 +0100 Subject: [PATCH 2/2] colour: leave room for possible new rendering intents --- libvips/include/vips/colour.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libvips/include/vips/colour.h b/libvips/include/vips/colour.h index f9d03f6567..4433f85cfc 100644 --- a/libvips/include/vips/colour.h +++ b/libvips/include/vips/colour.h @@ -101,7 +101,10 @@ typedef enum { VIPS_INTENT_RELATIVE, VIPS_INTENT_SATURATION, VIPS_INTENT_ABSOLUTE, - VIPS_INTENT_AUTO, + /* Leave room for possible new rendering intents beyond the + * four standard ones. + */ + VIPS_INTENT_AUTO = 32, VIPS_INTENT_LAST } VipsIntent;