Table of Contents

Class HistoryFrame

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

History frame, contains 3 previous 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: - Frame0: Most recent frame (current - 1) - Frame1: Previous frame (current - 2) - Frame2: Oldest frame (current - 3) - CurrentFrameCopy: Copy of the current frame being processed

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 - Most recent historical frame (current - 1).

public nint Frame0

Field Value

nint

Remarks

Contains the frame data from one frame ago. This is typically used as the primary reference frame for motion detection and temporal filtering algorithms.

Frame1

Frame 1 - Previous historical frame (current - 2).

public nint Frame1

Field Value

nint

Remarks

Contains the frame data from two frames ago. Used for multi-frame analysis and advanced temporal processing algorithms.

Frame2

Frame 2 - Oldest historical frame (current - 3).

public nint Frame2

Field Value

nint

Remarks

Contains the frame data from three frames ago. 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.

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: Previous frame (t-1)
    // - history.Frame1: Frame before that (t-2)
    // - history.Frame2: Oldest frame (t-3)
}

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 most recent historical frame, and Frame2 contains the oldest. The current frame parameter is not stored directly but can be copied to CurrentFrameCopy if needed.

~HistoryFrame()

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

protected ~HistoryFrame()