tiffsave has region_shrink param

for new pyr shrink stuff
This commit is contained in:
John Cupitt 2018-06-13 18:16:03 +01:00
parent a373d2c876
commit 581e0178d2
4 changed files with 41 additions and 23 deletions

View File

@ -1407,8 +1407,7 @@ strip_shrink( Layer *layer )
if( vips_rect_isempty( &target ) ) if( vips_rect_isempty( &target ) )
break; break;
(void) vips_region_shrink( from, to, &target, (void) vips_region_shrink( from, to, &target, region_shrink );
region_shrink );
below->write_y += target.height; below->write_y += target.height;
@ -2034,8 +2033,7 @@ vips_foreign_save_dz_class_init( VipsForeignSaveDzClass *class )
_( "Directory layout" ), _( "Directory layout" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, layout ), G_STRUCT_OFFSET( VipsForeignSaveDz, layout ),
VIPS_TYPE_FOREIGN_DZ_LAYOUT, VIPS_TYPE_FOREIGN_DZ_LAYOUT, VIPS_FOREIGN_DZ_LAYOUT_DZ );
VIPS_FOREIGN_DZ_LAYOUT_DZ );
VIPS_ARG_STRING( class, "suffix", 9, VIPS_ARG_STRING( class, "suffix", 9,
_( "suffix" ), _( "suffix" ),
@ -2063,8 +2061,7 @@ vips_foreign_save_dz_class_init( VipsForeignSaveDzClass *class )
_( "Pyramid depth" ), _( "Pyramid depth" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, depth ), G_STRUCT_OFFSET( VipsForeignSaveDz, depth ),
VIPS_TYPE_FOREIGN_DZ_DEPTH, VIPS_TYPE_FOREIGN_DZ_DEPTH, VIPS_FOREIGN_DZ_DEPTH_ONEPIXEL );
VIPS_FOREIGN_DZ_DEPTH_ONEPIXEL );
VIPS_ARG_BOOL( class, "centre", 13, VIPS_ARG_BOOL( class, "centre", 13,
_( "Center" ), _( "Center" ),
@ -2085,8 +2082,7 @@ vips_foreign_save_dz_class_init( VipsForeignSaveDzClass *class )
_( "Pyramid container type" ), _( "Pyramid container type" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, container ), G_STRUCT_OFFSET( VipsForeignSaveDz, container ),
VIPS_TYPE_FOREIGN_DZ_CONTAINER, VIPS_TYPE_FOREIGN_DZ_CONTAINER, VIPS_FOREIGN_DZ_CONTAINER_FS );
VIPS_FOREIGN_DZ_CONTAINER_FS );
VIPS_ARG_BOOL( class, "properties", 16, VIPS_ARG_BOOL( class, "properties", 16,
_( "Properties" ), _( "Properties" ),
@ -2104,11 +2100,10 @@ vips_foreign_save_dz_class_init( VipsForeignSaveDzClass *class )
VIPS_ARG_ENUM( class, "region_shrink", 18, VIPS_ARG_ENUM( class, "region_shrink", 18,
_( "Region shrink" ), _( "Region shrink" ),
_( "Method for blah" ), _( "Method to shrink regions" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveDz, region_shrink ), G_STRUCT_OFFSET( VipsForeignSaveDz, region_shrink ),
VIPS_TYPE_REGION_SHRINK, VIPS_TYPE_REGION_SHRINK, VIPS_REGION_SHRINK_MEAN );
VIPS_REGION_SHRINK_MEAN );
/* How annoying. We stupidly had these in earlier versions. /* How annoying. We stupidly had these in earlier versions.
*/ */
@ -2375,7 +2370,7 @@ vips_foreign_save_dz_buffer_init( VipsForeignSaveDzBuffer *buffer )
* *
* You can rotate the image during write with the @angle argument. However, * You can rotate the image during write with the @angle argument. However,
* this will only work for images which support random access, like openslide, * this will only work for images which support random access, like openslide,
* and not for things like JPEG. You'll need to rotate these images * and not for things like JPEG. You'll need to rotate those images
* yourself with vips_rot(). Note that the `autorotate` option to the loader * yourself with vips_rot(). Note that the `autorotate` option to the loader
* may do what you need. * may do what you need.
* *
@ -2391,7 +2386,7 @@ vips_foreign_save_dz_buffer_init( VipsForeignSaveDzBuffer *buffer )
* *
* You can use @region_shrink to control the method for shrinking each 2x2 * 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 * 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 preseve the range of values. * also use the median in cases where you want to preserve the range of values.
* *
* See also: vips_tiffsave(). * See also: vips_tiffsave().
* *
@ -2431,6 +2426,7 @@ vips_dzsave( VipsImage *in, const char *name, ... )
* * @container: #VipsForeignDzContainer set container type * * @container: #VipsForeignDzContainer set container type
* * @properties: %gboolean write a properties file * * @properties: %gboolean write a properties file
* * @compression: %gint zip deflate compression level * * @compression: %gint zip deflate compression level
* * @shrink_region: #VipsRegionShrink How to shrink each 2x2 region.
* *
* As vips_dzsave(), but save to a memory buffer. * As vips_dzsave(), but save to a memory buffer.
* *

View File

@ -49,7 +49,8 @@ int vips__tiff_write( VipsImage *in, const char *filename,
gboolean bigtiff, gboolean bigtiff,
gboolean rgbjpeg, gboolean rgbjpeg,
gboolean properties, gboolean properties,
gboolean strip ); gboolean strip,
VipsRegionShrink region_shrink );
int vips__tiff_write_buf( VipsImage *in, int vips__tiff_write_buf( VipsImage *in,
void **obuf, size_t *olen, void **obuf, size_t *olen,
@ -63,7 +64,8 @@ int vips__tiff_write_buf( VipsImage *in,
VipsForeignTiffResunit resunit, double xres, double yres, VipsForeignTiffResunit resunit, double xres, double yres,
gboolean bigtiff, gboolean bigtiff,
gboolean rgbjpeg, gboolean rgbjpeg,
gboolean properties, gboolean strip ); gboolean properties, gboolean strip,
VipsRegionShrink region_shrink );
int vips__tiff_read_header( const char *filename, VipsImage *out, int vips__tiff_read_header( const char *filename, VipsImage *out,
int page, int n, gboolean autorotate ); int page, int n, gboolean autorotate );

View File

@ -85,6 +85,7 @@ typedef struct _VipsForeignSaveTiff {
gboolean bigtiff; gboolean bigtiff;
gboolean rgbjpeg; gboolean rgbjpeg;
gboolean properties; gboolean properties;
VipsRegionShrink region_shrink;
} VipsForeignSaveTiff; } VipsForeignSaveTiff;
typedef VipsForeignSaveClass VipsForeignSaveTiffClass; typedef VipsForeignSaveClass VipsForeignSaveTiffClass;
@ -293,6 +294,13 @@ vips_foreign_save_tiff_class_init( VipsForeignSaveTiffClass *class )
G_STRUCT_OFFSET( VipsForeignSaveTiff, properties ), G_STRUCT_OFFSET( VipsForeignSaveTiff, properties ),
FALSE ); FALSE );
VIPS_ARG_ENUM( class, "region_shrink", 22,
_( "Region shrink" ),
_( "Method to shrink regions" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveTiff, region_shrink ),
VIPS_TYPE_REGION_SHRINK, VIPS_REGION_SHRINK_MEAN );
} }
static void static void
@ -306,6 +314,7 @@ vips_foreign_save_tiff_init( VipsForeignSaveTiff *tiff )
tiff->resunit = VIPS_FOREIGN_TIFF_RESUNIT_CM; tiff->resunit = VIPS_FOREIGN_TIFF_RESUNIT_CM;
tiff->xres = 1.0; tiff->xres = 1.0;
tiff->yres = 1.0; tiff->yres = 1.0;
tiff->region_shrink = VIPS_REGION_SHRINK_MEAN;
} }
typedef struct _VipsForeignSaveTiffFile { typedef struct _VipsForeignSaveTiffFile {
@ -341,7 +350,8 @@ vips_foreign_save_tiff_file_build( VipsObject *object )
tiff->bigtiff, tiff->bigtiff,
tiff->rgbjpeg, tiff->rgbjpeg,
tiff->properties, tiff->properties,
save->strip ) ) save->strip,
tiff->region_shrink ) )
return( -1 ); return( -1 );
return( 0 ); return( 0 );
@ -409,7 +419,8 @@ vips_foreign_save_tiff_buffer_build( VipsObject *object )
tiff->bigtiff, tiff->bigtiff,
tiff->rgbjpeg, tiff->rgbjpeg,
tiff->properties, tiff->properties,
save->strip ) ) save->strip,
tiff->region_shrink ) )
return( -1 ); return( -1 );
/* vips__tiff_write_buf() makes a buffer that needs g_free(), not /* vips__tiff_write_buf() makes a buffer that needs g_free(), not
@ -475,6 +486,7 @@ vips_foreign_save_tiff_buffer_init( VipsForeignSaveTiffBuffer *buffer )
* * @properties: set %TRUE to write an IMAGEDESCRIPTION tag * * @properties: set %TRUE to write an IMAGEDESCRIPTION tag
* * @strip: set %TRUE to block metadata save * * @strip: set %TRUE to block metadata save
* * @page_height: %gint for page height for multi-page save * * @page_height: %gint for page height for multi-page save
* * @shrink_region: #VipsRegionShrink How to shrink each 2x2 region.
* *
* Write a VIPS image to a file as TIFF. * Write a VIPS image to a file as TIFF.
* *
@ -509,7 +521,9 @@ vips_foreign_save_tiff_buffer_init( VipsForeignSaveTiffBuffer *buffer )
* is 128 by 128. * is 128 by 128.
* *
* Set @pyramid to write the image as a set of images, one per page, of * Set @pyramid to write the image as a set of images, one per page, of
* decreasing size. * decreasing size. Use @shrink_region to set how images will be shrunk: by
* default each 2x2 block is just averaged, but you can set MODE or MEDIAN as
* well.
* *
* Set @squash to make 8-bit uchar images write as 1-bit TIFFs. Values >128 * Set @squash to make 8-bit uchar images write as 1-bit TIFFs. Values >128
* are written as white, values <=128 as black. Normally vips will write * are written as white, values <=128 as black. Normally vips will write
@ -586,6 +600,7 @@ vips_tiffsave( VipsImage *in, const char *filename, ... )
* * @properties: set %TRUE to write an IMAGEDESCRIPTION tag * * @properties: set %TRUE to write an IMAGEDESCRIPTION tag
* * @strip: set %TRUE to block metadata save * * @strip: set %TRUE to block metadata save
* * @page_height: %gint for page height for multi-page save * * @page_height: %gint for page height for multi-page save
* * @shrink_region: #VipsRegionShrink How to shrink each 2x2 region.
* *
* As vips_tiffsave(), but save to a memory buffer. * As vips_tiffsave(), but save to a memory buffer.
* *

View File

@ -309,6 +309,7 @@ struct _Wtiff {
int rgbjpeg; /* True for RGB not YCbCr */ int rgbjpeg; /* True for RGB not YCbCr */
int properties; /* Set to save XML props */ int properties; /* Set to save XML props */
int strip; /* Don't write metadata */ int strip; /* Don't write metadata */
VipsRegionShrink region_shrink; /* How to shrink regions */
/* True if we've detected a toilet-roll image, plus the page height, /* True if we've detected a toilet-roll image, plus the page height,
* which has been checked to be a factor of im->Ysize. * which has been checked to be a factor of im->Ysize.
@ -891,7 +892,8 @@ wtiff_new( VipsImage *im, const char *filename,
gboolean bigtiff, gboolean bigtiff,
gboolean rgbjpeg, gboolean rgbjpeg,
gboolean properties, gboolean properties,
gboolean strip ) gboolean strip,
VipsRegionShrink region_shrink )
{ {
Wtiff *wtiff; Wtiff *wtiff;
@ -919,6 +921,7 @@ wtiff_new( VipsImage *im, const char *filename,
wtiff->rgbjpeg = rgbjpeg; wtiff->rgbjpeg = rgbjpeg;
wtiff->properties = properties; wtiff->properties = properties;
wtiff->strip = strip; wtiff->strip = strip;
wtiff->region_shrink = region_shrink;
wtiff->toilet_roll = FALSE; wtiff->toilet_roll = FALSE;
wtiff->page_height = -1; wtiff->page_height = -1;
@ -1771,7 +1774,8 @@ vips__tiff_write( VipsImage *in, const char *filename,
VipsForeignTiffResunit resunit, double xres, double yres, VipsForeignTiffResunit resunit, double xres, double yres,
gboolean bigtiff, gboolean bigtiff,
gboolean rgbjpeg, gboolean rgbjpeg,
gboolean properties, gboolean strip ) gboolean properties, gboolean strip,
VipsRegionShrink region_shrink )
{ {
Wtiff *wtiff; Wtiff *wtiff;
@ -1788,7 +1792,7 @@ vips__tiff_write( VipsImage *in, const char *filename,
compression, Q, predictor, profile, compression, Q, predictor, profile,
tile, tile_width, tile_height, pyramid, squash, tile, tile_width, tile_height, pyramid, squash,
miniswhite, resunit, xres, yres, bigtiff, rgbjpeg, miniswhite, resunit, xres, yres, bigtiff, rgbjpeg,
properties, strip )) ) properties, strip, region_shrink )) )
return( -1 ); return( -1 );
if( wtiff_write_image( wtiff ) ) { if( wtiff_write_image( wtiff ) ) {
@ -1814,7 +1818,8 @@ vips__tiff_write_buf( VipsImage *in,
VipsForeignTiffResunit resunit, double xres, double yres, VipsForeignTiffResunit resunit, double xres, double yres,
gboolean bigtiff, gboolean bigtiff,
gboolean rgbjpeg, gboolean rgbjpeg,
gboolean properties, gboolean strip ) gboolean properties, gboolean strip,
VipsRegionShrink region_shrink )
{ {
Wtiff *wtiff; Wtiff *wtiff;
@ -1827,7 +1832,7 @@ vips__tiff_write_buf( VipsImage *in,
compression, Q, predictor, profile, compression, Q, predictor, profile,
tile, tile_width, tile_height, pyramid, squash, tile, tile_width, tile_height, pyramid, squash,
miniswhite, resunit, xres, yres, bigtiff, rgbjpeg, miniswhite, resunit, xres, yres, bigtiff, rgbjpeg,
properties, strip )) ) properties, strip, region_shrink )) )
return( -1 ); return( -1 );
wtiff->obuf = obuf; wtiff->obuf = obuf;