Skip to content

Commit 616c60f

Browse files
committed
GTiff mask overview: fix vertical shift in internal mask overview computation
Fixes OSGeo#11555
1 parent 8d5ca35 commit 616c60f

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

autotest/gcore/data/test_11555.tif

33.2 KB
Binary file not shown.

autotest/gcore/tiff_ovr.py

+35
Original file line numberDiff line numberDiff line change
@@ -2950,3 +2950,38 @@ def test_tiff_ovr_JXL_ALPHA_DISTANCE_OVERVIEW(tmp_vsimem):
29502950
assert ds.GetRasterBand(4).Checksum() != cs4
29512951
del ds
29522952
gdal.Unlink(tmpfilename + ".ovr")
2953+
2954+
2955+
###############################################################################
2956+
# Test fix for https://github.com/OSGeo/gdal/issues/11555
2957+
2958+
2959+
def test_tiff_ovr_internal_mask_issue_11555(tmp_vsimem):
2960+
2961+
if "debug build" in gdal.VersionInfo("--version") and "CI" in os.environ:
2962+
pytest.skip("test skipped on CI for debug builds (to keep things fast)")
2963+
2964+
tmpfilename = str(tmp_vsimem / "test.tif")
2965+
gdal.FileFromMemBuffer(tmpfilename, open("data/test_11555.tif", "rb").read())
2966+
2967+
ds = gdal.Open(tmpfilename, gdal.GA_Update)
2968+
ds.BuildOverviews("bilinear", [2])
2969+
del ds
2970+
2971+
ds = gdal.Open(tmpfilename)
2972+
2973+
# Check that we have non-zero data when mask = 255
2974+
assert ds.GetRasterBand(1).GetOverview(0).ReadRaster(0, 5270, 1, 1) == b"\x7F"
2975+
assert ds.GetRasterBand(2).GetOverview(0).ReadRaster(0, 5270, 1, 1) == b"\x7F"
2976+
assert (
2977+
ds.GetRasterBand(1).GetMaskBand().GetOverview(0).ReadRaster(0, 5270, 1, 1)
2978+
== b"\xFF"
2979+
)
2980+
2981+
# Check that we have zero data when mask = 0
2982+
assert ds.GetRasterBand(1).GetOverview(0).ReadRaster(0, 5271, 1, 1) == b"\x00"
2983+
assert ds.GetRasterBand(2).GetOverview(0).ReadRaster(0, 5271, 1, 1) == b"\x00"
2984+
assert (
2985+
ds.GetRasterBand(1).GetMaskBand().GetOverview(0).ReadRaster(0, 5271, 1, 1)
2986+
== b"\x00"
2987+
)

gcore/overview.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4964,7 +4964,7 @@ CPLErr GDALRegenerateOverviewsEx(GDALRasterBandH hSrcBand, int nOverviewCount,
49644964
poJob->nSrcHeight = nHeight;
49654965
poJob->args.nChunkXOff = 0;
49664966
poJob->args.nChunkXSize = nWidth;
4967-
poJob->args.nChunkYOff = nChunkYOff;
4967+
poJob->args.nChunkYOff = nChunkYOffQueried;
49684968
poJob->args.nChunkYSize = nChunkYSizeQueried;
49694969
poJob->nDstWidth = nDstWidth;
49704970
poJob->args.nDstXOff = 0;

0 commit comments

Comments
 (0)