DO NOT MERGE: CameraITS: add delta on saturation value for images

Use numpy.isclose() instead of equal to determine saturated images.
Allow up to 1 DN of difference between channels.
Have break to exit while loop.

Bug: 32577928
Change-Id: I6d441e350aa7fcfcd15eade6de4b57ff6324b0bc
diff --git a/apps/CameraITS/tests/scene1/test_ev_compensation_basic.py b/apps/CameraITS/tests/scene1/test_ev_compensation_basic.py
index 49ccbcf..a05a254 100644
--- a/apps/CameraITS/tests/scene1/test_ev_compensation_basic.py
+++ b/apps/CameraITS/tests/scene1/test_ev_compensation_basic.py
@@ -23,7 +23,11 @@
 import numpy
 
 #AE must converge within this number of auto requests for EV
-THREASH_CONVERGE_FOR_EV = 8
+THRESH_CONVERGE_FOR_EV = 8
+YUV_FULL_SCALE = 255.0
+YUV_SATURATION_MIN = 253.0
+YUV_SATURATION_TOL = 1.0
+
 
 def main():
     """Tests that EV compensation is applied.
@@ -66,9 +70,19 @@
         pylab.plot(evs, lumas, 'r')
         matplotlib.pyplot.savefig("%s_plot_means.png" % (NAME))
 
-        # trim trailing 1.0s (for saturated image)
-        while lumas and lumas[-1] == 1.0:
-            lumas.pop(-1)
+        # Trim extra saturated images
+        while lumas and lumas[-1] >= YUV_SATURATION_MIN/YUV_FULL_SCALE:
+            if (np.isclose(reds[-1], greens[-1],
+                           YUV_SATURATION_TOL/YUV_FULL_SCALE) and
+                    np.isclose(blues[-1], greens[-1],
+                               YUV_SATURATION_TOL/YUV_FULL_SCALE)):
+                lumas.pop(-1)
+                reds.pop(-1)
+                greens.pop(-1)
+                blues.pop(-1)
+                print 'Removed saturated image.'
+            else:
+                break
         # Only allow positive EVs to give saturated image
         assert(len(lumas) > 2)
         luma_diffs = numpy.diff(lumas)