Parcourir la source

Fix saving to JPEG when using linear colorspace

DarthSim il y a 1 an
Parent
commit
136a5d093f
3 fichiers modifiés avec 12 ajouts et 0 suppressions
  1. 2 0
      CHANGELOG.md
  2. 6 0
      processing/export_color_profile.go
  3. 4 0
      vips/vips.go

+ 2 - 0
CHANGELOG.md

@@ -1,6 +1,8 @@
 # Changelog
 # Changelog
 
 
 ## [Unreleased]
 ## [Unreleased]
+### Fix
+- Fix saving to JPEG when using linear colorspace.
 
 
 ## [3.18.1] - 2023-07-29
 ## [3.18.1] - 2023-07-29
 ### Change
 ### Change

+ 6 - 0
processing/export_color_profile.go

@@ -9,6 +9,12 @@ import (
 func exportColorProfile(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
 func exportColorProfile(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
 	keepProfile := !po.StripColorProfile && po.Format.SupportsColourProfile()
 	keepProfile := !po.StripColorProfile && po.Format.SupportsColourProfile()
 
 
+	if img.IsLinear() {
+		if err := img.RgbColourspace(); err != nil {
+			return err
+		}
+	}
+
 	if pctx.iccImported {
 	if pctx.iccImported {
 		if keepProfile {
 		if keepProfile {
 			// We imported ICC profile and want to keep it,
 			// We imported ICC profile and want to keep it,

+ 4 - 0
vips/vips.go

@@ -638,6 +638,10 @@ func (img *Image) IsRGB() bool {
 		format == C.VIPS_INTERPRETATION_RGB16
 		format == C.VIPS_INTERPRETATION_RGB16
 }
 }
 
 
+func (img *Image) IsLinear() bool {
+	return C.vips_image_guess_interpretation(img.VipsImage) == C.VIPS_INTERPRETATION_scRGB
+}
+
 func (img *Image) ImportColourProfile() error {
 func (img *Image) ImportColourProfile() error {
 	var tmp *C.VipsImage
 	var tmp *C.VipsImage