From b28a386c946269d310789cc916af43ed1bcfcb84 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 23 Nov 2023 17:44:33 +0100 Subject: [PATCH] gdal_footprint: fix -ovr on RGBA datasets (fixes #8792) --- apps/gdal_footprint_lib.cpp | 3 ++- autotest/utilities/test_gdal_footprint_lib.py | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/apps/gdal_footprint_lib.cpp b/apps/gdal_footprint_lib.cpp index dd02f0b911e8..aa09b6d378a8 100644 --- a/apps/gdal_footprint_lib.cpp +++ b/apps/gdal_footprint_lib.cpp @@ -703,7 +703,8 @@ static bool GDALFootprintProcess(GDALDataset *poSrcDS, OGRLayer *poDstLayer, { GDALRasterBand *poMaskBand; const int nMaskFlags = poBand->GetMaskFlags(); - if ((nMaskFlags & GMF_ALPHA) != 0) + if ((nMaskFlags & GMF_ALPHA) != 0 || + poBand->GetColorInterpretation() == GCI_AlphaBand) { poMaskBand = poBand; } diff --git a/autotest/utilities/test_gdal_footprint_lib.py b/autotest/utilities/test_gdal_footprint_lib.py index fdfbed3bb350..8accaa983330 100755 --- a/autotest/utilities/test_gdal_footprint_lib.py +++ b/autotest/utilities/test_gdal_footprint_lib.py @@ -427,3 +427,28 @@ def test_gdaldem_footprint_dict_arguments(): "-lco", "STRING_DEFAULT_WIDTH=10", ] + + +############################################################################### +# Test footprint, RGBA and overviews + + +def test_gdaldem_footprint_rgba_overviews(): + + src_ds = gdal.GetDriverByName("MEM").Create("", 6, 6, 4) + for i in range(4): + src_ds.GetRasterBand(i + 1).SetColorInterpretation(gdal.GCI_RedBand + i) + src_ds.BuildOverviews("NONE", [2]) + for i in range(4): + src_ds.GetRasterBand(i + 1).GetOverview(0).WriteRaster(1, 1, 1, 1, b"\xFF") + out_ds = gdal.Footprint( + "", + src_ds, + format="Memory", + targetCoordinateSystem="pixel", + ovr=0, + ) + assert out_ds is not None + lyr = out_ds.GetLayer(0) + f = lyr.GetNextFeature() + ogrtest.check_feature_geometry(f, "MULTIPOLYGON (((2 2,2 4,4 4,4 2,2 2)))")