From da8cee048ff0e22d9f8b4277b7fc1f0e9a98c9d3 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 1 Sep 2019 16:58:50 +0100 Subject: [PATCH] enable alpha in heifsave Check for image alpha and enable it. There seem to be some non-transparent tiles, curiously. See https://github.com/libvips/libvips/issues/1411 --- ChangeLog | 2 +- libvips/foreign/heifsave.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index e187cb1e..3c99096a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,7 +11,7 @@ - add vips_switch() / vips_case() ... fast many-way ifthenelse - better const handling for arithmetic operators fixes comparisons against out of range values -- handle alpha in heifload [meyermarcel] +- handle alpha in heifload / heifsave [meyermarcel] 31/8/19 started 8.8.3 - revert sharpen restoring the input colourspace diff --git a/libvips/foreign/heifsave.c b/libvips/foreign/heifsave.c index 05a7a516..7fe44bf8 100644 --- a/libvips/foreign/heifsave.c +++ b/libvips/foreign/heifsave.c @@ -4,6 +4,8 @@ * - from niftisave.c * 3/7/19 [lovell] * - add "compression" option + * 1/9/19 [meyermarcel] + * - save alpha when necessary */ /* @@ -199,10 +201,8 @@ vips_foreign_save_heif_write_page( VipsForeignSaveHeif *heif, int page ) #ifdef HAVE_HEIF_ENCODING_OPTIONS_ALLOC options = heif_encoding_options_alloc(); - /* FIXME .. should be an option, though I don't know of any way to - * test it - */ - options->save_alpha_channel = 1; + if( vips_image_hasalpha( save->ready ) ) + options->save_alpha_channel = 1; #else /*!HAVE_HEIF_ENCODING_OPTIONS_ALLOC*/ options = NULL; #endif /*HAVE_HEIF_ENCODING_OPTIONS_ALLOC*/ @@ -294,6 +294,7 @@ vips_foreign_save_heif_build( VipsObject *object ) VipsForeignSaveHeif *heif = (VipsForeignSaveHeif *) object; struct heif_error error; + enum heif_chroma chroma; if( VIPS_OBJECT_CLASS( vips_foreign_save_heif_parent_class )-> build( object ) ) @@ -335,8 +336,10 @@ vips_foreign_save_heif_build( VipsObject *object ) /* Make a heif image the size of a page. We send sink_disc() output * here and write a frame each time it fills. */ + chroma = vips_image_hasalpha( save->ready ) ? + heif_chroma_interleaved_RGBA : heif_chroma_interleaved_RGB; error = heif_image_create( heif->page_width, heif->page_height, - heif_colorspace_RGB, heif_chroma_interleaved_RGB, &heif->img ); + heif_colorspace_RGB, chroma, &heif->img ); if( error.code ) { vips__heif_error( &error ); return( -1 ); @@ -394,7 +397,7 @@ vips_foreign_save_heif_class_init( VipsForeignSaveHeifClass *class ) foreign_class->suffs = vips__heif_suffs; - save_class->saveable = VIPS_SAVEABLE_RGB; + save_class->saveable = VIPS_SAVEABLE_RGBA_ONLY; save_class->format_table = vips_heif_bandfmt; VIPS_ARG_INT( class, "Q", 10,