Skip to content

Reverse Pixel Mapping API ​

ReversePixelMapper interface ​

General interface for Reverse Pixel Mapping. Maps output image point coordinates into source image point coordinates using mathematical function.

ts
interface ReversePixelMapper {
  reverseMap(x: number, y: number): Point;
  getValidity(x: number, y: number, scaling: number): number;
}

Methods ​

reverseMap() ​

  • Params: x: number, y: number - Output image point coordinates.
  • Returns: Point - Source image point coordinates in Point format

Returns corresponding source image point coordinates for given output (destination, distorted) image point coordinates.


getValidity() ​

  • Params: x: number, y: number - Output image point coordinates.
  • Returns: number

Returns number that represents how mathematically valid is mapping. If validity is < 0 -- the mapping is invalid. When mapping is invalid, matte color will be used. When validity is between 0 and 1, blended color of matte color and resampled color will be used.

Type guard ​

isReversePixelMapper() function checks if given argument is ReversePixelMapper and can be used as type guard.

ReversePixelMapperFactory interface ​

Creates ReversePixelMapper concrete implementation.

ts
interface ReversePixelMapperFactory<T extends number[] = number[]> {
  create(args: T, viewport: Viewport): ReversePixelMapper;
}

Methods ​

create() ​

  • Params:
    • args: T - Array of numbers, which are distortion arguments, different for concrete implementations.
    • viewport: Viewport - instance of Viewport class.

Creates instance of concrete ReversePixelMapper.

ReversePixelMapperFactoriesPool type ​

Pool of ReversePixelMapperFactory instances. Pool keys are Distortion enum values, which are alse distortion names, which you pass to distort() function second argument.

ts
interface ReversePixelMapperFactoriesPoolKeyMap {
  [Distortion.ARC]: ArcFactory;
  [Distortion.AFFINE]: AffineFactory;
  [Distortion.AFFINE_PROJECTION]: AffineProjectionFactory;
  [Distortion.PERSPECTIVE]: PerspectiveFactory;
  [Distortion.PERSPECTIVE_PROJECTION]: PerspectiveProjectionFactory;
  [key: Distortion | string]: ReversePixelMapperFactory;
}

type ReversePixelMapperFactoriesPool = Pool<
  ReversePixelMapperFactory,
  ReversePixelMapperFactoriesPoolKeyMap
>;

BestFitReversePixelMapper interface ​

Interface extends ReversePixelMapper and provides props and methods for best-fit viewport calculation.

ts
interface BestFitReversePixelMapper extends ReversePixelMapper {
  readonly forceBestFit?: boolean;
  getBestFitViewport(viewport: Viewport): Viewport;
}

Properties ​

forceBestFit ​

  • Type: boolean

Optional boolean property which is flag of that given pixel mapper will force to use best-fit output image viewport, rather than source image viewport, unless custom user-provided viewport is given.

Methods ​

getBestFitViewport() ​

  • Param: viewport: Viewport - source image Viewport
  • Returns: Viewport

Calculates output image best-fit viewport, based on given source image viewport.

Type guard ​

isBestFitReversePixelMapper() functions checks if given argument is BestFitReversePixelMapper and can be used as type guard.

EwaReversePixelMapper interface ​

Interface extends ReversePixelMapper and provides properties and methods, required for performing EWA resampling.

ts
type PartialDerivatives = [number, number, number, number];

interface EwaReversePixelMapper extends ReversePixelMapper {
  readonly isConstantPartialDerivatives: boolean;
  getPartialDerivatives(x: number, y: number): PartialDerivatives;
}

Properties ​

isConstantPartialDerivatives ​

  • Type: boolean

Flag of pixel mapper having constant partial derivatives. If true, there is no need for EWA resampler to call getPartialDerivatives() method for each pixel.

Methods ​

getPartialDerivatives() ​

  • Params: x: number, y: number - output image point coordinates
  • Returns: PartialDerivatives - array of 4 numbers.

Returns array of 4 numbers which are partial derivatives: dux, dvy, dvx, dvy and are used for EWA ellipse params calculation.

Type guard ​

isEwaReversePixelMapper() function checks if given argument is EwaReversePixelMapper and can be used as type guard.