public static class 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

static final int

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

static final 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 fields

static @NonNull CameraMath

Public methods

static final @NonNull DiscreteRotation
computeSensorRotationToDisplayOrientation(
    int displayRotation,
    int sensorOrientation,
    boolean sensorIsFacingScreen
)

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

static final @NonNull DiscreteRotation
computeSensorRotationToJpegOrientation(
    int deviceOrientation,
    int sensorOrientation,
    boolean sensorIsFacingScreen
)

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

static final @NonNull PointF
mapSensorPointToStreamPointF(
    @NonNull Point sensorPoint,
    @NonNull Size streamSize,
    @NonNull Rect sensorCrop
)

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

static final @NonNull PointF
mapSensorPointToUiPointF(
    @NonNull Point sensorPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    @NonNull Rect sensorCrop
)

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

static final @NonNull RectF
mapSensorRectToStreamRectF(
    @NonNull Rect sensorRect,
    @NonNull Size streamSize,
    @NonNull Rect sensorCrop
)

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

static final @NonNull RectF
mapSensorRectToUiRectF(
    @NonNull Rect sensorRect,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    @NonNull Rect sensorCrop
)

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

static final @NonNull SizeF
mapSensorSizeToStreamSizeF(
    @NonNull Size size,
    @NonNull Size streamSize,
    int sensorCropWidth,
    int sensorCropHeight
)

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

static final @NonNull SizeF
mapSensorSizeToUiSizeF(
    @NonNull Size size,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    int sensorRotationToDisplayOrientation,
    int sensorCropWidth,
    int sensorCropHeight
)

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

static final @NonNull Point
mapStreamPointToSensorPoint(
    @NonNull PointF streamPoint,
    @NonNull Size streamSize,
    @NonNull Rect sensorCrop,
    boolean coerceToCropRegion
)

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

static final @NonNull Rect
mapStreamPointToSensorRect(
    @NonNull PointF streamPoint,
    @NonNull Size streamSize,
    @NonNull Rect sensorCrop,
    int minimumSensorSize,
    boolean coerceToCropRegion,
    float touchToFocusRatio
)

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

static final @NonNull PointF
mapStreamPointToUiPointF(
    @NonNull PointF streamPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation
)

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

static final @NonNull Rect
mapStreamRectToSensorRect(
    @NonNull RectF streamRect,
    @NonNull Size streamSize,
    @NonNull Rect sensorCrop,
    int minimumSensorSize,
    boolean coerceToCropRegion
)

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

static final @NonNull RectF
mapStreamRectToUiRectF(
    @NonNull RectF streamRect,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation
)

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

static final @NonNull Size
mapStreamSizeToSensorSize(
    @NonNull Size size,
    @NonNull Size streamSize,
    int sensorCropWidth,
    int sensorCropHeight
)

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

static final @NonNull SizeF
mapStreamSizeToUiSizeF(
    @NonNull Size size,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    int sensorRotationToDisplayOrientation
)

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

static final @NonNull Point
mapUiPointToSensorPoint(
    @NonNull Point uiPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    @NonNull Rect sensorCrop,
    boolean coerceToCropRegion
)

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

static final @NonNull Rect
mapUiPointToSensorRect(
    @NonNull Point uiPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    @NonNull Rect sensorCrop,
    int minimumSensorSize,
    boolean coerceToCropRegion,
    float touchToFocusRatio
)

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

static final @NonNull PointF
mapUiPointToStreamPointF(
    @NonNull Point uiPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation
)

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

static final @NonNull RectF
mapUiPointToStreamRectF(
    @NonNull Point uiPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    float touchToFocusRatio
)

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

static final @NonNull Rect
mapUiRectToSensorRect(
    @NonNull RectF uiRect,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    @NonNull Rect sensorCrop,
    int minimumSensorSize,
    boolean coerceToCropRegion
)

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

static final @NonNull RectF
mapUiRectToStreamRectF(
    @NonNull RectF uiRect,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation
)

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

