1 /* 2 * Copyright 2015 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 android.hardware.camera2.utils.HashCodeHelpers; 20 21 /** 22 * Immutable class to store an input configuration that is used to create a reprocessable capture 23 * session. 24 * 25 * @see android.hardware.camera2.CameraDevice#createReprocessableCaptureSession 26 * @see android.hardware.camera2.CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP 27 */ 28 public final class InputConfiguration { 29 30 private final int mWidth; 31 private final int mHeight; 32 private final int mFormat; 33 34 /** 35 * Create an input configration with the width, height, and user-defined format. 36 * 37 * <p>Images of an user-defined format are accessible by applications. Use 38 * {@link android.hardware.camera2.CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP} 39 * to query supported input formats</p> 40 * 41 * @param width Width of the input buffers. 42 * @param height Height of the input buffers. 43 * @param format Format of the input buffers. One of ImageFormat or PixelFormat constants. 44 * 45 * @see android.graphics.ImageFormat 46 * @see android.graphics.PixelFormat 47 * @see android.hardware.camera2.CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP 48 */ InputConfiguration(int width, int height, int format)49 public InputConfiguration(int width, int height, int format) { 50 mWidth = width; 51 mHeight = height; 52 mFormat = format; 53 } 54 55 /** 56 * Get the width of this input configration. 57 * 58 * @return width of this input configuration. 59 */ getWidth()60 public int getWidth() { 61 return mWidth; 62 } 63 64 /** 65 * Get the height of this input configration. 66 * 67 * @return height of this input configuration. 68 */ getHeight()69 public int getHeight() { 70 return mHeight; 71 } 72 73 /** 74 * Get the format of this input configration. 75 * 76 * @return format of this input configuration. 77 */ getFormat()78 public int getFormat() { 79 return mFormat; 80 } 81 82 /** 83 * Check if this InputConfiguration is equal to another InputConfiguration. 84 * 85 * <p>Two input configurations are equal if and only if they have the same widths, heights, and 86 * formats.</p> 87 * 88 * @param obj the object to compare this instance with. 89 * 90 * @return {@code true} if the objects were equal, {@code false} otherwise. 91 */ 92 @Override equals(Object obj)93 public boolean equals(Object obj) { 94 if (!(obj instanceof InputConfiguration)) { 95 return false; 96 } 97 98 InputConfiguration otherInputConfig = (InputConfiguration) obj; 99 100 if (otherInputConfig.getWidth() == mWidth && 101 otherInputConfig.getHeight() == mHeight && 102 otherInputConfig.getFormat() == mFormat) { 103 return true; 104 } 105 return false; 106 } 107 108 /** 109 * {@inheritDoc} 110 */ 111 @Override hashCode()112 public int hashCode() { 113 return HashCodeHelpers.hashCode(mWidth, mHeight, mFormat); 114 } 115 116 /** 117 * Return this {@link InputConfiguration} as a string representation. 118 * 119 * <p> {@code "InputConfiguration(w:%d, h:%d, format:%d)"}, where {@code %d} represents 120 * the width, height, and format, respectively.</p> 121 * 122 * @return string representation of {@link InputConfiguration} 123 */ 124 @Override toString()125 public String toString() { 126 return String.format("InputConfiguration(w:%d, h:%d, format:%d)", mWidth, mHeight, mFormat); 127 } 128 } 129