Camera: Add android.scaler.rotateAndCrop control

Intended for backward compatibility support for camera apps that do
not handle multi-window scenarios like inset portrait or foldables
with dynamic screen changes.

Test: New CTS tests pass
Bug: 134631897
Change-Id: I1cc85d4413e6af2b490b86916933a5cd7ce84a6a
This commit is contained in:
Eino-Ville Talvala
2020-01-06 13:10:22 -08:00
parent f2de0a0e1f
commit a9b1d60f9e
6 changed files with 261 additions and 0 deletions

View File

@@ -17036,6 +17036,7 @@ package android.hardware.camera2 {
field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Integer> REQUEST_PARTIAL_RESULT_COUNT;
field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Byte> REQUEST_PIPELINE_MAX_DEPTH;
field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Float> SCALER_AVAILABLE_MAX_DIGITAL_ZOOM;
field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<int[]> SCALER_AVAILABLE_ROTATE_AND_CROP_MODES;
field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Integer> SCALER_CROPPING_TYPE;
field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<android.hardware.camera2.params.MandatoryStreamCombination[]> SCALER_MANDATORY_STREAM_COMBINATIONS;
field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<android.hardware.camera2.params.StreamConfigurationMap> SCALER_STREAM_CONFIGURATION_MAP;
@@ -17313,6 +17314,11 @@ package android.hardware.camera2 {
field public static final int REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING = 7; // 0x7
field public static final int SCALER_CROPPING_TYPE_CENTER_ONLY = 0; // 0x0
field public static final int SCALER_CROPPING_TYPE_FREEFORM = 1; // 0x1
field public static final int SCALER_ROTATE_AND_CROP_180 = 2; // 0x2
field public static final int SCALER_ROTATE_AND_CROP_270 = 3; // 0x3
field public static final int SCALER_ROTATE_AND_CROP_90 = 1; // 0x1
field public static final int SCALER_ROTATE_AND_CROP_AUTO = 4; // 0x4
field public static final int SCALER_ROTATE_AND_CROP_NONE = 0; // 0x0
field public static final int SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_BGGR = 3; // 0x3
field public static final int SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_GBRG = 2; // 0x2
field public static final int SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_GRBG = 1; // 0x1
@@ -17434,6 +17440,7 @@ package android.hardware.camera2 {
field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> NOISE_REDUCTION_MODE;
field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Float> REPROCESS_EFFECTIVE_EXPOSURE_FACTOR;
field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<android.graphics.Rect> SCALER_CROP_REGION;
field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> SCALER_ROTATE_AND_CROP;
field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Long> SENSOR_EXPOSURE_TIME;
field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Long> SENSOR_FRAME_DURATION;
field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> SENSOR_SENSITIVITY;
@@ -17530,6 +17537,7 @@ package android.hardware.camera2 {
field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Float> REPROCESS_EFFECTIVE_EXPOSURE_FACTOR;
field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Byte> REQUEST_PIPELINE_DEPTH;
field @NonNull public static final android.hardware.camera2.CaptureResult.Key<android.graphics.Rect> SCALER_CROP_REGION;
field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> SCALER_ROTATE_AND_CROP;
field @NonNull public static final android.hardware.camera2.CaptureResult.Key<float[]> SENSOR_DYNAMIC_BLACK_LEVEL;
field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> SENSOR_DYNAMIC_WHITE_LEVEL;
field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Long> SENSOR_EXPOSURE_TIME;

View File

@@ -2848,6 +2848,23 @@ public final class CameraCharacteristics extends CameraMetadata<CameraCharacteri
public static final Key<android.hardware.camera2.params.MandatoryStreamCombination[]> SCALER_MANDATORY_STREAM_COMBINATIONS =
new Key<android.hardware.camera2.params.MandatoryStreamCombination[]>("android.scaler.mandatoryStreamCombinations", android.hardware.camera2.params.MandatoryStreamCombination[].class);
/**
* <p>List of rotate-and-crop modes for {@link CaptureRequest#SCALER_ROTATE_AND_CROP android.scaler.rotateAndCrop} that are supported by this camera device.</p>
* <p>This entry lists the valid modes for {@link CaptureRequest#SCALER_ROTATE_AND_CROP android.scaler.rotateAndCrop} for this camera device.</p>
* <p>Starting with API level 30, all devices will list at least <code>ROTATE_AND_CROP_NONE</code>.
* Devices with support for rotate-and-crop will additionally list at least
* <code>ROTATE_AND_CROP_AUTO</code> and <code>ROTATE_AND_CROP_90</code>.</p>
* <p><b>Range of valid values:</b><br>
* Any value listed in {@link CaptureRequest#SCALER_ROTATE_AND_CROP android.scaler.rotateAndCrop}</p>
* <p><b>Optional</b> - The value for this key may be {@code null} on some devices.</p>
*
* @see CaptureRequest#SCALER_ROTATE_AND_CROP
*/
@PublicKey
@NonNull
public static final Key<int[]> SCALER_AVAILABLE_ROTATE_AND_CROP_MODES =
new Key<int[]>("android.scaler.availableRotateAndCropModes", int[].class);
/**
* <p>The area of the image sensor which corresponds to active pixels after any geometric
* distortion correction has been applied.</p>

View File

@@ -2714,6 +2714,56 @@ public abstract class CameraMetadata<TKey> {
*/
public static final int NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG = 4;
//
// Enumeration values for CaptureRequest#SCALER_ROTATE_AND_CROP
//
/**
* <p>No rotate and crop is applied. Processed outputs are in the sensor orientation.</p>
* @see CaptureRequest#SCALER_ROTATE_AND_CROP
*/
public static final int SCALER_ROTATE_AND_CROP_NONE = 0;
/**
* <p>Processed images are rotated by 90 degrees clockwise, and then cropped
* to the original aspect ratio.</p>
* @see CaptureRequest#SCALER_ROTATE_AND_CROP
*/
public static final int SCALER_ROTATE_AND_CROP_90 = 1;
/**
* <p>Processed images are rotated by 180 degrees. Since the aspect ratio does not
* change, no cropping is performed.</p>
* @see CaptureRequest#SCALER_ROTATE_AND_CROP
*/
public static final int SCALER_ROTATE_AND_CROP_180 = 2;
/**
* <p>Processed images are rotated by 270 degrees clockwise, and then cropped
* to the original aspect ratio.</p>
* @see CaptureRequest#SCALER_ROTATE_AND_CROP
*/
public static final int SCALER_ROTATE_AND_CROP_270 = 3;
/**
* <p>The camera API automatically selects the best concrete value for
* rotate-and-crop based on the application's support for resizability and the current
* multi-window mode.</p>
* <p>If the application does not support resizing but the display mode for its main
* Activity is not in a typical orientation, the camera API will set <code>ROTATE_AND_CROP_90</code>
* or some other supported rotation value, depending on device configuration,
* to ensure preview and captured images are correctly shown to the user. Otherwise,
* <code>ROTATE_AND_CROP_NONE</code> will be selected.</p>
* <p>When a value other than NONE is selected, several metadata fields will also be parsed
* differently to ensure that coordinates are correctly handled for features like drawing
* face detection boxes or passing in tap-to-focus coordinates. The camera API will
* convert positions in the active array coordinate system to/from the cropped-and-rotated
* coordinate system to make the operation transparent for applications.</p>
* <p>No coordinate mapping will be done when the application selects a non-AUTO mode.</p>
* @see CaptureRequest#SCALER_ROTATE_AND_CROP
*/
public static final int SCALER_ROTATE_AND_CROP_AUTO = 4;
//
// Enumeration values for CaptureRequest#SENSOR_TEST_PATTERN_MODE
//

View File

@@ -2844,6 +2844,99 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>>
public static final Key<android.graphics.Rect> SCALER_CROP_REGION =
new Key<android.graphics.Rect>("android.scaler.cropRegion", android.graphics.Rect.class);
/**
* <p>Whether a rotation-and-crop operation is applied to processed
* outputs from the camera.</p>
* <p>This control is primarily intended to help camera applications with no support for
* multi-window modes to work correctly on devices where multi-window scenarios are
* unavoidable, such as foldables or other devices with variable display geometry or more
* free-form window placement (such as laptops, which often place portrait-orientation apps
* in landscape with pillarboxing).</p>
* <p>If supported, the default value is <code>ROTATE_AND_CROP_AUTO</code>, which allows the camera API
* to enable backwards-compatibility support for applications that do not support resizing
* / multi-window modes, when the device is in fact in a multi-window mode (such as inset
* portrait on laptops, or on a foldable device in some fold states). In addition,
* <code>ROTATE_AND_CROP_NONE</code> and <code>ROTATE_AND_CROP_90</code> will always be available if this control
* is supported by the device. If not supported, devices API level 30 or higher will always
* list only <code>ROTATE_AND_CROP_NONE</code>.</p>
* <p>When <code>CROP_AUTO</code> is in use, and the camera API activates backward-compatibility mode,
* several metadata fields will also be parsed differently to ensure that coordinates are
* correctly handled for features like drawing face detection boxes or passing in
* tap-to-focus coordinates. The camera API will convert positions in the active array
* coordinate system to/from the cropped-and-rotated coordinate system to make the
* operation transparent for applications. The following controls are affected:</p>
* <ul>
* <li>{@link CaptureRequest#CONTROL_AE_REGIONS android.control.aeRegions}</li>
* <li>{@link CaptureRequest#CONTROL_AF_REGIONS android.control.afRegions}</li>
* <li>{@link CaptureRequest#CONTROL_AWB_REGIONS android.control.awbRegions}</li>
* <li>{@link CaptureResult#STATISTICS_FACES android.statistics.faces}</li>
* </ul>
* <p>Capture results will contain the actual value selected by the API;
* <code>ROTATE_AND_CROP_AUTO</code> will never be seen in a capture result.</p>
* <p>Applications can also select their preferred cropping mode, either to opt out of the
* backwards-compatibility treatment, or to use the cropping feature themselves as needed.
* In this case, no coordinate translation will be done automatically, and all controls
* will continue to use the normal active array coordinates.</p>
* <p>Cropping and rotating is done after the application of digital zoom (via either
* {@link CaptureRequest#SCALER_CROP_REGION android.scaler.cropRegion} or {@link CaptureRequest#CONTROL_ZOOM_RATIO android.control.zoomRatio}), but before each individual
* output is further cropped and scaled. It only affects processed outputs such as
* YUV, PRIVATE, and JPEG. It has no effect on RAW outputs.</p>
* <p>When <code>CROP_90</code> or <code>CROP_270</code> are selected, there is a significant loss to the field of
* view. For example, with a 4:3 aspect ratio output of 1600x1200, <code>CROP_90</code> will still
* produce 1600x1200 output, but these buffers are cropped from a vertical 3:4 slice at the
* center of the 4:3 area, then rotated to be 4:3, and then upscaled to 1600x1200. Only
* 56.25% of the original FOV is still visible. In general, for an aspect ratio of <code>w:h</code>,
* the crop and rotate operation leaves <code>(h/w)^2</code> of the field of view visible. For 16:9,
* this is ~31.6%.</p>
* <p>As a visual example, the figure below shows the effect of <code>ROTATE_AND_CROP_90</code> on the
* outputs for the following parameters:</p>
* <ul>
* <li>Sensor active array: <code>2000x1500</code></li>
* <li>Crop region: top-left: <code>(500, 375)</code>, size: <code>(1000, 750)</code> (4:3 aspect ratio)</li>
* <li>Output streams: YUV <code>640x480</code> and YUV <code>1280x720</code></li>
* <li><code>ROTATE_AND_CROP_90</code></li>
* </ul>
* <p><img alt="Effect of ROTATE_AND_CROP_90" src="/reference/images/camera2/metadata/android.scaler.rotateAndCrop/crop-region-rotate-90-43-ratio.png" /></p>
* <p>With these settings, the regions of the active array covered by the output streams are:</p>
* <ul>
* <li>640x480 stream crop: top-left: <code>(219, 375)</code>, size: <code>(562, 750)</code></li>
* <li>1280x720 stream crop: top-left: <code>(289, 375)</code>, size: <code>(422, 750)</code></li>
* </ul>
* <p>Since the buffers are rotated, the buffers as seen by the application are:</p>
* <ul>
* <li>640x480 stream: top-left: <code>(781, 375)</code> on active array, size: <code>(640, 480)</code>, downscaled 1.17x from sensor pixels</li>
* <li>1280x720 stream: top-left: <code>(711, 375)</code> on active array, size: <code>(1280, 720)</code>, upscaled 1.71x from sensor pixels</li>
* </ul>
* <p><b>Possible values:</b>
* <ul>
* <li>{@link #SCALER_ROTATE_AND_CROP_NONE NONE}</li>
* <li>{@link #SCALER_ROTATE_AND_CROP_90 90}</li>
* <li>{@link #SCALER_ROTATE_AND_CROP_180 180}</li>
* <li>{@link #SCALER_ROTATE_AND_CROP_270 270}</li>
* <li>{@link #SCALER_ROTATE_AND_CROP_AUTO AUTO}</li>
* </ul></p>
* <p><b>Available values for this device:</b><br>
* {@link CameraCharacteristics#SCALER_AVAILABLE_ROTATE_AND_CROP_MODES android.scaler.availableRotateAndCropModes}</p>
* <p><b>Optional</b> - The value for this key may be {@code null} on some devices.</p>
*
* @see CaptureRequest#CONTROL_AE_REGIONS
* @see CaptureRequest#CONTROL_AF_REGIONS
* @see CaptureRequest#CONTROL_AWB_REGIONS
* @see CaptureRequest#CONTROL_ZOOM_RATIO
* @see CameraCharacteristics#SCALER_AVAILABLE_ROTATE_AND_CROP_MODES
* @see CaptureRequest#SCALER_CROP_REGION
* @see CaptureResult#STATISTICS_FACES
* @see #SCALER_ROTATE_AND_CROP_NONE
* @see #SCALER_ROTATE_AND_CROP_90
* @see #SCALER_ROTATE_AND_CROP_180
* @see #SCALER_ROTATE_AND_CROP_270
* @see #SCALER_ROTATE_AND_CROP_AUTO
*/
@PublicKey
@NonNull
public static final Key<Integer> SCALER_ROTATE_AND_CROP =
new Key<Integer>("android.scaler.rotateAndCrop", int.class);
/**
* <p>Duration each pixel is exposed to
* light.</p>

View File

@@ -3483,6 +3483,99 @@ public class CaptureResult extends CameraMetadata<CaptureResult.Key<?>> {
public static final Key<android.graphics.Rect> SCALER_CROP_REGION =
new Key<android.graphics.Rect>("android.scaler.cropRegion", android.graphics.Rect.class);
/**
* <p>Whether a rotation-and-crop operation is applied to processed
* outputs from the camera.</p>
* <p>This control is primarily intended to help camera applications with no support for
* multi-window modes to work correctly on devices where multi-window scenarios are
* unavoidable, such as foldables or other devices with variable display geometry or more
* free-form window placement (such as laptops, which often place portrait-orientation apps
* in landscape with pillarboxing).</p>
* <p>If supported, the default value is <code>ROTATE_AND_CROP_AUTO</code>, which allows the camera API
* to enable backwards-compatibility support for applications that do not support resizing
* / multi-window modes, when the device is in fact in a multi-window mode (such as inset
* portrait on laptops, or on a foldable device in some fold states). In addition,
* <code>ROTATE_AND_CROP_NONE</code> and <code>ROTATE_AND_CROP_90</code> will always be available if this control
* is supported by the device. If not supported, devices API level 30 or higher will always
* list only <code>ROTATE_AND_CROP_NONE</code>.</p>
* <p>When <code>CROP_AUTO</code> is in use, and the camera API activates backward-compatibility mode,
* several metadata fields will also be parsed differently to ensure that coordinates are
* correctly handled for features like drawing face detection boxes or passing in
* tap-to-focus coordinates. The camera API will convert positions in the active array
* coordinate system to/from the cropped-and-rotated coordinate system to make the
* operation transparent for applications. The following controls are affected:</p>
* <ul>
* <li>{@link CaptureRequest#CONTROL_AE_REGIONS android.control.aeRegions}</li>
* <li>{@link CaptureRequest#CONTROL_AF_REGIONS android.control.afRegions}</li>
* <li>{@link CaptureRequest#CONTROL_AWB_REGIONS android.control.awbRegions}</li>
* <li>{@link CaptureResult#STATISTICS_FACES android.statistics.faces}</li>
* </ul>
* <p>Capture results will contain the actual value selected by the API;
* <code>ROTATE_AND_CROP_AUTO</code> will never be seen in a capture result.</p>
* <p>Applications can also select their preferred cropping mode, either to opt out of the
* backwards-compatibility treatment, or to use the cropping feature themselves as needed.
* In this case, no coordinate translation will be done automatically, and all controls
* will continue to use the normal active array coordinates.</p>
* <p>Cropping and rotating is done after the application of digital zoom (via either
* {@link CaptureRequest#SCALER_CROP_REGION android.scaler.cropRegion} or {@link CaptureRequest#CONTROL_ZOOM_RATIO android.control.zoomRatio}), but before each individual
* output is further cropped and scaled. It only affects processed outputs such as
* YUV, PRIVATE, and JPEG. It has no effect on RAW outputs.</p>
* <p>When <code>CROP_90</code> or <code>CROP_270</code> are selected, there is a significant loss to the field of
* view. For example, with a 4:3 aspect ratio output of 1600x1200, <code>CROP_90</code> will still
* produce 1600x1200 output, but these buffers are cropped from a vertical 3:4 slice at the
* center of the 4:3 area, then rotated to be 4:3, and then upscaled to 1600x1200. Only
* 56.25% of the original FOV is still visible. In general, for an aspect ratio of <code>w:h</code>,
* the crop and rotate operation leaves <code>(h/w)^2</code> of the field of view visible. For 16:9,
* this is ~31.6%.</p>
* <p>As a visual example, the figure below shows the effect of <code>ROTATE_AND_CROP_90</code> on the
* outputs for the following parameters:</p>
* <ul>
* <li>Sensor active array: <code>2000x1500</code></li>
* <li>Crop region: top-left: <code>(500, 375)</code>, size: <code>(1000, 750)</code> (4:3 aspect ratio)</li>
* <li>Output streams: YUV <code>640x480</code> and YUV <code>1280x720</code></li>
* <li><code>ROTATE_AND_CROP_90</code></li>
* </ul>
* <p><img alt="Effect of ROTATE_AND_CROP_90" src="/reference/images/camera2/metadata/android.scaler.rotateAndCrop/crop-region-rotate-90-43-ratio.png" /></p>
* <p>With these settings, the regions of the active array covered by the output streams are:</p>
* <ul>
* <li>640x480 stream crop: top-left: <code>(219, 375)</code>, size: <code>(562, 750)</code></li>
* <li>1280x720 stream crop: top-left: <code>(289, 375)</code>, size: <code>(422, 750)</code></li>
* </ul>
* <p>Since the buffers are rotated, the buffers as seen by the application are:</p>
* <ul>
* <li>640x480 stream: top-left: <code>(781, 375)</code> on active array, size: <code>(640, 480)</code>, downscaled 1.17x from sensor pixels</li>
* <li>1280x720 stream: top-left: <code>(711, 375)</code> on active array, size: <code>(1280, 720)</code>, upscaled 1.71x from sensor pixels</li>
* </ul>
* <p><b>Possible values:</b>
* <ul>
* <li>{@link #SCALER_ROTATE_AND_CROP_NONE NONE}</li>
* <li>{@link #SCALER_ROTATE_AND_CROP_90 90}</li>
* <li>{@link #SCALER_ROTATE_AND_CROP_180 180}</li>
* <li>{@link #SCALER_ROTATE_AND_CROP_270 270}</li>
* <li>{@link #SCALER_ROTATE_AND_CROP_AUTO AUTO}</li>
* </ul></p>
* <p><b>Available values for this device:</b><br>
* {@link CameraCharacteristics#SCALER_AVAILABLE_ROTATE_AND_CROP_MODES android.scaler.availableRotateAndCropModes}</p>
* <p><b>Optional</b> - The value for this key may be {@code null} on some devices.</p>
*
* @see CaptureRequest#CONTROL_AE_REGIONS
* @see CaptureRequest#CONTROL_AF_REGIONS
* @see CaptureRequest#CONTROL_AWB_REGIONS
* @see CaptureRequest#CONTROL_ZOOM_RATIO
* @see CameraCharacteristics#SCALER_AVAILABLE_ROTATE_AND_CROP_MODES
* @see CaptureRequest#SCALER_CROP_REGION
* @see CaptureResult#STATISTICS_FACES
* @see #SCALER_ROTATE_AND_CROP_NONE
* @see #SCALER_ROTATE_AND_CROP_90
* @see #SCALER_ROTATE_AND_CROP_180
* @see #SCALER_ROTATE_AND_CROP_270
* @see #SCALER_ROTATE_AND_CROP_AUTO
*/
@PublicKey
@NonNull
public static final Key<Integer> SCALER_ROTATE_AND_CROP =
new Key<Integer>("android.scaler.rotateAndCrop", int.class);
/**
* <p>Duration each pixel is exposed to
* light.</p>

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB