Skip to content

Commit

Permalink
Merge pull request #8823 from OSGeo/backport-8819-to-release/3.8
Browse files Browse the repository at this point in the history
[Backport release/3.8] GDALOverviewDataset::IRasterIO(): use parent dataset when possible for more efficiency
  • Loading branch information
rouault authored Nov 28, 2023
2 parents 12ed8de + fb414cc commit c98149d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
22 changes: 22 additions & 0 deletions autotest/utilities/test_gdal_translate_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,28 @@ def test_gdal_translate_lib_overview_level(tmp_vsimem):
assert out_ds.RasterYSize == 20


###############################################################################
# Test overviewLevel option in a situation where overview bands have not a
# dedicated owner dataset.
# Test last part of GDALOverviewDataset::IRasterIO() implementation


@pytest.mark.require_driver("JP2KAK")
def test_gdal_translate_lib_overview_level_freestanding(tmp_vsimem):

tmp_filename = tmp_vsimem / "tmp.jp2"

src_ds = gdal.Translate(
tmp_filename,
"../gcore/data/byte.tif",
width=20 * 32,
creationOptions=["QUALITY=100"],
format="JP2KAK",
)
out_ds = gdal.Translate("", src_ds, format="MEM", overviewLevel=0, width=20)
assert out_ds.GetRasterBand(1).Checksum() == 4667


###############################################################################
# Test copying a raster with no input band

Expand Down
10 changes: 9 additions & 1 deletion gcore/gdaloverviewdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ GDALOverviewDataset::GDALOverviewDataset(GDALDataset *poMainDSIn,
nBands = poMainDS->GetRasterCount();
for (int i = 0; i < nBands; ++i)
{
if (poOvrDS)
{
// Check that all overview bands belong to the same dataset
auto poOvrBand =
GetOverviewEx(poMainDS->GetRasterBand(i + 1), nOvrLevel);
if (poOvrBand->GetDataset() != poOvrDS)
poOvrDS = nullptr;
}
SetBand(i + 1, new GDALOverviewBand(this, i + 1));
}

Expand Down Expand Up @@ -328,7 +336,7 @@ CPLErr GDALOverviewDataset::IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff,

// In case the overview bands are really linked to a dataset, then issue
// the request to that dataset.
if (nOvrLevel != -1 && poOvrDS != nullptr)
if (poOvrDS != nullptr)
{
return poOvrDS->RasterIO(eRWFlag, nXOff, nYOff, nXSize, nYSize, pData,
nBufXSize, nBufYSize, eBufType, nBandCount,
Expand Down

0 comments on commit c98149d

Please sign in to comment.