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 |
Chien-Yu Chen | bad96ca | 2014-10-20 17:30:56 -0700 | [diff] [blame] | 17 | import sys |
| 18 | |
| 19 | |
| 20 | def skip_unless(cond): |
| 21 | """Skips the test if the condition is false. |
| 22 | |
| 23 | If a test is skipped, then it is exited and returns the special code |
| 24 | of 101 to the calling shell, which can be used by an external test |
| 25 | harness to differentiate a skip from a pass or fail. |
| 26 | |
| 27 | Args: |
| 28 | cond: Boolean, which must be true for the test to not skip. |
| 29 | |
| 30 | Returns: |
| 31 | Nothing. |
| 32 | """ |
| 33 | SKIP_RET_CODE = 101 |
| 34 | |
| 35 | if not cond: |
| 36 | print "Test skipped" |
| 37 | sys.exit(SKIP_RET_CODE) |
| 38 | |
Lu | 7c6f52e | 2015-12-15 14:42:18 -0800 | [diff] [blame] | 39 | def level3(props): |
| 40 | """Returns whether a device is a LEVEL3 capability camera2 device. |
| 41 | |
| 42 | Args: |
| 43 | props: Camera properties object. |
| 44 | |
| 45 | Returns: |
| 46 | Boolean. |
| 47 | """ |
| 48 | return props.has_key("android.info.supportedHardwareLevel") and \ |
| 49 | props["android.info.supportedHardwareLevel"] == 3 |
Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 50 | |
| 51 | def full(props): |
| 52 | """Returns whether a device is a FULL capability camera2 device. |
| 53 | |
| 54 | Args: |
| 55 | props: Camera properties object. |
| 56 | |
| 57 | Returns: |
| 58 | Boolean. |
| 59 | """ |
| 60 | return props.has_key("android.info.supportedHardwareLevel") and \ |
| 61 | props["android.info.supportedHardwareLevel"] == 1 |
| 62 | |
| 63 | def limited(props): |
| 64 | """Returns whether a device is a LIMITED capability camera2 device. |
| 65 | |
| 66 | Args: |
| 67 | props: Camera properties object. |
| 68 | |
| 69 | Returns: |
| 70 | Boolean. |
| 71 | """ |
| 72 | return props.has_key("android.info.supportedHardwareLevel") and \ |
| 73 | props["android.info.supportedHardwareLevel"] == 0 |
| 74 | |
| 75 | def legacy(props): |
| 76 | """Returns whether a device is a LEGACY capability camera2 device. |
| 77 | |
| 78 | Args: |
| 79 | props: Camera properties object. |
| 80 | |
| 81 | Returns: |
| 82 | Boolean. |
| 83 | """ |
| 84 | return props.has_key("android.info.supportedHardwareLevel") and \ |
| 85 | props["android.info.supportedHardwareLevel"] == 2 |
| 86 | |
Lu | 7c6f52e | 2015-12-15 14:42:18 -0800 | [diff] [blame] | 87 | def radial_distortion_correction(props): |
| 88 | """Returns whether a device supports RADIAL_DISTORTION_CORRECTION |
| 89 | capabilities. |
| 90 | |
| 91 | Args: |
| 92 | props: Camera properties object. |
| 93 | |
| 94 | Returns: |
| 95 | Boolean. |
| 96 | """ |
| 97 | return props.has_key("android.lens.radialDistortion") and \ |
| 98 | props["android.lens.radialDistortion"] is not None |
| 99 | |
Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 100 | def manual_sensor(props): |
| 101 | """Returns whether a device supports MANUAL_SENSOR capabilities. |
| 102 | |
| 103 | Args: |
| 104 | props: Camera properties object. |
| 105 | |
| 106 | Returns: |
| 107 | Boolean. |
| 108 | """ |
| 109 | return props.has_key("android.request.availableCapabilities") and \ |
| 110 | 1 in props["android.request.availableCapabilities"] \ |
| 111 | or full(props) |
| 112 | |
| 113 | def manual_post_proc(props): |
| 114 | """Returns whether a device supports MANUAL_POST_PROCESSING capabilities. |
| 115 | |
| 116 | Args: |
| 117 | props: Camera properties object. |
| 118 | |
| 119 | Returns: |
| 120 | Boolean. |
| 121 | """ |
| 122 | return props.has_key("android.request.availableCapabilities") and \ |
| 123 | 2 in props["android.request.availableCapabilities"] \ |
| 124 | or full(props) |
| 125 | |
| 126 | def raw(props): |
| 127 | """Returns whether a device supports RAW capabilities. |
| 128 | |
| 129 | Args: |
| 130 | props: Camera properties object. |
| 131 | |
| 132 | Returns: |
| 133 | Boolean. |
| 134 | """ |
| 135 | return props.has_key("android.request.availableCapabilities") and \ |
| 136 | 3 in props["android.request.availableCapabilities"] |
| 137 | |
| 138 | def raw16(props): |
| 139 | """Returns whether a device supports RAW16 output. |
| 140 | |
| 141 | Args: |
| 142 | props: Camera properties object. |
| 143 | |
| 144 | Returns: |
| 145 | Boolean. |
| 146 | """ |
| 147 | return len(its.objects.get_available_output_sizes("raw", props)) > 0 |
| 148 | |
| 149 | def raw10(props): |
| 150 | """Returns whether a device supports RAW10 output. |
| 151 | |
| 152 | Args: |
| 153 | props: Camera properties object. |
| 154 | |
| 155 | Returns: |
| 156 | Boolean. |
| 157 | """ |
| 158 | return len(its.objects.get_available_output_sizes("raw10", props)) > 0 |
| 159 | |
Yin-Chia Yeh | 76dd143 | 2015-04-27 16:42:03 -0700 | [diff] [blame] | 160 | def raw12(props): |
| 161 | """Returns whether a device supports RAW12 output. |
| 162 | |
| 163 | Args: |
| 164 | props: Camera properties object. |
| 165 | |
| 166 | Returns: |
| 167 | Boolean. |
| 168 | """ |
| 169 | return len(its.objects.get_available_output_sizes("raw12", props)) > 0 |
| 170 | |
Yin-Chia Yeh | b283e1ca | 2016-02-12 16:20:57 -0800 | [diff] [blame] | 171 | def raw_output(props): |
| 172 | """Returns whether a device supports any of RAW output format. |
| 173 | |
| 174 | Args: |
| 175 | props: Camera properties object. |
| 176 | |
| 177 | Returns: |
| 178 | Boolean. |
| 179 | """ |
| 180 | return raw16(props) or raw10(props) or raw12(props) |
| 181 | |
| 182 | def post_raw_sensitivity_boost(props): |
| 183 | """Returns whether a device supports post RAW sensitivity boost.. |
| 184 | |
| 185 | Args: |
| 186 | props: Camera properties object. |
| 187 | |
| 188 | Returns: |
| 189 | Boolean. |
| 190 | """ |
| 191 | return props.has_key("android.control.postRawSensitivityBoostRange") and \ |
| 192 | props["android.control.postRawSensitivityBoostRange"] != [100, 100] |
| 193 | |
Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 194 | def sensor_fusion(props): |
| 195 | """Returns whether the camera and motion sensor timestamps for the device |
Chien-Yu Chen | 682faa2 | 2014-10-22 17:34:44 -0700 | [diff] [blame] | 196 | are in the same time domain and can be compared directly. |
Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 197 | |
| 198 | Args: |
| 199 | props: Camera properties object. |
| 200 | |
| 201 | Returns: |
| 202 | Boolean. |
| 203 | """ |
| 204 | return props.has_key("android.sensor.info.timestampSource") and \ |
| 205 | props["android.sensor.info.timestampSource"] == 1 |
| 206 | |
| 207 | def read_3a(props): |
| 208 | """Return whether a device supports reading out the following 3A settings: |
| 209 | sensitivity |
| 210 | exposure time |
| 211 | awb gain |
| 212 | awb cct |
| 213 | focus distance |
| 214 | |
| 215 | Args: |
| 216 | props: Camera properties object. |
| 217 | |
| 218 | Returns: |
| 219 | Boolean. |
| 220 | """ |
| 221 | # TODO: check available result keys explicitly |
| 222 | return manual_sensor(props) and manual_post_proc(props) |
| 223 | |
| 224 | def compute_target_exposure(props): |
| 225 | """Return whether a device supports target exposure computation in its.target module. |
| 226 | |
| 227 | Args: |
| 228 | props: Camera properties object. |
| 229 | |
| 230 | Returns: |
| 231 | Boolean. |
| 232 | """ |
| 233 | return manual_sensor(props) and manual_post_proc(props) |
| 234 | |
Chien-Yu Chen | 0feea4a | 2014-10-20 11:04:11 -0700 | [diff] [blame] | 235 | def freeform_crop(props): |
| 236 | """Returns whether a device supports freefrom cropping. |
| 237 | |
| 238 | Args: |
| 239 | props: Camera properties object. |
| 240 | |
| 241 | Return: |
| 242 | Boolean. |
| 243 | """ |
| 244 | return props.has_key("android.scaler.croppingType") and \ |
| 245 | props["android.scaler.croppingType"] == 1 |
| 246 | |
Chien-Yu Chen | 8273911 | 2014-10-21 13:33:42 -0700 | [diff] [blame] | 247 | def flash(props): |
| 248 | """Returns whether a device supports flash control. |
| 249 | |
| 250 | Args: |
| 251 | props: Camera properties object. |
| 252 | |
| 253 | Return: |
| 254 | Boolean. |
| 255 | """ |
| 256 | return props.has_key("android.flash.info.available") and \ |
| 257 | props["android.flash.info.available"] == 1 |
| 258 | |
Chien-Yu Chen | 34fa85d | 2014-10-22 16:58:08 -0700 | [diff] [blame] | 259 | def per_frame_control(props): |
| 260 | """Returns whether a device supports per frame control |
| 261 | |
| 262 | Args: |
| 263 | props: Camera properties object. |
| 264 | |
| 265 | Return: |
| 266 | Boolean. |
| 267 | """ |
| 268 | return props.has_key("android.sync.maxLatency") and \ |
| 269 | props["android.sync.maxLatency"] == 0 |
| 270 | |
Zhijun He | 503da80 | 2015-02-04 14:35:38 -0800 | [diff] [blame] | 271 | def ev_compensation(props): |
| 272 | """Returns whether a device supports ev compensation |
| 273 | |
| 274 | Args: |
| 275 | props: Camera properties object. |
| 276 | |
| 277 | Return: |
| 278 | Boolean. |
| 279 | """ |
| 280 | return props.has_key("android.control.aeCompensationRange") and \ |
| 281 | props["android.control.aeCompensationRange"] != [0, 0] |
| 282 | |
Yin-Chia Yeh | 9c0d926 | 2015-04-03 17:02:13 -0700 | [diff] [blame] | 283 | def ae_lock(props): |
| 284 | """Returns whether a device supports AE lock |
| 285 | |
| 286 | Args: |
| 287 | props: Camera properties object. |
| 288 | |
| 289 | Return: |
| 290 | Boolean. |
| 291 | """ |
| 292 | return props.has_key("android.control.aeLockAvailable") and \ |
| 293 | props["android.control.aeLockAvailable"] == 1 |
| 294 | |
| 295 | def awb_lock(props): |
| 296 | """Returns whether a device supports AWB lock |
| 297 | |
| 298 | Args: |
| 299 | props: Camera properties object. |
| 300 | |
| 301 | Return: |
| 302 | Boolean. |
| 303 | """ |
| 304 | return props.has_key("android.control.awbLockAvailable") and \ |
| 305 | props["android.control.awbLockAvailable"] == 1 |
| 306 | |
Yin-Chia Yeh | 934d800 | 2015-05-26 14:34:39 -0700 | [diff] [blame] | 307 | def lsc_map(props): |
| 308 | """Returns whether a device supports lens shading map output |
| 309 | |
| 310 | Args: |
| 311 | props: Camera properties object. |
| 312 | |
| 313 | Return: |
| 314 | Boolean. |
| 315 | """ |
| 316 | return props.has_key( |
| 317 | "android.statistics.info.availableLensShadingMapModes") and \ |
| 318 | 1 in props["android.statistics.info.availableLensShadingMapModes"] |
| 319 | |
| 320 | def lsc_off(props): |
| 321 | """Returns whether a device supports disabling lens shading correction |
| 322 | |
| 323 | Args: |
| 324 | props: Camera properties object. |
| 325 | |
| 326 | Return: |
| 327 | Boolean. |
| 328 | """ |
| 329 | return props.has_key( |
| 330 | "android.shading.availableModes") and \ |
| 331 | 0 in props["android.shading.availableModes"] |
| 332 | |
Chien-Yu Chen | 4e1e2cc | 2015-06-08 17:46:52 -0700 | [diff] [blame] | 333 | def yuv_reprocess(props): |
| 334 | """Returns whether a device supports YUV reprocessing. |
| 335 | |
| 336 | Args: |
| 337 | props: Camera properties object. |
| 338 | |
| 339 | Returns: |
| 340 | Boolean. |
| 341 | """ |
| 342 | return props.has_key("android.request.availableCapabilities") and \ |
| 343 | 7 in props["android.request.availableCapabilities"] |
| 344 | |
| 345 | def private_reprocess(props): |
| 346 | """Returns whether a device supports PRIVATE reprocessing. |
| 347 | |
| 348 | Args: |
| 349 | props: Camera properties object. |
| 350 | |
| 351 | Returns: |
| 352 | Boolean. |
| 353 | """ |
| 354 | return props.has_key("android.request.availableCapabilities") and \ |
| 355 | 4 in props["android.request.availableCapabilities"] |
| 356 | |
Chien-Yu Chen | 455b57f | 2015-07-09 12:02:25 -0700 | [diff] [blame] | 357 | def noise_reduction_mode(props, mode): |
| 358 | """Returns whether a device supports the noise reduction mode. |
| 359 | |
| 360 | Args: |
| 361 | props: Camera properties objects. |
| 362 | mode: Integer, indicating the noise reduction mode to check for |
| 363 | availability. |
| 364 | |
| 365 | Returns: |
| 366 | Boolean. |
| 367 | """ |
| 368 | return props.has_key( |
| 369 | "android.noiseReduction.availableNoiseReductionModes") and mode \ |
| 370 | in props["android.noiseReduction.availableNoiseReductionModes"]; |
| 371 | |
| 372 | def edge_mode(props, mode): |
| 373 | """Returns whether a device supports the edge mode. |
| 374 | |
| 375 | Args: |
| 376 | props: Camera properties objects. |
| 377 | mode: Integer, indicating the edge mode to check for availability. |
| 378 | |
| 379 | Returns: |
| 380 | Boolean. |
| 381 | """ |
| 382 | return props.has_key( |
| 383 | "android.edge.availableEdgeModes") and mode \ |
| 384 | in props["android.edge.availableEdgeModes"]; |
| 385 | |
Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 386 | class __UnitTest(unittest.TestCase): |
| 387 | """Run a suite of unit tests on this module. |
| 388 | """ |
| 389 | # TODO: Add more unit tests. |
| 390 | |
| 391 | if __name__ == '__main__': |
| 392 | unittest.main() |
| 393 | |