-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathvisioncamera.controller.exposure.harness.ts
More file actions
164 lines (152 loc) · 5.46 KB
/
visioncamera.controller.exposure.harness.ts
File metadata and controls
164 lines (152 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import { beforeAll, describe, expect, it } from 'react-native-harness'
import type {
CameraDevice,
CameraDeviceFactory,
} from 'react-native-vision-camera'
import { CommonResolutions, VisionCamera } from 'react-native-vision-camera'
describe('VisionCamera - Controller Exposure', () => {
let factory: CameraDeviceFactory
let backDevice: CameraDevice
beforeAll(async () => {
await VisionCamera.requestCameraPermission()
expect(VisionCamera.cameraPermissionStatus).toBe('authorized')
factory = await VisionCamera.createDeviceFactory()
const back = factory.getDefaultCamera('back')
expect(back).toBeDefined()
if (back == null) throw new Error('no back camera')
backDevice = back
})
it('sets exposure bias to min/max when the device supports it', async (context) => {
if (!backDevice.supportsExposureBias) {
return context.skip('exposureBias: not supported on this device')
}
const session = await VisionCamera.createCameraSession(false)
const photoOutput = VisionCamera.createPhotoOutput({
targetResolution: CommonResolutions.HD_4_3,
containerFormat: 'jpeg',
quality: 0.8,
qualityPrioritization: 'balanced',
})
const [controller] = await session.configure([
{
input: backDevice,
outputs: [{ output: photoOutput, mirrorMode: 'auto' }],
constraints: [],
},
])
if (controller == null) throw new Error('no controller')
await session.start()
try {
// AVCaptureDevice quantizes the requested bias to a discrete rational
// step, so the readback may differ from the request by a tiny epsilon.
await controller.setExposureBias(backDevice.maxExposureBias)
expect(controller.exposureBias).toBeCloseTo(backDevice.maxExposureBias, 4)
await controller.setExposureBias(backDevice.minExposureBias)
expect(controller.exposureBias).toBeCloseTo(backDevice.minExposureBias, 4)
await controller.setExposureBias(0)
expect(controller.exposureBias).toBeCloseTo(0, 4)
} finally {
await session.stop()
}
})
it('rejects setExposureBias outside the device range', async (context) => {
if (!backDevice.supportsExposureBias) {
return context.skip(
'exposureBias out-of-range: not supported on this device',
)
}
const session = await VisionCamera.createCameraSession(false)
const photoOutput = VisionCamera.createPhotoOutput({
targetResolution: CommonResolutions.HD_4_3,
containerFormat: 'jpeg',
quality: 0.8,
qualityPrioritization: 'balanced',
})
const [controller] = await session.configure([
{
input: backDevice,
outputs: [{ output: photoOutput, mirrorMode: 'auto' }],
constraints: [],
},
])
if (controller == null) throw new Error('no controller')
await session.start()
try {
const tooHighExposureBias = backDevice.maxExposureBias + 1
const tooLowExposureBias = backDevice.minExposureBias - 1
await expect(
controller.setExposureBias(tooHighExposureBias),
).rejects.toThrow()
await expect(
controller.setExposureBias(tooLowExposureBias),
).rejects.toThrow()
} finally {
await session.stop()
}
})
// TODO(Android): Re-enable once initial CameraX control config is applied after the camera is active.
it.skip('honors initialExposureBias passed to configure', async (context) => {
if (!backDevice.supportsExposureBias) {
return context.skip(
'initialExposureBias: device does not support exposure bias',
)
}
const session = await VisionCamera.createCameraSession(false)
const photoOutput = VisionCamera.createPhotoOutput({
targetResolution: CommonResolutions.HD_4_3,
containerFormat: 'jpeg',
quality: 0.8,
qualityPrioritization: 'balanced',
})
const initial = backDevice.maxExposureBias
const [controller] = await session.configure([
{
input: backDevice,
outputs: [{ output: photoOutput, mirrorMode: 'auto' }],
constraints: [],
initialExposureBias: initial,
},
])
if (controller == null) throw new Error('no controller')
await session.start()
try {
expect(controller.exposureBias).toBeCloseTo(initial, 4)
} finally {
await session.stop()
}
})
it('enables low-light boost via CameraController.configure when supported', async (context) => {
const lowLightDevice = factory.cameraDevices.find(
(d) => d.supportsLowLightBoost,
)
if (lowLightDevice == null) {
return context.skip(
'low-light boost: no device on this system supports it',
)
}
const session = await VisionCamera.createCameraSession(false)
const photoOutput = VisionCamera.createPhotoOutput({
targetResolution: CommonResolutions.HD_4_3,
containerFormat: 'jpeg',
quality: 0.8,
qualityPrioritization: 'balanced',
})
const [controller] = await session.configure([
{
input: lowLightDevice,
outputs: [{ output: photoOutput, mirrorMode: 'auto' }],
constraints: [],
},
])
if (controller == null) throw new Error('no controller')
await session.start()
try {
await controller.configure({ enableLowLightBoost: true })
expect(controller.isLowLightBoostEnabled).toBe(true)
await controller.configure({ enableLowLightBoost: false })
expect(controller.isLowLightBoostEnabled).toBe(false)
} finally {
await session.stop()
}
})
})