Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 41670721 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

Camera2: Add distortion correction support

This allows camera devices to correct geometric distortion in their
optics, when requested by the application.

The correction only applies to processed (YUV, JPEG, etc) outputs,
not RAW buffers, or the result metadata.

Test: New CTS test passes
Bug: 74434422
Change-Id: I4566713874a152eaed237e823b8d65de4bcab539
parent 915f5041
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -15787,6 +15787,7 @@ package android.hardware.camera2 {
    field public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Integer> CONTROL_MAX_REGIONS_AWB;
    field public static final android.hardware.camera2.CameraCharacteristics.Key<android.util.Range<java.lang.Integer>> CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE;
    field public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Boolean> DEPTH_DEPTH_IS_EXCLUSIVE;
    field public static final android.hardware.camera2.CameraCharacteristics.Key<int[]> DISTORTION_CORRECTION_AVAILABLE_MODES;
    field public static final android.hardware.camera2.CameraCharacteristics.Key<int[]> EDGE_AVAILABLE_EDGE_MODES;
    field public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Boolean> FLASH_INFO_AVAILABLE;
    field public static final android.hardware.camera2.CameraCharacteristics.Key<int[]> HOT_PIXEL_AVAILABLE_HOT_PIXEL_MODES;
@@ -16020,6 +16021,9 @@ package android.hardware.camera2 {
    field public static final int CONTROL_SCENE_MODE_THEATRE = 7; // 0x7
    field public static final int CONTROL_VIDEO_STABILIZATION_MODE_OFF = 0; // 0x0
    field public static final int CONTROL_VIDEO_STABILIZATION_MODE_ON = 1; // 0x1
    field public static final int DISTORTION_CORRECTION_MODE_FAST = 1; // 0x1
    field public static final int DISTORTION_CORRECTION_MODE_HIGH_QUALITY = 2; // 0x2
    field public static final int DISTORTION_CORRECTION_MODE_OFF = 0; // 0x0
    field public static final int EDGE_MODE_FAST = 1; // 0x1
    field public static final int EDGE_MODE_HIGH_QUALITY = 2; // 0x2
    field public static final int EDGE_MODE_OFF = 0; // 0x0
@@ -16172,6 +16176,7 @@ package android.hardware.camera2 {
    field public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> CONTROL_SCENE_MODE;
    field public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> CONTROL_VIDEO_STABILIZATION_MODE;
    field public static final android.os.Parcelable.Creator<android.hardware.camera2.CaptureRequest> CREATOR;
    field public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> DISTORTION_CORRECTION_MODE;
    field public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> EDGE_MODE;
    field public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> FLASH_MODE;
    field public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> HOT_PIXEL_MODE;
@@ -16254,6 +16259,7 @@ package android.hardware.camera2 {
    field public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> CONTROL_POST_RAW_SENSITIVITY_BOOST;
    field public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> CONTROL_SCENE_MODE;
    field public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> CONTROL_VIDEO_STABILIZATION_MODE;
    field public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> DISTORTION_CORRECTION_MODE;
    field public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> EDGE_MODE;
    field public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> FLASH_MODE;
    field public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> FLASH_STATE;
+15 −0
Original line number Diff line number Diff line
@@ -3393,6 +3393,21 @@ public final class CameraCharacteristics extends CameraMetadata<CameraCharacteri
    public static final Key<Integer> LOGICAL_MULTI_CAMERA_SENSOR_SYNC_TYPE =
            new Key<Integer>("android.logicalMultiCamera.sensorSyncType", int.class);

    /**
     * <p>List of distortion correction modes for {@link CaptureRequest#DISTORTION_CORRECTION_MODE android.distortionCorrection.mode} that are
     * supported by this camera device.</p>
     * <p>No device is required to support this API; such devices will always list only 'OFF'.
     * All devices that support this API will list both FAST and HIGH_QUALITY.</p>
     * <p><b>Range of valid values:</b><br>
     * Any value listed in {@link CaptureRequest#DISTORTION_CORRECTION_MODE android.distortionCorrection.mode}</p>
     * <p><b>Optional</b> - This value may be {@code null} on some devices.</p>
     *
     * @see CaptureRequest#DISTORTION_CORRECTION_MODE
     */
    @PublicKey
    public static final Key<int[]> DISTORTION_CORRECTION_AVAILABLE_MODES =
            new Key<int[]>("android.distortionCorrection.availableModes", int[].class);

    /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
     * End generated code
     *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/
+25 −0
Original line number Diff line number Diff line
@@ -2727,6 +2727,31 @@ public abstract class CameraMetadata<TKey> {
     */
    public static final int TONEMAP_PRESET_CURVE_REC709 = 1;

    //
    // Enumeration values for CaptureRequest#DISTORTION_CORRECTION_MODE
    //

    /**
     * <p>No distortion correction is applied.</p>
     * @see CaptureRequest#DISTORTION_CORRECTION_MODE
     */
    public static final int DISTORTION_CORRECTION_MODE_OFF = 0;

    /**
     * <p>Lens distortion correction is applied without reducing frame rate
     * relative to sensor output. It may be the same as OFF if distortion correction would
     * reduce frame rate relative to sensor.</p>
     * @see CaptureRequest#DISTORTION_CORRECTION_MODE
     */
    public static final int DISTORTION_CORRECTION_MODE_FAST = 1;

    /**
     * <p>High-quality distortion correction is applied, at the cost of
     * possibly reduced frame rate relative to sensor output.</p>
     * @see CaptureRequest#DISTORTION_CORRECTION_MODE
     */
    public static final int DISTORTION_CORRECTION_MODE_HIGH_QUALITY = 2;

    //
    // Enumeration values for CaptureResult#CONTROL_AE_STATE
    //
+43 −0
Original line number Diff line number Diff line
@@ -3167,6 +3167,49 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>>
    public static final Key<Float> REPROCESS_EFFECTIVE_EXPOSURE_FACTOR =
            new Key<Float>("android.reprocess.effectiveExposureFactor", float.class);

    /**
     * <p>Mode of operation for the lens distortion correction block.</p>
     * <p>The lens distortion correction block attempts to improve image quality by fixing
     * radial, tangential, or other geometric aberrations in the camera device's optics.  If
     * available, the {@link CameraCharacteristics#LENS_DISTORTION android.lens.distortion} field documents the lens's distortion parameters.</p>
     * <p>OFF means no distortion correction is done.</p>
     * <p>FAST/HIGH_QUALITY both mean camera device determined distortion correction will be
     * applied. HIGH_QUALITY mode indicates that the camera device will use the highest-quality
     * correction algorithms, even if it slows down capture rate. FAST means the camera device
     * will not slow down capture rate when applying correction. FAST may be the same as OFF if
     * any correction at all would slow down capture rate.  Every output stream will have a
     * similar amount of enhancement applied.</p>
     * <p>The correction only applies to processed outputs such as YUV, JPEG, or DEPTH16; it is not
     * applied to any RAW output.  Metadata coordinates such as face rectangles or metering
     * regions are also not affected by correction.</p>
     * <p>Applications enabling distortion correction need to pay extra attention when converting
     * image coordinates between corrected output buffers and the sensor array. For example, if
     * the app supports tap-to-focus and enables correction, it then has to apply the distortion
     * model described in {@link CameraCharacteristics#LENS_DISTORTION android.lens.distortion} to the image buffer tap coordinates to properly
     * calculate the tap position on the sensor active array to be used with
     * {@link CaptureRequest#CONTROL_AF_REGIONS android.control.afRegions}. The same applies in reverse to detected face rectangles if
     * they need to be drawn on top of the corrected output buffers.</p>
     * <p><b>Possible values:</b>
     * <ul>
     *   <li>{@link #DISTORTION_CORRECTION_MODE_OFF OFF}</li>
     *   <li>{@link #DISTORTION_CORRECTION_MODE_FAST FAST}</li>
     *   <li>{@link #DISTORTION_CORRECTION_MODE_HIGH_QUALITY HIGH_QUALITY}</li>
     * </ul></p>
     * <p><b>Available values for this device:</b><br>
     * {@link CameraCharacteristics#DISTORTION_CORRECTION_AVAILABLE_MODES android.distortionCorrection.availableModes}</p>
     * <p><b>Optional</b> - This value may be {@code null} on some devices.</p>
     *
     * @see CaptureRequest#CONTROL_AF_REGIONS
     * @see CameraCharacteristics#DISTORTION_CORRECTION_AVAILABLE_MODES
     * @see CameraCharacteristics#LENS_DISTORTION
     * @see #DISTORTION_CORRECTION_MODE_OFF
     * @see #DISTORTION_CORRECTION_MODE_FAST
     * @see #DISTORTION_CORRECTION_MODE_HIGH_QUALITY
     */
    @PublicKey
    public static final Key<Integer> DISTORTION_CORRECTION_MODE =
            new Key<Integer>("android.distortionCorrection.mode", int.class);

    /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
     * End generated code
     *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/
+43 −0
Original line number Diff line number Diff line
@@ -4449,6 +4449,49 @@ public class CaptureResult extends CameraMetadata<CaptureResult.Key<?>> {
    public static final Key<Float> REPROCESS_EFFECTIVE_EXPOSURE_FACTOR =
            new Key<Float>("android.reprocess.effectiveExposureFactor", float.class);

    /**
     * <p>Mode of operation for the lens distortion correction block.</p>
     * <p>The lens distortion correction block attempts to improve image quality by fixing
     * radial, tangential, or other geometric aberrations in the camera device's optics.  If
     * available, the {@link CameraCharacteristics#LENS_DISTORTION android.lens.distortion} field documents the lens's distortion parameters.</p>
     * <p>OFF means no distortion correction is done.</p>
     * <p>FAST/HIGH_QUALITY both mean camera device determined distortion correction will be
     * applied. HIGH_QUALITY mode indicates that the camera device will use the highest-quality
     * correction algorithms, even if it slows down capture rate. FAST means the camera device
     * will not slow down capture rate when applying correction. FAST may be the same as OFF if
     * any correction at all would slow down capture rate.  Every output stream will have a
     * similar amount of enhancement applied.</p>
     * <p>The correction only applies to processed outputs such as YUV, JPEG, or DEPTH16; it is not
     * applied to any RAW output.  Metadata coordinates such as face rectangles or metering
     * regions are also not affected by correction.</p>
     * <p>Applications enabling distortion correction need to pay extra attention when converting
     * image coordinates between corrected output buffers and the sensor array. For example, if
     * the app supports tap-to-focus and enables correction, it then has to apply the distortion
     * model described in {@link CameraCharacteristics#LENS_DISTORTION android.lens.distortion} to the image buffer tap coordinates to properly
     * calculate the tap position on the sensor active array to be used with
     * {@link CaptureRequest#CONTROL_AF_REGIONS android.control.afRegions}. The same applies in reverse to detected face rectangles if
     * they need to be drawn on top of the corrected output buffers.</p>
     * <p><b>Possible values:</b>
     * <ul>
     *   <li>{@link #DISTORTION_CORRECTION_MODE_OFF OFF}</li>
     *   <li>{@link #DISTORTION_CORRECTION_MODE_FAST FAST}</li>
     *   <li>{@link #DISTORTION_CORRECTION_MODE_HIGH_QUALITY HIGH_QUALITY}</li>
     * </ul></p>
     * <p><b>Available values for this device:</b><br>
     * {@link CameraCharacteristics#DISTORTION_CORRECTION_AVAILABLE_MODES android.distortionCorrection.availableModes}</p>
     * <p><b>Optional</b> - This value may be {@code null} on some devices.</p>
     *
     * @see CaptureRequest#CONTROL_AF_REGIONS
     * @see CameraCharacteristics#DISTORTION_CORRECTION_AVAILABLE_MODES
     * @see CameraCharacteristics#LENS_DISTORTION
     * @see #DISTORTION_CORRECTION_MODE_OFF
     * @see #DISTORTION_CORRECTION_MODE_FAST
     * @see #DISTORTION_CORRECTION_MODE_HIGH_QUALITY
     */
    @PublicKey
    public static final Key<Integer> DISTORTION_CORRECTION_MODE =
            new Key<Integer>("android.distortionCorrection.mode", int.class);

    /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
     * End generated code
     *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/