Browse Source

Remove ICC if source image is linear

DarthSim 1 year ago
parent
commit
46e63464f7
2 changed files with 6 additions and 1 deletions
  1. 1 0
      CHANGELOG.md
  2. 5 1
      processing/import_color_profile.go

+ 1 - 0
CHANGELOG.md

@@ -3,6 +3,7 @@
 ## [Unreleased]
 ## [Unreleased]
 ### Fix
 ### Fix
 - Fix parsing of HEIF files with large boxes.
 - Fix parsing of HEIF files with large boxes.
+- Fix wrong colors when the source image has a linear colorspace.
 
 
 ## [3.19.0] - 2023-08-21
 ## [3.19.0] - 2023-08-21
 ### Add
 ### Add

+ 5 - 1
processing/import_color_profile.go

@@ -18,7 +18,11 @@ func importColorProfile(pctx *pipelineContext, img *vips.Image, po *options.Proc
 
 
 	convertToLinear := config.UseLinearColorspace && (pctx.wscale != 1 || pctx.hscale != 1)
 	convertToLinear := config.UseLinearColorspace && (pctx.wscale != 1 || pctx.hscale != 1)
 
 
-	if convertToLinear || !img.IsRGB() {
+	if img.IsLinear() {
+		// The image is linear. If we keep its ICC, we'll get wrong colors after
+		// converting it to sRGB
+		img.RemoveColourProfile()
+	} else if convertToLinear || !img.IsRGB() {
 		if err := img.ImportColourProfile(); err != nil {
 		if err := img.ImportColourProfile(); err != nil {
 			return err
 			return err
 		}
 		}