GDAL

gdalpansharpen.h
Go to the documentation of this file.
1/******************************************************************************
2 * $Id$
3 *
4 * Project: GDAL Pansharpening module
5 * Purpose: Prototypes, and definitions for pansharpening related work.
6 * Author: Even Rouault <even.rouault at spatialys.com>
7 *
8 ******************************************************************************
9 * Copyright (c) 2015, Even Rouault <even.rouault at spatialys.com>
10 *
11 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14#ifndef GDALPANSHARPEN_H_INCLUDED
15#define GDALPANSHARPEN_H_INCLUDED
16
17#include "gdal.h"
18
19 CPL_C_START
20
30 typedef enum
31{
33 GDAL_PSH_WEIGHTED_BROVEY
34} GDALPansharpenAlg;
35
38 typedef struct
39{
41 GDALPansharpenAlg ePansharpenAlg;
42
45 GDALRIOResampleAlg eResampleAlg;
46
49 int nBitDepth;
50
52 int nWeightCount;
53
55 double *padfWeights;
56
58 GDALRasterBandH hPanchroBand;
59
61 int nInputSpectralBands;
62
69 GDALRasterBandH *pahInputSpectralBands;
70
72 int nOutPansharpenedBands;
73
76 int *panOutPansharpenedBands;
77
79 int bHasNoData;
80
84 double dfNoData;
85
89 int nThreads;
90} GDALPansharpenOptions;
91
92 GDALPansharpenOptions CPL_DLL *GDALCreatePansharpenOptions(void);
93 void CPL_DLL GDALDestroyPansharpenOptions(GDALPansharpenOptions *);
94 GDALPansharpenOptions CPL_DLL *
95 GDALClonePansharpenOptions(const GDALPansharpenOptions *psOptions);
96
98 typedef void *GDALPansharpenOperationH;
99
100 GDALPansharpenOperationH CPL_DLL
101 GDALCreatePansharpenOperation(const GDALPansharpenOptions *);
102 void CPL_DLL GDALDestroyPansharpenOperation(GDALPansharpenOperationH);
103 CPLErr CPL_DLL GDALPansharpenProcessRegion(GDALPansharpenOperationH hOperation,
104 int nXOff, int nYOff, int nXSize,
105 int nYSize, void *pDataBuf,
106 GDALDataType eBufDataType);
107
108 CPL_C_END
109
110#ifdef __cplusplus
111
112#include <array>
113#include <vector>
114#include "gdal_priv.h"
115
116#ifdef DEBUG_TIMING
117#include <sys/time.h>
118#endif
119
120 class GDALPansharpenOperation;
121
123 typedef struct
124{
125 GDALPansharpenOperation *poPansharpenOperation;
126 GDALDataType eWorkDataType;
127 GDALDataType eBufDataType;
128 const void *pPanBuffer;
129 const void *pUpsampledSpectralBuffer;
130 void *pDataBuf;
131 size_t nValues;
132 size_t nBandValues;
133 GUInt32 nMaxValue;
134
135#ifdef DEBUG_TIMING
136 struct timeval *ptv;
137#endif
138
139 CPLErr eErr;
140} GDALPansharpenJob;
141
142 struct GDALPansharpenResampleJob
143{
144 GDALDataset *poMEMDS = nullptr;
145 int nXOff = 0;
146 int nYOff = 0;
147 int nXSize = 0;
148 int nYSize = 0;
149 double dfXOff = 0;
150 double dfYOff = 0;
151 double dfXSize = 0;
152 double dfYSize = 0;
153 void *pBuffer = nullptr;
154 GDALDataType eDT = GDT_Unknown;
155 int nBufXSize = 0;
156 int nBufYSize = 0;
157 int nBandCount = 0;
158 GDALRIOResampleAlg eResampleAlg = GRIORA_NearestNeighbour;
159 GSpacing nBandSpace = 0;
160
161#ifdef DEBUG_TIMING
162 struct timeval *ptv = nullptr;
163#endif
164
165 CPLErr eErr = CE_Failure;
166 std::string osLastErrorMsg{};
167};
168
169 class CPLWorkerThreadPool;
170
172
175 class GDALPansharpenOperation
176{
177 CPL_DISALLOW_COPY_ASSIGN(GDALPansharpenOperation)
178
179 GDALPansharpenOptions *psOptions = nullptr;
180 std::vector<int> anInputBands{};
181 std::vector<GDALDataset *> aVDS{}; // to destroy
182 std::vector<GDALRasterBand *> aMSBands{}; // original multispectral bands
183 // potentially warped into a VRT
184 int bPositiveWeights = TRUE;
185 CPLWorkerThreadPool *poThreadPool = nullptr;
186 int nKernelRadius = 0;
187 GDALGeoTransform m_panToMSGT{};
188
189 static void PansharpenJobThreadFunc(void *pUserData);
190 static void PansharpenResampleJobThreadFunc(void *pUserData);
191
192 template <class WorkDataType, class OutDataType>
193 void WeightedBroveyWithNoData(const WorkDataType *pPanBuffer,
194 const WorkDataType *pUpsampledSpectralBuffer,
195 OutDataType *pDataBuf, size_t nValues,
196 size_t nBandValues,
197 WorkDataType nMaxValue) const;
198 template <class WorkDataType, class OutDataType, int bHasBitDepth>
199 void WeightedBrovey3(const WorkDataType *pPanBuffer,
200 const WorkDataType *pUpsampledSpectralBuffer,
201 OutDataType *pDataBuf, size_t nValues,
202 size_t nBandValues, WorkDataType nMaxValue) const;
203
204 // cppcheck-suppress functionStatic
205 template <class WorkDataType, class OutDataType>
206 void WeightedBrovey(const WorkDataType *pPanBuffer,
207 const WorkDataType *pUpsampledSpectralBuffer,
208 OutDataType *pDataBuf, size_t nValues,
209 size_t nBandValues, WorkDataType nMaxValue) const;
210 template <class WorkDataType>
211 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
212 const WorkDataType *pUpsampledSpectralBuffer,
213 void *pDataBuf, GDALDataType eBufDataType,
214 size_t nValues, size_t nBandValues,
215 WorkDataType nMaxValue) const;
216
217 // cppcheck-suppress functionStatic
218 template <class WorkDataType>
219 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
220 const WorkDataType *pUpsampledSpectralBuffer,
221 void *pDataBuf, GDALDataType eBufDataType,
222 size_t nValues, size_t nBandValues) const;
223 template <class T>
224 void WeightedBroveyPositiveWeights(const T *pPanBuffer,
225 const T *pUpsampledSpectralBuffer,
226 T *pDataBuf, size_t nValues,
227 size_t nBandValues, T nMaxValue) const;
228
229 template <class T, int NINPUT, int NOUTPUT>
230 size_t WeightedBroveyPositiveWeightsInternal(
231 const T *pPanBuffer, const T *pUpsampledSpectralBuffer, T *pDataBuf,
232 size_t nValues, size_t nBandValues, T nMaxValue) const;
233
234 // cppcheck-suppress unusedPrivateFunction
235 template <class T>
236 void WeightedBroveyGByteOrUInt16(const T *pPanBuffer,
237 const T *pUpsampledSpectralBuffer,
238 T *pDataBuf, size_t nValues,
239 size_t nBandValues, T nMaxValue) const;
240
241 // cppcheck-suppress functionStatic
242 CPLErr PansharpenChunk(GDALDataType eWorkDataType,
243 GDALDataType eBufDataType, const void *pPanBuffer,
244 const void *pUpsampledSpectralBuffer, void *pDataBuf,
245 size_t nValues, size_t nBandValues,
246 GUInt32 nMaxValue) const;
247
248 public:
249 GDALPansharpenOperation();
250 ~GDALPansharpenOperation();
251
252 CPLErr Initialize(const GDALPansharpenOptions *psOptions);
253 CPLErr ProcessRegion(int nXOff, int nYOff, int nXSize, int nYSize,
254 void *pDataBuf, GDALDataType eBufDataType);
255 GDALPansharpenOptions *GetOptions();
256};
257
258#endif /* __cplusplus */
259
260#endif /* GDALPANSHARPEN_H_INCLUDED */
CPLWorkerThreadPool
Pool of worker threads.
Definition cpl_worker_thread_pool.h:64
GDALDataset
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:76
GDALGeoTransform
Class that encapsulates a geotransform matrix.
Definition gdal_geotransform.h:42
GDALPansharpenOperation
Pansharpening operation class.
Definition gdalpansharpen.h:176
GDALPansharpenOperation::ProcessRegion
CPLErr ProcessRegion(int nXOff, int nYOff, int nXSize, int nYSize, void *pDataBuf, GDALDataType eBufDataType)
Executes a pansharpening operation on a rectangular region of the resulting dataset.
Definition gdalpansharpen.cpp:1162
GDALPansharpenOperation::GDALPansharpenOperation
GDALPansharpenOperation()
Pansharpening operation constructor.
GDALPansharpenOperation::~GDALPansharpenOperation
~GDALPansharpenOperation()
Pansharpening operation destructor.
Definition gdalpansharpen.cpp:153
GDALPansharpenOperation::GetOptions
GDALPansharpenOptions * GetOptions()
Return options.
Definition gdalpansharpen.cpp:1835
GDALPansharpenOperation::Initialize
CPLErr Initialize(const GDALPansharpenOptions *psOptions)
Initialize the pansharpening operation.
Definition gdalpansharpen.cpp:172
CPLErr
CPLErr
Error category.
Definition cpl_error.h:37
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:289
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:285
GUInt32
unsigned int GUInt32
Unsigned int32 type.
Definition cpl_port.h:167
CPL_DISALLOW_COPY_ASSIGN
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
gdal.h
Public (C callable) GDAL entry points.
GSpacing
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:386
GDALDataType
GDALDataType
Definition gdal.h:48
GDT_Unknown
@ GDT_Unknown
Definition gdal.h:49
GDALRIOResampleAlg
GDALRIOResampleAlg
RasterIO() resampling method.
Definition gdal.h:135
GRIORA_NearestNeighbour
@ GRIORA_NearestNeighbour
Definition gdal.h:136
GDALRasterBandH
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal_fwd.h:45
gdal_priv.h
This file is legacy since GDAL 3.12, but will be kept at least in the whole GDAL 3....
GDALPansharpenProcessRegion
CPLErr GDALPansharpenProcessRegion(GDALPansharpenOperationH hOperation, int nXOff, int nYOff, int nXSize, int nYSize, void *pDataBuf, GDALDataType eBufDataType)
Executes a pansharpening operation on a rectangular region of the resulting dataset.
Definition gdalpansharpen.cpp:1907
GDALCreatePansharpenOperation
GDALPansharpenOperationH GDALCreatePansharpenOperation(const GDALPansharpenOptions *)
Instantiate a pansharpening operation.
Definition gdalpansharpen.cpp:1855
GDALPansharpenAlg
GDALPansharpenAlg
Pansharpening algorithms.
Definition gdalpansharpen.h:31
GDAL_PSH_WEIGHTED_BROVEY
@ GDAL_PSH_WEIGHTED_BROVEY
Definition gdalpansharpen.h:33
GDALDestroyPansharpenOptions
void GDALDestroyPansharpenOptions(GDALPansharpenOptions *)
Destroy pansharpening options.
Definition gdalpansharpen.cpp:72
GDALPansharpenOperationH
void * GDALPansharpenOperationH
Definition gdalpansharpen.h:98
GDALCreatePansharpenOptions
GDALPansharpenOptions * GDALCreatePansharpenOptions(void)
Create pansharpening options.
Definition gdalpansharpen.cpp:52
GDALClonePansharpenOptions
GDALPansharpenOptions * GDALClonePansharpenOptions(const GDALPansharpenOptions *psOptions)
Clone pansharpening options.
Definition gdalpansharpen.cpp:96
GDALDestroyPansharpenOperation
void GDALDestroyPansharpenOperation(GDALPansharpenOperationH)
Destroy a pansharpening operation.
Definition gdalpansharpen.cpp:1874
GDALPansharpenOptions
Pansharpening options.
Definition gdalpansharpen.h:39
GDALPansharpenOptions::ePansharpenAlg
GDALPansharpenAlg ePansharpenAlg
Definition gdalpansharpen.h:41
GDALPansharpenOptions::bHasNoData
int bHasNoData
Definition gdalpansharpen.h:79
GDALPansharpenOptions::nBitDepth
int nBitDepth
Definition gdalpansharpen.h:49
GDALPansharpenOptions::padfWeights
double * padfWeights
Definition gdalpansharpen.h:55
GDALPansharpenOptions::nThreads
int nThreads
Number of threads or -1 to mean ALL_CPUS.
Definition gdalpansharpen.h:89
GDALPansharpenOptions::nWeightCount
int nWeightCount
Definition gdalpansharpen.h:52
GDALPansharpenOptions::pahInputSpectralBands
GDALRasterBandH * pahInputSpectralBands
Array of nInputSpectralBands input spectral bands.
Definition gdalpansharpen.h:69
GDALPansharpenOptions::panOutPansharpenedBands
int * panOutPansharpenedBands
Definition gdalpansharpen.h:76
GDALPansharpenOptions::eResampleAlg
GDALRIOResampleAlg eResampleAlg
Definition gdalpansharpen.h:45
GDALPansharpenOptions::hPanchroBand
GDALRasterBandH hPanchroBand
Definition gdalpansharpen.h:58
GDALPansharpenOptions::nInputSpectralBands
int nInputSpectralBands
Definition gdalpansharpen.h:61
GDALPansharpenOptions::nOutPansharpenedBands
int nOutPansharpenedBands
Definition gdalpansharpen.h:72
GDALPansharpenOptions::dfNoData
double dfNoData
NoData value of the panchromatic and spectral bands (only taken into account if bHasNoData = TRUE).
Definition gdalpansharpen.h:84