1 /*
2 * Copyright 2024 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.viewfinder.compose
18
19 import android.util.Size
20 import androidx.camera.viewfinder.core.ImplementationMode
21 import androidx.camera.viewfinder.core.TransformationInfo
22 import androidx.compose.ui.Alignment
23 import androidx.compose.ui.layout.ContentScale
24 import androidx.compose.ui.unit.DpSize
25 import androidx.compose.ui.unit.dp
26
27 data class ViewfinderTestParams(
28 val viewfinderSize: DpSize = TEST_VIEWFINDER_SIZE,
29 val sourceRotation: Int = TEST_ROTATION,
30 val sourceResolution: Size =
31 when (sourceRotation) {
32 0,
33 180 -> TEST_RESOLUTION
34 90,
35 270 -> TEST_RESOLUTION.swapDimens()
36 else -> throw IllegalArgumentException("Invalid source rotation: $sourceRotation")
37 },
38 val implementationMode: ImplementationMode = ImplementationMode.EXTERNAL,
39 val isMirroredHorizontally: Boolean = false,
40 val isMirroredVertically: Boolean = false,
41 val transformationInfo: TransformationInfo =
42 TransformationInfo(
43 sourceRotation = sourceRotation,
44 isSourceMirroredHorizontally = isMirroredHorizontally,
45 isSourceMirroredVertically = isMirroredVertically
46 ),
47 val alignment: Alignment = Alignment.Center,
48 val contentScale: ContentScale = ContentScale.Crop
49 ) {
50 companion object {
51 val TEST_VIEWFINDER_SIZE = DpSize(360.dp, 640.dp)
52 const val TEST_ROTATION = 0
53 val TEST_RESOLUTION = Size(540, 960)
54 val Default = ViewfinderTestParams()
55 }
56 }
57
Sizenull58 private fun Size.swapDimens(): Size = Size(height, width)
59