# GDALWarpKernel Class Reference

Low level image warping class. More...

`#include <gdalwarper.h>`

List of all members.

## Public Member Functions
CPLErr | 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.
CPLErr | PerformWarp ()
| This method performs the warp described in the GDALWarpKernel.
## Public Attributes
char ** | papszWarpOptions
GDALResampleAlg | eResample
| Resampling algorithm.
GDALDataType | eWorkingDataType
| Working pixel data type.
int | nBands
| Number of bands.
int | nSrcXSize
| Source image width in pixels.
int | nSrcYSize
| Source image height in pixels.
GByte ** | papabySrcImage
| Array of source image band data.
GUInt32 ** | papanBandSrcValid
| Per band validity mask for source pixels.
GUInt32 * | panUnifiedSrcValid
| Per pixel validity mask for source pixels.
float * | pafUnifiedSrcDensity
| Per pixel density mask for source pixels.
int | nDstXSize
| Width of destination image in pixels.
int | nDstYSize
| Height of destination image in pixels.
GByte ** | papabyDstImage
| Array of destination image band data.
GUInt32 * | panDstValid
| Per pixel validity mask for destination pixels.
float * | pafDstDensity
| Per pixel density mask for destination pixels.
double | dfXScale
double | dfYScale
double | dfXFilter
double | dfYFilter
int | nXRadius
int | nYRadius
int | nFiltInitX
int | nFiltInitY
int | nSrcXOff
| X offset to source pixel coordinates for transformation.
int | nSrcYOff
| Y offset to source pixel coordinates for transformation.
int | nDstXOff
| X offset to destination pixel coordinates for transformation.
int | nDstYOff
| Y offset to destination pixel coordinates for transformation.
GDALTransformerFunc | pfnTransformer
| Source/destination location transformer.
void * | pTransformerArg
| Callback data for pfnTransformer.
GDALProgressFunc | pfnProgress
| The function to call to report progress of the algorithm, and to check for a requested termination of the operation.
void * | pProgress
| Callback data for pfnProgress.
double | dfProgressBase
double | dfProgressScale
double * | padfDstNoDataReal

## Detailed Description

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.

### Design Issues

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:

- One for each resampling algorithm for 8bit data with no masks.
- One for each resampling algorithm for float data with no masks.
- One for each resampling algorithm for float data with any/all masks (essentially the generic case for just float data).
- One for each resampling algorithm for 8bit data with support for input validity masks (per band or per pixel). This handles the common case of nodata masking.
- One for each resampling algorithm for float data with support for input validity masks (per band or per pixel). This handles the common case of nodata masking.

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.

### Masking Semantics

A detailed explanation of the semantics of the validity and density masks, and their effects on resampling kernels is needed here.

## Member Function Documentation

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.

Returns:
  CE_None on success or CE_Failure if an error is detected.

References eResample.

Referenced by PerformWarp().

CPLErr GDALWarpKernel::PerformWarp | ( |  | ) |

This method performs the warp described in the GDALWarpKernel.

Returns:
  CE_None on success or CE_Failure if an error occurs.

References eResample, eWorkingDataType, GDT_Byte, GDT_CFloat32, GDT_CInt16, GDT_Float32, GDT_Int16, GDT_UInt16, GRA_Bilinear, GRA_Cubic, GRA_CubicSpline, GRA_Lanczos, GRA_NearestNeighbour, nDstXSize, nDstYSize, nSrcXSize, nSrcYSize, pafDstDensity, pafUnifiedSrcDensity, panDstValid, panUnifiedSrcValid, papanBandSrcValid, pfnProgress, pProgress, and Validate().

## Member Data Documentation

GDALResampleAlg GDALWarpKernel::eResample

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().

GDALDataType GDALWarpKernel::eWorkingDataType

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().

int GDALWarpKernel::nBands

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().

int GDALWarpKernel::nSrcXSize

Source image width in pixels.

This field is required.

Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().

int GDALWarpKernel::nSrcYSize

Source image height in pixels.

This field is required.

Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().

int GDALWarpKernel::papabySrcImage

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().

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().

float * GDALWarpKernel::pafUnifiedSrcDensity

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().

int GDALWarpKernel::nDstXSize

Width of destination image in pixels.

This field is required.

Referenced by PerformWarp(), and GDALWarpOperation::WarpRegionToBuffer().

int GDALWarpKernel::nDstYSize

Height of destination image in pixels.

This field is required.

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().

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().

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().

int GDALWarpKernel::nSrcXOff

X offset to source pixel coordinates for transformation.

See pfnTransformer.

This field is required.

Referenced by GDALWarpOperation::WarpRegionToBuffer().

int GDALWarpKernel::nSrcYOff

Y offset to source pixel coordinates for transformation.

See pfnTransformer.

This field is required.

Referenced by GDALWarpOperation::WarpRegionToBuffer().

int GDALWarpKernel::nDstXOff

X offset to destination pixel coordinates for transformation.

See pfnTransformer.

This field is required.

Referenced by GDALWarpOperation::WarpRegionToBuffer().

int GDALWarpKernel::nDstYOff

Y offset to destination pixel coordinates for transformation.

See pfnTransformer.

This field is required.

Referenced by GDALWarpOperation::WarpRegionToBuffer().

GDALTransformerFunc GDALWarpKernel::pfnTransformer

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::pTransformerArg

Callback data for pfnTransformer.

This field may be NULL if not required for the pfnTransformer being used.

Referenced by 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().

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().

The documentation for this class was generated from the following files:

- gdalwarper.h
- gdalwarpkernel.cpp

Generated for GDAL by 1.5.6.