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