/* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.hardware.camera2.params; import android.annotation.NonNull; import android.annotation.Nullable; import android.graphics.ImageFormat; import android.graphics.ImageFormat.Format; import android.graphics.PixelFormat; import android.hardware.camera2.params.MultiResolutionStreamInfo; import android.hardware.camera2.params.StreamConfigurationMap; import android.hardware.camera2.utils.HashCodeHelpers; import android.util.Size; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.List; import java.util.Set; import static com.android.internal.util.Preconditions.*; /** * Immutable class to store the information of the multi-resolution streams supported by * the camera device. * *
For a {@link * android.hardware.camera2.CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA * logical multi-camera} or an ultra high resolution sensor camera, the maximum resolution of images * produced by the camera device may be variable. For example, for a logical multi-camera, depending * on factors such as current zoom ratio, the camera device may be backed by different physical * cameras. If the physical cameras are of different resolutions, the application may intend to * consume the variable full resolution images from the physical cameras. For an ultra high * resolution sensor camera, the same use case exists where depending on lighting conditions, the * camera device may deem it better to run in default mode and maximum resolution mode. *
* *For the use cases described above, multi-resolution output streams can be used by * {@link android.hardware.camera2.MultiResolutionImageReader} to allow the * camera device to output variable size maximum-resolution images.
* *Similarly, multi-resolution input streams can be used for reprocessing of variable size * images. In order to reprocess input images of different sizes, the {@link InputConfiguration} * used for creating reprocessable session can be initialized using the group of input stream * configurations returned by {@link #getInputInfo}.
*/ public final class MultiResolutionStreamConfigurationMap { /** * Create a new {@link MultiResolutionStreamConfigurationMap}. * * @param configurations a non-{@code null} array of multi-resolution stream * configurations supported by this camera device * @hide */ public MultiResolutionStreamConfigurationMap( @NonNull MapIf two the areas of two sizes are same, compare the widths.
* * @hide */ public static class SizeComparator implements ComparatorA logical multi-camera or an ultra high resolution sensor camera may support * {@link android.hardware.camera2.MultiResolutionImageReader} to dynamically output maximum * resolutions of different sizes (when switching between physical cameras, or between different * modes of an ultra high resolution sensor camera). This function returns the formats * supported for such case.
* *All image formats returned by this function will be defined in either {@link ImageFormat} * or in {@link PixelFormat} (and there is no possibility of collision).
* * @return an array of integer format, or empty array if multi-resolution output is not * supported * * @see ImageFormat * @see PixelFormat * @see android.hardware.camera2.MultiResolutionImageReader */ public @NonNull @Format int[] getOutputFormats() { return getPublicImageFormats(/*output*/true); } /** * Get the input formats in this multi-resolution stream configuration. * *A logical multi-camera or ultra high resolution sensor camera may support reprocessing * images of different resolutions when switching between physical cameras, or between * different modes of the ultra high resolution sensor camera. This function returns the * formats supported for such case.
* *The supported output format for an input format can be queried by calling the camera * device's {@link StreamConfigurationMap#getValidOutputFormatsForInput}.
* *All image formats returned by this function will be defined in either {@link ImageFormat} * or in {@link PixelFormat} (and there is no possibility of collision).
* * @return an array of integer format, or empty array if no multi-resolution reprocessing is * supported * * @see ImageFormat * @see PixelFormat */ public @NonNull @Format int[] getInputFormats() { return getPublicImageFormats(/*output*/false); } // Get the list of publicly visible multi-resolution input/output stream formats private int[] getPublicImageFormats(boolean output) { MapThe {@code format} should be a supported format (one of the formats returned by * {@link #getOutputFormats}).
* * @param format an image format from {@link ImageFormat} or {@link PixelFormat} * @return * a group of supported {@link MultiResolutionStreamInfo}. If the {@code format} is not * a supported multi-resolution output, an empty group is returned. * * @see ImageFormat * @see PixelFormat * @see #getOutputFormats */ public @NonNull CollectionThe {@code format} should be a supported format (one of the formats returned by * {@link #getInputFormats}).
* * @param format an image format from {@link ImageFormat} or {@link PixelFormat} * @return * a group of supported {@link MultiResolutionStreamInfo}. If the {@code format} is not * a supported multi-resolution input, an empty group is returned. * * @see ImageFormat * @see PixelFormat * @see #getInputFormats */ public @NonNull Collection{@code "MultiResolutionStreamConfigurationMap(Outputs([format1: [w:%d, h:%d, id:%s], ... * ... [w:%d, h:%d, id:%s]), [format2: [w:%d, h:%d, id:%s], ... [w:%d, h:%d, id:%s]], ...), * Inputs([format1: [w:%d, h:%d, id:%s], ... [w:%d, h:%d, id:%s], ...).
* * @return string representation of {@link MultiResolutionStreamConfigurationMap} */ @Override public String toString() { StringBuilder sb = new StringBuilder("MultiResolutionStreamConfigurationMap("); appendConfigurationsString(sb, /*output*/ true); sb.append(","); appendConfigurationsString(sb, /*output*/ false); sb.append(")"); return sb.toString(); } private final Map