GDAL
gdal_cpp_functions.h
1/******************************************************************************
2 *
3 * Name: gdal_cpp_functions.h
4 * Project: GDAL Core
5 * Purpose: Declaration of various semi-primate C++ functions
6 * Author: Frank Warmerdam, warmerdam@pobox.com
7 *
8 ******************************************************************************
9 * Copyright (c) 1998, Frank Warmerdam
10 * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
11 *
12 * SPDX-License-Identifier: MIT
13 ****************************************************************************/
14
15#ifndef GDAL_CPP_FUNCTIONS_H_INCLUDED
16#define GDAL_CPP_FUNCTIONS_H_INCLUDED
17
18#include "cpl_port.h"
19#include "cpl_error.h"
20#include "cpl_progress.h"
21#include "cpl_string.h"
22
23#include "gdal.h"
24#include "gdal_gcp.h"
25#include "gdal_geotransform.h"
26
27#include <cstddef>
28#include <limits>
29#include <memory>
30#include <utility>
31#include <vector>
32
33typedef struct _CPLMutex CPLMutex;
34
35class GDALColorTable;
36class GDALDataset;
37class GDALDriver;
38class GDALMDArray;
40class GDALRasterBand;
42
43/* ==================================================================== */
44/* An assortment of overview related stuff. */
45/* ==================================================================== */
46
48/* Only exported for drivers as plugin. Signature may change */
49CPLErr CPL_DLL GDALRegenerateOverviewsMultiBand(
50 int nBands, GDALRasterBand *const *papoSrcBands, int nOverviews,
51 GDALRasterBand *const *const *papapoOverviewBands,
52 const char *pszResampling, GDALProgressFunc pfnProgress,
53 void *pProgressData, CSLConstList papszOptions);
54
55CPLErr CPL_DLL GDALRegenerateOverviewsMultiBand(
56 const std::vector<GDALRasterBand *> &apoSrcBands,
57 // First level of array is indexed by band (thus aapoOverviewBands.size() must be equal to apoSrcBands.size())
58 // Second level is indexed by overview
59 const std::vector<std::vector<GDALRasterBand *>> &aapoOverviewBands,
60 const char *pszResampling, GDALProgressFunc pfnProgress,
61 void *pProgressData, CSLConstList papszOptions);
62
63/************************************************************************/
64/* GDALOverviewResampleArgs */
65/************************************************************************/
66
68// Should not contain any dataset/rasterband object, as this might be
69// read in a worker thread.
70struct GDALOverviewResampleArgs
71{
73 GDALDataType eSrcDataType = GDT_Unknown;
75 GDALDataType eOvrDataType = GDT_Unknown;
77 int nOvrXSize = 0;
79 int nOvrYSize = 0;
81 int nOvrNBITS = 0;
83 // (source width divided by destination width)
84 double dfXRatioDstToSrc = 0;
86 // (source height divided by destination height)
87 double dfYRatioDstToSrc = 0;
89 double dfSrcXDelta = 0;
91 double dfSrcYDelta = 0;
93 GDALDataType eWrkDataType = GDT_Unknown;
95 const GByte *pabyChunkNodataMask = nullptr;
97 int nChunkXOff = 0;
99 int nChunkXSize = 0;
101 int nChunkYOff = 0;
103 int nChunkYSize = 0;
105 int nDstXOff = 0;
107 int nDstXOff2 = 0;
109 int nDstYOff = 0;
111 int nDstYOff2 = 0;
113 const char *pszResampling = nullptr;
115 bool bHasNoData = false;
117 double dfNoDataValue = 0;
119 const GDALColorTable *poColorTable = nullptr;
121 // in the target pixel to be at nodata too (only taken into account by
122 // average resampling)
123 bool bPropagateNoData = false;
124};
125
126typedef CPLErr (*GDALResampleFunction)(const GDALOverviewResampleArgs &args,
127 const void *pChunk, void **ppDstBuffer,
128 GDALDataType *peDstBufferDataType);
129
130GDALResampleFunction GDALGetResampleFunction(const char *pszResampling,
131 int *pnRadius);
132
133std::string CPL_DLL GDALGetNormalizedOvrResampling(const char *pszResampling);
134
135GDALDataType GDALGetOvrWorkDataType(const char *pszResampling,
136 GDALDataType eSrcDataType);
137
139
140CPLErr CPL_DLL
141HFAAuxBuildOverviews(const char *pszOvrFilename, GDALDataset *poParentDS,
142 GDALDataset **ppoDS, int nBands, const int *panBandList,
143 int nNewOverviews, const int *panNewOverviewList,
144 const char *pszResampling, GDALProgressFunc pfnProgress,
145 void *pProgressData, CSLConstList papszOptions);
146
147CPLErr CPL_DLL GTIFFBuildOverviews(const char *pszFilename, int nBands,
148 GDALRasterBand *const *papoBandList,
149 int nOverviews, const int *panOverviewList,
150 const char *pszResampling,
151 GDALProgressFunc pfnProgress,
152 void *pProgressData,
153 CSLConstList papszOptions);
154
155CPLErr CPL_DLL GTIFFBuildOverviewsEx(const char *pszFilename, int nBands,
156 GDALRasterBand *const *papoBandList,
157 int nOverviews, const int *panOverviewList,
158 const std::pair<int, int> *pasOverviewSize,
159 const char *pszResampling,
160 const char *const *papszOptions,
161 GDALProgressFunc pfnProgress,
162 void *pProgressData);
163
164int CPL_DLL GDALBandGetBestOverviewLevel(GDALRasterBand *poBand, int &nXOff,
165 int &nYOff, int &nXSize, int &nYSize,
166 int nBufXSize, int nBufYSize)
167 CPL_WARN_DEPRECATED("Use GDALBandGetBestOverviewLevel2 instead");
168int CPL_DLL GDALBandGetBestOverviewLevel2(GDALRasterBand *poBand, int &nXOff,
169 int &nYOff, int &nXSize, int &nYSize,
170 int nBufXSize, int nBufYSize,
171 GDALRasterIOExtraArg *psExtraArg);
172
173int CPL_DLL GDALOvLevelAdjust(int nOvLevel, int nXSize)
174 CPL_WARN_DEPRECATED("Use GDALOvLevelAdjust2 instead");
175int CPL_DLL GDALOvLevelAdjust2(int nOvLevel, int nXSize, int nYSize);
176int CPL_DLL GDALComputeOvFactor(int nOvrXSize, int nRasterXSize, int nOvrYSize,
177 int nRasterYSize);
178
179GDALDataset CPL_DLL *GDALFindAssociatedAuxFile(const char *pszBasefile,
180 GDALAccess eAccess,
181 GDALDataset *poDependentDS);
182
183/* ==================================================================== */
184/* Infrastructure to check that dataset characteristics are valid */
185/* ==================================================================== */
186
187int CPL_DLL GDALCheckDatasetDimensions(int nXSize, int nYSize);
188int CPL_DLL GDALCheckBandCount(int nBands, int bIsZeroAllowed);
189
190/* Internal use only */
191
192/* CPL_DLL exported, but only for in-tree drivers that can be built as plugins
193 */
194int CPL_DLL GDALReadWorldFile2(const char *pszBaseFilename,
195 const char *pszExtension,
196 double *padfGeoTransform,
197 CSLConstList papszSiblingFiles,
198 char **ppszWorldFileNameOut);
199int CPL_DLL GDALReadTabFile2(const char *pszBaseFilename,
200 double *padfGeoTransform, char **ppszWKT,
201 int *pnGCPCount, GDAL_GCP **ppasGCPs,
202 CSLConstList papszSiblingFiles,
203 char **ppszTabFileNameOut);
204
205void CPL_DLL GDALCopyRasterIOExtraArg(GDALRasterIOExtraArg *psDestArg,
206 GDALRasterIOExtraArg *psSrcArg);
207
208void CPL_DLL GDALExpandPackedBitsToByteAt0Or1(
209 const GByte *CPL_RESTRICT pabyInput, GByte *CPL_RESTRICT pabyOutput,
210 size_t nInputBits);
211
212void CPL_DLL GDALExpandPackedBitsToByteAt0Or255(
213 const GByte *CPL_RESTRICT pabyInput, GByte *CPL_RESTRICT pabyOutput,
214 size_t nInputBits);
215
217
218int CPL_DLL GDALReadWorldFile2(const char *pszBaseFilename,
219 const char *pszExtension, GDALGeoTransform &gt,
220 CSLConstList papszSiblingFiles,
221 char **ppszWorldFileNameOut);
222
223std::unique_ptr<GDALDataset> CPL_DLL
224GDALGetThreadSafeDataset(std::unique_ptr<GDALDataset> poDS, int nScopeFlags);
225
227 int nScopeFlags);
228
229void GDALNullifyOpenDatasetsList();
230CPLMutex **GDALGetphDMMutex();
231CPLMutex **GDALGetphDLMutex();
232void GDALNullifyProxyPoolSingleton();
233void GDALSetResponsiblePIDForCurrentThread(GIntBig responsiblePID);
234GIntBig GDALGetResponsiblePIDForCurrentThread();
235
236CPLString GDALFindAssociatedFile(const char *pszBasename, const char *pszExt,
237 CSLConstList papszSiblingFiles, int nFlags);
238
239CPLErr CPL_DLL EXIFExtractMetadata(char **&papszMetadata, void *fpL,
240 int nOffset, int bSwabflag, int nTIFFHEADER,
241 int &nExifOffset, int &nInterOffset,
242 int &nGPSOffset);
243
244int GDALValidateOpenOptions(GDALDriverH hDriver,
245 const char *const *papszOptionOptions);
246int GDALValidateOptions(const char *pszOptionList,
247 const char *const *papszOptionsToValidate,
248 const char *pszErrorMessageOptionType,
249 const char *pszErrorMessageContainerName);
250
251GDALRIOResampleAlg CPL_DLL
252GDALRasterIOGetResampleAlg(const char *pszResampling);
253const char *GDALRasterIOGetResampleAlg(GDALRIOResampleAlg eResampleAlg);
254
255void GDALRasterIOExtraArgSetResampleAlg(GDALRasterIOExtraArg *psExtraArg,
256 int nXSize, int nYSize, int nBufXSize,
257 int nBufYSize);
258
259GDALDataset *GDALCreateOverviewDataset(GDALDataset *poDS, int nOvrLevel,
260 bool bThisLevelOnly);
261
262// Should cover particular cases of #3573, #4183, #4506, #6578
263// Behavior is undefined if fVal1 or fVal2 are NaN (should be tested before
264// calling this function)
265
266// TODO: The expression `abs(fVal1 + fVal2)` looks strange; is this a bug?
267// Should this be `abs(fVal1) + abs(fVal2)` instead?
268
269inline bool ARE_REAL_EQUAL(float fVal1, float fVal2, int ulp = 2)
270{
271 using std::abs;
272 return fVal1 == fVal2 || /* Should cover infinity */
273 abs(fVal1 - fVal2) <
274 std::numeric_limits<float>::epsilon() * abs(fVal1 + fVal2) * ulp;
275}
276
277// We are using `std::numeric_limits<float>::epsilon()` for backward
278// compatibility
279inline bool ARE_REAL_EQUAL(double dfVal1, double dfVal2, int ulp = 2)
280{
281 using std::abs;
282 return dfVal1 == dfVal2 || /* Should cover infinity */
283 abs(dfVal1 - dfVal2) <
284 static_cast<double>(std::numeric_limits<float>::epsilon()) *
285 abs(dfVal1 + dfVal2) * ulp;
286}
287
288double GDALAdjustNoDataCloseToFloatMax(double dfVal);
289
290#define DIV_ROUND_UP(a, b) (((a) % (b)) == 0 ? ((a) / (b)) : (((a) / (b)) + 1))
291
292// Number of data samples that will be used to compute approximate statistics
293// (minimum value, maximum value, etc.)
294#define GDALSTAT_APPROX_NUMSAMPLES 2500
295
296void GDALSerializeGCPListToXML(CPLXMLNode *psParentNode,
297 const std::vector<gdal::GCP> &asGCPs,
298 const OGRSpatialReference *poGCP_SRS);
299void GDALDeserializeGCPListFromXML(const CPLXMLNode *psGCPList,
300 std::vector<gdal::GCP> &asGCPs,
301 OGRSpatialReference **ppoGCP_SRS);
302
303void GDALSerializeOpenOptionsToXML(CPLXMLNode *psParentNode,
304 CSLConstList papszOpenOptions);
305char CPL_DLL **
306GDALDeserializeOpenOptionsFromXML(const CPLXMLNode *psParentNode);
307
308int GDALCanFileAcceptSidecarFile(const char *pszFilename);
309
310bool GDALCanReliablyUseSiblingFileList(const char *pszFilename);
311
312typedef enum
313{
314 GSF_UNSIGNED_INT,
315 GSF_SIGNED_INT,
316 GSF_FLOATING_POINT,
317} GDALBufferSampleFormat;
318
319bool CPL_DLL GDALBufferHasOnlyNoData(const void *pBuffer, double dfNoDataValue,
320 size_t nWidth, size_t nHeight,
321 size_t nLineStride, size_t nComponents,
322 int nBitsPerSample,
323 GDALBufferSampleFormat nSampleFormat);
324
325bool CPL_DLL GDALCopyNoDataValue(GDALRasterBand *poDstBand,
326 GDALRasterBand *poSrcBand,
327 bool *pbCannotBeExactlyRepresented = nullptr);
328
329double CPL_DLL GDALGetNoDataValueCastToDouble(int64_t nVal);
330double CPL_DLL GDALGetNoDataValueCastToDouble(uint64_t nVal);
331
332// Remove me in GDAL 4.0. See GetMetadataItem() implementation
333// Internal use in GDAL only !
334// Declaration copied in swig/include/gdal.i
335void CPL_DLL GDALEnablePixelTypeSignedByteWarning(GDALRasterBandH hBand,
336 bool b);
337
338std::string CPL_DLL GDALGetCompressionFormatForJPEG(VSILFILE *fp);
339std::string CPL_DLL GDALGetCompressionFormatForJPEG(const void *pBuffer,
340 size_t nBufferSize);
341
343 GDALRATTableType eTableType,
344 const std::vector<std::shared_ptr<GDALMDArray>> &apoArrays,
345 const std::vector<GDALRATFieldUsage> &aeUsages);
346
347GDALColorInterp CPL_DLL
348GDALGetColorInterpFromSTACCommonName(const char *pszName);
349const char CPL_DLL *
350GDALGetSTACCommonNameFromColorInterp(GDALColorInterp eInterp);
351
352std::string CPL_DLL GDALGetCacheDirectory();
353
354bool GDALDoesFileOrDatasetExist(const char *pszName,
355 const char **ppszType = nullptr,
356 GDALDriver **ppDriver = nullptr);
357
358std::string CPL_DLL
359GDALGetMessageAboutMissingPluginDriver(GDALDriver *poMissingPluginDriver);
360
361std::string GDALPrintDriverList(int nOptions, bool bJSON);
362
363struct GDALColorAssociation
364{
365 double dfVal;
366 int nR;
367 int nG;
368 int nB;
369 int nA;
370};
371
372std::vector<GDALColorAssociation> GDALLoadTextColorMap(const char *pszFilename,
373 GDALRasterBand *poBand);
374
375namespace GDAL
376{
377inline CPLErr Combine(CPLErr eErr1, CPLErr eErr2)
378{
379 return eErr1 == CE_None ? eErr2 : eErr1;
380}
381
382inline CPLErr Combine(CPLErr eErr1, int) = delete;
383
384inline CPLErr Combine(CPLErr eErr1, bool b)
385{
386 return eErr1 == CE_None ? (b ? CE_None : CE_Failure) : eErr1;
387}
388
389} // namespace GDAL
390
392
393#endif
Convenient string class based on std::string.
Definition cpl_string.h:320
A color table / palette.
Definition gdal_colortable.h:32
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:76
Format specific driver.
Definition gdal_driver.h:63
Class that encapsulates a geotransform matrix.
Definition gdal_geotransform.h:42
Class modeling a multi-dimensional array.
Definition gdal_multidim.h:852
The GDALRasterAttributeTable (or RAT) class is used to encapsulate a table used to provide attribute ...
Definition gdal_rat.h:48
A single raster band (or channel).
Definition gdal_rasterband.h:105
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:152
CPL error handling services.
CPLErr
Error category.
Definition cpl_error.h:37
Core portability definitions for CPL.
#define CPL_RESTRICT
restrict keyword to declare that pointers do not alias
Definition cpl_port.h:916
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:289
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:285
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1087
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:175
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:205
Various convenience functions for working with strings and string lists.
struct VSIVirtualHandle VSILFILE
Opaque type for a FILE that implements the VSIVirtualHandle API.
Definition cpl_vsi.h:141
Public (C callable) GDAL entry points.
GDALRATTableType
RAT table type (thematic or athematic).
Definition gdal.h:2263
GDALAccess
Definition gdal.h:118
GDALDataType
Definition gdal.h:48
@ GDT_Unknown
Definition gdal.h:49
GDALRasterAttributeTableH GDALCreateRasterAttributeTableFromMDArrays(GDALRATTableType eTableType, int nArrays, const GDALMDArrayH *ahArrays, const GDALRATFieldUsage *paeUsages)
Return a virtual Raster Attribute Table from several GDALMDArray's.
Definition gdalmultidim_rat.cpp:511
GDALRIOResampleAlg
RasterIO() resampling method.
Definition gdal.h:135
GDALDatasetH GDALGetThreadSafeDataset(GDALDatasetH, int nScopeFlags, CSLConstList papszOptions)
Return a thread-safe dataset.
Definition gdalthreadsafedataset.cpp:1285
GDALColorInterp
Types of color interpretation for raster bands.
Definition gdal.h:270
void * GDALDriverH
Opaque type used for the C bindings of the C++ GDALDriver class.
Definition gdal_fwd.h:51
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal_fwd.h:45
Document node structure.
Definition cpl_minixml.h:54
Structure to pass extra arguments to RasterIO() method, must be initialized with INIT_RASTERIO_EXTRA_...
Definition gdal.h:168
Ground Control Point.
Definition gdal.h:1221