• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 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.image
16import its.caps
17import its.device
18import its.objects
19import its.error
20import its.target
21import sys
22import os
23
24NAME = os.path.basename(__file__).split(".")[0]
25STOP_AT_FIRST_FAILURE = False  # change to True to have test break @ 1st FAIL
26
27
28def main():
29    """Test different combinations of output formats."""
30
31    with its.device.ItsSession() as cam:
32
33        props = cam.get_camera_properties()
34        its.caps.skip_unless(its.caps.compute_target_exposure(props) and
35                             its.caps.raw16(props))
36
37        successes = []
38        failures = []
39        debug = its.caps.debug_mode()
40
41        # Two different requests: auto, and manual.
42        e, s = its.target.get_target_exposure_combos(cam)["midExposureTime"]
43        req_aut = its.objects.auto_capture_request()
44        req_man = its.objects.manual_capture_request(s, e)
45        reqs = [req_aut,  # R0
46                req_man]  # R1
47
48        # 10 different combos of output formats; some are single surfaces, and
49        # some are multiple surfaces.
50        wyuv, hyuv = its.objects.get_available_output_sizes("yuv", props)[-1]
51        wjpg, hjpg = its.objects.get_available_output_sizes("jpg", props)[-1]
52        fmt_yuv_prev = {"format": "yuv", "width": wyuv, "height": hyuv}
53        fmt_yuv_full = {"format": "yuv"}
54        fmt_jpg_prev = {"format": "jpeg", "width": wjpg, "height": hjpg}
55        fmt_jpg_full = {"format": "jpeg"}
56        fmt_raw_full = {"format": "raw"}
57        fmt_combos = [
58            [fmt_yuv_prev],                              # F0
59            [fmt_yuv_full],                              # F1
60            [fmt_jpg_prev],                              # F2
61            [fmt_jpg_full],                              # F3
62            [fmt_raw_full],                              # F4
63            [fmt_yuv_prev, fmt_jpg_prev],                # F5
64            [fmt_yuv_prev, fmt_jpg_full],                # F6
65            [fmt_yuv_prev, fmt_raw_full],                # F7
66            [fmt_yuv_prev, fmt_jpg_prev, fmt_raw_full],  # F8
67            [fmt_yuv_prev, fmt_jpg_full, fmt_raw_full]]  # F9
68
69        # Two different burst lengths: single frame, and 3 frames.
70        burst_lens = [1,  # B0
71                      3]  # B1
72
73        # There are 2x10x2=40 different combinations. Run through them all.
74        n = 0
75        for r,req in enumerate(reqs):
76            for f,fmt_combo in enumerate(fmt_combos):
77                for b,burst_len in enumerate(burst_lens):
78                    try:
79                        caps = cam.do_capture([req]*burst_len, fmt_combo)
80                        successes.append((n,r,f,b))
81                        print "==> Success[%02d]: R%d F%d B%d" % (n,r,f,b)
82
83                        # Dump the captures out to jpegs in debug mode.
84                        if debug:
85                            if not isinstance(caps, list):
86                                caps = [caps]
87                            elif isinstance(caps[0], list):
88                                caps = sum(caps, [])
89                            for c, cap in enumerate(caps):
90                                img = its.image.convert_capture_to_rgb_image(cap, props=props)
91                                its.image.write_image(img,
92                                    "%s_n%02d_r%d_f%d_b%d_c%d.jpg"%(NAME,n,r,f,b,c))
93
94                    except Exception as e:
95                        print e
96                        print "==> Failure[%02d]: R%d F%d B%d" % (n,r,f,b)
97                        failures.append((n,r,f,b))
98                        if STOP_AT_FIRST_FAILURE:
99                            sys.exit(1)
100                    n += 1
101
102        num_fail = len(failures)
103        num_success = len(successes)
104        num_total = len(reqs)*len(fmt_combos)*len(burst_lens)
105        num_not_run = num_total - num_success - num_fail
106
107        print "\nFailures (%d / %d):" % (num_fail, num_total)
108        for (n,r,f,b) in failures:
109            print "  %02d: R%d F%d B%d" % (n,r,f,b)
110        print "\nSuccesses (%d / %d):" % (num_success, num_total)
111        for (n,r,f,b) in successes:
112            print "  %02d: R%d F%d B%d" % (n,r,f,b)
113        if num_not_run > 0:
114            print "\nNumber of tests not run: %d / %d" % (num_not_run, num_total)
115        print ""
116
117        # The test passes if all the combinations successfully capture.
118        assert num_fail == 0
119        assert num_success == num_total
120
121if __name__ == '__main__':
122    main()
123
124