public final class FakeImage implements MutableImageWrapper


Fake implementation of MutableImageWrapper for testing.

This class supports optional injection of both a ByteBuffer and a HardwareBuffer.

HardwareBuffer & Backing Behavior

If a hardwareBuffer is provided, its width, height, and format metadata will be verified and accessible. However, accessing pixel data directly from within the HardwareBuffer is not supported on pure JVM. Accessing the buffer fields from imagePlanes will use data backed by the byteBuffer parameter and/or byteBuffer field on this image.

If provided, the HardwareBuffer will be closed when this FakeImage is closed.

Summary

Public constructors

FakeImage(
    int width,
    int height,
    int format,
    long timestamp,
    ByteBuffer byteBuffer,
    HardwareBuffer hardwareBuffer,
    @NonNull Rect cropRect
)

Public methods

void
final int
@NonNull Rect
int
int
HardwareBuffer

Returns a handle to the underlying image's hardware buffer, or null if this image does not support hardware buffer.

int
@NonNull List<@NonNull ImagePlane>
SyncFence
long
int
final boolean
void
void
setDataSpace(int value)
void
void
setTimestamp(long value)
@NonNull String
T
<T extends Object> unwrapAs(@NonNull Class<@NonNull T> type)

Attempt to unwrap this object into an underlying type.

Public constructors

FakeImage

Added in 1.7.0-alpha02
public FakeImage(
    int width,
    int height,
    int format,
    long timestamp,
    ByteBuffer byteBuffer,
    HardwareBuffer hardwareBuffer,
    @NonNull Rect cropRect
)

Public methods

close

Added in 1.7.0-alpha02
public void close()

getCloseCount

Added in 1.7.0-alpha02
public final int getCloseCount()

getCropRect

Added in 1.7.0-alpha02
public @NonNull Rect getCropRect()
See also
setCropRect

getDataSpace

public int getDataSpace()
See also
setDataSpace

getFormat

Added in 1.7.0-alpha02
public int getFormat()
See also
getFormat

getHardwareBuffer

public HardwareBuffer getHardwareBuffer()

Returns a handle to the underlying image's hardware buffer, or null if this image does not support hardware buffer.

The android.hardware.HardwareBuffer follows the lifecycle of its associated image. It is not required to be closed explicitly; however, the image needs to be closed after finishing processing the hardware buffer. In other words, if the hardware buffer is being used, the image cannot be closed.

getHeight

Added in 1.7.0-alpha02
public int getHeight()
See also
getHeight

getImagePlanes

Added in 1.7.0-alpha02
public @NonNull List<@NonNull ImagePlanegetImagePlanes()
See also
getPlanes

getSyncFence

public SyncFence getSyncFence()
See also
setFence

getTimestamp

Added in 1.7.0-alpha02
public long getTimestamp()
See also
setTimestamp

getWidth

Added in 1.7.0-alpha02
public int getWidth()
See also
getWidth

isClosed

Added in 1.7.0-alpha02
public final boolean isClosed()

setCropRect

Added in 1.7.0-alpha02
public void setCropRect(@NonNull Rect value)
See also
setCropRect

setDataSpace

Added in 1.7.0-alpha02
public void setDataSpace(int value)
See also
setDataSpace

setSyncFence

Added in 1.7.0-alpha02
public void setSyncFence(SyncFence value)
See also
setFence

setTimestamp

Added in 1.7.0-alpha02
public void setTimestamp(long value)
See also
setTimestamp

toString

public @NonNull String toString()

unwrapAs

Added in 1.7.0-alpha02
public T <T extends Object> unwrapAs(@NonNull Class<@NonNull T> type)

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