IImageProcessor<TPixel> Interface

A custom image processor that computes each frame of a new canvas, possibly of another size, from the whole frame before the operation (a crop, a warp, a content-aware resize, ...), applied to every frame of an image transactionally by ImageProcessingExtensions.ApplyProcessor.

public interface IImageProcessor<TPixel> where TPixel : unmanaged

Type parameters

TPixel
The pixel type of the frames: the pixel type of the image, or a wider working type.

Remarks

IImageProcessor<TPixel>.GetOutputSize is called once, before anything is allocated; IImageProcessor<TPixel>.Process is then called once per frame, on the calling thread, for every displayed frame then the poster frame. The new frames replace the old ones only after every frame was processed: when a call throws (or the operation is canceled), the image is left unchanged.

Implement the processor as a struct or a class: the processing loop is compiled for its type, without reflection.

Methods

NameDescription
GetOutputSize(Size)Gets the size of the new canvas.
Process(int, PixelRowSource<TPixel>, PixelAccessor<TPixel>, CancellationToken)Computes one frame of the result.
TryMapPoint(Point, Size, Size, Point)Gets where a pixel of the canvas lands on the new canvas: the new position of the cursor hotspot of a frame (FrameMetadata.Hotspot). The default implementation keeps a pixel where it is when it is inside the new canvas.

GetOutputSize(Size)

Gets the size of the new canvas.

Size GetOutputSize(Size size)

Parameters

size Size
The size of the canvas of the image.

Returns

Size The size of every frame of the result. It must not be empty.

Process(int, PixelRowSource<TPixel>, PixelAccessor<TPixel>, CancellationToken)

Computes one frame of the result.

void Process(int frameIndex, PixelRowSource<TPixel> source, PixelAccessor<TPixel> destination, CancellationToken cancellationToken)

Parameters

frameIndex int
The index of the frame: 0 to Frames.Count - 1 for the displayed frames, and Frames.Count for the poster frame.
source PixelRowSource<TPixel>
The pixels of the frame before the operation. Valid until the method returns.
destination PixelAccessor<TPixel>
The pixels of the new frame, of the size IImageProcessor<TPixel>.GetOutputSize returned. It initially holds a cleared frame: transparent black, or opaque black in a pixel format without alpha. Valid until the method returns.
cancellationToken CancellationToken
The token of the operation.

TryMapPoint(Point, Size, Size, Point)

IImageProcessor.cs

Gets where a pixel of the canvas lands on the new canvas: the new position of the cursor hotspot of a frame (FrameMetadata.Hotspot). The default implementation keeps a pixel where it is when it is inside the new canvas.

public bool TryMapPoint(Point source, Size sourceSize, Size destinationSize, out Point destination)

Parameters

source Point
The pixel on the canvas of the image.
sourceSize Size
The size of the canvas of the image.
destinationSize Size
The size of the new canvas.
destination Point
The pixel on the new canvas.

Returns

bool false when the pixel is not part of the result: the operation then fails for a frame whose hotspot designates it.