Table of Contents

Struct RAWImage

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

Represents a raw image frame, providing direct access to image data in unmanaged memory. This struct is designed for high-performance image processing and interoperation with native code.

public struct RAWImage

Inherited Members

Remarks

The RAWImage struct holds a pointer to the raw pixel data, along with its dimensions, stride, and color space. It is crucial to manage the memory pointed to by VisioForge.Core.Types.RAWImage.Data using the VisioForge.Core.Types.RAWImage.Alloc and VisioForge.Core.Types.RAWImage.Free methods, or ensure that the memory is managed externally if the RAWImage is merely a view into an existing buffer. This struct is marked with [StructLayout(LayoutKind.Sequential)] to ensure its memory layout is compatible with native structures. The Stride field is critical for correct memory access - it represents the byte width of each row including any padding for alignment. Always use Stride * Height to calculate the total buffer size, never Width * BytesPerPixel * Height. This type is commonly used when interfacing with native image processing libraries, video decoders, or when optimizing critical image operations. Memory allocated with Alloc() must be freed with Free() to prevent leaks - consider using try/finally blocks. The constructor allows wrapping existing memory without allocation, useful for zero-copy scenarios.

Constructors

RAWImage(nint, int, int, int, int, RAWVideoColorSpace)

Initializes a new instance of the VisioForge.Core.Types.RAWImage struct with specified parameters.

public RAWImage(nint data, int dataSize, int width, int height, int stride, RAWVideoColorSpace colorspace)

Parameters

data nint

A pointer to the raw image data.

dataSize int

The size of the data in bytes.

width int

The width of the image in pixels.

height int

The height of the image in pixels.

stride int

The stride of the image in bytes.

colorspace RAWVideoColorSpace

The color space of the image.

Fields

Colorspace

Gets or sets the color space format of the raw image data.

public RAWVideoColorSpace Colorspace

Field Value

RAWVideoColorSpace

See Also

Data

Gets or sets a pointer to the unmanaged memory buffer containing the raw pixel data.

public nint Data

Field Value

nint

DataSize

Gets or sets the total size of the image data buffer in bytes. This is typically VisioForge.Core.Types.RAWImage.Stride multiplied by VisioForge.Core.Types.RAWImage.Height.

public int DataSize

Field Value

int

Height

Gets or sets the height of the image in pixels.

public int Height

Field Value

int

Stride

Gets or sets the stride (or pitch) of the image in bytes. This is the number of bytes required to store one row of pixels, including any padding.

public int Stride

Field Value

int

Width

Gets or sets the width of the image in pixels.

public int Width

Field Value

int

Methods

Alloc()

Allocates unmanaged memory for the image data buffer based on the VisioForge.Core.Types.RAWImage.Stride and VisioForge.Core.Types.RAWImage.Height. The VisioForge.Core.Types.RAWImage.DataSize field is updated accordingly.

public void Alloc()

Remarks

This method should be called before writing pixel data to the VisioForge.Core.Types.RAWImage.Data pointer. It is crucial to call VisioForge.Core.Types.RAWImage.Free when the allocated memory is no longer needed.

Free()

Frees the unmanaged memory previously allocated for the image data buffer.

public void Free()

Remarks

This method should always be called to prevent memory leaks when the RAWImage instance is no longer needed, especially if VisioForge.Core.Types.RAWImage.Alloc was used.