Skip to content

Commit 917d6f0

Browse files
authored
colour: add support for auto-selecting the rendering intent (#4366)
* colour: add support for auto-selecting the rendering intent Via the `VIPS_INTENT_AUTO` enum value. Resolves: #3475. * colour: leave room for possible new rendering intents
1 parent 7e68ac6 commit 917d6f0

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- tiffload: add support for fail_on flag [lovell]
77
- tiffload: add support for unlimited flag (requires libtiff 4.7.0+) [lovell]
88
- much more reliable operation caching
9+
- colour: add support for auto-selecting the rendering intent [kleisauke]
910

1011
8.16.1
1112

libvips/colour/icc_transform.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
* @VIPS_INTENT_RELATIVE: relative colorimetric rendering intent
107107
* @VIPS_INTENT_SATURATION: saturation rendering intent
108108
* @VIPS_INTENT_ABSOLUTE: absolute colorimetric rendering intent
109+
* @VIPS_INTENT_AUTO: the rendering intent that the profile suggests
109110
*
110111
* The rendering intent. #VIPS_INTENT_ABSOLUTE is best for
111112
* scientific work, #VIPS_INTENT_RELATIVE is usually best for
@@ -620,16 +621,18 @@ vips_icc_load_profile_blob(VipsIcc *icc, VipsBlob *blob,
620621
}
621622

622623
icc->selected_intent = icc->intent;
623-
if (!cmsIsIntentSupported(profile, icc->intent, direction)) {
624+
if (icc->intent == VIPS_INTENT_AUTO ||
625+
!cmsIsIntentSupported(profile, icc->intent, direction))
624626
icc->selected_intent = (VipsIntent) cmsGetHeaderRenderingIntent(
625627
profile);
626628

629+
if (icc->intent != VIPS_INTENT_AUTO &&
630+
icc->selected_intent != icc->intent)
627631
g_warning(_("fallback to suggested %s intent, as profile "
628632
"does not support %s %s intent"),
629633
vips_enum_nick(VIPS_TYPE_INTENT, icc->selected_intent),
630634
vips_enum_nick(VIPS_TYPE_INTENT, icc->intent),
631635
direction == LCMS_USED_AS_INPUT ? _("input") : _("output"));
632-
}
633636

634637
#ifdef DEBUG
635638
vips_icc_print_profile("loaded from blob to make", profile);

libvips/include/vips/colour.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,18 @@ extern "C" {
9393
#define VIPS_D3250_Y0 (100.0)
9494
#define VIPS_D3250_Z0 (45.8501)
9595

96-
/* Note: constants align with those defined in lcms2.h.
96+
/* Note: constants align with those defined in lcms2.h, except for
97+
* VIPS_INTENT_AUTO, which is libvips-specific.
9798
*/
9899
typedef enum {
99100
VIPS_INTENT_PERCEPTUAL = 0,
100101
VIPS_INTENT_RELATIVE,
101102
VIPS_INTENT_SATURATION,
102103
VIPS_INTENT_ABSOLUTE,
104+
/* Leave room for possible new rendering intents beyond the
105+
* four standard ones.
106+
*/
107+
VIPS_INTENT_AUTO = 32,
103108
VIPS_INTENT_LAST
104109
} VipsIntent;
105110

0 commit comments

Comments
 (0)