[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2023-11-07 Thread Kai O'Reilly
For future reference for anyone who comes across this thread, you can directly pass RGBA image data to a canvas, which is around 200 times faster than encoding it to a PNG and rendering it to an offscreen image. Also, passing the unsafe pointer to the slice to JavaScript instead of copying the

[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2020-07-24 Thread Mark Farnan
Little old, but this might also help. A while back I built a helper package to deal with these issues for canvas rendering from Go. https://github.com/markfarnan/go-canvas I'm currently working on it to add WebGL support & get it working in TinyGo (some issues still). Regards Mark.

[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2020-03-22 Thread Scott Pakin
I figure I ought to follow up with some results. First, I got the suggested approach of local render + js.CopyBytesToJS + update canvas from image to work, so thanks, Agniva and Howard! Second, for the benefit of future readers of this

[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2020-03-12 Thread Scott Pakin
On Thursday, March 12, 2020 at 1:14:43 PM UTC-6, howar...@gmail.com wrote: > > If the was off-screen or hidden, couldn't you still reference it to > get the data into the canvas like: > var img = document.getElementById('targetImg'); > ctx.drawImage(img, 10, 10); > > Might not be the most

[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2020-03-12 Thread howardcshaw
> > let blob = new Blob([buf], {'type': imageType}); >> document.getElementById('targetImg').src = URL.createObjectURL(blob); >> } >> > > I see. In your case, targetImg is an , right? Do you know how I > could use this same technique with a ? > > If the was off-screen or hidden,

[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2020-03-12 Thread Scott Pakin
On Thursday, March 12, 2020 at 11:35:30 AM UTC-6, Agniva De Sarker wrote: > > There is no base64 conversion now anywhere. If you read the code below, > you'll see I use > > dst := js.Global().Get("Uint8Array").New(len(s.outBuf.Bytes())) > n := js.CopyBytesToJS(dst, s.outBuf.Bytes()) >

[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2020-03-12 Thread Agniva De Sarker
On Wednesday, 11 March 2020 18:52:15 UTC+5:30, howar...@gmail.com wrote: > > I've no relevant experience, but I can recommend a couple of projects to > look at in the absence of anyone chiming in with actual experience: > > https://agniva.me/wasm/2018/06/18/shimmer-wasm.html >

[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2020-03-11 Thread Scott Pakin
Thanks for the links and summaries. I had actually seen a few of those pages before. The plasma demonstration at least provides some empirical evidence that as hacky as it is to convert binary→base-64 ASCII→binary for every frame update, the actual performance isn't too terrible. On

[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2020-03-11 Thread howardcshaw
I've no relevant experience, but I can recommend a couple of projects to look at in the absence of anyone chiming in with actual experience: https://agniva.me/wasm/2018/06/18/shimmer-wasm.html https://github.com/agnivade/shimmer This is a play-project that involves loading images. It appears to