From 9c8790b40aa4de3a486608a0495836a91fc6b2b9 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 27 Nov 2017 15:15:21 +0000 Subject: [PATCH] setting EXIF data blocks sets other tags too calling vips_image_set() to set the EXIF data block VIPS_META_EXIF_NAME will automaticaly set other tags, like orientation etc. --- ChangeLog | 1 + libvips/foreign/exif.c | 2 +- libvips/foreign/jpeg2vips.c | 3 --- libvips/foreign/pforeign.h | 3 --- libvips/foreign/vips2webp.c | 1 + libvips/foreign/webp2vips.c | 5 ----- libvips/include/vips/internal.h | 3 +++ libvips/iofuncs/header.c | 10 ++++++++++ 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 926fde9d..0ee38139 100644 --- a/ChangeLog +++ b/ChangeLog @@ -40,6 +40,7 @@ - add gif-delay, gif-comment and gif-loop metadata - add dispose handling to gifload - deprecate the "centre" option for vips_resize(): it's now always on +- setting the EXIF data block automatically sets other image tags 29/8/17 started 8.5.9 - make --fail stop jpeg read on any libjpeg warning, thanks @mceachen diff --git a/libvips/foreign/exif.c b/libvips/foreign/exif.c index ee137159..c36de7e5 100644 --- a/libvips/foreign/exif.c +++ b/libvips/foreign/exif.c @@ -484,7 +484,7 @@ vips__exif_parse( VipsImage *image ) return( -1 ); } - /* Make sure all required fields are there before we attach to vips + /* Make sure all required fields are there before we attach the vips * metadata. */ exif_data_fix( ed ); diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index ecb583c6..1bca9fb7 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -514,9 +514,6 @@ read_jpeg_header( ReadJpeg *jpeg, VipsImage *out ) (VipsCallbackFn) vips_free, data, data_length ); } - if( vips__exif_parse( out ) ) - return( -1 ); - /* Tell downstream we are reading sequentially. */ vips_image_set_area( out, VIPS_META_SEQUENTIAL, NULL, NULL ); diff --git a/libvips/foreign/pforeign.h b/libvips/foreign/pforeign.h index 2b0f207f..08973569 100644 --- a/libvips/foreign/pforeign.h +++ b/libvips/foreign/pforeign.h @@ -239,9 +239,6 @@ int vips__openslide_read( const char *filename, VipsImage *out, int vips__openslide_read_associated( const char *filename, VipsImage *out, const char *associated ); -int vips__exif_parse( VipsImage *image ); -int vips__exif_update( VipsImage *image ); - #ifdef __cplusplus } #endif /*__cplusplus*/ diff --git a/libvips/foreign/vips2webp.c b/libvips/foreign/vips2webp.c index 5119c94e..3725e100 100644 --- a/libvips/foreign/vips2webp.c +++ b/libvips/foreign/vips2webp.c @@ -53,6 +53,7 @@ #include #include +#include #include "pforeign.h" diff --git a/libvips/foreign/webp2vips.c b/libvips/foreign/webp2vips.c index ee542c40..971f9238 100644 --- a/libvips/foreign/webp2vips.c +++ b/libvips/foreign/webp2vips.c @@ -269,11 +269,6 @@ read_header( Read *read, VipsImage *out ) } WebPMuxDelete( mux ); - - /* We may have read some exif ... parse into the header. - */ - if( vips__exif_parse( out ) ) - return( -1 ); } #endif /*HAVE_LIBWEBPMUX*/ diff --git a/libvips/include/vips/internal.h b/libvips/include/vips/internal.h index 1fa988a9..1b9ae9de 100644 --- a/libvips/include/vips/internal.h +++ b/libvips/include/vips/internal.h @@ -52,6 +52,9 @@ typedef struct _VipsMeta { GValue value; /* copy of value */ } VipsMeta; +int vips__exif_parse( VipsImage *image ); +int vips__exif_update( VipsImage *image ); + void vips_check_init( void ); void vips__meta_init_types( void ); diff --git a/libvips/iofuncs/header.c b/libvips/iofuncs/header.c index 7c3b2184..1f6c60ff 100644 --- a/libvips/iofuncs/header.c +++ b/libvips/iofuncs/header.c @@ -962,6 +962,16 @@ vips_image_set( VipsImage *image, const char *name, GValue *value ) meta_init( image ); (void) meta_new( image, name, value ); + /* If we're setting an EXIF data block, we need to automatically expand + * out all the tags. This will set things like xres/yres too. + * + * We do this herfe rather than in meta_new() since we don't want to + * trigger on copy_fields. + */ + if( strcmp( name, VIPS_META_EXIF_NAME ) == 0 ) + if( vips__exif_parse( image ) ) + g_warning( "image_set: bad exif data" ); + #ifdef DEBUG meta_sanity( image ); #endif /*DEBUG*/