note and use res unit on jpg load/save

previously, jpeg save always used pixels/inch and jpeg load converted to
vips pixels/mm

now on jpg load the image's res unit is recorded in
VIPS_META_RESOLUTION_UNIT, and on jpg save the res unit is set from
VIPS_META_RESOLUTION_UNIT (or defaults to inches).

you can now copy a cm-preferring tiff to a jpg and the unit is preserved
This commit is contained in:
John Cupitt 2012-08-07 14:10:19 +01:00
parent 8214d15982
commit 463058c149
3 changed files with 32 additions and 3 deletions

View File

@ -6,6 +6,7 @@
- so affinei and affinei_all appear in Python
- be more cautious enabling YCbCr mode in tiff write
- add "DEPRECATED" flag to arguments
- jpeg load/save note and use the preferred resolution unit
20/7/12 started 7.30.0
- support "rs" mode in vips7

View File

@ -45,6 +45,8 @@
* - read jfif resolution as well as exif
* 19/2/12
* - switch to lazy reading
* 7/8/12
* - note EXIF resolution unit in VIPS_META_RESOLUTION_UNIT
*/
/*
@ -493,6 +495,8 @@ set_vips_resolution( VipsImage *im, ExifData *ed )
*/
xres /= 25.4;
yres /= 25.4;
vips_image_set_string( im,
VIPS_META_RESOLUTION_UNIT, "in" );
break;
case 3:
@ -500,6 +504,8 @@ set_vips_resolution( VipsImage *im, ExifData *ed )
*/
xres /= 10.0;
yres /= 10.0;
vips_image_set_string( im,
VIPS_META_RESOLUTION_UNIT, "cm" );
break;
default:

View File

@ -48,6 +48,8 @@
* - rebuild exif tags from coded metadata values
* 24/11/11
* - turn into a set of write fns ready to be called from a class
* 7/8/12
* - use VIPS_META_RESOLUTION_UNIT to select resoltuion unit
*/
/*
@ -345,13 +347,33 @@ static int
set_exif_resolution( ExifData *ed, VipsImage *im )
{
double xres, yres;
char *p;
int unit;
/* Always save as inches - more progs support it for read.
/* Default to inches, more progs support it.
*/
xres = im->Xres * 25.4;
yres = im->Yres * 25.4;
unit = 2;
if( vips_image_get_typeof( im, VIPS_META_RESOLUTION_UNIT ) &&
!vips_image_get_string( im, VIPS_META_RESOLUTION_UNIT, &p ) &&
vips_isprefix( "cm", p ) )
unit = 3;
switch( unit ) {
case 2:
xres = im->Xres * 25.4;
yres = im->Yres * 25.4;
break;
case 3:
xres = im->Xres * 10.0;
yres = im->Yres * 10.0;
break;
default:
vips_warn( "VipsJpeg",
"%s", _( "unknown EXIF resolution unit" ) );
return;
}
if( write_tag( ed, EXIF_TAG_X_RESOLUTION, EXIF_FORMAT_RATIONAL,
vips_exif_set_double, (void *) &xres ) ||