test_formats.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.path 19import Image 20 21def main(): 22 """Test that the reported sizes and formats for image capture work. 23 """ 24 NAME = os.path.basename(__file__).split(".")[0] 25 26 with its.device.ItsSession() as cam: 27 props = cam.get_camera_properties() 28 for size in props['android.scaler.availableProcessedSizes']: 29 req = its.objects.capture_request({"android.control.aeMode": 0}) 30 req["outputSurface"] = size 31 req["outputSurface"]["format"] = "yuv" 32 fname, w, h, cap_md = cam.do_capture(req) 33 assert(os.path.splitext(fname)[1] == ".yuv") 34 assert(w == size["width"] and h == size["height"]) 35 assert(os.path.getsize(fname) == w*h*3/2) 36 print "Successfully captured YUV %dx%d" % (w, h) 37 for size in props['android.scaler.availableJpegSizes']: 38 req = its.objects.capture_request({"android.control.aeMode": 0}) 39 req["outputSurface"] = size 40 req["outputSurface"]["format"] = "jpg" 41 fname, w, h, cap_md = cam.do_capture(req) 42 assert(os.path.splitext(fname)[1] == ".jpg") 43 assert(w == size["width"] and h == size["height"]) 44 img = Image.open(fname) 45 assert(img.size[0] == size["width"]) 46 assert(img.size[1] == size["height"]) 47 print "Successfully captured JPEG %dx%d" % (w, h) 48 49if __name__ == '__main__': 50 main() 51 52