kornelski / dssim

Image similarity comparison simulating human perception (multiscale SSIM in Rust)
https://kornel.ski/dssim
GNU Affero General Public License v3.0
1.07k stars 69 forks source link

Wasm #148

Closed gedw99 closed 1 month ago

gedw99 commented 10 months ago

Would make it easier for me to use if I can compile it as wasm.

Anyone know how to do that ? Am not a rust expert but with rust I think it’s pretty easy by adding the right wasm export annotations to the rust functions we want exported.

then I can use it as part of a bigger system.

the wasm host runner will need to feed each image in as a byte array or similar because the wasm guest ( the rust code ) does not have access to the file system or network.

gedw99 commented 10 months ago

I just saw that this code is already designed to compile to wasm.

But odes it allow passing in the images as byte array though ?

--

For example:

https://kornel.ski/dssim shows that the image is passed in by ref.

I need to pass in as bytes because WASM environment can't use file system or network. Is that currently designed for ?

kornelski commented 10 months ago

The command-line version that takes PNG/JPEG files is not supported in WASM.

The library interface of https://docs.rs/dssim-core/latest/dssim_core/ is supported in WASM. It's up to you how to load images. The library takes raw pixels:

https://docs.rs/dssim-core/latest/dssim_core/struct.Dssim.html#method.create_image_rgba

There are no bindings for JS - you'll need to make your own Rust library that computes what you want, and make your own WASM bindings for JS in there.

gedw99 commented 10 months ago

Right .. thats @kornelski

I am not great at rust, and can't work out how to do that.

unclesmiley commented 1 month ago

@gedw99 You can try this project, which is a port version of this project.