mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-01-18 11:12:10 +02:00
Refactor colorspace code
This commit is contained in:
parent
e5e3736d29
commit
a08a5d41d9
@ -300,7 +300,7 @@ func transformImage(ctx context.Context, img *vipsImage, data []byte, po *proces
|
||||
checkTimeout(ctx)
|
||||
|
||||
if convertToLinear {
|
||||
if err = img.FixColourspace(); err != nil {
|
||||
if err = img.RgbColourspace(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
@ -347,7 +347,7 @@ func transformImage(ctx context.Context, img *vipsImage, data []byte, po *proces
|
||||
}
|
||||
}
|
||||
|
||||
return img.FixColourspace()
|
||||
return img.RgbColourspace()
|
||||
}
|
||||
|
||||
func transformAnimated(ctx context.Context, img *vipsImage, data []byte, po *processingOptions, imgtype imageType) error {
|
||||
|
21
vips.go
21
vips.go
@ -538,23 +538,18 @@ func (img *vipsImage) ImportColourProfile(evenSRGB bool) error {
|
||||
}
|
||||
|
||||
func (img *vipsImage) LinearColourspace() error {
|
||||
if C.vips_image_guess_interpretation(img.VipsImage) != C.VIPS_INTERPRETATION_scRGB {
|
||||
var tmp *C.VipsImage
|
||||
|
||||
if C.vips_colourspace_go(img.VipsImage, &tmp, C.VIPS_INTERPRETATION_scRGB) != 0 {
|
||||
return vipsError()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
}
|
||||
|
||||
return nil
|
||||
return img.Colorspace(C.VIPS_INTERPRETATION_scRGB)
|
||||
}
|
||||
|
||||
func (img *vipsImage) FixColourspace() error {
|
||||
if C.vips_image_guess_interpretation(img.VipsImage) != C.VIPS_INTERPRETATION_sRGB {
|
||||
func (img *vipsImage) RgbColourspace() error {
|
||||
return img.Colorspace(C.VIPS_INTERPRETATION_sRGB)
|
||||
}
|
||||
|
||||
func (img *vipsImage) Colourspace(colorspace C.VipsInterpretation) error {
|
||||
if C.vips_image_guess_interpretation(img.VipsImage) != colorspace {
|
||||
var tmp *C.VipsImage
|
||||
|
||||
if C.vips_colourspace_go(img.VipsImage, &tmp, C.VIPS_INTERPRETATION_sRGB) != 0 {
|
||||
if C.vips_colourspace_go(img.VipsImage, &tmp, colorspace) != 0 {
|
||||
return vipsError()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
|
Loading…
x
Reference in New Issue
Block a user