static final @NonNull Size
mapUiSizeToSensorSize(
    @NonNull Size size,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    int sensorRotationToDisplayOrientation,
    int sensorCropWidth,
    int sensorCropHeight
)

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

static final @NonNull SizeF
mapUiSizeToStreamSizeF(
    @NonNull Size size,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    int sensorRotationToDisplayOrientation
)

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
public static final int DEFAULT_MIN_SENSOR_PIXELS = 32

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
public static final float DEFAULT_POINT_TO_RECT_RATIO = 0.18375f

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 fields

INSTANCE

Added in 1.7.0-alpha02
public static @NonNull CameraMath INSTANCE

Public methods

computeSensorRotationToDisplayOrientation

Added in 1.7.0-alpha02
public static final @NonNull DiscreteRotation computeSensorRotationToDisplayOrientation(
    int displayRotation,
    int sensorOrientation,
    boolean sensorIsFacingScreen
)

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

Parameters
int displayRotation

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).

int sensorOrientation

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

boolean sensorIsFacingScreen

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

computeSensorRotationToJpegOrientation

Added in 1.7.0-alpha02
public static final @NonNull DiscreteRotation computeSensorRotationToJpegOrientation(
    int deviceOrientation,
    int sensorOrientation,
    boolean sensorIsFacingScreen
)

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

Parameters
int deviceOrientation

The orientation of the device in degrees.

int sensorOrientation

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

boolean sensorIsFacingScreen

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

mapSensorPointToStreamPointF

Added in 1.7.0-alpha02
public static final @NonNull PointF mapSensorPointToStreamPointF(
    @NonNull Point sensorPoint,
    @NonNull Size streamSize,
    @NonNull Rect sensorCrop
)

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

Parameters
@NonNull Point sensorPoint

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

@NonNull Size streamSize

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

@NonNull Rect sensorCrop

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

mapSensorPointToUiPointF

Added in 1.7.0-alpha02
public static final @NonNull PointF mapSensorPointToUiPointF(
    @NonNull Point sensorPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    @NonNull Rect sensorCrop
)

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

Parameters
@NonNull Point sensorPoint

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

@NonNull Size uiSize

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

@NonNull Size streamSize

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

boolean streamMirroring

Whether the camera stream is mirrored.

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

@NonNull Rect sensorCrop

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

mapSensorRectToStreamRectF

Added in 1.7.0-alpha02
public static final @NonNull RectF mapSensorRectToStreamRectF(
    @NonNull Rect sensorRect,
    @NonNull Size streamSize,
    @NonNull Rect sensorCrop
)

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

Parameters
@NonNull Rect sensorRect

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

@NonNull Size streamSize

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

@NonNull Rect sensorCrop

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

mapSensorRectToUiRectF

Added in 1.7.0-alpha02
public static final @NonNull RectF mapSensorRectToUiRectF(
    @NonNull Rect sensorRect,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    @NonNull Rect sensorCrop
)

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

Parameters
@NonNull Rect sensorRect

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

@NonNull Size uiSize

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

@NonNull Size streamSize

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

boolean streamMirroring

Whether the camera stream is mirrored.

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

@NonNull Rect sensorCrop

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

mapSensorSizeToStreamSizeF

Added in 1.7.0-alpha02
public static final @NonNull SizeF mapSensorSizeToStreamSizeF(
    @NonNull Size size,
    @NonNull Size streamSize,
    int sensorCropWidth,
    int sensorCropHeight
)

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

Parameters
@NonNull Size size

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

@NonNull Size streamSize

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

int sensorCropWidth

The width of the sensor crop region.

int sensorCropHeight

The height of the sensor crop region.

mapSensorSizeToUiSizeF

Added in 1.7.0-alpha02
public static final @NonNull SizeF mapSensorSizeToUiSizeF(
    @NonNull Size size,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    int sensorRotationToDisplayOrientation,
    int sensorCropWidth,
    int sensorCropHeight
)

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

