CameraITS: Changed manual expsosure helper from ms to ns

Change-Id: I5c9d55da9c2a83df7a3b49a4454811e01c362695
diff --git a/apps/CameraITS/pymodules/its/objects.py b/apps/CameraITS/pymodules/its/objects.py
index cdcb6e7..78336f6 100644
--- a/apps/CameraITS/pymodules/its/objects.py
+++ b/apps/CameraITS/pymodules/its/objects.py
@@ -37,15 +37,15 @@
     else:
         return {"numerator":i, "denominator":1}
 
-def manual_capture_request(sensitivity, exp_time_ms):
+def manual_capture_request(sensitivity, exp_time):
     """Return a capture request with everything set to manual.
 
     Uses identity/unit color correction, and the default tonemap curve.
 
     Args:
         sensitivity: The sensitivity value to populate the request with.
-        exp_time_ms: The exposure time, in milliseconds, to populate the
-            request with.
+        exp_time: The exposure time, in nanoseconds, to populate the request
+            with.
 
     Returns:
         The default manual capture request, ready to be passed to the
@@ -59,7 +59,7 @@
         "android.control.effectMode": 0,
         "android.sensor.frameDuration": 0,
         "android.sensor.sensitivity": sensitivity,
-        "android.sensor.exposureTime": exp_time_ms*1000*1000,
+        "android.sensor.exposureTime": exp_time,
         "android.colorCorrection.mode": 0,
         "android.colorCorrection.transform":
                 int_to_rational([1,0,0, 0,1,0, 0,0,1]),
diff --git a/apps/CameraITS/pymodules/its/target.py b/apps/CameraITS/pymodules/its/target.py
index 1761ec5..2c2ca71 100644
--- a/apps/CameraITS/pymodules/its/target.py
+++ b/apps/CameraITS/pymodules/its/target.py
@@ -66,7 +66,7 @@
 
     # Capture a manual shot with this exposure, using a linear tonemap.
     # Use the gains+transform returned by the AWB pass.
-    req = its.objects.manual_capture_request(sens, exp_time / 1000000.0)
+    req = its.objects.manual_capture_request(sens, exp_time)
     req["android.tonemap.mode"] = 0
     req["android.tonemap.curveRed"] = tmap
     req["android.tonemap.curveGreen"] = tmap
diff --git a/apps/CameraITS/tests/test_black_level.py b/apps/CameraITS/tests/test_black_level.py
index 1405746..8d1c6cf 100644
--- a/apps/CameraITS/tests/test_black_level.py
+++ b/apps/CameraITS/tests/test_black_level.py
@@ -50,12 +50,12 @@
         props = cam.get_camera_properties()
         sens_range = props['android.sensor.info.sensitivityRange']
         sens_step = (sens_range[1] - sens_range[0]) / float(NUM_STEPS-1)
-        sensitivities = [sens_range[0] + i * sens_step for i in range(NUM_STEPS)]
+        sensitivities = [sens_range[0] + i*sens_step for i in range(NUM_STEPS)]
         print "Sensitivities:", sensitivities
 
         for si, s in enumerate(sensitivities):
             for rep in xrange(NUM_REPEAT):
-                req = its.objects.manual_capture_request(100, 1)
+                req = its.objects.manual_capture_request(100, 1*1000*1000)
                 req["android.blackLevel.lock"] = True
                 req["android.sensor.sensitivity"] = s
                 cap = cam.do_capture(req)
diff --git a/apps/CameraITS/tests/test_black_white.py b/apps/CameraITS/tests/test_black_white.py
index ac9bf2e..64d6045 100644
--- a/apps/CameraITS/tests/test_black_white.py
+++ b/apps/CameraITS/tests/test_black_white.py
@@ -41,8 +41,7 @@
 
         # Take a shot with very low ISO and exposure time. Expect it to
         # be black.
-        req = its.objects.manual_capture_request(sens_range[0],
-                                                 expt_range[0]/1000000.0)
+        req = its.objects.manual_capture_request(sens_range[0], expt_range[0])
         cap = cam.do_capture(req)
         img = its.image.convert_capture_to_rgb_image(cap)
         its.image.write_image(img, "%s_black.jpg" % (NAME))
@@ -55,8 +54,7 @@
 
         # Take a shot with very high ISO and exposure time. Expect it to
         # be white.
-        req = its.objects.manual_capture_request(sens_range[1],
-                                                 expt_range[1]/1000000.0)
+        req = its.objects.manual_capture_request(sens_range[1], expt_range[1])
         cap = cam.do_capture(req)
         img = its.image.convert_capture_to_rgb_image(cap)
         its.image.write_image(img, "%s_white.jpg" % (NAME))
diff --git a/apps/CameraITS/tests/test_blc_lsc.py b/apps/CameraITS/tests/test_blc_lsc.py
index 8324ec5..46e4025 100644
--- a/apps/CameraITS/tests/test_blc_lsc.py
+++ b/apps/CameraITS/tests/test_blc_lsc.py
@@ -41,8 +41,7 @@
         r = [0,0,1,1]
         ae_sen,ae_exp,awb_gains,awb_transform,_ = \
                 cam.do_3a(r,r,r,True,True,False)
-        ae_exp = ae_exp / 1000000.0
-        print "AE:", ae_sen, ae_exp
+        print "AE:", ae_sen, ae_exp / 1000000.0
         print "AWB:", awb_gains, awb_transform
 
         # Set analog gain (sensitivity) to 800
@@ -52,7 +51,7 @@
         # Capture range of exposures from 1/100x to 4x of AE estimate.
         exposures = [ae_exp*x/100.0 for x in [1]+range(10,401,20)]
         exposures = [e for e in exposures
-                     if e >= expt_range[0]/1000000 and e <= expt_range[1]/1000000]
+                     if e >= expt_range[0] and e <= expt_range[1]]
 
         # Convert the transform back to rational.
         awb_transform_rat = [{"numerator":int(100*x),"denominator":100}
diff --git a/apps/CameraITS/tests/test_exposure.py b/apps/CameraITS/tests/test_exposure.py
index 35f607f..82919e9 100644
--- a/apps/CameraITS/tests/test_exposure.py
+++ b/apps/CameraITS/tests/test_exposure.py
@@ -50,7 +50,7 @@
         m = 1
         while s*m < sens_range[1] and e/m > expt_range[0]:
             mults.append(m)
-            req = its.objects.manual_capture_request(s*m, e/1000000.0/m)
+            req = its.objects.manual_capture_request(s*m, e/m)
             cap = cam.do_capture(req)
             img = its.image.convert_capture_to_rgb_image(cap)
             its.image.write_image(img, "%s_mult=%02d.jpg" % (NAME, m))
diff --git a/apps/CameraITS/tests/test_formats.py b/apps/CameraITS/tests/test_formats.py
index ef7ab50..425e2a8 100644
--- a/apps/CameraITS/tests/test_formats.py
+++ b/apps/CameraITS/tests/test_formats.py
@@ -27,7 +27,7 @@
     with its.device.ItsSession() as cam:
         props = cam.get_camera_properties()
         for size in props['android.scaler.availableProcessedSizes']:
-            req = its.objects.manual_capture_request(100,10)
+            req = its.objects.manual_capture_request(100,10*1000*1000)
             out_surface = copy.deepcopy(size)
             out_surface["format"] = "yuv"
             cap = cam.do_capture(req, out_surface)
@@ -36,7 +36,7 @@
             assert(cap["height"] == size["height"])
             print "Captured YUV %dx%d" % (cap["width"], cap["height"])
         for size in props['android.scaler.availableJpegSizes']:
-            req = its.objects.manual_capture_request(100,10)
+            req = its.objects.manual_capture_request(100,10*1000*1000)
             out_surface = copy.deepcopy(size)
             out_surface["format"] = "jpg"
             cap = cam.do_capture(req, out_surface)
diff --git a/apps/CameraITS/tests/test_jpeg.py b/apps/CameraITS/tests/test_jpeg.py
index 8fdcbdf..e075518 100644
--- a/apps/CameraITS/tests/test_jpeg.py
+++ b/apps/CameraITS/tests/test_jpeg.py
@@ -33,7 +33,7 @@
         props = cam.get_camera_properties()
 
         # YUV
-        req = its.objects.manual_capture_request(100,100)
+        req = its.objects.manual_capture_request(100,100*1000*1000)
         size = props['android.scaler.availableProcessedSizes'][0]
         out_surface = copy.deepcopy(size)
         out_surface["format"] = "yuv"
@@ -44,7 +44,7 @@
         rgb0 = its.image.compute_image_means(tile)
 
         # JPEG
-        req = its.objects.manual_capture_request(100,100)
+        req = its.objects.manual_capture_request(100,100*1000*1000)
         size = props['android.scaler.availableJpegSizes'][0]
         out_surface = copy.deepcopy(size)
         out_surface["format"] = "jpg"
diff --git a/apps/CameraITS/tests/test_latching.py b/apps/CameraITS/tests/test_latching.py
index 5e3a9b7..30543ab 100644
--- a/apps/CameraITS/tests/test_latching.py
+++ b/apps/CameraITS/tests/test_latching.py
@@ -40,18 +40,18 @@
         s = s / 2.0
 
         reqs = [
-            its.objects.manual_capture_request(s,  e/1000000.0  ),
-            its.objects.manual_capture_request(s,  e/1000000.0  ),
-            its.objects.manual_capture_request(s*4,e/1000000.0  ),
-            its.objects.manual_capture_request(s*4,e/1000000.0  ),
-            its.objects.manual_capture_request(s,  e/1000000.0  ),
-            its.objects.manual_capture_request(s,  e/1000000.0  ),
-            its.objects.manual_capture_request(s,  e/1000000.0*4),
-            its.objects.manual_capture_request(s,  e/1000000.0  ),
-            its.objects.manual_capture_request(s*4,e/1000000.0  ),
-            its.objects.manual_capture_request(s,  e/1000000.0  ),
-            its.objects.manual_capture_request(s,  e/1000000.0*4),
-            its.objects.manual_capture_request(s,  e/1000000.0  ),
+            its.objects.manual_capture_request(s,  e  ),
+            its.objects.manual_capture_request(s,  e  ),
+            its.objects.manual_capture_request(s*4,e  ),
+            its.objects.manual_capture_request(s*4,e  ),
+            its.objects.manual_capture_request(s,  e  ),
+            its.objects.manual_capture_request(s,  e  ),
+            its.objects.manual_capture_request(s,  e*4),
+            its.objects.manual_capture_request(s,  e  ),
+            its.objects.manual_capture_request(s*4,e  ),
+            its.objects.manual_capture_request(s,  e  ),
+            its.objects.manual_capture_request(s,  e*4),
+            its.objects.manual_capture_request(s,  e  ),
             ]
 
         caps = cam.do_capture(reqs)
diff --git a/apps/CameraITS/tests/test_linearity.py b/apps/CameraITS/tests/test_linearity.py
index 656ebc1..340c629 100644
--- a/apps/CameraITS/tests/test_linearity.py
+++ b/apps/CameraITS/tests/test_linearity.py
@@ -55,7 +55,7 @@
         sens_step = (sens_range[1] - sens_range[0]) / float(NUM_STEPS-1)
         sensitivities = [sens_range[0] + i * sens_step for i in range(NUM_STEPS)]
 
-        req = its.objects.manual_capture_request(0, expt/1000000.0)
+        req = its.objects.manual_capture_request(0, expt)
         req["android.blackLevel.lock"] = True
         req["android.tonemap.mode"] = 0
         req["android.tonemap.curveRed"] = gamma_lut.tolist()
diff --git a/apps/CameraITS/tests/test_param_exposure_time.py b/apps/CameraITS/tests/test_param_exposure_time.py
index 8e0bd8a..a19af30 100644
--- a/apps/CameraITS/tests/test_param_exposure_time.py
+++ b/apps/CameraITS/tests/test_param_exposure_time.py
@@ -44,7 +44,7 @@
         exp_times = [expt_range[0] + i * expt_step for i in range(NUM_STEPS)]
 
         for e in exp_times:
-            req = its.objects.manual_capture_request(sens, e/1000000.0)
+            req = its.objects.manual_capture_request(sens, e)
             cap = cam.do_capture(req)
             img = its.image.convert_capture_to_rgb_image(cap)
             its.image.write_image(
diff --git a/apps/CameraITS/tests/test_param_exposure_time_burst.py b/apps/CameraITS/tests/test_param_exposure_time_burst.py
index f576af3..f0cb92b 100644
--- a/apps/CameraITS/tests/test_param_exposure_time_burst.py
+++ b/apps/CameraITS/tests/test_param_exposure_time_burst.py
@@ -26,7 +26,7 @@
     """
     NAME = os.path.basename(__file__).split(".")[0]
 
