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 : unmanagedType 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
| Name | Description |
|---|---|
| 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)
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
frameIndexint- The index of the frame:
0toFrames.Count - 1for the displayed frames, andFrames.Countfor the poster frame. sourcePixelRowSource<TPixel>- The pixels of the frame before the operation. Valid until the method returns.
destinationPixelAccessor<TPixel>- The pixels of the new frame, of the size
IImageProcessor<TPixel>.GetOutputSizereturned. It initially holds a cleared frame: transparent black, or opaque black in a pixel format without alpha. Valid until the method returns. cancellationTokenCancellationToken- The token of the operation.
TryMapPoint(Point, Size, Size, Point)
IImageProcessor.csGets 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.
Parameters
sourcePoint- The pixel on the canvas of the image.
sourceSizeSize- The size of the canvas of the image.
destinationSizeSize- The size of the new canvas.
destinationPoint- 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.