1 /* 2 * Copyright (C) 2013 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; 18 19 /** 20 * A simple immutable class for describing the dimensions of camera image 21 * buffers. 22 */ 23 public final class Size { 24 /** 25 * Create a new immutable Size instance 26 * 27 * @param width The width to store in the Size instance 28 * @param height The height to store in the Size instance 29 */ 30 public Size(int width, int height) { 31 mWidth = width; 32 mHeight = height; 33 } 34 35 public final int getWidth() { 36 return mWidth; 37 } 38 39 public final int getHeight() { 40 return mHeight; 41 } 42 43 @Override 44 public boolean equals(Object obj) { 45 if (obj == null) { 46 return false; 47 } 48 if (this == obj) { 49 return true; 50 } 51 if (obj instanceof Size) { 52 Size other = (Size) obj; 53 return mWidth == other.mWidth && mHeight == other.mHeight; 54 } 55 return false; 56 } 57 58 @Override 59 public String toString() { 60 return mWidth + "x" + mHeight; 61 } 62 63 @Override 64 public int hashCode() { 65 final long INT_MASK = 0xffffffffL; 66 67 long asLong = INT_MASK & mWidth; 68 asLong <<= 32; 69 70 asLong |= (INT_MASK & mHeight); 71 72 return ((Long)asLong).hashCode(); 73 } 74 75 private final int mWidth; 76 private final int mHeight; 77 }; 78