Skip to content

Commit

Permalink
fixed "rgba array mismatch" bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sehugg committed Nov 29, 2023
1 parent abd8559 commit 9818e67
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/ui/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ const destCanvas = document.getElementById('destcanvas') as HTMLCanvasElement;
//const cmdline = document.getElementById('cmdline');

class ProxyDithertron {
worker: Worker;
settings: DithertronSettings;
lastPixels: PixelsAvailableMessage;

constructor(worker: Worker) {
worker.onmessage = (ev) => {
constructor() {
this.newWorker();
}
newWorker() {
// disable old worker
if (this.worker) this.worker.onmessage = () => {};
// create a new worker
this.worker = new Worker("./gen/worker.js");
this.worker.onmessage = (ev) => {
var data = ev.data;
if (data != null) {
//console.log('recv',data);
Expand All @@ -43,20 +51,18 @@ class ProxyDithertron {
}
setSettings(settings: DithertronSettings) {
this.settings = settings;
worker.postMessage({ cmd: "setSettings", data: settings });
this.worker.postMessage({ cmd: "setSettings", data: settings });
}
setSourceImage(img: Uint32Array) {
worker.postMessage({ cmd: "setSourceImage", data: img });
this.worker.postMessage({ cmd: "setSourceImage", data: img });
}
restart() {
worker.postMessage({ cmd: "restart" });
this.worker.postMessage({ cmd: "restart" });
}
pixelsAvailable: (msg: PixelsAvailableMessage) => void;
}

const worker = new Worker("./gen/worker.js");

export const dithertron = new ProxyDithertron(worker);
export const dithertron = new ProxyDithertron();

var filenameLoaded: string;
var presetLoaded: string;
Expand Down Expand Up @@ -231,6 +237,7 @@ function loadSourceImage(url: string) {

function setTargetSystem(sys: DithertronSettings) {
var showNoise = sys.conv != 'DitheringCanvas';
dithertron.newWorker();
dithertron.setSettings(sys);
dithertron.restart();
showSystemInfo(sys);
Expand Down

0 comments on commit 9818e67

Please sign in to comment.