Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame^] | 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 | |
| 15 | import unittest |
| 16 | import its.objects |
| 17 | |
| 18 | def full(props): |
| 19 | """Returns whether a device is a FULL capability camera2 device. |
| 20 | |
| 21 | Args: |
| 22 | props: Camera properties object. |
| 23 | |
| 24 | Returns: |
| 25 | Boolean. |
| 26 | """ |
| 27 | return props.has_key("android.info.supportedHardwareLevel") and \ |
| 28 | props["android.info.supportedHardwareLevel"] == 1 |
| 29 | |
| 30 | def limited(props): |
| 31 | """Returns whether a device is a LIMITED capability camera2 device. |
| 32 | |
| 33 | Args: |
| 34 | props: Camera properties object. |
| 35 | |
| 36 | Returns: |
| 37 | Boolean. |
| 38 | """ |
| 39 | return props.has_key("android.info.supportedHardwareLevel") and \ |
| 40 | props["android.info.supportedHardwareLevel"] == 0 |
| 41 | |
| 42 | def legacy(props): |
| 43 | """Returns whether a device is a LEGACY capability camera2 device. |
| 44 | |
| 45 | Args: |
| 46 | props: Camera properties object. |
| 47 | |
| 48 | Returns: |
| 49 | Boolean. |
| 50 | """ |
| 51 | return props.has_key("android.info.supportedHardwareLevel") and \ |
| 52 | props["android.info.supportedHardwareLevel"] == 2 |
| 53 | |
| 54 | def manual_sensor(props): |
| 55 | """Returns whether a device supports MANUAL_SENSOR capabilities. |
| 56 | |
| 57 | Args: |
| 58 | props: Camera properties object. |
| 59 | |
| 60 | Returns: |
| 61 | Boolean. |
| 62 | """ |
| 63 | return props.has_key("android.request.availableCapabilities") and \ |
| 64 | 1 in props["android.request.availableCapabilities"] \ |
| 65 | or full(props) |
| 66 | |
| 67 | def manual_post_proc(props): |
| 68 | """Returns whether a device supports MANUAL_POST_PROCESSING capabilities. |
| 69 | |
| 70 | Args: |
| 71 | props: Camera properties object. |
| 72 | |
| 73 | Returns: |
| 74 | Boolean. |
| 75 | """ |
| 76 | return props.has_key("android.request.availableCapabilities") and \ |
| 77 | 2 in props["android.request.availableCapabilities"] \ |
| 78 | or full(props) |
| 79 | |
| 80 | def raw(props): |
| 81 | """Returns whether a device supports RAW capabilities. |
| 82 | |
| 83 | Args: |
| 84 | props: Camera properties object. |
| 85 | |
| 86 | Returns: |
| 87 | Boolean. |
| 88 | """ |
| 89 | return props.has_key("android.request.availableCapabilities") and \ |
| 90 | 3 in props["android.request.availableCapabilities"] |
| 91 | |
| 92 | def raw16(props): |
| 93 | """Returns whether a device supports RAW16 output. |
| 94 | |
| 95 | Args: |
| 96 | props: Camera properties object. |
| 97 | |
| 98 | Returns: |
| 99 | Boolean. |
| 100 | """ |
| 101 | return len(its.objects.get_available_output_sizes("raw", props)) > 0 |
| 102 | |
| 103 | def raw10(props): |
| 104 | """Returns whether a device supports RAW10 output. |
| 105 | |
| 106 | Args: |
| 107 | props: Camera properties object. |
| 108 | |
| 109 | Returns: |
| 110 | Boolean. |
| 111 | """ |
| 112 | return len(its.objects.get_available_output_sizes("raw10", props)) > 0 |
| 113 | |
| 114 | def sensor_fusion(props): |
| 115 | """Returns whether the camera and motion sensor timestamps for the device |
| 116 | are in the same time domain and can be compared direcctly. |
| 117 | |
| 118 | Args: |
| 119 | props: Camera properties object. |
| 120 | |
| 121 | Returns: |
| 122 | Boolean. |
| 123 | """ |
| 124 | return props.has_key("android.sensor.info.timestampSource") and \ |
| 125 | props["android.sensor.info.timestampSource"] == 1 |
| 126 | |
| 127 | def read_3a(props): |
| 128 | """Return whether a device supports reading out the following 3A settings: |
| 129 | sensitivity |
| 130 | exposure time |
| 131 | awb gain |
| 132 | awb cct |
| 133 | focus distance |
| 134 | |
| 135 | Args: |
| 136 | props: Camera properties object. |
| 137 | |
| 138 | Returns: |
| 139 | Boolean. |
| 140 | """ |
| 141 | # TODO: check available result keys explicitly |
| 142 | return manual_sensor(props) and manual_post_proc(props) |
| 143 | |
| 144 | def compute_target_exposure(props): |
| 145 | """Return whether a device supports target exposure computation in its.target module. |
| 146 | |
| 147 | Args: |
| 148 | props: Camera properties object. |
| 149 | |
| 150 | Returns: |
| 151 | Boolean. |
| 152 | """ |
| 153 | return manual_sensor(props) and manual_post_proc(props) |
| 154 | |
| 155 | class __UnitTest(unittest.TestCase): |
| 156 | """Run a suite of unit tests on this module. |
| 157 | """ |
| 158 | # TODO: Add more unit tests. |
| 159 | |
| 160 | if __name__ == '__main__': |
| 161 | unittest.main() |
| 162 | |