find_trim works for all bg images

width/height == 0 if whole image is bg
This commit is contained in:
John Cupitt 2017-07-26 15:13:12 +01:00
parent 254e6a8b2a
commit 18595ca0dd
2 changed files with 7 additions and 6 deletions

View File

@ -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.
*

View File

@ -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()