Skip to content

Commit

Permalink
port MaxPos and MinPos
Browse files Browse the repository at this point in the history
  • Loading branch information
n0vad3v committed Nov 14, 2024
1 parent 9ab4185 commit fcf4866
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
9 changes: 4 additions & 5 deletions vips/arithmetic.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ int average(VipsImage *in, double *out) {
return vips_avg(in, out, NULL);
}

int maxpos(VipsImage *in, double *out) {
return vips_max(in, out, NULL);
int maxpos(VipsImage *in, double *out, int *x, int *y) {
return vips_max(in, out, "x", x, "y", y, NULL);
}

int minpos(VipsImage *in, double *out) {
return vips_min(in, out, NULL);
int minpos(VipsImage *in, double *out, int *x, int *y) {
return vips_min(in, out, "x", x, "y", y, NULL);
}

int find_trim(VipsImage *in, int *left, int *top, int *width, int *height,
double threshold, double r, double g, double b) {

Expand Down
18 changes: 10 additions & 8 deletions vips/arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,29 @@ func vipsHistFindNdim(in *C.VipsImage, bins int) (*C.VipsImage, error) {
}

// https://www.libvips.org/API/current/libvips-arithmetic.html#vips-max
func vipsMax(in *C.VipsImage) (float64, error) {
func vipsMax(in *C.VipsImage) (int, int, error) {
incOpCounter("max")
var out C.double
var x, y C.int

if err := C.maxpos(in, &out); err != 0 {
return 0, handleVipsError()
if err := C.maxpos(in, &out, &x, &y); err != 0 {
return -1, -1, handleVipsError()
}

return float64(out), nil
return int(x), int(y), nil
}

// https://www.libvips.org/API/current/libvips-arithmetic.html#vips-min
func vipsMin(in *C.VipsImage) (float64, error) {
func vipsMin(in *C.VipsImage) (int, int, error) {
incOpCounter("min")
var out C.double
var x, y C.int

if err := C.minpos(in, &out); err != 0 {
return 0, handleVipsError()
if err := C.maxpos(in, &out, &x, &y); err != 0 {
return -1, -1, handleVipsError()
}

return float64(out), nil
return int(x), int(y), nil
}

// https://www.libvips.org/API/current/libvips-histogram.html#vips-hist-norm
Expand Down
4 changes: 2 additions & 2 deletions vips/arithmetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ int find_trim(VipsImage *in, int *left, int *top, int *width, int *height,
double threshold, double r, double g, double b);
int getpoint(VipsImage *in, double **vector, int n, int x, int y);
int stats(VipsImage *in, VipsImage **out);
int maxpos(VipsImage *in, double *out);
int minpos(VipsImage *in, double *out);
int maxpos(VipsImage *in, double *out, int *x, int *y);
int minpos(VipsImage *in, double *out, int *x, int *y);
int hist_find(VipsImage *in, VipsImage **out);
int hist_find_ndim(VipsImage *in, VipsImage **out, int bins);
int hist_cum(VipsImage *in, VipsImage **out);
Expand Down
6 changes: 4 additions & 2 deletions vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -1730,11 +1730,13 @@ func (r *ImageRef) HistogramFindNdim(bins int) error {
return nil
}

func (r *ImageRef) MaxPos() (float64, error) {
// This operation finds the maximum value in an image.
func (r *ImageRef) MaxPos() (x, y int, err error) {
return vipsMax(r.image)
}

func (r *ImageRef) MinPos() (float64, error) {
// This operation finds the maximum value in an image.
func (r *ImageRef) MinPos() (x, y int, err error) {
return vipsMin(r.image)
}

Expand Down

0 comments on commit fcf4866

Please sign in to comment.