From 302bf64ea2a6275b35f088aa8c699bd68d84c24e Mon Sep 17 00:00:00 2001 From: DarthSim Date: Fri, 25 Jun 2021 13:28:33 +0600 Subject: [PATCH] Remove ICC hacks; Enable ICC support for PNG --- CHANGELOG.md | 2 ++ image_type.go | 1 + process.go | 2 +- vips.c | 25 ------------------------- vips.go | 16 ++++++---------- vips.h | 1 - 6 files changed, 10 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d51e7fa1..6a39351a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## [Unreleased] +### Fix +- Fix ICC profile handling in some cases. ## [2.16.4] - 2021-06-16 ### Change diff --git a/image_type.go b/image_type.go index 0d07c7ca..ef3106f3 100644 --- a/image_type.go +++ b/image_type.go @@ -128,6 +128,7 @@ func (it imageType) SupportsAlpha() bool { func (it imageType) SupportsColourProfile() bool { return it == imageTypeJPEG || + it == imageTypePNG || it == imageTypeWEBP || it == imageTypeAVIF } diff --git a/process.go b/process.go index 94c60dac..05cb6997 100644 --- a/process.go +++ b/process.go @@ -397,7 +397,7 @@ func transformImage(ctx context.Context, img *vipsImage, data []byte, po *proces iccImported := false convertToLinear := conf.UseLinearColorspace && scale != 1 - if convertToLinear || !img.IsSRGB() { + if convertToLinear { if err = img.ImportColourProfile(); err != nil { return err } diff --git a/vips.c b/vips.c index 910e6db7..7fe81373 100644 --- a/vips.c +++ b/vips.c @@ -355,31 +355,6 @@ vips_resize_with_premultiply(VipsImage *in, VipsImage **out, double scale) { return 0; } -int -vips_icc_is_srgb_iec61966(VipsImage *in) { - VIPS_BLOB_DATA_TYPE data; - size_t data_len; - - // 1998-12-01 - static char date[] = { 7, 206, 0, 2, 0, 9 }; - // 2.1 - static char version[] = { 2, 16, 0, 0 }; - - if (vips_image_get_blob(in, VIPS_META_ICC_NAME, &data, &data_len)) - return FALSE; - - // Less than header size - if (data_len < 128) - return FALSE; - - // Predict it is sRGB IEC61966 2.1 by checking some header fields - return ((memcmp(data + 48, "IEC ", 4) == 0) && // Device manufacturer - (memcmp(data + 52, "sRGB", 4) == 0) && // Device model - (memcmp(data + 80, "HP ", 4) == 0) && // Profile creator - (memcmp(data + 24, date, 6) == 0) && // Date of creation - (memcmp(data + 8, version, 4) == 0)); // Version -} - int vips_has_embedded_icc(VipsImage *in) { return vips_image_get_typeof(in, VIPS_META_ICC_NAME) != 0; diff --git a/vips.go b/vips.go index d13814da..4dacd360 100644 --- a/vips.go +++ b/vips.go @@ -578,8 +578,8 @@ func (img *vipsImage) ImportColourProfile() error { func (img *vipsImage) ExportColourProfile() error { var tmp *C.VipsImage - // Don't export is there's no embedded profile or embedded profile is sRGB - if C.vips_has_embedded_icc(img.VipsImage) == 0 || C.vips_icc_is_srgb_iec61966(img.VipsImage) == 1 { + // Don't export is there's no embedded profile + if C.vips_has_embedded_icc(img.VipsImage) == 0 { return nil } @@ -595,8 +595,8 @@ func (img *vipsImage) ExportColourProfile() error { func (img *vipsImage) ExportColourProfileToSRGB() error { var tmp *C.VipsImage - // Don't export is there's no embedded profile or embedded profile is sRGB - if C.vips_has_embedded_icc(img.VipsImage) == 0 || C.vips_icc_is_srgb_iec61966(img.VipsImage) == 1 { + // Don't export is there's no embedded profile + if C.vips_has_embedded_icc(img.VipsImage) == 0 { return nil } @@ -612,8 +612,8 @@ func (img *vipsImage) ExportColourProfileToSRGB() error { func (img *vipsImage) TransformColourProfile() error { var tmp *C.VipsImage - // Don't transform is there's no embedded profile or embedded profile is sRGB - if C.vips_has_embedded_icc(img.VipsImage) == 0 || C.vips_icc_is_srgb_iec61966(img.VipsImage) == 1 { + // Don't transform is there's no embedded profile + if C.vips_has_embedded_icc(img.VipsImage) == 0 { return nil } @@ -638,10 +638,6 @@ func (img *vipsImage) RemoveColourProfile() error { return nil } -func (img *vipsImage) IsSRGB() bool { - return img.VipsImage.Type == C.VIPS_INTERPRETATION_sRGB -} - func (img *vipsImage) LinearColourspace() error { return img.Colorspace(C.VIPS_INTERPRETATION_scRGB) } diff --git a/vips.h b/vips.h index e0fffac4..410312df 100644 --- a/vips.h +++ b/vips.h @@ -61,7 +61,6 @@ int vips_rad2float_go(VipsImage *in, VipsImage **out); int vips_resize_go(VipsImage *in, VipsImage **out, double scale); int vips_resize_with_premultiply(VipsImage *in, VipsImage **out, double scale); -int vips_icc_is_srgb_iec61966(VipsImage *in); int vips_has_embedded_icc(VipsImage *in); int vips_icc_import_go(VipsImage *in, VipsImage **out); int vips_icc_export_go(VipsImage *in, VipsImage **out);