Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upExample use cases #7
Comments
This was referenced Jan 12, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mpizenberg
Jan 14, 2018
Owner
Canvas 2D ImageData example done in 80b8491, in folder examples/CanvasImageData/. It's working fine, but with one main issue for performance: every frame, a new array is created, generating a lot of garbage collection. I wonder if providing a dedicated module clearly marked as Mutable with very few functions would make sense for use cases like this one, or WebGL.
|
Canvas 2D ImageData example done in 80b8491, in folder |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mpizenberg
Jan 14, 2018
Owner
A mutable typed array experimentation done in 7d0d625. It enables Canvas 2D ImageData manipulation without garbage collection. See example code in examples/CanvasImageDataMutable.
|
A mutable typed array experimentation done in 7d0d625. It enables Canvas 2D ImageData manipulation without garbage collection. See example code in |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mpizenberg
Jan 15, 2018
Owner
WebGL example done in 0213ec5. Typed arrays are used to pass the vertices attributes at initialization and projection matrices at each animation frame.
|
WebGL example done in 0213ec5. Typed arrays are used to pass the vertices attributes at initialization and projection matrices at each animation frame. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mpizenberg
Jan 17, 2018
Owner
File example done in de5d04b. A File input is used to load a file, sent through port to call readAsArrayBuffer(), array buffer result sent back to elm through port.
|
File example done in de5d04b. A File input is used to load a file, sent through port to call |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mpizenberg
Jan 28, 2018
Owner
WebSocket example done in 1accc47. The exchanged data with WebSocket is done through port in JS since there is no support of ArrayBuffer in the kind of data sendable through elm websocket api. The array buffer is extracted in JS from the Blob received and sent directly back to elm as an ArrayBuffer.
|
WebSocket example done in 1accc47. The exchanged data with WebSocket is done through port in JS since there is no support of |
mpizenberg commentedJan 12, 2018
•
edited
Edited 5 times
-
mpizenberg
edited Jan 28, 2018 (most recent)
-
mpizenberg
edited Jan 27, 2018
-
mpizenberg
edited Jan 17, 2018
-
mpizenberg
edited Jan 15, 2018
-
mpizenberg
edited Jan 14, 2018
Since one of the purposes of this library is to make Web APIs relying on typed arrays available, let's just do that ;)
In this blog post introducing typed arrays, the author list APIs making use of typed arrays, providing some examples. It would be awesome to try to implement one example of each use case with this elm-js-type-array package to improve design.
examples/WebGL/{Main.elm, index.html, webgl.js}examples/CanvasImageData/{Main.elm, index.html}examples/XMLHttpRequest/{Main.elm, index.html, answer.bin}examples/File/{Main.elm, index.html, answer.bin}examples/WebSocket/{Main.elm, index.html}Blog Post Examples
WebGL: useful to manipulate buffer data, textures, reading pixels, etc.
Canvas 2D: manipulating directly the pixel values in RGBA order.
XMLHttpRequest: getting array buffers in http requests
File APIs: reading file as buffers
MediaSource API: adding sources to media source buffer
WebSocket API: exchanging data as raw buffers over network
Endianness
Beware that typed arrays are using native hardware endiannes for maximum efficiency. Therefore the first thing to do when receiving a buffer from an external source (file, network, ...) is to check endianness used by the protocol and convert array buffer to the one with correct endianness on your machine.
Third Party Libraries
Some JavaScript libraries are filling gaps in the API. In particular, I suggest having a look at implementation and APIs of:
DataStream.js: improve reading of data from array bufferstext-encoding: ease encoding / decoding of strings