vipsthumbnail copies metadata to embedded thumb

when working from the embedded thumbnail, vipsthumbnail now copies the
metadata from the main image onto the thumbnail

see

https://github.com/jcupitt/libvips/issues/109

thanks ottob
This commit is contained in:
John Cupitt 2014-03-04 14:36:49 +00:00
parent 499b977043
commit 4be4f9f0ff
2 changed files with 41 additions and 8 deletions

8
TODO
View File

@ -1,12 +1,4 @@
- vipsthumbnail needs to attach main image metadata to the jpeg header
thumbnail, see:
https://github.com/jcupitt/libvips/issues/109
- think of a better way to support skipahead - think of a better way to support skipahead
extract needs to hint to it's image sources what line it will start reading extract needs to hint to it's image sources what line it will start reading

View File

@ -189,6 +189,37 @@ thumbnail_find_jpegshrink( VipsImage *im )
#define THUMBNAIL "jpeg-thumbnail-data" #define THUMBNAIL "jpeg-thumbnail-data"
/* Copy a blob from one image to another.
*
* We don't make a private copy of the blob, we just copy pointers. Therefore
* @from must stay alive as long as @to is alive.
*/
static int
copy_blob( VipsImage *from, VipsImage *to, const char *field )
{
if( vips_image_get_typeof( from, field ) ) {
void *blob;
size_t blob_length;
if( vips_image_get_blob( from, field, &blob, &blob_length ) )
return( -1 );
vips_image_set_blob( to, field, NULL, blob, blob_length );
}
return( 0 );
}
static void *
copy_exif_field( VipsImage *from, const char *field, GValue *value, void *a )
{
VipsImage *to = (VipsImage *) a;
if( vips_isprefix( "exif-", field ) )
vips_image_set( to, field, value );
return( NULL );
}
/* Try to read an embedded thumbnail. /* Try to read an embedded thumbnail.
*/ */
static VipsImage * static VipsImage *
@ -228,6 +259,16 @@ thumbnail_get_thumbnail( VipsImage *im )
return( NULL ); return( NULL );
} }
/* Copy over the metadata from the main image. We want our thumbnail
* to have the orientation, profile etc. from there.
*/
if( copy_blob( im, thumb, VIPS_META_EXIF_NAME ) ||
copy_blob( im, thumb, VIPS_META_XMP_NAME ) ||
copy_blob( im, thumb, VIPS_META_IPCT_NAME ) ||
copy_blob( im, thumb, VIPS_META_ICC_NAME ) )
return( NULL );
(void) vips_image_map( im, copy_exif_field, thumb );
vips_info( "vipsthumbnail", "using %dx%d jpeg thumbnail", vips_info( "vipsthumbnail", "using %dx%d jpeg thumbnail",
thumb->Xsize, thumb->Ysize ); thumb->Xsize, thumb->Ysize );