second day
This commit is contained in:
@ -7,14 +7,14 @@
|
||||
|
||||
<title>Karls Analyzer</title>
|
||||
|
||||
<link rel='icon' type='image/png' href='/favicon.png'>
|
||||
<link rel='stylesheet' href='/global.css'>
|
||||
<link rel='stylesheet' href='/build/bundle.css'>
|
||||
<link rel='icon' type='image/png' href='favicon.png'>
|
||||
<link rel='stylesheet' href='global.css'>
|
||||
<link rel='stylesheet' href='build/bundle.css'>
|
||||
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;900&display=swap" rel="stylesheet">
|
||||
|
||||
<script defer src='/build/bundle.js'></script>
|
||||
<script defer src='build/bundle.js'></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
29
view/public/worker.js
Normal file
29
view/public/worker.js
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
|
||||
self.addEventListener('message', function (e) {
|
||||
|
||||
|
||||
const { data: { i, arr: pixels } } = e;
|
||||
|
||||
let store = {};
|
||||
|
||||
let total = pixels.length / 4;
|
||||
|
||||
const threshold = 200;
|
||||
|
||||
for (let i = 0; i < total; i++) {
|
||||
const r = pixels[i * 4 + 0] > threshold ? 1 : 0;
|
||||
const g = pixels[i * 4 + 1] > threshold ? 1 : 0;
|
||||
const b = pixels[i * 4 + 2] > threshold ? 1 : 0;
|
||||
const id = r + "-" + g + "-" + b;
|
||||
store[id] = store[id] + 1 || 1;
|
||||
}
|
||||
|
||||
|
||||
Object.keys(store).forEach(k => {
|
||||
store[k] = store[k] / total;
|
||||
});
|
||||
|
||||
|
||||
self.postMessage({ res: store, i });
|
||||
}, false);
|
Reference in New Issue
Block a user