feat: add some ai stuff
This commit is contained in:
20
view/src/helpers/AI.ts
Normal file
20
view/src/helpers/AI.ts
Normal 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 }
|
@@ -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;
|
||||
});
|
@@ -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";
|
Reference in New Issue
Block a user