test_param_tonemap_mode.py revision 12339cdd90b2c98eb4f7adf794ddca8de53992b8
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 its.image 16import its.device 17import its.objects 18import os 19import sys 20import numpy 21import Image 22import math 23import time 24import os.path 25 26def main(): 27 """Test that the android.tonemap.mode param is applied. 28 29 Applies three different tonemap curves (linear, and clamped to zero and 30 one), and saves the resultant images. 31 """ 32 NAME = os.path.basename(__file__).split(".")[0] 33 34 # TODO: Query the allowable tonemap curve sizes; here, it's hardcoded to 35 # a length=32 list of tuples. The max allowed length should be inside the 36 # camera properties object. 37 TMLEN = 32 38 TMSCALE = float(TMLEN-1) 39 40 # Tonemap curves. 41 tonemap_linear = sum([[i/TMSCALE, i/TMSCALE] for i in range(TMLEN)], []) 42 tonemap_zero = sum([[i/TMSCALE, 0] for i in range(TMLEN)], []) 43 tonemap_one = sum([[i/TMSCALE, 1] for i in range(TMLEN)], []) 44 tonemaps = [tonemap_linear, tonemap_zero, tonemap_one] 45 46 req = its.objects.capture_request( { 47 "android.control.aeMode": 0, 48 "android.sensor.sensitivity": 100, 49 "android.sensor.exposureTime": 100*1000*1000, 50 "android.sensor.frameDuration": 0 51 }) 52 53 with its.device.ItsSession() as cam: 54 for mode in [0,1,2]: 55 for i, t in enumerate(tonemaps): 56 req["captureRequest"]["android.tonemap.mode"] = mode 57 req["captureRequest"]["android.tonemap.curveRed"] = t 58 req["captureRequest"]["android.tonemap.curveGreen"] = t 59 req["captureRequest"]["android.tonemap.curveBlue"] = t 60 fname, w, h, md = cam.do_capture(req) 61 img = its.image.load_yuv420_to_rgb_image(fname, w, h) 62 its.image.write_image( 63 img, "%s_mode=%d_curve=%d.jpg" %(NAME, mode,i)) 64 65if __name__ == '__main__': 66 main() 67 68