From 1177bd1dae4ba5fce7a5917ecb74d8cd33c598ef Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Fri, 9 Oct 2020 15:54:17 +0100 Subject: [PATCH] heifload: expose heif-compression metadata --- configure.ac | 12 ++++++++++++ libvips/foreign/heifload.c | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/configure.ac b/configure.ac index 71aa97a6..891bce12 100644 --- a/configure.ac +++ b/configure.ac @@ -888,6 +888,18 @@ if test x"$with_heif" = x"yes"; then LIBS="$save_LIBS" fi +# heif_main_brand added in 1.4.0 +if test x"$with_heif" = x"yes"; then + save_LIBS="$LIBS" + LIBS="$LIBS $HEIF_LIBS" + AC_CHECK_FUNCS(heif_main_brand,[ + AC_DEFINE(HAVE_HEIF_MAIN_BRAND,1, + [define if you have heif_main_brand.]) + ],[] + ) + LIBS="$save_LIBS" +fi + # heif_decoding_options.convert_hdr_to_8bit added in 1.7.0 if test x"$with_heif" = x"yes"; then save_CFLAGS="$CFLAGS" diff --git a/libvips/foreign/heifload.c b/libvips/foreign/heifload.c index 802fdc66..ca95e2f7 100644 --- a/libvips/foreign/heifload.c +++ b/libvips/foreign/heifload.c @@ -420,6 +420,7 @@ vips_foreign_load_heif_set_header( VipsForeignLoadHeif *heif, VipsImage *out ) heif_item_id id[16]; int n_metadata; struct heif_error error; + VipsForeignHeifCompression compression; /* We take the metadata from the non-thumbnail first page. HEIC * thumbnails don't have metadata. @@ -566,6 +567,25 @@ vips_foreign_load_heif_set_header( VipsForeignLoadHeif *heif, VipsImage *out ) vips_image_set_int( out, VIPS_META_PAGE_HEIGHT, heif->page_height ); + /* Determine compression from HEIF "brand" + * Requires libheif 1.4.0+, prior versions were HEVC only + */ + compression = VIPS_FOREIGN_HEIF_COMPRESSION_HEVC; + +#ifdef HAVE_HEIF_MAIN_BRAND + const unsigned char *brand_data; + if ( brand_data = vips_source_sniff( heif->source, 12 ) ) { + enum heif_brand brand; + brand = heif_main_brand( brand_data, 12 ); + if( brand == heif_avif || brand == heif_avis ) + compression = VIPS_FOREIGN_HEIF_COMPRESSION_AV1; + } +#endif /*HAVE_HEIF_MAIN_BRAND*/ + + vips_image_set_string( out, "heif-compression", + vips_enum_nick( VIPS_TYPE_FOREIGN_HEIF_COMPRESSION, + compression ) ); + /* FIXME .. we always decode to RGB in generate. We should check for * all grey images, perhaps. */