gdalwarper.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: gdalwarper.h,v 1.16 2004/11/14 04:16:30 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.16  2004/11/14 04:16:30  fwarmerdam
00032  * fixup src alpha support
00033  *
00034  * Revision 1.15  2004/10/07 15:50:18  fwarmerdam
00035  * added preliminary alpha band support
00036  *
00037  * Revision 1.14  2004/08/11 20:11:47  warmerda
00038  * added GDALInitializeWarpedVRT
00039  *
00040  * Revision 1.13  2004/08/11 19:01:25  warmerda
00041  * Added prototypes for GDALAutoCreateWarpedVRT and GDALCreateWarpedVRT
00042  *
00043  * Revision 1.12  2004/08/09 14:38:27  warmerda
00044  * added serialize/deserialize support for warpoptions and transformers
00045  *
00046  * Revision 1.11  2003/11/22 19:13:31  dron
00047  * Added C bindings for GDALWarpOperation functions.
00048  *
00049  * Revision 1.10  2003/07/04 11:50:57  dron
00050  * GRA_CubicSpline added to the list of resampling algorithms.
00051  *
00052  * Revision 1.9  2003/06/12 11:21:33  dron
00053  * Few additional comments.
00054  *
00055  * Revision 1.8  2003/05/27 20:49:25  warmerda
00056  * added REPORT_TIMINGS support
00057  *
00058  * Revision 1.7  2003/05/07 19:13:06  warmerda
00059  * added pre and post warp chunk processor
00060  *
00061  * Revision 1.6  2003/04/23 05:18:57  warmerda
00062  * added multithread support
00063  *
00064  * Revision 1.5  2003/03/02 05:25:59  warmerda
00065  * added some source nodata support
00066  *
00067  * Revision 1.4  2003/02/22 02:04:11  warmerda
00068  * added dfMaxError to reproject function
00069  *
00070  * Revision 1.3  2003/02/21 15:41:37  warmerda
00071  * added progressbase/scale for operation
00072  *
00073  * Revision 1.2  2003/02/20 21:53:06  warmerda
00074  * partial implementation
00075  *
00076  * Revision 1.1  2003/02/18 17:25:50  warmerda
00077  * New
00078  *
00079  */
00080 
00081 #ifndef GDALWARPER_H_INCLUDED
00082 #define GDALWARPER_H_INCLUDED
00083 
00092 #include "gdal_alg.h"
00093 #include "cpl_minixml.h"
00094 
00095 CPL_C_START
00096 
00098 typedef enum { GRA_NearestNeighbour=0,                         GRA_Bilinear=1,  GRA_Cubic=2,     GRA_CubicSpline=3,
00103 } GDALResampleAlg;
00104 
00105 typedef int 
00106 (*GDALMaskFunc)( void *pMaskFuncArg,
00107                  int nBandCount, GDALDataType eType, 
00108                  int nXOff, int nYOff, 
00109                  int nXSize, int nYSize,
00110                  GByte **papabyImageData, 
00111                  int bMaskIsFloat, void *pMask );
00112 
00113 CPLErr CPL_DLL 
00114 GDALWarpNoDataMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00115                       int nXOff, int nYOff, int nXSize, int nYSize,
00116                       GByte **papabyImageData, int bMaskIsFloat,
00117                       void *pValidityMask );
00118 
00119 CPLErr CPL_DLL 
00120 GDALWarpDstAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00121                         int nXOff, int nYOff, int nXSize, int nYSize,
00122                         GByte ** /*ppImageData */,
00123                         int bMaskIsFloat, void *pValidityMask );
00124 CPLErr CPL_DLL 
00125 GDALWarpSrcAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00126                         int nXOff, int nYOff, int nXSize, int nYSize,
00127                         GByte ** /*ppImageData */,
00128                         int bMaskIsFloat, void *pValidityMask );
00129 
00130 /************************************************************************/
00131 /*                           GDALWarpOptions                            */
00132 /************************************************************************/
00133 
00135 typedef struct {
00136     
00137     char              **papszWarpOptions;  
00138 
00140     double              dfWarpMemoryLimit; 
00141 
00143     GDALResampleAlg     eResampleAlg;
00144 
00147     GDALDataType        eWorkingDataType;
00148 
00150     GDALDatasetH        hSrcDS;
00151 
00153     GDALDatasetH        hDstDS;
00154 
00156     int                 nBandCount;
00157     
00159     int                *panSrcBands;
00160 
00162     int                *panDstBands;
00163 
00165     int                nSrcAlphaBand;
00166 
00168     int                nDstAlphaBand;
00169 
00171     double             *padfSrcNoDataReal;
00174     double             *padfSrcNoDataImag;
00175 
00177     double             *padfDstNoDataReal;
00180     double             *padfDstNoDataImag;
00181 
00184     GDALProgressFunc    pfnProgress;
00185 
00187     void               *pProgressArg;
00188 
00190     GDALTransformerFunc pfnTransformer;
00191 
00193     void                *pTransformerArg;
00194 
00195     GDALMaskFunc       *papfnSrcPerBandValidityMaskFunc;
00196     void              **papSrcPerBandValidityMaskFuncArg;
00197     
00198     GDALMaskFunc        pfnSrcValidityMaskFunc;
00199     void               *pSrcValidityMaskFuncArg;
00200     
00201     GDALMaskFunc        pfnSrcDensityMaskFunc;
00202     void               *pSrcDensityMaskFuncArg;
00203 
00204     GDALMaskFunc        pfnDstDensityMaskFunc;
00205     void               *pDstDensityMaskFuncArg;
00206 
00207     GDALMaskFunc        pfnDstValidityMaskFunc;
00208     void               *pDstValidityMaskFuncArg;
00209 
00210     CPLErr              (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg );
00211     void               *pPreWarpProcessorArg;
00212     
00213     CPLErr              (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg);
00214     void               *pPostWarpProcessorArg;
00215 
00216 } GDALWarpOptions;
00217 
00218 GDALWarpOptions CPL_DLL *GDALCreateWarpOptions();
00219 void CPL_DLL GDALDestroyWarpOptions( GDALWarpOptions * );
00220 GDALWarpOptions CPL_DLL *GDALCloneWarpOptions( const GDALWarpOptions * );
00221 
00222 CPLXMLNode CPL_DLL *GDALSerializeWarpOptions( const GDALWarpOptions * );
00223 GDALWarpOptions CPL_DLL *GDALDeserializeWarpOptions( CPLXMLNode * );
00224 
00225 /************************************************************************/
00226 /*                         GDALReprojectImage()                         */
00227 /************************************************************************/
00228 
00229 CPLErr CPL_DLL 
00230 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00231                     GDALDatasetH hDstDS, const char *pszDstWKT,
00232                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00233                     double dfMaxError,
00234                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00235                     GDALWarpOptions *psOptions );
00236 
00237 CPLErr CPL_DLL 
00238 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00239                     const char *pszDstFilename, const char *pszDstWKT,
00240                     GDALDriverH hDstDriver, char **papszCreateOptions,
00241                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00242                     double dfMaxError,
00243                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00244                     GDALWarpOptions *psOptions );
00245 
00246 /************************************************************************/
00247 /*                           VRTWarpedDataset                           */
00248 /************************************************************************/
00249 
00250 GDALDatasetH CPL_DLL 
00251 GDALAutoCreateWarpedVRT( GDALDatasetH hSrcDS, 
00252                          const char *pszSrcWKT, const char *pszDstWKT, 
00253                          GDALResampleAlg eResampleAlg, 
00254                          double dfMaxError, const GDALWarpOptions *psOptions );
00255 
00256 GDALDatasetH CPL_DLL 
00257 GDALCreateWarpedVRT( GDALDatasetH hSrcDS, 
00258                      int nPixels, int nLines, double *padfGeoTransform,
00259                      GDALWarpOptions *psOptions );
00260 
00261 CPLErr CPL_DLL GDALInitializeWarpedVRT( GDALDatasetH hDS, 
00262                                         GDALWarpOptions *psWO );
00263 
00264 CPL_C_END
00265 
00266 #ifdef __cplusplus 
00267 
00268 /************************************************************************/
00269 /*                            GDALWarpKernel                            */
00270 /*                                                                      */
00271 /*      This class represents the lowest level of abstraction.  It      */
00272 /*      is holds the imagery for one "chunk" of a warp, and the         */
00273 /*      pre-prepared masks.  All IO is done before and after it's       */
00274 /*      operation.  This class is not normally used by the              */
00275 /*      application.                                                    */
00276 /************************************************************************/
00277 
00278 class CPL_DLL GDALWarpKernel
00279 {
00280 public:
00281                        GDALWarpKernel();
00282     virtual           ~GDALWarpKernel();
00283 
00284     char              **papszWarpOptions;
00285 
00286     GDALResampleAlg     eResample;
00287     GDALDataType        eWorkingDataType;
00288     int                 nBands;
00289 
00290     int                 nSrcXSize;
00291     int                 nSrcYSize;
00292     GByte               **papabySrcImage;
00293 
00294     GUInt32           **papanBandSrcValid;
00295     GUInt32            *panUnifiedSrcValid;
00296     float              *pafUnifiedSrcDensity;
00297 
00298     int                 nDstXSize;
00299     int                 nDstYSize;
00300     GByte             **papabyDstImage;
00301     GUInt32            *panDstValid;
00302     float              *pafDstDensity;
00303     
00304     int                 nSrcXOff;
00305     int                 nSrcYOff;
00306 
00307     int                 nDstXOff;
00308     int                 nDstYOff;
00309         
00310     GDALTransformerFunc pfnTransformer;
00311     void                *pTransformerArg;
00312 
00313     GDALProgressFunc    pfnProgress;
00314     void                *pProgress;
00315 
00316     double              dfProgressBase;
00317     double              dfProgressScale;
00318 
00319     CPLErr              Validate();
00320     CPLErr              PerformWarp();
00321 };
00322 
00323 /************************************************************************/
00324 /*                         GDALWarpOperation()                          */
00325 /*                                                                      */
00326 /*      This object is application created, or created by a higher      */
00327 /*      level convenience function.  It is responsible for              */
00328 /*      subdividing the operation into chunks, loading and saving       */
00329 /*      imagery, and establishing the varios validity and density       */
00330 /*      masks.  Actual resampling is done by the GDALWarpKernel.        */
00331 /************************************************************************/
00332 
00333 class CPL_DLL GDALWarpOperation {
00334 private:
00335     GDALWarpOptions *psOptions;
00336 
00337     double          dfProgressBase;
00338     double          dfProgressScale;
00339 
00340     void            WipeOptions();
00341     int             ValidateOptions();
00342 
00343     CPLErr          ComputeSourceWindow( int nDstXOff, int nDstYOff, 
00344                                          int nDstXSize, int nDstYSize,
00345                                          int *pnSrcXOff, int *pnSrcYOff, 
00346                                          int *pnSrcXSize, int *pnSrcYSize );
00347 
00348     CPLErr          CreateKernelMask( GDALWarpKernel *, int iBand, 
00349                                       const char *pszType );
00350 
00351     void            *hThread1Mutex;
00352     void            *hThread2Mutex;
00353     void            *hIOMutex;
00354     void            *hWarpMutex;
00355 
00356     int             nChunkListCount;
00357     int             nChunkListMax;
00358     int            *panChunkList;
00359 
00360     int             bReportTimings;
00361     unsigned long   nLastTimeReported;
00362 
00363     void            WipeChunkList();
00364     CPLErr          CollectChunkList( int nDstXOff, int nDstYOff, 
00365                                       int nDstXSize, int nDstYSize );
00366     void            ReportTiming( const char * );
00367     
00368 public:
00369                     GDALWarpOperation();
00370     virtual        ~GDALWarpOperation();
00371 
00372     CPLErr          Initialize( const GDALWarpOptions *psNewOptions );
00373 
00374     const GDALWarpOptions         *GetOptions();
00375 
00376     CPLErr          ChunkAndWarpImage( int nDstXOff, int nDstYOff, 
00377                                        int nDstXSize, int nDstYSize );
00378     CPLErr          ChunkAndWarpMulti( int nDstXOff, int nDstYOff, 
00379                                        int nDstXSize, int nDstYSize );
00380     CPLErr          WarpRegion( int nDstXOff, int nDstYOff, 
00381                                 int nDstXSize, int nDstYSize,
00382                                 int nSrcXOff=0, int nSrcYOff=0,
00383                                 int nSrcXSize=0, int nSrcYSize=0 );
00384     
00385     CPLErr          WarpRegionToBuffer( int nDstXOff, int nDstYOff, 
00386                                         int nDstXSize, int nDstYSize, 
00387                                         void *pDataBuf, 
00388                                         GDALDataType eBufDataType,
00389                                         int nSrcXOff=0, int nSrcYOff=0,
00390                                         int nSrcXSize=0, int nSrcYSize=0 );
00391 };
00392 
00393 #endif /* def __cplusplus */
00394 
00395 CPL_C_START
00396 
00397 typedef void * GDALWarpOperationH;
00398 
00399 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* );
00400 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH );
00401 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int );
00402 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int );
00403 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH,
00404                                int, int, int, int, int, int, int, int );
00405 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int,
00406                                        void *, GDALDataType,
00407                                        int, int, int, int );
00408 
00409 CPL_C_END
00410 
00411 #endif /* ndef GDAL_ALG_H_INCLUDED */

Generated on Mon Jan 9 18:03:35 2006 for GDAL by  doxygen 1.4.6