GDAL
gdalwarper.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: gdalwarper.h 33717 2016-03-14 06:29:14Z goatbar $
3  *
4  * Project: GDAL High Performance Warper
5  * Purpose: Prototypes, and definitions for warping related work.
6  * Author: Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2003, Frank Warmerdam
10  * Copyright (c) 2009-2012, Even Rouault <even dot rouault at mines-paris dot org>
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30 
31 #ifndef GDALWARPER_H_INCLUDED
32 #define GDALWARPER_H_INCLUDED
33 
42 #include "gdal_alg.h"
43 #include "cpl_minixml.h"
44 #include "cpl_multiproc.h"
45 
46 CPL_C_START
47 
48 /* Note: values are selected to be consistent with GDALRIOResampleAlg of gcore/gdal.h */
58  // GRA_Gauss=7 reserved. GRA_Max=8, GRA_Min=9, GRA_Med=10, GRA_Q1=11, GRA_Q3=12
65 
75 
76 typedef int
77 (*GDALMaskFunc)( void *pMaskFuncArg,
78  int nBandCount, GDALDataType eType,
79  int nXOff, int nYOff,
80  int nXSize, int nYSize,
81  GByte **papabyImageData,
82  int bMaskIsFloat, void *pMask );
83 
84 CPLErr CPL_DLL
85 GDALWarpNoDataMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
86  int nXOff, int nYOff, int nXSize, int nYSize,
87  GByte **papabyImageData, int bMaskIsFloat,
88  void *pValidityMask, int* pbOutAllValid );
89 
90 CPLErr CPL_DLL
91 GDALWarpDstAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
92  int nXOff, int nYOff, int nXSize, int nYSize,
93  GByte ** /*ppImageData */,
94  int bMaskIsFloat, void *pValidityMask );
95 CPLErr CPL_DLL
96 GDALWarpSrcAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
97  int nXOff, int nYOff, int nXSize, int nYSize,
98  GByte ** /*ppImageData */,
99  int bMaskIsFloat, void *pValidityMask, int* pbOutAllOpaque );
100 
101 CPLErr CPL_DLL
102 GDALWarpSrcMaskMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
103  int nXOff, int nYOff, int nXSize, int nYSize,
104  GByte ** /*ppImageData */,
105  int bMaskIsFloat, void *pValidityMask );
106 
107 CPLErr CPL_DLL
108 GDALWarpCutlineMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
109  int nXOff, int nYOff, int nXSize, int nYSize,
110  GByte ** /* ppImageData */,
111  int bMaskIsFloat, void *pValidityMask );
112 
113 /************************************************************************/
114 /* GDALWarpOptions */
115 /************************************************************************/
116 
118 typedef struct {
119 
121 
124 
127 
131 
134 
137 
140 
143 
146 
149 
152 
158 
164 
167  GDALProgressFunc pfnProgress;
168 
171 
174 
177 
178  GDALMaskFunc *papfnSrcPerBandValidityMaskFunc;
179  void **papSrcPerBandValidityMaskFuncArg;
180 
181  GDALMaskFunc pfnSrcValidityMaskFunc;
182  void *pSrcValidityMaskFuncArg;
183 
184  GDALMaskFunc pfnSrcDensityMaskFunc;
185  void *pSrcDensityMaskFuncArg;
186 
187  GDALMaskFunc pfnDstDensityMaskFunc;
188  void *pDstDensityMaskFuncArg;
189 
190  GDALMaskFunc pfnDstValidityMaskFunc;
191  void *pDstValidityMaskFuncArg;
192 
193  CPLErr (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg );
194  void *pPreWarpProcessorArg;
195 
196  CPLErr (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg);
197  void *pPostWarpProcessorArg;
198 
200  void *hCutline;
201 
204 
206 
207 GDALWarpOptions CPL_DLL * CPL_STDCALL GDALCreateWarpOptions(void);
208 void CPL_DLL CPL_STDCALL GDALDestroyWarpOptions( GDALWarpOptions * );
209 GDALWarpOptions CPL_DLL * CPL_STDCALL
210 GDALCloneWarpOptions( const GDALWarpOptions * );
211 
212 CPLXMLNode CPL_DLL * CPL_STDCALL
213  GDALSerializeWarpOptions( const GDALWarpOptions * );
214 GDALWarpOptions CPL_DLL * CPL_STDCALL
215  GDALDeserializeWarpOptions( CPLXMLNode * );
216 
217 /************************************************************************/
218 /* GDALReprojectImage() */
219 /************************************************************************/
220 
221 CPLErr CPL_DLL CPL_STDCALL
222 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT,
223  GDALDatasetH hDstDS, const char *pszDstWKT,
224  GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
225  double dfMaxError,
226  GDALProgressFunc pfnProgress, void *pProgressArg,
227  GDALWarpOptions *psOptions );
228 
229 CPLErr CPL_DLL CPL_STDCALL
230 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT,
231  const char *pszDstFilename, const char *pszDstWKT,
232  GDALDriverH hDstDriver, char **papszCreateOptions,
233  GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
234  double dfMaxError,
235  GDALProgressFunc pfnProgress, void *pProgressArg,
236  GDALWarpOptions *psOptions );
237 
238 /************************************************************************/
239 /* VRTWarpedDataset */
240 /************************************************************************/
241 
242 GDALDatasetH CPL_DLL CPL_STDCALL
244  const char *pszSrcWKT, const char *pszDstWKT,
245  GDALResampleAlg eResampleAlg,
246  double dfMaxError, const GDALWarpOptions *psOptions );
247 
248 GDALDatasetH CPL_DLL CPL_STDCALL
250  int nPixels, int nLines, double *padfGeoTransform,
251  GDALWarpOptions *psOptions );
252 
253 CPLErr CPL_DLL CPL_STDCALL
255  GDALWarpOptions *psWO );
256 
257 CPL_C_END
258 
259 #ifdef __cplusplus
260 
261 /************************************************************************/
262 /* GDALWarpKernel */
263 /* */
264 /* This class represents the lowest level of abstraction. It */
265 /* is holds the imagery for one "chunk" of a warp, and the */
266 /* pre-prepared masks. All IO is done before and after it's */
267 /* operation. This class is not normally used by the */
268 /* application. */
269 /************************************************************************/
270 
271 // This is the number of dummy pixels that must be reserved in source arrays
272 // in order to satisfy assumptions made in GWKResample(), and more specifically
273 // by GWKGetPixelRow() that always read a even number of pixels. So if we are
274 // in the situation to read the last pixel of the source array, we need 1 extra
275 // dummy pixel to avoid reading out of bounds.
276 #define WARP_EXTRA_ELTS 1
277 
278 class CPL_DLL GDALWarpKernel
279 {
280 public:
281  char **papszWarpOptions;
282 
285  int nBands;
286 
289  int nSrcXExtraSize; /* extra pixels (included in nSrcXSize) reserved for filter window. Should be ignored in scale computation */
290  int nSrcYExtraSize; /* extra pixels (included in nSrcYSize) reserved for filter window. Should be ignored in scale computation */
291  GByte **papabySrcImage; /* each subarray must have WARP_EXTRA_ELTS at the end */
292 
293  GUInt32 **papanBandSrcValid; /* each subarray must have WARP_EXTRA_ELTS at the end */
294  GUInt32 *panUnifiedSrcValid; /* must have WARP_EXTRA_ELTS at the end */
295  float *pafUnifiedSrcDensity; /* must have WARP_EXTRA_ELTS at the end */
296 
299  GByte **papabyDstImage;
300  GUInt32 *panDstValid;
302 
303  double dfXScale; // Resampling scale, i.e.
304  double dfYScale; // nDstSize/nSrcSize.
305  double dfXFilter; // Size of filter kernel.
306  double dfYFilter;
307  int nXRadius; // Size of window to filter.
308  int nYRadius;
309  int nFiltInitX; // Filtering offset
310  int nFiltInitY;
311 
312  int nSrcXOff;
313  int nSrcYOff;
314 
315  int nDstXOff;
316  int nDstYOff;
317 
320 
321  GDALProgressFunc pfnProgress;
322  void *pProgress;
323 
324  double dfProgressBase;
325  double dfProgressScale;
326 
327  double *padfDstNoDataReal;
328 
329  void *psThreadData;
330 
331  GDALWarpKernel();
332  virtual ~GDALWarpKernel();
333 
334  CPLErr Validate();
335  CPLErr PerformWarp();
336 };
337 
338 void* GWKThreadsCreate(char** papszWarpOptions,
339  GDALTransformerFunc pfnTransformer,
340  void* pTransformerArg);
341 void GWKThreadsEnd(void* psThreadDataIn);
342 
343 /************************************************************************/
344 /* GDALWarpOperation() */
345 /* */
346 /* This object is application created, or created by a higher */
347 /* level convenience function. It is responsible for */
348 /* subdividing the operation into chunks, loading and saving */
349 /* imagery, and establishing the varios validity and density */
350 /* masks. Actual resampling is done by the GDALWarpKernel. */
351 /************************************************************************/
352 
353 typedef struct _GDALWarpChunk GDALWarpChunk;
354 
355 class CPL_DLL GDALWarpOperation {
356 private:
357  GDALWarpOptions *psOptions;
358 
359  void WipeOptions();
360  int ValidateOptions();
361 
362  CPLErr ComputeSourceWindow( int nDstXOff, int nDstYOff,
363  int nDstXSize, int nDstYSize,
364  int *pnSrcXOff, int *pnSrcYOff,
365  int *pnSrcXSize, int *pnSrcYSize,
366  int *pnSrcXExtraSize, int *pnSrcYExtraSize,
367  double* pdfSrcFillRatio );
368 
369  CPLErr CreateKernelMask( GDALWarpKernel *, int iBand,
370  const char *pszType );
371 
372  CPLMutex *hIOMutex;
373  CPLMutex *hWarpMutex;
374 
375  int nChunkListCount;
376  int nChunkListMax;
377  GDALWarpChunk *pasChunkList;
378 
379  int bReportTimings;
380  unsigned long nLastTimeReported;
381 
382  void *psThreadData;
383 
384  void WipeChunkList();
385  CPLErr CollectChunkList( int nDstXOff, int nDstYOff,
386  int nDstXSize, int nDstYSize );
387  void ReportTiming( const char * );
388 
389 public:
391  virtual ~GDALWarpOperation();
392 
393  CPLErr Initialize( const GDALWarpOptions *psNewOptions );
394 
395  const GDALWarpOptions *GetOptions();
396 
397  CPLErr ChunkAndWarpImage( int nDstXOff, int nDstYOff,
398  int nDstXSize, int nDstYSize );
399  CPLErr ChunkAndWarpMulti( int nDstXOff, int nDstYOff,
400  int nDstXSize, int nDstYSize );
401  CPLErr WarpRegion( int nDstXOff, int nDstYOff,
402  int nDstXSize, int nDstYSize,
403  int nSrcXOff=0, int nSrcYOff=0,
404  int nSrcXSize=0, int nSrcYSize=0,
405  double dfProgressBase=0.0, double dfProgressScale=1.0);
406  CPLErr WarpRegion( int nDstXOff, int nDstYOff,
407  int nDstXSize, int nDstYSize,
408  int nSrcXOff, int nSrcYOff,
409  int nSrcXSize, int nSrcYSize,
410  int nSrcXExtraSize, int nSrcYExtraSize,
411  double dfProgressBase, double dfProgressScale);
412  CPLErr WarpRegionToBuffer( int nDstXOff, int nDstYOff,
413  int nDstXSize, int nDstYSize,
414  void *pDataBuf,
415  GDALDataType eBufDataType,
416  int nSrcXOff=0, int nSrcYOff=0,
417  int nSrcXSize=0, int nSrcYSize=0,
418  double dfProgressBase=0.0, double dfProgressScale=1.0);
419  CPLErr WarpRegionToBuffer( int nDstXOff, int nDstYOff,
420  int nDstXSize, int nDstYSize,
421  void *pDataBuf,
422  GDALDataType eBufDataType,
423  int nSrcXOff, int nSrcYOff,
424  int nSrcXSize, int nSrcYSize,
425  int nSrcXExtraSize, int nSrcYExtraSize,
426  double dfProgressBase, double dfProgressScale);
427 };
428 
429 #endif /* def __cplusplus */
430 
431 CPL_C_START
432 
433 typedef void * GDALWarpOperationH;
434 
435 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* );
436 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH );
437 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int );
438 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int );
439 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH,
440  int, int, int, int, int, int, int, int );
441 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int,
442  void *, GDALDataType,
443  int, int, int, int );
444 
445 /************************************************************************/
446 /* Warping kernel functions */
447 /************************************************************************/
448 
449 int GWKGetFilterRadius(GDALResampleAlg eResampleAlg);
450 
451 typedef double (*FilterFuncType)(double dfX);
452 FilterFuncType GWKGetFilterFunc(GDALResampleAlg eResampleAlg);
453 
454 typedef double (*FilterFunc4ValuesType)(double* padfVals);
455 FilterFunc4ValuesType GWKGetFilterFunc4Values(GDALResampleAlg eResampleAlg);
456 
457 CPL_C_END
458 
459 #endif /* ndef GDAL_ALG_H_INCLUDED */
int nSrcXOff
X offset to source pixel coordinates for transformation.
Definition: gdalwarper.h:312
int nSrcXExtraSize
Number of pixels included in nSrcXSize that are present on the edges of the area of interest to take ...
Definition: gdalwarper.h:289
GDALDataType
Definition: gdal.h:57
Document node structure.
Definition: cpl_minixml.h:65
Low level image warping class.
Definition: gdalwarper.h:278
Definitions for CPL mini XML Parser/Serializer.
Definition: gdalwarper.h:54
GByte ** papabySrcImage
Array of source image band data.
Definition: gdalwarper.h:291
Definition: gdalwarper.h:72
CPLErr GDALInitializeWarpedVRT(GDALDatasetH hDS, GDALWarpOptions *psWO)
Set warp info on virtual warped dataset.
Definition: vrtwarped.cpp:1018
GUInt32 * panUnifiedSrcValid
Per pixel validity mask for source pixels.
Definition: gdalwarper.h:294
int nDstXSize
Width of destination image in pixels.
Definition: gdalwarper.h:297
int * panDstBands
Definition: gdalwarper.h:145
void * pProgressArg
Definition: gdalwarper.h:170
int nDstXOff
X offset to destination pixel coordinates for transformation.
Definition: gdalwarper.h:315
double dfWarpMemoryLimit
Definition: gdalwarper.h:123
int nSrcAlphaBand
Definition: gdalwarper.h:148
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition: gdal.h:230
CPLErr GDALWarpRegionToBuffer(GDALWarpOperationH, int, int, int, int, void *, GDALDataType, int, int, int, int)
Definition: gdalwarpoperation.cpp:1965
Definition: gdalwarper.h:55
Definition: gdalwarper.h:56
GUInt32 * panDstValid
Per pixel validity mask for destination pixels.
Definition: gdalwarper.h:300
double * padfDstNoDataReal
Definition: gdalwarper.h:160
GWKAverageOrModeAlg
Definition: gdalwarper.h:67
GDALDataType eWorkingDataType
Working pixel data type.
Definition: gdalwarper.h:284
float * pafUnifiedSrcDensity
Per pixel density mask for source pixels.
Definition: gdalwarper.h:295
double * padfSrcNoDataImag
Definition: gdalwarper.h:157
GDALResampleAlg eResampleAlg
Definition: gdalwarper.h:126
CPLErr GDALChunkAndWarpMulti(GDALWarpOperationH, int, int, int, int)
Definition: gdalwarpoperation.cpp:976
CPLErr GDALWarpRegion(GDALWarpOperationH, int, int, int, int, int, int, int, int)
Definition: gdalwarpoperation.cpp:1430
GDALDatasetH GDALCreateWarpedVRT(GDALDatasetH hSrcDS, int nPixels, int nLines, double *padfGeoTransform, GDALWarpOptions *psOptions)
Create virtual warped dataset.
Definition: vrtwarped.cpp:230
Definition: gdalwarper.h:68
GDALTransformerFunc pfnTransformer
Definition: gdalwarper.h:173
void GDALDestroyWarpOperation(GDALWarpOperationH)
Definition: gdalwarpoperation.cpp:623
CPLErr GDALReprojectImage(GDALDatasetH hSrcDS, const char *pszSrcWKT, GDALDatasetH hDstDS, const char *pszDstWKT, GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit, double dfMaxError, GDALProgressFunc pfnProgress, void *pProgressArg, GDALWarpOptions *psOptions)
Reproject image.
Definition: gdalwarper.cpp:80
double * padfDstNoDataImag
Definition: gdalwarper.h:163
Definition: gdalwarper.h:69
Definition: gdalwarper.h:71
int nDstYOff
Y offset to destination pixel coordinates for transformation.
Definition: gdalwarper.h:316
GDALResampleAlg eResample
Resampling algorithm.
Definition: gdalwarper.h:283
GDALResampleAlg
Definition: gdalwarper.h:50
Warp control options for use with GDALWarpOperation::Initialize()
Definition: gdalwarper.h:118
GDALProgressFunc pfnProgress
Definition: gdalwarper.h:167
Definition: gdalwarper.h:53
int nSrcYExtraSize
Number of pixels included in nSrcYExtraSize that are present on the edges of the area of interest to ...
Definition: gdalwarper.h:290
High level image warping class.
Definition: gdalwarper.h:355
void * pTransformerArg
Definition: gdalwarper.h:176
int nSrcYSize
Source image height in pixels.
Definition: gdalwarper.h:288
GDALProgressFunc pfnProgress
The function to call to report progress of the algorithm, and to check for a requested termination of...
Definition: gdalwarper.h:321
Definition: gdalwarper.h:52
int * panSrcBands
Definition: gdalwarper.h:142
int(* GDALTransformerFunc)(void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess)
Definition: gdal_alg.h:114
void * GDALDriverH
Opaque type used for the C bindings of the C++ GDALDriver class.
Definition: gdal.h:236
char ** papszWarpOptions
A string list of additional options controlling the warp operation in name=value format.
Definition: gdalwarper.h:120
int nDstYSize
Height of destination image in pixels.
Definition: gdalwarper.h:298
Definition: gdalwarper.h:73
int nBands
Number of bands.
Definition: gdalwarper.h:285
CPLErr GDALChunkAndWarpImage(GDALWarpOperationH, int, int, int, int)
Definition: gdalwarpoperation.cpp:743
Definition: gdalwarper.h:51
Public (C callable) GDAL algorithm entry points, and definitions.
void * pTransformerArg
Callback data for pfnTransformer.
Definition: gdalwarper.h:319
int nSrcXSize
Source image width in pixels.
Definition: gdalwarper.h:287
GDALDatasetH hSrcDS
Definition: gdalwarper.h:133
int nBandCount
Definition: gdalwarper.h:139
float * pafDstDensity
Per pixel density mask for destination pixels.
Definition: gdalwarper.h:301
GDALDataType eWorkingDataType
Definition: gdalwarper.h:130
GDALTransformerFunc pfnTransformer
Source/destination location transformer.
Definition: gdalwarper.h:318
GDALDatasetH hDstDS
Definition: gdalwarper.h:136
Definition: gdalwarper.h:57
void * hCutline
Definition: gdalwarper.h:200
double dfCutlineBlendDist
Definition: gdalwarper.h:203
GDALDatasetH GDALAutoCreateWarpedVRT(GDALDatasetH hSrcDS, const char *pszSrcWKT, const char *pszDstWKT, GDALResampleAlg eResampleAlg, double dfMaxError, const GDALWarpOptions *psOptions)
Create virtual warped dataset automatically.
Definition: vrtwarped.cpp:90
double * padfSrcNoDataReal
Definition: gdalwarper.h:154
void * pProgress
Callback data for pfnProgress.
Definition: gdalwarper.h:322
int nSrcYOff
Y offset to source pixel coordinates for transformation.
Definition: gdalwarper.h:313
Definition: gdalwarper.h:70
GDALWarpOperationH GDALCreateWarpOperation(const GDALWarpOptions *)
Definition: gdalwarpoperation.cpp:600
GByte ** papabyDstImage
Array of destination image band data.
Definition: gdalwarper.h:299
int nDstAlphaBand
Definition: gdalwarper.h:151
GUInt32 ** papanBandSrcValid
Per band validity mask for source pixels.
Definition: gdalwarper.h:293

Generated for GDAL by doxygen 1.8.13.