Skip to content

Commit

Permalink
Merge pull request #11577 from OSGeo/backport-11562-to-release/3.10
Browse files Browse the repository at this point in the history
[Backport release/3.10] GTiff mask overview: fix vertical shift in internal mask overview computation
  • Loading branch information
rouault authored Jan 5, 2025
2 parents ea151b7 + 509d01e commit 8eb0778
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Binary file added autotest/gcore/data/test_11555.tif
Binary file not shown.
35 changes: 35 additions & 0 deletions autotest/gcore/tiff_ovr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2996,3 +2996,38 @@ def test_tiff_ovr_JXL_ALPHA_DISTANCE_OVERVIEW(tmp_vsimem):
assert ds.GetRasterBand(4).Checksum() != cs4
del ds
gdal.Unlink(tmpfilename + ".ovr")


###############################################################################
# Test fix for https://github.com/OSGeo/gdal/issues/11555


def test_tiff_ovr_internal_mask_issue_11555(tmp_vsimem):

if "debug build" in gdal.VersionInfo("--version") and "CI" in os.environ:
pytest.skip("test skipped on CI for debug builds (to keep things fast)")

tmpfilename = str(tmp_vsimem / "test.tif")
gdal.FileFromMemBuffer(tmpfilename, open("data/test_11555.tif", "rb").read())

ds = gdal.Open(tmpfilename, gdal.GA_Update)
ds.BuildOverviews("bilinear", [2])
del ds

ds = gdal.Open(tmpfilename)

# Check that we have non-zero data when mask = 255
assert ds.GetRasterBand(1).GetOverview(0).ReadRaster(0, 5270, 1, 1) == b"\x7F"
assert ds.GetRasterBand(2).GetOverview(0).ReadRaster(0, 5270, 1, 1) == b"\x7F"
assert (
ds.GetRasterBand(1).GetMaskBand().GetOverview(0).ReadRaster(0, 5270, 1, 1)
== b"\xFF"
)

# Check that we have zero data when mask = 0
assert ds.GetRasterBand(1).GetOverview(0).ReadRaster(0, 5271, 1, 1) == b"\x00"
assert ds.GetRasterBand(2).GetOverview(0).ReadRaster(0, 5271, 1, 1) == b"\x00"
assert (
ds.GetRasterBand(1).GetMaskBand().GetOverview(0).ReadRaster(0, 5271, 1, 1)
== b"\x00"
)
2 changes: 1 addition & 1 deletion gcore/overview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4958,7 +4958,7 @@ CPLErr GDALRegenerateOverviewsEx(GDALRasterBandH hSrcBand, int nOverviewCount,
poJob->nSrcHeight = nHeight;
poJob->args.nChunkXOff = 0;
poJob->args.nChunkXSize = nWidth;
poJob->args.nChunkYOff = nChunkYOff;
poJob->args.nChunkYOff = nChunkYOffQueried;
poJob->args.nChunkYSize = nChunkYSizeQueried;
poJob->nDstWidth = nDstWidth;
poJob->args.nDstXOff = 0;
Expand Down

0 comments on commit 8eb0778

Please sign in to comment.