# FakeImagePlane

Artifact: [androidx.camera:camera-common-testing](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/common/testing/FakeImagePlane.kt+class:androidx.camera.common.testing.FakeImagePlane) Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

*** ** * ** ***


```
class FakeImagePlane : ImagePlane
```

<br />

*** ** * ** ***

Fake implementation of `https://developer.android.com/reference/kotlin/androidx/camera/common/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 `https://developer.android.com/reference/java/nio/ByteBuffer.html` of size `rowStride * rowCount` when accessed.

```kotlin
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.

```kotlin
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())`).

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane#FakeImagePlane(kotlin.Int,kotlin.Int,kotlin.Int,java.nio.ByteBuffer)( rowStride: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, rowCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, pixelStride: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html? )` |

| ### Public functions |
|---|---|
| `open T?` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane#unwrapAs(java.lang.Class)(type: https://developer.android.com/reference/java/lang/Class.html<T>)` Unwraps this fake image plane to its underlying implementation types. |

| ### Public properties |
|---|---|
| `open https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane#buffer()` A `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the image data for this plane. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane#pixelStride()` The distance between adjacent pixel samples in bytes. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane#rowStride()` The row stride of the plane in bytes. |

## Public constructors

### FakeImagePlane

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
FakeImagePlane(
    rowStride: Int,
    rowCount: Int = 1,
    pixelStride: Int = 1,
    buffer: ByteBuffer? = null
)
```

| Parameters |
|---|---|
| `rowStride: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The row stride of the plane in bytes. |
| `rowCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 1` | The height of the plane in rows. Used for lazy buffer allocation if `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane#(kotlin.Int,kotlin.Int,kotlin.Int,java.nio.ByteBuffer)` is null. Defaults to 1 (convenient for single-row compressed formats like JPEG). |
| `pixelStride: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 1` | The distance between adjacent pixel samples in bytes. Defaults to 1. |
| `buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html? = null` | An optional pre-allocated `https://developer.android.com/reference/java/nio/ByteBuffer.html` to back this plane. If null, a direct `https://developer.android.com/reference/java/nio/ByteBuffer.html` of size `rowStride * rowCount` is allocated lazily using `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeByteBuffers#allocateNative(kotlin.Int)` upon first access. |

## Public functions

### unwrapAs

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

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

Unwraps this fake image plane to its underlying implementation types.

This implementation supports unwrapping to:

- `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane` (returns `this`)

- `https://developer.android.com/reference/java/nio/ByteBuffer.html` (returns the backing `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane#buffer()`)

| Parameters |
|---|---|
| `type: https://developer.android.com/reference/java/lang/Class.html<T>` | The class representing the type to unwrap to. |

| Returns |
|---|---|
| `T?` | The unwrapped object instance of type `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane#unwrapAs(java.lang.Class)`, or `null` if the requested type is not supported. |

## Public properties

### buffer

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
open val buffer: ByteBuffer
```

A `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the image data for this plane.

If a custom `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane#buffer()` was passed to the constructor, it is returned directly. Otherwise, a direct `https://developer.android.com/reference/java/nio/ByteBuffer.html` with native byte order and capacity equal to `rowStride * rowCount` is allocated lazily upon first access.

### pixelStride

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
open val pixelStride: Int
```

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

### rowStride

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
open val rowStride: Int
```

The row stride of the plane in bytes.