Skip to content

Commit ab95671

Browse files
committed
cleanup
1 parent a97253e commit ab95671

File tree

4 files changed

+40
-56
lines changed

4 files changed

+40
-56
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h2>Output Settings</h2>
7676
<div id="loadingBarContainer">
7777
<div id="loadingBar"></div>
7878
</div>
79-
<p id="loadingText">Loading...</p>
79+
<p id="loadingText">Rendering Image!</p>
8080
</div>
8181
</main>
8282

index.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,17 @@ function drawQbist(canvas, info, oversampling = 0) {
1212
worker.addEventListener("message", (e) => {
1313
const { command } = e.data
1414
if (command === "progress") {
15-
console.log(`Rendering progress: ${e.data.progress}%`)
15+
const { progress } = e.data
16+
loadingOverlay.style.display = "flex"
17+
loadingBar.style.width = progress + "%"
1618
} else if (command === "rendered") {
1719
const { imageData } = e.data
1820
const data = new Uint8ClampedArray(imageData)
1921
const imgData = new ImageData(data, width, height)
2022
ctx.putImageData(imgData, 0, 0)
2123
worker.terminate() // Clean up the worker
22-
resolve() // Resolve the Promise when rendering is complete
23-
}
24-
})
25-
worker.addEventListener("message", (e) => {
26-
const { command, progress } = e.data
27-
console.log("Worker message:", command, progress)
28-
if (command === "progress") {
29-
loadingOverlay.style.display = "flex"
30-
loadingBar.style.width = progress + "%"
31-
} else if (command === "rendered") {
3224
loadingOverlay.style.display = "none"
25+
resolve() // Resolve the Promise when rendering is complete
3326
}
3427
})
3528

@@ -79,9 +72,7 @@ export function updateAll() {
7972
function checkURLState() {
8073
const urlParams = new URLSearchParams(window.location.search)
8174
if (urlParams.has("state")) {
82-
console.log("State found in URL")
8375
const state = urlParams.get("state")
84-
console.log("State:", state)
8576
loadStateFromParam(state)
8677
return true
8778
}

qbistListeners.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export function loadStateFromParam(stateBase64) {
3737
try {
3838
const stateJSON = atob(stateBase64)
3939
const stateObj = JSON.parse(stateJSON)
40-
console.log("Loaded state:", stateObj)
4140
if (
4241
stateObj.transformSequence &&
4342
stateObj.source &&

worker.js

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,43 @@ import { optimize, qbist } from "/qbist.js"
22
// --- Worker Message Handling ---
33
// Receives a "render" command with payload and sends back the computed image data.
44
self.addEventListener("message", (e) => {
5-
console.log("aaa")
5+
const data = e.data
6+
if (data.command === "render") {
7+
const { info, width, height, oversampling = 1 } = data
8+
const { usedTransFlag, usedRegFlag } = optimize(info)
9+
const buffer = new Uint8ClampedArray(width * height * 4)
610

7-
try {
8-
const data = e.data
9-
if (data.command === "render") {
10-
const { info, width, height, oversampling = 1 } = data
11-
const { usedTransFlag, usedRegFlag } = optimize(info)
12-
const buffer = new Uint8ClampedArray(width * height * 4)
13-
14-
for (let y = 0; y < height; y++) {
15-
const progress = Math.floor((y / height) * 100)
16-
if (height > 256) {
17-
self.postMessage({ command: "progress", progress })
18-
}
19-
for (let x = 0; x < width; x++) {
20-
const color = qbist(
21-
info,
22-
x,
23-
y,
24-
width,
25-
height,
26-
oversampling,
27-
usedTransFlag,
28-
usedRegFlag
29-
)
30-
const r = Math.floor(color[0] * 255)
31-
const g = Math.floor(color[1] * 255)
32-
const b = Math.floor(color[2] * 255)
33-
const idx = (y * width + x) * 4
34-
buffer[idx] = r
35-
buffer[idx + 1] = g
36-
buffer[idx + 2] = b
37-
buffer[idx + 3] = 255
38-
}
11+
for (let y = 0; y < height; y++) {
12+
const progress = Math.floor((y / height) * 100)
13+
if (height > 256) {
14+
self.postMessage({ command: "progress", progress })
15+
}
16+
for (let x = 0; x < width; x++) {
17+
const color = qbist(
18+
info,
19+
x,
20+
y,
21+
width,
22+
height,
23+
oversampling,
24+
usedTransFlag,
25+
usedRegFlag
26+
)
27+
const r = Math.floor(color[0] * 255)
28+
const g = Math.floor(color[1] * 255)
29+
const b = Math.floor(color[2] * 255)
30+
const idx = (y * width + x) * 4
31+
buffer[idx] = r
32+
buffer[idx + 1] = g
33+
buffer[idx + 2] = b
34+
buffer[idx + 3] = 255
3935
}
40-
41-
// Transfer the image data buffer back to the main thread
42-
self.postMessage(
43-
{ command: "rendered", imageData: buffer.buffer, width, height },
44-
[buffer.buffer]
45-
)
4636
}
47-
} catch (e) {
48-
console.log(e)
37+
38+
// Transfer the image data buffer back to the main thread
39+
self.postMessage(
40+
{ command: "rendered", imageData: buffer.buffer, width, height },
41+
[buffer.buffer]
42+
)
4943
}
5044
})

0 commit comments

Comments
 (0)