- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# gdalwarper.h

Go to the documentation of this file.

    00001 /******************************************************************************
    00002  * $Id: gdalwarper.h 27044 2014-03-16 23:41:27Z 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
    00045 CPL_C_START
    00046
    00048 typedef enum { GRA_NearestNeighbour=0,                         GRA_Bilinear=1,  GRA_Cubic=2,     GRA_CubicSpline=3, GRA_Lanczos=4, GRA_Average=5,  GRA_Mode=6
    00056 } GDALResampleAlg;
    00057
    00058 typedef int
    00059 (*GDALMaskFunc)( void *pMaskFuncArg,
    00060                  int nBandCount, GDALDataType eType,
    00061                  int nXOff, int nYOff,
    00062                  int nXSize, int nYSize,
    00063                  GByte **papabyImageData,
    00064                  int bMaskIsFloat, void *pMask );
    00065
    00066 CPLErr CPL_DLL
    00067 GDALWarpNoDataMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
    00068                       int nXOff, int nYOff, int nXSize, int nYSize,
    00069                       GByte **papabyImageData, int bMaskIsFloat,
    00070                       void *pValidityMask );
    00071
    00072 CPLErr CPL_DLL
    00073 GDALWarpDstAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
    00074                         int nXOff, int nYOff, int nXSize, int nYSize,
    00075                         GByte ** /*ppImageData */,
    00076                         int bMaskIsFloat, void *pValidityMask );
    00077 CPLErr CPL_DLL
    00078 GDALWarpSrcAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
    00079                         int nXOff, int nYOff, int nXSize, int nYSize,
    00080                         GByte ** /*ppImageData */,
    00081                         int bMaskIsFloat, void *pValidityMask );
    00082
    00083 CPLErr CPL_DLL
    00084 GDALWarpSrcMaskMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
    00085                        int nXOff, int nYOff, int nXSize, int nYSize,
    00086                        GByte ** /*ppImageData */,
    00087                        int bMaskIsFloat, void *pValidityMask );
    00088
    00089 CPLErr CPL_DLL
    00090 GDALWarpCutlineMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
    00091                        int nXOff, int nYOff, int nXSize, int nYSize,
    00092                        GByte ** /* ppImageData */,
    00093                        int bMaskIsFloat, void *pValidityMask );
    00094
    00095 /************************************************************************/
    00096 /*                           GDALWarpOptions                            */
    00097 /************************************************************************/
    00098
    00100 typedef struct {
    00101
    00102     char              **papszWarpOptions;
    00103
    00105     double              dfWarpMemoryLimit;
    00106
    00108     GDALResampleAlg     eResampleAlg;
    00109
    00112     GDALDataType        eWorkingDataType;
    00113
    00115     GDALDatasetH        hSrcDS;
    00116
    00118     GDALDatasetH        hDstDS;
    00119
    00121     int                 nBandCount;
    00122
    00124     int                *panSrcBands;
    00125
    00127     int                *panDstBands;
    00128
    00130     int                nSrcAlphaBand;
    00131
    00133     int                nDstAlphaBand;
    00134
    00136     double             *padfSrcNoDataReal;
    00139     double             *padfSrcNoDataImag;
    00140
    00142     double             *padfDstNoDataReal;
    00145     double             *padfDstNoDataImag;
    00146
    00149     GDALProgressFunc    pfnProgress;
    00150
    00152     void               *pProgressArg;
    00153
    00155     GDALTransformerFunc pfnTransformer;
    00156
    00158     void                *pTransformerArg;
    00159
    00160     GDALMaskFunc       *papfnSrcPerBandValidityMaskFunc;
    00161     void              **papSrcPerBandValidityMaskFuncArg;
    00162
    00163     GDALMaskFunc        pfnSrcValidityMaskFunc;
    00164     void               *pSrcValidityMaskFuncArg;
    00165
    00166     GDALMaskFunc        pfnSrcDensityMaskFunc;
    00167     void               *pSrcDensityMaskFuncArg;
    00168
    00169     GDALMaskFunc        pfnDstDensityMaskFunc;
    00170     void               *pDstDensityMaskFuncArg;
    00171
    00172     GDALMaskFunc        pfnDstValidityMaskFunc;
    00173     void               *pDstValidityMaskFuncArg;
    00174
    00175     CPLErr              (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg );
    00176     void               *pPreWarpProcessorArg;
    00177
    00178     CPLErr              (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg);
    00179     void               *pPostWarpProcessorArg;
    00180
    00182     void               *hCutline;
    00183
    00185     double              dfCutlineBlendDist;
    00186
    00187 } GDALWarpOptions;
    00188
    00189 GDALWarpOptions CPL_DLL * CPL_STDCALL GDALCreateWarpOptions(void);
    00190 void CPL_DLL CPL_STDCALL GDALDestroyWarpOptions( GDALWarpOptions * );
    00191 GDALWarpOptions CPL_DLL * CPL_STDCALL
    00192 GDALCloneWarpOptions( const GDALWarpOptions * );
    00193
    00194 CPLXMLNode CPL_DLL * CPL_STDCALL
    00195       GDALSerializeWarpOptions( const GDALWarpOptions * );
    00196 GDALWarpOptions CPL_DLL * CPL_STDCALL
    00197       GDALDeserializeWarpOptions( CPLXMLNode * );
    00198
    00199 /************************************************************************/
    00200 /*                         GDALReprojectImage()                         */
    00201 /************************************************************************/
    00202
    00203 CPLErr CPL_DLL CPL_STDCALL
    00204 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT,
    00205                     GDALDatasetH hDstDS, const char *pszDstWKT,
    00206                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
    00207                     double dfMaxError,
    00208                     GDALProgressFunc pfnProgress, void *pProgressArg,
    00209                     GDALWarpOptions *psOptions );
    00210
    00211 CPLErr CPL_DLL CPL_STDCALL
    00212 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT,
    00213                     const char *pszDstFilename, const char *pszDstWKT,
    00214                     GDALDriverH hDstDriver, char **papszCreateOptions,
    00215                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
    00216                     double dfMaxError,
    00217                     GDALProgressFunc pfnProgress, void *pProgressArg,
    00218                     GDALWarpOptions *psOptions );
    00219
    00220 /************************************************************************/
    00221 /*                           VRTWarpedDataset                           */
    00222 /************************************************************************/
    00223
    00224 GDALDatasetH CPL_DLL CPL_STDCALL
    00225 GDALAutoCreateWarpedVRT( GDALDatasetH hSrcDS,
    00226                          const char *pszSrcWKT, const char *pszDstWKT,
    00227                          GDALResampleAlg eResampleAlg,
    00228                          double dfMaxError, const GDALWarpOptions *psOptions );
    00229
    00230 GDALDatasetH CPL_DLL CPL_STDCALL
    00231 GDALCreateWarpedVRT( GDALDatasetH hSrcDS,
    00232                      int nPixels, int nLines, double *padfGeoTransform,
    00233                      GDALWarpOptions *psOptions );
    00234
    00235 CPLErr CPL_DLL CPL_STDCALL
    00236 GDALInitializeWarpedVRT( GDALDatasetH hDS,
    00237                          GDALWarpOptions *psWO );
    00238
    00239 CPL_C_END
    00240
    00241 #ifdef __cplusplus
    00242
    00243 /************************************************************************/
    00244 /*                            GDALWarpKernel                            */
    00245 /*                                                                      */
    00246 /*      This class represents the lowest level of abstraction.  It      */
    00247 /*      is holds the imagery for one "chunk" of a warp, and the         */
    00248 /*      pre-prepared masks.  All IO is done before and after it's       */
    00249 /*      operation.  This class is not normally used by the              */
    00250 /*      application.                                                    */
    00251 /************************************************************************/
    00252
    00253 // This is the number of dummy pixels that must be reserved in source arrays
    00254 // in order to satisfy assumptions made in GWKResample(), and more specifically
    00255 // by GWKGetPixelRow() that always read a even number of pixels. So if we are
    00256 // in the situation to read the last pixel of the source array, we need 1 extra
    00257 // dummy pixel to avoid reading out of bounds.
    00258 #define WARP_EXTRA_ELTS    1
    00259
    00260 class CPL_DLL GDALWarpKernel
    00261 {
    00262 public:
    00263     char              **papszWarpOptions;
    00264
    00265     GDALResampleAlg     eResample;
    00266     GDALDataType        eWorkingDataType;
    00267     int                 nBands;
    00268
    00269     int                 nSrcXSize;
    00270     int                 nSrcYSize;
    00271     GByte               **papabySrcImage; /* each subarray must have WARP_EXTRA_ELTS at the end */
    00272
    00273     GUInt32           **papanBandSrcValid; /* each subarray must have WARP_EXTRA_ELTS at the end */
    00274     GUInt32            *panUnifiedSrcValid; /* must have WARP_EXTRA_ELTS at the end */
    00275     float              *pafUnifiedSrcDensity; /* must have WARP_EXTRA_ELTS at the end */
    00276
    00277     int                 nDstXSize;
    00278     int                 nDstYSize;
    00279     GByte             **papabyDstImage;
    00280     GUInt32            *panDstValid;
    00281     float              *pafDstDensity;
    00282
    00283     double              dfXScale;   // Resampling scale, i.e.
    00284     double              dfYScale;   // nDstSize/nSrcSize.
    00285     double              dfXFilter;  // Size of filter kernel.
    00286     double              dfYFilter;
    00287     int                 nXRadius;   // Size of window to filter.
    00288     int                 nYRadius;
    00289     int                 nFiltInitX; // Filtering offset
    00290     int                 nFiltInitY;
    00291
    00292     int                 nSrcXOff;
    00293     int                 nSrcYOff;
    00294
    00295     int                 nDstXOff;
    00296     int                 nDstYOff;
    00297
    00298     GDALTransformerFunc pfnTransformer;
    00299     void                *pTransformerArg;
    00300
    00301     GDALProgressFunc    pfnProgress;
    00302     void                *pProgress;
    00303
    00304     double              dfProgressBase;
    00305     double              dfProgressScale;
    00306
    00307     double              *padfDstNoDataReal;
    00308
    00309                        GDALWarpKernel();
    00310     virtual           ~GDALWarpKernel();
    00311
    00312     CPLErr              Validate();
    00313     CPLErr              PerformWarp();
    00314 };
    00315
    00316 /************************************************************************/
    00317 /*                         GDALWarpOperation()                          */
    00318 /*                                                                      */
    00319 /*      This object is application created, or created by a higher      */
    00320 /*      level convenience function.  It is responsible for              */
    00321 /*      subdividing the operation into chunks, loading and saving       */
    00322 /*      imagery, and establishing the varios validity and density       */
    00323 /*      masks.  Actual resampling is done by the GDALWarpKernel.        */
    00324 /************************************************************************/
    00325
    00326 class CPL_DLL GDALWarpOperation {
    00327 private:
    00328     GDALWarpOptions *psOptions;
    00329
    00330     void            WipeOptions();
    00331     int             ValidateOptions();
    00332
    00333     CPLErr          ComputeSourceWindow( int nDstXOff, int nDstYOff,
    00334                                          int nDstXSize, int nDstYSize,
    00335                                          int *pnSrcXOff, int *pnSrcYOff,
    00336                                          int *pnSrcXSize, int *pnSrcYSize );
    00337
    00338     CPLErr          CreateKernelMask( GDALWarpKernel *, int iBand,
    00339                                       const char *pszType );
    00340
    00341     void            *unused1;
    00342     void            *unused2;
    00343     void            *hIOMutex;
    00344     void            *hWarpMutex;
    00345
    00346     int             nChunkListCount;
    00347     int             nChunkListMax;
    00348     int            *panChunkList;
    00349
    00350     int             bReportTimings;
    00351     unsigned long   nLastTimeReported;
    00352
    00353     void            WipeChunkList();
    00354     CPLErr          CollectChunkList( int nDstXOff, int nDstYOff,
    00355                                       int nDstXSize, int nDstYSize );
    00356     void            ReportTiming( const char * );
    00357
    00358 public:
    00359                     GDALWarpOperation();
    00360     virtual        ~GDALWarpOperation();
    00361
    00362     CPLErr          Initialize( const GDALWarpOptions *psNewOptions );
    00363
    00364     const GDALWarpOptions         *GetOptions();
    00365
    00366     CPLErr          ChunkAndWarpImage( int nDstXOff, int nDstYOff,
    00367                                        int nDstXSize, int nDstYSize );
    00368     CPLErr          ChunkAndWarpMulti( int nDstXOff, int nDstYOff,
    00369                                        int nDstXSize, int nDstYSize );
    00370     CPLErr          WarpRegion( int nDstXOff, int nDstYOff,
    00371                                 int nDstXSize, int nDstYSize,
    00372                                 int nSrcXOff=0, int nSrcYOff=0,
    00373                                 int nSrcXSize=0, int nSrcYSize=0,
    00374                                 double dfProgressBase=0.0, double dfProgressScale=1.0);
    00375
    00376     CPLErr          WarpRegionToBuffer( int nDstXOff, int nDstYOff,
    00377                                         int nDstXSize, int nDstYSize,
    00378                                         void *pDataBuf,
    00379                                         GDALDataType eBufDataType,
    00380                                         int nSrcXOff=0, int nSrcYOff=0,
    00381                                         int nSrcXSize=0, int nSrcYSize=0,
    00382                                         double dfProgressBase=0.0, double dfProgressScale=1.0);
    00383 };
    00384
    00385 #endif /* def __cplusplus */
    00386
    00387 CPL_C_START
    00388
    00389 typedef void * GDALWarpOperationH;
    00390
    00391 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* );
    00392 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH );
    00393 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int );
    00394 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int );
    00395 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH,
    00396                                int, int, int, int, int, int, int, int );
    00397 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int,
    00398                                        void *, GDALDataType,
    00399                                        int, int, int, int );
    00400
    00401 CPL_C_END
    00402
    00403 #endif /* ndef GDAL_ALG_H_INCLUDED */

Generated for GDAL by 1.7.1.