make tiff load and save IPCT data

we did XMP already, but add IPCT as well

see https://github.com/jcupitt/libvips/issues/332
This commit is contained in:
John Cupitt 2015-09-29 17:41:11 +01:00
parent e62df8c573
commit 3889dcc3e2
3 changed files with 65 additions and 7 deletions

View File

@ -19,6 +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
7/5/15 started 8.0.3
- dzsave and tif pyr write could fail for some image dimensions, thanks Jonas

View File

@ -157,6 +157,8 @@
* 26/2/15
* - close the read down early for a header read ... this saves an
* fd during file read, handy for large numbers of input images
* 29/9/15
* - load IPCT metadata
*/
/*
@ -1182,6 +1184,24 @@ parse_header( ReadTiff *rtiff, VipsImage *out )
(VipsCallbackFn) vips_free, data_copy, data_length );
}
/* Read any IPCT metadata.
*/
if( TIFFGetField( rtiff->tiff,
TIFFTAG_RICHTIFFIPTC, &data_length, &data ) ) {
void *data_copy;
/* For no very good reason, libtiff stores IPCT as an array of
* long, not byte.
*/
data_length *= 4;
if( !(data_copy = vips_malloc( NULL, data_length )) )
return( -1 );
memcpy( data_copy, data, data_length );
vips_image_set_blob( out, VIPS_META_IPCT_NAME,
(VipsCallbackFn) vips_free, data_copy, data_length );
}
return( 0 );
}

View File

@ -153,6 +153,8 @@
* 27/3/15
* - squash >128 rather than >0, nicer results for shrink
* - add miniswhite option
* 29/9/15
* - try to write IPCT metadata
*/
/*
@ -442,6 +444,41 @@ write_embed_xmp( Write *write, TIFF *tif )
return( 0 );
}
/* Embed any IPCT metadata.
*/
static int
write_embed_ipct( Write *write, TIFF *tif )
{
void *data;
size_t data_length;
if( !vips_image_get_typeof( write->im, VIPS_META_IPCT_NAME ) )
return( 0 );
if( vips_image_get_blob( write->im, VIPS_META_IPCT_NAME,
&data, &data_length ) )
return( -1 );
/* For no very good reason, libtiff stores IPCT as an array of
* long, not byte.
*/
if( data_length & 3 ) {
vips_warn( "vips2tiff",
"%s", _( "rounding up IPCT data length" ) );
data_length /= 4;
data_length += 1;
}
else
data_length /= 4;
TIFFSetField( tif, TIFFTAG_RICHTIFFIPTC, data_length, data );
#ifdef DEBUG
printf( "vips2tiff: attached XMP from meta\n" );
#endif /*DEBUG*/
return( 0 );
}
/* Write a TIFF header. width and height are the size of the VipsImage we are
* writing (it may have been shrunk).
*/
@ -475,10 +512,10 @@ write_tiff_header( Write *write, Layer *layer )
TIFFSetField( tif, TIFFTAG_YRESOLUTION,
VIPS_CLIP( 0.01, write->yres, 1000000 ) );
if( write_embed_profile( write, tif ) )
return( -1 );
if( write_embed_xmp( write, tif ) )
return( -1 );
if( write_embed_profile( write, tif ) ||
write_embed_xmp( write, tif ) ||
write_embed_ipct( write, tif ) )
return( -1 );
/* And colour fields.
*/
@ -1422,9 +1459,9 @@ write_copy_tiff( Write *write, TIFF *out, TIFF *in )
/* We can't copy profiles or xmp :( Set again from Write.
*/
if( write_embed_profile( write, out ) )
return( -1 );
if( write_embed_xmp( write, out ) )
if( write_embed_profile( write, out ) ||
write_embed_xmp( write, out ) ||
write_embed_ipct( write, out ) )
return( -1 );
buf = vips_malloc( NULL, TIFFTileSize( in ) );