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 pylab
     19 import os.path
     20 import matplotlib
     21 import matplotlib.pyplot
     22 import copy
     23 
     24 def main():
     25     """Test that predicted AWB values come out on the right frames.
     26     """
     27     NAME = os.path.basename(__file__).split(".")[0]
     28 
     29     def r2f(r):
     30         return float(r["numerator"]) / float(r["denominator"])
     31 
     32     reqs = its.objects.capture_request_list(
     33         [its.objects.manual_capture_request(100,0.1)["captureRequest"]]*7 + \
     34         [its.objects.manual_capture_request(300,33)["captureRequest"]]*7 + \
     35         [its.objects.manual_capture_request(100,0.1)["captureRequest"]]*7
     36         )
     37 
     38     curve = sum([[i/63.0, pow(i/63.0, 1/2.2)] for i in range(64)], [])
     39     for r in reqs["captureRequestList"]:
     40         r["android.tonemap.mode"] = 0
     41         r["android.tonemap.curveRed"] = curve
     42         r["android.tonemap.curveGreen"] = curve
     43         r["android.tonemap.curveBlue"] = curve
     44 
     45     with its.device.ItsSession() as cam:
     46         fnames, w, h, cap_mds = cam.do_capture(reqs)
     47         for i, fname in enumerate(fnames):
     48             img = its.image.load_yuv420_to_rgb_image(fname, w, h)
     49             its.image.write_image(img, "%s_i=%02d.jpg" % (NAME, i))
     50             cap_res = cap_mds[i]["captureResult"]
     51             print "Predicted:", \
     52                   cap_res["android.statistics.predictedColorGains"], \
     53                   [r2f(t) for t in cap_res["android.statistics.predictedColorTransform"]]
     54 
     55 if __name__ == '__main__':
     56     main()
     57 
     58