Support brightness and contrast

This commit is contained in:
Mereng 2021-06-17 18:57:39 +02:00
parent d0fb333ce4
commit 76894654c7
4 changed files with 68 additions and 0 deletions

View file

@ -142,6 +142,18 @@ func resizer(buf []byte, o Options) ([]byte, error) {
return nil, err
}
// Apply brightness, if necessary
image, err = applyBrightness(image, o)
if err != nil {
return nil, err
}
// Apply contrast, if necessary
image, err = applyContrast(image, o)
if err != nil {
return nil, err
}
return saveImage(image, o)
}
@ -610,3 +622,25 @@ func getAngle(angle Angle) Angle {
}
return Angle(math.Min(float64(angle), 270))
}
func applyBrightness(image *C.VipsImage, o Options) (*C.VipsImage, error) {
var err error
if o.Brightness != 0 {
image, err = vipsBrightness(image, o.Brightness)
if err != nil {
return nil, err
}
}
return image, nil
}
func applyContrast(image *C.VipsImage, o Options) (*C.VipsImage, error) {
var err error
if o.Contrast > 0 {
image, err = vipsContrast(image, o.Contrast)
if err != nil {
return nil, err
}
}
return image, nil
}