From 7025fe408131dc40b84999493fc98a123c4a5eb8 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 16 Nov 2012 19:53:59 +0000 Subject: [PATCH] more exif read improvements some jpegs use a signed long to store the resolution unit (??), remove the checks on tag format for res unit --- libvips/foreign/jpeg2vips.c | 5 ++--- libvips/foreign/vips2jpeg.c | 12 +++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 50f1dc52..cfc9f87f 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -484,12 +484,11 @@ get_entry_double( ExifData *ed, int ifd, ExifTag tag, double *out ) } static int -get_entry_short( ExifData *ed, int ifd, ExifTag tag, int *out ) +get_entry_int( ExifData *ed, int ifd, ExifTag tag, int *out ) { ExifEntry *entry; if( !(entry = exif_content_get_entry( ed->ifd[ifd], tag )) || - entry->format != EXIF_FORMAT_SHORT || entry->components != 1 ) return( -1 ); @@ -507,7 +506,7 @@ set_vips_resolution( VipsImage *im, ExifData *ed ) */ if( get_entry_double( ed, 0, EXIF_TAG_X_RESOLUTION, &xres ) || get_entry_double( ed, 0, EXIF_TAG_Y_RESOLUTION, &yres ) || - get_entry_short( ed, 0, EXIF_TAG_RESOLUTION_UNIT, &unit ) ) { + get_entry_int( ed, 0, EXIF_TAG_RESOLUTION_UNIT, &unit ) ) { vips_warn( "VipsJpeg", "%s", _( "error reading resolution" ) ); return; diff --git a/libvips/foreign/vips2jpeg.c b/libvips/foreign/vips2jpeg.c index c7438793..4f173499 100644 --- a/libvips/foreign/vips2jpeg.c +++ b/libvips/foreign/vips2jpeg.c @@ -417,14 +417,12 @@ typedef void (*write_fn)( ExifData *ed, /* Write a tag. Update what's there, or make a new one. */ static int -write_tag( ExifData *ed, int ifd, - ExifTag tag, ExifFormat format, write_fn fn, void *data ) +write_tag( ExifData *ed, int ifd, ExifTag tag, write_fn fn, void *data ) { ExifEntry *entry; if( (entry = exif_content_get_entry( ed->ifd[ifd], tag )) ) { - if( entry->format == format ) - fn( ed, entry, 0, data ); + fn( ed, entry, 0, data ); } else { entry = exif_entry_new(); @@ -484,11 +482,11 @@ set_exif_resolution( ExifData *ed, VipsImage *im ) /* Main image xres/yres/unit are in ifd0. ifd1 has the thumbnail * xres/yres/unit. */ - if( write_tag( ed, 0, EXIF_TAG_X_RESOLUTION, EXIF_FORMAT_RATIONAL, + if( write_tag( ed, 0, EXIF_TAG_X_RESOLUTION, vips_exif_set_double, (void *) &xres ) || - write_tag( ed, 0, EXIF_TAG_Y_RESOLUTION, EXIF_FORMAT_RATIONAL, + write_tag( ed, 0, EXIF_TAG_Y_RESOLUTION, vips_exif_set_double, (void *) &yres ) || - write_tag( ed, 0, EXIF_TAG_RESOLUTION_UNIT, EXIF_FORMAT_SHORT, + write_tag( ed, 0, EXIF_TAG_RESOLUTION_UNIT, vips_exif_set_int, (void *) &unit ) ) { vips_error( "VipsJpeg", "%s", _( "error setting JPEG resolution" ) );