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