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
108
111GDALPansharpenOptions CPL_DLL *
113
116
121 int nXOff, int nYOff, int nXSize,
122 int nYSize, void *pDataBuf,
123 GDALDataType eBufDataType);
124
126
127#ifdef __cplusplus
128
129#include <array>
130#include <vector>
131#include "gdal_priv.h"
132
133#ifdef DEBUG_TIMING
134#include <sys/time.h>
135#endif
136
138
140typedef struct
141{
142 GDALPansharpenOperation *poPansharpenOperation;
143 GDALDataType eWorkDataType;
144 GDALDataType eBufDataType;
145 const void *pPanBuffer;
146 const void *pUpsampledSpectralBuffer;
147 void *pDataBuf;
148 size_t nValues;
149 size_t nBandValues;
150 GUInt32 nMaxValue;
151
152#ifdef DEBUG_TIMING
153 struct timeval *ptv;
154#endif
155
156 CPLErr eErr;
157} GDALPansharpenJob;
158
159typedef struct
160{
161 GDALDataset *poMEMDS;
162 int nXOff;
163 int nYOff;
164 int nXSize;
165 int nYSize;
166 double dfXOff;
167 double dfYOff;
168 double dfXSize;
169 double dfYSize;
170 void *pBuffer;
171 GDALDataType eDT;
172 int nBufXSize;
173 int nBufYSize;
174 int nBandCount;
175 GDALRIOResampleAlg eResampleAlg;
176 GSpacing nBandSpace;
177
178#ifdef DEBUG_TIMING
179 struct timeval *ptv;
180#endif
181} GDALPansharpenResampleJob;
182
184
186
190{
192
193 GDALPansharpenOptions *psOptions = nullptr;
194 std::vector<int> anInputBands{};
195 std::vector<GDALDataset *> aVDS{}; // to destroy
196 std::vector<GDALRasterBand *> aMSBands{}; // original multispectral bands
197 // potentially warped into a VRT
198 int bPositiveWeights = TRUE;
199 CPLWorkerThreadPool *poThreadPool = nullptr;
200 int nKernelRadius = 0;
201 std::array<double, 6> m_adfPanToMSGT = {{0.0, 1.0, 0, 0.0, 0.0, 1.0}};
202
203 static void PansharpenJobThreadFunc(void *pUserData);
204 static void PansharpenResampleJobThreadFunc(void *pUserData);
205
206 template <class WorkDataType, class OutDataType>
207 void WeightedBroveyWithNoData(const WorkDataType *pPanBuffer,
208 const WorkDataType *pUpsampledSpectralBuffer,
209 OutDataType *pDataBuf, size_t nValues,
210 size_t nBandValues,
211 WorkDataType nMaxValue) const;
212 template <class WorkDataType, class OutDataType, int bHasBitDepth>
213 void WeightedBrovey3(const WorkDataType *pPanBuffer,
214 const WorkDataType *pUpsampledSpectralBuffer,
215 OutDataType *pDataBuf, size_t nValues,
216 size_t nBandValues, WorkDataType nMaxValue) const;
217
218 // cppcheck-suppress functionStatic
219 template <class WorkDataType, class OutDataType>
220 void WeightedBrovey(const WorkDataType *pPanBuffer,
221 const WorkDataType *pUpsampledSpectralBuffer,
222 OutDataType *pDataBuf, size_t nValues,
223 size_t nBandValues, WorkDataType nMaxValue) const;
224 template <class WorkDataType>
225 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
226 const WorkDataType *pUpsampledSpectralBuffer,
227 void *pDataBuf, GDALDataType eBufDataType,
228 size_t nValues, size_t nBandValues,
229 WorkDataType nMaxValue) const;
230
231 // cppcheck-suppress functionStatic
232 template <class WorkDataType>
233 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
234 const WorkDataType *pUpsampledSpectralBuffer,
235 void *pDataBuf, GDALDataType eBufDataType,
236 size_t nValues, size_t nBandValues) const;
237 template <class T>
238 void WeightedBroveyPositiveWeights(const T *pPanBuffer,
239 const T *pUpsampledSpectralBuffer,
240 T *pDataBuf, size_t nValues,
241 size_t nBandValues, T nMaxValue) const;
242
243 template <class T, int NINPUT, int NOUTPUT>
244 size_t WeightedBroveyPositiveWeightsInternal(
245 const T *pPanBuffer, const T *pUpsampledSpectralBuffer, T *pDataBuf,
246 size_t nValues, size_t nBandValues, T nMaxValue) const;
247
248 // cppcheck-suppress unusedPrivateFunction
249 template <class T>
250 void WeightedBroveyGByteOrUInt16(const T *pPanBuffer,
251 const T *pUpsampledSpectralBuffer,
252 T *pDataBuf, size_t nValues,
253 size_t nBandValues, T nMaxValue) const;
254
255 // cppcheck-suppress functionStatic
256 CPLErr PansharpenChunk(GDALDataType eWorkDataType,
257 GDALDataType eBufDataType, const void *pPanBuffer,
258 const void *pUpsampledSpectralBuffer, void *pDataBuf,
259 size_t nValues, size_t nBandValues,
260 GUInt32 nMaxValue) const;
261
262 public:
265
266 CPLErr Initialize(const GDALPansharpenOptions *psOptions);
267 CPLErr ProcessRegion(int nXOff, int nYOff, int nXSize, int nYSize,
268 void *pDataBuf, GDALDataType eBufDataType);
270};
271
272#endif /* __cplusplus */
273
274#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:490
Pansharpening operation class.
Definition gdalpansharpen.h:190
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:1173
GDALPansharpenOperation()
Pansharpening operation constructor.
~GDALPansharpenOperation()
Pansharpening operation destructor.
Definition gdalpansharpen.cpp:171
GDALPansharpenOptions * GetOptions()
Return options.
Definition gdalpansharpen.cpp:1807
CPLErr Initialize(const GDALPansharpenOptions *psOptions)
Initialize the pansharpening operation.
Definition gdalpansharpen.cpp:190
CPLErr
Error category.
Definition cpl_error.h:53
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:299
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:295
unsigned int GUInt32
Unsigned int32 type.
Definition cpl_port.h:177
#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:1042
Public (C callable) GDAL entry points.
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:315
GDALDataType
Definition gdal.h:64
GDALRIOResampleAlg
RasterIO() resampling method.
Definition gdal.h:143
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal.h:294
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:1882
GDALPansharpenOperationH GDALCreatePansharpenOperation(const GDALPansharpenOptions *)
Instantiate a pansharpening operation.
Definition gdalpansharpen.cpp:1828
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:115
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:1848
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
GDALRasterBandH * pahInputSpectralBands
Array of nInputSpectralBands input spectral bands.
Definition gdalpansharpen.h:86
int * panOutPansharpenedBands
Definition gdalpansharpen.h:93
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