#include "gdalwarper.h"
Public Member Functions | |
CPLErr | Validate () |
CPLErr | PerformWarp () |
Public Attributes | |
char ** | papszWarpOptions |
GDALResampleAlg | eResample |
GDALDataType | eWorkingDataType |
int | nBands |
int | nSrcXSize |
int | nSrcYSize |
GByte ** | papabySrcImage |
GUInt32 ** | papanBandSrcValid |
GUInt32 * | panUnifiedSrcValid |
float * | pafUnifiedSrcDensity |
int | nDstXSize |
int | nDstYSize |
GByte ** | papabyDstImage |
GUInt32 * | panDstValid |
float * | pafDstDensity |
double | dfXScale |
double | dfYScale |
double | dfXFilter |
double | dfYFilter |
int | nXRadius |
int | nYRadius |
int | nFiltInitX |
int | nFiltInitY |
int | nSrcXOff |
int | nSrcYOff |
int | nDstXOff |
int | nDstYOff |
GDALTransformerFunc | pfnTransformer |
void * | pTransformerArg |
GDALProgressFunc | pfnProgress |
void * | pProgress |
double | dfProgressBase |
double | dfProgressScale |
Low level image warping class.
This class is responsible for low level image warping for one "chunk" of imagery. The class is essentially a structure with all data members public - primarily so that new special-case functions can be added without changing the class declaration.
Applications are normally intended to interactive with warping facilities through the GDALWarpOperation class, though the GDALWarpKernel can in theory be used directly if great care is taken in setting up the control data.
My intention is that PerformWarp() would analyse the setup in terms of the datatype, resampling type, and validity/density mask usage and pick one of many specific implementations of the warping algorithm over a continuim of optimization vs. generality. At one end there will be a reference general purpose implementation of the algorithm that supports any data type (working internally in double precision complex), all three resampling types, and any or all of the validity/density masks. At the other end would be highly optimized algorithms for common cases like nearest neighbour resampling on GDT_Byte data with no masks.
The full set of optimized versions have not been decided but we should expect to have at least:
Some of the specializations would operate on all bands in one pass (especially the ones without masking would do this), while others might process each band individually to reduce code complexity.
A detailed explanation of the semantics of the validity and density masks, and their effects on resampling kernels is needed here.
CPLErr GDALWarpKernel::PerformWarp | ( | ) |
This method performs the warp described in the GDALWarpKernel.
References eResample, eWorkingDataType, GDT_Byte, GDT_Float32, GDT_Int16, GDT_UInt16, GRA_Bilinear, GRA_Cubic, GRA_CubicSpline, GRA_NearestNeighbour, nDstXSize, nDstYSize, nSrcXSize, nSrcYSize, pafDstDensity, pafUnifiedSrcDensity, panDstValid, panUnifiedSrcValid, papanBandSrcValid, pfnProgress, pProgress, and Validate().
CPLErr GDALWarpKernel::Validate | ( | ) |
Check the settings in the GDALWarpKernel, and issue a CPLError() (and return CE_Failure) if the configuration is considered to be invalid for some reason.
This method will also do some standard defaulting such as setting pfnProgress to GDALDummyProgress() if it is NULL.
References eResample.
Referenced by PerformWarp().
Resampling algorithm.
The resampling algorithm to use. One of GRA_NearestNeighbour, GRA_Bilinear, or GRA_Cubic.
This field is required. GDT_NearestNeighbour may be used as a default value.
Referenced by PerformWarp(), Validate(), and GDALWarpOperation::WarpRegionToBuffer().
Working pixel data type.
The datatype of pixels in the source image (papabySrcimage) and destination image (papabyDstImage) buffers. Note that operations on some data types (such as GDT_Byte) may be much better optimized than other less common cases.
This field is required. It may not be GDT_Unknown.
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
Number of bands.
The number of bands (layers) of imagery being warped. Determines the number of entries in the papabySrcImage, papanBandSrcValid, and papabyDstImage arrays.
This field is required.
Referenced by GDALWarpOperation::WarpRegionToBuffer().
X offset to destination pixel coordinates for transformation.
See pfnTransformer.
This field is required.
Referenced by GDALWarpOperation::WarpRegionToBuffer().
Width of destination image in pixels.
This field is required.
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
Y offset to destination pixel coordinates for transformation.
See pfnTransformer.
This field is required.
Referenced by GDALWarpOperation::WarpRegionToBuffer().
Height of destination image in pixels.
This field is required.
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
X offset to source pixel coordinates for transformation.
See pfnTransformer.
This field is required.
Referenced by GDALWarpOperation::WarpRegionToBuffer().
Source image width in pixels.
This field is required.
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
Y offset to source pixel coordinates for transformation.
See pfnTransformer.
This field is required.
Referenced by GDALWarpOperation::WarpRegionToBuffer().
Source image height in pixels.
This field is required.
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
float * GDALWarpKernel::pafDstDensity |
Per pixel density mask for destination pixels.
A single density mask layer that applies to the pixels of all destination bands. It contains values between 0.0 and 1.0.
This pointer may be NULL indicating that all pixels have a density of 1.0.
The density for a pixel may be accessed like this:
float fDensity = 1.0; int nPixel = 3; // zero based int nLine = 4; // zero based assert( nPixel >= 0 && nPixel < poKern->nDstXSize ); assert( nLine >= 0 && nLine < poKern->nDstYSize ); if( poKern->pafDstDensity != NULL ) fDensity = poKern->pafDstDensity[nPixel + nLine * poKern->nDstXSize];
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
Per pixel density mask for source pixels.
A single density mask layer that applies to the pixels of all source bands. It contains values between 0.0 and 1.0 indicating the degree to which this pixel should be allowed to contribute to the output result.
This pointer may be NULL indicating that all pixels have a density of 1.0.
The density for a pixel may be accessed like this:
float fDensity = 1.0; int nPixel = 3; // zero based int nLine = 4; // zero based assert( nPixel >= 0 && nPixel < poKern->nSrcXSize ); assert( nLine >= 0 && nLine < poKern->nSrcYSize ); if( poKern->pafUnifiedSrcDensity != NULL ) fDensity = poKern->pafUnifiedSrcDensity [nPixel + nLine * poKern->nSrcXSize];
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
GUInt32 * GDALWarpKernel::panDstValid |
Per pixel validity mask for destination pixels.
A single validity mask layer that applies to the pixels of all destination bands. It is accessed similarly to papanUnitifiedSrcValid, but based on the size of the destination image.
This pointer may be NULL indicating that all pixels are valid.
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
GUInt32 * GDALWarpKernel::panUnifiedSrcValid |
Per pixel validity mask for source pixels.
A single validity mask layer that applies to the pixels of all source bands. It is accessed similarly to papanBandSrcValid, but without the extra level of band indirection.
This pointer may be NULL indicating that all pixels are valid.
Note that if both panUnifiedSrcValid, and papanBandSrcValid are available, the pixel isn't considered to be valid unless both arrays indicate it is valid.
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
GByte ** GDALWarpKernel::papabyDstImage |
Array of destination image band data.
This is an array of pointers (of size GDALWarpKernel::nBands) pointers to image data. Each individual band of image data is organized as a single block of image data in left to right, then bottom to top order. The actual type of the image data is determined by GDALWarpKernel::eWorkingDataType.
To access the the pixel value for the (x=3,y=4) pixel (zero based) of the second band with eWorkingDataType set to GDT_Float32 use code like this:
float dfPixelValue; int nBand = 1; // band indexes are zero based. int nPixel = 3; // zero based int nLine = 4; // zero based assert( nPixel >= 0 && nPixel < poKern->nDstXSize ); assert( nLine >= 0 && nLine < poKern->nDstYSize ); assert( nBand >= 0 && nBand < poKern->nBands ); dfPixelValue = ((float *) poKern->papabyDstImage[nBand-1]) [nPixel + nLine * poKern->nSrcYSize];
This field is required.
Referenced by GDALWarpOperation::WarpRegionToBuffer().
Array of source image band data.
This is an array of pointers (of size GDALWarpKernel::nBands) pointers to image data. Each individual band of image data is organized as a single block of image data in left to right, then bottom to top order. The actual type of the image data is determined by GDALWarpKernel::eWorkingDataType.
To access the the pixel value for the (x=3,y=4) pixel (zero based) of the second band with eWorkingDataType set to GDT_Float32 use code like this:
float dfPixelValue; int nBand = 1; // band indexes are zero based. int nPixel = 3; // zero based int nLine = 4; // zero based assert( nPixel >= 0 && nPixel < poKern->nSrcXSize ); assert( nLine >= 0 && nLine < poKern->nSrcYSize ); assert( nBand >= 0 && nBand < poKern->nBands ); dfPixelValue = ((float *) poKern->papabySrcImage[nBand-1]) [nPixel + nLine * poKern->nSrcXSize];
This field is required.
Referenced by GDALWarpOperation::WarpRegionToBuffer().
GUInt32 ** GDALWarpKernel::papanBandSrcValid |
Per band validity mask for source pixels.
Array of pixel validity mask layers for each source band. Each of the mask layers is the same size (in pixels) as the source image with one bit per pixel. Note that it is legal (and common) for this to be NULL indicating that none of the pixels are invalidated, or for some band validity masks to be NULL in which case all pixels of the band are valid. The following code can be used to test the validity of a particular pixel.
int bIsValid = TRUE; int nBand = 1; // band indexes are zero based. int nPixel = 3; // zero based int nLine = 4; // zero based assert( nPixel >= 0 && nPixel < poKern->nSrcXSize ); assert( nLine >= 0 && nLine < poKern->nSrcYSize ); assert( nBand >= 0 && nBand < poKern->nBands ); if( poKern->papanBandSrcValid != NULL && poKern->papanBandSrcValid[nBand] != NULL ) { GUInt32 *panBandMask = poKern->papanBandSrcValid[nBand]; int iPixelOffset = nPixel + nLine * poKern->nSrcXSize; bIsValid = panBandMask[iPixelOffset>>5] & (0x01 << (iPixelOffset & 0x1f)); }
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
GDALProgressFunc GDALWarpKernel::pfnProgress |
The function to call to report progress of the algorithm, and to check for a requested termination of the operation. It operates according to GDALProgressFunc() semantics.
Generally speaking the progress function will be invoked for each scanline of the destination buffer that has been processed.
This field may be NULL (internally set to GDALDummyProgress()).
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
Source/destination location transformer.
The function to call to transform coordinates between source image pixel/line coordinates and destination image pixel/line coordinates. See GDALTransformerFunc() for details of the semantics of this function.
The GDALWarpKern algorithm will only ever use this transformer in "destination to source" mode (bDstToSrc=TRUE), and will always pass partial or complete scanlines of points in the destination image as input. This means, amoung other things, that it is safe to the the approximating transform GDALApproxTransform() as the transformation function.
Source and destination images may be subsets of a larger overall image. The transformation algorithms will expect and return pixel/line coordinates in terms of this larger image, so coordinates need to be offset by the offsets specified in nSrcXOff, nSrcYOff, nDstXOff, and nDstYOff before passing to pfnTransformer, and after return from it.
The GDALWarpKernel::pfnTransformerArg value will be passed as the callback data to this function when it is called.
This field is required.
Referenced by GDALWarpOperation::WarpRegionToBuffer().
void * GDALWarpKernel::pProgress |
Callback data for pfnProgress.
This field may be NULL if not required for the pfnProgress being used.
Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().
Callback data for pfnTransformer.
This field may be NULL if not required for the pfnTransformer being used.
Referenced by GDALWarpOperation::WarpRegionToBuffer().