From e131f173a0f1dd6bd68b64d1a88cf5a06b1e1652 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 20 Jan 2019 21:08:06 +0000 Subject: [PATCH] fix up exif parse, add icc profile attach --- libvips/foreign/heifload.c | 39 +++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/libvips/foreign/heifload.c b/libvips/foreign/heifload.c index 1d7f3dd6..bb40776b 100644 --- a/libvips/foreign/heifload.c +++ b/libvips/foreign/heifload.c @@ -211,7 +211,7 @@ vips_foreign_load_heif_set_header( VipsForeignLoadHeif *heif, VipsImage *out ) const char *type = heif_image_handle_get_metadata_type( heif->handle, id[i] ); - void *data; + unsigned char *data; char name[256]; /* exif has a special name. @@ -223,20 +223,49 @@ vips_foreign_load_heif_set_header( VipsForeignLoadHeif *heif, VipsImage *out ) printf( "metadata type = %s, length = %zd\n", type, length ); - data = g_malloc( length ); + if( !(data = VIPS_ARRAY( out, length, unsigned char )) ) + return( -1 ); error = heif_image_handle_get_metadata( heif->handle, id[i], data ); if( error.code ) { vips_heif_error( error ); - g_free( data ); return( -1 ); } + /* We need to skip the first four bytes of EXIF, they just + * contain the offset. + */ + if( strcasecmp( type, "exif" ) == 0 ) { + data += 4; + length -= 4; + } + vips_image_set_blob( out, name, - (VipsCallbackFn) vips_free, data, length ); + (VipsCallbackFn) NULL, data, length ); if( strcasecmp( type, "exif" ) == 0 ) - vips__exif_parse( out ); + (void) vips__exif_parse( out ); + } + + if( heif_image_handle_get_color_profile_type( heif->handle ) ) { + size_t length = heif_image_handle_get_raw_color_profile_size( + heif->handle ); + + unsigned char *data; + + if( !(data = VIPS_ARRAY( out, length, unsigned char )) ) + return( -1 ); + error = heif_image_handle_get_raw_color_profile( + heif->handle, data ); + if( error.code ) { + vips_heif_error( error ); + return( -1 ); + } + + printf( "profile data, length = %zd\n", length ); + + vips_image_set_blob( out, VIPS_META_ICC_NAME, + (VipsCallbackFn) NULL, data, length ); } return( 0 );