class FakeImagePlane : ImagePlane


Fake implementation of ImagePlane for testing classes that consume camera image planes.

This class provides lazy buffer allocation and multiple construction paradigms to support both standalone dimension-based allocation and slicing from a shared contiguous parent buffer.

Usage Examples

1. Standalone Allocation by Dimensions

Allocates a direct ByteBuffer of size rowStride * rowCount when accessed.

val plane = FakeImagePlane(rowStride = 640, rowCount = 480)
assertThat(plane.buffer.capacity()).isEqualTo(640 * 480)

2. Custom Strides and Sub-sampling

Useful for mocking interleaved UV planes where pixel stride is 2.

val uvPlane = FakeImagePlane(rowStride = 640, rowCount = 240, pixelStride = 2)

3. Backing by an Existing Buffer Slice

Avoids extra allocations by wrapping an existing buffer window (e.g. from a contiguous NV12 buffer). Ensure the slice maintains native byte ordering (order(ByteOrder.nativeOrder())).

val slice = parentBuffer.slice().order(ByteOrder.nativeOrder())
val plane = FakeImagePlane(rowStride = 640, pixelStride = 1, buffer = slice)
assertThat(plane.buffer).isSameInstanceAs(slice)

Summary

Public constructors

FakeImagePlane(
    rowStride: Int,
    rowCount: Int,
    pixelStride: Int,
    buffer: ByteBuffer?
)

Public functions

open T?
<T : Any> unwrapAs(type: Class<T>)

Attempt to unwrap this object into an underlying type.

Public properties

open ByteBuffer
open Int

The distance between adjacent pixel samples in bytes.

open Int

The row stride of the plane in bytes.

Public constructors

FakeImagePlane

Added in 1.7.0-alpha02
FakeImagePlane(
    rowStride: Int,
    rowCount: Int = 1,
    pixelStride: Int = 1,
    buffer: ByteBuffer? = null
)
Parameters
rowStride: Int

The row stride of the plane in bytes.

rowCount: Int = 1

The height of the plane in rows. Used for lazy buffer allocation if buffer is null. Defaults to 1 (convenient for single-row compressed formats like JPEG).

pixelStride: Int = 1

The distance between adjacent pixel samples in bytes. Defaults to 1.

buffer: ByteBuffer? = null

An optional pre-allocated ByteBuffer to back this plane. If null, a direct buffer of size rowStride * rowCount is allocated lazily upon first access.

Public functions

unwrapAs

Added in 1.7.0-alpha02
open fun <T : Any> unwrapAs(type: Class<T>): T?

Attempt to unwrap this object into an underlying type.

This operation is not safe and should be used with caution as it makes no guarantees about the state of the underlying objects. In particular, implementations should assume that fakes, test wrappers will always return null. Finally this method should return null when unwrapping into the provided type is not supported.

Returns
T?

unwrapped object matching T or null

Public properties

buffer

Added in 1.7.0-alpha02
open val bufferByteBuffer
See also
getBuffer

pixelStride

Added in 1.7.0-alpha02
open val pixelStrideInt

The distance between adjacent pixel samples in bytes. Defaults to 1.

rowStride

Added in 1.7.0-alpha02
open val rowStrideInt

The row stride of the plane in bytes.