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. */