Skip to content

Commit

Permalink
Add GDT_Int64 and GDT_UInt64 data types and handle them in MEM, GTiff…
Browse files Browse the repository at this point in the history
…, netCDF and Zarr drivers
  • Loading branch information
rouault committed Mar 8, 2022
1 parent d51d00d commit 930b2a0
Show file tree
Hide file tree
Showing 67 changed files with 1,129 additions and 300 deletions.
6 changes: 6 additions & 0 deletions MIGRATION_GUIDE.TXT
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
MIGRATION GUIDE FROM GDAL 3.4 to GDAL 3.5
-----------------------------------------

- GDAL drivers may now return raster bands with the new data types GDT_Int64 or
GDT_UInt64.

MIGRATION GUIDE FROM GDAL 3.3 to GDAL 3.4
-----------------------------------------

Expand Down
6 changes: 4 additions & 2 deletions alg/gdal_alg_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#ifndef DOXYGEN_SKIP

#include <cstdint>

#include "gdal_alg.h"
#include "ogr_spatialref.h"

Expand Down Expand Up @@ -146,10 +148,10 @@ template<class DataType, class EqualityTest> class GDALRasterPolygonEnumeratorT

struct IntEqualityTest
{
bool operator()(GInt32 a, GInt32 b) const { return a == b; }
bool operator()(std::int64_t a, std::int64_t b) const { return a == b; }
};

typedef GDALRasterPolygonEnumeratorT<GInt32, IntEqualityTest> GDALRasterPolygonEnumerator;
typedef GDALRasterPolygonEnumeratorT<std::int64_t, IntEqualityTest> GDALRasterPolygonEnumerator;

typedef void* (*GDALTransformDeserializeFunc)( CPLXMLNode *psTree );

