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        mono_camera = its.caps.mono_camera(props)
31
32        cam.do_3a(mono_camera=mono_camera)
33
34        req = its.objects.auto_capture_request()
35        max_dng_size = \
36                its.objects.get_available_output_sizes("raw", props)[0]
37        w,h = its.objects.get_available_output_sizes(
38                "yuv", props, (1920, 1080), max_dng_size)[0]
39        out_surfaces = [{"format":"dng"},
40                        {"format":"yuv", "width":w, "height":h}]
41        cap_dng, cap_yuv = cam.do_capture(req, cam.CAP_DNG_YUV)
42
43        img = its.image.convert_capture_to_rgb_image(cap_yuv)
44        its.image.write_image(img, "%s.jpg" % (NAME))
45
46        with open("%s.dng"%(NAME), "wb") as f:
47            f.write(cap_dng["data"])
48
49        # No specific pass/fail check; test is assumed to have succeeded if
50        # it completes.
51
52if __name__ == '__main__':
53    main()
54
55