1# Copyright 2017 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import its.caps
16import its.device
17import its.target
18
19import numpy as np
20
21GAIN_LENGTH = 4
22TRANSFORM_LENGTH = 9
23GREEN_GAIN = 1.0
24GREEN_GAIN_TOL = 0.05
25SINGLE_A = {'ae': [True, False, True], 'af': [False, True, True],
26            'full_3a': [True, True, True]}  # note no AWB solo
27
28
29def main():
30    """Basic test for bring-up of 3A.
31
32    To pass, 3A must converge. Check that the returned 3A values are legal.
33    """
34
35    with its.device.ItsSession() as cam:
36        props = cam.get_camera_properties()
37        its.caps.skip_unless(its.caps.read_3a(props))
38        mono_camera = its.caps.mono_camera(props)
39
40        for k, v in sorted(SINGLE_A.items()):
41            print k
42            try:
43                s, e, gains, xform, fd = cam.do_3a(get_results=True,
44                                                   do_ae=v[0],
45                                                   do_af=v[1],
46                                                   do_awb=v[2],
47                                                   mono_camera=mono_camera)
48                print ' sensitivity', s, 'exposure', e
49                print ' gains', gains, 'transform', xform
50                print ' fd', fd
51                print ''
52            except its.error.Error:
53                print ' FAIL\n'
54            if k == 'full_3a':
55                assert s > 0
56                assert e > 0
57                assert len(gains) == 4
58                for g in gains:
59                    assert not np.isnan(g)
60                assert len(xform) == 9
61                for x in xform:
62                    assert not np.isnan(x)
63                assert fd >= 0
64                assert np.isclose(gains[2], GREEN_GAIN, GREEN_GAIN_TOL)
65
66if __name__ == '__main__':
67    main()
68
69