mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-16 02:45:54 -07:00
GammaFilter
This commit is contained in:
parent
15cd115607
commit
f67988d37b
5 changed files with 40 additions and 0 deletions
6
image.go
6
image.go
|
|
@ -185,6 +185,12 @@ func (i *Image) Trim() ([]byte, error) {
|
||||||
return i.Process(options)
|
return i.Process(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gamma returns the gamma filtered image buffer.
|
||||||
|
func (i *Image) Gamma(exponent float64) ([]byte, error) {
|
||||||
|
options := Options{Gamma: exponent}
|
||||||
|
return i.Process(options)
|
||||||
|
}
|
||||||
|
|
||||||
// Process processes the image based on the given transformation options,
|
// Process processes the image based on the given transformation options,
|
||||||
// talking with libvips bindings accordingly and returning the resultant
|
// talking with libvips bindings accordingly and returning the resultant
|
||||||
// image buffer.
|
// image buffer.
|
||||||
|
|
|
||||||
|
|
@ -222,5 +222,6 @@ type Options struct {
|
||||||
GaussianBlur GaussianBlur
|
GaussianBlur GaussianBlur
|
||||||
Sharpen Sharpen
|
Sharpen Sharpen
|
||||||
Threshold float64
|
Threshold float64
|
||||||
|
Gamma float64
|
||||||
OutputICC string
|
OutputICC string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
resizer.go
17
resizer.go
|
|
@ -125,6 +125,12 @@ func resizer(buf []byte, o Options) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply Gamma filter, if necessary
|
||||||
|
image, err = applyGamma(image, o)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return saveImage(image, o)
|
return saveImage(image, o)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -382,6 +388,17 @@ func imageFlatten(image *C.VipsImage, imageType ImageType, o Options) (*C.VipsIm
|
||||||
return vipsFlattenBackground(image, o.Background)
|
return vipsFlattenBackground(image, o.Background)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applyGamma(image *C.VipsImage, o Options) (*C.VipsImage, error) {
|
||||||
|
var err error
|
||||||
|
if o.Gamma > 0 {
|
||||||
|
image, err = vipsGamma(image, o.Gamma)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return image, nil
|
||||||
|
}
|
||||||
|
|
||||||
func zoomImage(image *C.VipsImage, zoom int) (*C.VipsImage, error) {
|
func zoomImage(image *C.VipsImage, zoom int) (*C.VipsImage, error) {
|
||||||
if zoom == 0 {
|
if zoom == 0 {
|
||||||
return image, nil
|
return image, nil
|
||||||
|
|
|
||||||
11
vips.go
11
vips.go
|
|
@ -703,3 +703,14 @@ func vipsDrawWatermark(image *C.VipsImage, o WatermarkImage) (*C.VipsImage, erro
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func vipsGamma(image *C.VipsImage, Gamma float64) (*C.VipsImage, error) {
|
||||||
|
var out *C.VipsImage
|
||||||
|
defer C.g_object_unref(C.gpointer(image))
|
||||||
|
|
||||||
|
err := C.vips_gamma_bridge(image, &out, C.double(Gamma))
|
||||||
|
if err != 0 {
|
||||||
|
return nil, catchVipsError()
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
5
vips.h
5
vips.h
|
|
@ -561,3 +561,8 @@ int vips_find_trim_bridge(VipsImage *in, int *top, int *left, int *width, int *h
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vips_gamma_bridge(VipsImage *in, VipsImage **out, double exponent)
|
||||||
|
{
|
||||||
|
return vips_gamma(in, out, "exponent", 1.0 / exponent, NULL);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue