00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 #ifndef GDALWARPER_H_INCLUDED
00085 #define GDALWARPER_H_INCLUDED
00086
00095 #include "gdal_alg.h"
00096 #include "cpl_minixml.h"
00097
00098 CPL_C_START
00099
00101 typedef enum { GRA_NearestNeighbour=0, GRA_Bilinear=1, GRA_Cubic=2, GRA_CubicSpline=3,
00106 } GDALResampleAlg;
00107
00108 typedef int
00109 (*GDALMaskFunc)( void *pMaskFuncArg,
00110 int nBandCount, GDALDataType eType,
00111 int nXOff, int nYOff,
00112 int nXSize, int nYSize,
00113 GByte **papabyImageData,
00114 int bMaskIsFloat, void *pMask );
00115
00116 CPLErr CPL_DLL
00117 GDALWarpNoDataMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00118 int nXOff, int nYOff, int nXSize, int nYSize,
00119 GByte **papabyImageData, int bMaskIsFloat,
00120 void *pValidityMask );
00121
00122 CPLErr CPL_DLL
00123 GDALWarpDstAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00124 int nXOff, int nYOff, int nXSize, int nYSize,
00125 GByte ** ,
00126 int bMaskIsFloat, void *pValidityMask );
00127 CPLErr CPL_DLL
00128 GDALWarpSrcAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00129 int nXOff, int nYOff, int nXSize, int nYSize,
00130 GByte ** ,
00131 int bMaskIsFloat, void *pValidityMask );
00132
00133
00134
00135
00136
00138 typedef struct {
00139
00140 char **papszWarpOptions;
00141
00143 double dfWarpMemoryLimit;
00144
00146 GDALResampleAlg eResampleAlg;
00147
00150 GDALDataType eWorkingDataType;
00151
00153 GDALDatasetH hSrcDS;
00154
00156 GDALDatasetH hDstDS;
00157
00159 int nBandCount;
00160
00162 int *panSrcBands;
00163
00165 int *panDstBands;
00166
00168 int nSrcAlphaBand;
00169
00171 int nDstAlphaBand;
00172
00174 double *padfSrcNoDataReal;
00177 double *padfSrcNoDataImag;
00178
00180 double *padfDstNoDataReal;
00183 double *padfDstNoDataImag;
00184
00187 GDALProgressFunc pfnProgress;
00188
00190 void *pProgressArg;
00191
00193 GDALTransformerFunc pfnTransformer;
00194
00196 void *pTransformerArg;
00197
00198 GDALMaskFunc *papfnSrcPerBandValidityMaskFunc;
00199 void **papSrcPerBandValidityMaskFuncArg;
00200
00201 GDALMaskFunc pfnSrcValidityMaskFunc;
00202 void *pSrcValidityMaskFuncArg;
00203
00204 GDALMaskFunc pfnSrcDensityMaskFunc;
00205 void *pSrcDensityMaskFuncArg;
00206
00207 GDALMaskFunc pfnDstDensityMaskFunc;
00208 void *pDstDensityMaskFuncArg;
00209
00210 GDALMaskFunc pfnDstValidityMaskFunc;
00211 void *pDstValidityMaskFuncArg;
00212
00213 CPLErr (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg );
00214 void *pPreWarpProcessorArg;
00215
00216 CPLErr (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg);
00217 void *pPostWarpProcessorArg;
00218
00219 } GDALWarpOptions;
00220
00221 GDALWarpOptions CPL_DLL * CPL_STDCALL GDALCreateWarpOptions();
00222 void CPL_DLL CPL_STDCALL GDALDestroyWarpOptions( GDALWarpOptions * );
00223 GDALWarpOptions CPL_DLL * CPL_STDCALL
00224 GDALCloneWarpOptions( const GDALWarpOptions * );
00225
00226 CPLXMLNode CPL_DLL * CPL_STDCALL
00227 GDALSerializeWarpOptions( const GDALWarpOptions * );
00228 GDALWarpOptions CPL_DLL * CPL_STDCALL
00229 GDALDeserializeWarpOptions( CPLXMLNode * );
00230
00231
00232
00233
00234
00235 CPLErr CPL_DLL CPL_STDCALL
00236 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT,
00237 GDALDatasetH hDstDS, const char *pszDstWKT,
00238 GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00239 double dfMaxError,
00240 GDALProgressFunc pfnProgress, void *pProgressArg,
00241 GDALWarpOptions *psOptions );
00242
00243 CPLErr CPL_DLL CPL_STDCALL
00244 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT,
00245 const char *pszDstFilename, const char *pszDstWKT,
00246 GDALDriverH hDstDriver, char **papszCreateOptions,
00247 GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00248 double dfMaxError,
00249 GDALProgressFunc pfnProgress, void *pProgressArg,
00250 GDALWarpOptions *psOptions );
00251
00252
00253
00254
00255
00256 GDALDatasetH CPL_DLL CPL_STDCALL
00257 GDALAutoCreateWarpedVRT( GDALDatasetH hSrcDS,
00258 const char *pszSrcWKT, const char *pszDstWKT,
00259 GDALResampleAlg eResampleAlg,
00260 double dfMaxError, const GDALWarpOptions *psOptions );
00261
00262 GDALDatasetH CPL_DLL CPL_STDCALL
00263 GDALCreateWarpedVRT( GDALDatasetH hSrcDS,
00264 int nPixels, int nLines, double *padfGeoTransform,
00265 GDALWarpOptions *psOptions );
00266
00267 CPLErr CPL_DLL CPL_STDCALL
00268 GDALInitializeWarpedVRT( GDALDatasetH hDS,
00269 GDALWarpOptions *psWO );
00270
00271 CPL_C_END
00272
00273 #ifdef __cplusplus
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 class CPL_DLL GDALWarpKernel
00286 {
00287 public:
00288 GDALWarpKernel();
00289 virtual ~GDALWarpKernel();
00290
00291 char **papszWarpOptions;
00292
00293 GDALResampleAlg eResample;
00294 GDALDataType eWorkingDataType;
00295 int nBands;
00296
00297 int nSrcXSize;
00298 int nSrcYSize;
00299 GByte **papabySrcImage;
00300
00301 GUInt32 **papanBandSrcValid;
00302 GUInt32 *panUnifiedSrcValid;
00303 float *pafUnifiedSrcDensity;
00304
00305 int nDstXSize;
00306 int nDstYSize;
00307 GByte **papabyDstImage;
00308 GUInt32 *panDstValid;
00309 float *pafDstDensity;
00310
00311 int nSrcXOff;
00312 int nSrcYOff;
00313
00314 int nDstXOff;
00315 int nDstYOff;
00316
00317 GDALTransformerFunc pfnTransformer;
00318 void *pTransformerArg;
00319
00320 GDALProgressFunc pfnProgress;
00321 void *pProgress;
00322
00323 double dfProgressBase;
00324 double dfProgressScale;
00325
00326 CPLErr Validate();
00327 CPLErr PerformWarp();
00328 };
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 class CPL_DLL GDALWarpOperation {
00341 private:
00342 GDALWarpOptions *psOptions;
00343
00344 double dfProgressBase;
00345 double dfProgressScale;
00346
00347 void WipeOptions();
00348 int ValidateOptions();
00349
00350 CPLErr ComputeSourceWindow( int nDstXOff, int nDstYOff,
00351 int nDstXSize, int nDstYSize,
00352 int *pnSrcXOff, int *pnSrcYOff,
00353 int *pnSrcXSize, int *pnSrcYSize );
00354
00355 CPLErr CreateKernelMask( GDALWarpKernel *, int iBand,
00356 const char *pszType );
00357
00358 void *hThread1Mutex;
00359 void *hThread2Mutex;
00360 void *hIOMutex;
00361 void *hWarpMutex;
00362
00363 int nChunkListCount;
00364 int nChunkListMax;
00365 int *panChunkList;
00366
00367 int bReportTimings;
00368 unsigned long nLastTimeReported;
00369
00370 void WipeChunkList();
00371 CPLErr CollectChunkList( int nDstXOff, int nDstYOff,
00372 int nDstXSize, int nDstYSize );
00373 void ReportTiming( const char * );
00374
00375 public:
00376 GDALWarpOperation();
00377 virtual ~GDALWarpOperation();
00378
00379 CPLErr Initialize( const GDALWarpOptions *psNewOptions );
00380
00381 const GDALWarpOptions *GetOptions();
00382
00383 CPLErr ChunkAndWarpImage( int nDstXOff, int nDstYOff,
00384 int nDstXSize, int nDstYSize );
00385 CPLErr ChunkAndWarpMulti( int nDstXOff, int nDstYOff,
00386 int nDstXSize, int nDstYSize );
00387 CPLErr WarpRegion( int nDstXOff, int nDstYOff,
00388 int nDstXSize, int nDstYSize,
00389 int nSrcXOff=0, int nSrcYOff=0,
00390 int nSrcXSize=0, int nSrcYSize=0 );
00391
00392 CPLErr WarpRegionToBuffer( int nDstXOff, int nDstYOff,
00393 int nDstXSize, int nDstYSize,
00394 void *pDataBuf,
00395 GDALDataType eBufDataType,
00396 int nSrcXOff=0, int nSrcYOff=0,
00397 int nSrcXSize=0, int nSrcYSize=0 );
00398 };
00399
00400 #endif
00401
00402 CPL_C_START
00403
00404 typedef void * GDALWarpOperationH;
00405
00406 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* );
00407 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH );
00408 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int );
00409 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int );
00410 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH,
00411 int, int, int, int, int, int, int, int );
00412 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int,
00413 void *, GDALDataType,
00414 int, int, int, int );
00415
00416 CPL_C_END
00417
00418 #endif