diff --git a/ChangeLog b/ChangeLog index 750d5a91..2e19248f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,7 +19,7 @@ - vips_log(), vips_log10() are zero-avoiding - better overlap handling for dzsave, thanks robclouth - add @spacing option to vips_text() -- tiff loads and saves IPCT data +- tiff loads and saves IPCT and Photoshop data 7/5/15 started 8.0.3 - dzsave and tif pyr write could fail for some image dimensions, thanks Jonas diff --git a/libvips/foreign/tiff2vips.c b/libvips/foreign/tiff2vips.c index 13532f3f..432ee1ce 100644 --- a/libvips/foreign/tiff2vips.c +++ b/libvips/foreign/tiff2vips.c @@ -159,6 +159,7 @@ * fd during file read, handy for large numbers of input images * 29/9/15 * - load IPCT metadata + * - load photoshop metadata */ /* @@ -1202,6 +1203,19 @@ parse_header( ReadTiff *rtiff, VipsImage *out ) (VipsCallbackFn) vips_free, data_copy, data_length ); } + /* Read any photoshop metadata. + */ + if( TIFFGetField( rtiff->tiff, + TIFFTAG_PHOTOSHOP, &data_length, &data ) ) { + void *data_copy; + + if( !(data_copy = vips_malloc( NULL, data_length )) ) + return( -1 ); + memcpy( data_copy, data, data_length ); + vips_image_set_blob( out, VIPS_META_PHOTOSHOP_NAME, + (VipsCallbackFn) vips_free, data_copy, data_length ); + } + return( 0 ); } diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index 746bb781..1159c019 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -155,6 +155,7 @@ * - add miniswhite option * 29/9/15 * - try to write IPCT metadata + * - try to write photoshop metadata */ /* @@ -473,7 +474,29 @@ write_embed_ipct( Write *write, TIFF *tif ) TIFFSetField( tif, TIFFTAG_RICHTIFFIPTC, data_length, data ); #ifdef DEBUG - printf( "vips2tiff: attached XMP from meta\n" ); + printf( "vips2tiff: attached IPCT from meta\n" ); +#endif /*DEBUG*/ + + return( 0 ); +} + +/* Embed any XMP metadata. + */ +static int +write_embed_photoshop( Write *write, TIFF *tif ) +{ + void *data; + size_t data_length; + + if( !vips_image_get_typeof( write->im, VIPS_META_PHOTOSHOP_NAME ) ) + return( 0 ); + if( vips_image_get_blob( write->im, VIPS_META_PHOTOSHOP_NAME, + &data, &data_length ) ) + return( -1 ); + TIFFSetField( tif, TIFFTAG_PHOTOSHOP, data_length, data ); + +#ifdef DEBUG + printf( "vips2tiff: attached photoshop data from meta\n" ); #endif /*DEBUG*/ return( 0 ); @@ -514,7 +537,8 @@ write_tiff_header( Write *write, Layer *layer ) if( write_embed_profile( write, tif ) || write_embed_xmp( write, tif ) || - write_embed_ipct( write, tif ) ) + write_embed_ipct( write, tif ) || + write_embed_photoshop( write, tif ) ) return( -1 ); /* And colour fields. @@ -1461,7 +1485,8 @@ write_copy_tiff( Write *write, TIFF *out, TIFF *in ) */ if( write_embed_profile( write, out ) || write_embed_xmp( write, out ) || - write_embed_ipct( write, out ) ) + write_embed_ipct( write, out ) || + write_embed_photoshop( write, out ) ) return( -1 ); buf = vips_malloc( NULL, TIFFTileSize( in ) ); diff --git a/libvips/include/vips/header.h b/libvips/include/vips/header.h index 2a7bdeb6..45e8163b 100644 --- a/libvips/include/vips/header.h +++ b/libvips/include/vips/header.h @@ -48,17 +48,25 @@ extern "C" { /** * VIPS_META_XMP_NAME: * - * The name that JPEG read and write operations use for the image's XMP data. + * The name that read and write operations use for the image's XMP data. */ #define VIPS_META_XMP_NAME "xmp-data" /** * VIPS_META_IPCT_NAME: * - * The name that JPEG read and write operations use for the image's IPCT data. + * The name that read and write operations use for the image's IPCT data. */ #define VIPS_META_IPCT_NAME "ipct-data" +/** + * VIPS_META_PHOTOSHOP_NAME: + * + * The name that TIFF read and write operations use for the image's + * TIFFTAG_PHOTOSHOP data. + */ +#define VIPS_META_PHOTOSHOP_NAME "photoshop-data" + /** * VIPS_META_ICC_NAME: *