Vips: Skip all images that already have an ICC profile #5389

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2025-12-29 10:14:13 +01:00
parent 69acd58e12
commit 79a5afd2f5

View file

@ -27,6 +27,10 @@ const (
// but lacks an embedded profile. If an ICC profile is already present, it
// leaves the image untouched.
func vipsSetIccProfileForInteropIndex(img *vips.ImageRef, logName string) (err error) {
if img.HasICCProfile() {
return nil
}
// Some cameras signal color space via EXIF InteroperabilityIndex instead of
// embedding an ICC profile. Browsers and libvips ignore this tag, so we
// inject a matching ICC profile to produce correct thumbnails.
@ -54,19 +58,14 @@ func vipsSetIccProfileForInteropIndex(img *vips.ImageRef, logName string) (err e
// a string with a trailing space. Using the first three bytes covers the
// meaningful code (e.g., "R03", "R98").
if len(iiFull) < 3 {
log.Debugf("interopindex: %s has unexpected interop index %q", logName, iiFull)
log.Debugf("vips: %s has unexpected interop index %q", logName, iiFull)
return nil
}
ii := iiFull[:3]
log.Tracef("interopindex: %s read exif and got interopindex %s, %s", logName, ii, iiFull)
log.Tracef("vips: %s read exif and got interopindex %s, %s", logName, ii, iiFull)
if img.HasICCProfile() {
log.Debugf("interopindex: %s already has an embedded ICC profile; skipping fallback.", logName)
return nil
}
profilePath := ""
var profilePath string
switch ii {
case InteropIndexAdobeRGB:
@ -74,14 +73,14 @@ func vipsSetIccProfileForInteropIndex(img *vips.ImageRef, logName string) (err e
profilePath, err = GetIccProfile(IccAdobeRGBCompat, IccAdobeRGBCompatV2, IccAdobeRGBCompatV4)
if err != nil {
return fmt.Errorf("interopindex %s: %w", ii, err)
return fmt.Errorf("vips: failed to get %s profile for %s (%w)", ii, logName, err)
}
case InteropIndexSRGB:
// sRGB: browsers and libvips assume sRGB by default, so no embed needed.
case InteropIndexThumb:
// Thumbnail file; specification unclear—treat as sRGB and do nothing.
default:
log.Debugf("interopindex: %s has unknown interop index %s", logName, ii)
log.Debugf("vips: %s has unknown interop index %s", logName, ii)
}
if profilePath == "" {