Skip to content

How to pass image data from JS to WASM and vice versa #1011

Description

@TrOllOchamO

Hello !
I'm currently trying to process image data on the browser using java code compiled to WASM.
To do so, I'm looking for a way to pass an Uint8Array from the JS side to WASM and get one in return, like below :

@Export("process")
public static byte[] process(byte[] data) {
  // process the data and return a new byte array
}
const imageData = new Uint8Array([1, 2, 3, 4]);
const processedImageData = bytecoder.instance.exports.process(0, imageData); // why should i pass 0 ?

The issue is that in the documentation it is said that supported types are :

  • Primitives (int, float, double, long, char, byte, short)
  • java.lang.String
  • de.mirkosertic.bytecoder.api.OpaqueReferenceType and sub classes of it
  • de.mirkosertic.bytecoder.api.Callback and sub classes of it

From what I understand from #433 and #542 it would be possible in my case to use an OpaqueReferenceType, but I wasn't able to find how I should use them.

Could you provide me (if it's possible) an example on how I could pass my data around ?

Also on a side note, I wasn't able to find an explanation on why we have to provide an unused parameter for all functions exported from WASM. Am I missing something ?

Thanks in advance,
--Barnabé

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions