From 01c6954a48e46347cbf85890a85c00333ebc680b Mon Sep 17 00:00:00 2001
From: Jake Read <jake.read@cba.mit.edu>
Date: Sat, 16 Nov 2019 13:45:40 -0500
Subject: [PATCH] setup non-blocking pipes for correlation

---
 hunks/adhoc/correlate.js | 53 ++++++++++++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 13 deletions(-)

diff --git a/hunks/adhoc/correlate.js b/hunks/adhoc/correlate.js
index 957cd95..03d1871 100644
--- a/hunks/adhoc/correlate.js
+++ b/hunks/adhoc/correlate.js
@@ -11,9 +11,34 @@ import {
   State
 } from '../hunks.js'
 
-let correlate = (A, B) => {
+let running = false
+
+let correlate = (a, b) => {
   // score a against b,
   // a, b are str8 up matricies
+  console.log(b.width)
+  // ok, now we can do the maths on a and b, thx 
+}
+
+let delay = (time) => {
+  return new Promise(resolve =>{
+    setTimeout(() => {
+      resolve()
+    }, time)
+  })
+}
+
+async function run(ca, cb){
+  running = true
+  let a = ca.getImageData(0,0, ca.height, ca.width)
+  for(let x = 0; x < cb.width - a.width; x ++){
+    for(let y = 0; y < cb.height - a.height; y ++){
+      // make some b,
+      let b = cb.getImageData(x, y, a.width, a.height)
+      correlate(a, b)
+      await delay(100)
+    }
+  }
 }
 
 export default function Correlate(){
@@ -24,8 +49,11 @@ export default function Correlate(){
 
   let canvasA = $('<canvas>').get(0)
   let ctxA = canvasA.getContext('2d')
-  ctxA.width = 100
-  ctxA.height = 100
+  ctxA.width = 50
+  ctxA.height = 50
+
+  let canvasB = $('<canvas>').get(0)
+  let ctxB = canvasB.getContext('2d')
 
   this.dom = $('<div>').get(0)
 
@@ -34,25 +62,24 @@ export default function Correlate(){
 
   this.onload = () => {
     $(this.dom).append(canvasA)
+    $(this.dom).append(canvasB)
   }
 
   this.loop = () => {
-    if(imgIn.io() && !imgOut.io()){
+    if(imgIn.io() && !imgOut.io() && !running){
       let img = imgIn.get()
+      // put that into a context, where it's easy to snip from:
+      canvasB.width = img.width
+      canvasB.height = img.height
+      ctxB.width = img.width
+      ctxB.height = img.height
+      ctxB.putImageData(img, 0, 0, 0, 0, img.width, img.height)
       // we want to set up a loop for this ... first we need some A: a slice of our img,
       // since we're just checking against ourselves for now... let's take the middle
       // to clip, I'll use this canvas context ...
       // this is kind of surprising positioning inputs, but OK
       ctxA.putImageData(img, -img.width / 2, -img.height / 2, img.width / 2, img.height / 2, ctxA.height, ctxA.width)
-      let a = ctxA.getImageData(0,0, ctxA.height, ctxA.width)
-      //console.log(a.width, a.height)
-      // and b is our original img,
-      // what's the move here?
-      for(let x = 0; x < img.width - a.width, x ++){
-        for(let y = 0; y < img.height - a.height, y ++){
-
-        }
-      }
+      run(ctxA, ctxB)
     }
   }
 }
-- 
GitLab