feat: add some ai stuff

This commit is contained in:
2021-03-10 13:50:41 +01:00
parent a7851e5058
commit 578ee0d3fa
17 changed files with 438 additions and 86 deletions

20
view/src/helpers/AI.ts Normal file
View File

@@ -0,0 +1,20 @@
const worker = new Worker("build/ai-worker.js");
let i = 0;
let cb = {};
worker.addEventListener("message", ev => {
if (ev.data.i in cb) {
cb[ev.data.i](ev.data.res);
}
})
const analyze = (img: Image) => new Promise((res, rej) => {
i++;
const _i = i;
worker.postMessage({ i: _i, pixels: img.data, width: img.width, height: img.height });
cb[_i] = res;
});
export default { analyze }

View File

@@ -1,3 +1,5 @@
import { images } from "../stores";
const worker = new Worker("worker.js");
let i = 0;
@@ -6,13 +8,20 @@ let cb = {};
worker.addEventListener("message", ev => {
if (ev.data.i in cb) {
cb[ev.data.i](ev.data.res);
cb[ev.data.i](ev.data.result);
}
})
export default (arr: ArrayBuffer) => new Promise((res, rej) => {
interface res {
color: string
distortedValue: number
id: string
value: number
}
export default (img: Image, correctDistortion: boolean): Promise<res[]> => new Promise((res, rej) => {
i++;
const _i = i;
worker.postMessage({ i: _i, arr });
worker.postMessage({ i: _i, pixels: img.overlayData, width: img.width, height: img.height, correctDistortion });
cb[_i] = res;
});

View File

@@ -1,3 +1,4 @@
export { default as bufToImageUrl } from "./BuffToImg";
export { default as fileToImage } from "./FileToImage";
export { default as countPixels } from "./CountPixels";
export { default as countPixels } from "./CountPixels";
export { default as AI } from "./AI";