1 /* 2 * Copyright 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 androidx.camera.testing.impl.fakes; 18 19 import android.graphics.Matrix; 20 21 import androidx.camera.core.ImageInfo; 22 import androidx.camera.core.impl.MutableTagBundle; 23 import androidx.camera.core.impl.TagBundle; 24 import androidx.camera.core.impl.utils.ExifData; 25 26 import org.jspecify.annotations.NonNull; 27 28 /** 29 * A fake implementation of {@link ImageInfo} where the values are settable. 30 */ 31 public final class FakeImageInfo implements ImageInfo { 32 private @NonNull MutableTagBundle mTagBundle = MutableTagBundle.create(); 33 private @NonNull Matrix mSensorToBufferTransformMatrix = new Matrix(); 34 35 private long mTimestamp; 36 private int mRotationDegrees; 37 private float mFocalLength; 38 39 /** set tag to a TagBundle */ setTag(@onNull String key, @NonNull Integer tag)40 public void setTag(@NonNull String key, @NonNull Integer tag) { 41 mTagBundle.putTag(key, tag); 42 } 43 44 /** set tag to a TagBundle */ setTag(@onNull TagBundle tagBundle)45 public void setTag(@NonNull TagBundle tagBundle) { 46 mTagBundle.addTagBundle(tagBundle); 47 } 48 setTimestamp(long timestamp)49 public void setTimestamp(long timestamp) { 50 mTimestamp = timestamp; 51 } 52 setRotationDegrees(int rotationDegrees)53 public void setRotationDegrees(int rotationDegrees) { 54 mRotationDegrees = rotationDegrees; 55 } 56 setFocalLength(float focalLength)57 public void setFocalLength(float focalLength) { 58 mFocalLength = focalLength; 59 } 60 setSensorToBufferTransformMatrix(@onNull Matrix sensorToBufferTransformMatrix)61 public void setSensorToBufferTransformMatrix(@NonNull Matrix sensorToBufferTransformMatrix) { 62 mSensorToBufferTransformMatrix = sensorToBufferTransformMatrix; 63 } 64 65 @Override getTagBundle()66 public @NonNull TagBundle getTagBundle() { 67 return mTagBundle; 68 } 69 70 @Override getTimestamp()71 public long getTimestamp() { 72 return mTimestamp; 73 } 74 75 @Override getRotationDegrees()76 public int getRotationDegrees() { 77 return mRotationDegrees; 78 } 79 80 @Override getSensorToBufferTransformMatrix()81 public @NonNull Matrix getSensorToBufferTransformMatrix() { 82 return mSensorToBufferTransformMatrix; 83 } 84 85 @Override populateExifData(ExifData.@onNull Builder exifBuilder)86 public void populateExifData(ExifData.@NonNull Builder exifBuilder) { 87 exifBuilder.setOrientationDegrees(mRotationDegrees); 88 exifBuilder.setFocalLength(mFocalLength); 89 } 90 } 91