Merge pull request #1850 from lovell/heif-compression-metadata

heifload: expose heif-compression metadata
This commit is contained in:
John Cupitt 2020-10-10 06:07:02 +01:00 committed by GitHub
commit 302f1f70d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -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"

View File

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