Some updates to debug_window/threshold to support yuyv frames.

Also some errata improvements to image_types, segment, vector.

Change-Id: Ia7b32a469c20726c90b6148acf14151458f79e7d
diff --git a/aos/vision/blob/threshold.h b/aos/vision/blob/threshold.h
index 8b6051f..eef5b20 100644
--- a/aos/vision/blob/threshold.h
+++ b/aos/vision/blob/threshold.h
@@ -9,15 +9,15 @@
 
 // ThresholdFn should be a lambda.
 template <typename ThresholdFn>
-RangeImage DoThreshold(const ImagePtr &img, ThresholdFn &&fn) {
+RangeImage DoThreshold(ImageFormat fmt, ThresholdFn &&fn) {
   std::vector<std::vector<ImageRange>> ranges;
-  ranges.reserve(img.fmt().h);
-  for (int y = 0; y < img.fmt().h; ++y) {
+  ranges.reserve(fmt.h);
+  for (int y = 0; y < fmt.h; ++y) {
     bool p_score = false;
     int pstart = -1;
     std::vector<ImageRange> rngs;
-    for (int x = 0; x < img.fmt().w; ++x) {
-      if (fn(img.get_px(x, y)) != p_score) {
+    for (int x = 0; x < fmt.w; ++x) {
+      if (fn(x, y) != p_score) {
         if (p_score) {
           rngs.emplace_back(ImageRange(pstart, x));
         } else {
@@ -27,13 +27,29 @@
       }
     }
     if (p_score) {
-      rngs.emplace_back(ImageRange(pstart, img.fmt().w));
+      rngs.emplace_back(ImageRange(pstart, fmt.w));
     }
     ranges.push_back(rngs);
   }
   return RangeImage(0, std::move(ranges));
 }
 
+// ThresholdFn should be a lambda.
+template <typename ThresholdFn>
+RangeImage DoThreshold(const ImagePtr &img, ThresholdFn &&fn) {
+  return DoThreshold(img.fmt(),
+                     [&](int x, int y) { return fn(img.get_px(x, y)); });
+}
+
+// YUYV image types:
+inline RangeImage DoThresholdYUYV(ImageFormat fmt, const char *data,
+                                  uint8_t value) {
+  return DoThreshold(fmt, [&](int x, int y) {
+    uint8_t v = data[y * fmt.w * 2 + x * 2];
+    return v > value;
+  });
+}
+
 }  // namespace vision
 }  // namespace aos