Parameters
@NonNull Size size

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

@NonNull Size uiSize

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

@NonNull Size streamSize

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

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

int sensorCropWidth

The width of the sensor crop region.

int sensorCropHeight

The height of the sensor crop region.

mapStreamPointToSensorPoint

Added in 1.7.0-alpha02
public static final @NonNull Point mapStreamPointToSensorPoint(
    @NonNull PointF streamPoint,
    @NonNull Size streamSize,
    @NonNull Rect sensorCrop,
    boolean coerceToCropRegion
)

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

Parameters
@NonNull PointF streamPoint

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

@NonNull Size streamSize

The size of the camera stream.

@NonNull Rect sensorCrop

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.

boolean coerceToCropRegion

Whether to coerce the output point into the crop region.

mapStreamPointToSensorRect

Added in 1.7.0-alpha02
public static final @NonNull Rect mapStreamPointToSensorRect(
    @NonNull PointF streamPoint,
    @NonNull Size streamSize,
    @NonNull Rect sensorCrop,
    int minimumSensorSize,
    boolean coerceToCropRegion,
    float touchToFocusRatio
)

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
@NonNull PointF streamPoint

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

@NonNull Size streamSize

The size of the camera stream.

@NonNull Rect sensorCrop

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

int minimumSensorSize

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.

boolean coerceToCropRegion

Whether to coerce the output rectangle into the crop region.

float touchToFocusRatio

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

mapStreamPointToUiPointF

Added in 1.7.0-alpha02
public static final @NonNull PointF mapStreamPointToUiPointF(
    @NonNull PointF streamPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation
)

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

Parameters
@NonNull PointF streamPoint

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

@NonNull Size uiSize

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

@NonNull Size streamSize

The size of the camera stream.

boolean streamMirroring

Whether the camera stream is mirrored.

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

mapStreamRectToSensorRect

Added in 1.7.0-alpha02
public static final @NonNull Rect mapStreamRectToSensorRect(
    @NonNull RectF streamRect,
    @NonNull Size streamSize,
    @NonNull Rect sensorCrop,
    int minimumSensorSize,
    boolean coerceToCropRegion
)

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

Parameters
@NonNull RectF streamRect

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

@NonNull Size streamSize

The size of the camera stream.

@NonNull Rect sensorCrop

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.

int minimumSensorSize

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.

boolean coerceToCropRegion

Whether to coerce the output rectangle into the crop region.

mapStreamRectToUiRectF

Added in 1.7.0-alpha02
public static final @NonNull RectF mapStreamRectToUiRectF(
    @NonNull RectF streamRect,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation
)

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

Parameters
@NonNull RectF streamRect

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

@NonNull Size uiSize

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

@NonNull Size streamSize

The size of the camera stream.

boolean streamMirroring

Whether the camera stream is mirrored.

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

mapStreamSizeToSensorSize

Added in 1.7.0-alpha02
public static final @NonNull Size mapStreamSizeToSensorSize(
    @NonNull Size size,
    @NonNull Size streamSize,
    int sensorCropWidth,
    int sensorCropHeight
)

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

Parameters
@NonNull Size size

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

@NonNull Size streamSize

The size of the camera stream.

int sensorCropWidth

The width of the sensor crop region.

int sensorCropHeight

The height of the sensor crop region.

mapStreamSizeToUiSizeF

Added in 1.7.0-alpha02
public static final @NonNull SizeF mapStreamSizeToUiSizeF(
    @NonNull Size size,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    int sensorRotationToDisplayOrientation
)

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

Parameters
@NonNull Size size

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

@NonNull Size uiSize

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

@NonNull Size streamSize

The size of the camera stream.

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

mapUiPointToSensorPoint

Added in 1.7.0-alpha02
public static final @NonNull Point mapUiPointToSensorPoint(
    @NonNull Point uiPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    @NonNull Rect sensorCrop,
    boolean coerceToCropRegion
)

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

