GDAL
|
00001 /****************************************************************************** 00002 * $Id: gdalwarper.h 29330 2015-06-14 12:11:11Z rouault $ 00003 * 00004 * Project: GDAL High Performance Warper 00005 * Purpose: Prototypes, and definitions for warping related work. 00006 * Author: Frank Warmerdam, warmerdam@pobox.com 00007 * 00008 ****************************************************************************** 00009 * Copyright (c) 2003, Frank Warmerdam 00010 * Copyright (c) 2009-2012, Even Rouault <even dot rouault at mines-paris dot org> 00011 * 00012 * Permission is hereby granted, free of charge, to any person obtaining a 00013 * copy of this software and associated documentation files (the "Software"), 00014 * to deal in the Software without restriction, including without limitation 00015 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00016 * and/or sell copies of the Software, and to permit persons to whom the 00017 * Software is furnished to do so, subject to the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be included 00020 * in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00023 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00024 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00025 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00026 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00027 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00028 * DEALINGS IN THE SOFTWARE. 00029 ****************************************************************************/ 00030 00031 #ifndef GDALWARPER_H_INCLUDED 00032 #define GDALWARPER_H_INCLUDED 00033 00042 #include "gdal_alg.h" 00043 #include "cpl_minixml.h" 00044 #include "cpl_multiproc.h" 00045 00046 CPL_C_START 00047 00048 /* Note: values are selected to be consistent with GDALRIOResampleAlg of gcore/gdal.h */ 00050 typedef enum { GRA_NearestNeighbour=0, GRA_Bilinear=1, GRA_Cubic=2, GRA_CubicSpline=3, GRA_Lanczos=4, GRA_Average=5, GRA_Mode=6, 00058 // GRA_Gauss=7 reserved. GRA_Max=8, GRA_Min=9, GRA_Med=10, GRA_Q1=11, GRA_Q3=12 00064 } GDALResampleAlg; 00065 00067 typedef enum { GWKAOM_Average=1, GWKAOM_Fmode=2, GWKAOM_Imode=3, GWKAOM_Max=4, GWKAOM_Min=5, GWKAOM_Quant=6 00074 } GWKAverageOrModeAlg; 00075 00076 typedef int 00077 (*GDALMaskFunc)( void *pMaskFuncArg, 00078 int nBandCount, GDALDataType eType, 00079 int nXOff, int nYOff, 00080 int nXSize, int nYSize, 00081 GByte **papabyImageData, 00082 int bMaskIsFloat, void *pMask ); 00083 00084 CPLErr CPL_DLL 00085 GDALWarpNoDataMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType, 00086 int nXOff, int nYOff, int nXSize, int nYSize, 00087 GByte **papabyImageData, int bMaskIsFloat, 00088 void *pValidityMask, int* pbOutAllValid ); 00089 00090 CPLErr CPL_DLL 00091 GDALWarpDstAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType, 00092 int nXOff, int nYOff, int nXSize, int nYSize, 00093 GByte ** /*ppImageData */, 00094 int bMaskIsFloat, void *pValidityMask ); 00095 CPLErr CPL_DLL 00096 GDALWarpSrcAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType, 00097 int nXOff, int nYOff, int nXSize, int nYSize, 00098 GByte ** /*ppImageData */, 00099 int bMaskIsFloat, void *pValidityMask, int* pbOutAllOpaque ); 00100 00101 CPLErr CPL_DLL 00102 GDALWarpSrcMaskMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType, 00103 int nXOff, int nYOff, int nXSize, int nYSize, 00104 GByte ** /*ppImageData */, 00105 int bMaskIsFloat, void *pValidityMask ); 00106 00107 CPLErr CPL_DLL 00108 GDALWarpCutlineMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType, 00109 int nXOff, int nYOff, int nXSize, int nYSize, 00110 GByte ** /* ppImageData */, 00111 int bMaskIsFloat, void *pValidityMask ); 00112 00113 /************************************************************************/ 00114 /* GDALWarpOptions */ 00115 /************************************************************************/ 00116 00118 typedef struct { 00119 00120 char **papszWarpOptions; 00121 00123 double dfWarpMemoryLimit; 00124 00126 GDALResampleAlg eResampleAlg; 00127 00130 GDALDataType eWorkingDataType; 00131 00133 GDALDatasetH hSrcDS; 00134 00136 GDALDatasetH hDstDS; 00137 00139 int nBandCount; 00140 00142 int *panSrcBands; 00143 00145 int *panDstBands; 00146 00148 int nSrcAlphaBand; 00149 00151 int nDstAlphaBand; 00152 00154 double *padfSrcNoDataReal; 00157 double *padfSrcNoDataImag; 00158 00160 double *padfDstNoDataReal; 00163 double *padfDstNoDataImag; 00164 00167 GDALProgressFunc pfnProgress; 00168 00170 void *pProgressArg; 00171 00173 GDALTransformerFunc pfnTransformer; 00174 00176 void *pTransformerArg; 00177 00178 GDALMaskFunc *papfnSrcPerBandValidityMaskFunc; 00179 void **papSrcPerBandValidityMaskFuncArg; 00180 00181 GDALMaskFunc pfnSrcValidityMaskFunc; 00182 void *pSrcValidityMaskFuncArg; 00183 00184 GDALMaskFunc pfnSrcDensityMaskFunc; 00185 void *pSrcDensityMaskFuncArg; 00186 00187 GDALMaskFunc pfnDstDensityMaskFunc; 00188 void *pDstDensityMaskFuncArg; 00189 00190 GDALMaskFunc pfnDstValidityMaskFunc; 00191 void *pDstValidityMaskFuncArg; 00192 00193 CPLErr (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg ); 00194 void *pPreWarpProcessorArg; 00195 00196 CPLErr (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg); 00197 void *pPostWarpProcessorArg; 00198 00200 void *hCutline; 00201 00203 double dfCutlineBlendDist; 00204 00205 } GDALWarpOptions; 00206 00207 GDALWarpOptions CPL_DLL * CPL_STDCALL GDALCreateWarpOptions(void); 00208 void CPL_DLL CPL_STDCALL GDALDestroyWarpOptions( GDALWarpOptions * ); 00209 GDALWarpOptions CPL_DLL * CPL_STDCALL 00210 GDALCloneWarpOptions( const GDALWarpOptions * ); 00211 00212 CPLXMLNode CPL_DLL * CPL_STDCALL 00213 GDALSerializeWarpOptions( const GDALWarpOptions * ); 00214 GDALWarpOptions CPL_DLL * CPL_STDCALL 00215 GDALDeserializeWarpOptions( CPLXMLNode * ); 00216 00217 /************************************************************************/ 00218 /* GDALReprojectImage() */ 00219 /************************************************************************/ 00220 00221 CPLErr CPL_DLL CPL_STDCALL 00222 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 00223 GDALDatasetH hDstDS, const char *pszDstWKT, 00224 GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit, 00225 double dfMaxError, 00226 GDALProgressFunc pfnProgress, void *pProgressArg, 00227 GDALWarpOptions *psOptions ); 00228 00229 CPLErr CPL_DLL CPL_STDCALL 00230 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 00231 const char *pszDstFilename, const char *pszDstWKT, 00232 GDALDriverH hDstDriver, char **papszCreateOptions, 00233 GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit, 00234 double dfMaxError, 00235 GDALProgressFunc pfnProgress, void *pProgressArg, 00236 GDALWarpOptions *psOptions ); 00237 00238 /************************************************************************/ 00239 /* VRTWarpedDataset */ 00240 /************************************************************************/ 00241 00242 GDALDatasetH CPL_DLL CPL_STDCALL 00243 GDALAutoCreateWarpedVRT( GDALDatasetH hSrcDS, 00244 const char *pszSrcWKT, const char *pszDstWKT, 00245 GDALResampleAlg eResampleAlg, 00246 double dfMaxError, const GDALWarpOptions *psOptions ); 00247 00248 GDALDatasetH CPL_DLL CPL_STDCALL 00249 GDALCreateWarpedVRT( GDALDatasetH hSrcDS, 00250 int nPixels, int nLines, double *padfGeoTransform, 00251 GDALWarpOptions *psOptions ); 00252 00253 CPLErr CPL_DLL CPL_STDCALL 00254 GDALInitializeWarpedVRT( GDALDatasetH hDS, 00255 GDALWarpOptions *psWO ); 00256 00257 CPL_C_END 00258 00259 #ifdef __cplusplus 00260 00261 /************************************************************************/ 00262 /* GDALWarpKernel */ 00263 /* */ 00264 /* This class represents the lowest level of abstraction. It */ 00265 /* is holds the imagery for one "chunk" of a warp, and the */ 00266 /* pre-prepared masks. All IO is done before and after it's */ 00267 /* operation. This class is not normally used by the */ 00268 /* application. */ 00269 /************************************************************************/ 00270 00271 // This is the number of dummy pixels that must be reserved in source arrays 00272 // in order to satisfy assumptions made in GWKResample(), and more specifically 00273 // by GWKGetPixelRow() that always read a even number of pixels. So if we are 00274 // in the situation to read the last pixel of the source array, we need 1 extra 00275 // dummy pixel to avoid reading out of bounds. 00276 #define WARP_EXTRA_ELTS 1 00277 00278 class CPL_DLL GDALWarpKernel 00279 { 00280 public: 00281 char **papszWarpOptions; 00282 00283 GDALResampleAlg eResample; 00284 GDALDataType eWorkingDataType; 00285 int nBands; 00286 00287 int nSrcXSize; 00288 int nSrcYSize; 00289 int nSrcXExtraSize; /* extra pixels (included in nSrcXSize) reserved for filter window. Should be ignored in scale computation */ 00290 int nSrcYExtraSize; /* extra pixels (included in nSrcYSize) reserved for filter window. Should be ignored in scale computation */ 00291 GByte **papabySrcImage; /* each subarray must have WARP_EXTRA_ELTS at the end */ 00292 00293 GUInt32 **papanBandSrcValid; /* each subarray must have WARP_EXTRA_ELTS at the end */ 00294 GUInt32 *panUnifiedSrcValid; /* must have WARP_EXTRA_ELTS at the end */ 00295 float *pafUnifiedSrcDensity; /* must have WARP_EXTRA_ELTS at the end */ 00296 00297 int nDstXSize; 00298 int nDstYSize; 00299 GByte **papabyDstImage; 00300 GUInt32 *panDstValid; 00301 float *pafDstDensity; 00302 00303 double dfXScale; // Resampling scale, i.e. 00304 double dfYScale; // nDstSize/nSrcSize. 00305 double dfXFilter; // Size of filter kernel. 00306 double dfYFilter; 00307 int nXRadius; // Size of window to filter. 00308 int nYRadius; 00309 int nFiltInitX; // Filtering offset 00310 int nFiltInitY; 00311 00312 int nSrcXOff; 00313 int nSrcYOff; 00314 00315 int nDstXOff; 00316 int nDstYOff; 00317 00318 GDALTransformerFunc pfnTransformer; 00319 void *pTransformerArg; 00320 00321 GDALProgressFunc pfnProgress; 00322 void *pProgress; 00323 00324 double dfProgressBase; 00325 double dfProgressScale; 00326 00327 double *padfDstNoDataReal; 00328 00329 GDALWarpKernel(); 00330 virtual ~GDALWarpKernel(); 00331 00332 CPLErr Validate(); 00333 CPLErr PerformWarp(); 00334 }; 00335 00336 /************************************************************************/ 00337 /* GDALWarpOperation() */ 00338 /* */ 00339 /* This object is application created, or created by a higher */ 00340 /* level convenience function. It is responsible for */ 00341 /* subdividing the operation into chunks, loading and saving */ 00342 /* imagery, and establishing the varios validity and density */ 00343 /* masks. Actual resampling is done by the GDALWarpKernel. */ 00344 /************************************************************************/ 00345 00346 typedef struct _GDALWarpChunk GDALWarpChunk; 00347 00348 class CPL_DLL GDALWarpOperation { 00349 private: 00350 GDALWarpOptions *psOptions; 00351 00352 void WipeOptions(); 00353 int ValidateOptions(); 00354 00355 CPLErr ComputeSourceWindow( int nDstXOff, int nDstYOff, 00356 int nDstXSize, int nDstYSize, 00357 int *pnSrcXOff, int *pnSrcYOff, 00358 int *pnSrcXSize, int *pnSrcYSize, 00359 int *pnSrcXExtraSize, int *pnSrcYExtraSize, 00360 double* pdfSrcFillRatio ); 00361 00362 CPLErr CreateKernelMask( GDALWarpKernel *, int iBand, 00363 const char *pszType ); 00364 00365 CPLMutex *hIOMutex; 00366 CPLMutex *hWarpMutex; 00367 00368 int nChunkListCount; 00369 int nChunkListMax; 00370 GDALWarpChunk *pasChunkList; 00371 00372 int bReportTimings; 00373 unsigned long nLastTimeReported; 00374 00375 void WipeChunkList(); 00376 CPLErr CollectChunkList( int nDstXOff, int nDstYOff, 00377 int nDstXSize, int nDstYSize ); 00378 void ReportTiming( const char * ); 00379 00380 public: 00381 GDALWarpOperation(); 00382 virtual ~GDALWarpOperation(); 00383 00384 CPLErr Initialize( const GDALWarpOptions *psNewOptions ); 00385 00386 const GDALWarpOptions *GetOptions(); 00387 00388 CPLErr ChunkAndWarpImage( int nDstXOff, int nDstYOff, 00389 int nDstXSize, int nDstYSize ); 00390 CPLErr ChunkAndWarpMulti( int nDstXOff, int nDstYOff, 00391 int nDstXSize, int nDstYSize ); 00392 CPLErr WarpRegion( int nDstXOff, int nDstYOff, 00393 int nDstXSize, int nDstYSize, 00394 int nSrcXOff=0, int nSrcYOff=0, 00395 int nSrcXSize=0, int nSrcYSize=0, 00396 double dfProgressBase=0.0, double dfProgressScale=1.0); 00397 CPLErr WarpRegion( int nDstXOff, int nDstYOff, 00398 int nDstXSize, int nDstYSize, 00399 int nSrcXOff, int nSrcYOff, 00400 int nSrcXSize, int nSrcYSize, 00401 int nSrcXExtraSize, int nSrcYExtraSize, 00402 double dfProgressBase, double dfProgressScale); 00403 CPLErr WarpRegionToBuffer( int nDstXOff, int nDstYOff, 00404 int nDstXSize, int nDstYSize, 00405 void *pDataBuf, 00406 GDALDataType eBufDataType, 00407 int nSrcXOff=0, int nSrcYOff=0, 00408 int nSrcXSize=0, int nSrcYSize=0, 00409 double dfProgressBase=0.0, double dfProgressScale=1.0); 00410 CPLErr WarpRegionToBuffer( int nDstXOff, int nDstYOff, 00411 int nDstXSize, int nDstYSize, 00412 void *pDataBuf, 00413 GDALDataType eBufDataType, 00414 int nSrcXOff, int nSrcYOff, 00415 int nSrcXSize, int nSrcYSize, 00416 int nSrcXExtraSize, int nSrcYExtraSize, 00417 double dfProgressBase, double dfProgressScale); 00418 }; 00419 00420 #endif /* def __cplusplus */ 00421 00422 CPL_C_START 00423 00424 typedef void * GDALWarpOperationH; 00425 00426 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* ); 00427 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH ); 00428 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int ); 00429 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int ); 00430 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH, 00431 int, int, int, int, int, int, int, int ); 00432 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int, 00433 void *, GDALDataType, 00434 int, int, int, int ); 00435 00436 /************************************************************************/ 00437 /* Warping kernel functions */ 00438 /************************************************************************/ 00439 00440 int GWKGetFilterRadius(GDALResampleAlg eResampleAlg); 00441 00442 typedef double (*FilterFuncType)(double dfX); 00443 FilterFuncType GWKGetFilterFunc(GDALResampleAlg eResampleAlg); 00444 00445 typedef double (*FilterFunc4ValuesType)(double* padfVals); 00446 FilterFunc4ValuesType GWKGetFilterFunc4Values(GDALResampleAlg eResampleAlg); 00447 00448 CPL_C_END 00449 00450 #endif /* ndef GDAL_ALG_H_INCLUDED */