GDAL
gdalwarper.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: gdalwarper.h 29330 2015-06-14 12:11:11Z rouault $
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  GDALWarpKernel();
330  virtual ~GDALWarpKernel();
331 
332  CPLErr Validate();
333  CPLErr PerformWarp();
334 };
335 
336 /************************************************************************/
337 /* GDALWarpOperation() */
338 /* */
339 /* This object is application created, or created by a higher */
340 /* level convenience function. It is responsible for */
341 /* subdividing the operation into chunks, loading and saving */
342 /* imagery, and establishing the varios validity and density */
343 /* masks. Actual resampling is done by the GDALWarpKernel. */
344 /************************************************************************/
345 
346 typedef struct _GDALWarpChunk GDALWarpChunk;
347 
348 class CPL_DLL GDALWarpOperation {
349 private:
350  GDALWarpOptions *psOptions;
351 
352  void WipeOptions();
353  int ValidateOptions();
354 
355  CPLErr ComputeSourceWindow( int nDstXOff, int nDstYOff,
356  int nDstXSize, int nDstYSize,
357  int *pnSrcXOff, int *pnSrcYOff,
358  int *pnSrcXSize, int *pnSrcYSize,
359  int *pnSrcXExtraSize, int *pnSrcYExtraSize,
360  double* pdfSrcFillRatio );
361 
362  CPLErr CreateKernelMask( GDALWarpKernel *, int iBand,
363  const char *pszType );
364 
365  CPLMutex *hIOMutex;
366  CPLMutex *hWarpMutex;
367 
368  int nChunkListCount;
369  int nChunkListMax;
370  GDALWarpChunk *pasChunkList;
371 
372  int bReportTimings;
373  unsigned long nLastTimeReported;
374 
375  void WipeChunkList();
376  CPLErr CollectChunkList( int nDstXOff, int nDstYOff,
377  int nDstXSize, int nDstYSize );
378  void ReportTiming( const char * );
379 
380 public:
382  virtual ~GDALWarpOperation();
383 
384  CPLErr Initialize( const GDALWarpOptions *psNewOptions );
385 
386  const GDALWarpOptions *GetOptions();
387 
388  CPLErr ChunkAndWarpImage( int nDstXOff, int nDstYOff,
389  int nDstXSize, int nDstYSize );
390  CPLErr ChunkAndWarpMulti( int nDstXOff, int nDstYOff,
391  int nDstXSize, int nDstYSize );
392  CPLErr WarpRegion( int nDstXOff, int nDstYOff,
393  int nDstXSize, int nDstYSize,
394  int nSrcXOff=0, int nSrcYOff=0,
395  int nSrcXSize=0, int nSrcYSize=0,
396  double dfProgressBase=0.0, double dfProgressScale=1.0);
397  CPLErr WarpRegion( int nDstXOff, int nDstYOff,
398  int nDstXSize, int nDstYSize,
399  int nSrcXOff, int nSrcYOff,
400  int nSrcXSize, int nSrcYSize,
401  int nSrcXExtraSize, int nSrcYExtraSize,
402  double dfProgressBase, double dfProgressScale);
403  CPLErr WarpRegionToBuffer( int nDstXOff, int nDstYOff,
404  int nDstXSize, int nDstYSize,
405  void *pDataBuf,
406  GDALDataType eBufDataType,
407  int nSrcXOff=0, int nSrcYOff=0,
408  int nSrcXSize=0, int nSrcYSize=0,
409  double dfProgressBase=0.0, double dfProgressScale=1.0);
410  CPLErr WarpRegionToBuffer( int nDstXOff, int nDstYOff,
411  int nDstXSize, int nDstYSize,
412  void *pDataBuf,
413  GDALDataType eBufDataType,
414  int nSrcXOff, int nSrcYOff,
415  int nSrcXSize, int nSrcYSize,
416  int nSrcXExtraSize, int nSrcYExtraSize,
417  double dfProgressBase, double dfProgressScale);
418 };
419 
420 #endif /* def __cplusplus */
421 
422 CPL_C_START
423 
424 typedef void * GDALWarpOperationH;
425 
426 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* );
427 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH );
428 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int );
429 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int );
430 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH,
431  int, int, int, int, int, int, int, int );
432 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int,
433  void *, GDALDataType,
434  int, int, int, int );
435 
436 /************************************************************************/
437 /* Warping kernel functions */
438 /************************************************************************/
439 
440 int GWKGetFilterRadius(GDALResampleAlg eResampleAlg);
441 
442 typedef double (*FilterFuncType)(double dfX);
443 FilterFuncType GWKGetFilterFunc(GDALResampleAlg eResampleAlg);
444 
445 typedef double (*FilterFunc4ValuesType)(double* padfVals);
446 FilterFunc4ValuesType GWKGetFilterFunc4Values(GDALResampleAlg eResampleAlg);
447 
448 CPL_C_END
449 
450 #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:1023
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:227
CPLErr GDALWarpRegionToBuffer(GDALWarpOperationH, int, int, int, int, void *, GDALDataType, int, int, int, int)
Definition: gdalwarpoperation.cpp:1963
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:965
CPLErr GDALWarpRegion(GDALWarpOperationH, int, int, int, int, int, int, int, int)
Definition: gdalwarpoperation.cpp:1423
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:613
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:348
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:233
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:732
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:87
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:590
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.8.