Sfoglia il codice sorgente

Remove ICC hacks; Enable ICC support for PNG

DarthSim 3 anni fa
parent
commit
302bf64ea2
6 ha cambiato i file con 10 aggiunte e 37 eliminazioni
  1. 2 0
      CHANGELOG.md
  2. 1 0
      image_type.go
  3. 1 1
      process.go
  4. 0 25
      vips.c
  5. 6 10
      vips.go
  6. 0 1
      vips.h

+ 2 - 0
CHANGELOG.md

@@ -1,6 +1,8 @@
 # Changelog
 
 ## [Unreleased]
+### Fix
+- Fix ICC profile handling in some cases.
 
 ## [2.16.4] - 2021-06-16
 ### Change

+ 1 - 0
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
 }

+ 1 - 1
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
 		}

+ 0 - 25
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;

+ 6 - 10
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)
 }

+ 0 - 1
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);