object CameraMath


Utility functions for doing common transformations of camera and sensor coordinate spaces.

When doing camera coordinate transformations, there are three main "coordinate spaces" that a developer may need to understand and work with:

  • Sensor-relative coordinates: These are integer-pixel coordinates that correspond to the physical active pixel array of a camera device. Most operations in Camera2 (like 3A metering regions or crop regions) define coordinates relative to the physical sensor (with (0,0) being the top-left active pixel).

  • Stream-relative coordinates: When configuring camera output streams, they are configured with a specific resolution. The stream coordinate space is axially aligned and centered within the crop region of the sensor, but may be further cropped either horizontally or vertically to maintain square pixels and its own aspect ratio (see Android's camera cropping specification at Output streams, cropping, and zoom). Stream coordinates are relative to the streamWidth and streamHeight boundaries.

  • UI-relative coordinates: These represent the display area of a stream on a UI surface (like a viewfinder). UI coordinates are scaled, potentially mirrored, and rotated relative to the coordinate system of the screen or window the viewfinder is currently displayed on. Note: The uiWidth and uiHeight used in calculations represent the UI-relative size of the viewfinder, without accounting for any viewport clipping or padding. Callers must normalize UI coordinates to account for clipping or padding before calling these functions.

Summary

Constants

const Int

When converting to sensor coordinates, this is the minimum width/height for rectangles that will be sent to the sensor.

const Float

It's common to need to convert a point into a sensor-relative rectangle for things like touch-to-focus, which often starts from a touch point that then needs to be converted into a sensor-relative rectangle.

Public functions

inline DiscreteRotation
computeSensorRotationToDisplayOrientation(
    displayRotation: DiscreteRotation,
    sensorOrientation: DiscreteRotation,
    sensorIsFacingScreen: Boolean
)

Computes the rotation required to rotate coordinates from sensor space to the display coordinate system.

DiscreteRotation
computeSensorRotationToDisplayOrientation(
    displayRotation: Int,
    sensorOrientation: Int,
    sensorIsFacingScreen: Boolean
)

Computes the rotation required to rotate coordinates from sensor space to the display coordinate system.

inline DiscreteRotation
computeSensorRotationToJpegOrientation(
    deviceOrientation: DiscreteRotation,
    sensorOrientation: DiscreteRotation,
    sensorIsFacingScreen: Boolean
)

Computes the clockwise rotation required to be applied to the captured image to be viewed upright.

DiscreteRotation
computeSensorRotationToJpegOrientation(
    deviceOrientation: Int,
    sensorOrientation: Int,
    sensorIsFacingScreen: Boolean
)

Computes the clockwise rotation required to be applied to the captured image to be viewed upright.

inline T
<T : Any?> mapSensorPointToStreamPoint(
    sensorX: Int,
    sensorY: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toStreamPoint: (streamX: Float, streamY: Float) -> T
)

Converts a point relative to the camera sensor to an equivalent point relative to a specific camera stream.

PointF
mapSensorPointToStreamPointF(
    sensorPoint: Point,
    streamSize: Size,
    sensorCrop: Rect
)

Converts a point relative to the camera sensor to an equivalent point relative to a specific camera stream.

inline T
<T : Any?> mapSensorPointToUiPoint(
    sensorX: Int,
    sensorY: Int,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toUiPoint: (uiX: Float, uiY: Float) -> T
)

Converts a point relative to the camera sensor to an equivalent point relative to a UI element.

PointF
mapSensorPointToUiPointF(
    sensorPoint: Point,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    sensorCrop: Rect
)

Converts a point relative to the camera sensor to an equivalent point relative to a UI element.

inline T
<T : Any?> mapSensorRectToStreamRect(
    sensorLeft: Int,
    sensorTop: Int,
    sensorRight: Int,
    sensorBottom: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toStreamRect: (streamLeft: Float, streamTop: Float, streamRight: Float, streamBottom: Float) -> T
)

Converts a rectangle relative to the camera sensor to an equivalent rectangle relative to a specific camera stream.

RectF
mapSensorRectToStreamRectF(
    sensorRect: Rect,
    streamSize: Size,
    sensorCrop: Rect
)

Converts a rectangle relative to the camera sensor to an equivalent rectangle relative to a specific camera stream.

inline T
<T : Any?> mapSensorRectToUiRect(
    sensorLeft: Int,
    sensorTop: Int,
    sensorRight: Int,
    sensorBottom: Int,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toUiRect: (uiLeft: Float, uiTop: Float, uiRight: Float, uiBottom: Float) -> T
)

Converts a rectangle relative to the camera sensor to an equivalent rectangle relative to a UI element.

RectF
mapSensorRectToUiRectF(
    sensorRect: Rect,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    sensorCrop: Rect
)

Converts a rectangle relative to the camera sensor to an equivalent rectangle relative to a UI element.

inline T
<T : Any?> mapSensorSizeToStreamSize(
    sensorSizeWidth: Int,
    sensorSizeHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toStreamSize: (streamWidth: Float, streamHeight: Float) -> T
)

Converts a size relative to the camera sensor to an equivalent size relative to a specific camera stream.

SizeF
mapSensorSizeToStreamSizeF(
    size: Size,
    streamSize: Size,
    sensorCropWidth: Int,
    sensorCropHeight: Int
)

Converts a size relative to the camera sensor to an equivalent size relative to a specific camera stream.

inline T
<T : Any?> mapSensorSizeToUiSize(
    sensorSizeWidth: Int,
    sensorSizeHeight: Int,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toUiSize: (uiSizeWidth: Float, uiSizeHeight: Float) -> T
)

Converts a size relative to the camera sensor to an equivalent size relative to a UI element.

SizeF
mapSensorSizeToUiSizeF(
    size: Size,
    uiSize: Size,
    streamSize: Size,
    sensorRotationToDisplayOrientation: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int
)

Converts a size relative to the camera sensor to an equivalent size relative to a UI element.

Point
mapStreamPointToSensorPoint(
    streamPoint: PointF,
    streamSize: Size,
    sensorCrop: Rect,
    coerceToCropRegion: Boolean
)

Converts a point relative to a specific camera stream to an equivalent point relative to the camera sensor.

inline T
<T : Any?> mapStreamPointToSensorPoint(
    streamX: Float,
    streamY: Float,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    coerceToCropRegion: Boolean,
    crossinline toSensorPoint: (sensorX: Int, sensorY: Int) -> T
)

Converts a point relative to a specific camera stream to an equivalent point relative to the camera sensor.

Rect
mapStreamPointToSensorRect(
    streamPoint: PointF,
    streamSize: Size,
    sensorCrop: Rect,
    minimumSensorSize: Int,
    coerceToCropRegion: Boolean,
    touchToFocusRatio: Float
)

Converts a point relative to a specific camera stream to an equivalent rectangle relative to the camera sensor.

inline T
<T : Any?> mapStreamPointToSensorRect(
    streamX: Float,
    streamY: Float,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    minimumSensorSize: Int,
    coerceToCropRegion: Boolean,
    ratio: Float,
    crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T
)

Converts a point relative to a specific camera stream to an equivalent rectangle relative to the camera sensor.

inline T
<T : Any?> mapStreamPointToUiPoint(
    streamX: Float,
    streamY: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toUiPoint: (uiX: Float, uiY: Float) -> T
)

Converts a point relative to a specific camera stream to an equivalent point relative to a UI element.

PointF
mapStreamPointToUiPointF(
    streamPoint: PointF,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int
)

Converts a point relative to a specific camera stream to an equivalent point relative to a UI element.

Rect
mapStreamRectToSensorRect(
    streamRect: RectF,
    streamSize: Size,
    sensorCrop: Rect,
    minimumSensorSize: Int,
    coerceToCropRegion: Boolean
)

Converts a rectangle relative to a specific camera stream to an equivalent rectangle relative to the camera sensor.

inline T
<T : Any?> mapStreamRectToSensorRect(
    streamLeft: Float,
    streamTop: Float,
    streamRight: Float,
    streamBottom: Float,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    minimumSensorSize: Int,
    coerceToCropRegion: Boolean,
    crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T
)

Converts a rectangle relative to a specific camera stream to an equivalent rectangle relative to the camera sensor.

inline T
<T : Any?> mapStreamRectToUiRect(
    streamLeft: Float,
    streamTop: Float,
    streamRight: Float,
    streamBottom: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toUiRect: (uiLeft: Float, uiTop: Float, uiRight: Float, uiBottom: Float) -> T
)

Converts a rectangle relative to a specific camera stream to an equivalent rectangle relative to a UI element.

RectF
mapStreamRectToUiRectF(
    streamRect: RectF,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int
)

Converts a rectangle relative to a specific camera stream to an equivalent rectangle relative to a UI element.

Size
mapStreamSizeToSensorSize(
    size: Size,
    streamSize: Size,
    sensorCropWidth: Int,
    sensorCropHeight: Int
)

Converts a size relative to a specific camera stream to an equivalent size relative to the camera sensor.

inline T
<T : Any?> mapStreamSizeToSensorSize(
    streamSizeWidth: Float,
    streamSizeHeight: Float,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toSensorSize: (sensorWidth: Int, sensorHeight: Int) -> T
)

Converts a size relative to a specific camera stream to an equivalent size relative to the camera sensor.

inline T
<T : Any?> mapStreamSizeToUiSize(
    streamSizeWidth: Float,
    streamSizeHeight: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toUiSize: (width: Float, height: Float) -> T
)

Converts a size relative to a specific camera stream to an equivalent size relative to a UI element.

SizeF
mapStreamSizeToUiSizeF(
    size: Size,
    uiSize: Size,
    streamSize: Size,
    sensorRotationToDisplayOrientation: Int
)

Converts a size relative to a specific camera stream to an equivalent size relative to a UI element.

Point
mapUiPointToSensorPoint(
    uiPoint: Point,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    sensorCrop: Rect,
    coerceToCropRegion: Boolean
)

Converts a point relative to a UI element to an equivalent point relative to the camera sensor.

inline T
<T : Any?> mapUiPointToSensorPoint(
    uiX: Float,
    uiY: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    coerceToCropRegion: Boolean,
    crossinline toSensorPoint: (sensorX: Int, sensorY: Int) -> T
)

Converts a point relative to a UI element to an equivalent point relative to the camera sensor.

Rect
mapUiPointToSensorRect(
    uiPoint: Point,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    sensorCrop: Rect,
    minimumSensorSize: Int,
    coerceToCropRegion: Boolean,
    touchToFocusRatio: Float
)

Converts a point relative to a UI element to an equivalent rectangle relative to the camera sensor.

inline T
<T : Any?> mapUiPointToSensorRect(
    uiX: Float,
    uiY: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    minimumSensorSize: Int,
    coerceToCropRegion: Boolean,
    ratio: Float,
    crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T
)

Converts a point relative to a UI element to an equivalent rectangle relative to the camera sensor.

inline T
<T : Any?> mapUiPointToStreamPoint(
    uiX: Float,
    uiY: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toStreamPoint: (streamX: Float, streamY: Float) -> T
)

Converts a point relative to a UI element to an equivalent point relative to a specific camera stream.

PointF
mapUiPointToStreamPointF(
    uiPoint: Point,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int
)

Converts a point relative to a UI element to an equivalent point relative to a specific camera stream.

inline T
<T : Any?> mapUiPointToStreamRect(
    uiX: Float,
    uiY: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    ratio: Float,
    crossinline toStreamRect: (streamLeft: Float, streamTop: Float, streamRight: Float, streamBottom: Float) -> T
)

Converts a point relative to a UI element to an equivalent rectangle relative to a specific camera stream.

RectF
mapUiPointToStreamRectF(
    uiPoint: Point,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    touchToFocusRatio: Float
)

Converts a point relative to a UI element to an equivalent rectangle relative to a specific camera stream.

Rect
mapUiRectToSensorRect(
    uiRect: RectF,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    sensorCrop: Rect,
    minimumSensorSize: Int,
    coerceToCropRegion: Boolean
)

Converts a rectangle relative to a UI element to an equivalent rectangle relative to the camera sensor.

inline T
<T : Any?> mapUiRectToSensorRect(
    uiLeft: Float,
    uiTop: Float,
    uiRight: Float,
    uiBottom: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    minimumSensorSize: Int,
    coerceToCropRegion: Boolean,
    crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T
)

Converts a rectangle relative to a UI element to an equivalent rectangle relative to the camera sensor.

inline T
<T : Any?> mapUiRectToStreamRect(
    uiLeft: Float,
    uiTop: Float,
    uiRight: Float,
    uiBottom: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toStreamRect: (streamLeft: Float, streamTop: Float, streamRight: Float, streamBottom: Float) -> T
)

Converts a rectangle relative to a UI element to an equivalent rectangle relative to a specific camera stream.

RectF
mapUiRectToStreamRectF(
    uiRect: RectF,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int
)

Converts a rectangle relative to a UI element to an equivalent rectangle relative to a specific camera stream.

Size
mapUiSizeToSensorSize(
    size: Size,
    uiSize: Size,
    streamSize: Size,
    sensorRotationToDisplayOrientation: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int
)

Converts a size relative to a UI element to an equivalent size relative to the camera sensor.

inline T
<T : Any?> mapUiSizeToSensorSize(
    uiSizeWidth: Float,
    uiSizeHeight: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toSensorSize: (sensorWidth: Int, sensorHeight: Int) -> T
)

Converts a size relative to a UI element to an equivalent size relative to the camera sensor.

inline T
<T : Any?> mapUiSizeToStreamSize(
    uiSizeWidth: Float,
    uiSizeHeight: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toStreamSize: (streamWidth: Float, streamHeight: Float) -> T
)

Converts a size relative to a UI element to an equivalent size relative to a specific camera stream.

SizeF
mapUiSizeToStreamSizeF(
    size: Size,
    uiSize: Size,
    streamSize: Size,
    sensorRotationToDisplayOrientation: Int
)

Converts a size relative to a UI element to an equivalent size relative to a specific camera stream.

Constants

DEFAULT_MIN_SENSOR_PIXELS

Added in 1.7.0-alpha02
const val DEFAULT_MIN_SENSOR_PIXELS = 32: Int

When converting to sensor coordinates, this is the minimum width/height for rectangles that will be sent to the sensor. This helps prevent scenarios where rectangles need to be clamped to the sensor, but where setting a small, or zero, size can lead to unexpected or bad behavior.

DEFAULT_POINT_TO_RECT_RATIO

Added in 1.7.0-alpha02
const val DEFAULT_POINT_TO_RECT_RATIO = 0.18375f: Float

It's common to need to convert a point into a sensor-relative rectangle for things like touch-to-focus, which often starts from a touch point that then needs to be converted into a sensor-relative rectangle.

This ratio is used to compute a rectangle based on the short dimension of the current stream.

Public functions

computeSensorRotationToDisplayOrientation

Added in 1.7.0-alpha02
inline fun computeSensorRotationToDisplayOrientation(
    displayRotation: DiscreteRotation,
    sensorOrientation: DiscreteRotation,
    sensorIsFacingScreen: Boolean
): DiscreteRotation

Computes the rotation required to rotate coordinates from sensor space to the display coordinate system.

Parameters
displayRotation: DiscreteRotation

The rotation of the display.

sensorOrientation: DiscreteRotation

The physical orientation of the sensor.

sensorIsFacingScreen: Boolean

Whether the camera sensor is facing the screen (front-facing).

computeSensorRotationToDisplayOrientation

Added in 1.7.0-alpha02
fun computeSensorRotationToDisplayOrientation(
    displayRotation: Int,
    sensorOrientation: Int,
    sensorIsFacingScreen: Boolean
): DiscreteRotation

Computes the rotation required to rotate coordinates from sensor space to the display coordinate system.

Parameters
displayRotation: Int

The rotation of the display in degrees. Must be one of 0, 90, 180, 270. (Note: do not pass Surface.ROTATION_X constants directly as they represent index values rather than degrees).

sensorOrientation: Int

The physical orientation of the sensor in degrees (typically SENSOR_ORIENTATION from CameraCharacteristics). Must be one of 0, 90, 180, 270.

sensorIsFacingScreen: Boolean

Whether the camera sensor is facing the screen (front-facing).

computeSensorRotationToJpegOrientation

Added in 1.7.0-alpha02
inline fun computeSensorRotationToJpegOrientation(
    deviceOrientation: DiscreteRotation,
    sensorOrientation: DiscreteRotation,
    sensorIsFacingScreen: Boolean
): DiscreteRotation

Computes the clockwise rotation required to be applied to the captured image to be viewed upright.

Parameters
deviceOrientation: DiscreteRotation

The orientation of the device.

sensorOrientation: DiscreteRotation

The physical orientation of the sensor.

sensorIsFacingScreen: Boolean

Whether the camera sensor is facing the screen (front-facing).

computeSensorRotationToJpegOrientation

Added in 1.7.0-alpha02
fun computeSensorRotationToJpegOrientation(
    deviceOrientation: Int,
    sensorOrientation: Int,
    sensorIsFacingScreen: Boolean
): DiscreteRotation

Computes the clockwise rotation required to be applied to the captured image to be viewed upright.

Parameters
deviceOrientation: Int

The orientation of the device in degrees.

sensorOrientation: Int

The physical orientation of the sensor (typically SENSOR_ORIENTATION from CameraCharacteristics).

sensorIsFacingScreen: Boolean

Whether the camera sensor is facing the screen (front-facing).

mapSensorPointToStreamPoint

Added in 1.7.0-alpha02
inline fun <T : Any?> mapSensorPointToStreamPoint(
    sensorX: Int,
    sensorY: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toStreamPoint: (streamX: Float, streamY: Float) -> T
): T

Converts a point relative to the camera sensor to an equivalent point relative to a specific camera stream.

Parameters
sensorX: Int

The x coordinate on the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorY: Int

The y coordinate on the sensor. Sensor coordinates are relative to the sensor 0,0.

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

sensorCropX: Int

The x coordinate of the crop region of the sensor.

sensorCropY: Int

The y coordinate of the crop region of the sensor.

sensorCropWidth: Int

The width of the crop region of the sensor.

sensorCropHeight: Int

The height of the crop region of the sensor.

crossinline toStreamPoint: (streamX: Float, streamY: Float) -> T

A callback to construct the final return object from the computed stream coordinates.

mapSensorPointToStreamPointF

Added in 1.7.0-alpha02
fun mapSensorPointToStreamPointF(
    sensorPoint: Point,
    streamSize: Size,
    sensorCrop: Rect
): PointF

Converts a point relative to the camera sensor to an equivalent point relative to a specific camera stream.

Parameters
sensorPoint: Point

The point on the sensor. Sensor coordinates are relative to the sensor 0,0.

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

sensorCrop: Rect

The crop region of the sensor (typically CameraMetadata.SCALER_CROP_REGION, or CameraMetadata.SENSOR_INFO_ACTIVE_ARRAY_SIZE if no crop is applied).

mapSensorPointToUiPoint

inline fun <T : Any?> mapSensorPointToUiPoint(
    sensorX: Int,
    sensorY: Int,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toUiPoint: (uiX: Float, uiY: Float) -> T
): T

Converts a point relative to the camera sensor to an equivalent point relative to a UI element.

Parameters
sensorX: Int

The x coordinate on the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorY: Int

The y coordinate on the sensor. Sensor coordinates are relative to the sensor 0,0.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

sensorCropX: Int

The x coordinate of the crop region of the sensor.

sensorCropY: Int

The y coordinate of the crop region of the sensor.

sensorCropWidth: Int

The width of the crop region of the sensor.

sensorCropHeight: Int

The height of the crop region of the sensor.

crossinline toUiPoint: (uiX: Float, uiY: Float) -> T

A callback to construct the final return object from the computed UI coordinates.

mapSensorPointToUiPointF

Added in 1.7.0-alpha02
fun mapSensorPointToUiPointF(
    sensorPoint: Point,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    sensorCrop: Rect
): PointF

Converts a point relative to the camera sensor to an equivalent point relative to a UI element.

Parameters
sensorPoint: Point

The point on the sensor. Sensor coordinates are relative to the sensor 0,0.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

sensorCrop: Rect

The crop region of the sensor (typically CameraMetadata.SCALER_CROP_REGION, or CameraMetadata.SENSOR_INFO_ACTIVE_ARRAY_SIZE if no crop is applied).

mapSensorRectToStreamRect

Added in 1.7.0-alpha02
inline fun <T : Any?> mapSensorRectToStreamRect(
    sensorLeft: Int,
    sensorTop: Int,
    sensorRight: Int,
    sensorBottom: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toStreamRect: (streamLeft: Float, streamTop: Float, streamRight: Float, streamBottom: Float) -> T
): T

Converts a rectangle relative to the camera sensor to an equivalent rectangle relative to a specific camera stream.

Parameters
sensorLeft: Int

The left coordinate of the rectangle on the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorTop: Int

The top coordinate of the rectangle on the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorRight: Int

The right coordinate of the rectangle on the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorBottom: Int

The bottom coordinate of the rectangle on the sensor. Sensor coordinates are relative to the sensor 0,0.

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

sensorCropX: Int

The x coordinate of the crop region of the sensor.

sensorCropY: Int

The y coordinate of the crop region of the sensor.

sensorCropWidth: Int

The width of the crop region of the sensor.

sensorCropHeight: Int

The height of the crop region of the sensor.

crossinline toStreamRect: (streamLeft: Float, streamTop: Float, streamRight: Float, streamBottom: Float) -> T

A callback to construct the final return object from the computed stream coordinates.

mapSensorRectToStreamRectF

Added in 1.7.0-alpha02
fun mapSensorRectToStreamRectF(
    sensorRect: Rect,
    streamSize: Size,
    sensorCrop: Rect
): RectF

Converts a rectangle relative to the camera sensor to an equivalent rectangle relative to a specific camera stream.

Parameters
sensorRect: Rect

The rectangle on the sensor. Sensor coordinates are relative to the sensor 0,0.

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

sensorCrop: Rect

The crop region of the sensor (typically CameraMetadata.SCALER_CROP_REGION, or CameraMetadata.SENSOR_INFO_ACTIVE_ARRAY_SIZE if no crop is applied).

mapSensorRectToUiRect

inline fun <T : Any?> mapSensorRectToUiRect(
    sensorLeft: Int,
    sensorTop: Int,
    sensorRight: Int,
    sensorBottom: Int,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toUiRect: (uiLeft: Float, uiTop: Float, uiRight: Float, uiBottom: Float) -> T
): T

Converts a rectangle relative to the camera sensor to an equivalent rectangle relative to a UI element.

Parameters
sensorLeft: Int

The left coordinate of the rectangle on the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorTop: Int

The top coordinate of the rectangle on the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorRight: Int

The right coordinate of the rectangle on the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorBottom: Int

The bottom coordinate of the rectangle on the sensor. Sensor coordinates are relative to the sensor 0,0.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

sensorCropX: Int

The x coordinate of the crop region of the sensor.

sensorCropY: Int

The y coordinate of the crop region of the sensor.

sensorCropWidth: Int

The width of the crop region of the sensor.

sensorCropHeight: Int

The height of the crop region of the sensor.

crossinline toUiRect: (uiLeft: Float, uiTop: Float, uiRight: Float, uiBottom: Float) -> T

A callback to construct the final return object from the computed UI coordinates.

mapSensorRectToUiRectF

Added in 1.7.0-alpha02
fun mapSensorRectToUiRectF(
    sensorRect: Rect,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    sensorCrop: Rect
): RectF

Converts a rectangle relative to the camera sensor to an equivalent rectangle relative to a UI element.

Parameters
sensorRect: Rect

The rectangle on the sensor. Sensor coordinates are relative to the sensor 0,0.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

sensorCrop: Rect

The crop region of the sensor (typically CameraMetadata.SCALER_CROP_REGION, or CameraMetadata.SENSOR_INFO_ACTIVE_ARRAY_SIZE if no crop is applied).

mapSensorSizeToStreamSize

Added in 1.7.0-alpha02
inline fun <T : Any?> mapSensorSizeToStreamSize(
    sensorSizeWidth: Int,
    sensorSizeHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toStreamSize: (streamWidth: Float, streamHeight: Float) -> T
): T

Converts a size relative to the camera sensor to an equivalent size relative to a specific camera stream.

Parameters
sensorSizeWidth: Int

The width of the size on the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorSizeHeight: Int

The height of the size on the sensor. Sensor coordinates are relative to the sensor 0,0.

streamWidth: Float

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Float

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

sensorCropWidth: Int

The width of the sensor crop region.

sensorCropHeight: Int

The height of the sensor crop region.

crossinline toStreamSize: (streamWidth: Float, streamHeight: Float) -> T

A callback to construct the final return object from the computed stream coordinates.

mapSensorSizeToStreamSizeF

Added in 1.7.0-alpha02
fun mapSensorSizeToStreamSizeF(
    size: Size,
    streamSize: Size,
    sensorCropWidth: Int,
    sensorCropHeight: Int
): SizeF

Converts a size relative to the camera sensor to an equivalent size relative to a specific camera stream.

Parameters
size: Size

The size on the sensor. Sensor coordinates are relative to the sensor 0,0.

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

sensorCropWidth: Int

The width of the sensor crop region.

sensorCropHeight: Int

The height of the sensor crop region.

mapSensorSizeToUiSize

inline fun <T : Any?> mapSensorSizeToUiSize(
    sensorSizeWidth: Int,
    sensorSizeHeight: Int,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toUiSize: (uiSizeWidth: Float, uiSizeHeight: Float) -> T
): T

Converts a size relative to the camera sensor to an equivalent size relative to a UI element.

Parameters
sensorSizeWidth: Int

The width of the size on the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorSizeHeight: Int

The height of the size on the sensor. Sensor coordinates are relative to the sensor 0,0.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

sensorCropWidth: Int

The width of the sensor crop region.

sensorCropHeight: Int

The height of the sensor crop region.

crossinline toUiSize: (uiSizeWidth: Float, uiSizeHeight: Float) -> T

A callback to construct the final return object from the computed UI coordinates.

mapSensorSizeToUiSizeF

Added in 1.7.0-alpha02
fun mapSensorSizeToUiSizeF(
    size: Size,
    uiSize: Size,
    streamSize: Size,
    sensorRotationToDisplayOrientation: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int
): SizeF

Converts a size relative to the camera sensor to an equivalent size relative to a UI element.

Parameters
size: Size

The size on the sensor. Sensor coordinates are relative to the sensor 0,0.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

sensorCropWidth: Int

The width of the sensor crop region.

sensorCropHeight: Int

The height of the sensor crop region.

mapStreamPointToSensorPoint

Added in 1.7.0-alpha02
fun mapStreamPointToSensorPoint(
    streamPoint: PointF,
    streamSize: Size,
    sensorCrop: Rect,
    coerceToCropRegion: Boolean = true
): Point

Converts a point relative to a specific camera stream to an equivalent point relative to the camera sensor.

Parameters
streamPoint: PointF

The point in the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamSize: Size

The size of the camera stream.

sensorCrop: Rect

The crop region of the sensor (typically CameraMetadata.SCALER_CROP_REGION, or CameraMetadata.SENSOR_INFO_ACTIVE_ARRAY_SIZE if no crop is applied). Sensor coordinates are relative to the sensor 0,0.

coerceToCropRegion: Boolean = true

Whether to coerce the output point into the crop region.

mapStreamPointToSensorPoint

Added in 1.7.0-alpha02
inline fun <T : Any?> mapStreamPointToSensorPoint(
    streamX: Float,
    streamY: Float,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    coerceToCropRegion: Boolean = true,
    crossinline toSensorPoint: (sensorX: Int, sensorY: Int) -> T
): T

Converts a point relative to a specific camera stream to an equivalent point relative to the camera sensor.

Parameters
streamX: Float

The x coordinate in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamY: Float

The y coordinate in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamWidth: Int

The width of the camera stream.

streamHeight: Int

The height of the camera stream.

sensorCropX: Int

The x coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropY: Int

The y coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropWidth: Int

The width of the crop region of the sensor.

sensorCropHeight: Int

The height of the crop region of the sensor.

coerceToCropRegion: Boolean = true

Whether to coerce the output point into the crop region.

crossinline toSensorPoint: (sensorX: Int, sensorY: Int) -> T

A callback to construct the final return object from the computed sensor coordinates.

mapStreamPointToSensorRect

Added in 1.7.0-alpha02
fun mapStreamPointToSensorRect(
    streamPoint: PointF,
    streamSize: Size,
    sensorCrop: Rect,
    minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS,
    coerceToCropRegion: Boolean = true,
    touchToFocusRatio: Float = DEFAULT_POINT_TO_RECT_RATIO
): Rect

Converts a point relative to a specific camera stream to an equivalent rectangle relative to the camera sensor.

The output rectangle will have a size determined by the touchToFocusRatio and will be centered on the mapped point. If the calculated rectangle is smaller than minimumSensorSize in either dimension, it will be expanded symmetrically from its center to reach the minimum.

Parameters
streamPoint: PointF

The point in the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamSize: Size

The size of the camera stream.

sensorCrop: Rect

The crop region of the sensor (typically CameraMetadata.SCALER_CROP_REGION, or CameraMetadata.SENSOR_INFO_ACTIVE_ARRAY_SIZE if no crop is applied).

minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS

The minimum allowed width and height for the output rectangle in sensor pixels. If the calculated rectangle is smaller than this value in either dimension, it will be expanded symmetrically from its center to reach the minimum. Defaults to DEFAULT_MIN_SENSOR_PIXELS. Set to 0 or less to disable this behavior.

coerceToCropRegion: Boolean = true

Whether to coerce the output rectangle into the crop region.

touchToFocusRatio: Float = DEFAULT_POINT_TO_RECT_RATIO

The ratio to use when computing a rectangle based on the short dimension of the stream.

mapStreamPointToSensorRect

Added in 1.7.0-alpha02
inline fun <T : Any?> mapStreamPointToSensorRect(
    streamX: Float,
    streamY: Float,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS,
    coerceToCropRegion: Boolean = true,
    ratio: Float = DEFAULT_POINT_TO_RECT_RATIO,
    crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T
): T

Converts a point relative to a specific camera stream to an equivalent rectangle relative to the camera sensor.

Parameters
streamX: Float

The x coordinate in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamY: Float

The y coordinate in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamWidth: Int

The width of the camera stream.

streamHeight: Int

The height of the camera stream.

sensorCropX: Int

The x coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropY: Int

The y coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropWidth: Int

The width of the crop region of the sensor.

sensorCropHeight: Int

The height of the crop region of the sensor.

minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS

The minimum allowed width and height for the output rectangle in sensor pixels. If the calculated rectangle is smaller than this value in either dimension, it will be expanded symmetrically from its center to reach the minimum. Defaults to DEFAULT_MIN_SENSOR_PIXELS. Set to 0 or less to disable this behavior.

coerceToCropRegion: Boolean = true

Whether to coerce the output rectangle into the crop region.

ratio: Float = DEFAULT_POINT_TO_RECT_RATIO

The ratio to use when computing a rectangle based on the short dimension of the stream.

crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T

A callback to construct the final return object from the computed sensor coordinates.

mapStreamPointToUiPoint

inline fun <T : Any?> mapStreamPointToUiPoint(
    streamX: Float,
    streamY: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toUiPoint: (uiX: Float, uiY: Float) -> T
): T

Converts a point relative to a specific camera stream to an equivalent point relative to a UI element.

Parameters
streamX: Float

The x coordinate in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamY: Float

The y coordinate in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream.

streamHeight: Int

The height of the camera stream.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

crossinline toUiPoint: (uiX: Float, uiY: Float) -> T

A callback to construct the final return object from the computed UI coordinates.

mapStreamPointToUiPointF

Added in 1.7.0-alpha02
fun mapStreamPointToUiPointF(
    streamPoint: PointF,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int
): PointF

Converts a point relative to a specific camera stream to an equivalent point relative to a UI element.

Parameters
streamPoint: PointF

The point in the camera stream. Stream coordinates are relative to the streamWidth/Height.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

mapStreamRectToSensorRect

Added in 1.7.0-alpha02
fun mapStreamRectToSensorRect(
    streamRect: RectF,
    streamSize: Size,
    sensorCrop: Rect,
    minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS,
    coerceToCropRegion: Boolean = true
): Rect

Converts a rectangle relative to a specific camera stream to an equivalent rectangle relative to the camera sensor.

Parameters
streamRect: RectF

The rectangle in the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamSize: Size

The size of the camera stream.

sensorCrop: Rect

The crop region of the sensor (typically CameraMetadata.SCALER_CROP_REGION, or CameraMetadata.SENSOR_INFO_ACTIVE_ARRAY_SIZE if no crop is applied). Sensor coordinates are relative to the sensor 0,0.

minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS

The minimum allowed width and height for the output rectangle in sensor pixels. If the calculated rectangle is smaller than this value in either dimension, it will be expanded symmetrically from its center to reach the minimum. Defaults to DEFAULT_MIN_SENSOR_PIXELS. Set to 0 or less to disable this behavior.

coerceToCropRegion: Boolean = true

Whether to coerce the output rectangle into the crop region.

mapStreamRectToSensorRect

Added in 1.7.0-alpha02
inline fun <T : Any?> mapStreamRectToSensorRect(
    streamLeft: Float,
    streamTop: Float,
    streamRight: Float,
    streamBottom: Float,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS,
    coerceToCropRegion: Boolean = true,
    crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T
): T

Converts a rectangle relative to a specific camera stream to an equivalent rectangle relative to the camera sensor.

Parameters
streamLeft: Float

The left coordinate of the rectangle in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamTop: Float

The top coordinate of the rectangle in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamRight: Float

The right coordinate of the rectangle in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamBottom: Float

The bottom coordinate of the rectangle in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamWidth: Int

The width of the camera stream.

streamHeight: Int

The height of the camera stream.

sensorCropX: Int

The x coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropY: Int

The y coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropWidth: Int

The width of the crop region of the sensor.

sensorCropHeight: Int

The height of the crop region of the sensor.

minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS

The minimum allowed width and height for the output rectangle in sensor pixels. If the calculated rectangle is smaller than this value in either dimension, it will be expanded symmetrically from its center to reach the minimum. Defaults to DEFAULT_MIN_SENSOR_PIXELS. Set to 0 or less to disable this behavior.

coerceToCropRegion: Boolean = true

Whether to coerce the output rectangle into the crop region.

crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T

A callback to construct the final return object from the computed sensor coordinates.

mapStreamRectToUiRect

inline fun <T : Any?> mapStreamRectToUiRect(
    streamLeft: Float,
    streamTop: Float,
    streamRight: Float,
    streamBottom: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toUiRect: (uiLeft: Float, uiTop: Float, uiRight: Float, uiBottom: Float) -> T
): T

Converts a rectangle relative to a specific camera stream to an equivalent rectangle relative to a UI element.

Parameters
streamLeft: Float

The left coordinate of the rectangle in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamTop: Float

The top coordinate of the rectangle in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamRight: Float

The right coordinate of the rectangle in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamBottom: Float

The bottom coordinate of the rectangle in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream.

streamHeight: Int

The height of the camera stream.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

crossinline toUiRect: (uiLeft: Float, uiTop: Float, uiRight: Float, uiBottom: Float) -> T

A callback to construct the final return object from the computed UI coordinates.

mapStreamRectToUiRectF

Added in 1.7.0-alpha02
fun mapStreamRectToUiRectF(
    streamRect: RectF,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int
): RectF

Converts a rectangle relative to a specific camera stream to an equivalent rectangle relative to a UI element.

Parameters
streamRect: RectF

The rectangle in the camera stream. Stream coordinates are relative to the streamWidth/Height.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

mapStreamSizeToSensorSize

Added in 1.7.0-alpha02
fun mapStreamSizeToSensorSize(
    size: Size,
    streamSize: Size,
    sensorCropWidth: Int,
    sensorCropHeight: Int
): Size

Converts a size relative to a specific camera stream to an equivalent size relative to the camera sensor.

Parameters
size: Size

The size in the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamSize: Size

The size of the camera stream.

sensorCropWidth: Int

The width of the sensor crop region.

sensorCropHeight: Int

The height of the sensor crop region.

mapStreamSizeToSensorSize

Added in 1.7.0-alpha02
inline fun <T : Any?> mapStreamSizeToSensorSize(
    streamSizeWidth: Float,
    streamSizeHeight: Float,
    streamWidth: Int,
    streamHeight: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toSensorSize: (sensorWidth: Int, sensorHeight: Int) -> T
): T

Converts a size relative to a specific camera stream to an equivalent size relative to the camera sensor.

Parameters
streamSizeWidth: Float

The width of the size in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamSizeHeight: Float

The height of the size in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamWidth: Int

The width of the camera stream.

streamHeight: Int

The height of the camera stream.

sensorCropWidth: Int

The width of the sensor crop region.

sensorCropHeight: Int

The height of the sensor crop region.

crossinline toSensorSize: (sensorWidth: Int, sensorHeight: Int) -> T

A callback to construct the final return object from the computed sensor coordinates.

mapStreamSizeToUiSize

inline fun <T : Any?> mapStreamSizeToUiSize(
    streamSizeWidth: Float,
    streamSizeHeight: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toUiSize: (width: Float, height: Float) -> T
): T

Converts a size relative to a specific camera stream to an equivalent size relative to a UI element.

Parameters
streamSizeWidth: Float

The width of the size in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamSizeHeight: Float

The height of the size in the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream.

streamHeight: Int

The height of the camera stream.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

crossinline toUiSize: (width: Float, height: Float) -> T

A callback to construct the final return object from the computed UI coordinates.

mapStreamSizeToUiSizeF

Added in 1.7.0-alpha02
fun mapStreamSizeToUiSizeF(
    size: Size,
    uiSize: Size,
    streamSize: Size,
    sensorRotationToDisplayOrientation: Int
): SizeF

Converts a size relative to a specific camera stream to an equivalent size relative to a UI element.

Parameters
size: Size

The size in the camera stream. Stream coordinates are relative to the streamWidth/Height.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

mapUiPointToSensorPoint

Added in 1.7.0-alpha02
fun mapUiPointToSensorPoint(
    uiPoint: Point,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    sensorCrop: Rect,
    coerceToCropRegion: Boolean = true
): Point

Converts a point relative to a UI element to an equivalent point relative to the camera sensor.

Parameters
uiPoint: Point

The point in the UI. UI coordinates are relative to the uiSize, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

sensorCrop: Rect

The crop region of the sensor (typically CameraMetadata.SCALER_CROP_REGION, or CameraMetadata.SENSOR_INFO_ACTIVE_ARRAY_SIZE if no crop is applied). Sensor coordinates are relative to the sensor 0,0.

coerceToCropRegion: Boolean = true

Whether to coerce the output point into the crop region.

mapUiPointToSensorPoint

inline fun <T : Any?> mapUiPointToSensorPoint(
    uiX: Float,
    uiY: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    coerceToCropRegion: Boolean = true,
    crossinline toSensorPoint: (sensorX: Int, sensorY: Int) -> T
): T

Converts a point relative to a UI element to an equivalent point relative to the camera sensor.

Parameters
uiX: Float

The x coordinate in the UI. UI coordinates are relative to the uiWidth, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiY: Float

The y coordinate in the UI. UI coordinates are relative to the uiHeight, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

sensorCropX: Int

The x coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropY: Int

The y coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropWidth: Int

The width of the crop region of the sensor.

sensorCropHeight: Int

The height of the crop region of the sensor.

coerceToCropRegion: Boolean = true

Whether to coerce the output point into the crop region.

crossinline toSensorPoint: (sensorX: Int, sensorY: Int) -> T

A callback to construct the final return object from the computed sensor coordinates.

mapUiPointToSensorRect

Added in 1.7.0-alpha02
fun mapUiPointToSensorRect(
    uiPoint: Point,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    sensorCrop: Rect,
    minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS,
    coerceToCropRegion: Boolean = true,
    touchToFocusRatio: Float = DEFAULT_POINT_TO_RECT_RATIO
): Rect

Converts a point relative to a UI element to an equivalent rectangle relative to the camera sensor.

The output rectangle will have a size determined by the touchToFocusRatio and will be centered on the mapped point. If the calculated rectangle is smaller than minimumSensorSize in either dimension, it will be expanded symmetrically from its center to reach the minimum.

Parameters
uiPoint: Point

The point in the UI. UI coordinates are relative to the uiSize, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

sensorCrop: Rect

The crop region of the sensor (typically CameraMetadata.SCALER_CROP_REGION, or CameraMetadata.SENSOR_INFO_ACTIVE_ARRAY_SIZE if no crop is applied). Sensor coordinates are relative to the sensor 0,0.

minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS

The minimum allowed width and height for the output rectangle in sensor pixels. If the calculated rectangle is smaller than this value in either dimension, it will be expanded symmetrically from its center to reach the minimum. Defaults to DEFAULT_MIN_SENSOR_PIXELS. Set to 0 or less to disable this behavior.

coerceToCropRegion: Boolean = true

Whether to coerce the output rectangle into the crop region.

touchToFocusRatio: Float = DEFAULT_POINT_TO_RECT_RATIO

The ratio to use when computing a rectangle based on the short dimension of the stream.

mapUiPointToSensorRect

inline fun <T : Any?> mapUiPointToSensorRect(
    uiX: Float,
    uiY: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS,
    coerceToCropRegion: Boolean = true,
    ratio: Float = DEFAULT_POINT_TO_RECT_RATIO,
    crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T
): T

Converts a point relative to a UI element to an equivalent rectangle relative to the camera sensor.

Parameters
uiX: Float

The x coordinate in the UI. UI coordinates are relative to the uiWidth, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiY: Float

The y coordinate in the UI. UI coordinates are relative to the uiHeight, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

sensorCropX: Int

The x coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropY: Int

The y coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropWidth: Int

The width of the crop region of the sensor.

sensorCropHeight: Int

The height of the crop region of the sensor.

minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS

The minimum allowed width and height for the output rectangle in sensor pixels. If the calculated rectangle is smaller than this value in either dimension, it will be expanded symmetrically from its center to reach the minimum. Defaults to DEFAULT_MIN_SENSOR_PIXELS. Set to 0 or less to disable this behavior.

coerceToCropRegion: Boolean = true

Whether to coerce the output rectangle into the crop region.

ratio: Float = DEFAULT_POINT_TO_RECT_RATIO

The ratio to use when computing a rectangle based on the short dimension of the stream.

crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T

A callback to construct the final return object from the computed sensor coordinates.

mapUiPointToStreamPoint

inline fun <T : Any?> mapUiPointToStreamPoint(
    uiX: Float,
    uiY: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toStreamPoint: (streamX: Float, streamY: Float) -> T
): T

Converts a point relative to a UI element to an equivalent point relative to a specific camera stream.

Parameters
uiX: Float

The x coordinate in the UI. UI coordinates are relative to the uiWidth, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiY: Float

The y coordinate in the UI. UI coordinates are relative to the uiHeight, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

crossinline toStreamPoint: (streamX: Float, streamY: Float) -> T

A callback to construct the final return object from the computed stream coordinates.

mapUiPointToStreamPointF

Added in 1.7.0-alpha02
fun mapUiPointToStreamPointF(
    uiPoint: Point,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int
): PointF

Converts a point relative to a UI element to an equivalent point relative to a specific camera stream.

Parameters
uiPoint: Point

The point in the UI. UI coordinates are relative to the uiSize, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

mapUiPointToStreamRect

inline fun <T : Any?> mapUiPointToStreamRect(
    uiX: Float,
    uiY: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    ratio: Float = DEFAULT_POINT_TO_RECT_RATIO,
    crossinline toStreamRect: (streamLeft: Float, streamTop: Float, streamRight: Float, streamBottom: Float) -> T
): T

Converts a point relative to a UI element to an equivalent rectangle relative to a specific camera stream.

Parameters
uiX: Float

The x coordinate in the UI. UI coordinates are relative to the uiWidth, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiY: Float

The y coordinate in the UI. UI coordinates are relative to the uiHeight, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

ratio: Float = DEFAULT_POINT_TO_RECT_RATIO

The ratio to use when computing a rectangle based on the short dimension of the stream.

crossinline toStreamRect: (streamLeft: Float, streamTop: Float, streamRight: Float, streamBottom: Float) -> T

A callback to construct the final return object from the computed stream coordinates.

mapUiPointToStreamRectF

Added in 1.7.0-alpha02
fun mapUiPointToStreamRectF(
    uiPoint: Point,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    touchToFocusRatio: Float = DEFAULT_POINT_TO_RECT_RATIO
): RectF

Converts a point relative to a UI element to an equivalent rectangle relative to a specific camera stream.

Parameters
uiPoint: Point

The point in the UI. UI coordinates are relative to the uiSize, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

touchToFocusRatio: Float = DEFAULT_POINT_TO_RECT_RATIO

The ratio to use when computing a rectangle based on the short dimension of the stream.

mapUiRectToSensorRect

Added in 1.7.0-alpha02
fun mapUiRectToSensorRect(
    uiRect: RectF,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int,
    sensorCrop: Rect,
    minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS,
    coerceToCropRegion: Boolean = true
): Rect

Converts a rectangle relative to a UI element to an equivalent rectangle relative to the camera sensor.

Parameters
uiRect: RectF

The rectangle in the UI. UI coordinates are relative to the uiSize, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

sensorCrop: Rect

The crop region of the sensor (typically CameraMetadata.SCALER_CROP_REGION, or CameraMetadata.SENSOR_INFO_ACTIVE_ARRAY_SIZE if no crop is applied). Sensor coordinates are relative to the sensor 0,0.

minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS

The minimum allowed width and height for the output rectangle in sensor pixels. If the calculated rectangle is smaller than this value in either dimension, it will be expanded symmetrically from its center to reach the minimum. Defaults to DEFAULT_MIN_SENSOR_PIXELS. Set to 0 or less to disable this behavior.

coerceToCropRegion: Boolean = true

Whether to coerce the output rectangle into the crop region.

mapUiRectToSensorRect

inline fun <T : Any?> mapUiRectToSensorRect(
    uiLeft: Float,
    uiTop: Float,
    uiRight: Float,
    uiBottom: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropX: Int,
    sensorCropY: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS,
    coerceToCropRegion: Boolean = true,
    crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T
): T

Converts a rectangle relative to a UI element to an equivalent rectangle relative to the camera sensor.

Parameters
uiLeft: Float

The left coordinate of the rectangle in the UI. UI coordinates are relative to the uiWidth, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiTop: Float

The top coordinate of the rectangle in the UI. UI coordinates are relative to the uiHeight, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiRight: Float

The right coordinate of the rectangle in the UI. UI coordinates are relative to the uiWidth, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiBottom: Float

The bottom coordinate of the rectangle in the UI. UI coordinates are relative to the uiHeight, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

sensorCropX: Int

The x coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropY: Int

The y coordinate of the crop region of the sensor. Sensor coordinates are relative to the sensor 0,0.

sensorCropWidth: Int

The width of the crop region of the sensor.

sensorCropHeight: Int

The height of the crop region of the sensor.

minimumSensorSize: Int = DEFAULT_MIN_SENSOR_PIXELS

The minimum allowed width and height for the output rectangle in sensor pixels. If the calculated rectangle is smaller than this value in either dimension, it will be expanded symmetrically from its center to reach the minimum. Defaults to DEFAULT_MIN_SENSOR_PIXELS. Set to 0 or less to disable this behavior.

coerceToCropRegion: Boolean = true

Whether to coerce the output rectangle into the crop region.

crossinline toSensorRect: (sensorLeft: Int, sensorTop: Int, sensorRight: Int, sensorBottom: Int) -> T

A callback to construct the final return object from the computed sensor coordinates.

mapUiRectToStreamRect

inline fun <T : Any?> mapUiRectToStreamRect(
    uiLeft: Float,
    uiTop: Float,
    uiRight: Float,
    uiBottom: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toStreamRect: (streamLeft: Float, streamTop: Float, streamRight: Float, streamBottom: Float) -> T
): T

Converts a rectangle relative to a UI element to an equivalent rectangle relative to a specific camera stream.

Parameters
uiLeft: Float

The left coordinate of the rectangle in the UI. UI coordinates are relative to the uiWidth, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiTop: Float

The top coordinate of the rectangle in the UI. UI coordinates are relative to the uiHeight, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiRight: Float

The right coordinate of the rectangle in the UI. UI coordinates are relative to the uiWidth, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiBottom: Float

The bottom coordinate of the rectangle in the UI. UI coordinates are relative to the uiHeight, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

crossinline toStreamRect: (streamLeft: Float, streamTop: Float, streamRight: Float, streamBottom: Float) -> T

A callback to construct the final return object from the computed stream coordinates.

mapUiRectToStreamRectF

Added in 1.7.0-alpha02
fun mapUiRectToStreamRectF(
    uiRect: RectF,
    uiSize: Size,
    streamSize: Size,
    streamMirroring: Boolean,
    sensorRotationToDisplayOrientation: Int
): RectF

Converts a rectangle relative to a UI element to an equivalent rectangle relative to a specific camera stream.

Parameters
uiRect: RectF

The rectangle in the UI. UI coordinates are relative to the uiSize, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

streamMirroring: Boolean

Whether the camera stream is mirrored.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

mapUiSizeToSensorSize

Added in 1.7.0-alpha02
fun mapUiSizeToSensorSize(
    size: Size,
    uiSize: Size,
    streamSize: Size,
    sensorRotationToDisplayOrientation: Int,
    sensorCropWidth: Int,
    sensorCropHeight: Int
): Size

Converts a size relative to a UI element to an equivalent size relative to the camera sensor.

Parameters
size: Size

The size in the UI. UI coordinates are relative to the uiSize, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.

sensorCropWidth: Int

The width of the sensor crop region.

sensorCropHeight: Int

The height of the sensor crop region.

mapUiSizeToSensorSize

inline fun <T : Any?> mapUiSizeToSensorSize(
    uiSizeWidth: Float,
    uiSizeHeight: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    sensorCropWidth: Int,
    sensorCropHeight: Int,
    crossinline toSensorSize: (sensorWidth: Int, sensorHeight: Int) -> T
): T

Converts a size relative to a UI element to an equivalent size relative to the camera sensor.

Parameters
uiSizeWidth: Float

The width of the size in the UI. UI coordinates are relative to the uiWidth, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiSizeHeight: Float

The height of the size in the UI. UI coordinates are relative to the uiHeight, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Int

The width of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

streamHeight: Int

The height of the camera stream. Stream coordinates are relative to the streamWidth/streamHeight.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

sensorCropWidth: Int

The width of the sensor crop region.

sensorCropHeight: Int

The height of the sensor crop region.

crossinline toSensorSize: (sensorWidth: Int, sensorHeight: Int) -> T

A callback to construct the final return object from the computed sensor coordinates.

mapUiSizeToStreamSize

inline fun <T : Any?> mapUiSizeToStreamSize(
    uiSizeWidth: Float,
    uiSizeHeight: Float,
    uiWidth: Int,
    uiHeight: Int,
    streamWidth: Int,
    streamHeight: Int,
    sensorRotationToDisplayOrientation: DiscreteRotation,
    crossinline toStreamSize: (streamWidth: Float, streamHeight: Float) -> T
): T

Converts a size relative to a UI element to an equivalent size relative to a specific camera stream.

Parameters
uiSizeWidth: Float

The width of the size in the UI. UI coordinates are relative to the uiWidth, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiSizeHeight: Float

The height of the size in the UI. UI coordinates are relative to the uiHeight, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiWidth: Int

The width of the UI (specifically the UI-relative width of the viewfinder, without accounting for clipping or padding).

uiHeight: Int

The height of the UI (specifically the UI-relative height of the viewfinder, without accounting for clipping or padding).

streamWidth: Float

The width of the camera stream.

streamHeight: Float

The height of the camera stream.

sensorRotationToDisplayOrientation: DiscreteRotation

The orientation from sensor to display.

crossinline toStreamSize: (streamWidth: Float, streamHeight: Float) -> T

A callback to construct the final return object from the computed stream coordinates.

mapUiSizeToStreamSizeF

Added in 1.7.0-alpha02
fun mapUiSizeToStreamSizeF(
    size: Size,
    uiSize: Size,
    streamSize: Size,
    sensorRotationToDisplayOrientation: Int
): SizeF

Converts a size relative to a UI element to an equivalent size relative to a specific camera stream.

Parameters
size: Size

The size in the UI. UI coordinates are relative to the uiSize, and does not account for the positioning of the UI. Callers must normalize coordinates to account for clipping or padding before calling this function.

uiSize: Size

The size of the UI (specifically the UI-relative size of the viewfinder, without accounting for clipping or padding).

streamSize: Size

The size of the camera stream. Stream coordinates are relative to the streamWidth/Height.

sensorRotationToDisplayOrientation: Int

The orientation from sensor to display.