-    exp_times = range(1, 100, 9)
+    exp_times = range(1*1000*1000, 100*1000*1000, 9*1000*1000)
     reqs = [its.objects.manual_capture_request(100,e) for e in exp_times]
 
     with its.device.ItsSession() as cam:
diff --git a/apps/CameraITS/tests/test_param_sensitivity.py b/apps/CameraITS/tests/test_param_sensitivity.py
index 76e4647..43aec76 100644
--- a/apps/CameraITS/tests/test_param_sensitivity.py
+++ b/apps/CameraITS/tests/test_param_sensitivity.py
@@ -44,7 +44,7 @@
         sensitivities = [sens_range[0] + i * sens_step for i in range(NUM_STEPS)]
 
         for s in sensitivities:
-            req = its.objects.manual_capture_request(s, expt/1000000.0)
+            req = its.objects.manual_capture_request(s, expt)
             cap = cam.do_capture(req)
             img = its.image.convert_capture_to_rgb_image(cap)
             its.image.write_image(
diff --git a/apps/CameraITS/tests/test_param_sensitivity_burst.py b/apps/CameraITS/tests/test_param_sensitivity_burst.py
index f9143d7..315aee1 100644
--- a/apps/CameraITS/tests/test_param_sensitivity_burst.py
+++ b/apps/CameraITS/tests/test_param_sensitivity_burst.py
@@ -27,7 +27,8 @@
     NAME = os.path.basename(__file__).split(".")[0]
 
     sensitivities = range(350, 400, 7)
-    reqs = [its.objects.manual_capture_request(s,10) for s in sensitivities]
+    reqs = [its.objects.manual_capture_request(s,10*1000*1000)
+            for s in sensitivities]
 
     with its.device.ItsSession() as cam:
         caps = cam.do_capture(reqs)
diff --git a/apps/CameraITS/tests/test_param_tonemap_mode.py b/apps/CameraITS/tests/test_param_tonemap_mode.py
index 40f1582..5e75533 100644
--- a/apps/CameraITS/tests/test_param_tonemap_mode.py
+++ b/apps/CameraITS/tests/test_param_tonemap_mode.py
@@ -50,7 +50,7 @@
         rgb_means = []
 
         for n in [0,1]:
-            req = its.objects.manual_capture_request(100,50)
+            req = its.objects.manual_capture_request(100,50*1000*1000)
             req["android.tonemap.mode"] = 0
             req["android.tonemap.curveRed"] = (
                     sum([[i/LM1, (1+0.5*n)*i/LM1] for i in range(L)], []))
@@ -78,7 +78,7 @@
         for size in [32,64]:
             m = float(size-1)
             curve = sum([[i/m, i/m] for i in range(size)], [])
-            req = its.objects.manual_capture_request(100,50)
+            req = its.objects.manual_capture_request(100,50*1000*1000)
             req["android.tonemap.mode"] = 0
             req["android.tonemap.curveRed"] = curve
             req["android.tonemap.curveGreen"] = curve
diff --git a/apps/CameraITS/tests/tutorial.py b/apps/CameraITS/tests/tutorial.py
index 5fc96c6..a9a1797 100644
--- a/apps/CameraITS/tests/tutorial.py
+++ b/apps/CameraITS/tests/tutorial.py
@@ -30,6 +30,7 @@
 # Standard Python modules.
 import os.path
 import pprint
+import math
 
 # Modules from the numpy, scipy, and matplotlib libraries. These are used for
 # the image processing code, and images are represented as numpy arrays.
@@ -64,7 +65,7 @@
 
         # Grab a YUV frame with manual exposure of sensitivity = 200, exposure
         # duration = 50ms.
-        req = its.objects.manual_capture_request(200, 50)
+        req = its.objects.manual_capture_request(200, 50*1000*1000)
         cap = cam.do_capture(req)
 
         # Print the properties of the captured frame; width and height are
@@ -112,8 +113,9 @@
         # requests, meaning it is an object with integer numerators and
         # denominators. The 3A routine returns simple floats instead, however,
         # so a conversion from float to rational must be performed.
-        req = its.objects.manual_capture_request(sens, exp/1000000.0)
-        xform_rat = [{"numerator":int(f*100),"denominator":100} for f in xform]
+        req = its.objects.manual_capture_request(sens, exp)
+        xform_rat = [{"numerator":math.floor(v*128+0.5), "denominator":128}
+                     for v in xform]
         req["android.colorCorrection.transform"] = xform_rat
         req["android.colorCorrection.gains"] = gains
         cap = cam.do_capture(req)