Interface IRasterOperation
- Namespace
- Egami.Operations
- Assembly
- Egami.dll
One step of an operation chain. Built-in operations implement it, and so can callers: add one to a chain with Add(IRasterOperation).
public interface IRasterOperation
Examples
/// <summary>Swaps red and blue, in parallel bands of rows.</summary>
public sealed class SwapRedBlue : IRasterOperation
{
public Size OutputSize(Size input) => input;
public void Run<TPixel>(OperationInput<TPixel> input)
where TPixel : unmanaged, IPixelType<TPixel>
{
input.ForEachBand((start, end) =>
{
for (int y = start; y < end; y++)
{
Span<TPixel> source = input.Source.Row(y);
Span<TPixel> destination = input.Destination.Row(y);
for (int x = 0; x < source.Length; x++)
{
Vector4 v = source[x].ToScaled();
destination[x] = TPixel.FromScaled(new Vector4(v.Z, v.Y, v.X, v.W));
}
}
});
}
}
Remarks
Implementations must be stateless or immutable: one instance runs on every frame and may run on several threads.
Methods
OutputSize(Size)
Returns the frame size after this operation, so the pipeline can plan memory before any pixel changes.
Size OutputSize(Size input)
Parameters
inputSizeThe frame size before it.
Returns
- Size
The size after it. Return
inputfor operations that keep the size.
Exceptions
- ArgumentException
The operation cannot apply to a frame of this size.
Run<TPixel>(OperationInput<TPixel>)
Runs the operation on one frame: reads Source and writes every pixel of Destination. The two can be the same plane, so an operation must handle working in place.
void Run<TPixel>(OperationInput<TPixel> input) where TPixel : unmanaged, IPixelType<TPixel>
Parameters
inputOperationInput<TPixel>The planes, context and cancellation token.
Type Parameters
TPixelThe pixel type.