second day

This commit is contained in:
2021-03-10 01:20:22 +01:00
parent 7fc8feb0cc
commit 521e2a4eb1
36 changed files with 3187 additions and 111 deletions

View File

@@ -0,0 +1,8 @@
const urlCreator = window.URL || window.webkitURL;
export default (buff: ArrayBuffer, mimeType: string) => {
const blob = new Blob([buff], { type: mimeType });
const imageUrl = urlCreator.createObjectURL(blob);
return imageUrl;
}

View File

@@ -0,0 +1,18 @@
const worker = new Worker("worker.js");
let i = 0;
let cb = {};
worker.addEventListener("message", ev => {
if (ev.data.i in cb) {
cb[ev.data.i](ev.data.res);
}
})
export default (arr: ArrayBuffer) => new Promise((res, rej) => {
i++;
const _i = i;
worker.postMessage({ i: _i, arr });
cb[_i] = res;
});

View File

@@ -0,0 +1,25 @@
import bufToImageUrl from "./BuffToImg";
export default (f: File): Promise<Image> => new Promise(async (res, rej) => {
const arr = await f.arrayBuffer()
const img = document.createElement("img");
img.src = bufToImageUrl(arr, f.type);
img.onload = async () => {
res({
id: 0,
width: img.width,
height: img.height,
name: f.name,
filename: f.name,
type: f.type,
colors: [],
overlayData: new ArrayBuffer(0),
lastModified: f.lastModified,
data: arr
});
};
});

View File

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