MCPcopy Create free account
hub / github.com/OSGeo/gdal / GDALBandGetBestOverviewLevel2

Function GDALBandGetBestOverviewLevel2

gcore/rasterio.cpp:4647–4740  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4645}
4646
4647int GDALBandGetBestOverviewLevel2(GDALRasterBand *poBand, int &nXOff,
4648 int &nYOff, int &nXSize, int &nYSize,
4649 int nBufXSize, int nBufYSize,
4650 GDALRasterIOExtraArg *psExtraArg)
4651{
4652 if (psExtraArg != nullptr && psExtraArg->nVersion > 1 &&
4653 psExtraArg->bUseOnlyThisScale)
4654 return -1;
4655 /* -------------------------------------------------------------------- */
4656 /* Compute the desired downsampling factor. It is */
4657 /* based on the least reduced axis, and represents the number */
4658 /* of source pixels to one destination pixel. */
4659 /* -------------------------------------------------------------------- */
4660 const double dfDesiredDownsamplingFactor =
4661 ((nXSize / static_cast<double>(nBufXSize)) <
4662 (nYSize / static_cast<double>(nBufYSize)) ||
4663 nBufYSize == 1)
4664 ? nXSize / static_cast<double>(nBufXSize)
4665 : nYSize / static_cast<double>(nBufYSize);
4666
4667 /* -------------------------------------------------------------------- */
4668 /* Find the overview level that largest downsampling factor (most */
4669 /* downsampled) that is still less than (or only a little more) */
4670 /* downsampled than the request. */
4671 /* -------------------------------------------------------------------- */
4672
4673 const char *pszOversampligThreshold =
4674 CPLGetConfigOption("GDAL_OVERVIEW_OVERSAMPLING_THRESHOLD", nullptr);
4675
4676 // Cf https://github.com/OSGeo/gdal/pull/9040#issuecomment-1898524693
4677 const double dfOversamplingThreshold =
4678 pszOversampligThreshold ? CPLAtof(pszOversampligThreshold)
4679 : psExtraArg && psExtraArg->eResampleAlg != GRIORA_NearestNeighbour
4680 ? 1.0
4681 : 1.2;
4682 const int iBestOvrLevel = GDALBandGetBestOverviewLevel(
4683 poBand, dfDesiredDownsamplingFactor, dfOversamplingThreshold);
4684
4685 /* -------------------------------------------------------------------- */
4686 /* If we didn't find an overview that helps us, just return */
4687 /* indicating failure and the full resolution image will be used. */
4688 /* -------------------------------------------------------------------- */
4689 if (iBestOvrLevel < 0)
4690 return -1;
4691 const GDALRasterBand *poBestOverview = poBand->GetOverview(iBestOvrLevel);
4692
4693 /* -------------------------------------------------------------------- */
4694 /* Recompute the source window in terms of the selected */
4695 /* overview. */
4696 /* -------------------------------------------------------------------- */
4697 const double dfXFactor =
4698 poBand->GetXSize() / static_cast<double>(poBestOverview->GetXSize());
4699 const double dfYFactor =
4700 poBand->GetYSize() / static_cast<double>(poBestOverview->GetYSize());
4701 CPLDebug("GDAL", "Selecting overview %d x %d", poBestOverview->GetXSize(),
4702 poBestOverview->GetYSize());
4703
4704 const int nOXOff = std::min(poBestOverview->GetXSize() - 1,

Callers 8

IRasterIOMethod · 0.85
OverviewRasterIOMethod · 0.85
TryOverviewRasterIOMethod · 0.85
IRasterIOMethod · 0.85
IRasterIOMethod · 0.85
AdviseReadMethod · 0.85

Calls 8

CPLAtofFunction · 0.85
CPLDebugFunction · 0.85
minFunction · 0.70
maxFunction · 0.70
GetOverviewMethod · 0.45
GetXSizeMethod · 0.45
GetYSizeMethod · 0.45

Tested by

no test coverage detected