Skip to content
Commits on Source (15)
......@@ -415,7 +415,8 @@ RECURSIVE = NO
# excluded from the INPUT source files. This way you can easily exclude a
# subdirectory from a directory tree whose root is specified with the INPUT tag.
EXCLUDE =
EXCLUDE = gcore/rawdataset.cpp \
gcore/rawdataset.h
# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
# directories that are symbolic links (a Unix filesystem feature) are excluded
......
......@@ -37,7 +37,7 @@ LIBS = $(SDE_LIB) @LIBS@ $(KAK_LIBS) $(DWG_LIBS) $(CURL_LIB) \
$(MRSID_LIBS) $(MRSID_LIDAR_LIBS) $(ECW_LIBS) $(INGRES_LIB) \
$(PCIDSK_LIB) $(RASDAMAN_LIB) $(SOSI_LIB) \
$(OPENCL_LIB) $(JVM_LIB) $(LIBICONV) $(FGDB_LIB) $(LIBXML2_LIB) $(MONGODB_LIB) \
$(JNI_LIB) $(HDFS_LIB)
$(MONGOCXXV3_LIBS) $(JNI_LIB) $(HDFS_LIB)
SSEFLAGS = @SSEFLAGS@
SSSE3FLAGS = @SSSE3FLAGS@
......@@ -122,9 +122,9 @@ GDAL_INCLUDE = -I$(GDAL_ROOT)/port -I$(GDAL_ROOT)/gcore \
# libtool targets and help variables
LIBGDAL := libgdal.la
LIBGDAL_CURRENT := 25
LIBGDAL_REVISION := 1
LIBGDAL_AGE := 5
LIBGDAL_CURRENT := 26
LIBGDAL_REVISION := 0
LIBGDAL_AGE := 0
# native build targets and variables
GDAL_VER = @GDAL_VER@
......@@ -340,6 +340,13 @@ HAVE_MONGODB = @MONGODB_ENABLED@
MONGODB_LIB = @MONGODB_LIB@
MONGODB_INC = @MONGODB_INC@
#
# MongoCXX v3
#
HAVE_MONGOCXXV3 = @MONGOCXXV3_ENABLED@
MONGOCXXV3_LIBS = @MONGOCXXV3_LIBS@
MONGOCXXV3_CFLAGS = @MONGOCXXV3_CFLAGS@
#
# ArcObjects
#
......@@ -393,11 +400,6 @@ HAVE_LIBXML2 = @HAVE_LIBXML2@
LIBXML2_INC = @LIBXML2_INC@
LIBXML2_LIB = @LIBXML2_LIB@
#
# CAD Support
#
HAVE_CAD = yes
#
# Informix DataBlade support
#
......@@ -453,6 +455,7 @@ LIBZ_SETTING = @LIBZ_SETTING@
LIBLZMA_SETTING = @LIBLZMA_SETTING@
WEBP_SETTING = @WEBP_SETTING@
ZSTD_SETTING = @ZSTD_SETTING@
TILEDB_SETTING = @TILEDB_SETTING@
#
# DDS via Crunch Support.
......@@ -511,12 +514,8 @@ TEIGHA_DIR = @TEIGHA_DIR@
TEIGHA_CPPFLAGS = @TEIGHA_CPPFLAGS@
#
# PROJ.4 stuff
# PROJ stuff
#
PROJ_STATIC = @PROJ_STATIC@
ifeq ($(PROJ_STATIC),yes)
PROJ_FLAGS = -DPROJ_STATIC -DPROJ_VERSION=@PROJ_VERSION@
endif
PROJ_INCLUDE = @PROJ_INCLUDE@
PAM_SETTING = @PAM_SETTING@
......@@ -574,32 +573,14 @@ HAVE_OPENSSL_CRYPTO = @HAVE_OPENSSL_CRYPTO@
# and their uppercase form should be the format portion of the
# format registration entry point. eg. gdb -> GDALRegister_GTiff().
#
GDAL_FORMATS :=
GDAL_FORMATS += gxf gtiff hfa aigrid aaigrid ceos ceos2 iso8211 xpm
GDAL_FORMATS += sdts raw dted mem jdem envisat elas fit vrt usgsdem l1b
GDAL_FORMATS += nitf bmp airsar rs2 ilwis rmf leveller sgi srtmhgt
GDAL_FORMATS += idrisi gsg ingr ers jaxapalsar dimap gff cosar pds adrg
GDAL_FORMATS += coasp tsx terragen blx msgn til r northwood saga xyz hf2
GDAL_FORMATS += kmlsuperoverlay ctg e00grid zmap ngsgeoid iris map cals
GDAL_FORMATS += safe sentinel2 derived
GDAL_FORMATS += prf
GDAL_FORMATS += sigdem
GDAL_FORMATS += ignfheightasciigrid
GDAL_FORMATS += @OPT_GDAL_FORMATS@
GDAL_FORMATS := derived gtiff hfa mem vrt @GDALFORMATS_ENABLED@ @OPT_GDAL_FORMATS@
OGR_FORMATS := @OGRFORMATS_ENABLED@
OGR_FORMATS_ENABLED_CFLAGS := @OGRFORMATS_ENABLED_CFLAGS@
ifneq ($(PCIDSK_SETTING),no)
GDAL_FORMATS += pcidsk
endif
ifneq ($(LIBZ_SETTING),no)
GDAL_FORMATS := $(GDAL_FORMATS) rik ozi
ifneq ($(PDF_PLUGIN),yes)
GDAL_FORMATS := $(GDAL_FORMATS) pdf
endif
endif
ifeq ($(HAVE_SQLITE),yes)
GDAL_FORMATS := $(GDAL_FORMATS) rasterlite mbtiles
endif
......@@ -612,7 +593,6 @@ ifeq ($(HAVE_CHARLS),yes)
GDAL_FORMATS := $(GDAL_FORMATS) jpegls
endif
GDAL_FORMATS := $(GDAL_FORMATS) arg
#
# CONFIG_LIBS is what local program should link against, and CONFIG_LIBS_INS
......
MIGRATION GUIDE FROM GDAL 2.4 to GDAL 2.5
-----------------------------------------
- Unix Build: ./configure arguments --without-bsb, --without-grib,
and --without-mrf have been renamed to --disable-driver-bsb,
--disable-driver-grib and --disable-driver-mrf
- Substantial changes, sometimes backward incompatible, in coordinate reference
system and coordinate transformations have been introduced per
https://trac.osgeo.org/gdal/wiki/rfc73_proj6_wkt2_srsbarn
* OSRImportFromEPSG() takes into account official axis order.
Traditional GIS-friendly axis order can be restored with
OGRSpatialReference::SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
* Same for SetWellKnownGeogCS("WGS84") / SetFromUserInput("WGS84")
* removal of OPTGetProjectionMethods(), OPTGetParameterList() and OPTGetParameterInfo()
No equivalent.
* removal of OSRFixup() and OSRFixupOrdering(): no longer needed since objects
constructed are always valid
* removal of OSRStripCTParms(). Use OSRExportToWktEx() instead with the
FORMAT=SQSQL option
* exportToWkt() outputs AXIS nodes
* OSRIsSame(): now takes into account data axis to CRS axis mapping, unless
IGNORE_DATA_AXIS_TO_SRS_AXIS_MAPPING=YES is set as an option to OSRIsSameEx()
* ogr_srs_api.h: SRS_WKT_WGS84 macro is no longer declared by default since
WKT without AXIS is too ambiguous. Preferred remediation: use SRS_WKT_WGS84_LAT_LONG.
Or #define USE_DEPRECATED_SRS_WKT_WGS84 before including ogr_srs_api.h
Out-of-tree drivers:
* GDALDataset::GetProjectionRef() made non-virtual.
Replaced by GetSpatialRef() virtual method.
Compatibility emulation possible by defining:
const char* _GetProjectionRef() override; // note leading underscore
const OGRSpatialReference* GetSpatialRef() const override {
return GetSpatialRefFromOldGetProjectionRef();
}
* GDALDataset::SetProjection() made non-virtual.
Replaced by SetSpatialRef() virtual method.
Compatibility emulation possible by defining:
CPLErr SetProjection(const char*) override; // note leading underscore
CPLErr SetSpatialRef(const OGRSpatialReference* poSRS) override {
return OldSetProjectionFromSetSpatialRef(poSRS);
}
* GDALDataset::GetGCPProjection() made non-virtual.
Replaced by GetGCPSpatialRef() virtual method.
Compatibility emulation possible by defining:
const char* _GetGCPProjectionRef() override; // note leading underscore
const OGRSpatialReference* GetGCPSpatialRef() const override {
return GetGCPSpatialRefFromOldGetGCPProjection();
}
* GDALDataset::SetGCPs(..., const char* pszWKT) made non-virtual.
Replaced by SetGCPs(..., const OGRSpatialReference* poSRS) virtual mode.
CPLErr _SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
const char *pszGCPProjection ) override; // note leading underscore
CPLErr SetGCPs( int nGCPCountIn, const GDAL_GCP *pasGCPListIn,
const OGRSpatialReference* poSRS ) override {
return OldSetGCPsFromNew(nGCPCountIn, pasGCPListIn, poSRS);
}
MIGRATION GUIDE FROM GDAL 2.3 to GDAL 2.4
-----------------------------------------
......
This diff is collapsed.
......@@ -122,8 +122,6 @@ Note: all the following are build options, not required.
* Contains various data files without copyright messages embedded.
* cubewerx_extra.wkt: derived from definitions distributed by Cubewerx, rights unclear. See http://trac.osgeo.org/gdal/ticket/2165
* ecw_cs.wkt: Derived via much processing from ERMapper GDT definitions, rights unclear. See http://trac.osgeo.org/gdal/ticket/2162
* esri_extra.wkt + esri_epsg.wkt: Provided by ESRI under Apache v2 license. See http://trac.osgeo.org/gdal/ticket/2163
* ellipsoid.csv, gcs.csv, gdal_datum.csv, pcs.csv, prime_meridian.csv, projop_wparm.csv, unit_of_measure.csv: Derived from EPSG. Modifications to EPSG data violate the EPSG use agreement (if we are to still attribute it to EPSG) so I have segregated changes into override files (i.e. gcs.override.csv).
* seed_2d.dgn, seed_3d.dgn: Exact source of these files is unclear. The files contain no substantial creative content since all but the header elements were stripped. Judged to acceptable use.
* NTS-50kindex.csv: Provided by Matt Wilkie, derived from NRCan dataset, rights unclear. See http://trac.osgeo.org/gdal/ticket/2164 (closed - this file isn't actually in the source tree - it is separately distributed as part of FWTools!)
......
......@@ -501,17 +501,17 @@ an averaged value from the two nearby points (in this case (12+3+5)/3).
* ELEV_FIELD=d
*
* This will be used as a field index to indicate where the elevation value
* of the contour should be written.
* of the contour should be written. Only used in line contouring mode.
*
* ELEV_FIELD_MIN=d
*
* This will be used as a field index to indicate where the minimum elevation value
* of the polygon contour should be written.
* of the polygon contour should be written. Only used in polygonal contouring mode.
*
* ELEV_FIELD_MAX=d
*
* This will be used as a field index to indicate where the maximum elevation value
* of the polygon contour should be written.
* of the polygon contour should be written. Only used in polygonal contouring mode.
*
* POLYGONIZE=YES|NO
*
......
/******************************************************************************
* $Id: gdal_alg.h b9ddc19f9ccd776cac9388f260aebc24439f10aa 2018-10-09 11:45:33 +0200 Julien Cabieces $
* $Id: gdal_alg.h 8e5eeb35bf76390e3134a4ea7076dab7d478ea0e 2018-11-14 22:55:13 +0100 Even Rouault $
*
* Project: GDAL Image Processing Algorithms
* Purpose: Prototypes, and definitions for various GDAL based algorithms.
......@@ -154,6 +154,14 @@ GDALCreateGenImgProjTransformer3( const char *pszSrcWKT,
const double *padfSrcGeoTransform,
const char *pszDstWKT,
const double *padfDstGeoTransform );
void CPL_DLL *
GDALCreateGenImgProjTransformer4( OGRSpatialReferenceH hSrcSRS,
const double *padfSrcGeoTransform,
OGRSpatialReferenceH hDstSRS,
const double *padfDstGeoTransform,
const char* const *papszOptions );
void CPL_DLL GDALSetGenImgProjTransformerDstGeoTransform( void *,
const double * );
void CPL_DLL GDALDestroyGenImgProjTransformer( void * );
......@@ -168,6 +176,11 @@ void GDALGetTransformerDstGeoTransform( void*, double* );
void CPL_DLL *
GDALCreateReprojectionTransformer( const char *pszSrcWKT,
const char *pszDstWKT );
void CPL_DLL *
GDALCreateReprojectionTransformerEx(
OGRSpatialReferenceH hSrcSRS,
OGRSpatialReferenceH hDstSRS,
const char* const *papszOptions);
void CPL_DLL GDALDestroyReprojectionTransformer( void * );
int CPL_DLL GDALReprojectionTransform(
void *pTransformArg, int bDstToSrc, int nPointCount,
......
/******************************************************************************
* $Id: gdal_alg_priv.h fe2d81c8819bf9794bce0210098e637565728350 2018-05-06 00:49:51 +0200 Even Rouault $
* $Id: gdal_alg_priv.h e40d0a17ddb8ca683d53dd68777a74094f8f1bde 2019-03-12 13:31:28 +0100 Even Rouault $
*
* Project: GDAL Image Processing Algorithms
* Purpose: Prototypes and definitions for various GDAL based algorithms:
......@@ -35,6 +35,7 @@
#ifndef DOXYGEN_SKIP
#include "gdal_alg.h"
#include "ogr_spatialref.h"
CPL_C_START
......@@ -56,6 +57,9 @@ typedef struct {
int nYSize;
int nBands;
GDALDataType eType;
int nPixelSpace;
GSpacing nLineSpace;
GSpacing nBandSpace;
double *padfBurnValue;
GDALBurnValueSrc eBurnValueSource;
GDALRasterMergeAlg eMergeAlg;
......@@ -89,7 +93,8 @@ void GDALdllImageLineAllTouched( int nRasterXSize, int nRasterYSize,
int nPartCount, int *panPartSize,
double *padfX, double *padfY,
double *padfVariant,
llPointFunc pfnPointFunc, void *pCBData );
llPointFunc pfnPointFunc, void *pCBData,
int bAvoidBurningSamePoints );
void GDALdllImageFilledPolygon( int nRasterXSize, int nRasterYSize,
int nPartCount, int *panPartSize,
......@@ -217,6 +222,26 @@ struct FloatEqualityTest
bool operator()(float a, float b) { return GDALFloatEquals(a,b) == TRUE; }
};
bool GDALComputeAreaOfInterest(OGRSpatialReference* poSRS,
double adfGT[6],
int nXSize,
int nYSize,
double& dfWestLongitudeDeg,
double& dfSouthLatitudeDeg,
double& dfEastLongitudeDeg,
double& dfNorthLatitudeDeg );
bool GDALComputeAreaOfInterest(OGRSpatialReference* poSRS,
double dfX1,
double dfY1,
double dfX2,
double dfY2,
double& dfWestLongitudeDeg,
double& dfSouthLatitudeDeg,
double& dfEastLongitudeDeg,
double& dfNorthLatitudeDeg );
#endif /* #ifndef DOXYGEN_SKIP */
#endif /* ndef GDAL_ALG_PRIV_H_INCLUDED */
......@@ -52,6 +52,7 @@
****************************************************************************/
#include "gdal_alg.h"
#include "gdal_priv.h"
#include "cpl_conv.h"
#include "cpl_minixml.h"
#include "cpl_string.h"
......@@ -61,24 +62,11 @@
#include <stdlib.h>
#include <string.h>
CPL_CVSID("$Id: gdal_crs.c ee3197beea00209aedcf77e928b1e0c828251bd7 2018-10-01 23:39:49 +0200 Even Rouault $")
/* Hum, we cannot include gdal_priv.h from a .c file... */
CPL_C_START
void GDALSerializeGCPListToXML( CPLXMLNode* psParentNode,
GDAL_GCP* pasGCPList,
int nGCPCount,
const char* pszGCPProjection );
void GDALDeserializeGCPListFromXML( CPLXMLNode* psGCPList,
GDAL_GCP** ppasGCPList,
int* pnGCPCount,
char** ppszGCPProjection );
CPL_C_END
CPL_CVSID("$Id: gdal_crs.cpp 8e5eeb35bf76390e3134a4ea7076dab7d478ea0e 2018-11-14 22:55:13 +0100 Even Rouault $")
#define MAXORDER 3
namespace {
struct Control_Points
{
int count;
......@@ -88,6 +76,7 @@ struct Control_Points
double *n2;
int *status;
};
}
typedef struct
{
......@@ -151,10 +140,10 @@ static
void* GDALCreateSimilarGCPTransformer( void *hTransformArg, double dfRatioX, double dfRatioY )
{
int i = 0;
GDAL_GCP *pasGCPList = NULL;
GCPTransformInfo *psInfo = (GCPTransformInfo *) hTransformArg;
GDAL_GCP *pasGCPList = nullptr;
GCPTransformInfo *psInfo = static_cast<GCPTransformInfo *>(hTransformArg);
VALIDATE_POINTER1( hTransformArg, "GDALCreateSimilarGCPTransformer", NULL );
VALIDATE_POINTER1( hTransformArg, "GDALCreateSimilarGCPTransformer", nullptr );
if( dfRatioX == 1.0 && dfRatioY == 1.0 )
{
......@@ -171,8 +160,8 @@ void* GDALCreateSimilarGCPTransformer( void *hTransformArg, double dfRatioX, dou
pasGCPList[i].dfGCPLine /= dfRatioY;
}
/* As remove_outliers modifies the provided GCPs we don't need to reapply it */
psInfo = (GCPTransformInfo *) GDALCreateGCPTransformer(
psInfo->nGCPCount, pasGCPList, psInfo->nOrder, psInfo->bReversed );
psInfo = static_cast<GCPTransformInfo *>(GDALCreateGCPTransformer(
psInfo->nGCPCount, pasGCPList, psInfo->nOrder, psInfo->bReversed ));
GDALDeinitGCPs( psInfo->nGCPCount, pasGCPList );
CPLFree( pasGCPList );
}
......@@ -189,12 +178,12 @@ void *GDALCreateGCPTransformerEx( int nGCPCount, const GDAL_GCP *pasGCPList,
int nReqOrder, int bReversed, int bRefine, double dfTolerance, int nMinimumGcps)
{
GCPTransformInfo *psInfo = NULL;
double *padfGeoX = NULL;
double *padfGeoY = NULL;
double *padfRasterX = NULL;
double *padfRasterY = NULL;
int *panStatus = NULL;
GCPTransformInfo *psInfo = nullptr;
double *padfGeoX = nullptr;
double *padfGeoY = nullptr;
double *padfRasterX = nullptr;
double *padfRasterY = nullptr;
int *panStatus = nullptr;
int iGCP = 0;
int nCRSresult = 0;
struct Control_Points sPoints;
......@@ -216,7 +205,7 @@ void *GDALCreateGCPTransformerEx( int nGCPCount, const GDAL_GCP *pasGCPList,
nReqOrder = 1;
}
psInfo = (GCPTransformInfo *) CPLCalloc(sizeof(GCPTransformInfo),1);
psInfo = static_cast<GCPTransformInfo *>(CPLCalloc(sizeof(GCPTransformInfo),1));
psInfo->bReversed = bReversed;
psInfo->nOrder = nReqOrder;
psInfo->bRefine = bRefine;
......@@ -252,11 +241,13 @@ void *GDALCreateGCPTransformerEx( int nGCPCount, const GDAL_GCP *pasGCPList,
/* -------------------------------------------------------------------- */
/* Allocate and initialize the working points list. */
/* -------------------------------------------------------------------- */
padfGeoX = (double *) CPLCalloc(sizeof(double),nGCPCount);
padfGeoY = (double *) CPLCalloc(sizeof(double),nGCPCount);
padfRasterX = (double *) CPLCalloc(sizeof(double),nGCPCount);
padfRasterY = (double *) CPLCalloc(sizeof(double),nGCPCount);
panStatus = (int *) CPLCalloc(sizeof(int),nGCPCount);
try
{
padfGeoX = new double[nGCPCount];
padfGeoY = new double[nGCPCount];
padfRasterX = new double[nGCPCount];
padfRasterY = new double[nGCPCount];
panStatus = new int[nGCPCount];
for( iGCP = 0; iGCP < nGCPCount; iGCP++ )
{
panStatus[iGCP] = 1;
......@@ -284,18 +275,24 @@ void *GDALCreateGCPTransformerEx( int nGCPCount, const GDAL_GCP *pasGCPList,
psInfo->adfToGeoX, psInfo->adfToGeoY,
psInfo->adfFromGeoX, psInfo->adfFromGeoY,
nReqOrder );
CPLFree( padfGeoX );
CPLFree( padfGeoY );
CPLFree( padfRasterX );
CPLFree( padfRasterY );
CPLFree( panStatus );
}
catch( const std::exception& e )
{
CPLError(CE_Failure, CPLE_OutOfMemory, "%s", e.what());
nCRSresult = MINTERR;
}
delete[] padfGeoX;
delete[] padfGeoY;
delete[] padfRasterX;
delete[] padfRasterY;
delete[] panStatus;
}
if (nCRSresult != 1)
{
CPLError( CE_Failure, CPLE_AppDefined, "%s", CRS_error_message[-nCRSresult]);
GDALDestroyGCPTransformer( psInfo );
return NULL;
return nullptr;
}
else
{
......@@ -315,7 +312,7 @@ void *GDALCreateGCPTransformerEx( int nGCPCount, const GDAL_GCP *pasGCPList,
* GDALTransformerFunc signature. The returned transform argument should
* be deallocated with GDALDestroyGCPTransformer when no longer needed.
*
* This function may fail (returning NULL) if the provided set of GCPs
* This function may fail (returning nullptr) if the provided set of GCPs
* are inadequate for the requested order, the determinate is zero or they
* are otherwise "ill conditioned".
*
......@@ -329,7 +326,7 @@ void *GDALCreateGCPTransformerEx( int nGCPCount, const GDAL_GCP *pasGCPList,
* Using 3 is not recommended due to potential numeric instabilities issues.
* @param bReversed set it to TRUE to compute the reversed transformation.
*
* @return the transform argument or NULL if creation fails.
* @return the transform argument or nullptr if creation fails.
*/
void *GDALCreateGCPTransformer( int nGCPCount, const GDAL_GCP *pasGCPList,
int nReqOrder, int bReversed )
......@@ -371,12 +368,10 @@ void *GDALCreateGCPRefineTransformer( int nGCPCount, const GDAL_GCP *pasGCPList,
void GDALDestroyGCPTransformer( void *pTransformArg )
{
GCPTransformInfo *psInfo = NULL;
if( pTransformArg == NULL )
if( pTransformArg == nullptr )
return;
psInfo = (GCPTransformInfo *) pTransformArg;
GCPTransformInfo *psInfo = static_cast<GCPTransformInfo *>(pTransformArg);
if( CPLAtomicDec(&(psInfo->nRefCount)) == 0 )
{
......@@ -419,7 +414,7 @@ int GDALGCPTransform( void *pTransformArg, int bDstToSrc,
{
int i = 0;
GCPTransformInfo *psInfo = (GCPTransformInfo *) pTransformArg;
GCPTransformInfo *psInfo = static_cast<GCPTransformInfo *>(pTransformArg);
if( psInfo->bReversed )
bDstToSrc = !bDstToSrc;
......@@ -457,12 +452,12 @@ int GDALGCPTransform( void *pTransformArg, int bDstToSrc,
CPLXMLNode *GDALSerializeGCPTransformer( void *pTransformArg )
{
CPLXMLNode *psTree = NULL;
GCPTransformInfo *psInfo = (GCPTransformInfo *) pTransformArg;
CPLXMLNode *psTree = nullptr;
GCPTransformInfo *psInfo = static_cast<GCPTransformInfo *>(pTransformArg);
VALIDATE_POINTER1( pTransformArg, "GDALSerializeGCPTransformer", NULL );
VALIDATE_POINTER1( pTransformArg, "GDALSerializeGCPTransformer", nullptr );
psTree = CPLCreateXMLNode( NULL, CXT_Element, "GCPTransformer" );
psTree = CPLCreateXMLNode( nullptr, CXT_Element, "GCPTransformer" );
/* -------------------------------------------------------------------- */
/* Serialize Order and bReversed. */
......@@ -503,7 +498,7 @@ CPLXMLNode *GDALSerializeGCPTransformer( void *pTransformArg )
GDALSerializeGCPListToXML( psTree,
psInfo->pasGCPList,
psInfo->nGCPCount,
NULL );
nullptr );
}
return psTree;
......@@ -516,9 +511,9 @@ CPLXMLNode *GDALSerializeGCPTransformer( void *pTransformArg )
void *GDALDeserializeGCPTransformer( CPLXMLNode *psTree )
{
GDAL_GCP *pasGCPList = 0;
GDAL_GCP *pasGCPList = nullptr;
int nGCPCount = 0;
void *pResult = NULL;
void *pResult = nullptr;
int nReqOrder = 0;
int bReversed = 0;
int bRefine = 0;
......@@ -530,12 +525,12 @@ void *GDALDeserializeGCPTransformer( CPLXMLNode *psTree )
/* -------------------------------------------------------------------- */
CPLXMLNode *psGCPList = CPLGetXMLNode( psTree, "GCPList" );
if( psGCPList != NULL )
if( psGCPList != nullptr )
{
GDALDeserializeGCPListFromXML( psGCPList,
&pasGCPList,
&nGCPCount,
NULL );
nullptr );
}
/* -------------------------------------------------------------------- */
......@@ -690,7 +685,7 @@ CRS_compute_georef_equations (GCPTransformInfo *psInfo, struct Control_Points *c
double E21[], double N21[],
int order)
{
double *tempptr = NULL;
double *tempptr = nullptr;
int status = 0;
if(order < 1 || order > MAXORDER)
......@@ -737,8 +732,8 @@ static int
calccoef (struct Control_Points *cp, double x_mean, double y_mean, double E[], double N[], int order)
{
struct MATRIX m;
double *a = NULL;
double *b = NULL;
double *a = nullptr;
double *b = nullptr;
int numactive = 0; /* NUMBER OF ACTIVE CONTROL POINTS */
int status = 0;
int i = 0;
......@@ -763,22 +758,22 @@ calccoef (struct Control_Points *cp, double x_mean, double y_mean, double E[], d
/* INITIALIZE MATRIX */
m.v = (double *)CPLCalloc(m.n*m.n,sizeof(double));
if(m.v == NULL)
m.v = static_cast<double*>(VSICalloc(m.n*m.n,sizeof(double)));
if(m.v == nullptr)
{
return(MMEMERR);
}
a = (double *)CPLCalloc(m.n,sizeof(double));
if(a == NULL)
a = static_cast<double*>(VSICalloc(m.n,sizeof(double)));
if(a == nullptr)
{
CPLFree((char *)m.v);
CPLFree(m.v);
return(MMEMERR);
}
b = (double *)CPLCalloc(m.n,sizeof(double));
if(b == NULL)
b = static_cast<double*>(VSICalloc(m.n,sizeof(double)));
if(b == nullptr)
{
CPLFree((char *)m.v);
CPLFree((char *)a);
CPLFree(m.v);
CPLFree(a);
return(MMEMERR);
}
......@@ -787,9 +782,9 @@ calccoef (struct Control_Points *cp, double x_mean, double y_mean, double E[], d
else
status = calcls(cp,&m, x_mean, y_mean,a,b,E,N);
CPLFree((char *)m.v);
CPLFree((char *)a);
CPLFree((char *)b);
CPLFree(m.v);
CPLFree(a);
CPLFree(b);
return(status);
}
......@@ -920,18 +915,18 @@ static double term (int nTerm, double e, double n)
{
switch(nTerm)
{
case 1: return((double)1.0);
case 2: return((double)e);
case 3: return((double)n);
case 4: return((double)(e*e));
case 5: return((double)(e*n));
case 6: return((double)(n*n));
case 7: return((double)(e*e*e));
case 8: return((double)(e*e*n));
case 9: return((double)(e*n*n));
case 10: return((double)(n*n*n));
case 1: return(1.0);
case 2: return(e);
case 3: return(n);
case 4: return((e*e));
case 5: return((e*n));
case 6: return((n*n));
case 7: return((e*e*e));
case 8: return((e*e*n));
case 9: return((e*n*n));
case 10: return((n*n*n));
}
return((double)0.0);
return 0.0;
}
/***************************************************************************/
......@@ -1074,7 +1069,7 @@ static int worst_outlier(struct Control_Points *cp, double x_mean, double y_mean
double dfCurrentDifference = 0.0;
double dfSampleResidual = 0.0;
double dfLineResidual = 0.0;
double *padfResiduals = (double *) CPLCalloc(sizeof(double),cp->count);
double *padfResiduals = static_cast<double*>(CPLCalloc(sizeof(double),cp->count));
for(nI = 0; nI < cp->count; nI++)
{
......@@ -1122,11 +1117,11 @@ static int worst_outlier(struct Control_Points *cp, double x_mean, double y_mean
/***************************************************************************/
static int remove_outliers( GCPTransformInfo *psInfo )
{
double *padfGeoX = NULL;
double *padfGeoY = NULL;
double *padfRasterX = NULL;
double *padfRasterY = NULL;
int *panStatus = NULL;
double *padfGeoX = nullptr;
double *padfGeoY = nullptr;
double *padfRasterX = nullptr;
double *padfRasterY = nullptr;
int *panStatus = nullptr;
int nI = 0;
int nCRSresult = 0;
int nGCPCount = 0;
......@@ -1146,11 +1141,13 @@ static int remove_outliers( GCPTransformInfo *psInfo )
nReqOrder = psInfo->nOrder;
dfTolerance = psInfo->dfTolerance;
padfGeoX = (double *) CPLCalloc(sizeof(double),nGCPCount);
padfGeoY = (double *) CPLCalloc(sizeof(double),nGCPCount);
padfRasterX = (double *) CPLCalloc(sizeof(double),nGCPCount);
padfRasterY = (double *) CPLCalloc(sizeof(double),nGCPCount);
panStatus = (int *) CPLCalloc(sizeof(int),nGCPCount);
try
{
padfGeoX = new double[nGCPCount];
padfGeoY = new double[nGCPCount];
padfRasterX = new double[nGCPCount];
padfRasterY = new double[nGCPCount];
panStatus = new int[nGCPCount];
for( nI = 0; nI < nGCPCount; nI++ )
{
......@@ -1223,11 +1220,17 @@ static int remove_outliers( GCPTransformInfo *psInfo )
psInfo->pasGCPList[nI].dfGCPLine = sPoints.n1[nI];
}
psInfo->nGCPCount = sPoints.count;
}
catch( const std::exception& e )
{
CPLError(CE_Failure, CPLE_OutOfMemory, "%s", e.what());
nCRSresult = MINTERR;
}
delete[] padfGeoX;
delete[] padfGeoY;
delete[] padfRasterX;
delete[] padfRasterY;
delete[] panStatus;
CPLFree( sPoints.e1 );
CPLFree( sPoints.n1 );
CPLFree( sPoints.e2 );
CPLFree( sPoints.n2 );
CPLFree( sPoints.status );
return nCRSresult;
}
......@@ -51,12 +51,13 @@
# include "gdalsse_priv.h"
#endif
#include "ogr_api.h"
#include "ogr_geometry.h"
#include "ogr_spatialref.h"
#include "ogr_srs_api.h"
// #define DEBUG_VERBOSE_EXTRACT_DEM
CPL_CVSID("$Id: gdal_rpc.cpp 9ff327806cd64df6d73a6c91f92d12ca0c5e07df 2018-04-07 20:25:06 +0200 Even Rouault $")
CPL_CVSID("$Id: gdal_rpc.cpp 32d7ee9c6858066d6bf7986860d2ed2742c7220c 2019-02-16 10:50:28 +0100 Even Rouault $")
CPL_C_START
CPLXMLNode *GDALSerializeRPCTransformer( void *pTransformArg );
......@@ -263,6 +264,11 @@ typedef struct {
bool bRPCInverseVerbose;
char *pszRPCInverseLog;
char *pszRPCFootprint;
OGRGeometry *poRPCFootprintGeom;
OGRPreparedGeometry *poRPCFootprintPreparedGeom;
} GDALRPCTransformInfo;
static bool GDALRPCOpenDEM( GDALRPCTransformInfo* psTransform );
......@@ -741,6 +747,14 @@ retry:
* iterative solution of pixel/line to lat/long computations. Default value is
* 10 in the absence of a DEM, or 20 if there is a DEM. (GDAL >= 2.1.0)
*
* <li> RPC_FOOTPRINT: WKT or GeoJSON polygon (in long / lat coordinate space)
* with a validity footprint for the RPC. Any coordinate transformation that
* goes from or arrive outside this footprint will be considered invalid. This
* is useful in situations where the RPC values become highly unstable outside
* of the area on which they have been computed for, potentially leading to
* undesirable "echoes" / false positives. This requires GDAL to be built against
* GEOS.
*
* </ul>
*
* @param psRPCInfo Definition of the RPC parameters.
......@@ -890,6 +904,38 @@ void *GDALCreateRPCTransformer( GDALRPCInfo *psRPCInfo, int bReversed,
if( pszRPCInverseLog != nullptr )
psTransform->pszRPCInverseLog = CPLStrdup(pszRPCInverseLog);
/* -------------------------------------------------------------------- */
/* Footprint */
/* -------------------------------------------------------------------- */
const char* pszFootprint = CSLFetchNameValue(papszOptions, "RPC_FOOTPRINT");
if( pszFootprint != nullptr )
{
psTransform->pszRPCFootprint = CPLStrdup(pszFootprint);
if( pszFootprint[0] == '{' )
{
psTransform->poRPCFootprintGeom =
OGRGeometryFactory::createFromGeoJson(pszFootprint);
}
else
{
OGRGeometryFactory::createFromWkt(pszFootprint, nullptr,
&(psTransform->poRPCFootprintGeom));
}
if( psTransform->poRPCFootprintGeom )
{
if( OGRHasPreparedGeometrySupport() )
{
psTransform->poRPCFootprintPreparedGeom =
OGRCreatePreparedGeometry(psTransform->poRPCFootprintGeom);
}
else
{
CPLError(CE_Warning, CPLE_AppDefined,
"GEOS not available. RPC_FOOTPRINT will be ignored");
}
}
}
/* -------------------------------------------------------------------- */
/* Open DEM if needed. */
/* -------------------------------------------------------------------- */
......@@ -922,7 +968,7 @@ void *GDALCreateRPCTransformer( GDALRPCInfo *psRPCInfo, int bReversed,
int nSuccess = 0;
// Try with DEM first.
if( GDALRPCTransform( psTransform, !(psTransform->bReversed), 1,
&dfX, &dfY, &dfZ, &nSuccess) )
&dfX, &dfY, &dfZ, &nSuccess) && nSuccess )
{
dfRefPixel = dfX;
dfRefLine = dfY;
......@@ -948,7 +994,7 @@ void *GDALCreateRPCTransformer( GDALRPCInfo *psRPCInfo, int bReversed,
int nSuccess = 0;
// Try with DEM first.
if( GDALRPCTransform( psTransform, !(psTransform->bReversed), 1,
&dfX, &dfY, &dfZ, &nSuccess) )
&dfX, &dfY, &dfZ, &nSuccess) && nSuccess )
{
dfRefPixel = dfX;
dfRefLine = dfY;
......@@ -1024,6 +1070,10 @@ void GDALDestroyRPCTransformer( void *pTransformAlg )
reinterpret_cast<OGRCoordinateTransformationH>(psTransform->poCT));
CPLFree( psTransform->pszRPCInverseLog );
CPLFree( psTransform->pszRPCFootprint );
delete psTransform->poRPCFootprintGeom;
OGRDestroyPreparedGeometry(psTransform->poRPCFootprintPreparedGeom);
CPLFree( pTransformAlg );
}
......@@ -1572,6 +1622,22 @@ near_fallback:
}
}
/************************************************************************/
/* RPCIsValidLongLat() */
/************************************************************************/
static bool RPCIsValidLongLat( const GDALRPCTransformInfo *psTransform,
double dfLong, double dfLat )
{
if( !psTransform->poRPCFootprintPreparedGeom )
return true;
OGRPoint p(dfLong, dfLat);
return CPL_TO_BOOL(
OGRPreparedGeometryContains(psTransform->poRPCFootprintPreparedGeom,
&p));
}
/************************************************************************/
/* GDALRPCTransformWholeLineWithDEM() */
/************************************************************************/
......@@ -1617,6 +1683,9 @@ GDALRPCTransformWholeLineWithDEM( const GDALRPCTransformInfo *psTransform,
for( int i = 0; i < nPointCount; i++ )
{
if( padfX[i] == HUGE_VAL )
continue;
double dfDEMH = 0.0;
const double dfZ_i = padfZ ? padfZ[i] : 0.0;
......@@ -1709,6 +1778,13 @@ GDALRPCTransformWholeLineWithDEM( const GDALRPCTransformInfo *psTransform,
{
if( k_valid_sample >= 0 )
{
if( !RPCIsValidLongLat(psTransform, padfX[i], padfY[i]) )
{
panSuccess[i] = FALSE;
padfX[i] = HUGE_VAL;
padfY[i] = HUGE_VAL;
continue;
}
dfDEMH = adfElevData[k_valid_sample];
RPCTransformPoint( psTransform, padfX[i], padfY[i],
dfZ_i + (psTransform->dfHeightOffset + dfDEMH) *
......@@ -1720,6 +1796,13 @@ GDALRPCTransformWholeLineWithDEM( const GDALRPCTransformInfo *psTransform,
}
else if( psTransform->bHasDEMMissingValue )
{
if( !RPCIsValidLongLat(psTransform, padfX[i], padfY[i]) )
{
panSuccess[i] = FALSE;
padfX[i] = HUGE_VAL;
padfY[i] = HUGE_VAL;
continue;
}
dfDEMH = psTransform->dfDEMMissingValue;
RPCTransformPoint( psTransform, padfX[i], padfY[i],
dfZ_i + (psTransform->dfHeightOffset + dfDEMH) *
......@@ -1732,6 +1815,8 @@ GDALRPCTransformWholeLineWithDEM( const GDALRPCTransformInfo *psTransform,
else
{
panSuccess[i] = FALSE;
padfX[i] = HUGE_VAL;
padfY[i] = HUGE_VAL;
continue;
}
}
......@@ -1761,11 +1846,20 @@ GDALRPCTransformWholeLineWithDEM( const GDALRPCTransformInfo *psTransform,
else
{
panSuccess[i] = FALSE;
padfX[i] = HUGE_VAL;
padfY[i] = HUGE_VAL;
continue;
}
}
}
if( !RPCIsValidLongLat(psTransform, padfX[i], padfY[i]) )
{
panSuccess[i] = FALSE;
padfX[i] = HUGE_VAL;
padfY[i] = HUGE_VAL;
continue;
}
RPCTransformPoint( psTransform, padfX[i], padfY[i],
dfZ_i + (psTransform->dfHeightOffset + dfDEMH) *
psTransform->dfHeightScale,
......@@ -1816,17 +1910,39 @@ static bool GDALRPCOpenDEM( GDALRPCTransformInfo* psTransform )
psTransform->nBufferHeight = -1;
psTransform->nLastQueriedX = -1;
psTransform->nLastQueriedY = -1;
const char* pszSpatialRef = psTransform->poDS->GetProjectionRef();
if( pszSpatialRef != nullptr && pszSpatialRef[0] != '\0' )
auto poDSSpaRefSrc = psTransform->poDS->GetSpatialRef();
if( poDSSpaRefSrc )
{
OGRSpatialReference* poWGSSpaRef =
new OGRSpatialReference(SRS_WKT_WGS84);
auto poDSSpaRef = poDSSpaRefSrc->Clone();
OGRSpatialReference* poDSSpaRef =
new OGRSpatialReference(pszSpatialRef);
if( !psTransform->bApplyDEMVDatumShift )
poDSSpaRef->StripVertical();
auto wkt_EPSG_4979 =
"GEODCRS[\"WGS 84\",\n"
" DATUM[\"World Geodetic System 1984\",\n"
" ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n"
" LENGTHUNIT[\"metre\",1]]],\n"
" PRIMEM[\"Greenwich\",0,\n"
" ANGLEUNIT[\"degree\",0.0174532925199433]],\n"
" CS[ellipsoidal,3],\n"
" AXIS[\"geodetic latitude (Lat)\",north,\n"
" ORDER[1],\n"
" ANGLEUNIT[\"degree\",0.0174532925199433]],\n"
" AXIS[\"geodetic longitude (Lon)\",east,\n"
" ORDER[2],\n"
" ANGLEUNIT[\"degree\",0.0174532925199433]],\n"
" AXIS[\"ellipsoidal height (h)\",up,\n"
" ORDER[3],\n"
" LENGTHUNIT[\"metre\",1]],\n"
" AREA[\"World (by country)\"],\n"
" BBOX[-90,-180,90,180],\n"
" ID[\"EPSG\",4979]]";
OGRSpatialReference* poWGSSpaRef =
new OGRSpatialReference(
poDSSpaRef->IsCompound() ? wkt_EPSG_4979 : SRS_WKT_WGS84_LAT_LONG);
poWGSSpaRef->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
if( !poWGSSpaRef->IsSame(poDSSpaRef) )
psTransform->poCT =
OGRCreateCoordinateTransformation(poWGSSpaRef,
......@@ -2024,6 +2140,13 @@ int GDALRPCTransform( void *pTransformArg, int bDstToSrc,
for( int i = 0; i < nPointCount; i++ )
{
if( !RPCIsValidLongLat(psTransform, padfX[i], padfY[i]) )
{
panSuccess[i] = FALSE;
padfX[i] = HUGE_VAL;
padfY[i] = HUGE_VAL;
continue;
}
double dfHeight = 0.0;
if( !GDALRPCGetHeightAtLongLat( psTransform, padfX[i], padfY[i],
&dfHeight ) )
......@@ -2069,6 +2192,13 @@ int GDALRPCTransform( void *pTransformArg, int bDstToSrc,
padfY[i] = HUGE_VAL;
continue;
}
if( !RPCIsValidLongLat(psTransform, padfX[i], padfY[i]) )
{
panSuccess[i] = FALSE;
padfX[i] = HUGE_VAL;
padfY[i] = HUGE_VAL;
continue;
}
padfX[i] = dfResultX;
padfY[i] = dfResultY;
......
......@@ -29,23 +29,18 @@
#include "cpl_string.h"
#include "gdal.h"
#include "gdal_alg.h"
#include "gdal_alg_priv.h"
#include "gdal_priv.h"
#include "gdal_utils.h"
#include "gdalwarper.h"
#include "vrtdataset.h"
#include "ogr_spatialref.h"
#ifdef PROJ_STATIC
#if defined(PROJ_VERSION) && PROJ_VERSION >= 5
#include "proj.h"
#else
#include "proj_api.h"
#endif
#endif
#include <limits>
CPL_CVSID("$Id: gdalapplyverticalshiftgrid.cpp fe2d81c8819bf9794bce0210098e637565728350 2018-05-06 00:49:51 +0200 Even Rouault $")
CPL_CVSID("$Id: gdalapplyverticalshiftgrid.cpp 8e5eeb35bf76390e3134a4ea7076dab7d478ea0e 2018-11-14 22:55:13 +0100 Even Rouault $")
/************************************************************************/
/* GDALApplyVSGDataset */
......@@ -76,7 +71,7 @@ class GDALApplyVSGDataset final: public GDALDataset
virtual int CloseDependentDatasets() override;
virtual CPLErr GetGeoTransform(double* padfGeoTransform) override;
virtual const char* GetProjectionRef() override;
virtual const OGRSpatialReference* GetSpatialRef() const override;
bool IsInitOK();
};
......@@ -174,12 +169,12 @@ CPLErr GDALApplyVSGDataset::GetGeoTransform(double* padfGeoTransform)
}
/************************************************************************/
/* GetProjectionRef() */
/* GetSpatialRef() */
/************************************************************************/
const char* GDALApplyVSGDataset::GetProjectionRef()
const OGRSpatialReference* GDALApplyVSGDataset::GetSpatialRef() const
{
return m_poSrcDataset->GetProjectionRef();
return m_poSrcDataset->GetSpatialRef();
}
/************************************************************************/
......@@ -393,10 +388,25 @@ GDALDatasetH GDALApplyVerticalShiftGrid( GDALDatasetH hSrcDataset,
"Source dataset has no geotransform.");
return nullptr;
}
const char* pszSrcProjection = CSLFetchNameValueDef(papszOptions,
"SRC_SRS",
GDALGetProjectionRef(hSrcDataset));
if( pszSrcProjection == nullptr || pszSrcProjection[0] == '\0' )
const char* pszSrcProjection = CSLFetchNameValue(papszOptions, "SRC_SRS");
OGRSpatialReference oSrcSRS;
if( pszSrcProjection != nullptr && pszSrcProjection[0] != '\0' )
{
oSrcSRS.SetFromUserInput(pszSrcProjection);
}
else
{
auto poSRS = GDALDataset::FromHandle(hSrcDataset)->GetSpatialRef();
if( poSRS )
oSrcSRS = *poSRS;
}
if( oSrcSRS.IsCompound() )
{
oSrcSRS.StripVertical();
}
if( oSrcSRS.IsEmpty() )
{
CPLError(CE_Failure, CPLE_NotSupported,
"Source dataset has no projection.");
......@@ -416,8 +426,9 @@ GDALDatasetH GDALApplyVerticalShiftGrid( GDALDatasetH hSrcDataset,
"Grid dataset has no geotransform.");
return nullptr;
}
const char* pszGridProjection = GDALGetProjectionRef(hGridDataset);
if( pszGridProjection == nullptr || pszGridProjection[0] == '\0' )
OGRSpatialReferenceH hGridSRS = GDALGetSpatialRef(hGridDataset);
if( hGridSRS == nullptr )
{
CPLError(CE_Failure, CPLE_NotSupported,
"Grid dataset has no projection.");
......@@ -444,25 +455,37 @@ GDALDatasetH GDALApplyVerticalShiftGrid( GDALDatasetH hSrcDataset,
const int nSrcXSize = GDALGetRasterXSize(hSrcDataset);
const int nSrcYSize = GDALGetRasterYSize(hSrcDataset);
OGRSpatialReference oSRS;
CPLString osSrcProjection(pszSrcProjection);
oSRS.SetFromUserInput(osSrcProjection);
if( oSRS.IsCompound() )
{
OGR_SRSNode* poNode = oSRS.GetRoot()->GetChild(1);
if( poNode != nullptr )
{
char* pszWKT = nullptr;
poNode->exportToWkt(&pszWKT);
osSrcProjection = pszWKT;
CPLFree(pszWKT);
}
}
void* hTransform = GDALCreateGenImgProjTransformer3( pszGridProjection,
double dfWestLongitudeDeg = 0.0;
double dfSouthLatitudeDeg = 0.0;
double dfEastLongitudeDeg = 0.0;
double dfNorthLatitudeDeg = 0.0;
GDALComputeAreaOfInterest(
&oSrcSRS,
adfSrcGT,
nSrcXSize,
nSrcYSize,
dfWestLongitudeDeg,
dfSouthLatitudeDeg,
dfEastLongitudeDeg,
dfNorthLatitudeDeg);
CPLStringList aosOptions;
if( !(dfWestLongitudeDeg == 0.0 && dfSouthLatitudeDeg == 0.0 &&
dfEastLongitudeDeg == 0.0 && dfNorthLatitudeDeg == 0.0) )
{
aosOptions.SetNameValue(
"AREA_OF_INTEREST",
CPLSPrintf("%.16g,%.16g,%.16g,%.16g",
dfWestLongitudeDeg,
dfSouthLatitudeDeg,
dfEastLongitudeDeg,
dfNorthLatitudeDeg));
}
void* hTransform = GDALCreateGenImgProjTransformer4( hGridSRS,
adfGridGT,
osSrcProjection,
adfSrcGT );
OGRSpatialReference::ToHandle(&oSrcSRS),
adfSrcGT,
aosOptions.List());
if( hTransform == nullptr )
return nullptr;
GDALWarpOptions* psWO = GDALCreateWarpOptions();
......@@ -550,18 +573,6 @@ GDALDatasetH GDALApplyVerticalShiftGrid( GDALDatasetH hSrcDataset,
return reinterpret_cast<GDALDatasetH>(poOutDS);
}
/************************************************************************/
/* my_proj4_logger() */
/************************************************************************/
#if defined(PROJ_STATIC) && PJ_VERSION >= 490 && PJ_VERSION <= 493
static void my_proj4_logger(void * user_data, int /*level*/, const char * msg)
{
CPLString* posMsg = static_cast<CPLString*>(user_data);
*posMsg += msg;
}
#endif
/************************************************************************/
/* GetProj4Filename() */
/************************************************************************/
......@@ -576,78 +587,12 @@ static CPLString GetProj4Filename(const char* pszFilename)
return pszFilename;
}
#if defined(PROJ_STATIC) && PROJ_VERSION >= 5
PJ_GRID_INFO info = proj_grid_info(pszFilename);
if( info.filename[0] )
{
osFilename = info.filename;
}
#elif defined(PROJ_STATIC) && PJ_VERSION > 493
osFilename.resize(2048);
projCtx ctx = pj_ctx_alloc();
if( pj_find_file(ctx, pszFilename, &osFilename[0], osFilename.size()) )
{
osFilename.resize( strlen(osFilename) );
}
else
{
osFilename.clear();
}
pj_ctx_free(ctx);
#else
// Transpose some of the proj.4 pj_open_lib() logic...
/* check if ~/name */
char* pszSysname;
if (*pszFilename == '~' &&
(pszFilename[1] == '/' || pszFilename[1] == '\\') )
{
if ((pszSysname = getenv("HOME")) != nullptr)
{
osFilename = CPLFormFilename(pszSysname, pszFilename + 1, nullptr);
}
return osFilename;
}
/* or is environment PROJ_LIB defined */
else if ((pszSysname = getenv("PROJ_LIB")) != nullptr)
{
osFilename = CPLFormFilename(pszSysname, pszFilename, nullptr);
VSIStatBufL sStat;
if( VSIStatL(osFilename, &sStat) == 0 )
return osFilename;
osFilename.clear();
}
#if defined(PROJ_STATIC) && PJ_VERSION >= 490
// Super messy. proj.4 up to 4.9.3 had no public API to return the full
// path to a resource file, so we rely on the fact that it emits a log
// message with it...
// Basically this is needed in the case where the file is in the
// resource installation directory of proj.4, which we have no way to
// know otherwise.
CPLString osMsg;
projCtx ctx = pj_ctx_alloc();
pj_ctx_set_app_data(ctx, &osMsg);
pj_ctx_set_debug(ctx, PJ_LOG_DEBUG_MAJOR);
pj_ctx_set_logger(ctx, my_proj4_logger);
PAFile f = pj_open_lib(ctx, pszFilename, "rb");
if( f )
{
pj_ctx_fclose(ctx, f);
size_t nPos = osMsg.find("fopen(");
if( nPos != std::string::npos )
{
osFilename = osMsg.substr(nPos + strlen("fopen("));
nPos = osFilename.find(")");
if( nPos != std::string::npos )
osFilename = osFilename.substr(0, nPos);
}
}
pj_ctx_free(ctx);
#endif
#endif
return osFilename;
}
......
......@@ -46,7 +46,7 @@
#include "gdal.h"
#include "gdal_priv.h"
CPL_CVSID("$Id: gdalgeoloc.cpp faaa208b7316149585a7d8e5f755ab4c56f1b31c 2018-01-22 14:27:17Z Kurt Schwehr $")
CPL_CVSID("$Id: gdalgeoloc.cpp e261fa324369d4f7742b57bf7761bcf41765cabb 2019-03-19 16:43:56 +0100 Even Rouault $")
CPL_C_START
CPLXMLNode *GDALSerializeGeoLocTransformer( void *pTransformArg );
......@@ -83,6 +83,7 @@ typedef struct {
GDALRasterBandH hBand_X;
GDALDatasetH hDS_Y;
GDALRasterBandH hBand_Y;
int bSwapXY;
// Located geolocation data.
int nGeoLocXSize;
......@@ -764,6 +765,9 @@ void *GDALCreateGeoLocTransformer( GDALDatasetH hBaseDS,
return nullptr;
}
psTransform->bSwapXY = CPLTestBool(CSLFetchNameValueDef(
papszGeolocationInfo, "SWAP_XY", "NO"));
/* -------------------------------------------------------------------- */
/* Check that X and Y bands have the same dimensions */
/* -------------------------------------------------------------------- */
......@@ -948,6 +952,11 @@ int GDALGeoLocTransform( void *pTransformArg,
padfY[i] = padfGLY[0];
}
if( psTransform->bSwapXY )
{
std::swap(padfX[i], padfY[i]);
}
panSuccess[i] = TRUE;
}
}
......@@ -965,6 +974,11 @@ int GDALGeoLocTransform( void *pTransformArg,
continue;
}
if( psTransform->bSwapXY )
{
std::swap(padfX[i], padfY[i]);
}
const double dfBMX =
((padfX[i] - psTransform->adfBackMapGeoTransform[0])
/ psTransform->adfBackMapGeoTransform[1]) - ISHIFT;
......
......@@ -32,7 +32,7 @@
#ifdef HAVE_SSE_AT_COMPILE_TIME
#include <xmmintrin.h>
CPL_CVSID("$Id: gdalgridsse.cpp 9ff327806cd64df6d73a6c91f92d12ca0c5e07df 2018-04-07 20:25:06 +0200 Even Rouault $")
CPL_CVSID("$Id: gdalgridsse.cpp 75ca5cf8283b1c35266b53e555a575aa4180f38a 2019-02-18 20:54:30 +0100 Even Rouault $")
/************************************************************************/
/* GDALGridInverseDistanceToAPower2NoSmoothingNoSearchSSE() */
......@@ -106,13 +106,13 @@ GDALGridInverseDistanceToAPower2NoSmoothingNoSearchSSE(
size_t nPointsRound = (nPoints / LOOP_SIZE) * LOOP_SIZE;
for( i = 0; i < nPointsRound; i += LOOP_SIZE )
{
__m128 xmm_rx = _mm_sub_ps(_mm_load_ps((float*)pafX + i), xmm_x); /* rx = pafX[i] - fXPoint */
__m128 xmm_ry = _mm_sub_ps(_mm_load_ps((float*)pafY + i), xmm_y); /* ry = pafY[i] - fYPoint */
__m128 xmm_rx = _mm_sub_ps(_mm_load_ps(pafX + i), xmm_x); /* rx = pafX[i] - fXPoint */
__m128 xmm_ry = _mm_sub_ps(_mm_load_ps(pafY + i), xmm_y); /* ry = pafY[i] - fYPoint */
__m128 xmm_r2 = _mm_add_ps(_mm_mul_ps(xmm_rx, xmm_rx), /* r2 = rx * rx + ry * ry */
_mm_mul_ps(xmm_ry, xmm_ry));
__m128 xmm_invr2 = _mm_rcp_ps(xmm_r2); /* invr2 = 1.0f / r2 */
xmm_nominator = _mm_add_ps(xmm_nominator, /* nominator += invr2 * pafZ[i] */
_mm_mul_ps(xmm_invr2, _mm_load_ps((float*)pafZ + i)));
_mm_mul_ps(xmm_invr2, _mm_load_ps(pafZ + i)));
xmm_denominator = _mm_add_ps(xmm_denominator, xmm_invr2); /* denominator += invr2 */
mask = _mm_movemask_ps(_mm_cmplt_ps(xmm_r2, xmm_small)); /* if( r2 < fEpsilon) */
if( mask )
......
......@@ -51,7 +51,7 @@
// Limit types to practical use cases.
#define LIMIT_TYPES 1
CPL_CVSID("$Id: gdalpansharpen.cpp 9f0bbc321e11d7f88ee59af5ccdfb58204ec04f6 2018-11-22 11:25:14 +0100 Even Rouault $")
CPL_CVSID("$Id: gdalpansharpen.cpp 850a0ae6beb0f39f01b5a44e136f0eebf99a421b 2019-03-24 20:29:56 +0100 Even Rouault $")
/************************************************************************/
/* GDALCreatePansharpenOptions() */
......@@ -259,7 +259,7 @@ GDALPansharpenOperation::Initialize( const GDALPansharpenOptions* psOptionsIn )
}
}
GDALRasterBand* poPanchroBand = reinterpret_cast<GDALRasterBand*>(
GDALRasterBand* poPanchroBand = GDALRasterBand::FromHandle(
psOptionsIn->hPanchroBand);
GDALDataType eWorkDataType = poPanchroBand->GetRasterDataType();
if( psOptionsIn->nBitDepth )
......@@ -301,7 +301,7 @@ GDALPansharpenOperation::Initialize( const GDALPansharpenOptions* psOptionsIn )
for( int i = 0; i < psOptions->nInputSpectralBands; i++ )
{
aMSBands.push_back( reinterpret_cast<GDALRasterBand*>(
aMSBands.push_back( GDALRasterBand::FromHandle(
psOptions->pahInputSpectralBands[i]) );
}
......@@ -310,7 +310,7 @@ GDALPansharpenOperation::Initialize( const GDALPansharpenOptions* psOptionsIn )
bool bNeedToWrapInVRT = false;
for( int i = 0; i < psOptions->nInputSpectralBands; i++ )
{
GDALRasterBand* poBand = reinterpret_cast<GDALRasterBand*>(
GDALRasterBand* poBand = GDALRasterBand::FromHandle(
psOptions->pahInputSpectralBands[i]);
int bHasNoData = FALSE;
double dfNoData = poBand->GetNoDataValue(&bHasNoData);
......@@ -381,6 +381,7 @@ GDALPansharpenOperation::Initialize( const GDALPansharpenOptions* psOptionsIn )
{
CPLDebug("PANSHARPEN", "Using %d threads", nThreads);
poThreadPool = new (std::nothrow) CPLWorkerThreadPool();
// coverity[tainted_data]
if( poThreadPool == nullptr ||
!poThreadPool->Setup( nThreads, nullptr, nullptr ) )
{
......@@ -416,8 +417,8 @@ template<class WorkDataType, class OutDataType>
const WorkDataType* pPanBuffer,
const WorkDataType* pUpsampledSpectralBuffer,
OutDataType* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
WorkDataType nMaxValue) const
{
WorkDataType noData, validValue;
......@@ -430,7 +431,7 @@ template<class WorkDataType, class OutDataType>
else
validValue = noData - 1;
for( int j = 0; j < nValues; j++ )
for( size_t j = 0; j < nValues; j++ )
{
double dfPseudoPanchro = 0.0;
for( int i = 0; i < psOptions->nInputSpectralBands; i++ )
......@@ -507,8 +508,8 @@ void GDALPansharpenOperation::WeightedBrovey3(
const WorkDataType* pPanBuffer,
const WorkDataType* pUpsampledSpectralBuffer,
OutDataType* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
WorkDataType nMaxValue) const
{
if( psOptions->bHasNoData )
......@@ -519,7 +520,7 @@ void GDALPansharpenOperation::WeightedBrovey3(
return;
}
for( int j = 0; j < nValues; j++ )
for( size_t j = 0; j < nValues; j++ )
{
double dfFactor = 0.0;
// if( pPanBuffer[j] == 0 )
......@@ -553,12 +554,12 @@ void GDALPansharpenOperation::WeightedBrovey3(
#include "gdalsse_priv.h"
template<class T, int NINPUT, int NOUTPUT>
int GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal(
size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal(
const T* pPanBuffer,
const T* pUpsampledSpectralBuffer,
T* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
T nMaxValue) const
{
CPL_STATIC_ASSERT( NINPUT == 3 || NINPUT == 4 );
......@@ -574,8 +575,8 @@ int GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal(
const XMMReg4Double maxValue =
XMMReg4Double::Load1ValHighAndLow(&dfMaxValue);
int j = 0; // Used after for.
for( ; j < nValues - 3; j += 4 )
size_t j = 0; // Used after for.
for( ; j + 3 < nValues; j += 4 )
{
XMMReg4Double pseudoPanchro = zero;
......@@ -620,12 +621,12 @@ int GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal(
#else
template<class T, int NINPUT, int NOUTPUT>
int GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal(
size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal(
const T* pPanBuffer,
const T* pUpsampledSpectralBuffer,
T* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
T nMaxValue) const
{
// cppcheck-suppress knownConditionTrueFalse
......@@ -635,8 +636,8 @@ int GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal(
const double dfw2 = psOptions->padfWeights[2];
// cppcheck-suppress knownConditionTrueFalse
const double dfw3 = (NINPUT == 3) ? 0 : psOptions->padfWeights[3];
int j = 0; // Used after for.
for( ; j < nValues-1; j += 2 )
size_t j = 0; // Used after for.
for( ; j + 1 < nValues; j += 2 )
{
double dfFactor = 0.0;
double dfFactor2 = 0.0;
......@@ -691,8 +692,8 @@ void GDALPansharpenOperation::WeightedBroveyPositiveWeights(
const T* pPanBuffer,
const T* pUpsampledSpectralBuffer,
T* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
T nMaxValue) const
{
if( psOptions->bHasNoData )
......@@ -705,7 +706,7 @@ void GDALPansharpenOperation::WeightedBroveyPositiveWeights(
if( nMaxValue == 0 )
nMaxValue = std::numeric_limits<T>::max();
int j;
size_t j;
if( psOptions->nInputSpectralBands == 3 &&
psOptions->nOutPansharpenedBands == 3 &&
psOptions->panOutPansharpenedBands[0] == 0 &&
......@@ -739,7 +740,7 @@ void GDALPansharpenOperation::WeightedBroveyPositiveWeights(
}
else
{
for( j = 0; j < nValues - 1; j += 2 )
for( j = 0; j + 1 < nValues; j += 2 )
{
double dfFactor = 0.0;
double dfFactor2 = 0.0;
......@@ -797,8 +798,8 @@ GDALPansharpenOperation::WeightedBrovey(
const WorkDataType* pPanBuffer,
const WorkDataType* pUpsampledSpectralBuffer,
OutDataType* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
WorkDataType nMaxValue ) const
{
if( nMaxValue == 0 )
......@@ -818,8 +819,8 @@ void GDALPansharpenOperation::WeightedBroveyGByteOrUInt16(
const T* pPanBuffer,
const T* pUpsampledSpectralBuffer,
T* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
T nMaxValue ) const
{
if( bPositiveWeights )
......@@ -848,8 +849,8 @@ void GDALPansharpenOperation::WeightedBrovey<GByte, GByte>(
const GByte* pPanBuffer,
const GByte* pUpsampledSpectralBuffer,
GByte* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
GByte nMaxValue ) const
{
WeightedBroveyGByteOrUInt16(pPanBuffer, pUpsampledSpectralBuffer,
......@@ -862,8 +863,8 @@ void GDALPansharpenOperation::WeightedBrovey<GUInt16, GUInt16>(
const GUInt16* pPanBuffer,
const GUInt16* pUpsampledSpectralBuffer,
GUInt16* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
GUInt16 nMaxValue ) const
{
WeightedBroveyGByteOrUInt16(pPanBuffer, pUpsampledSpectralBuffer,
......@@ -876,8 +877,8 @@ template<class WorkDataType> CPLErr GDALPansharpenOperation::WeightedBrovey(
const WorkDataType* pUpsampledSpectralBuffer,
void *pDataBuf,
GDALDataType eBufDataType,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
WorkDataType nMaxValue ) const
{
switch( eBufDataType )
......@@ -941,7 +942,7 @@ template<class WorkDataType> CPLErr GDALPansharpenOperation::WeightedBrovey(
const WorkDataType* pUpsampledSpectralBuffer,
void *pDataBuf,
GDALDataType eBufDataType,
int nValues, int nBandValues ) const
size_t nValues, size_t nBandValues ) const
{
switch( eBufDataType )
{
......@@ -1004,9 +1005,9 @@ template<class WorkDataType> CPLErr GDALPansharpenOperation::WeightedBrovey(
/************************************************************************/
template< class T >
static void ClampValues( T* panBuffer, int nValues, T nMaxVal )
static void ClampValues( T* panBuffer, size_t nValues, T nMaxVal )
{
for( int i = 0; i < nValues; i++ )
for( size_t i = 0; i < nValues; i++ )
{
if( panBuffer[i] > nMaxVal )
panBuffer[i] = nMaxVal;
......@@ -1050,7 +1051,7 @@ CPLErr GDALPansharpenOperation::ProcessRegion( int nXOff, int nYOff,
return CE_Failure;
// TODO: Avoid allocating buffers each time.
GDALRasterBand* poPanchroBand = reinterpret_cast<GDALRasterBand*>(
GDALRasterBand* poPanchroBand = GDALRasterBand::FromHandle(
psOptions->hPanchroBand);
GDALDataType eWorkDataType = poPanchroBand->GetRasterDataType();
#ifdef LIMIT_TYPES
......@@ -1402,22 +1403,22 @@ CPLErr GDALPansharpenOperation::ProcessRegion( int nXOff, int nYOff,
{
if( eWorkDataType == GDT_Byte )
{
ClampValues(reinterpret_cast<GByte*>(pUpsampledSpectralBuffer) + i * nXSize * nYSize,
nXSize*nYSize,
ClampValues(reinterpret_cast<GByte*>(pUpsampledSpectralBuffer) + static_cast<size_t>(i) * nXSize * nYSize,
static_cast<size_t>(nXSize)*nYSize,
static_cast<GByte>((1 << nBitDepth)-1));
}
else if( eWorkDataType == GDT_UInt16 )
{
ClampValues(reinterpret_cast<GUInt16*>(pUpsampledSpectralBuffer) + i * nXSize * nYSize,
nXSize*nYSize,
ClampValues(reinterpret_cast<GUInt16*>(pUpsampledSpectralBuffer) + static_cast<size_t>(i) * nXSize * nYSize,
static_cast<size_t>(nXSize)*nYSize,
static_cast<GUInt16>((1 << nBitDepth)-1));
}
#ifndef LIMIT_TYPES
else if( eWorkDataType == GDT_UInt32 )
{
ClampValues(reinterpret_cast<GUInt32*>(pUpsampledSpectralBuffer) +
i * nXSize * nYSize,
nXSize*nYSize,
static_cast<size_t>(i) * nXSize * nYSize,
static_cast<size_t>(nXSize)*nYSize,
(static_cast<GUInt32>((1 << nBitDepth)-1));
}
#endif
......@@ -1481,8 +1482,8 @@ CPLErr GDALPansharpenOperation::ProcessRegion( int nXOff, int nYOff,
iStartLine * nXSize *
GDALGetDataTypeSizeBytes(eBufDataType);
pasJobs[i].nValues =
static_cast<int>(iNextStartLine - iStartLine) * nXSize;
pasJobs[i].nBandValues = nXSize * nYSize;
(iNextStartLine - iStartLine) * nXSize;
pasJobs[i].nBandValues = static_cast<size_t>(nXSize) * nYSize;
pasJobs[i].nMaxValue = nMaxValue;
#ifdef DEBUG_TIMING
pasJobs[i].ptv = &tv;
......@@ -1509,17 +1510,17 @@ CPLErr GDALPansharpenOperation::ProcessRegion( int nXOff, int nYOff,
pPanBuffer,
pUpsampledSpectralBuffer,
pDataBuf,
nXSize * nYSize,
nXSize * nYSize,
static_cast<size_t>(nXSize) * nYSize,
static_cast<size_t>(nXSize) * nYSize,
nMaxValue);
}
if( padfTempBuffer )
{
GDALCopyWords(padfTempBuffer, GDT_Float64, sizeof(double),
GDALCopyWords64(padfTempBuffer, GDT_Float64, sizeof(double),
pDataBufOri, eBufDataTypeOri,
GDALGetDataTypeSizeBytes(eBufDataTypeOri),
nXSize*nYSize*psOptions->nOutPansharpenedBands);
static_cast<size_t>(nXSize)*nYSize*psOptions->nOutPansharpenedBands);
VSIFree(padfTempBuffer);
}
......@@ -1649,8 +1650,8 @@ GDALPansharpenOperation::PansharpenChunk( GDALDataType eWorkDataType,
const void* pPanBuffer,
const void* pUpsampledSpectralBuffer,
void* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
GUInt32 nMaxValue) const
{
CPLErr eErr = CE_None;
......@@ -1658,51 +1659,51 @@ GDALPansharpenOperation::PansharpenChunk( GDALDataType eWorkDataType,
switch( eWorkDataType )
{
case GDT_Byte:
eErr = WeightedBrovey(reinterpret_cast<const GByte*>(pPanBuffer),
reinterpret_cast<const GByte*>(pUpsampledSpectralBuffer),
eErr = WeightedBrovey(static_cast<const GByte*>(pPanBuffer),
static_cast<const GByte*>(pUpsampledSpectralBuffer),
pDataBuf, eBufDataType,
nValues, nBandValues, static_cast<GByte>(nMaxValue));
break;
case GDT_UInt16:
eErr = WeightedBrovey(reinterpret_cast<const GUInt16*>(pPanBuffer),
reinterpret_cast<const GUInt16*>(pUpsampledSpectralBuffer),
eErr = WeightedBrovey(static_cast<const GUInt16*>(pPanBuffer),
static_cast<const GUInt16*>(pUpsampledSpectralBuffer),
pDataBuf, eBufDataType,
nValues, nBandValues, static_cast<GUInt16>(nMaxValue));
break;
#ifndef LIMIT_TYPES
case GDT_Int16:
eErr = WeightedBrovey(reinterpret_cast<const GInt16*>(pPanBuffer),
reinterpret_cast<const GInt16*>(pUpsampledSpectralBuffer),
eErr = WeightedBrovey(static_cast<const GInt16*>(pPanBuffer),
static_cast<const GInt16*>(pUpsampledSpectralBuffer),
pDataBuf, eBufDataType,
nValues, nBandValues);
break;
case GDT_UInt32:
eErr = WeightedBrovey(reinterpret_cast<const GUInt32*>(pPanBuffer),
reinterpret_cast<const GUInt32*>(pUpsampledSpectralBuffer),
eErr = WeightedBrovey(static_cast<const GUInt32*>(pPanBuffer),
static_cast<const GUInt32*>(pUpsampledSpectralBuffer),
pDataBuf, eBufDataType,
nValues, nBandValues, nMaxValue);
break;
case GDT_Int32:
eErr = WeightedBrovey(reinterpret_cast<const GInt32*>(pPanBuffer),
reinterpret_cast<const GInt32*>(pUpsampledSpectralBuffer),
eErr = WeightedBrovey(static_cast<const GInt32*>(pPanBuffer),
static_cast<const GInt32*>(pUpsampledSpectralBuffer),
pDataBuf, eBufDataType,
nValues, nBandValues);
break;
case GDT_Float32:
eErr = WeightedBrovey(reinterpret_cast<const float*>(pPanBuffer),
reinterpret_cast<const float*>(pUpsampledSpectralBuffer),
eErr = WeightedBrovey(static_cast<const float*>(pPanBuffer),
static_cast<const float*>(pUpsampledSpectralBuffer),
pDataBuf, eBufDataType,
nValues, nBandValues);
break;
#endif
case GDT_Float64:
eErr = WeightedBrovey(reinterpret_cast<const double*>(pPanBuffer),
reinterpret_cast<const double*>(pUpsampledSpectralBuffer),
eErr = WeightedBrovey(static_cast<const double*>(pPanBuffer),
static_cast<const double*>(pUpsampledSpectralBuffer),
pDataBuf, eBufDataType,
nValues, nBandValues);
break;
......
/******************************************************************************
* $Id: gdalpansharpen.h fe2d81c8819bf9794bce0210098e637565728350 2018-05-06 00:49:51 +0200 Even Rouault $
* $Id: gdalpansharpen.h cde29aa7b4807045c418e469b59b60f92af59468 2019-02-18 15:49:24 +0100 Even Rouault $
*
* Project: GDAL Pansharpening module
* Purpose: Prototypes, and definitions for pansharpening related work.
......@@ -147,8 +147,8 @@ typedef struct
const void* pPanBuffer;
const void* pUpsampledSpectralBuffer;
void* pDataBuf;
int nValues;
int nBandValues;
size_t nValues;
size_t nBandValues;
GUInt32 nMaxValue;
#ifdef DEBUG_TIMING
......@@ -204,15 +204,15 @@ class GDALPansharpenOperation
const WorkDataType* pPanBuffer,
const WorkDataType* pUpsampledSpectralBuffer,
OutDataType* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
WorkDataType nMaxValue) const;
template<class WorkDataType, class OutDataType, int bHasBitDepth> void WeightedBrovey3(
const WorkDataType* pPanBuffer,
const WorkDataType* pUpsampledSpectralBuffer,
OutDataType* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
WorkDataType nMaxValue) const;
// cppcheck-suppress functionStatic
......@@ -220,16 +220,16 @@ class GDALPansharpenOperation
const WorkDataType* pPanBuffer,
const WorkDataType* pUpsampledSpectralBuffer,
OutDataType* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
WorkDataType nMaxValue) const;
template<class WorkDataType> CPLErr WeightedBrovey(
const WorkDataType* pPanBuffer,
const WorkDataType* pUpsampledSpectralBuffer,
void *pDataBuf,
GDALDataType eBufDataType,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
WorkDataType nMaxValue) const;
// cppcheck-suppress functionStatic
......@@ -238,22 +238,22 @@ class GDALPansharpenOperation
const WorkDataType* pUpsampledSpectralBuffer,
void *pDataBuf,
GDALDataType eBufDataType,
int nValues,
int nBandValues) const;
size_t nValues,
size_t nBandValues) const;
template<class T> void WeightedBroveyPositiveWeights(
const T* pPanBuffer,
const T* pUpsampledSpectralBuffer,
T* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
T nMaxValue) const;
template<class T, int NINPUT, int NOUTPUT> int WeightedBroveyPositiveWeightsInternal(
template<class T, int NINPUT, int NOUTPUT> size_t WeightedBroveyPositiveWeightsInternal(
const T* pPanBuffer,
const T* pUpsampledSpectralBuffer,
T* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
T nMaxValue) const;
// cppcheck-suppress unusedPrivateFunction
......@@ -261,16 +261,16 @@ class GDALPansharpenOperation
const T* pPanBuffer,
const T* pUpsampledSpectralBuffer,
T* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
T nMaxValue ) const;
CPLErr PansharpenChunk( GDALDataType eWorkDataType, GDALDataType eBufDataType,
const void* pPanBuffer,
const void* pUpsampledSpectralBuffer,
void* pDataBuf,
int nValues,
int nBandValues,
size_t nValues,
size_t nBandValues,
GUInt32 nMaxValue) const;
public:
GDALPansharpenOperation();
......
This diff is collapsed.
This diff is collapsed.
......@@ -71,7 +71,7 @@
#endif
CPL_CVSID("$Id: gdalwarpkernel.cpp 805bf6906b8af247eab8dee060e215d6b8e5c7ae 2018-11-18 12:25:32 +0100 Even Rouault $")
CPL_CVSID("$Id: gdalwarpkernel.cpp fa2676737e01040b4457b2a637db5e73eb9c744f 2019-03-23 10:08:04 +0100 Even Rouault $")
constexpr double BAND_DENSITY_THRESHOLD = 0.0000000001;
constexpr float SRC_DENSITY_THRESHOLD = 0.000000001f;
......@@ -1327,7 +1327,7 @@ CPLErr GDALWarpKernel::Validate()
/* original density. */
/************************************************************************/
static void GWKOverlayDensity( GDALWarpKernel *poWK, int iDstOffset,
static void GWKOverlayDensity( GDALWarpKernel *poWK, GPtrDiff_t iDstOffset,
double dfDensity )
{
if( dfDensity < 0.0001 || poWK->pafDstDensity == nullptr )
......@@ -1406,7 +1406,7 @@ template<> double GWKClampValueT<double>(double dfValue)
template<class T>
static bool GWKSetPixelValueRealT( GDALWarpKernel *poWK, int iBand,
int iDstOffset, double dfDensity,
GPtrDiff_t iDstOffset, double dfDensity,
T value)
{
T *pDst = reinterpret_cast<T*>(poWK->papabyDstImage[iBand]);
......@@ -1477,7 +1477,7 @@ static bool GWKSetPixelValueRealT( GDALWarpKernel *poWK, int iBand,
/************************************************************************/
static bool GWKSetPixelValue( GDALWarpKernel *poWK, int iBand,
int iDstOffset, double dfDensity,
GPtrDiff_t iDstOffset, double dfDensity,
double dfReal, double dfImag )
{
......@@ -1703,7 +1703,7 @@ static bool GWKSetPixelValue( GDALWarpKernel *poWK, int iBand,
/************************************************************************/
static bool GWKSetPixelValueReal( GDALWarpKernel *poWK, int iBand,
int iDstOffset, double dfDensity,
GPtrDiff_t iDstOffset, double dfDensity,
double dfReal )
{
......@@ -1831,7 +1831,7 @@ static bool GWKSetPixelValueReal( GDALWarpKernel *poWK, int iBand,
/* It is assumed that panUnifiedSrcValid has been checked before */
static bool GWKGetPixelValue( GDALWarpKernel *poWK, int iBand,
int iSrcOffset, double *pdfDensity,
GPtrDiff_t iSrcOffset, double *pdfDensity,
double *pdfReal, double *pdfImag )
{
......@@ -1922,7 +1922,7 @@ static bool GWKGetPixelValue( GDALWarpKernel *poWK, int iBand,
/************************************************************************/
static bool GWKGetPixelValueReal( GDALWarpKernel *poWK, int iBand,
int iSrcOffset, double *pdfDensity,
GPtrDiff_t iSrcOffset, double *pdfDensity,
double *pdfReal )
{
......@@ -1988,7 +1988,7 @@ static bool GWKGetPixelValueReal( GDALWarpKernel *poWK, int iBand,
/* data-types. */
static bool GWKGetPixelRow( GDALWarpKernel *poWK, int iBand,
int iSrcOffset, int nHalfSrcLen,
GPtrDiff_t iSrcOffset, int nHalfSrcLen,
double* padfDensity,
double adfReal[],
double* padfImag )
......@@ -2257,7 +2257,7 @@ static bool GWKGetPixelRow( GDALWarpKernel *poWK, int iBand,
template<class T>
static bool GWKGetPixelT( GDALWarpKernel *poWK, int iBand,
int iSrcOffset, double *pdfDensity,
GPtrDiff_t iSrcOffset, double *pdfDensity,
T *pValue )
{
......@@ -2316,11 +2316,11 @@ static bool GWKBilinearResample4Sample( GDALWarpKernel *poWK, int iBand,
iSrcY = 0;
dfRatioY = 1;
}
int iSrcOffset = iSrcX + iSrcY * nSrcXSize;
GPtrDiff_t iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * nSrcXSize;
// Shift so we don't overrun the array.
if( nSrcXSize * nSrcYSize == iSrcOffset + 1
|| nSrcXSize * nSrcYSize == iSrcOffset + nSrcXSize + 1 )
if( static_cast<GPtrDiff_t>(nSrcXSize) * nSrcYSize == iSrcOffset + 1
|| static_cast<GPtrDiff_t>(nSrcXSize) * nSrcYSize == iSrcOffset + nSrcXSize + 1 )
{
bShifted = true;
--iSrcOffset;
......@@ -2334,9 +2334,10 @@ static bool GWKBilinearResample4Sample( GDALWarpKernel *poWK, int iBand,
double dfAccumulatorDensity = 0.0;
double dfAccumulatorDivisor = 0.0;
const GPtrDiff_t nSrcPixels = static_cast<GPtrDiff_t>(nSrcXSize) * nSrcYSize;
// Get pixel row.
if( iSrcY >= 0 && iSrcY < nSrcYSize
&& iSrcOffset >= 0 && iSrcOffset < nSrcXSize * nSrcYSize
&& iSrcOffset >= 0 && iSrcOffset < nSrcPixels
&& GWKGetPixelRow( poWK, iBand, iSrcOffset, 1,
adfDensity, adfReal, adfImag ) )
{
......@@ -2377,7 +2378,7 @@ static bool GWKBilinearResample4Sample( GDALWarpKernel *poWK, int iBand,
// Get pixel row.
if( iSrcY+1 >= 0 && iSrcY+1 < nSrcYSize
&& iSrcOffset+nSrcXSize >= 0
&& iSrcOffset+nSrcXSize < nSrcXSize * nSrcYSize
&& iSrcOffset+nSrcXSize < nSrcPixels
&& GWKGetPixelRow( poWK, iBand, iSrcOffset+nSrcXSize, 1,
adfDensity, adfReal, adfImag ) )
{
......@@ -3370,7 +3371,7 @@ static bool GWKResample( GDALWarpKernel *poWK, int iBand,
double dfAccumulatorWeight = 0.0;
const int iSrcX = static_cast<int>(floor(dfSrcX - 0.5));
const int iSrcY = static_cast<int>(floor(dfSrcY - 0.5));
const int iSrcOffset = iSrcX + iSrcY * nSrcXSize;
const GPtrDiff_t iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * nSrcXSize;
const double dfDeltaX = dfSrcX - 0.5 - iSrcX;
const double dfDeltaY = dfSrcY - 0.5 - iSrcY;
......@@ -3413,7 +3414,7 @@ static bool GWKResample( GDALWarpKernel *poWK, int iBand,
const int bXScaleBelow1 = ( dfXScale < 1.0 );
const int bYScaleBelow1 = ( dfYScale < 1.0 );
int iRowOffset = iSrcOffset + (j - 1) * nSrcXSize + iMin;
GPtrDiff_t iRowOffset = iSrcOffset + static_cast<GPtrDiff_t>(j - 1) * nSrcXSize + iMin;
// Loop over pixel rows in the kernel.
for( ; j <= jMax; ++j )
......@@ -3693,7 +3694,7 @@ static bool GWKResampleOptimizedLanczos( GDALWarpKernel *poWK, int iBand,
}
}
int iRowOffset = iSrcOffset + (jMin - 1) * nSrcXSize + iMin;
GPtrDiff_t iRowOffset = iSrcOffset + static_cast<GPtrDiff_t>(jMin - 1) * nSrcXSize + iMin;
// If we have no density information, we can simply compute the
// accumulated weight.
......@@ -3833,7 +3834,7 @@ static bool GWKResampleNoMasksT( GDALWarpKernel *poWK, int iBand,
const int iSrcX = static_cast<int>(floor(dfSrcX - 0.5));
const int iSrcY = static_cast<int>(floor(dfSrcY - 0.5));
const int iSrcOffset = iSrcX + iSrcY * nSrcXSize;
const GPtrDiff_t iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * nSrcXSize;
const int nXRadius = poWK->nXRadius;
const int nYRadius = poWK->nYRadius;
......@@ -3895,7 +3896,7 @@ static bool GWKResampleNoMasksT( GDALWarpKernel *poWK, int iBand,
for( ; j <= jMax; ++j )
{
const int iSampJ = iSrcOffset + j * nSrcXSize;
const GPtrDiff_t iSampJ = iSrcOffset + static_cast<GPtrDiff_t>(j) * nSrcXSize;
// Loop over all pixels in the row.
double dfAccumulatorLocal = 0.0;
......@@ -3957,7 +3958,7 @@ static bool GWKResampleNoMasks_SSE2_T( GDALWarpKernel *poWK, int iBand,
const int iSrcX = static_cast<int>(floor(dfSrcX - 0.5));
const int iSrcY = static_cast<int>(floor(dfSrcY - 0.5));
const int iSrcOffset = iSrcX + iSrcY * nSrcXSize;
const GPtrDiff_t iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * nSrcXSize;
const int nXRadius = poWK->nXRadius;
const int nYRadius = poWK->nYRadius;
......@@ -4017,7 +4018,7 @@ static bool GWKResampleNoMasks_SSE2_T( GDALWarpKernel *poWK, int iBand,
// Process by chunk of 4 rows.
for( ; j+2 < jMax; j+=4 )
{
int iSampJ = iSrcOffset + j * nSrcXSize;
const GPtrDiff_t iSampJ = iSrcOffset + static_cast<GPtrDiff_t>(j) * nSrcXSize;
// Loop over all pixels in the row.
iC = 0;
......@@ -4106,7 +4107,7 @@ static bool GWKResampleNoMasks_SSE2_T( GDALWarpKernel *poWK, int iBand,
}
for( ; j <= jMax; ++j )
{
int iSampJ = iSrcOffset + j * nSrcXSize;
const GPtrDiff_t iSampJ = iSrcOffset + static_cast<GPtrDiff_t>(j) * nSrcXSize;
// Loop over all pixels in the row.
iC = 0;
......@@ -4514,7 +4515,7 @@ static CPLErr GWKOpenCLCase( GDALWarpKernel *poWK )
{
const double dfX = padfX[iDstX];
const double dfY = padfY[iDstX];
const int iDstOffset = iDstX + iDstY * nDstXSize;
const GPtrDiff_t iDstOffset = iDstX + static_cast<GPtrDiff_t>(iDstY) * nDstXSize;
// See GWKGeneralCase() for appropriate commenting.
if( !pabSuccess[iDstX] || dfX < nSrcXOff || dfY < nSrcYOff )
......@@ -4527,7 +4528,7 @@ static CPLErr GWKOpenCLCase( GDALWarpKernel *poWK )
iSrcY < 0 || iSrcY >= nSrcYSize )
continue;
int iSrcOffset = iSrcX + iSrcY * nSrcXSize;
GPtrDiff_t iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * nSrcXSize;
double dfDensity = 1.0;
if( poWK->pafUnifiedSrcDensity != nullptr
......@@ -4670,7 +4671,7 @@ static CPL_INLINE bool GWKCheckAndComputeSrcOffsets(
const GDALWarpKernel* _poWK,
int _nSrcXSize,
int _nSrcYSize,
int& iSrcOffset)
GPtrDiff_t& iSrcOffset)
{
if( !_pabSuccess[_iDstX] )
return false;
......@@ -4720,7 +4721,7 @@ static CPL_INLINE bool GWKCheckAndComputeSrcOffsets(
CPLAssert( iSrcX < _nSrcXSize );
CPLAssert( iSrcY < _nSrcYSize );
iSrcOffset = iSrcX + iSrcY * _nSrcXSize;
iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * _nSrcXSize;
return true;
}
......@@ -4813,7 +4814,7 @@ static void GWKGeneralCaseThread( void* pData)
/* ==================================================================== */
for( int iDstX = 0; iDstX < nDstXSize; iDstX++ )
{
int iSrcOffset = 0;
GPtrDiff_t iSrcOffset = 0;
if( !GWKCheckAndComputeSrcOffsets(pabSuccess, iDstX, padfX, padfY,
poWK, nSrcXSize, nSrcYSize, iSrcOffset) )
continue;
......@@ -4842,7 +4843,7 @@ static void GWKGeneralCaseThread( void* pData)
/* ==================================================================== */
bool bHasFoundDensity = false;
const int iDstOffset = iDstX + iDstY * nDstXSize;
const GPtrDiff_t iDstOffset = iDstX + static_cast<GPtrDiff_t>(iDstY) * nDstXSize;
for( int iBand = 0; iBand < poWK->nBands; iBand++ )
{
double dfBandDensity = 0.0;
......@@ -5038,7 +5039,7 @@ static void GWKRealCaseThread( void* pData)
/* ==================================================================== */
for( int iDstX = 0; iDstX < nDstXSize; iDstX++ )
{
int iSrcOffset = 0;
GPtrDiff_t iSrcOffset = 0;
if( !GWKCheckAndComputeSrcOffsets(pabSuccess, iDstX, padfX, padfY,
poWK, nSrcXSize, nSrcYSize, iSrcOffset) )
continue;
......@@ -5067,7 +5068,7 @@ static void GWKRealCaseThread( void* pData)
/* ==================================================================== */
bool bHasFoundDensity = false;
const int iDstOffset = iDstX + iDstY * nDstXSize;
const GPtrDiff_t iDstOffset = iDstX + static_cast<GPtrDiff_t>(iDstY) * nDstXSize;
for( int iBand = 0; iBand < poWK->nBands; iBand++ )
{
double dfBandDensity = 0.0;
......@@ -5286,7 +5287,7 @@ static void GWKResampleNoMasksOrDstDensityOnlyThreadInternal( void* pData )
/* ==================================================================== */
for( int iDstX = 0; iDstX < nDstXSize; iDstX++ )
{
int iSrcOffset = 0;
GPtrDiff_t iSrcOffset = 0;
if( !GWKCheckAndComputeSrcOffsets(pabSuccess, iDstX, padfX, padfY,
poWK, nSrcXSize, nSrcYSize,
iSrcOffset) )
......@@ -5295,7 +5296,7 @@ static void GWKResampleNoMasksOrDstDensityOnlyThreadInternal( void* pData )
/* ==================================================================== */
/* Loop processing each band. */
/* ==================================================================== */
const int iDstOffset = iDstX + iDstY * nDstXSize;
const GPtrDiff_t iDstOffset = iDstX + static_cast<GPtrDiff_t>(iDstY) * nDstXSize;
for( int iBand = 0; iBand < poWK->nBands; iBand++ )
{
......@@ -5503,7 +5504,7 @@ static void GWKNearestThread( void* pData )
/* ==================================================================== */
for( int iDstX = 0; iDstX < nDstXSize; iDstX++ )
{
int iSrcOffset = 0;
GPtrDiff_t iSrcOffset = 0;
if( !GWKCheckAndComputeSrcOffsets(pabSuccess, iDstX, padfX, padfY,
poWK, nSrcXSize, nSrcYSize, iSrcOffset) )
continue;
......@@ -5532,7 +5533,7 @@ static void GWKNearestThread( void* pData )
/* Loop processing each band. */
/* ==================================================================== */
const int iDstOffset = iDstX + iDstY * nDstXSize;
const GPtrDiff_t iDstOffset = iDstX + static_cast<GPtrDiff_t>(iDstY) * nDstXSize;
for( int iBand = 0; iBand < poWK->nBands; iBand++ )
{
......@@ -5901,13 +5902,13 @@ static void GWKAverageOrModeThread( void* pData)
/* ==================================================================== */
for( int iDstX = 0; iDstX < nDstXSize; iDstX++ )
{
int iSrcOffset = 0;
GPtrDiff_t iSrcOffset = 0;
double dfDensity = 1.0;
bool bHasFoundDensity = false;
if( !pabSuccess[iDstX] || !pabSuccess2[iDstX] )
continue;
const int iDstOffset = iDstX + iDstY * nDstXSize;
const GPtrDiff_t iDstOffset = iDstX + static_cast<GPtrDiff_t>(iDstY) * nDstXSize;
/* ==================================================================== */
/* Loop processing each band. */
......@@ -5970,7 +5971,7 @@ static void GWKAverageOrModeThread( void* pData)
{
for( int iSrcX = iSrcXMin; iSrcX < iSrcXMax; iSrcX++ )
{
iSrcOffset = iSrcX + iSrcY * nSrcXSize;
iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * nSrcXSize;
if( poWK->panUnifiedSrcValid != nullptr
&& !(poWK->panUnifiedSrcValid[iSrcOffset>>5]
......@@ -6028,7 +6029,7 @@ static void GWKAverageOrModeThread( void* pData)
iSrcX < iSrcXMax;
iSrcX++ )
{
iSrcOffset = iSrcX + iSrcY * nSrcXSize;
iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * nSrcXSize;
if( poWK->panUnifiedSrcValid != nullptr
&& !(poWK->panUnifiedSrcValid[iSrcOffset>>5]
......@@ -6091,7 +6092,7 @@ static void GWKAverageOrModeThread( void* pData)
iSrcX < iSrcXMax;
iSrcX++ )
{
iSrcOffset = iSrcX + iSrcY * nSrcXSize;
iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * nSrcXSize;
if( poWK->panUnifiedSrcValid != nullptr
&& !(poWK->panUnifiedSrcValid[iSrcOffset>>5]
......@@ -6137,7 +6138,7 @@ static void GWKAverageOrModeThread( void* pData)
{
for( int iSrcX = iSrcXMin; iSrcX < iSrcXMax; iSrcX++ )
{
iSrcOffset = iSrcX + iSrcY * nSrcXSize;
iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * nSrcXSize;
if( poWK->panUnifiedSrcValid != nullptr
&& !(poWK->panUnifiedSrcValid[iSrcOffset>>5]
......@@ -6178,7 +6179,7 @@ static void GWKAverageOrModeThread( void* pData)
{
for( int iSrcX = iSrcXMin; iSrcX < iSrcXMax; iSrcX++ )
{
iSrcOffset = iSrcX + iSrcY * nSrcXSize;
iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * nSrcXSize;
if( poWK->panUnifiedSrcValid != nullptr
&& !(poWK->panUnifiedSrcValid[iSrcOffset>>5]
......@@ -6220,7 +6221,7 @@ static void GWKAverageOrModeThread( void* pData)
{
for( int iSrcX = iSrcXMin; iSrcX < iSrcXMax; iSrcX++ )
{
iSrcOffset = iSrcX + iSrcY * nSrcXSize;
iSrcOffset = iSrcX + static_cast<GPtrDiff_t>(iSrcY) * nSrcXSize;
if( poWK->panUnifiedSrcValid != nullptr
&& !(poWK->panUnifiedSrcValid[iSrcOffset>>5]
......
......@@ -53,7 +53,7 @@
#include "ogr_api.h"
#include "ogr_core.h"
CPL_CVSID("$Id: gdalwarpoperation.cpp d16ecc80707f9c7097a11bfe47c8403bb9df310f 2018-07-27 20:14:48 -0700 piyush.agram@jpl.nasa.gov $")
CPL_CVSID("$Id: gdalwarpoperation.cpp cde29aa7b4807045c418e469b59b60f92af59468 2019-02-18 15:49:24 +0100 Even Rouault $")
struct _GDALWarpChunk {
int dx, dy, dsx, dsy;
......@@ -646,23 +646,13 @@ void* GDALWarpOperation::CreateDestinationBuffer(
/* for this block. */
/* -------------------------------------------------------------------- */
const int nWordSize = GDALGetDataTypeSizeBytes(psOptions->eWorkingDataType);
const int nBandSize = nWordSize * nDstXSize * nDstYSize;
const int knIntMax = std::numeric_limits<int>::max();
if( nDstXSize > knIntMax / nDstYSize ||
nDstXSize * nDstYSize > knIntMax / (nWordSize * psOptions->nBandCount) )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Integer overflow : nDstXSize=%d, nDstYSize=%d",
nDstXSize, nDstYSize);
return nullptr;
}
void *pDstBuffer = VSI_MALLOC_VERBOSE( nBandSize * psOptions->nBandCount );
void *pDstBuffer = VSI_MALLOC3_VERBOSE( nWordSize * psOptions->nBandCount, nDstXSize, nDstYSize );
if( pDstBuffer == nullptr )
{
return nullptr;
}
const GPtrDiff_t nBandSize = static_cast<GPtrDiff_t>(nWordSize) * nDstXSize * nDstYSize;
/* -------------------------------------------------------------------- */
/* Initialize if requested in the options */
......@@ -729,17 +719,17 @@ void* GDALWarpOperation::CreateDestinationBuffer(
}
else if( !CPLIsNan(adfInitRealImag[1]) && adfInitRealImag[1] == 0.0 )
{
GDALCopyWords( &adfInitRealImag, GDT_Float64, 0,
GDALCopyWords64( &adfInitRealImag, GDT_Float64, 0,
pBandData, psOptions->eWorkingDataType,
nWordSize,
nDstXSize * nDstYSize );
static_cast<GPtrDiff_t>(nDstXSize) * nDstYSize );
}
else
{
GDALCopyWords( &adfInitRealImag, GDT_CFloat64, 0,
GDALCopyWords64( &adfInitRealImag, GDT_CFloat64, 0,
pBandData, psOptions->eWorkingDataType,
nWordSize,
nDstXSize * nDstYSize );
static_cast<GPtrDiff_t>(nDstXSize) * nDstYSize );
}
}
......@@ -1817,23 +1807,22 @@ CPLErr GDALWarpOperation::WarpRegionToBuffer(
oWK.dfSrcXExtraSize = dfSrcXExtraSize;
oWK.dfSrcYExtraSize = dfSrcYExtraSize;
const int knIntMax = std::numeric_limits<int>::max();
if( nSrcXSize != 0 && nSrcYSize != 0 &&
(nSrcXSize > knIntMax / nSrcYSize ||
nSrcXSize * nSrcYSize >
knIntMax / (nWordSize * psOptions->nBandCount) - WARP_EXTRA_ELTS) )
GInt64 nAlloc64 = nWordSize * (static_cast<GInt64>(nSrcXSize) * nSrcYSize + WARP_EXTRA_ELTS)
* psOptions->nBandCount;
#if SIZEOF_VOIDP == 4
if( nAlloc64 != static_cast<GInt64>(static_cast<size_t>(nAlloc64)) )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Integer overflow : nSrcXSize=%d, nSrcYSize=%d",
nSrcXSize, nSrcYSize);
return CE_Failure;
}
#endif
oWK.papabySrcImage = static_cast<GByte **>(
CPLCalloc(sizeof(GByte*), psOptions->nBandCount));
oWK.papabySrcImage[0] = static_cast<GByte *>(
VSI_MALLOC_VERBOSE(nWordSize * (nSrcXSize * nSrcYSize + WARP_EXTRA_ELTS)
* psOptions->nBandCount));
VSI_MALLOC_VERBOSE(static_cast<size_t>(nAlloc64)));
CPLErr eErr =
nSrcXSize != 0 && nSrcYSize != 0 && oWK.papabySrcImage[0] == nullptr
......@@ -1843,7 +1832,7 @@ CPLErr GDALWarpOperation::WarpRegionToBuffer(
for( int i = 0; i < psOptions->nBandCount && eErr == CE_None; i++ )
oWK.papabySrcImage[i] = reinterpret_cast<GByte *>(oWK.papabySrcImage[0])
+ nWordSize * (nSrcXSize * nSrcYSize + WARP_EXTRA_ELTS) * i;
+ nWordSize * (static_cast<GPtrDiff_t>(nSrcXSize) * nSrcYSize + WARP_EXTRA_ELTS) * i;
if( eErr == CE_None && nSrcXSize > 0 && nSrcYSize > 0 )
{
......@@ -1866,7 +1855,7 @@ CPLErr GDALWarpOperation::WarpRegionToBuffer(
oWK.papabySrcImage[0], nSrcXSize, nSrcYSize,
psOptions->eWorkingDataType,
psOptions->nBandCount, psOptions->panSrcBands,
0, 0, nWordSize * (nSrcXSize * nSrcYSize + WARP_EXTRA_ELTS),
0, 0, nWordSize * (static_cast<GPtrDiff_t>(nSrcXSize) * nSrcYSize + WARP_EXTRA_ELTS),
nullptr );
}
}
......@@ -1888,7 +1877,7 @@ CPLErr GDALWarpOperation::WarpRegionToBuffer(
for( ; i1 < psOptions->nBandCount && eErr == CE_None; i1++ )
{
oWK.papabyDstImage[i1] = static_cast<GByte *>(pDataBuf)
+ i1 * nDstXSize * nDstYSize * nWordSize;
+ i1 * static_cast<GPtrDiff_t>(nDstXSize) * nDstYSize * nWordSize;
}
/* -------------------------------------------------------------------- */
......@@ -1945,7 +1934,7 @@ CPLErr GDALWarpOperation::WarpRegionToBuffer(
if( eErr == CE_None )
{
for( int j = 0; j < oWK.nSrcXSize * oWK.nSrcYSize; j++ )
for( GPtrDiff_t j = 0; j < static_cast<GPtrDiff_t>(oWK.nSrcXSize) * oWK.nSrcYSize; j++ )
oWK.pafUnifiedSrcDensity[j] = 1.0;
}
}
......@@ -2055,7 +2044,7 @@ CPLErr GDALWarpOperation::WarpRegionToBuffer(
false )
&& eErr == CE_None )
{
const int nBytesInMask = (oWK.nSrcXSize * oWK.nSrcYSize + 31) / 8;
const GPtrDiff_t nBytesInMask = (static_cast<GPtrDiff_t>(oWK.nSrcXSize) * oWK.nSrcYSize + 31) / 8;
eErr = CreateKernelMask( &oWK, i2, "UnifiedSrcValid" );
......@@ -2065,7 +2054,7 @@ CPLErr GDALWarpOperation::WarpRegionToBuffer(
for( int k = 0; k < psOptions->nBandCount; k++ )
{
for( int iWord = nBytesInMask/4 - 1; iWord >= 0; iWord-- )
for( GPtrDiff_t iWord = nBytesInMask/4 - 1; iWord >= 0; iWord-- )
oWK.panUnifiedSrcValid[iWord] |=
oWK.papanBandSrcValid[k][iWord];
CPLFree( oWK.papanBandSrcValid[k] );
......@@ -2124,7 +2113,7 @@ CPLErr GDALWarpOperation::WarpRegionToBuffer(
{
CPLAssert( oWK.panDstValid == nullptr );
const int nMaskWords = (oWK.nDstXSize * oWK.nDstYSize + 31)/32;
const GPtrDiff_t nMaskWords = (static_cast<GPtrDiff_t>(oWK.nDstXSize) * oWK.nDstYSize + 31)/32;
eErr = CreateKernelMask( &oWK, 0, "DstValid" );
GUInt32 *panBandMask =
......@@ -2168,7 +2157,7 @@ CPLErr GDALWarpOperation::WarpRegionToBuffer(
break;
}
for( int iWord = nMaskWords - 1; iWord >= 0; iWord-- )
for( GPtrDiff_t iWord = nMaskWords - 1; iWord >= 0; iWord-- )
oWK.panDstValid[iWord] |= panBandMask[iWord];
}
CPLFree( panBandMask );
......