Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing in WebAssembly #3

Open
ThatGuySam opened this issue Nov 24, 2021 · 7 comments
Open

Implementing in WebAssembly #3

ThatGuySam opened this issue Nov 24, 2021 · 7 comments

Comments

@ThatGuySam
Copy link

This may be a dumb and obvious question but how would you implement this in WebAssembly so you can use it with things like Node Serverless Functions and Edge Workers?

@gkrasin
Copy link

gkrasin commented Nov 24, 2021

The simplest way would be to use Emscripten for that: https://emscripten.org/
It can compile C and C++ into WebAssembly.
Given that qoi is a simple header-only library, this should be almost as easy as running a hello world for Emscripten.

It helps that no machine assembly / SIMD instructions are used in qoi, which is usually the primary pain when compiling into WebAssembly.

@ThatGuySam
Copy link
Author

I would assume I would have to pass in the whole image file into the "wasmed" qoi script as opposed to streaming the file.

Again, forgive my ignorance if these are simple questions.

@gkrasin
Copy link

gkrasin commented Nov 24, 2021

That sounds right. I recommend following this guide: https://developer.mozilla.org/en-US/docs/WebAssembly/existing_C_to_wasm

It shows how to compile libwebp into WebAssembly and get it working in the browser, so it should be very similar in the qoi case, just simpler.

@lifeart
Copy link

lifeart commented Nov 25, 2021

following this totorial https://emscripten.org/docs/getting_started/Tutorial.html

I got:
image

error (looks like i neeed to read readme carefully)

Anyway, as mentioned fs related logic shold be different for wasm, it could be array of pixels as input + dimensions

@Robaire
Copy link

Robaire commented Dec 3, 2021

Rust supports compiling directly to WebAssembly. It should be fairly straight forward to take the Rust clone and create a JavaScript wrapper as an alternative solution.

@ikskuh
Copy link

ikskuh commented Dec 4, 2021

This is also on my bucket list. If i find the time today or tomorrow, i can try creating a "wasm polyfill" for QOI support based on the Zig impl

@farteryhr
Copy link

i think this is suitable as an exercise for the readers to handwrite wasm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants