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 os.path
20
21def main():
22    """Test capturing a single frame as both DNG and YUV outputs.
23    """
24    NAME = os.path.basename(__file__).split(".")[0]
25
26    with its.device.ItsSession() as cam:
27        props = cam.get_camera_properties()
28        its.caps.skip_unless(its.caps.raw(props) and
29                             its.caps.read_3a(props))
30
31        cam.do_3a()
32
33        req = its.objects.auto_capture_request()
34        max_dng_size = \
35                its.objects.get_available_output_sizes("raw", props)[0]
36        w,h = its.objects.get_available_output_sizes(
37                "yuv", props, (1920, 1080), max_dng_size)[0]
38        out_surfaces = [{"format":"dng"},
39                        {"format":"yuv", "width":w, "height":h}]
40        cap_dng, cap_yuv = cam.do_capture(req, cam.CAP_DNG_YUV)
41
42        img = its.image.convert_capture_to_rgb_image(cap_yuv)
43        its.image.write_image(img, "%s.jpg" % (NAME))
44
45        with open("%s.dng"%(NAME), "wb") as f:
46            f.write(cap_dng["data"])
47
48        # No specific pass/fail check; test is assumed to have succeeded if
49        # it completes.
50
51if __name__ == '__main__':
52    main()
53
54