Table of Contents

Class HistoryFrame

Namespace
VisioForge.Core.Types.FastImageProcessing
Assembly
VisioForge.Core.dll

History frame, contains the 3 most recent frames.

public class HistoryFrame : IDisposable

Inheritance

Implements

Inherited Members

Remarks

The HistoryFrame class is used in video processing algorithms that require temporal information, such as motion detection, deinterlacing, and noise reduction. It maintains a rolling buffer of the three most recent frames (Frame0, Frame1, Frame2) plus a copy of the current frame.

Frame organization, newest first, as VisioForge.Core.Types.FastImageProcessing.HistoryFrame.Fill(System.IntPtr,System.Int32) pushes them: - Frame0: the frame pushed last - Frame1: the one pushed before it - Frame2: the oldest - CurrentFrameCopy: Copy of the current frame being processed

Which of them is the current frame depends on whether the caller pushes it before or after processing it; each FastImageProcessing method taking a HistoryFrame says which frame it reads as which.

This class uses unmanaged memory allocation for performance reasons, as video frames can be large and frequent allocations would impact performance. The class implements IDisposable to ensure proper cleanup of unmanaged resources.

Constructors

HistoryFrame(BaseContext)

Initializes a new instance of the VisioForge.Core.Types.FastImageProcessing.HistoryFrame class.

public HistoryFrame(BaseContext context)

Parameters

context BaseContext

The context.

Fields

CurrentFrameCopy

The current frame copy.

public nint CurrentFrameCopy

Field Value

nint

Remarks

A separate copy of the current frame being processed. This allows algorithms to modify the current frame while preserving the original for history tracking.

Frame0

Frame 0 - the frame pushed last.

public nint Frame0

Field Value

nint

Remarks

The newest frame: the current one when the caller pushes it before processing, the one before otherwise. This is typically used as the primary reference frame for motion detection and temporal filtering algorithms.

Frame1

Frame 1 - the frame pushed before Frame0.

public nint Frame1

Field Value

nint

Remarks

Used for multi-frame analysis and advanced temporal processing algorithms.

Frame2

Frame 2 - the oldest frame, pushed before Frame1.

public nint Frame2

Field Value

nint

Remarks

Provides extended temporal context for algorithms requiring longer history windows.

Methods

Allocate(int, nint)

Allocates frames.

public void Allocate(int size, nint frame)

Parameters

size int

Frame size in bytes. Calculate as: width * height * bytes_per_pixel. For example, a 1920x1080 BGRA frame would be 1920 * 1080 * 4 = 8,294,400 bytes.

frame nint

Pointer to the initial frame data used to populate all history frames. This prevents undefined behavior when accessing history before enough frames have been processed.

Remarks

This method must be called before using the history frame. It allocates unmanaged memory for all frame buffers and initializes them with the provided frame data. This initialization strategy prevents artifacts in temporal algorithms during startup.

Exceptions

OutOfMemoryException

Thrown if there is insufficient memory to allocate the frame buffers.

Clear()

Clears frames.

public void Clear()

Dispose(bool)

Releases unmanaged resources used by this instance and, optionally, managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources - none at .NET Framework process exit, where a graph left running may still use them and the OS reclaims them.

Dispose()

Releases all unmanaged frame buffers held by this instance.

public void Dispose()

Fill(nint, int)

Fills frames.

public void Fill(nint frame, int frameSize)

Parameters

frame nint

Pointer to the new frame data to be added to the history.

frameSize int

Frame size in bytes. Must match the size used in Allocate().

Examples

// Process video frames with history
foreach (var currentFrame in videoStream)
{
    // Update history
    history.Fill(currentFrame, frameSize);

    // Now you can access:
    // - currentFrame: The frame being processed
    // - history.Frame0: a copy of currentFrame (t)
    // - history.Frame1: the previous frame (t-1)
    // - history.Frame2: the frame before that (t-2)
}

Remarks

Updates the frame history by shifting frames: - Frame2 receives data from Frame1 (becomes oldest) - Frame1 receives data from Frame0 - Frame0 receives the new frame data (becomes most recent)

This creates a rolling buffer where Frame0 always contains the frame pushed last, and Frame2 the oldest. CurrentFrameCopy is not touched.

~HistoryFrame()

Finalizes an instance of the VisioForge.Core.Types.FastImageProcessing.HistoryFrame class. Releases unmanaged resources.

protected ~HistoryFrame()