diff --git a/ChangeLog b/ChangeLog index 42ca4b7b..60c67162 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 6166dad6..9a105d74 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -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: diff --git a/libvips/foreign/vips2jpeg.c b/libvips/foreign/vips2jpeg.c index 33f5f49b..06398901 100644 --- a/libvips/foreign/vips2jpeg.c +++ b/libvips/foreign/vips2jpeg.c @@ -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 ) ||