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 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
28 ****************************************************************************/
29
30#ifndef GDALPANSHARPEN_H_INCLUDED
31#define GDALPANSHARPEN_H_INCLUDED
32
33#include "gdal.h"
34
36
52
117
120GDALPansharpenOptions CPL_DLL *
122
125
130 int nXOff, int nYOff, int nXSize,
131 int nYSize, void *pDataBuf,
132 GDALDataType eBufDataType);
133
135
136#ifdef __cplusplus
137
138#include <vector>
139#include "gdal_priv.h"
141
142#ifdef DEBUG_TIMING
143#include <sys/time.h>
144#endif
145
147
149typedef struct
150{
151 GDALPansharpenOperation *poPansharpenOperation;
152 GDALDataType eWorkDataType;
153 GDALDataType eBufDataType;
154 const void *pPanBuffer;
155 const void *pUpsampledSpectralBuffer;
156 void *pDataBuf;
157 size_t nValues;
158 size_t nBandValues;
159 GUInt32 nMaxValue;
160
161#ifdef DEBUG_TIMING
162 struct timeval *ptv;
163#endif
164
165 CPLErr eErr;
166} GDALPansharpenJob;
167
168typedef struct
169{
170 GDALDataset *poMEMDS;
171 int nXOff;
172 int nYOff;
173 int nXSize;
174 int nYSize;
175 double dfXOff;
176 double dfYOff;
177 double dfXSize;
178 double dfYSize;
179 void *pBuffer;
180 GDALDataType eDT;
181 int nBufXSize;
182 int nBufYSize;
183 int nBandCount;
184 GDALRIOResampleAlg eResampleAlg;
185 GSpacing nBandSpace;
186
187#ifdef DEBUG_TIMING
188 struct timeval *ptv;
189#endif
190} GDALPansharpenResampleJob;
192
196{
198
199 GDALPansharpenOptions *psOptions = nullptr;
200 std::vector<int> anInputBands{};
201 std::vector<GDALDataset *> aVDS{}; // to destroy
202 std::vector<GDALRasterBand *> aMSBands{}; // original multispectral bands
203 // potentially warped into a VRT
204 int bPositiveWeights = TRUE;
205 CPLWorkerThreadPool *poThreadPool = nullptr;
206 int nKernelRadius = 0;
207
208 static void PansharpenJobThreadFunc(void *pUserData);
209 static void PansharpenResampleJobThreadFunc(void *pUserData);
210
211 template <class WorkDataType, class OutDataType>
212 void WeightedBroveyWithNoData(const WorkDataType *pPanBuffer,
213 const WorkDataType *pUpsampledSpectralBuffer,
214 OutDataType *pDataBuf, size_t nValues,
215 size_t nBandValues,
216 WorkDataType nMaxValue) const;
217 template <class WorkDataType, class OutDataType, int bHasBitDepth>
218 void WeightedBrovey3(const WorkDataType *pPanBuffer,
219 const WorkDataType *pUpsampledSpectralBuffer,
220 OutDataType *pDataBuf, size_t nValues,
221 size_t nBandValues, WorkDataType nMaxValue) const;
222
223 // cppcheck-suppress functionStatic
224 template <class WorkDataType, class OutDataType>
225 void WeightedBrovey(const WorkDataType *pPanBuffer,
226 const WorkDataType *pUpsampledSpectralBuffer,
227 OutDataType *pDataBuf, size_t nValues,
228 size_t nBandValues, WorkDataType nMaxValue) const;
229 template <class WorkDataType>
230 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
231 const WorkDataType *pUpsampledSpectralBuffer,
232 void *pDataBuf, GDALDataType eBufDataType,
233 size_t nValues, size_t nBandValues,
234 WorkDataType nMaxValue) const;
235
236 // cppcheck-suppress functionStatic
237 template <class WorkDataType>
238 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
239 const WorkDataType *pUpsampledSpectralBuffer,
240 void *pDataBuf, GDALDataType eBufDataType,
241 size_t nValues, size_t nBandValues) const;
242 template <class T>
243 void WeightedBroveyPositiveWeights(const T *pPanBuffer,
244 const T *pUpsampledSpectralBuffer,
245 T *pDataBuf, size_t nValues,
246 size_t nBandValues, T nMaxValue) const;
247
248 template <class T, int NINPUT, int NOUTPUT>
249 size_t WeightedBroveyPositiveWeightsInternal(
250 const T *pPanBuffer, const T *pUpsampledSpectralBuffer, T *pDataBuf,
251 size_t nValues, size_t nBandValues, T nMaxValue) const;
252
253 // cppcheck-suppress unusedPrivateFunction
254 template <class T>
255 void WeightedBroveyGByteOrUInt16(const T *pPanBuffer,
256 const T *pUpsampledSpectralBuffer,
257 T *pDataBuf, size_t nValues,
258 size_t nBandValues, T nMaxValue) const;
259
260 // cppcheck-suppress functionStatic
261 CPLErr PansharpenChunk(GDALDataType eWorkDataType,
262 GDALDataType eBufDataType, const void *pPanBuffer,
263 const void *pUpsampledSpectralBuffer, void *pDataBuf,
264 size_t nValues, size_t nBandValues,
265 GUInt32 nMaxValue) const;
266
267 public:
270
271 CPLErr Initialize(const GDALPansharpenOptions *psOptions);
272 CPLErr ProcessRegion(int nXOff, int nYOff, int nXSize, int nYSize,
273 void *pDataBuf, GDALDataType eBufDataType);
275};
276
277#endif /* __cplusplus */
278
279#endif /* GDALPANSHARPEN_H_INCLUDED */
Pool of worker threads.
Definition cpl_worker_thread_pool.h:79
A set of associated raster bands, usually from one file.
Definition gdal_priv.h:348
Pansharpening operation class.
Definition gdalpansharpen.h:196
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:1040
GDALPansharpenOperation()
Pansharpening operation constructor.
~GDALPansharpenOperation()
Pansharpening operation destructor.
Definition gdalpansharpen.cpp:173
GDALPansharpenOptions * GetOptions()
Return options.
Definition gdalpansharpen.cpp:1671
CPLErr Initialize(const GDALPansharpenOptions *psOptions)
Initialize the pansharpening operation.
Definition gdalpansharpen.cpp:192
CPLErr
Error category.
Definition cpl_error.h:53
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:317
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:313
unsigned int GUInt32
Unsigned int32 type.
Definition cpl_port.h:197
#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:1049
Class to manage a pool of worker threads.
Public (C callable) GDAL entry points.
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:314
GDALDataType
Definition gdal.h:64
GDALRIOResampleAlg
RasterIO() resampling method.
Definition gdal.h:142
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal.h:293
C++ GDAL entry points.
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:1746
GDALPansharpenOperationH GDALCreatePansharpenOperation(const GDALPansharpenOptions *)
Instantiate a pansharpening operation.
Definition gdalpansharpen.cpp:1692
GDALPansharpenAlg
Pansharpening algorithms.
Definition gdalpansharpen.h:48
@ GDAL_PSH_WEIGHTED_BROVEY
Definition gdalpansharpen.h:50
void GDALDestroyPansharpenOptions(GDALPansharpenOptions *)
Destroy pansharpening options.
Definition gdalpansharpen.cpp:89
void * GDALPansharpenOperationH
Definition gdalpansharpen.h:124
GDALPansharpenOptions * GDALCreatePansharpenOptions(void)
Create pansharpening options.
Definition gdalpansharpen.cpp:68
GDALPansharpenOptions * GDALClonePansharpenOptions(const GDALPansharpenOptions *psOptions)
Clone pansharpening options.
Definition gdalpansharpen.cpp:114
void GDALDestroyPansharpenOperation(GDALPansharpenOperationH)
Destroy a pansharpening operation.
Definition gdalpansharpen.cpp:1712
Pansharpening options.
Definition gdalpansharpen.h:56
GDALPansharpenAlg ePansharpenAlg
Definition gdalpansharpen.h:58
int bHasNoData
Definition gdalpansharpen.h:96
int nBitDepth
Definition gdalpansharpen.h:66
double * padfWeights
Definition gdalpansharpen.h:72
int nThreads
Number of threads or -1 to mean ALL_CPUS.
Definition gdalpansharpen.h:106
int nWeightCount
Definition gdalpansharpen.h:69
double dfMSShiftY
Shift in pixels of multispectral bands w.r.t panchromatic band, in Y direction.
Definition gdalpansharpen.h:114
GDALRasterBandH * pahInputSpectralBands
Array of nInputSpectralBands input spectral bands.
Definition gdalpansharpen.h:86
int * panOutPansharpenedBands
Definition gdalpansharpen.h:93
double dfMSShiftX
Shift in pixels of multispectral bands w.r.t panchromatic band, in X direction.
Definition gdalpansharpen.h:110
GDALRIOResampleAlg eResampleAlg
Definition gdalpansharpen.h:62
GDALRasterBandH hPanchroBand
Definition gdalpansharpen.h:75
int nInputSpectralBands
Definition gdalpansharpen.h:78
int nOutPansharpenedBands
Definition gdalpansharpen.h:89
double dfNoData
NoData value of the panchromatic and spectral bands (only taken into account if bHasNoData = TRUE).
Definition gdalpansharpen.h:101