diff --git a/hunks/laah/distanceTransform.js b/hunks/laah/distanceTransform.js deleted file mode 100644 index bfcaf3be8865347dedb7ebec8a3441c9f4241110..0000000000000000000000000000000000000000 --- a/hunks/laah/distanceTransform.js +++ /dev/null @@ -1,136 +0,0 @@ -/* - -hunk template - -*/ - -// these are ES6 modules -import { - Hunkify, - Input, - Output, - State -} from '../hunks.js' - -import {html, svg, render} from 'https://unpkg.com/lit-html?module'; - - -export default function distanceTransform() { - // this fn attaches handles to our function-object, - Hunkify(this) - - // inputs - let imageIn = new Input('RGBA', 'Image', this); - this.inputs.push(imageIn); - - // outputs - let floatArrayOut = new Output('Float32Array', 'distances', this); - this.outputs.push(floatArrayOut); - - - // Helper Functions - const distanceTransform = (imageRGBA) => { - var ny = imageRGBA.height - var nx = imageRGBA.width - var input = imageRGBA.data - var output = new Float32Array(nx*ny) - function distance(g,x,y,i) { - return ((y-i)*(y-i)+g[i][x]*g[i][x]) - } - function intersection(g,x,y0,y1) { - return ((g[y0][x]*g[y0][x]-g[y1][x]*g[y1][x]+y0*y0-y1*y1)/(2.0*(y0-y1))) - } - // - // allocate arrays - // - var g = [] - for (var y = 0; y < ny; ++y) - g[y] = new Uint32Array(nx) - var h = [] - for (var y = 0; y < ny; ++y) - h[y] = new Uint32Array(nx) - var distances = [] - for (var y = 0; y < ny; ++y) - distances[y] = new Uint32Array(nx) - var starts = new Uint32Array(ny) - var minimums = new Uint32Array(ny) - var d - // - // column scan - // - for (var y = 0; y < ny; ++y) { - // - // right pass - // - var closest = -nx - for (var x = 0; x < nx; ++x) { - if (input[(ny-1-y)*nx*4+x*4+0] != 0) { - g[y][x] = 0 - closest = x - } - else - g[y][x] = (x-closest) - } - // - // left pass - // - closest = 2*nx - for (var x = (nx-1); x >= 0; --x) { - if (input[(ny-1-y)*nx*4+x*4+0] != 0) - closest = x - else { - d = (closest-x) - if (d < g[y][x]) - g[y][x] = d - } - } - } - // - // row scan - // - for (var x = 0; x < nx; ++x) { - var segment = 0 - starts[0] = 0 - minimums[0] = 0 - // - // down - // - for (var y = 1; y < ny; ++y) { - while ((segment >= 0) && - (distance(g,x,starts[segment],minimums[segment]) > distance(g,x,starts[segment],y))) - segment -= 1 - if (segment < 0) { - segment = 0 - minimums[0] = y - } - else { - var newstart = 1+intersection(g,x,minimums[segment],y) - if (newstart < ny) { - segment += 1 - minimums[segment] = y - starts[segment] = newstart - } - } - } - // - // up - // - for (var y = (ny-1); y >= 0; --y) { - d = Math.sqrt(distance(g,x,y,minimums[segment])) - output[(ny-1-y)*nx+x] = d - if (y == starts[segment]) - segment -= 1 - } - } - - return output; - } - - //loop - this.loop = () => { - if (imageIn.io() && !floatArrayOut.io()) { - const newOut = distanceTransform(imageIn.get()); - floatArrayOut.put(newOut); - } - } -} diff --git a/hunks/laah/inProgress/edgeDetect.js b/hunks/laah/inProgress/edgeDetect.js deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/hunks/laah/inProgress/offset.js b/hunks/laah/inProgress/offset.js deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/hunks/laah/inProgress/orientEdges.js b/hunks/laah/inProgress/orientEdges.js deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/hunks/laah/inProgress/renderVectors.js b/hunks/laah/inProgress/renderVectors.js deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/hunks/laah/inProgress/vectorize.js b/hunks/laah/inProgress/vectorize.js deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/hunks/laah/readpng.js b/hunks/laah/readpng.js deleted file mode 100644 index d2aaa336ac0b73e4b138dcd396ebc762d8700b0a..0000000000000000000000000000000000000000 --- a/hunks/laah/readpng.js +++ /dev/null @@ -1,114 +0,0 @@ -/* - -hunk template - -*/ - -// these are ES6 modules -import { - Hunkify, - Input, - Output, - State -} from '../hunks.js' - -import {html, svg, render} from 'https://unpkg.com/lit-html?module'; - - -function UploadPNG() { - // this fn attaches handles to our function-object, - Hunkify(this) - - const imageOut = new Output('RGBA', 'Image', this) - this.outputs.push(imageOut) - - this.init = () => { - this.dom = $('<div>').get(0) - } - - //import - const png_read_handler = (e) => { - const reader = new FileReader(); - - const files = e.target.files; - const file = files[0]; - - const img = new Image(); - img.file = file; - - const loader = (aImg) => (e) => { - aImg.src = e.target.result; - - aImg.onload = () => { - const canvas = document.getElementById("wackyAndTotallyUniqueID2"); - const ctx = canvas.getContext("2d"); - ctx.clearRect(0, 0, canvas.width, canvas.height); - ctx.drawImage(aImg, 0, 0); - - // string other functions here - const data = getImageDataRGBA(); - // console.log("data", data); - - imageOut.put(data) - // console.log(data); - // console.log("copied", JSON.stringify(data)); - - } - - }; - - - reader.onload = loader(img); - - reader.readAsDataURL(file); - } - - // get image data: RGBA - const getImageDataRGBA = () => { //should add dpi term here - const canvas = document.getElementById("wackyAndTotallyUniqueID2"); - const ctx = canvas.getContext("2d"); - - const imageRGBA = ctx.getImageData(0, 0, canvas.width, canvas.height); - - return imageRGBA; - } - - this.onload = () => { - const target = $('<div>').get(0); - $(this.dom).append(target); - - const view = html` - <style> - #wackyAndTotallyUniqueID2 { - border: 1px solid black; - margin: 5px; - } - - #wackyAndTotallyUniqueID { - position: absolute; - left: 10px; - top: 350px; - } - </style> - <div>Upload!</div> - <canvas - id="wackyAndTotallyUniqueID2" - width=300 - height=300> - </canvas> - <input - id="wackyAndTotallyUniqueID" - type="file" - accept="image/png" - @input=${(e) => png_read_handler(e)}></input> - ` - - render(view, target); - } - - - this.loop = () => {} -} - -// the hunk is also an ES6 module, this is how we export those: -export default UploadPNG; diff --git a/hunks/laah/thresholdRGBA.js b/hunks/laah/thresholdRGBA.js deleted file mode 100644 index cab2f8094f2e60ed354215241b2b8b81629732f3..0000000000000000000000000000000000000000 --- a/hunks/laah/thresholdRGBA.js +++ /dev/null @@ -1,100 +0,0 @@ -/* - -hunk template - -*/ - -// these are ES6 modules -import { - Hunkify, - Input, - Output, - State -} from '../hunks.js' - -import {html, svg, render} from 'https://unpkg.com/lit-html?module'; - - -export default function Threshold() { - // this fn attaches handles to our function-object, - Hunkify(this) - - // inputs - let imageIn = new Input('RGBA', 'Image', this); - this.inputs.push(imageIn); - - // states - let threshold = new State('number', 'Threshold', .5); - this.states.push(threshold); - - // outputs - let imageOut = new Output('RGBA', 'Image', this); - this.outputs.push(imageOut); - - - // Helper Functions - const thresholdRGBA = (imageRGBA, threshold) => { - const w = imageRGBA.width; - const h = imageRGBA.height; - const buf = imageRGBA.data; - const t = threshold; - - let r, g, b, a, i; - for (var row = 0; row < h; ++row) { - for (var col = 0; col < w; ++col) { - r = buf[(h-1-row)*w*4+col*4+0]; - g = buf[(h-1-row)*w*4+col*4+1]; - b = buf[(h-1-row)*w*4+col*4+2]; - a = buf[(h-1-row)*w*4+col*4+3]; - i = (r+g+b)/(3*255); - - let val; - if (a === 0) { - val = 255; - } else if (i > t) { - val = 255; - } else { - val = 0; - } - - buf[(h-1-row)*w*4+col*4+0] = val; - buf[(h-1-row)*w*4+col*4+1] = val; - buf[(h-1-row)*w*4+col*4+2] = val; - buf[(h-1-row)*w*4+col*4+3] = 255; - } - } - - const imgdata = new ImageData(buf, w, h) - - return imgdata; - } - - // view - // as is tradition - this.dom = {} - this.init = () => { - this.dom = $('<div>').get(0) - } - - this.onload = () => { - const target = $('<div>').get(0); - $(this.dom).append(target); - - const view = html` - <button - @mousedown=${() => { - // console.log("imageIn", imageIn.get()); - // console.log("copied", deepCopy(imageIn)); - const newOut = thresholdRGBA(imageIn.get(), threshold.value) - imageOut.put(newOut); - }}> - Calculate - </button> - ` - - render(view, target); - } - - //loop - this.loop = () => {} -} diff --git a/hunks/laah/viewRGBA.js b/hunks/laah/viewRGBA.js deleted file mode 100644 index 4b39a97bc40567838c3467890aa3ec699c10ec13..0000000000000000000000000000000000000000 --- a/hunks/laah/viewRGBA.js +++ /dev/null @@ -1,64 +0,0 @@ -/* - -hunk template - -*/ - -// these are ES6 modules -import { - Hunkify, - Input, - Output, - State -} from '../hunks.js' - -import {html, svg, render} from 'https://unpkg.com/lit-html?module'; - - -export default function viewRGBA() { - // this fn attaches handles to our function-object, - Hunkify(this) - - const imageIn = new Input('RGBA', 'Image', this) - this.inputs.push(imageIn) - - this.init = () => { - this.dom = $('<div>').get(0) - } - - this.onload = () => { - const target = $('<div>').get(0); - $(this.dom).append(target); - - const view = html` - <style> - #wackyAndTotallyUniqueID3 { - border: 1px solid black; - margin: 5px; - } - - </style> - <canvas - id="wackyAndTotallyUniqueID3" - width=300 - height=300> - </canvas> - ` - - render(view, target); - } - - - this.loop = () => { - if (imageIn.io()) { - const canvas = document.getElementById("wackyAndTotallyUniqueID3"); - const ctx = canvas.getContext("2d"); - ctx.clearRect(0, 0, canvas.width, canvas.height); - console.log("trying to draw", imageIn.get()); - ctx.putImageData(imageIn.get(), 0, 0); - // ctx.beginPath(); - // ctx.arc(100, 75, 50, 0, 2 * Math.PI); - // ctx.stroke(); - } - } -}