KASM-3521 need to support relative pathing for the qoi workers (#44)

KASM-3521 need to support relative pathing for the qoi workers
This commit is contained in:
Ryan Kuba 2022-11-04 12:40:41 -07:00 committed by GitHub
parent a97fa93d84
commit c5350ba2d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 39 deletions

View File

@ -1609,6 +1609,7 @@ const UI = {
break;
case 'setvideoquality':
UI.forceSetting('video_quality', parseInt(event.data.value), false);
UI.forceSetting('enable_qoi', false, false); // QOI controlled via video quality mode when in iframe
UI.updateQuality();
break;
case 'enable_game_mode':
@ -2043,7 +2044,7 @@ const UI = {
}
//force QOI off if mode is below extreme
if (present_mode !== 4 && UI.getSetting('enable_qoi')) {
if (present_mode < 4 && UI.getSetting('enable_qoi')) {
UI.showStatus("Lossless QOI disabled when not in extreme quality mode.");
UI.forceSetting('enable_qoi', false, false);
}

View File

@ -249,7 +249,7 @@ async function load(module, imports) {
async function init(input) {
if (typeof input === 'undefined') {
input = '/core/decoders/qoi/qoi_viewer_bg.wasm';
input = path + 'core/decoders/qoi/qoi_viewer_bg.wasm';
}
const imports = {};
imports.wbg = {};
@ -296,9 +296,18 @@ async function init(input) {
}
var arr;
var path;
async function run() {
self.addEventListener('message', function(evt) {
self.addEventListener('message', async function(evt) {
if (evt.data.path) {
path = evt.data.path;
await init();
//Send message that worker is ready
self.postMessage({
result: 1
})
} else {
try {
let length = evt.data.length;
let data = new Uint8Array(evt.data.sab.slice(0, length));
@ -329,14 +338,8 @@ async function run() {
error: err
});
}
}
}, false);
await init();
//Send message that worker is ready
self.postMessage({
result: 1
})
}
run();

View File

@ -398,6 +398,8 @@ export default class TightDecoder {
}
_enableQOIWorkers() {
let fullPath = window.location.pathname;
let path = fullPath.substring(0, fullPath.lastIndexOf('/')+1);
let sabTest = typeof SharedArrayBuffer;
if (sabTest !== 'undefined') {
this._enableQOI = true;
@ -416,7 +418,7 @@ export default class TightDecoder {
this._qoiRects = [];
this._rectQlooping = false;
for (let i = 0; i < this._threads; i++) {
this._workers.push(new Worker("/core/decoders/qoi/decoder.js"));
this._workers.push(new Worker("core/decoders/qoi/decoder.js"));
this._sabs.push(new SharedArrayBuffer(300000));
this._sabsR.push(new SharedArrayBuffer(400000));
this._arrs.push(new Uint8Array(this._sabs[i]));
@ -450,6 +452,9 @@ export default class TightDecoder {
}
};
}
for (let i = 0; i < this._threads; i++) {
this._workers[i].postMessage({path:path});
}
} else {
this._enableQOI = false;
Log.Warn("Enabling QOI Failed, client not compatible.");