Expand Down
43 changes: 40 additions & 3 deletions alg/gdalpansharpen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ GDALPansharpenOperation::Initialize( const GDALPansharpenOptions* psOptionsIn )
{
if( psOptionsIn->nBitDepth < 0 || psOptionsIn->nBitDepth > 31 ||
(eWorkDataType == GDT_Byte && psOptionsIn->nBitDepth > 8) ||
(eWorkDataType == GDT_UInt16 && psOptionsIn->nBitDepth > 16) ||
(eWorkDataType == GDT_UInt32 && psOptionsIn->nBitDepth > 32) )
(eWorkDataType == GDT_UInt16 && psOptionsIn->nBitDepth > 16) )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Invalid value nBitDepth = %d for type %s",
Expand All @@ -282,7 +281,7 @@ GDALPansharpenOperation::Initialize( const GDALPansharpenOptions* psOptionsIn )
psOptions->nBitDepth = 0;
if( psOptions->nBitDepth &&
!(eWorkDataType == GDT_Byte || eWorkDataType == GDT_UInt16 ||
eWorkDataType == GDT_UInt32) )
eWorkDataType == GDT_UInt32 || eWorkDataType == GDT_UInt64) )
{
CPLError(CE_Warning, CPLE_AppDefined,
"Ignoring nBitDepth = %d for type %s",
Expand Down Expand Up @@ -920,6 +919,18 @@ template<class WorkDataType> CPLErr GDALPansharpenOperation::WeightedBrovey(
nValues, nBandValues, nMaxValue);
break;

case GDT_UInt64:
WeightedBrovey(pPanBuffer, pUpsampledSpectralBuffer,
static_cast<std::uint64_t *>(pDataBuf),
nValues, nBandValues, nMaxValue);
break;

case GDT_Int64:
WeightedBrovey(pPanBuffer, pUpsampledSpectralBuffer,
static_cast<std::int64_t *>(pDataBuf),
nValues, nBandValues, nMaxValue);
break;

case GDT_Float32:
WeightedBrovey(pPanBuffer, pUpsampledSpectralBuffer,
static_cast<float *>(pDataBuf),
Expand Down Expand Up @@ -983,6 +994,18 @@ template<class WorkDataType> CPLErr GDALPansharpenOperation::WeightedBrovey(
static_cast<GInt32 *>(pDataBuf), nValues, nBandValues, 0);
break;

case GDT_UInt64:
WeightedBrovey3<WorkDataType, std::uint64_t, FALSE>(
pPanBuffer, pUpsampledSpectralBuffer,
static_cast<std::uint64_t *>(pDataBuf), nValues, nBandValues, 0);
break;

case GDT_Int64:
WeightedBrovey3<WorkDataType, std::int64_t, FALSE>(
pPanBuffer, pUpsampledSpectralBuffer,
static_cast<std::int64_t *>(pDataBuf), nValues, nBandValues, 0);
break;

case GDT_Float32:
WeightedBrovey3<WorkDataType, float, FALSE>(
pPanBuffer, pUpsampledSpectralBuffer,
Expand Down Expand Up @@ -1699,6 +1722,20 @@ GDALPansharpenOperation::PansharpenChunk( GDALDataType eWorkDataType,
nValues, nBandValues);
break;

case GDT_UInt64:
eErr = WeightedBrovey(static_cast<const std::uint64_t*>(pPanBuffer),
static_cast<const std::uint64_t*>(pUpsampledSpectralBuffer),
pDataBuf, eBufDataType,
nValues, nBandValues, nMaxValue);
break;

case GDT_Int64:
eErr = WeightedBrovey(static_cast<const std::int64_t*>(pPanBuffer),
static_cast<const std::int64_t*>(pUpsampledSpectralBuffer),
pDataBuf, eBufDataType,
nValues, nBandValues);
break;

case GDT_Float32:
eErr = WeightedBrovey(static_cast<const float*>(pPanBuffer),
static_cast<const float*>(pUpsampledSpectralBuffer),
Expand Down
15 changes: 14 additions & 1 deletion alg/gdalrasterize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ void gvBurnScanline( void *pCBData, int nY, int nXStart, int nXEnd,
case GDT_UInt32:
gvBurnScanlineBasic<GUInt32>( psInfo, nY, nXStart, nXEnd, dfVariant );
break;
case GDT_Int64:
gvBurnScanlineBasic<std::int64_t>( psInfo, nY, nXStart, nXEnd, dfVariant );
break;
case GDT_UInt64:
gvBurnScanlineBasic<std::uint64_t>( psInfo, nY, nXStart, nXEnd, dfVariant );
break;
case GDT_Float32:
gvBurnScanlineBasic<float>( psInfo, nY, nXStart, nXEnd, dfVariant );
break;
Expand Down Expand Up @@ -168,7 +174,8 @@ void gvBurnPointBasic( GDALRasterizeInfo *psInfo,
+ nY * psInfo->nLineSpace + nX * psInfo->nPixelSpace;

T* pbyPixel = reinterpret_cast<T*>(pbyInsert);
burnValue += ( psInfo->eMergeAlg != GRMA_Add ) ? 0 : *pbyPixel;
if( psInfo->eMergeAlg == GRMA_Add )
burnValue += static_cast<double>(*pbyPixel);
GDALCopyWord(burnValue, *pbyPixel);
}
}
Expand Down Expand Up @@ -203,6 +210,12 @@ void gvBurnPoint( void *pCBData, int nY, int nX, double dfVariant )
case GDT_UInt32:
gvBurnPointBasic<GUInt32>( psInfo, nY, nX, dfVariant );
break;
case GDT_Int64:
gvBurnPointBasic<std::int64_t>( psInfo, nY, nX, dfVariant );
break;
case GDT_UInt64:
gvBurnPointBasic<std::uint64_t>( psInfo, nY, nX, dfVariant );
break;
case GDT_Float32:
gvBurnPointBasic<float>( psInfo, nY, nX, dfVariant );
break;
Expand Down
2 changes: 1 addition & 1 deletion alg/gdalrasterpolygonenumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void GDALRasterPolygonEnumeratorT<DataType, EqualityTest>::ProcessLine(
}
}

template class GDALRasterPolygonEnumeratorT<GInt32, IntEqualityTest>;
template class GDALRasterPolygonEnumeratorT<std::int64_t, IntEqualityTest>;

template class GDALRasterPolygonEnumeratorT<float, FloatEqualityTest>;

Expand Down
30 changes: 15 additions & 15 deletions alg/gdalsievefilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CPL_CVSID("$Id$")
static CPLErr
GPMaskImageData( GDALRasterBandH hMaskBand, GByte *pabyMaskLine,
int iY, int nXSize,
GInt32 *panImageLine )
std::int64_t *panImageLine )

{
const CPLErr eErr =
Expand Down Expand Up @@ -113,7 +113,7 @@ GPMaskImageData( GDALRasterBandH hMaskBand, GByte *pabyMaskLine,

static inline void CompareNeighbour( int nPolyId1, int nPolyId2,
int *panPolyIdMap,
int * /* panPolyValue */,
std::int64_t * /* panPolyValue */,
std::vector<int> &anPolySizes,
std::vector<int> &anBigNeighbour )

Expand Down Expand Up @@ -215,16 +215,16 @@ GDALSieveFilter( GDALRasterBandH hSrcBand, GDALRasterBandH hMaskBand,
/* -------------------------------------------------------------------- */
int nXSize = GDALGetRasterBandXSize( hSrcBand );
int nYSize = GDALGetRasterBandYSize( hSrcBand );
GInt32 *panLastLineVal = static_cast<GInt32 *>(
auto *panLastLineVal = static_cast<std::int64_t *>(
VSI_MALLOC2_VERBOSE(sizeof(std::int64_t), nXSize));
auto *panThisLineVal = static_cast<std::int64_t *>(
VSI_MALLOC2_VERBOSE(sizeof(std::int64_t), nXSize));
auto *panLastLineId = static_cast<GInt32 *>(
VSI_MALLOC2_VERBOSE(sizeof(GInt32), nXSize));
GInt32 *panThisLineVal = static_cast<GInt32 *>(
VSI_MALLOC2_VERBOSE(sizeof(GInt32), nXSize));
GInt32 *panLastLineId = static_cast<GInt32 *>(
VSI_MALLOC2_VERBOSE(sizeof(GInt32), nXSize));
GInt32 *panThisLineId = static_cast<GInt32 *>(
VSI_MALLOC2_VERBOSE(sizeof(GInt32), nXSize));
GInt32 *panThisLineWriteVal = static_cast<GInt32 *>(
auto *panThisLineId = static_cast<GInt32 *>(
VSI_MALLOC2_VERBOSE(sizeof(GInt32), nXSize));
auto *panThisLineWriteVal = static_cast<std::int64_t *>(
VSI_MALLOC2_VERBOSE(sizeof(std::int64_t), nXSize));
GByte *pabyMaskLine =
hMaskBand != nullptr
? static_cast<GByte *>(VSI_MALLOC_VERBOSE(nXSize))
Expand Down Expand Up @@ -257,7 +257,7 @@ GDALSieveFilter( GDALRasterBandH hSrcBand, GDALRasterBandH hMaskBand,
eErr = GDALRasterIO(
hSrcBand,
GF_Read, 0, iY, nXSize, 1,
panThisLineVal, nXSize, 1, GDT_Int32, 0, 0 );
panThisLineVal, nXSize, 1, GDT_Int64, 0, 0 );

if( eErr == CE_None && hMaskBand != nullptr )
eErr = GPMaskImageData(hMaskBand, pabyMaskLine, iY, nXSize,
Expand Down Expand Up @@ -355,7 +355,7 @@ GDALSieveFilter( GDALRasterBandH hSrcBand, GDALRasterBandH hMaskBand,
/* Read the image data. */
/* -------------------------------------------------------------------- */
eErr = GDALRasterIO( hSrcBand, GF_Read, 0, iY, nXSize, 1,
panThisLineVal, nXSize, 1, GDT_Int32, 0, 0 );
panThisLineVal, nXSize, 1, GDT_Int64, 0, 0 );

if( eErr == CE_None && hMaskBand != nullptr )
eErr = GPMaskImageData( hMaskBand, pabyMaskLine, iY, nXSize,
Expand Down Expand Up @@ -532,9 +532,9 @@ GDALSieveFilter( GDALRasterBandH hSrcBand, GDALRasterBandH hMaskBand,
/* Read the image data. */
/* -------------------------------------------------------------------- */
eErr = GDALRasterIO( hSrcBand, GF_Read, 0, iY, nXSize, 1,
panThisLineVal, nXSize, 1, GDT_Int32, 0, 0 );
panThisLineVal, nXSize, 1, GDT_Int64, 0, 0 );

memcpy( panThisLineWriteVal, panThisLineVal, 4 * nXSize );
memcpy( panThisLineWriteVal, panThisLineVal, sizeof(panThisLineVal[0]) * nXSize );

if( eErr == CE_None && hMaskBand != nullptr )
eErr = GPMaskImageData( hMaskBand, pabyMaskLine, iY, nXSize,
Expand Down Expand Up @@ -580,7 +580,7 @@ GDALSieveFilter( GDALRasterBandH hSrcBand, GDALRasterBandH hMaskBand,
/* Write the update data out. */
/* -------------------------------------------------------------------- */
eErr = GDALRasterIO( hDstBand, GF_Write, 0, iY, nXSize, 1,
panThisLineWriteVal, nXSize, 1, GDT_Int32, 0, 0 );
panThisLineWriteVal, nXSize, 1, GDT_Int64, 0, 0 );

/* -------------------------------------------------------------------- */
/* Swap pixel value, and polygon id lines to be ready for the */
Expand Down
76 changes: 76 additions & 0 deletions alg/gdalwarpkernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,16 @@ static bool GWKSetPixelValue( const GDALWarpKernel *poWK, int iBand,
dfDstImag = 0.0;
break;

case GDT_Int64:
dfDstReal = static_cast<double>(reinterpret_cast<std::int64_t*>(pabyDst)[iDstOffset]);
dfDstImag = 0.0;
break;

case GDT_UInt64:
dfDstReal = static_cast<double>(reinterpret_cast<std::uint64_t*>(pabyDst)[iDstOffset]);
dfDstImag = 0.0;
break;

case GDT_Float32:
dfDstReal = reinterpret_cast<float*>(pabyDst)[iDstOffset];
dfDstImag = 0.0;
Expand Down Expand Up @@ -1690,6 +1700,14 @@ static bool GWKSetPixelValue( const GDALWarpKernel *poWK, int iBand,
CLAMP(GInt32);
break;

case GDT_UInt64:
CLAMP(std::uint64_t);
break;

case GDT_Int64:
CLAMP(std::int64_t);
break;

case GDT_Float32:
reinterpret_cast<float*>(pabyDst)[iDstOffset] = static_cast<float>(dfReal);
break;
Expand Down Expand Up @@ -1810,6 +1828,14 @@ static bool GWKSetPixelValueReal( const GDALWarpKernel *poWK, int iBand,
dfDstReal = reinterpret_cast<GUInt32*>(pabyDst)[iDstOffset];
break;

case GDT_Int64:
dfDstReal = static_cast<double>(reinterpret_cast<std::int64_t*>(pabyDst)[iDstOffset]);
break;

case GDT_UInt64:
dfDstReal = static_cast<double>(reinterpret_cast<std::uint64_t*>(pabyDst)[iDstOffset]);
break;

case GDT_Float32:
dfDstReal = reinterpret_cast<float*>(pabyDst)[iDstOffset];
break;
Expand Down Expand Up @@ -1861,6 +1887,14 @@ static bool GWKSetPixelValueReal( const GDALWarpKernel *poWK, int iBand,
CLAMP(GInt32);
break;

case GDT_UInt64:
CLAMP(std::uint64_t);
break;

case GDT_Int64:
CLAMP(std::int64_t);
break;

case GDT_Float32:
reinterpret_cast<float*>(pabyDst)[iDstOffset] = static_cast<float>(dfReal);
break;
Expand Down Expand Up @@ -1926,6 +1960,16 @@ static bool GWKGetPixelValue( const GDALWarpKernel *poWK, int iBand,
*pdfImag = 0.0;
break;

case GDT_Int64:
*pdfReal = static_cast<double>(reinterpret_cast<std::int64_t*>(pabySrc)[iSrcOffset]);
*pdfImag = 0.0;
break;

case GDT_UInt64:
*pdfReal = static_cast<double>(reinterpret_cast<std::uint64_t*>(pabySrc)[iSrcOffset]);
*pdfImag = 0.0;
break;

case GDT_Float32:
*pdfReal = reinterpret_cast<float*>(pabySrc)[iSrcOffset];
*pdfImag = 0.0;
Expand Down Expand Up @@ -2011,6 +2055,14 @@ static bool GWKGetPixelValueReal( const GDALWarpKernel *poWK, int iBand,
*pdfReal = reinterpret_cast<GUInt32*>(pabySrc)[iSrcOffset];
break;

case GDT_Int64:
*pdfReal = static_cast<double>(reinterpret_cast<std::int64_t*>(pabySrc)[iSrcOffset]);
break;

case GDT_UInt64:
*pdfReal = static_cast<double>(reinterpret_cast<std::uint64_t*>(pabySrc)[iSrcOffset]);
break;

case GDT_Float32:
*pdfReal = reinterpret_cast<float*>(pabySrc)[iSrcOffset];
break;
Expand Down Expand Up @@ -2172,6 +2224,30 @@ static bool GWKGetPixelRow( const GDALWarpKernel *poWK, int iBand,
break;
}

case GDT_Int64:
{
auto pSrc = reinterpret_cast<std::int64_t*>(poWK->papabySrcImage[iBand]);
pSrc += iSrcOffset;
for( int i = 0; i < nSrcLen; i += 2 )
{
adfReal[i] = static_cast<double>(pSrc[i]);
adfReal[i+1] = static_cast<double>(pSrc[i+1]);
}
break;
}

case GDT_UInt64:
{
auto pSrc = reinterpret_cast<std::uint64_t*>(poWK->papabySrcImage[iBand]);
pSrc += iSrcOffset;
for( int i = 0; i < nSrcLen; i += 2 )
{
adfReal[i] = static_cast<double>(pSrc[i]);
adfReal[i+1] = static_cast<double>(pSrc[i+1]);
}
break;
}

case GDT_Float32:
{
float* pSrc = reinterpret_cast<float*>(poWK->papabySrcImage[iBand]);
Expand Down
Loading

0 comments on commit 930b2a0

Please sign in to comment.