Skip to content

Commit

Permalink
GDALDataset::[I]BuildOverviews(): add a CSLConstList papszOptions par…
Browse files Browse the repository at this point in the history
…ameter

- Add corresponding GDALBuildOverviewsEx() and GDALRegenerateOverviewsEx()
- For GDALDataset::BuildOverviews() and GDALBuildOverviewsEx(), the
  passed options are translated as thread-local tempororary
  configuration options, because all exisisting code expects options to
  be provided that way.
- Add CSLConstList papszOptions parameter to GDALRegenerateOverviewsMultiBand()
  • Loading branch information
rouault committed Oct 5, 2022
1 parent b4e009e commit 8f1ca28
Show file tree
Hide file tree
Showing 54 changed files with 432 additions and 231 deletions.
2 changes: 2 additions & 0 deletions MIGRATION_GUIDE.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ MIGRATION GUIDE FROM GDAL 3.5 to GDAL 3.6
- Out-of-tree vector drivers:
* GDALDataset::IBuildOverviews(): parameters panOverviewList and panBandList
are now of type 'const int*' (previously 'int*')
Added a CSLConstList papszOptions member.
* GDALRasterBand::BuildOverviews(): parameter panOverviewList is now of
type 'const int*' (previously 'int*')
Added a CSLConstList papszOptions member.

MIGRATION GUIDE FROM GDAL 3.4 to GDAL 3.5
-----------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions apps/gdalbuildvrt_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1309,11 +1309,12 @@ void VRTBuilder::CreateVRTNonSeparate(VRTDatasetH hVRTDS)
anOverviewFactors.insert(anOverviewFactors.end(),
anOverviewFactorsSet.begin(),
anOverviewFactorsSet.end());
CPLConfigOptionSetter oSetter("VRT_VIRTUAL_OVERVIEWS", "YES", false);
const char* const apszOptions [] = { "VRT_VIRTUAL_OVERVIEWS=YES", nullptr };
poVRTDS->BuildOverviews(pszResampling ? pszResampling : "nearest",
static_cast<int>(anOverviewFactors.size()),
&anOverviewFactors[0],
0, nullptr, nullptr, nullptr);
0, nullptr, nullptr, nullptr,
apszOptions );
}
}

Expand Down
4 changes: 2 additions & 2 deletions frmts/dimap/dimapdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ int DIMAPDataset::ReadImageInformation2()
iLvl*=2;
ovrLevels[i]=iLvl;
}
poVRTDS->IBuildOverviews("average",nSrcOverviews,ovrLevels.get(),0,nullptr,nullptr,nullptr);
poVRTDS->IBuildOverviews("average",nSrcOverviews,ovrLevels.get(),0,nullptr,nullptr,nullptr, nullptr);
}

#ifdef DEBUG_VERBOSE
Expand Down Expand Up @@ -1727,7 +1727,7 @@ void DIMAPDataset::SetMetadataFromXML(
}
continue;
}

// Logic to support a parent element with many name/values.
CPLXMLNode *psTarget = psParent->psChild;
for( ; psTarget != nullptr && psTarget != psParent;
Expand Down
11 changes: 4 additions & 7 deletions frmts/exr/exrdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,8 +1289,8 @@ GDALDataset *GDALEXRDataset::CreateCopy( const char* pszFilename,
std::vector<int> anBands;
for( int iBand = 0; iBand < nBands; iBand++ )
anBands.push_back(iBand+1);
CPLSetThreadLocalConfigOption("GDAL_TIFF_OVR_BLOCKSIZE",
CPLSPrintf("%d", nBlockXSize));
CPLConfigOptionSetter oSetter("GDAL_TIFF_OVR_BLOCKSIZE",
CPLSPrintf("%d", nBlockXSize), false);
const CPLString osTmpOvrFileRadix(CPLSPrintf("%s_tmp",pszFilename));
osTmpOvrFile = osTmpOvrFileRadix + ".ovr";
progress.reset(GDALCreateScaledProgress(0.5, 0.8, pfnProgress, pProgressData));
Expand All @@ -1300,15 +1300,12 @@ GDALDataset *GDALEXRDataset::CreateCopy( const char* pszFilename,
static_cast<int>(anOvrFactors.size()),
&anOvrFactors[0],
nBands, &anBands[0],
GDALScaledProgress, progress.get()) != CE_None )
GDALScaledProgress, progress.get(),
nullptr) != CE_None )
{
CPLSetThreadLocalConfigOption("GDAL_TIFF_OVR_BLOCKSIZE",
nullptr);
VSIUnlink(osTmpOvrFile);
return nullptr;
}
CPLSetThreadLocalConfigOption("GDAL_TIFF_OVR_BLOCKSIZE",
nullptr);

