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

Using wasm to accelerate PixelManipulation.js #1093

Merged
merged 43 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2019622
Add wasm code
May 29, 2019
1ea2d20
Merge remote-tracking branch 'upstream/main' into wasm
May 29, 2019
f7f8f3a
First working model
May 31, 2019
2f4066f
Add PixelManipulation web assembly code to browser and node
Jun 3, 2019
6a60840
Tests corrected for modules
Jun 3, 2019
f6a4104
Corrected test script
Jun 5, 2019
8c22f33
Resolve merge conflicts
Jun 5, 2019
b640aaf
Add wasm bechmarks
Jun 11, 2019
7f2fadb
Resolve merge conflicts
Jun 11, 2019
d78c587
Update Readme
Jun 11, 2019
c41bb33
Merge branch 'main' into wasm
jywarren Jun 13, 2019
9da895f
Applies toggling functionality and refactored PixelManipulation code
Jun 13, 2019
afc42c5
Merge remote-tracking branch 'upstream/main' into wasm
Jun 13, 2019
15c495e
Merge remote-tracking branch 'origin/wasm' into wasm
Jun 13, 2019
0ea5419
Added documentation and corrected wasm toggling
Jun 13, 2019
6b21435
Merge remote-tracking branch 'upstream/main' into wasm
Jun 13, 2019
c129de1
change noise reduction module to use wasm code
Jun 13, 2019
adca670
Corrected formatting and removed extra comments
Jun 14, 2019
5b8b365
Merge branch 'main' into wasm
Divy123 Jun 14, 2019
5c7c2ba
Add default wasm option and made README changes
Jun 15, 2019
4ae1d4a
Resolve merge conflicts
Jun 15, 2019
a3821c0
Merge remote-tracking branch 'upstream/main' into wasm
Jun 15, 2019
320dcb3
Merge remote-tracking branch 'origin/wasm' into wasm
Jun 15, 2019
371b11d
Merge branch 'main' into wasm
Divy123 Jun 15, 2019
133673a
Fixed negative test timings
Jun 15, 2019
466ecf8
Merge remote-tracking branch 'origin/wasm' into wasm
Jun 15, 2019
8e2c1dc
combined benchmarks file
jywarren Jun 17, 2019
4419730
Merge branch 'main' into wasm
jywarren Jun 17, 2019
cf91655
Update benchmark.js
jywarren Jun 17, 2019
1e9f741
Resolve merge conflicts
Jun 17, 2019
5c19488
Removed copies of wasm file and corrected test format
Jun 17, 2019
c89bfe4
Merge branch 'main' into wasm
jywarren Jun 18, 2019
317c2ae
Resolve merge conflicts
Jun 18, 2019
bafdfcb
Update package.json
Divy123 Jun 18, 2019
e45da7d
Added wasm file and removed redundant code
Jun 18, 2019
11f24a5
Removed earlier benchmarks
Jun 18, 2019
4aefec1
move test/core/sequencer/benchmark.js to its own test command, not pa…
jywarren Jun 19, 2019
0358835
Solves memory leaks and blank lines
Jun 20, 2019
32ec906
Solves memory leaks and blank lines
Jun 20, 2019
1e4ba0d
Added handler for node code
Jun 20, 2019
1e1ac72
Modify test script
Jun 20, 2019
14ea03f
Modify test script
Jun 20, 2019
6f4fc3b
Correct doc and removed pace fuctionality
Jun 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "src/ImageSequencer.js",
"scripts": {
"debug": "TEST=true node ./index.js -i ./examples/images/monarch.png -s invert",
"test": "TEST=true istanbul cover tape test/core/*.js test/core/ui/user-interface.js test/core/modules/*.js | tap-spec; node test/core/sequencer/benchmark.js; node test/core/sequencer/meta-modules.js; browserify test/core/sequencer/image-sequencer.js test/core/sequencer/chain.js test/core/sequencer/replace.js test/core/sequencer/import-export.js test/core/sequencer/run.js test/core/sequencer/dynamic-imports.js test/core/util/*.js | tape-run --render=\"tap-spec\"",
"test": "TEST=true istanbul cover tape test/core/*.js test/core/ui/user-interface.js test/core/modules/*.js | tap-spec; node test/core/sequencer/benchmark.js; browserify test/core/sequencer/meta-modules.js test/core/sequencer/image-sequencer.js test/core/sequencer/chain.js test/core/sequencer/replace.js test/core/sequencer/import-export.js test/core/sequencer/run.js test/core/sequencer/dynamic-imports.js test/core/util/*.js | tape-run --render=\"tap-spec\"",
"test-ui": "node node_modules/jasmine/bin/jasmine test/spec/*.js",
"setup": "npm i && npm i -g grunt grunt-cli && grunt build",
"start": "grunt serve"
Expand Down
30 changes: 19 additions & 11 deletions src/modules/_nomodule/PixelManipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ module.exports = function PixelManipulation(image, options) {
// https://github.com/p-v-o-s/infragram-js/blob/master/public/infragram.js#L173-L181



if (!options.inBrowser && !process.env.TEST && options.ui) {
try {
var pace = require('pace')(pixels.shape[0] * pixels.shape[1]);
} catch (e) {
options.inBrowser = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a good assumption? If our error is TypeError: fs.readFileSync is not a function shouldn't we try to work around it by disabling ui as @tech4GT suggested?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disbling ui is not actually working here.

}
}
if (options.preProcess) pixels = options.preProcess(pixels); // Allow for preprocessing

function extraOperation() {
Expand Down Expand Up @@ -113,25 +119,27 @@ module.exports = function PixelManipulation(image, options) {
).then(bytes =>
WebAssembly.instantiate(bytes, imports)
).then(results => {
console.log('yes');
results.instance.exports.manipulatePixel(pixels.shape[0], pixels.shape[1], inBrowser, test);
extraOperation();
}).catch(err => {
perPixelManipulation();
Divy123 marked this conversation as resolved.
Show resolved Hide resolved
extraOperation();
});
} else {
const fs = require('fs');
const path = require('path');
const wasmPath = path.join(__dirname, '../../../', 'dist', 'manipulation.wasm');
const buf = fs.readFileSync(wasmPath);
WebAssembly.instantiate(buf, imports).then(results => {
results.instance.exports.manipulatePixel(pixels.shape[0], pixels.shape[1], inBrowser, test);
extraOperation();
}).catch(err => {
try{
const fs = require('fs');
const path = require('path');
const wasmPath = path.join(__dirname, '../../../', 'dist', 'manipulation.wasm');
const buf = fs.readFileSync(wasmPath);
WebAssembly.instantiate(buf, imports).then(results => {
results.instance.exports.manipulatePixel(pixels.shape[0], pixels.shape[1], inBrowser, test);
extraOperation();
});
}
catch(err){
perPixelManipulation();
extraOperation();
});
}
}
} else {
perPixelManipulation();
Expand Down