1 # Copyright 2013 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 15 import os 16 import os.path 17 import sys 18 import re 19 import json 20 import tempfile 21 import time 22 import unittest 23 import subprocess 24 25 def int_to_rational(i): 26 """Function to convert Python integers to Camera2 rationals. 27 28 Args: 29 i: Python integer or list of integers. 30 31 Returns: 32 Python dictionary or list of dictionary representing the given int(s) 33 as rationals with denominator=1. 34 """ 35 if isinstance(i, list): 36 return [{"numerator":val, "denominator":1} for val in i] 37 else: 38 return {"numerator":i, "denominator":1} 39 40 def manual_capture_request(sensitivity, exp_time_ms): 41 """Return a capture request with everything set to manual. 42 43 Uses identity/unit color correction, and the default tonemap curve. 44 45 Args: 46 sensitivity: The sensitivity value to populate the request with. 47 exp_time_ms: The exposure time, in milliseconds, to populate the 48 request with. 49 50 Returns: 51 The default manual capture request, ready to be passed to the 52 its.device.do_capture function. 53 """ 54 return { 55 "android.control.mode": 0, 56 "android.control.aeMode": 0, 57 "android.control.awbMode": 0, 58 "android.control.afMode": 0, 59 "android.control.effectMode": 0, 60 "android.sensor.frameDuration": 0, 61 "android.sensor.sensitivity": sensitivity, 62 "android.sensor.exposureTime": exp_time_ms*1000*1000, 63 "android.colorCorrection.mode": 0, 64 "android.colorCorrection.transform": 65 int_to_rational([1,0,0, 0,1,0, 0,0,1]), 66 "android.colorCorrection.gains": [1,1,1,1], 67 "android.tonemap.mode": 1, 68 } 69 70 def auto_capture_request(): 71 """Return a capture request with everything set to auto. 72 """ 73 return { 74 "android.control.mode": 1, 75 "android.control.aeMode": 1, 76 "android.control.awbMode": 1, 77 "android.control.afMode": 1, 78 "android.colorCorrection.mode": 1, 79 "android.tonemap.mode": 1, 80 } 81 82 class __UnitTest(unittest.TestCase): 83 """Run a suite of unit tests on this module. 84 """ 85 86 # TODO: Add more unit tests. 87 88 def test_int_to_rational(self): 89 """Unit test for int_to_rational. 90 """ 91 self.assertEqual(int_to_rational(10), 92 {"numerator":10,"denominator":1}) 93 self.assertEqual(int_to_rational([1,2]), 94 [{"numerator":1,"denominator":1}, 95 {"numerator":2,"denominator":1}]) 96 97 if __name__ == '__main__': 98 unittest.main() 99 100