From 040d76d81a03f2a150b144b805e0ceb64ad5a36e Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Tue, 22 Oct 2024 08:25:43 +1100 Subject: [PATCH] heif: skip tests for unsupported codecs --- autotest/gdrivers/heif.py | 36 ++++++++++++++++++++++++++++++----- frmts/heif/heifdataset.cpp | 35 +++++++++++++++++++++++++++++++++- frmts/heif/heifdrivercore.cpp | 3 --- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/autotest/gdrivers/heif.py b/autotest/gdrivers/heif.py index fa824d8c03b9..e26cff54bfe1 100644 --- a/autotest/gdrivers/heif.py +++ b/autotest/gdrivers/heif.py @@ -32,8 +32,26 @@ def get_version(): ] +def _has_tiling_support(): + drv = gdal.GetDriverByName("HEIF") + return drv and drv.GetMetadataItem("SUPPORTS_TILES", "HEIF") + + +def _has_hevc_decoding_support(): + drv = gdal.GetDriverByName("HEIF") + return drv and drv.GetMetadataItem("SUPPORTS_HEVC", "HEIF") + + +def _has_uncompressed_decoding_support(): + drv = gdal.GetDriverByName("HEIF") + return drv and drv.GetMetadataItem("SUPPORTS_UNCOMPRESSED", "HEIF") + + @pytest.mark.parametrize("endianness", ["big_endian", "little_endian"]) def test_heif_exif_endian(endianness): + if not _has_hevc_decoding_support(): + pytest.skip() + filename = "data/heif/byte_exif_%s.heic" % endianness gdal.ErrorReset() ds = gdal.Open(filename) @@ -63,6 +81,9 @@ def test_heif_exif_endian(endianness): def test_heif_thumbnail(): + if not _has_hevc_decoding_support(): + pytest.skip() + ds = gdal.Open("data/heif/byte_thumbnail.heic") assert ds assert ds.RasterXSize == 128 @@ -81,6 +102,8 @@ def test_heif_thumbnail(): def test_heif_rgb_16bit(): if get_version() < [1, 4, 0]: pytest.skip() + if not _has_hevc_decoding_support(): + pytest.skip() ds = gdal.Open("data/heif/small_world_16.heic") assert ds @@ -93,6 +116,8 @@ def test_heif_rgb_16bit(): def test_heif_rgba(): + if not _has_hevc_decoding_support(): + pytest.skip() ds = gdal.Open("data/heif/stefan_full_rgba.heic") assert ds @@ -110,6 +135,8 @@ def test_heif_rgba(): def test_heif_rgba_16bit(): if get_version() < [1, 4, 0]: pytest.skip() + if not _has_hevc_decoding_support(): + pytest.skip() ds = gdal.Open("data/heif/stefan_full_rgba_16.heic") assert ds @@ -117,14 +144,11 @@ def test_heif_rgba_16bit(): assert ds.GetRasterBand(1).DataType == gdal.GDT_UInt16 -def _has_tiling_support(): - drv = gdal.GetDriverByName("HEIF") - return drv and drv.GetMetadataItem("HEIF_SUPPORTS_TILES") - - def test_heif_tiled(): if not _has_tiling_support(): pytest.skip() + if not _has_uncompressed_decoding_support(): + pytest.skip() ds = gdal.Open("data/heif/uncompressed_comp_RGB_tiled.heif") assert ds @@ -361,6 +385,8 @@ def test_heif_tiled(): def test_heif_subdatasets(tmp_path): + if not _has_hevc_decoding_support(): + pytest.skip() filename = str(tmp_path / "out.heic") shutil.copy("data/heif/subdatasets.heic", filename) diff --git a/frmts/heif/heifdataset.cpp b/frmts/heif/heifdataset.cpp index 7862fdcefd57..3cdc9a7c5914 100644 --- a/frmts/heif/heifdataset.cpp +++ b/frmts/heif/heifdataset.cpp @@ -846,14 +846,47 @@ void GDALRegister_HEIF() HEIFDriverSetCommonMetadata(poDriver); #if LIBHEIF_NUMERIC_VERSION >= BUILD_LIBHEIF_VERSION(1, 12, 0) + if (heif_have_decoder_for_format(heif_compression_AVC)) + { + poDriver->SetMetadataItem("SUPPORTS_AVC", "YES", "HEIF"); + } // If the AVIF dedicated driver is not available, register an AVIF driver, // called AVIF_HEIF, based on libheif, if it has AV1 decoding capabilities. if (heif_have_decoder_for_format(heif_compression_AV1)) { poDriver->SetMetadataItem("SUPPORTS_AVIF", "YES", "HEIF"); } + if (heif_have_decoder_for_format(heif_compression_HEVC)) + { + poDriver->SetMetadataItem("SUPPORTS_HEVC", "YES", "HEIF"); + } + if (heif_have_decoder_for_format(heif_compression_JPEG)) + { + poDriver->SetMetadataItem("SUPPORTS_JPEG", "YES", "HEIF"); + } + if (heif_have_decoder_for_format(heif_compression_JPEG2000)) + { + poDriver->SetMetadataItem("SUPPORTS_JPEG2000", "YES", "HEIF"); + } + if (heif_have_decoder_for_format(heif_compression_HTJ2K)) + { + poDriver->SetMetadataItem("SUPPORTS_JPEG2000_HT", "YES", "HEIF"); + } + if (heif_have_decoder_for_format(heif_compression_uncompressed)) + { + poDriver->SetMetadataItem("SUPPORTS_UNCOMPRESSED", "YES", "HEIF"); + } + if (heif_have_decoder_for_format(heif_compression_VVC)) + { + poDriver->SetMetadataItem("SUPPORTS_VVC", "YES", "HEIF"); + } +#else + // Anything that old probably supports only HEVC + poDriver->SetMetadataItem("SUPPORTS_HEVC", "YES", "HEIF"); +#endif +#ifdef LIBHEIF_SUPPORTS_TILES + poDriver->SetMetadataItem("SUPPORTS_TILES", "YES", "HEIF"); #endif - poDriver->pfnOpen = GDALHEIFDataset::OpenHEIF; poDM->RegisterDriver(poDriver); } diff --git a/frmts/heif/heifdrivercore.cpp b/frmts/heif/heifdrivercore.cpp index 69e7b2ae28c1..012646d0860c 100644 --- a/frmts/heif/heifdrivercore.cpp +++ b/frmts/heif/heifdrivercore.cpp @@ -86,9 +86,6 @@ void HEIFDriverSetCommonMetadata(GDALDriver *poDriver) poDriver->pfnIdentify = HEIFDriverIdentifySimplified; poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); -#ifdef LIBHEIF_SUPPORTS_TILES - poDriver->SetMetadataItem("HEIF_SUPPORTS_TILES", "YES"); -#endif } /************************************************************************/