// Transfer overviews from temporary file to main image
std::unique_ptr<GDALDataset> poOvrDS(GDALDataset::Open(osTmpOvrFile));
Expand Down
8 changes: 5 additions & 3 deletions frmts/georaster/georaster_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2686,7 +2686,8 @@ CPLErr GeoRasterDataset::IBuildOverviews( const char* pszResampling,
int nListBands,
const int* panBandList,
GDALProgressFunc pfnProgress,
void* pProgressData )
void* pProgressData,
CSLConstList papszOptions )
{
(void) panBandList;
(void) nListBands;
Expand Down Expand Up @@ -2870,13 +2871,14 @@ CPLErr GeoRasterDataset::IBuildOverviews( const char* pszResampling,
i / (double) nBands, ( i + 1) / (double) nBands,
pfnProgress, pProgressData );

eErr = GDALRegenerateOverviews(
eErr = GDALRegenerateOverviewsEx(
(GDALRasterBandH) poBand,
poBand->nOverviewCount,
(GDALRasterBandH*) poBand->papoOverviews,
pszResampling,
GDALScaledProgress,
pScaledProgressData );
pScaledProgressData,
papszOptions);

GDALDestroyScaledProgress( pScaledProgressData );
}
Expand Down
3 changes: 2 additions & 1 deletion frmts/georaster/georaster_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ class GeoRasterDataset final: public GDALDataset
int nListBandsover,
const int* panBandList,
GDALProgressFunc pfnProgress,
void* pProgresoversData ) override;
void* pProgresoversData,
CSLConstList papszOptions) override;
CPLErr CreateMaskBand( int nFlags ) override;
// cppcheck-suppress functionStatic
OGRErr StartTransaction(int /* bForce */ =FALSE) override
Expand Down
22 changes: 13 additions & 9 deletions frmts/gtiff/geotiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,8 @@ class GTiffDataset final : public GDALPamDataset
virtual CPLErr IBuildOverviews( const char *,
int, const int *,
int, const int *,
GDALProgressFunc, void * ) override;
GDALProgressFunc, void *,
CSLConstList papszOptions ) override;

CPLErr OpenOffset( TIFF *,
toff_t nDirOffset, GDALAccess,
Expand Down Expand Up @@ -12720,7 +12721,8 @@ CPLErr GTiffDataset::IBuildOverviews(
const char * pszResampling,
int nOverviews, const int * panOverviewList,
int nBandsIn, const int * panBandList,
GDALProgressFunc pfnProgress, void * pProgressData )
GDALProgressFunc pfnProgress, void * pProgressData,
CSLConstList papszOptions)

{
ScanDirectories();
Expand Down Expand Up @@ -12775,7 +12777,7 @@ CPLErr GTiffDataset::IBuildOverviews(

CPLErr eErr = GDALDataset::IBuildOverviews(
pszResampling, nOverviews, panOverviewList,
nBandsIn, panBandList, pfnProgress, pProgressData );
nBandsIn, panBandList, pfnProgress, pProgressData, papszOptions );
if( eErr == CE_None && m_poMaskDS )
{
ReportError(CE_Warning, CPLE_NotSupported,
Expand Down Expand Up @@ -12809,7 +12811,8 @@ CPLErr GTiffDataset::IBuildOverviews(
if( m_nOverviewCount == 0 )
return GDALDataset::IBuildOverviews(
pszResampling, nOverviews, panOverviewList,
nBandsIn, panBandList, pfnProgress, pProgressData );
nBandsIn, panBandList, pfnProgress, pProgressData,
papszOptions );

return CleanOverviews();
}
Expand Down Expand Up @@ -12995,11 +12998,11 @@ CPLErr GTiffDataset::IBuildOverviews(
}
}

eErr = GDALRegenerateOverviews(
eErr = GDALRegenerateOverviewsEx(
m_poMaskDS->GetRasterBand(1),
nMaskOverviews,
reinterpret_cast<GDALRasterBandH *>( papoOverviewBands ),
pszResampling, GDALDummyProgress, nullptr );
pszResampling, GDALDummyProgress, nullptr, papszOptions );
CPLFree(papoOverviewBands);
}

Expand Down Expand Up @@ -13095,7 +13098,7 @@ CPLErr GTiffDataset::IBuildOverviews(
GDALRegenerateOverviewsMultiBand( nBandsIn, papoBandList,
nNewOverviews, papapoOverviewBands,
pszResampling, pfnProgress,
pProgressData );
pProgressData, papszOptions );

for( int iBand = 0; iBand < nBandsIn; ++iBand )
{
Expand Down Expand Up @@ -13159,13 +13162,14 @@ CPLErr GTiffDataset::IBuildOverviews(
(iBand + 1) / static_cast<double>( nBandsIn ),
pfnProgress, pProgressData );

eErr = GDALRegenerateOverviews(
eErr = GDALRegenerateOverviewsEx(
poBand,
nNewOverviews,
reinterpret_cast<GDALRasterBandH *>( papoOverviewBands ),
pszResampling,
GDALScaledProgress,
pScaledProgressData );
pScaledProgressData,
papszOptions );

GDALDestroyScaledProgress( pScaledProgressData );
}
Expand Down
Loading

0 comments on commit 8f1ca28

Please sign in to comment.