From 404cbf902fa61e7a19b04be932f5c808b4bc7af7 Mon Sep 17 00:00:00 2001 From: Thomas Meson Date: Mon, 14 Sep 2015 17:12:46 +0200 Subject: [PATCH] vips: add a vips__gaussblur method handle both < 7.41 and higher. Prior 7.41, vips_gaussblur took only a int param, the radius. The radius was then divided by 2.0 (min_ampl) in vips_gaussblur. After, you can now parameter the min_ampl and radius became sigma (and passed from an integer to a double). --- options.go | 6 ++++++ vips.go | 11 +++++++++++ vips.h | 12 ++++++++++++ 3 files changed, 29 insertions(+) diff --git a/options.go b/options.go index 67af96d..9526914 100644 --- a/options.go +++ b/options.go @@ -91,6 +91,11 @@ type Watermark struct { Background Color } +type GaussianBlur struct { + Sigma float64 + MinAmpl float64 +} + type Options struct { Height int Width int @@ -117,4 +122,5 @@ type Options struct { Type ImageType Interpolator Interpolator Interpretation Interpretation + GaussianBlur GaussianBlur } diff --git a/vips.go b/vips.go index 7734057..fc8bc7c 100644 --- a/vips.go +++ b/vips.go @@ -432,3 +432,14 @@ func boolToInt(b bool) int { } return 0 } + +func vipsGaussianBlur(image *C.VipsImage, o GaussianBlur) (*C.VipsImage, error) { + var out *C.VipsImage + defer C.g_object_unref(C.gpointer(image)) + + err := C.vips__gaussblur(image, &out, C.double(o.Sigma), C.double(o.MinAmpl)) + if err != 0 { + return nil, catchVipsError() + } + return out, nil +} diff --git a/vips.h b/vips.h index 428e994..ee0be0f 100644 --- a/vips.h +++ b/vips.h @@ -16,6 +16,9 @@ */ #if (VIPS_MAJOR_VERSION == 7 && VIPS_MINOR_VERSION < 41) +/* we need math.h for ceil() in vips__gaussblur */ +#include + #define VIPS_ANGLE_D0 VIPS_ANGLE_0 #define VIPS_ANGLE_D90 VIPS_ANGLE_90 #define VIPS_ANGLE_D180 VIPS_ANGLE_180 @@ -321,3 +324,12 @@ vips_watermark(VipsImage *in, VipsImage **out, WatermarkTextOptions *to, Waterma g_object_unref(base); return 0; } + +int +vips__gaussblur(VipsImage *in, VipsImage **out, double sigma, double min_ampl) { +#if (VIPS_MAJOR_VERSION == 7 && VIPS_MINOR_VERSION < 41) + return vips_gaussblur(in, out, ceil(sigma), NULL); +#else + return vips_gaussblur(in, out, sigma, NULL, "min_ampl", min_ampl); +#endif +}