Parameters
@NonNull Point uiPoint

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.

@NonNull Size uiSize

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

@NonNull Size streamSize

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

boolean streamMirroring

Whether the camera stream is mirrored.

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

@NonNull Rect sensorCrop

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.

boolean coerceToCropRegion

Whether to coerce the output point into the crop region.

mapUiPointToSensorRect

Added in 1.7.0-alpha02
public static final @NonNull Rect mapUiPointToSensorRect(
    @NonNull Point uiPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    @NonNull Rect sensorCrop,
    int minimumSensorSize,
    boolean coerceToCropRegion,
    float touchToFocusRatio
)

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
@NonNull Point uiPoint

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.

@NonNull Size uiSize

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

@NonNull Size streamSize

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

boolean streamMirroring

Whether the camera stream is mirrored.

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

@NonNull Rect sensorCrop

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.

int minimumSensorSize

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.

boolean coerceToCropRegion

Whether to coerce the output rectangle into the crop region.

float touchToFocusRatio

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

mapUiPointToStreamPointF

Added in 1.7.0-alpha02
public static final @NonNull PointF mapUiPointToStreamPointF(
    @NonNull Point uiPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation
)

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

Parameters
@NonNull Point uiPoint

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.

@NonNull Size uiSize

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

@NonNull Size streamSize

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

boolean streamMirroring

Whether the camera stream is mirrored.

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

mapUiPointToStreamRectF

Added in 1.7.0-alpha02
public static final @NonNull RectF mapUiPointToStreamRectF(
    @NonNull Point uiPoint,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    float touchToFocusRatio
)

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

Parameters
@NonNull Point uiPoint

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.

@NonNull Size uiSize

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

@NonNull Size streamSize

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

boolean streamMirroring

Whether the camera stream is mirrored.

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

float touchToFocusRatio

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

mapUiRectToSensorRect

Added in 1.7.0-alpha02
public static final @NonNull Rect mapUiRectToSensorRect(
    @NonNull RectF uiRect,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation,
    @NonNull Rect sensorCrop,
    int minimumSensorSize,
    boolean coerceToCropRegion
)

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

Parameters
@NonNull RectF uiRect

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.

@NonNull Size uiSize

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

@NonNull Size streamSize

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

boolean streamMirroring

Whether the camera stream is mirrored.

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

@NonNull Rect sensorCrop

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.

int minimumSensorSize

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.

boolean coerceToCropRegion

Whether to coerce the output rectangle into the crop region.

mapUiRectToStreamRectF

Added in 1.7.0-alpha02
public static final @NonNull RectF mapUiRectToStreamRectF(
    @NonNull RectF uiRect,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    boolean streamMirroring,
    int sensorRotationToDisplayOrientation
)

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

Parameters
@NonNull RectF uiRect

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.

@NonNull Size uiSize

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

@NonNull Size streamSize

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

boolean streamMirroring

Whether the camera stream is mirrored.

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

mapUiSizeToSensorSize

Added in 1.7.0-alpha02
public static final @NonNull Size mapUiSizeToSensorSize(
    @NonNull Size size,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    int sensorRotationToDisplayOrientation,
    int sensorCropWidth,
    int sensorCropHeight
)

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

Parameters
@NonNull 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.

@NonNull Size uiSize

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

@NonNull Size streamSize

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

int sensorRotationToDisplayOrientation

The orientation from sensor to display.

int sensorCropWidth

The width of the sensor crop region.

int sensorCropHeight

The height of the sensor crop region.

mapUiSizeToStreamSizeF

Added in 1.7.0-alpha02
public static final @NonNull SizeF mapUiSizeToStreamSizeF(
    @NonNull Size size,
    @NonNull Size uiSize,
    @NonNull Size streamSize,
    int sensorRotationToDisplayOrientation
)

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

Parameters
@NonNull 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.

@NonNull Size uiSize

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

@NonNull Size streamSize

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

int sensorRotationToDisplayOrientation

The orientation from sensor to display.