Skip to content

Commit

Permalink
gaussian blur support min_ampl (davidbyttow#307)
Browse files Browse the repository at this point in the history
Co-authored-by: muyouran <[email protected]>
  • Loading branch information
jishi92 and muyouran authored Oct 8, 2022
1 parent 8d6122f commit 5f0601e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
Binary file modified resources/jpg-24bit.GaussianBlur-macos-12.golden.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions vips/convolution.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "convolution.h"

int gaussian_blur_image(VipsImage *in, VipsImage **out, double sigma) {
return vips_gaussblur(in, out, sigma, NULL);
int gaussian_blur_image(VipsImage *in, VipsImage **out, double sigma, double min_ampl) {
return vips_gaussblur(in, out, sigma, "min_ampl", min_ampl, NULL);
}

int sharpen_image(VipsImage *in, VipsImage **out, double sigma, double x1,
Expand Down
4 changes: 2 additions & 2 deletions vips/convolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package vips
import "C"

// https://libvips.github.io/libvips/API/current/libvips-convolution.html#vips-gaussblur
func vipsGaussianBlur(in *C.VipsImage, sigma float64) (*C.VipsImage, error) {
func vipsGaussianBlur(in *C.VipsImage, sigma, minAmpl float64) (*C.VipsImage, error) {
incOpCounter("gaussblur")
var out *C.VipsImage

if err := C.gaussian_blur_image(in, &out, C.double(sigma)); err != 0 {
if err := C.gaussian_blur_image(in, &out, C.double(sigma), C.double(minAmpl)); err != 0 {
return nil, handleImageError(out)
}

Expand Down
2 changes: 1 addition & 1 deletion vips/convolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
#include <stdlib.h>
#include <vips/vips.h>

int gaussian_blur_image(VipsImage *in, VipsImage **out, double sigma);
int gaussian_blur_image(VipsImage *in, VipsImage **out, double sigma, double min_ampl);
int sharpen_image(VipsImage *in, VipsImage **out, double sigma, double x1,
double m2);
14 changes: 12 additions & 2 deletions vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"unsafe"
)

const GaussBlurDefaultMinAMpl = 0.2

// PreMultiplicationState stores the pre-multiplication band format of the image
type PreMultiplicationState struct {
bandFormat BandFormat
Expand Down Expand Up @@ -1364,8 +1366,16 @@ func (r *ImageRef) Flatten(backgroundColor *Color) error {
}

// GaussianBlur blurs the image
func (r *ImageRef) GaussianBlur(sigma float64) error {
out, err := vipsGaussianBlur(r.image, sigma)
// add support minAmpl
func (r *ImageRef) GaussianBlur(sigmas ...float64) error {
var (
sigma = sigmas[0]
minAmpl = GaussBlurDefaultMinAMpl
)
if len(sigmas) >= 2 {
minAmpl = sigmas[1]
}
out, err := vipsGaussianBlur(r.image, sigma, minAmpl)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions vips/image_golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ func TestImage_GaussianBlur(t *testing.T) {
goldenTest(t, resources+"jpg-24bit.jpg", func(img *ImageRef) error {
return img.GaussianBlur(10.5)
}, nil, nil)
goldenTest(t, resources+"jpg-24bit.jpg", func(img *ImageRef) error {
return img.GaussianBlur(10.5,0.2)
}, nil, nil)
}

func TestImage_BandJoinConst(t *testing.T) {
Expand Down

0 comments on commit 5f0601e

Please sign in to comment.