1 /* 2 * Copyright 2021 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.view.transform; 18 19 import android.graphics.Matrix; 20 import android.util.Size; 21 22 import androidx.annotation.RestrictTo; 23 import androidx.camera.core.UseCase; 24 import androidx.camera.core.UseCaseGroup; 25 import androidx.camera.view.TransformExperimental; 26 27 import org.jspecify.annotations.NonNull; 28 29 /** 30 * Represents the transform applied to the output of a {@link UseCase}. 31 * 32 * <p> Represents the rotation, cropping and/or mirroring applied to the raw buffer of a 33 * {@link UseCase} output. 34 */ 35 @TransformExperimental 36 public final class OutputTransform { 37 38 final @NonNull Matrix mMatrix; 39 final @NonNull Size mViewPortSize; 40 41 /** 42 * @param matrix The mapping from a normalized viewport space (-1, -1) - (1, 1) to 43 * the transformed output. e.g. the (-1, -1) maps to the (top, left) of 44 * the viewport and (1, 1) maps to the (bottom, right) of the 45 * viewport. 46 * @param viewPortSize The aspect ratio of the viewport. This is not used to calculate the 47 * transform. This is only used for mitigating the user mistake of not 48 * using a {@link UseCaseGroup}. By comparing the viewport to that of the 49 * other {@link OutputTransform}, we can at least make sure that they 50 * have the same aspect ratio, and warn developers if not. Viewports with 51 * different aspect ratios cannot be from the same {@link UseCaseGroup}. 52 */ 53 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) OutputTransform(@onNull Matrix matrix, @NonNull Size viewPortSize)54 public OutputTransform(@NonNull Matrix matrix, @NonNull Size viewPortSize) { 55 mMatrix = matrix; 56 mViewPortSize = viewPortSize; 57 } 58 59 /** 60 * Internal API that returns the underlying {@link Matrix} object. 61 * 62 */ 63 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) getMatrix()64 public @NonNull Matrix getMatrix() { 65 return mMatrix; 66 } 67 getViewPortSize()68 @NonNull Size getViewPortSize() { 69 return mViewPortSize; 70 } 71 72 } 73