- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# gdalwarper.h

Go to the documentation of this file.

    00001 /******************************************************************************
    00002  * $Id: gdalwarper.h 25884 2013-04-09 17:04:16Z etourigny $
    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  *
    00011  * Permission is hereby granted, free of charge, to any person obtaining a
    00012  * copy of this software and associated documentation files (the "Software"),
    00013  * to deal in the Software without restriction, including without limitation
    00014  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00015  * and/or sell copies of the Software, and to permit persons to whom the
    00016  * Software is furnished to do so, subject to the following conditions:
    00017  *
    00018  * The above copyright notice and this permission notice shall be included
    00019  * in all copies or substantial portions of the Software.
    00020  *
    00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    00022  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    00024  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00025  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    00026  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    00027  * DEALINGS IN THE SOFTWARE.
    00028  ****************************************************************************/
    00029
    00030 #ifndef GDALWARPER_H_INCLUDED
    00031 #define GDALWARPER_H_INCLUDED
    00032
    00041 #include "gdal_alg.h"
    00042 #include "cpl_minixml.h"
    00043
    00044 CPL_C_START
    00045
    00047 typedef enum { GRA_NearestNeighbour=0,                         GRA_Bilinear=1,  GRA_Cubic=2,     GRA_CubicSpline=3, GRA_Lanczos=4, GRA_Average=5,  GRA_Mode=6
    00055 } GDALResampleAlg;
    00056
    00057 typedef int
    00058 (*GDALMaskFunc)( void *pMaskFuncArg,
    00059                  int nBandCount, GDALDataType eType,
    00060                  int nXOff, int nYOff,
    00061                  int nXSize, int nYSize,
    00062                  GByte **papabyImageData,
    00063                  int bMaskIsFloat, void *pMask );
    00064
    00065 CPLErr CPL_DLL
    00066 GDALWarpNoDataMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
    00067                       int nXOff, int nYOff, int nXSize, int nYSize,
    00068                       GByte **papabyImageData, int bMaskIsFloat,
    00069                       void *pValidityMask );
    00070
    00071 CPLErr CPL_DLL
    00072 GDALWarpDstAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
    00073                         int nXOff, int nYOff, int nXSize, int nYSize,
    00074                         GByte ** /*ppImageData */,
    00075                         int bMaskIsFloat, void *pValidityMask );
    00076 CPLErr CPL_DLL
    00077 GDALWarpSrcAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
    00078                         int nXOff, int nYOff, int nXSize, int nYSize,
    00079                         GByte ** /*ppImageData */,
    00080                         int bMaskIsFloat, void *pValidityMask );
    00081
    00082 CPLErr CPL_DLL
    00083 GDALWarpSrcMaskMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
    00084                        int nXOff, int nYOff, int nXSize, int nYSize,
    00085                        GByte ** /*ppImageData */,
    00086                        int bMaskIsFloat, void *pValidityMask );
    00087
    00088 CPLErr CPL_DLL
    00089 GDALWarpCutlineMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
    00090                        int nXOff, int nYOff, int nXSize, int nYSize,
    00091                        GByte ** /* ppImageData */,
    00092                        int bMaskIsFloat, void *pValidityMask );
    00093
    00094 /************************************************************************/
    00095 /*                           GDALWarpOptions                            */
    00096 /************************************************************************/
    00097
    00099 typedef struct {
    00100
    00101     char              **papszWarpOptions;
    00102
    00104     double              dfWarpMemoryLimit;
    00105
    00107     GDALResampleAlg     eResampleAlg;
    00108
    00111     GDALDataType        eWorkingDataType;
    00112
    00114     GDALDatasetH        hSrcDS;
    00115
    00117     GDALDatasetH        hDstDS;
    00118
    00120     int                 nBandCount;
    00121
    00123     int                *panSrcBands;
    00124
    00126     int                *panDstBands;
    00127
    00129     int                nSrcAlphaBand;
    00130
    00132     int                nDstAlphaBand;
    00133
    00135     double             *padfSrcNoDataReal;
    00138     double             *padfSrcNoDataImag;
    00139
    00141     double             *padfDstNoDataReal;
    00144     double             *padfDstNoDataImag;
    00145
    00148     GDALProgressFunc    pfnProgress;
    00149
    00151     void               *pProgressArg;
    00152
    00154     GDALTransformerFunc pfnTransformer;
    00155
    00157     void                *pTransformerArg;
    00158
    00159     GDALMaskFunc       *papfnSrcPerBandValidityMaskFunc;
    00160     void              **papSrcPerBandValidityMaskFuncArg;
    00161
    00162     GDALMaskFunc        pfnSrcValidityMaskFunc;
    00163     void               *pSrcValidityMaskFuncArg;
    00164
    00165     GDALMaskFunc        pfnSrcDensityMaskFunc;
    00166     void               *pSrcDensityMaskFuncArg;
    00167
    00168     GDALMaskFunc        pfnDstDensityMaskFunc;
    00169     void               *pDstDensityMaskFuncArg;
    00170
    00171     GDALMaskFunc        pfnDstValidityMaskFunc;
    00172     void               *pDstValidityMaskFuncArg;
    00173
    00174     CPLErr              (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg );
    00175     void               *pPreWarpProcessorArg;
    00176
    00177     CPLErr              (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg);
    00178     void               *pPostWarpProcessorArg;
    00179
    00181     void               *hCutline;
    00182
    00184     double              dfCutlineBlendDist;
    00185
    00186 } GDALWarpOptions;
    00187
    00188 GDALWarpOptions CPL_DLL * CPL_STDCALL GDALCreateWarpOptions(void);
    00189 void CPL_DLL CPL_STDCALL GDALDestroyWarpOptions( GDALWarpOptions * );
    00190 GDALWarpOptions CPL_DLL * CPL_STDCALL
    00191 GDALCloneWarpOptions( const GDALWarpOptions * );
    00192
    00193 CPLXMLNode CPL_DLL * CPL_STDCALL
    00194       GDALSerializeWarpOptions( const GDALWarpOptions * );
    00195 GDALWarpOptions CPL_DLL * CPL_STDCALL
    00196       GDALDeserializeWarpOptions( CPLXMLNode * );
    00197
    00198 /************************************************************************/
    00199 /*                         GDALReprojectImage()                         */
    00200 /************************************************************************/
    00201
    00202 CPLErr CPL_DLL CPL_STDCALL
    00203 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT,
    00204                     GDALDatasetH hDstDS, const char *pszDstWKT,
    00205                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
    00206                     double dfMaxError,
    00207                     GDALProgressFunc pfnProgress, void *pProgressArg,
    00208                     GDALWarpOptions *psOptions );
    00209
    00210 CPLErr CPL_DLL CPL_STDCALL
    00211 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT,
    00212                     const char *pszDstFilename, const char *pszDstWKT,
    00213                     GDALDriverH hDstDriver, char **papszCreateOptions,
    00214                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
    00215                     double dfMaxError,
    00216                     GDALProgressFunc pfnProgress, void *pProgressArg,
    00217                     GDALWarpOptions *psOptions );
    00218
    00219 /************************************************************************/
    00220 /*                           VRTWarpedDataset                           */
    00221 /************************************************************************/
    00222
    00223 GDALDatasetH CPL_DLL CPL_STDCALL
    00224 GDALAutoCreateWarpedVRT( GDALDatasetH hSrcDS,
    00225                          const char *pszSrcWKT, const char *pszDstWKT,
    00226                          GDALResampleAlg eResampleAlg,
    00227                          double dfMaxError, const GDALWarpOptions *psOptions );
    00228
    00229 GDALDatasetH CPL_DLL CPL_STDCALL
    00230 GDALCreateWarpedVRT( GDALDatasetH hSrcDS,
    00231                      int nPixels, int nLines, double *padfGeoTransform,
    00232                      GDALWarpOptions *psOptions );
    00233
    00234 CPLErr CPL_DLL CPL_STDCALL
    00235 GDALInitializeWarpedVRT( GDALDatasetH hDS,
    00236                          GDALWarpOptions *psWO );
    00237
    00238 CPL_C_END
    00239
    00240 #ifdef __cplusplus
    00241
    00242 /************************************************************************/
    00243 /*                            GDALWarpKernel                            */
    00244 /*                                                                      */
    00245 /*      This class represents the lowest level of abstraction.  It      */
    00246 /*      is holds the imagery for one "chunk" of a warp, and the         */
    00247 /*      pre-prepared masks.  All IO is done before and after it's       */
    00248 /*      operation.  This class is not normally used by the              */
    00249 /*      application.                                                    */
    00250 /************************************************************************/
    00251
    00252 // This is the number of dummy pixels that must be reserved in source arrays
    00253 // in order to satisfy assumptions made in GWKResample(), and more specifically
    00254 // by GWKGetPixelRow() that always read a even number of pixels. So if we are
    00255 // in the situation to read the last pixel of the source array, we need 1 extra
    00256 // dummy pixel to avoid reading out of bounds.
    00257 #define WARP_EXTRA_ELTS    1
    00258
    00259 class CPL_DLL GDALWarpKernel
    00260 {
    00261 public:
    00262     char              **papszWarpOptions;
    00263
    00264     GDALResampleAlg     eResample;
    00265     GDALDataType        eWorkingDataType;
    00266     int                 nBands;
    00267
    00268     int                 nSrcXSize;
    00269     int                 nSrcYSize;
    00270     GByte               **papabySrcImage; /* each subarray must have WARP_EXTRA_ELTS at the end */
    00271
    00272     GUInt32           **papanBandSrcValid; /* each subarray must have WARP_EXTRA_ELTS at the end */
    00273     GUInt32            *panUnifiedSrcValid; /* must have WARP_EXTRA_ELTS at the end */
    00274     float              *pafUnifiedSrcDensity; /* must have WARP_EXTRA_ELTS at the end */
    00275
    00276     int                 nDstXSize;
    00277     int                 nDstYSize;
    00278     GByte             **papabyDstImage;
    00279     GUInt32            *panDstValid;
    00280     float              *pafDstDensity;
    00281
    00282     double              dfXScale;   // Resampling scale, i.e.
    00283     double              dfYScale;   // nDstSize/nSrcSize.
    00284     double              dfXFilter;  // Size of filter kernel.
    00285     double              dfYFilter;
    00286     int                 nXRadius;   // Size of window to filter.
    00287     int                 nYRadius;
    00288     int                 nFiltInitX; // Filtering offset
    00289     int                 nFiltInitY;
    00290
    00291     int                 nSrcXOff;
    00292     int                 nSrcYOff;
    00293
    00294     int                 nDstXOff;
    00295     int                 nDstYOff;
    00296
    00297     GDALTransformerFunc pfnTransformer;
    00298     void                *pTransformerArg;
    00299
    00300     GDALProgressFunc    pfnProgress;
    00301     void                *pProgress;
    00302
    00303     double              dfProgressBase;
    00304     double              dfProgressScale;
    00305
    00306     double              *padfDstNoDataReal;
    00307
    00308                        GDALWarpKernel();
    00309     virtual           ~GDALWarpKernel();
    00310
    00311     CPLErr              Validate();
    00312     CPLErr              PerformWarp();
    00313 };
    00314
    00315 /************************************************************************/
    00316 /*                         GDALWarpOperation()                          */
    00317 /*                                                                      */
    00318 /*      This object is application created, or created by a higher      */
    00319 /*      level convenience function.  It is responsible for              */
    00320 /*      subdividing the operation into chunks, loading and saving       */
    00321 /*      imagery, and establishing the varios validity and density       */
    00322 /*      masks.  Actual resampling is done by the GDALWarpKernel.        */
    00323 /************************************************************************/
    00324
    00325 class CPL_DLL GDALWarpOperation {
    00326 private:
    00327     GDALWarpOptions *psOptions;
    00328
    00329     void            WipeOptions();
    00330     int             ValidateOptions();
    00331
    00332     CPLErr          ComputeSourceWindow( int nDstXOff, int nDstYOff,
    00333                                          int nDstXSize, int nDstYSize,
    00334                                          int *pnSrcXOff, int *pnSrcYOff,
    00335                                          int *pnSrcXSize, int *pnSrcYSize );
    00336
    00337     CPLErr          CreateKernelMask( GDALWarpKernel *, int iBand,
    00338                                       const char *pszType );
    00339
    00340     void            *unused1;
    00341     void            *unused2;
    00342     void            *hIOMutex;
    00343     void            *hWarpMutex;
    00344
    00345     int             nChunkListCount;
    00346     int             nChunkListMax;
    00347     int            *panChunkList;
    00348
    00349     int             bReportTimings;
    00350     unsigned long   nLastTimeReported;
    00351
    00352     void            WipeChunkList();
    00353     CPLErr          CollectChunkList( int nDstXOff, int nDstYOff,
    00354                                       int nDstXSize, int nDstYSize );
    00355     void            ReportTiming( const char * );
    00356
    00357 public:
    00358                     GDALWarpOperation();
    00359     virtual        ~GDALWarpOperation();
    00360
    00361     CPLErr          Initialize( const GDALWarpOptions *psNewOptions );
    00362
    00363     const GDALWarpOptions         *GetOptions();
    00364
    00365     CPLErr          ChunkAndWarpImage( int nDstXOff, int nDstYOff,
    00366                                        int nDstXSize, int nDstYSize );
    00367     CPLErr          ChunkAndWarpMulti( int nDstXOff, int nDstYOff,
    00368                                        int nDstXSize, int nDstYSize );
    00369     CPLErr          WarpRegion( int nDstXOff, int nDstYOff,
    00370                                 int nDstXSize, int nDstYSize,
    00371                                 int nSrcXOff=0, int nSrcYOff=0,
    00372                                 int nSrcXSize=0, int nSrcYSize=0,
    00373                                 double dfProgressBase=0.0, double dfProgressScale=1.0);
    00374
    00375     CPLErr          WarpRegionToBuffer( int nDstXOff, int nDstYOff,
    00376                                         int nDstXSize, int nDstYSize,
    00377                                         void *pDataBuf,
    00378                                         GDALDataType eBufDataType,
    00379                                         int nSrcXOff=0, int nSrcYOff=0,
    00380                                         int nSrcXSize=0, int nSrcYSize=0,
    00381                                         double dfProgressBase=0.0, double dfProgressScale=1.0);
    00382 };
    00383
    00384 #endif /* def __cplusplus */
    00385
    00386 CPL_C_START
    00387
    00388 typedef void * GDALWarpOperationH;
    00389
    00390 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* );
    00391 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH );
    00392 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int );
    00393 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int );
    00394 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH,
    00395                                int, int, int, int, int, int, int, int );
    00396 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int,
    00397                                        void *, GDALDataType,
    00398                                        int, int, int, int );
    00399
    00400 CPL_C_END
    00401
    00402 #endif /* ndef GDAL_ALG_H_INCLUDED */

Generated for GDAL by 1.7.1.