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 15import os.path 16import its.caps 17import its.device 18import its.image 19import its.objects 20import its.target 21 22NAME = os.path.basename(__file__).split('.')[0] 23Y_DELTA = 0.1 24GRADIENT_DELTA = 0.1 25 26 27def main(): 28 """Test that the android.flash.mode parameter is applied.""" 29 30 with its.device.ItsSession() as cam: 31 props = cam.get_camera_properties() 32 its.caps.skip_unless(its.caps.compute_target_exposure(props) and 33 its.caps.flash(props) and 34 its.caps.per_frame_control(props)) 35 36 flash_modes_reported = [] 37 flash_states_reported = [] 38 means = [] 39 grads = [] 40 41 # Manually set the exposure to be a little on the dark side, so that 42 # it should be obvious whether the flash fired or not, and use a 43 # linear tonemap. 44 debug = its.caps.debug_mode() 45 largest_yuv = its.objects.get_largest_yuv_format(props) 46 if debug: 47 fmt = largest_yuv 48 else: 49 match_ar = (largest_yuv['width'], largest_yuv['height']) 50 fmt = its.objects.get_smallest_yuv_format(props, match_ar=match_ar) 51 52 e, s = its.target.get_target_exposure_combos(cam)['midExposureTime'] 53 e /= 4 54 req = its.objects.manual_capture_request(s, e, 0.0, True, props) 55 56 for f in [0, 1, 2]: 57 req['android.flash.mode'] = f 58 cap = cam.do_capture(req, fmt) 59 flash_modes_reported.append(cap['metadata']['android.flash.mode']) 60 flash_states_reported.append(cap['metadata']['android.flash.state']) 61 y, _, _ = its.image.convert_capture_to_planes(cap, props) 62 its.image.write_image(y, '%s_%d.jpg' % (NAME, f)) 63 tile = its.image.get_image_patch(y, 0.375, 0.375, 0.25, 0.25) 64 its.image.write_image(tile, '%s_%d_tile.jpg' % (NAME, f)) 65 means.append(its.image.compute_image_means(tile)[0]) 66 grads.append(its.image.compute_image_max_gradients(tile)[0]) 67 68 assert flash_modes_reported == [0, 1, 2] 69 assert flash_states_reported[0] not in [3, 4] 70 assert flash_states_reported[1] in [3, 4] 71 assert flash_states_reported[2] in [3, 4] 72 73 print 'Brightnesses:', means 74 print 'Max gradients: ', grads 75 assert means[1]-means[0] > Y_DELTA or grads[1]-grads[0] > GRADIENT_DELTA 76 assert means[2]-means[0] > Y_DELTA or grads[2]-grads[0] > GRADIENT_DELTA 77 78if __name__ == '__main__': 79 main() 80 81