aboutsummaryrefslogtreecommitdiff
path: root/apps/CameraITS/tests/scene1/test_format_combos.py
blob: a7cf5b8d1562bf43c3ee06fec29bfce3c729b9a6 (plain)
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
# Copyright 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import its.image
import its.device
import its.objects
import its.error
import its.target
import sys
import time
import os
import os.path

# Change this to True, to have the test break at the first failure.
stop_at_first_failure = False

def main():
    """Test different combinations of output formats.
    """
    NAME = os.path.basename(__file__).split(".")[0]

    with its.device.ItsSession() as cam:

        props = cam.get_camera_properties()

        successes = []
        failures = []

        # Two different requests: auto, and manual.
        e, s = its.target.get_target_exposure_combos(cam)["midExposureTime"]
        req_aut = its.objects.auto_capture_request()
        req_man = its.objects.manual_capture_request(s, e)
        reqs = [req_aut, # R0
                req_man] # R1

        # 10 different combos of output formats; some are single surfaces, and
        # some are multiple surfaces.
        wyuv,hyuv = its.objects.get_available_output_sizes("yuv", props)[-1]
        wjpg,hjpg = its.objects.get_available_output_sizes("jpg", props)[-1]
        fmt_yuv_prev = {"format":"yuv", "width":wyuv, "height":hyuv}
        fmt_yuv_full = {"format":"yuv"}
        fmt_jpg_prev = {"format":"jpeg","width":wjpg, "height":hjpg}
        fmt_jpg_full = {"format":"jpeg"}
        fmt_raw_full = {"format":"raw"}
        fmt_combos =[
                [fmt_yuv_prev],                             # F0
                [fmt_yuv_full],                             # F1
                [fmt_jpg_prev],                             # F2
                [fmt_jpg_full],                             # F3
                [fmt_raw_full],                             # F4
                [fmt_yuv_prev, fmt_jpg_prev],               # F5
                [fmt_yuv_prev, fmt_jpg_full],               # F6
                [fmt_yuv_prev, fmt_raw_full],               # F7
                [fmt_yuv_prev, fmt_jpg_prev, fmt_raw_full], # F8
                [fmt_yuv_prev, fmt_jpg_full, fmt_raw_full]] # F9

        # Two different burst lenghts: single frame, and 3 frames.
        burst_lens = [1, # B0
                      3] # B1

        # There are 2x10x2=40 different combinations. Run through them all.
        n = 0
        for r,req in enumerate(reqs):
            for f,fmt_combo in enumerate(fmt_combos):
                for b,burst_len in enumerate(burst_lens):
                    try:
                        caps = cam.do_capture([req]*burst_len, fmt_combo)
                        successes.append((n,r,f,b))
                        print "==> Success[%02d]: R%d F%d B%d" % (n,r,f,b)

                        # Dump the captures out to jpegs.
                        if not isinstance(caps, list):
                            caps = [caps]
                        elif isinstance(caps[0], list):
                            caps = sum(caps, [])
                        for c,cap in enumerate(caps):
                            img = its.image.convert_capture_to_rgb_image(cap,
                                    props=props)
                            its.image.write_image(img,
                                    "%s_n%02d_r%d_f%d_b%d_c%d.jpg"%(NAME,n,r,f,b,c))

                    except Exception as e:
                        print e
                        print "==> Failure[%02d]: R%d F%d B%d" % (n,r,f,b)
                        failures.append((n,r,f,b))
                        if stop_at_first_failure:
                            sys.exit(0)
                    n += 1

        num_fail = len(failures)
        num_success = len(successes)
        num_total = len(reqs)*len(fmt_combos)*len(burst_lens)
        num_not_run = num_total - num_success - num_fail

        print "\nFailures (%d / %d):" % (num_fail, num_total)
        for (n,r,f,b) in failures:
            print "  %02d: R%d F%d B%d" % (n,r,f,b)
        print "\nSuccesses (%d / %d):" % (num_success, num_total)
        for (n,r,f,b) in successes:
            print "  %02d: R%d F%d B%d" % (n,r,f,b)
        if num_not_run > 0:
            print "\nNumber of tests not run: %d / %d" % (num_not_run, num_total)
        print ""

        # The test passes if all the combinations successfully capture.
        assert(num_fail == 0)
        assert(num_success == num_total)

if __name__ == '__main__':
    main()