mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 20:22:31 +02:00
Merge branch 'master' into version/4
This commit is contained in:
42
processing/colorspace_to_processing.go
Normal file
42
processing/colorspace_to_processing.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
"github.com/imgproxy/imgproxy/v3/imagedata"
|
||||
"github.com/imgproxy/imgproxy/v3/options"
|
||||
"github.com/imgproxy/imgproxy/v3/vips"
|
||||
)
|
||||
|
||||
func colorspaceToProcessing(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata imagedata.ImageData) error {
|
||||
if img.ColourProfileImported() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := img.Rad2Float(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
convertToLinear := config.UseLinearColorspace && (pctx.wscale != 1 || pctx.hscale != 1)
|
||||
|
||||
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 {
|
||||
// vips 8.15+ tends to lose the colour profile during some color conversions.
|
||||
// We need to backup the colour profile before the conversion and restore it later.
|
||||
img.BackupColourProfile()
|
||||
|
||||
if convertToLinear || !img.IsRGB() {
|
||||
if err := img.ImportColourProfile(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if convertToLinear {
|
||||
return img.LinearColourspace()
|
||||
}
|
||||
|
||||
return img.RgbColourspace()
|
||||
}
|
Reference in New Issue
Block a user