From 6269c852ccf7e6af8cec88114b3a8f489ccf55bb Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 9 Sep 2014 12:18:21 +0100 Subject: [PATCH] support exif res unit "none" well why would you want that, but it seems some images use it --- ChangeLog | 1 + libvips/foreign/jpeg2vips.c | 9 +++++++++ libvips/foreign/vips2jpeg.c | 16 +++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7d244f06..cc989d6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 8/9/14 started 7.40.8 - fix configure on rhel6 [Lovell] - mono <-> rgb converters were not handling extra bands, thanks James +- support jpeg resunit "none" 21/8/14 started 7.40.7 - width and height were swapped in matlab load diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 666ec61c..98d8747e 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -57,6 +57,8 @@ * - null-terminate exif strings, thanks Mike * 24/2/14 * - don't write to our input buffer, thanks Lovell + * 9/9/14 + * - support "none" as a resolution unit */ /* @@ -547,6 +549,13 @@ res_from_exif( VipsImage *im, ExifData *ed ) #endif /*DEBUG*/ switch( unit ) { + case 1: + /* No unit ... just pass the fields straight to vips. + */ + vips_image_set_string( im, + VIPS_META_RESOLUTION_UNIT, "none" ); + break; + case 2: /* In inches. */ diff --git a/libvips/foreign/vips2jpeg.c b/libvips/foreign/vips2jpeg.c index cc56b178..83a6794c 100644 --- a/libvips/foreign/vips2jpeg.c +++ b/libvips/foreign/vips2jpeg.c @@ -63,6 +63,8 @@ * - add "strip" option to remove all metadata * 13/11/13 * - add a "no_subsample" option to disable chroma subsample + * 9/9/14 + * - support "none" as a resolution unit */ /* @@ -460,11 +462,19 @@ set_exif_resolution( ExifData *ed, VipsImage *im ) */ 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; + !vips_image_get_string( im, VIPS_META_RESOLUTION_UNIT, &p ) ) { + if( vips_isprefix( "cm", p ) ) + unit = 3; + else if( vips_isprefix( "none", p ) ) + unit = 1; + } switch( unit ) { + case 1: + xres = im->Xres; + yres = im->Yres; + break; + case 2: xres = im->Xres * 25.4; yres = im->Yres * 25.4;