diff --git a/libvips/arithmetic/find_trim.c b/libvips/arithmetic/find_trim.c index 2c262cb4..66a030be 100644 --- a/libvips/arithmetic/find_trim.c +++ b/libvips/arithmetic/find_trim.c @@ -147,8 +147,8 @@ vips_find_trim_build( VipsObject *object ) g_object_set( find_trim, "left", (int) left, "top", (int) top, - "width", (int) ((t[5]->Xsize - right) - left), - "height", (int) ((t[6]->Ysize - bottom) - top), + "width", (int) VIPS_MAX( 0, (t[5]->Xsize - right) - left ), + "height", (int) VIPS_MAX( 0, (t[6]->Ysize - bottom) - top ), NULL ); return( 0 ); @@ -208,14 +208,14 @@ vips_find_trim_class_init( VipsFindTrimClass *class ) _( "Width of extract area" ), VIPS_ARGUMENT_REQUIRED_OUTPUT, G_STRUCT_OFFSET( VipsFindTrim, width ), - 1, VIPS_MAX_COORD, 1 ); + 0, VIPS_MAX_COORD, 1 ); VIPS_ARG_INT( class, "height", 13, _( "Height" ), _( "Height of extract area" ), VIPS_ARGUMENT_REQUIRED_OUTPUT, G_STRUCT_OFFSET( VipsFindTrim, height ), - 1, VIPS_MAX_COORD, 1 ); + 0, VIPS_MAX_COORD, 1 ); } @@ -249,6 +249,9 @@ vips_find_trim_init( VipsFindTrim *find_trim ) * four directions where the sum is greater than @threshold gives the bounding * box. * + * If the image is entirely background, vips_find_trim() returns @width == 0 + * and @height == 0. + * * @background defaults to 255, or 65535 for 16-bit images. Set another value, * or use vips_getpoint() to pick a value from an edge. * diff --git a/test/test_arithmetic.py b/test/test_arithmetic.py index a81666bd..3db31750 100755 --- a/test/test_arithmetic.py +++ b/test/test_arithmetic.py @@ -645,8 +645,6 @@ class TestArithmetic(unittest.TestCase): im = Vips.Image.black(50, 60) + 100 test = im.embed(10, 20, 200, 300, extend = "white") - test.write_to_file("x.v") - for x in unsigned_formats + float_formats: a = test.cast(x) left, top, width, height = a.find_trim()