@@ -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.
44self . 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