improve resolution unit handling in tiff save

the deprecated tiff saver used to use pixels/mm in resolution
specification, rather than the user's suggested unit
This commit is contained in:
John Cupitt 2012-05-17 11:13:38 +01:00
parent c394f54952
commit d5bd8d0de0
3 changed files with 15 additions and 28 deletions

13
TODO
View File

@ -1,16 +1,3 @@
- try:
$ vips im_copy babe.jpg babe.tif:lzw,tile,,manybit,res_inch:72.00x72.00,,
$ header -a babe.tif
babe.tif: 1024x768 uchar, 3 bands, srgb VipsImage (0x2225050)
xres: 7.200000
yres: 7.200000
resolution-unit: in
argh!
blocking bugs
=============

View File

@ -178,20 +178,10 @@ im_vips2tiff( IMAGE *in, const char *filename )
}
if( (q = im_getnextoption( &p )) ) {
if( im_isprefix( "res_cm", q ) ) {
if( resunit == VIPS_FOREIGN_TIFF_RESUNIT_INCH ) {
xres /= 2.54;
yres /= 2.54;
}
if( im_isprefix( "res_cm", q ) )
resunit = VIPS_FOREIGN_TIFF_RESUNIT_CM;
}
else if( im_isprefix( "res_inch", q ) ) {
if( resunit == VIPS_FOREIGN_TIFF_RESUNIT_CM ) {
xres *= 2.54;
yres *= 2.54;
}
else if( im_isprefix( "res_inch", q ) )
resunit = VIPS_FOREIGN_TIFF_RESUNIT_INCH;
}
else {
im_error( "im_vips2tiff", _( "unknown resolution unit "
"\"%s\"\nshould be one of \"res_cm\" or "
@ -209,6 +199,15 @@ im_vips2tiff( IMAGE *in, const char *filename )
yres = xres;
}
/* vips resolutions are always in pixels/mm. If the
* user specifies ",res_inch:72x72" then they are
* using pixels/inch instead and we must convert.
*/
if( resunit == VIPS_FOREIGN_TIFF_RESUNIT_INCH ) {
xres /= 2.54;
yres /= 2.54;
}
}
}

View File

@ -1715,9 +1715,9 @@ vips_tiffload( const char *filename, VipsImage **out, ... )
* @tile_height; set tile size
* @pyramid; set %TRUE to write an image pyramid
* @squash; squash 8-bit images down to 1 bit
* @resunit; use pixels per inch or cm for the resolution
* @xres; horizontal resolution
* @yres; vertical resolution
* @resunit; convert resolution to pixels per inch or cm during write
* @xres; horizontal resolution in pixels/mm
* @yres; vertical resolution in pixels/mm
* @bigtiff; write a BigTiff file
*
* Write a VIPS image to a file as TIFF.
@ -1767,6 +1767,7 @@ vips_tiffload( const char *filename, VipsImage **out, ... )
*
* Use @xres and @yres to override the default horizontal and vertical
* resolutions. By default these values are taken from the VIPS image header.
* libvips resolution is always in pixels per millimetre.
*
* Set @bigtiff to attempt to write a bigtiff.
* Bigtiff is a variant of the TIFF