mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Decode Blurhash pixels in a WebWorker
This commit is contained in:
parent
302094523e
commit
a47dd1b35c
2 changed files with 46 additions and 14 deletions
25
src/components/images/blurhash.worker.ts
Normal file
25
src/components/images/blurhash.worker.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { decode } from 'blurhash';
|
||||
import { expose } from 'comlink';
|
||||
|
||||
/**
|
||||
* Decodes blurhash outside the main thread, in a web worker
|
||||
*
|
||||
* @param {string} hash - Hash to decode.
|
||||
* @param {number} width - Width of the decoded pixel array
|
||||
* @param {number} height - Height of the decoded pixel array.
|
||||
* @param {number} punch - Contrast of the decoded pixels
|
||||
* @returns {Uint8ClampedArray} - Returns the decoded pixels in the proxied response by Comlink
|
||||
*/
|
||||
function getPixels({
|
||||
hash,
|
||||
width,
|
||||
height
|
||||
}): Uint8ClampedArray {
|
||||
try {
|
||||
return decode(hash, width, height);
|
||||
} catch {
|
||||
throw new TypeError(`Blurhash ${hash} is not valid`);
|
||||
}
|
||||
}
|
||||
|
||||
expose(getPixels);
|
Loading…
Add table
Add a link
Reference in a new issue