load and save TIFFTAG_IMAGEDESCRIPTION

this often has useful metadata in, for example the OME spec has all the
metadata in there as an XML document

see https://github.com/jcupitt/libvips/issues/358
This commit is contained in:
John Cupitt 2015-12-21 13:53:33 +00:00
parent 7267ca4a28
commit 0deb640bc4
5 changed files with 50 additions and 5 deletions

View File

@ -23,6 +23,7 @@
- oop, removed a DEBUG from buffer.c, vips is 30% faster - oop, removed a DEBUG from buffer.c, vips is 30% faster
- faster and lower-mem TIFF read - faster and lower-mem TIFF read
- faster bilinear interpolator - faster bilinear interpolator
- TIFF loads and saves IMAGEDESCRIPTION
7/5/15 started 8.1.1 7/5/15 started 8.1.1
- oop, vips-8.0 wrapper script should be vips-8.1, thanks Danilo - oop, vips-8.0 wrapper script should be vips-8.1, thanks Danilo

View File

@ -160,6 +160,8 @@
* 29/9/15 * 29/9/15
* - load IPCT metadata * - load IPCT metadata
* - load photoshop metadata * - load photoshop metadata
* 21/12/15
* - load TIFFTAG_IMAGEDESCRIPTION
*/ */
/* /*
@ -1224,6 +1226,16 @@ parse_header( ReadTiff *rtiff, VipsImage *out )
(VipsCallbackFn) vips_free, data_copy, data_length ); (VipsCallbackFn) vips_free, data_copy, data_length );
} }
/* IMAGEDESCRIPTION often has useful metadata.
*/
if( TIFFGetField( rtiff->tiff, TIFFTAG_IMAGEDESCRIPTION, &data ) ) {
/* libtiff makes sure that data is null-terminated and contains
* no embedded null characters.
*/
vips_image_set_string( out,
VIPS_META_IMAGEDESCRIPTION, (char *) data );
}
return( 0 ); return( 0 );
} }

View File

@ -158,6 +158,8 @@
* - try to write photoshop metadata * - try to write photoshop metadata
* 11/11/15 * 11/11/15
* - better alpha handling, thanks sadaqatullahn * - better alpha handling, thanks sadaqatullahn
* 21/12/15
* - write TIFFTAG_IMAGEDESCRIPTION
*/ */
/* /*
@ -496,8 +498,8 @@ write_embed_photoshop( Write *write, TIFF *tif )
if( !vips_image_get_typeof( write->im, VIPS_META_PHOTOSHOP_NAME ) ) if( !vips_image_get_typeof( write->im, VIPS_META_PHOTOSHOP_NAME ) )
return( 0 ); return( 0 );
if( vips_image_get_blob( write->im, VIPS_META_PHOTOSHOP_NAME, if( vips_image_get_blob( write->im,
&data, &data_length ) ) VIPS_META_PHOTOSHOP_NAME, &data, &data_length ) )
return( -1 ); return( -1 );
TIFFSetField( tif, TIFFTAG_PHOTOSHOP, data_length, data ); TIFFSetField( tif, TIFFTAG_PHOTOSHOP, data_length, data );
@ -508,6 +510,27 @@ write_embed_photoshop( Write *write, TIFF *tif )
return( 0 ); return( 0 );
} }
/* Set IMAGEDESCRIPTION, if it's there.
*/
static int
write_embed_imagedescription( Write *write, TIFF *tif )
{
const char *imagedescription;
if( !vips_image_get_typeof( write->im, VIPS_META_IMAGEDESCRIPTION ) )
return( 0 );
if( vips_image_get_string( write->im,
VIPS_META_IMAGEDESCRIPTION, &imagedescription ) )
return( -1 );
TIFFSetField( tif, TIFFTAG_IMAGEDESCRIPTION, imagedescription );
#ifdef DEBUG
printf( "vips2tiff: attached imagedescription from meta\n" );
#endif /*DEBUG*/
return( 0 );
}
/* Write a TIFF header. width and height are the size of the VipsImage we are /* Write a TIFF header. width and height are the size of the VipsImage we are
* writing (it may have been shrunk). * writing (it may have been shrunk).
*/ */
@ -543,7 +566,8 @@ write_tiff_header( Write *write, Layer *layer )
if( write_embed_profile( write, tif ) || if( write_embed_profile( write, tif ) ||
write_embed_xmp( write, tif ) || write_embed_xmp( write, tif ) ||
write_embed_ipct( write, tif ) || write_embed_ipct( write, tif ) ||
write_embed_photoshop( write, tif ) ) write_embed_photoshop( write, tif ) ||
write_embed_imagedescription( write, tif ) )
return( -1 ); return( -1 );
/* And colour fields. /* And colour fields.
@ -1497,7 +1521,8 @@ write_copy_tiff( Write *write, TIFF *out, TIFF *in )
if( write_embed_profile( write, out ) || if( write_embed_profile( write, out ) ||
write_embed_xmp( write, out ) || write_embed_xmp( write, out ) ||
write_embed_ipct( write, out ) || write_embed_ipct( write, out ) ||
write_embed_photoshop( write, out ) ) write_embed_photoshop( write, out ) ||
write_embed_imagedescription( write, out ) )
return( -1 ); return( -1 );
buf = vips_malloc( NULL, TIFFTileSize( in ) ); buf = vips_malloc( NULL, TIFFTileSize( in ) );

View File

@ -85,6 +85,13 @@ extern "C" {
*/ */
#define VIPS_META_XML "xml-header" #define VIPS_META_XML "xml-header"
/**
* VIPS_META_IMAGEDESCRIPTION:
*
* The IMAGEDESCRIPTION tag. Often has useful metadata.
*/
#define VIPS_META_IMAGEDESCRIPTION "image-description"
/** /**
* VIPS_META_RESOLUTION_UNIT: * VIPS_META_RESOLUTION_UNIT:
* *

View File

@ -1413,7 +1413,7 @@ vips_value_get_ref_string( const GValue *value, size_t *length )
* Copies the C string @str into @value. * Copies the C string @str into @value.
* *
* vips_ref_string are immutable C strings that are copied between images by * vips_ref_string are immutable C strings that are copied between images by
* copying reference-counted pointers, making the much more efficient than * copying reference-counted pointers, making them much more efficient than
* regular %GValue strings. * regular %GValue strings.
*/ */
void void