1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.hardware.camera2.params; 18 19 import static com.android.internal.util.Preconditions.checkArgumentNonnegative; 20 import static com.android.internal.util.Preconditions.checkArgumentPositive; 21 22 import android.annotation.NonNull; 23 import android.hardware.camera2.CameraCharacteristics; 24 import android.hardware.camera2.CameraMetadata; 25 import android.hardware.camera2.utils.HashCodeHelpers; 26 import android.util.Range; 27 import android.util.Size; 28 29 /** 30 * Immutable class to store the camera capability, its corresponding maximum 31 * streaming dimension and zoom range. 32 * 33 * @see CameraCharacteristics#CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_CAPABILITIES 34 */ 35 36 public final class Capability { 37 /** 38 * @hide 39 */ 40 public static final int COUNT = 3; 41 42 private final int mMode; 43 private final int mMaxStreamingWidth; 44 private final int mMaxStreamingHeight; 45 private final float mMinZoomRatio; 46 private final float mMaxZoomRatio; 47 48 /** 49 * Create a new Capability object. 50 * 51 * @param mode supported mode for a camera capability. 52 * @param maxStreamingWidth The width of the maximum streaming size for this mode 53 * @param maxStreamingHeight The height of the maximum streaming size for this mode 54 * @param minZoomRatio the minimum zoom ratio this mode supports 55 * @param maxZoomRatio the maximum zoom ratio this mode supports 56 * 57 * @throws IllegalArgumentException if any of the argument is not valid 58 * @hide 59 */ Capability(int mode, int maxStreamingWidth, int maxStreamingHeight, float minZoomRatio, float maxZoomRatio)60 public Capability(int mode, int maxStreamingWidth, int maxStreamingHeight, 61 float minZoomRatio, float maxZoomRatio) { 62 mMode = mode; 63 mMaxStreamingWidth = checkArgumentNonnegative(maxStreamingWidth, 64 "maxStreamingWidth must be nonnegative"); 65 mMaxStreamingHeight = checkArgumentNonnegative(maxStreamingHeight, 66 "maxStreamingHeight must be nonnegative"); 67 68 if (minZoomRatio > maxZoomRatio) { 69 throw new IllegalArgumentException("minZoomRatio " + minZoomRatio 70 + " is greater than maxZoomRatio " + maxZoomRatio); 71 } 72 mMinZoomRatio = checkArgumentPositive(minZoomRatio, 73 "minZoomRatio must be positive"); 74 mMaxZoomRatio = checkArgumentPositive(maxZoomRatio, 75 "maxZoomRatio must be positive"); 76 } 77 78 /** 79 * Return the supported mode for this capability. 80 * 81 * @return One of supported modes for the capability. For example, for available extended 82 * scene modes, this will be one of {@link CameraMetadata#CONTROL_EXTENDED_SCENE_MODE_DISABLED}, 83 * {@link CameraMetadata#CONTROL_EXTENDED_SCENE_MODE_BOKEH_STILL_CAPTURE}, and 84 * {@link CameraMetadata#CONTROL_EXTENDED_SCENE_MODE_BOKEH_CONTINUOUS}. 85 */ getMode()86 public int getMode() { 87 return mMode; 88 } 89 90 /** 91 * Return the maximum streaming dimension of this capability. 92 * 93 * @return a new {@link Size} with non-negative width and height 94 */ getMaxStreamingSize()95 public @NonNull Size getMaxStreamingSize() { 96 return new Size(mMaxStreamingWidth, mMaxStreamingHeight); 97 } 98 99 /** 100 * Return the zoom ratio range of this capability. 101 * 102 * @return The supported zoom ratio range supported by this capability 103 */ getZoomRatioRange()104 public @NonNull Range<Float> getZoomRatioRange() { 105 return new Range<Float>(mMinZoomRatio, mMaxZoomRatio); 106 } 107 108 109 /** 110 * Compare two Capability objects to see if they are equal. 111 * 112 * @param obj Another Capability object 113 * 114 * @return {@code true} if the mode, max size and zoom ratio range are equal, 115 * {@code false} otherwise 116 */ 117 @Override equals(final Object obj)118 public boolean equals(final Object obj) { 119 if (obj == null) { 120 return false; 121 } 122 if (this == obj) { 123 return true; 124 } 125 if (obj instanceof Capability) { 126 final Capability other = (Capability) obj; 127 return (mMode == other.mMode 128 && mMaxStreamingWidth == other.mMaxStreamingWidth 129 && mMaxStreamingHeight == other.mMaxStreamingHeight 130 && mMinZoomRatio == other.mMinZoomRatio 131 && mMaxZoomRatio == other.mMaxZoomRatio); 132 } 133 return false; 134 } 135 136 /** 137 * {@inheritDoc} 138 */ 139 @Override hashCode()140 public int hashCode() { 141 return HashCodeHelpers.hashCode(mMode, mMaxStreamingWidth, mMaxStreamingHeight, 142 mMinZoomRatio, mMaxZoomRatio); 143 } 144 145 /** 146 * Return the Capability as a string representation 147 * {@code "(mode:%d, maxStreamingSize:%d x %d, zoomRatio: %f-%f)"}. 148 * 149 * @return string representation of the capability and max streaming size. 150 */ 151 @Override toString()152 public String toString() { 153 return String.format("(mode:%d, maxStreamingSize:%d x %d, zoomRatio: %f-%f)", 154 mMode, mMaxStreamingWidth, mMaxStreamingHeight, mMinZoomRatio, 155 mMaxZoomRatio); 156 } 157 } 158