|
GDAL
|
00001 /****************************************************************************** 00002 * $Id: gdalwarper.h 37035 2016-12-29 16:08:53Z goatbar $ 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 00077 typedef int 00078 (*GDALMaskFunc)( void *pMaskFuncArg, 00079 int nBandCount, GDALDataType eType, 00080 int nXOff, int nYOff, 00081 int nXSize, int nYSize, 00082 GByte **papabyImageData, 00083 int bMaskIsFloat, void *pMask ); 00084 00085 CPLErr CPL_DLL 00086 GDALWarpNoDataMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType, 00087 int nXOff, int nYOff, int nXSize, int nYSize, 00088 GByte **papabyImageData, int bMaskIsFloat, 00089 void *pValidityMask, int* pbOutAllValid ); 00090 00091 CPLErr CPL_DLL 00092 GDALWarpDstAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType, 00093 int nXOff, int nYOff, int nXSize, int nYSize, 00094 GByte ** /*ppImageData */, 00095 int bMaskIsFloat, void *pValidityMask ); 00096 CPLErr CPL_DLL 00097 GDALWarpSrcAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType, 00098 int nXOff, int nYOff, int nXSize, int nYSize, 00099 GByte ** /*ppImageData */, 00100 int bMaskIsFloat, void *pValidityMask, int* pbOutAllOpaque ); 00101 00102 CPLErr CPL_DLL 00103 GDALWarpSrcMaskMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType, 00104 int nXOff, int nYOff, int nXSize, int nYSize, 00105 GByte ** /*ppImageData */, 00106 int bMaskIsFloat, void *pValidityMask ); 00107 00108 CPLErr CPL_DLL 00109 GDALWarpCutlineMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType, 00110 int nXOff, int nYOff, int nXSize, int nYSize, 00111 GByte ** /* ppImageData */, 00112 int bMaskIsFloat, void *pValidityMask ); 00115 /************************************************************************/ 00116 /* GDALWarpOptions */ 00117 /************************************************************************/ 00118 00120 typedef struct { 00121 00122 char **papszWarpOptions; 00123 00125 double dfWarpMemoryLimit; 00126 00128 GDALResampleAlg eResampleAlg; 00129 00132 GDALDataType eWorkingDataType; 00133 00135 GDALDatasetH hSrcDS; 00136 00138 GDALDatasetH hDstDS; 00139 00141 int nBandCount; 00142 00144 int *panSrcBands; 00145 00147 int *panDstBands; 00148 00150 int nSrcAlphaBand; 00151 00153 int nDstAlphaBand; 00154 00156 double *padfSrcNoDataReal; 00159 double *padfSrcNoDataImag; 00160 00162 double *padfDstNoDataReal; 00165 double *padfDstNoDataImag; 00166 00169 GDALProgressFunc pfnProgress; 00170 00172 void *pProgressArg; 00173 00175 GDALTransformerFunc pfnTransformer; 00176 00178 void *pTransformerArg; 00179 00181 GDALMaskFunc *papfnSrcPerBandValidityMaskFunc; 00183 void **papSrcPerBandValidityMaskFuncArg; 00184 00186 GDALMaskFunc pfnSrcValidityMaskFunc; 00188 void *pSrcValidityMaskFuncArg; 00189 00191 GDALMaskFunc pfnSrcDensityMaskFunc; 00193 void *pSrcDensityMaskFuncArg; 00194 00196 GDALMaskFunc pfnDstDensityMaskFunc; 00198 void *pDstDensityMaskFuncArg; 00199 00201 GDALMaskFunc pfnDstValidityMaskFunc; 00203 void *pDstValidityMaskFuncArg; 00204 00206 CPLErr (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg ); 00208 void *pPreWarpProcessorArg; 00209 00211 CPLErr (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg); 00213 void *pPostWarpProcessorArg; 00214 00216 void *hCutline; 00217 00219 double dfCutlineBlendDist; 00220 00221 } GDALWarpOptions; 00222 00223 GDALWarpOptions CPL_DLL * CPL_STDCALL GDALCreateWarpOptions(void); 00224 void CPL_DLL CPL_STDCALL GDALDestroyWarpOptions( GDALWarpOptions * ); 00225 GDALWarpOptions CPL_DLL * CPL_STDCALL 00226 GDALCloneWarpOptions( const GDALWarpOptions * ); 00227 00229 CPLXMLNode CPL_DLL * CPL_STDCALL 00230 GDALSerializeWarpOptions( const GDALWarpOptions * ); 00231 GDALWarpOptions CPL_DLL * CPL_STDCALL 00232 GDALDeserializeWarpOptions( CPLXMLNode * ); 00235 /************************************************************************/ 00236 /* GDALReprojectImage() */ 00237 /************************************************************************/ 00238 00239 CPLErr CPL_DLL CPL_STDCALL 00240 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 00241 GDALDatasetH hDstDS, const char *pszDstWKT, 00242 GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit, 00243 double dfMaxError, 00244 GDALProgressFunc pfnProgress, void *pProgressArg, 00245 GDALWarpOptions *psOptions ); 00246 00247 CPLErr CPL_DLL CPL_STDCALL 00248 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 00249 const char *pszDstFilename, const char *pszDstWKT, 00250 GDALDriverH hDstDriver, char **papszCreateOptions, 00251 GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit, 00252 double dfMaxError, 00253 GDALProgressFunc pfnProgress, void *pProgressArg, 00254 GDALWarpOptions *psOptions ); 00255 00256 /************************************************************************/ 00257 /* VRTWarpedDataset */ 00258 /************************************************************************/ 00259 00260 GDALDatasetH CPL_DLL CPL_STDCALL 00261 GDALAutoCreateWarpedVRT( GDALDatasetH hSrcDS, 00262 const char *pszSrcWKT, const char *pszDstWKT, 00263 GDALResampleAlg eResampleAlg, 00264 double dfMaxError, const GDALWarpOptions *psOptions ); 00265 00266 GDALDatasetH CPL_DLL CPL_STDCALL 00267 GDALCreateWarpedVRT( GDALDatasetH hSrcDS, 00268 int nPixels, int nLines, double *padfGeoTransform, 00269 GDALWarpOptions *psOptions ); 00270 00271 CPLErr CPL_DLL CPL_STDCALL 00272 GDALInitializeWarpedVRT( GDALDatasetH hDS, 00273 GDALWarpOptions *psWO ); 00274 00275 CPL_C_END 00276 00277 #ifdef __cplusplus 00278 00279 /************************************************************************/ 00280 /* GDALWarpKernel */ 00281 /* */ 00282 00288 #define WARP_EXTRA_ELTS 1 00289 00297 class CPL_DLL GDALWarpKernel 00298 { 00299 public: 00301 char **papszWarpOptions; 00302 00304 GDALResampleAlg eResample; 00306 GDALDataType eWorkingDataType; 00308 int nBands; 00309 00311 int nSrcXSize; 00313 int nSrcYSize; 00315 int nSrcXExtraSize; 00317 int nSrcYExtraSize; 00319 GByte **papabySrcImage; 00320 00322 GUInt32 **papanBandSrcValid; 00324 GUInt32 *panUnifiedSrcValid; 00326 float *pafUnifiedSrcDensity; 00327 00329 int nDstXSize; 00331 int nDstYSize; 00333 GByte **papabyDstImage; 00335 GUInt32 *panDstValid; 00337 float *pafDstDensity; 00338 00340 double dfXScale; 00342 double dfYScale; 00344 double dfXFilter; 00346 double dfYFilter; 00348 int nXRadius; 00350 int nYRadius; 00352 int nFiltInitX; 00354 int nFiltInitY; 00355 00357 int nSrcXOff; 00359 int nSrcYOff; 00360 00362 int nDstXOff; 00364 int nDstYOff; 00365 00367 GDALTransformerFunc pfnTransformer; 00369 void *pTransformerArg; 00370 00372 GDALProgressFunc pfnProgress; 00374 void *pProgress; 00375 00377 double dfProgressBase; 00379 double dfProgressScale; 00380 00382 double *padfDstNoDataReal; 00383 00386 void *psThreadData; 00389 GDALWarpKernel(); 00390 virtual ~GDALWarpKernel(); 00391 00392 CPLErr Validate(); 00393 CPLErr PerformWarp(); 00394 }; 00395 00397 void* GWKThreadsCreate(char** papszWarpOptions, 00398 GDALTransformerFunc pfnTransformer, 00399 void* pTransformerArg); 00400 void GWKThreadsEnd(void* psThreadDataIn); 00403 /************************************************************************/ 00404 /* GDALWarpOperation() */ 00405 /* */ 00406 /* This object is application created, or created by a higher */ 00407 /* level convenience function. It is responsible for */ 00408 /* subdividing the operation into chunks, loading and saving */ 00409 /* imagery, and establishing the varios validity and density */ 00410 /* masks. Actual resampling is done by the GDALWarpKernel. */ 00411 /************************************************************************/ 00412 00414 typedef struct _GDALWarpChunk GDALWarpChunk; 00417 class CPL_DLL GDALWarpOperation { 00418 private: 00419 GDALWarpOptions *psOptions; 00420 00421 void WipeOptions(); 00422 int ValidateOptions(); 00423 00424 CPLErr ComputeSourceWindow( int nDstXOff, int nDstYOff, 00425 int nDstXSize, int nDstYSize, 00426 int *pnSrcXOff, int *pnSrcYOff, 00427 int *pnSrcXSize, int *pnSrcYSize, 00428 int *pnSrcXExtraSize, int *pnSrcYExtraSize, 00429 double* pdfSrcFillRatio ); 00430 00431 static CPLErr CreateKernelMask( GDALWarpKernel *, int iBand, 00432 const char *pszType ); 00433 00434 CPLMutex *hIOMutex; 00435 CPLMutex *hWarpMutex; 00436 00437 int nChunkListCount; 00438 int nChunkListMax; 00439 GDALWarpChunk *pasChunkList; 00440 00441 int bReportTimings; 00442 unsigned long nLastTimeReported; 00443 00444 void *psThreadData; 00445 00446 void WipeChunkList(); 00447 CPLErr CollectChunkList( int nDstXOff, int nDstYOff, 00448 int nDstXSize, int nDstYSize ); 00449 void ReportTiming( const char * ); 00450 00451 public: 00452 GDALWarpOperation(); 00453 virtual ~GDALWarpOperation(); 00454 00455 CPLErr Initialize( const GDALWarpOptions *psNewOptions ); 00456 00457 const GDALWarpOptions *GetOptions(); 00458 00459 CPLErr ChunkAndWarpImage( int nDstXOff, int nDstYOff, 00460 int nDstXSize, int nDstYSize ); 00461 CPLErr ChunkAndWarpMulti( int nDstXOff, int nDstYOff, 00462 int nDstXSize, int nDstYSize ); 00463 CPLErr WarpRegion( int nDstXOff, int nDstYOff, 00464 int nDstXSize, int nDstYSize, 00465 int nSrcXOff=0, int nSrcYOff=0, 00466 int nSrcXSize=0, int nSrcYSize=0, 00467 double dfProgressBase=0.0, double dfProgressScale=1.0); 00468 CPLErr WarpRegion( int nDstXOff, int nDstYOff, 00469 int nDstXSize, int nDstYSize, 00470 int nSrcXOff, int nSrcYOff, 00471 int nSrcXSize, int nSrcYSize, 00472 int nSrcXExtraSize, int nSrcYExtraSize, 00473 double dfProgressBase, double dfProgressScale); 00474 CPLErr WarpRegionToBuffer( int nDstXOff, int nDstYOff, 00475 int nDstXSize, int nDstYSize, 00476 void *pDataBuf, 00477 GDALDataType eBufDataType, 00478 int nSrcXOff=0, int nSrcYOff=0, 00479 int nSrcXSize=0, int nSrcYSize=0, 00480 double dfProgressBase=0.0, double dfProgressScale=1.0); 00481 CPLErr WarpRegionToBuffer( int nDstXOff, int nDstYOff, 00482 int nDstXSize, int nDstYSize, 00483 void *pDataBuf, 00484 GDALDataType eBufDataType, 00485 int nSrcXOff, int nSrcYOff, 00486 int nSrcXSize, int nSrcYSize, 00487 int nSrcXExtraSize, int nSrcYExtraSize, 00488 double dfProgressBase, double dfProgressScale); 00489 }; 00490 00491 #endif /* def __cplusplus */ 00492 00493 CPL_C_START 00494 00496 typedef void * GDALWarpOperationH; 00497 00498 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* ); 00499 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH ); 00500 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int ); 00501 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int ); 00502 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH, 00503 int, int, int, int, int, int, int, int ); 00504 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int, 00505 void *, GDALDataType, 00506 int, int, int, int ); 00507 00508 /************************************************************************/ 00509 /* Warping kernel functions */ 00510 /************************************************************************/ 00511 00513 int GWKGetFilterRadius(GDALResampleAlg eResampleAlg); 00514 00515 typedef double (*FilterFuncType)(double dfX); 00516 FilterFuncType GWKGetFilterFunc(GDALResampleAlg eResampleAlg); 00517 00518 // TODO(schwehr): Can padfVals be a const pointer? 00519 typedef double (*FilterFunc4ValuesType)(double* padfVals); 00520 FilterFunc4ValuesType GWKGetFilterFunc4Values(GDALResampleAlg eResampleAlg); 00523 CPL_C_END 00524 00525 #endif /* ndef GDAL_ALG_H_INCLUDED */
1.7.6.1.