gdalwarper.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: gdalwarper.h,v 1.17 2005/04/04 15:24:16 fwarmerdam Exp $
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  * $Log: gdalwarper.h,v $
00031  * Revision 1.17  2005/04/04 15:24:16  fwarmerdam
00032  * added CPL_STDCALL to some functions
00033  *
00034  * Revision 1.16  2004/11/14 04:16:30  fwarmerdam
00035  * fixup src alpha support
00036  *
00037  * Revision 1.15  2004/10/07 15:50:18  fwarmerdam
00038  * added preliminary alpha band support
00039  *
00040  * Revision 1.14  2004/08/11 20:11:47  warmerda
00041  * added GDALInitializeWarpedVRT
00042  *
00043  * Revision 1.13  2004/08/11 19:01:25  warmerda
00044  * Added prototypes for GDALAutoCreateWarpedVRT and GDALCreateWarpedVRT
00045  *
00046  * Revision 1.12  2004/08/09 14:38:27  warmerda
00047  * added serialize/deserialize support for warpoptions and transformers
00048  *
00049  * Revision 1.11  2003/11/22 19:13:31  dron
00050  * Added C bindings for GDALWarpOperation functions.
00051  *
00052  * Revision 1.10  2003/07/04 11:50:57  dron
00053  * GRA_CubicSpline added to the list of resampling algorithms.
00054  *
00055  * Revision 1.9  2003/06/12 11:21:33  dron
00056  * Few additional comments.
00057  *
00058  * Revision 1.8  2003/05/27 20:49:25  warmerda
00059  * added REPORT_TIMINGS support
00060  *
00061  * Revision 1.7  2003/05/07 19:13:06  warmerda
00062  * added pre and post warp chunk processor
00063  *
00064  * Revision 1.6  2003/04/23 05:18:57  warmerda
00065  * added multithread support
00066  *
00067  * Revision 1.5  2003/03/02 05:25:59  warmerda
00068  * added some source nodata support
00069  *
00070  * Revision 1.4  2003/02/22 02:04:11  warmerda
00071  * added dfMaxError to reproject function
00072  *
00073  * Revision 1.3  2003/02/21 15:41:37  warmerda
00074  * added progressbase/scale for operation
00075  *
00076  * Revision 1.2  2003/02/20 21:53:06  warmerda
00077  * partial implementation
00078  *
00079  * Revision 1.1  2003/02/18 17:25:50  warmerda
00080  * New
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 ** /*ppImageData */,
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 ** /*ppImageData */,
00131                         int bMaskIsFloat, void *pValidityMask );
00132 
00133 /************************************************************************/
00134 /*                           GDALWarpOptions                            */
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 /*                         GDALReprojectImage()                         */
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 /*                           VRTWarpedDataset                           */
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 /*                            GDALWarpKernel                            */
00277 /*                                                                      */
00278 /*      This class represents the lowest level of abstraction.  It      */
00279 /*      is holds the imagery for one "chunk" of a warp, and the         */
00280 /*      pre-prepared masks.  All IO is done before and after it's       */
00281 /*      operation.  This class is not normally used by the              */
00282 /*      application.                                                    */
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 /*                         GDALWarpOperation()                          */
00332 /*                                                                      */
00333 /*      This object is application created, or created by a higher      */
00334 /*      level convenience function.  It is responsible for              */
00335 /*      subdividing the operation into chunks, loading and saving       */
00336 /*      imagery, and establishing the varios validity and density       */
00337 /*      masks.  Actual resampling is done by the GDALWarpKernel.        */
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 /* def __cplusplus */
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 /* ndef GDAL_ALG_H_INCLUDED */

Generated on Sun Jul 2 22:18:26 2006 for GDAL by  doxygen 1.4.6