more exif read improvements

some jpegs use a signed long to store the resolution unit (??), remove
the checks on tag format for res unit
This commit is contained in:
John Cupitt 2012-11-16 19:53:59 +00:00
parent 74f545fc6f
commit 7025fe4081
2 changed files with 7 additions and 10 deletions

View File

@ -484,12 +484,11 @@ get_entry_double( ExifData *ed, int ifd, ExifTag tag, double *out )
} }
static int 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; ExifEntry *entry;
if( !(entry = exif_content_get_entry( ed->ifd[ifd], tag )) || if( !(entry = exif_content_get_entry( ed->ifd[ifd], tag )) ||
entry->format != EXIF_FORMAT_SHORT ||
entry->components != 1 ) entry->components != 1 )
return( -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 ) || if( get_entry_double( ed, 0, EXIF_TAG_X_RESOLUTION, &xres ) ||
get_entry_double( ed, 0, EXIF_TAG_Y_RESOLUTION, &yres ) || 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", vips_warn( "VipsJpeg",
"%s", _( "error reading resolution" ) ); "%s", _( "error reading resolution" ) );
return; return;

View File

@ -417,14 +417,12 @@ typedef void (*write_fn)( ExifData *ed,
/* Write a tag. Update what's there, or make a new one. /* Write a tag. Update what's there, or make a new one.
*/ */
static int static int
write_tag( ExifData *ed, int ifd, write_tag( ExifData *ed, int ifd, ExifTag tag, write_fn fn, void *data )
ExifTag tag, ExifFormat format, write_fn fn, void *data )
{ {
ExifEntry *entry; ExifEntry *entry;
if( (entry = exif_content_get_entry( ed->ifd[ifd], tag )) ) { 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 { else {
entry = exif_entry_new(); 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 /* Main image xres/yres/unit are in ifd0. ifd1 has the thumbnail
* xres/yres/unit. * 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 ) || 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 ) || 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_exif_set_int, (void *) &unit ) ) {
vips_error( "VipsJpeg", vips_error( "VipsJpeg",
"%s", _( "error setting JPEG resolution" ) ); "%s", _( "error setting JPEG resolution" ) );