add skip-blanks option to dzsave

Skip-blanks was a feature of google layout. This patch makes it into an
option you can control which defaults on in gm mode.

See https://github.com/libvips/libvips/issues/1185
This commit is contained in:
John Cupitt 2018-12-19 14:52:33 +00:00
parent 9303e382c1
commit 51dbf607dd
2 changed files with 29 additions and 10 deletions

View File

@ -12,6 +12,7 @@
- don't stop composite on first non-transparent image [felixbuenemann, GDmac]
- add vips_rect_overlapsrect()
- composite is much faster at positioning subimages
- dzsave has a new skip_blanks option
21/11/18 started 8.7.3
- fix infinite loop for autofit with non-scaleable font

View File

@ -76,6 +76,8 @@
* 24/11/17
* - output overlap-only tiles on edges for better deepzoom spec
* compliance
* 19/12/18
* - add @skip_blanks
*/
/*
@ -448,6 +450,7 @@ struct _VipsForeignSaveDz {
VipsForeignDzContainer container;
int compression;
VipsRegionShrink region_shrink;
gboolean skip_blanks;
/* Tile and overlap geometry. The members above are the parameters we
* accept, this next set are the derived values which are actually
@ -1166,10 +1169,7 @@ strip_work( VipsThreadState *state, void *a )
state->pos.width, state->pos.height, NULL ) )
return( -1 );
/* If we are writing a google map pyramid and the tile is equal to the
* background, don't save. The viewer will display blank.png for us.
*/
if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_GOOGLE &&
if( dz->skip_blanks &&
tile_equal( x, dz->ink ) ) {
g_object_unref( x );
@ -1631,6 +1631,12 @@ vips_foreign_save_dz_build( VipsObject *object )
dz->tile_size = 256;
}
/* skip_blanks defaults TRUE in google mode.
*/
if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_GOOGLE &&
!vips_object_argument_isset( object, "skip_blanks" ) )
dz->skip_blanks = TRUE;
/* Our tile layout.
*/
if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_DZ ) {
@ -1650,8 +1656,7 @@ vips_foreign_save_dz_build( VipsObject *object )
/* Default to white background. vips_foreign_save_init() defaults to
* black.
*/
if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_GOOGLE &&
!vips_object_argument_isset( object, "background" ) ) {
if( !vips_object_argument_isset( object, "background" ) ) {
VipsArrayDouble *background;
/* Using g_object_set() to set an input param in build will
@ -1690,9 +1695,9 @@ vips_foreign_save_dz_build( VipsObject *object )
save->ready = z;
}
/* We use ink in google mode to check for blank tiles.
/* We use ink to check for blank tiles.
*/
if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_GOOGLE ) {
if( dz->skip_blanks ) {
if( !(dz->ink = vips__vector_to_ink(
class->nickname, save->ready,
VIPS_AREA( save->background )->data, NULL,
@ -2105,6 +2110,13 @@ vips_foreign_save_dz_class_init( VipsForeignSaveDzClass *class )
G_STRUCT_OFFSET( VipsForeignSaveDz, region_shrink ),
VIPS_TYPE_REGION_SHRINK, VIPS_REGION_SHRINK_MEAN );
VIPS_ARG_BOOL( class, "skip_blanks", 19,
_( "Skip blanks" ),
_( "Skip tiles which are nearly equal to the background" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, skip_blanks ),
FALSE );
/* How annoying. We stupidly had these in earlier versions.
*/
@ -2340,7 +2352,8 @@ vips_foreign_save_dz_buffer_init( VipsForeignSaveDzBuffer *buffer )
* * @container: #VipsForeignDzContainer set container type
* * @properties: %gboolean write a properties file
* * @compression: %gint zip deflate compression level
* * @shrink_region: #VipsRegionShrink How to shrink each 2x2 region.
* * @region_shrink: #VipsRegionShrink How to shrink each 2x2 region
* * @skip_blanks: %gboolean Skip tiles which are equal to the background
*
* Save an image as a set of tiles at various resolutions. By default dzsave
* uses DeepZoom layout -- use @layout to pick other conventions.
@ -2387,6 +2400,10 @@ vips_foreign_save_dz_buffer_init( VipsForeignSaveDzBuffer *buffer )
* You can use @region_shrink to control the method for shrinking each 2x2
* region. This defaults to using the average of the 4 input pixels but you can
* also use the median in cases where you want to preserve the range of values.
*
* If you set @skip_blanks, tiles which are almost equal to the background are
* skipped. This can save a lot of space for some image types. This option
* defaults %TRUE in Google layout mode.
*
* See also: vips_tiffsave().
*
@ -2426,7 +2443,8 @@ vips_dzsave( VipsImage *in, const char *name, ... )
* * @container: #VipsForeignDzContainer set container type
* * @properties: %gboolean write a properties file
* * @compression: %gint zip deflate compression level
* * @shrink_region: #VipsRegionShrink How to shrink each 2x2 region.
* * @region_shrink: #VipsRegionShrink How to shrink each 2x2 region.
* * @skip_blanks: %gboolean Skip tiles which are equal to the background
*
* As vips_dzsave(), but save to a memory buffer.
*