Merge pull request #1207 from lovell/png-strip-xmp

PNG writer: ensure XMP metadata is ignored when strip=TRUE
This commit is contained in:
John Cupitt 2019-01-10 10:43:18 +00:00 committed by GitHub
commit 3de9f896ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1067,71 +1067,73 @@ write_vips( Write *write,
VIPS_RINT( in->Xres * 1000 ), VIPS_RINT( in->Yres * 1000 ), VIPS_RINT( in->Xres * 1000 ), VIPS_RINT( in->Yres * 1000 ),
PNG_RESOLUTION_METER ); PNG_RESOLUTION_METER );
/* Set ICC Profile. /* Metadata
*/ */
if( profile && if( !strip ) {
!strip ) { /* Set ICC Profile.
if( strcmp( profile, "none" ) != 0 ) { */
if( profile ) {
if( strcmp( profile, "none" ) != 0 ) {
void *data;
size_t length;
if( !(data = vips__file_read_name( profile,
vips__icc_dir(), &length )) )
return( -1 );
#ifdef DEBUG
printf( "write_vips: "
"attaching %zd bytes of ICC profile\n",
length );
#endif /*DEBUG*/
png_set_iCCP( write->pPng, write->pInfo, "icc",
PNG_COMPRESSION_TYPE_BASE, data, length );
}
}
else if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) {
void *data; void *data;
size_t length; size_t length;
if( !(data = vips__file_read_name( profile, if( vips_image_get_blob( in, VIPS_META_ICC_NAME,
vips__icc_dir(), &length )) ) &data, &length ) )
return( -1 ); return( -1 );
#ifdef DEBUG #ifdef DEBUG
printf( "write_vips: " printf( "write_vips: attaching %zd bytes of ICC profile\n",
"attaching %zd bytes of ICC profile\n",
length ); length );
#endif /*DEBUG*/ #endif /*DEBUG*/
png_set_iCCP( write->pPng, write->pInfo, "icc", png_set_iCCP( write->pPng, write->pInfo, "icc",
PNG_COMPRESSION_TYPE_BASE, data, length ); PNG_COMPRESSION_TYPE_BASE, data, length );
} }
}
else if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) &&
!strip ) {
void *data;
size_t length;
if( vips_image_get_blob( in, VIPS_META_ICC_NAME, if( vips_image_get_typeof( in, VIPS_META_XMP_NAME ) ) {
&data, &length ) ) void *data;
return( -1 ); size_t length;
char *str;
#ifdef DEBUG /* XMP is attached as a BLOB with no null-termination. We
printf( "write_vips: attaching %zd bytes of ICC profile\n", * must re-add this.
length ); */
#endif /*DEBUG*/ if( vips_image_get_blob( in,
VIPS_META_XMP_NAME, &data, &length ) )
return( -1 );
png_set_iCCP( write->pPng, write->pInfo, "icc", str = g_malloc( length + 1 );
PNG_COMPRESSION_TYPE_BASE, data, length ); vips_strncpy( str, data, length + 1 );
} vips__png_set_text( write->pPng, write->pInfo,
"XML:com.adobe.xmp", str );
g_free( str );
}
if( vips_image_get_typeof( in, VIPS_META_XMP_NAME ) ) { /* Set any "png-comment-xx-yyy" metadata items.
void *data;
size_t length;
char *str;
/* XMP is attached as a BLOB with no null-termination. We
* must re-add this.
*/ */
if( vips_image_get_blob( in, if( vips_image_map( in,
VIPS_META_XMP_NAME, &data, &length ) ) write_png_comment, write ) )
return( -1 ); return( -1 );
str = g_malloc( length + 1 );
vips_strncpy( str, data, length + 1 );
vips__png_set_text( write->pPng, write->pInfo,
"XML:com.adobe.xmp", str );
g_free( str );
} }
/* Set any "png-comment-xx-yyy" metadata items.
*/
if( vips_image_map( in,
write_png_comment, write ) )
return( -1 );
#ifdef HAVE_IMAGEQUANT #ifdef HAVE_IMAGEQUANT
if( palette ) { if( palette ) {
VipsImage *im_index; VipsImage *im_index;