1 /* 2 * Copyright (C) 2023 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.annotation.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.hardware.camera2.CaptureResult; 22 import android.hardware.camera2.utils.HashCodeHelpers; 23 import android.text.TextUtils; 24 25 import com.android.internal.camera.flags.Flags; 26 import com.android.internal.util.Preconditions; 27 28 import java.util.Arrays; 29 30 /** 31 * Immutable class to store an 32 * {@link CaptureResult#STATISTICS_LENS_INTRINSICS_SAMPLES lens intrinsics intra-frame sample}. 33 */ 34 @FlaggedApi(Flags.FLAG_CONCERT_MODE) 35 public final class LensIntrinsicsSample { 36 /** 37 * Create a new {@link LensIntrinsicsSample}. 38 * 39 * <p>{@link LensIntrinsicsSample} contains the timestamp and the 40 * {@link CaptureResult#LENS_INTRINSIC_CALIBRATION} sample.</p> 41 * 42 * @param timestampNs timestamp in nanoseconds of the lens intrinsics sample. This uses the 43 * same time basis as {@link CaptureResult#SENSOR_TIMESTAMP}. 44 * @param lensIntrinsics the lens {@link CaptureResult#LENS_INTRINSIC_CALIBRATION intrinsic} 45 * calibration for the sample. 46 * 47 * @throws IllegalArgumentException if lensIntrinsics length is different from 5 48 */ 49 @FlaggedApi(Flags.FLAG_CONCERT_MODE) LensIntrinsicsSample(final long timestampNs, @NonNull final float[] lensIntrinsics)50 public LensIntrinsicsSample(final long timestampNs, @NonNull final float[] lensIntrinsics) { 51 mTimestampNs = timestampNs; 52 Preconditions.checkArgument(lensIntrinsics.length == 5); 53 mLensIntrinsics = lensIntrinsics; 54 } 55 56 /** 57 * Get the timestamp in nanoseconds. 58 * 59 *<p>The timestamps are in the same time basis as and comparable to 60 *{@link CaptureResult#SENSOR_TIMESTAMP android.sensor.timestamp}.</p> 61 * 62 * @return a long value (guaranteed to be finite) 63 */ 64 @FlaggedApi(Flags.FLAG_CONCERT_MODE) getTimestampNanos()65 public long getTimestampNanos() { 66 return mTimestampNs; 67 } 68 69 /** 70 * Get the lens {@link CaptureResult#LENS_INTRINSIC_CALIBRATION intrinsics} calibration 71 * 72 * @return a floating point value (guaranteed to be finite) 73 * @see CaptureResult#LENS_INTRINSIC_CALIBRATION 74 */ 75 @FlaggedApi(Flags.FLAG_CONCERT_MODE) 76 @NonNull getLensIntrinsics()77 public float[] getLensIntrinsics() { 78 return mLensIntrinsics; 79 } 80 81 /** 82 * Check if this {@link LensIntrinsicsSample} is equal to another {@link LensIntrinsicsSample}. 83 * 84 * <p>Two samples are only equal if and only if each of the lens intrinsics are equal.</p> 85 * 86 * @return {@code true} if the objects were equal, {@code false} otherwise 87 */ 88 @Override equals(final Object obj)89 public boolean equals(final Object obj) { 90 if (obj == null) { 91 return false; 92 } else if (this == obj) { 93 return true; 94 } else if (obj instanceof LensIntrinsicsSample) { 95 final LensIntrinsicsSample other = (LensIntrinsicsSample) obj; 96 return mTimestampNs == other.mTimestampNs 97 && Arrays.equals(mLensIntrinsics, other.getLensIntrinsics()); 98 } 99 return false; 100 } 101 102 /** 103 * {@inheritDoc} 104 */ 105 @Override hashCode()106 public int hashCode() { 107 int timestampHash = HashCodeHelpers.hashCode(((float)mTimestampNs)); 108 return HashCodeHelpers.hashCode(Arrays.hashCode(mLensIntrinsics), timestampHash); 109 } 110 111 /** 112 * Return the LensIntrinsicsSample as a string representation. 113 * 114 * <p> {@code "LensIntrinsicsSample{timestamp:%l, sample:%s}"} represents the LensIntrinsics 115 * sample's timestamp, and calibration data.</p> 116 * 117 * @return string representation of {@link LensIntrinsicsSample} 118 */ 119 @Override toString()120 public String toString() { 121 return TextUtils.formatSimple("LensIntrinsicsSample{timestamp:%d, sample:%s}", mTimestampNs, 122 Arrays.toString(mLensIntrinsics)); 123 } 124 125 private final long mTimestampNs; 126 private final float [] mLensIntrinsics; 127 } 128