ref: 5d9892c1ed5a089b17181030616f8e49a333848d
parent: 3815536a83ec0d536db00d6c5c0d2a60ec90ed8e
author: glenda <glenda@9front.local>
date: Mon Aug 28 18:32:28 EDT 2023
motion
--- /dev/null
+++ b/motion.c
@@ -1,0 +1,54 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <memdraw.h>
+
+void
+usage(void)
+{
+ sysfatal("usage:\n\t%s [-v]\n", argv0);
+}
+
+void
+main(int argc, char **argv)
+{
+ Memimage *last, *this;
+ unsigned long long dist;
+ int len;
+ int thresh;
+ int i;
+ int debug = 0;
+
+ ARGBEGIN {
+ case 'v':
+ debug = 1;
+ break;
+ default:
+ usage();
+ } ARGEND;
+
+ last = readmemimage(0);
+ len = bytesperline(last->r, last->depth) * Dy(last->r);
+ thresh = (len / 3) * 10;
+
+ if (debug)
+ fprint(2, "%d %d\n", len, thresh);
+
+ while(1) {
+ this = readmemimage(0);
+ dist = 0;
+
+ for (i = 0; i < len; i++) {
+ dist += abs(this->data->bdata[i] - last->data->bdata[i]);
+ }
+
+ if (debug)
+ fprint(2, "%llud\n", dist);
+
+ if (dist > thresh)
+ writememimage(1, this);
+
+ freememimage(last);
+ last = this;
+ }
+}