From bba1aba4b668d2f0dbb1650c31fb985582c5badf Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 22 Nov 2016 18:04:58 +0000 Subject: [PATCH] don't clear meta before creating a pipeline vips__image_copy_fields_array() used to wipe meta on the output before merging the input images. This broke foreign.c in some cases, since it likes setting some meta on the output before calling the subclass loaders, and they sometimes call write(). see https://github.com/jcupitt/ruby-vips/issues/93 --- libvips/include/vips/header.h | 1 + libvips/iofuncs/header.c | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/libvips/include/vips/header.h b/libvips/include/vips/header.h index 691a407f..5affb207 100644 --- a/libvips/include/vips/header.h +++ b/libvips/include/vips/header.h @@ -190,6 +190,7 @@ int vips_image_get_string( const VipsImage *image, const char *name, const char **out ); void vips_image_set_string( VipsImage *image, const char *name, const char *str ); +void vips_image_print_field( const VipsImage *image, const char *field ); int vips_image_history_printf( VipsImage *image, const char *format, ... ) __attribute__((format(printf, 2, 3))); diff --git a/libvips/iofuncs/header.c b/libvips/iofuncs/header.c index 4a4f6965..bd361235 100644 --- a/libvips/iofuncs/header.c +++ b/libvips/iofuncs/header.c @@ -893,8 +893,11 @@ vips__image_copy_fields_array( VipsImage *out, VipsImage *in[] ) /* Need to copy last-to-first so that in0 meta will override any * earlier meta. + * + * Don't destroy the meta on out. Things like foreign.c like setting + * image properties before calling a subclass loader, and those + * subclass loaders will sometimes write to an image. */ - vips__meta_destroy( out ); for( i = ni - 1; i >= 0; i-- ) if( meta_cp( out, in[i] ) ) return( -1 ); @@ -1573,6 +1576,28 @@ vips_image_get_as_string( const VipsImage *image, return( 0 ); } +/** + * vips_image_print_field: + * @image: image to get the header field from + * @field: field name + * + * Prints a field to stdout as ASCII. Handy for debugging. + */ +void +vips_image_print_field( const VipsImage *image, const char *field ) +{ + char *str; + + if( vips_image_get_as_string( image, field, &str ) ) { + printf( "vips_image_print_field: unable to read field\n" ); + return; + } + + printf( ".%s: %s\n", field, str ); + + g_free( str ); +} + /** * vips_image_history_printf: * @image: add history line to this image