Skip to content

Commit

Permalink
Merge pull request #11069 from bradh/heif_supported_tests_2024-10-22
Browse files Browse the repository at this point in the history
heif: skip tests for unsupported codecs
  • Loading branch information
rouault authored Oct 22, 2024
2 parents 56b4519 + 040d76d commit 1222614
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
36 changes: 31 additions & 5 deletions autotest/gdrivers/heif.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -110,21 +135,20 @@ 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
assert ds.RasterCount == 4
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
Expand Down Expand Up @@ -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)
Expand Down
35 changes: 34 additions & 1 deletion frmts/heif/heifdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 0 additions & 3 deletions frmts/heif/heifdrivercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/************************************************************************/
Expand Down

0 comments on commit 1222614

Please sign in to comment.