Browse Source

Merge branch 'master' into version/3

DarthSim 3 years ago
parent
commit
493042a25d
4 changed files with 44 additions and 12 deletions
  1. 5 0
      CHANGELOG.md
  2. 31 0
      vips/vips.c
  3. 7 12
      vips/vips.go
  4. 1 0
      vips/vips.h

+ 5 - 0
CHANGELOG.md

@@ -17,6 +17,11 @@
 - Removed `crop` resizing type, use [crop](./docs/generating_the_url.md#crop) processing option instead.
 - Dropped old libvips (<8.8) support.
 
+## [2.16.6] - 2021-07-08
+### Fix
+- Fix performance regression in ICC profile handling.
+- Fix crashes while processing CMYK images without ICC profile.
+
 ## [2.16.5] - 2021-06-28
 ### Change
 - More clear downloading errors.

+ 31 - 0
vips/vips.c

@@ -258,6 +258,37 @@ vips_pixelate(VipsImage *in, VipsImage **out, int pixels) {
   return 0;
 }
 
+int
+vips_icc_is_srgb_iec61966(VipsImage *in) {
+  const void *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 };
+
+  // The image had no profile and built-in CMYK was imported.
+  // Vips gives us an invalid data pointer when the built-in profile was imported,
+  // so we check this mark before receiving an actual profile.
+  // if (vips_image_get_typeof(in, "icc-cmyk-no-profile"))
+  //   return FALSE;
+
+  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;

+ 7 - 12
vips/vips.go

@@ -580,12 +580,7 @@ func (img *Image) ImportColourProfile() error {
 	}
 
 	if C.vips_has_embedded_icc(img.VipsImage) == 0 {
-		// No embedded profile
-		if img.VipsImage.Type != C.VIPS_INTERPRETATION_CMYK {
-			// vips doesn't have built-in profile for other interpretations,
-			// so we can't do anything here
-			return nil
-		}
+		return nil
 	}
 
 	if C.vips_icc_import_go(img.VipsImage, &tmp) == 0 {
@@ -600,8 +595,8 @@ func (img *Image) ImportColourProfile() error {
 func (img *Image) ExportColourProfile() error {
 	var tmp *C.VipsImage
 
-	// Don't export is there's no embedded profile
-	if C.vips_has_embedded_icc(img.VipsImage) == 0 {
+	// 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 {
 		return nil
 	}
 
@@ -617,8 +612,8 @@ func (img *Image) ExportColourProfile() error {
 func (img *Image) ExportColourProfileToSRGB() error {
 	var tmp *C.VipsImage
 
-	// Don't export is there's no embedded profile
-	if C.vips_has_embedded_icc(img.VipsImage) == 0 {
+	// 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 {
 		return nil
 	}
 
@@ -634,8 +629,8 @@ func (img *Image) ExportColourProfileToSRGB() error {
 func (img *Image) TransformColourProfile() error {
 	var tmp *C.VipsImage
 
-	// Don't transform is there's no embedded profile
-	if C.vips_has_embedded_icc(img.VipsImage) == 0 {
+	// 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 {
 		return nil
 	}
 

+ 1 - 0
vips/vips.h

@@ -46,6 +46,7 @@ int vips_resize_go(VipsImage *in, VipsImage **out, double wscale, double hscale)
 
 int vips_pixelate(VipsImage *in, VipsImage **out, int pixels);
 
+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);