Skip to content
Snippets Groups Projects
Commit 01c6954a authored by Jake Read's avatar Jake Read
Browse files

setup non-blocking pipes for correlation

parent a7dad2b8
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment