Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nodeca/multimath
WebAssembly wrapper to simplify fast math coding
https://github.com/nodeca/multimath
Last synced: 1 day ago
JSON representation
WebAssembly wrapper to simplify fast math coding
- Host: GitHub
- URL: https://github.com/nodeca/multimath
- Owner: nodeca
- License: mit
- Created: 2017-04-16T03:48:00.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-05-11T14:16:11.000Z (over 3 years ago)
- Last Synced: 2024-04-14T04:22:26.530Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 91.8 KB
- Stars: 66
- Watchers: 9
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-frontend - multimath - Core to create fast image math in WebAssembly and JS. ![](https://img.shields.io/github/stars/nodeca/multimath.svg?style=social&label=Star) (Repository / Math)
- awesome-nodejs-cn - multimath - 使用 WebAssembly 和 JS 创建快速图像数学的核心 (包 / 数学)
- awesome-nodejs - multimath - Core to create fast image math in WebAssembly and JS. (Repository / Math)
- awesome-nodejs-cn - multimath - **star:71** 核心创建快速图像数学在WebAssembly和JS (包 / 数学)
- awesome-nodejs - multimath - Core to create fast image math in WebAssembly and JS. (Packages / Math)
- awesome-nodejs - multimath - WebAssembly wrapper to simplify fast math coding - ★ 31 (Math)
- awesome-node - multimath - Core to create fast image math in WebAssembly and JS. (Packages / Math)
- awesome-nodejs-cn - multimath - 在WebAssembly和JS中创建快速图像数学的核心. (目录 / 数学)
README
multimath
=========[![Build Status](https://travis-ci.org/nodeca/multimath.svg?branch=master)](https://travis-ci.org/nodeca/multimath)
[![NPM version](https://img.shields.io/npm/v/multimath.svg)](https://www.npmjs.org/package/multimath)> Core to create fast image math in WebAssembly and JS.
`multimath` simplifies creation of small CPU-intensive webassembly modules
with fallback to JavaScript implementations.- It cares about modules init, memory management and other things.
- Has built-in helpers to write webassembly code without additional runtimes.
- Use shared memory to chain webassembly calls without memory copy.Built-in functions (curently - unsharp mask) are available as examples for your
extensions.Install
-------```bash
npm install multimath
```Use
---```js
const mm = require('multimath')()
.use(require('multimath/lib/unsharp_mask'))
.use(require('your_custom_module'))// Simple sync call. Will use sync wasm compile. Ok for webworkers.
// Can freeze interface at first call if wasm source is too big.
mm.unsharp_mask(rgba_buffer, width, height);// Async init, compile all modules at once in async way.
mm.init().then(() => {
mm.unsharp_mask(rgba_buffer, width, height);
});
```API
---### new multimath(options)
Create library instance. Sugar - `multimath()` (without `new`).
```js
const mm = require('multimath')({
// Options are not mandatory, but you can disable js or ww
// implementations for testing
js: true,
wasm: true
});
```### .use(module)
Register new module, format is:
```js
{
name: String, // default wasm module & function name to expose
fn: Function, // JS implementation
wasm_fn: Function, // WebAssembly glue
wasm_src: String // Base64 encoded WebAssembly module
}
```See example implementation in `lib/` folder.
### .init() -> Promise
Optional. Compile all wasm modules in async way. May be useful in this cases:
1. If you have wasm module > 4K AND run multimath in the main thread (not in
webworker). Some browsers prohibit sync wasm creation in this case.
2. If you have a lot of small modules and wish to init everything before run
in the main thread, withoutinterface freeze.Probably, you will never need to use this method. Note, 3K was file is
initialized in ~ 3ms.### .
All modules, loaded via `.use()`, pin their methods to current `Multimath`
instance. The best implementation will be selected automatically (depends on
browser features and constructor options);### Development
Ways to go with your own modules:
- See `package.json`
- See `./lib/unsharp_mask` as example and... of cause `./index.js`.Also, see how [pica](https://github.com/nodeca/pica)
use this library.Licence
-------[MIT](https://github.com/nodeca/multimath/blob/master/LICENSE)