Skip to content

Commit

Permalink
Merge pull request #10246 from rouault/fix_10245
Browse files Browse the repository at this point in the history
Overview generation: fix multi-threaded bug, resulting in locks/crashes with GeoPackage in particular
  • Loading branch information
rouault authored Jun 20, 2024
2 parents 3d6831c + 366606f commit f36edcd
Show file tree
Hide file tree
Showing 3 changed files with 502 additions and 404 deletions.
75 changes: 66 additions & 9 deletions gcore/gdal_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4207,15 +4207,72 @@ CPLErr CPL_DLL GDALRegenerateOverviewsMultiBand(
const char *pszResampling, GDALProgressFunc pfnProgress,
void *pProgressData, CSLConstList papszOptions);

typedef CPLErr (*GDALResampleFunction)(
double dfXRatioDstToSrc, double dfYRatioDstToSrc, double dfSrcXDelta,
double dfSrcYDelta, GDALDataType eWrkDataType, const void *pChunk,
const GByte *pabyChunkNodataMask, int nChunkXOff, int nChunkXSize,
int nChunkYOff, int nChunkYSize, int nDstXOff, int nDstXOff2, int nDstYOff,
int nDstYOff2, GDALRasterBand *poOverview, void **ppDstBuffer,
GDALDataType *peDstBufferDataType, const char *pszResampling,
bool bHasNoData, double dfNoDataValue, GDALColorTable *poColorTable,
GDALDataType eSrcDataType, bool bPropagateNoData);
/************************************************************************/
/* GDALOverviewResampleArgs */
/************************************************************************/

/** Arguments for overview resampling function. */
// Should not contain any dataset/rasterband object, as this might be
// read in a worker thread.
struct GDALOverviewResampleArgs
{
//! Datatype of the source band argument
GDALDataType eSrcDataType = GDT_Unknown;
//! Datatype of the destination/overview band
GDALDataType eOvrDataType = GDT_Unknown;
//! Width in pixel of the destination/overview band
int nOvrXSize = 0;
//! Height in pixel of the destination/overview band
int nOvrYSize = 0;
//! NBITS value of the destination/overview band (or 0 if not set)
int nOvrNBITS = 0;
//! Factor to convert from destination X to source X
// (source width divided by destination width)
double dfXRatioDstToSrc = 0;
//! Factor to convert from destination Y to source Y
// (source height divided by destination height)
double dfYRatioDstToSrc = 0;
//! Sub-pixel delta to add to get source X
double dfSrcXDelta = 0;
//! Sub-pixel delta to add to get source Y
double dfSrcYDelta = 0;
//! Working data type (data type of the pChunk argument)
GDALDataType eWrkDataType = GDT_Unknown;
//! Array of nChunkXSize * nChunkYSize values of mask, or nullptr
const GByte *pabyChunkNodataMask = nullptr;
//! X offset of the source chunk in the source band
int nChunkXOff = 0;
//! Width in pixel of the source chunk in the source band
int nChunkXSize = 0;
//! Y offset of the source chunk in the source band
int nChunkYOff = 0;
//! Height in pixel of the source chunk in the source band
int nChunkYSize = 0;
//! X Offset of the destination chunk in the destination band
int nDstXOff = 0;
//! X Offset of the end (not included) of the destination chunk in the destination band
int nDstXOff2 = 0;
//! Y Offset of the destination chunk in the destination band
int nDstYOff = 0;
//! Y Offset of the end (not included) of the destination chunk in the destination band
int nDstYOff2 = 0;
//! Resampling method
const char *pszResampling = nullptr;
//! Whether the source band has a nodata value
bool bHasNoData = false;
//! Source band nodata value
double dfNoDataValue = 0;
//! Source color table
const GDALColorTable *poColorTable = nullptr;
//! Whether a single contributing source pixel at nodata should result
// in the target pixel to be at nodata too (only taken into account by
// average resampling)
bool bPropagateNoData = false;
};

typedef CPLErr (*GDALResampleFunction)(const GDALOverviewResampleArgs &args,
const void *pChunk, void **ppDstBuffer,
GDALDataType *peDstBufferDataType);

GDALResampleFunction GDALGetResampleFunction(const char *pszResampling,
int *pnRadius);
Expand Down
Loading

0 comments on commit f36edcd

Please sign in to comment.