diff --git a/libvips/foreign/vipspng.c b/libvips/foreign/vipspng.c index 40d594cc..a890b0be 100644 --- a/libvips/foreign/vipspng.c +++ b/libvips/foreign/vipspng.c @@ -1067,73 +1067,72 @@ write_vips( Write *write, VIPS_RINT( in->Xres * 1000 ), VIPS_RINT( in->Yres * 1000 ), PNG_RESOLUTION_METER ); - /* Set ICC Profile. + /* Metadata */ - if( profile && - !strip ) { - VipsBlob *blob; + if( !strip ) { + if( profile ) { + VipsBlob *blob; - if( vips_profile_load( profile, &blob, NULL ) ) - return( -1 ); - if( blob ) { - size_t length; - const void *data = vips_blob_get( blob, &length ); + if( vips_profile_load( profile, &blob, NULL ) ) + return( -1 ); + if( blob ) { + size_t length; + const void *data = vips_blob_get( blob, &length ); #ifdef DEBUG - printf( "write_vips: " - "attaching %zd bytes of ICC profile\n", - length ); + printf( "write_vips: attaching %zd bytes " + "of ICC profile\n", length ); #endif /*DEBUG*/ - png_set_iCCP( write->pPng, write->pInfo, "icc", + png_set_iCCP( write->pPng, write->pInfo, + "icc", PNG_COMPRESSION_TYPE_BASE, + data, length ); + + vips_area_unref( (VipsArea *) blob ); + } + } + else if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) { + const void *data; + size_t length; + + if( vips_image_get_blob( in, VIPS_META_ICC_NAME, + &data, &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 ); - vips_area_unref( (VipsArea *) blob ); } - } - else if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) && - !strip ) { - const void *data; - size_t size; - if( vips_image_get_blob( in, VIPS_META_ICC_NAME, - &data, &size ) ) - return( -1 ); + if( vips_image_get_typeof( in, VIPS_META_XMP_NAME ) ) { + const void *data; + size_t length; + char *str; -#ifdef DEBUG - printf( "write_vips: attaching %zd bytes of ICC profile\n", - size ); -#endif /*DEBUG*/ + /* XMP is attached as a BLOB with no null-termination. + * We must re-add this. + */ + if( vips_image_get_blob( in, + VIPS_META_XMP_NAME, &data, &length ) ) + return( -1 ); - png_set_iCCP( write->pPng, write->pInfo, "icc", - PNG_COMPRESSION_TYPE_BASE, data, size ); - } + 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 ); + } - if( vips_image_get_typeof( in, VIPS_META_XMP_NAME ) ) { - const void *data; - size_t size; - char *str; - - /* XMP is attached as a BLOB with no null-termination. We - * must re-add this. - */ - if( vips_image_get_blob( in, - VIPS_META_XMP_NAME, &data, &size ) ) + if( vips_image_map( in, + write_png_comment, write ) ) return( -1 ); - - str = g_malloc( size + 1 ); - vips_strncpy( str, data, size + 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 if( palette ) { VipsImage *im_index;