premultiply before startcrop search

or there might be stuff hidden in the fully transparent areas

see https://github.com/jcupitt/libvips/issues/619
This commit is contained in:
John Cupitt 2017-03-18 10:55:38 +00:00
parent 077978904a
commit 6bf83d1ddc
2 changed files with 19 additions and 8 deletions

View File

@ -257,6 +257,7 @@ vips_smartcrop_build( VipsObject *object )
VipsSmartcrop *smartcrop = (VipsSmartcrop *) object; VipsSmartcrop *smartcrop = (VipsSmartcrop *) object;
VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 ); VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 );
VipsImage *in;
int left; int left;
int top; int top;
@ -271,6 +272,18 @@ vips_smartcrop_build( VipsObject *object )
return( -1 ); return( -1 );
} }
in = smartcrop->in;
/* If there's an alpha, we have to premultiply before searching for
* content. There could be stuff in transparent areas which we don't
* want to consider.
*/
if( vips_image_hasalpha( in ) ) {
if( vips_premultiply( in, &t[0], NULL ) )
return( -1 );
in = t[0];
}
switch( smartcrop->interesting ) { switch( smartcrop->interesting ) {
case VIPS_INTERESTING_NONE: case VIPS_INTERESTING_NONE:
break; break;
@ -281,14 +294,12 @@ vips_smartcrop_build( VipsObject *object )
break; break;
case VIPS_INTERESTING_ENTROPY: case VIPS_INTERESTING_ENTROPY:
if( vips_smartcrop_entropy( smartcrop, if( vips_smartcrop_entropy( smartcrop, in, &left, &top ) )
smartcrop->in, &left, &top ) )
return( -1 ); return( -1 );
break; break;
case VIPS_INTERESTING_ATTENTION: case VIPS_INTERESTING_ATTENTION:
if( vips_smartcrop_attention( smartcrop, if( vips_smartcrop_attention( smartcrop, in, &left, &top ) )
smartcrop->in, &left, &top ) )
return( -1 ); return( -1 );
break; break;
@ -297,9 +308,9 @@ vips_smartcrop_build( VipsObject *object )
break; break;
} }
if( vips_extract_area( smartcrop->in, &t[0], if( vips_extract_area( smartcrop->in, &t[1],
left, top, smartcrop->width, smartcrop->height, NULL ) || left, top, smartcrop->width, smartcrop->height, NULL ) ||
vips_image_write( t[0], conversion->out ) ) vips_image_write( t[1], conversion->out ) )
return( -1 ); return( -1 );
return( 0 ); return( 0 );

View File

@ -179,5 +179,5 @@ As usual, there are a range of improvements to file format read and write.
## Other ## Other
Many small bug fixes, improvements to the C++ binding. Many small bug fixes, improvements to the C++ binding. As usual, the
As usual, the ChanegLog has more detail if you're interested. ChangeLog has more detail, if you're interested.