From 2019622e8d4719bd56b08704c52f3d0e31f1c136 Mon Sep 17 00:00:00 2001 From: Divy123 Date: Thu, 30 May 2019 01:44:51 +0530 Subject: [PATCH 01/26] Add wasm code --- package-lock.json | 20 +++--- src/modules/_nomodule/PixelManipulation.js | 73 +++++++++++++-------- src/modules/_nomodule/program.wasm | Bin 0 -> 518 bytes 3 files changed, 55 insertions(+), 38 deletions(-) create mode 100644 src/modules/_nomodule/program.wasm diff --git a/package-lock.json b/package-lock.json index 804b8cb6d9..1e1784bc91 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "image-sequencer", - "version": "3.3.2", + "version": "3.3.4", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -940,7 +940,7 @@ }, "minimist": { "version": "0.0.5", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.5.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.5.tgz", "integrity": "sha1-16oye87PUY+RBqxrjwA/o7zqhWY=", "dev": true }, @@ -4258,7 +4258,7 @@ }, "gif-encoder": { "version": "0.4.3", - "resolved": "http://registry.npmjs.org/gif-encoder/-/gif-encoder-0.4.3.tgz", + "resolved": "https://registry.npmjs.org/gif-encoder/-/gif-encoder-0.4.3.tgz", "integrity": "sha1-iitP6MqJWkjjoLbLs0CgpqNXGJk=", "requires": { "readable-stream": "~1.1.9" @@ -5177,7 +5177,7 @@ }, "minimist": { "version": "0.0.10", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", "dev": true }, @@ -5242,7 +5242,7 @@ "dependencies": { "minimist": { "version": "0.0.10", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", "dev": true }, @@ -6698,7 +6698,7 @@ }, "magic-string": { "version": "0.22.5", - "resolved": "http://registry.npmjs.org/magic-string/-/magic-string-0.22.5.tgz", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.22.5.tgz", "integrity": "sha512-oreip9rJZkzvA8Qzk9HFs8fZGF/u7H/gtrE8EN6RjKJ9kh2HlC+yQ2QezifqTZfGyiuAV0dRv5a+y/8gBb1m9w==", "requires": { "vlq": "^0.2.2" @@ -6991,7 +6991,7 @@ }, "minimist": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" }, "mitt": { @@ -7031,7 +7031,7 @@ "dependencies": { "minimist": { "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" } } @@ -7455,7 +7455,7 @@ "dependencies": { "minimist": { "version": "0.0.10", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=" } } @@ -8811,7 +8811,7 @@ }, "sax": { "version": "0.1.5", - "resolved": "http://registry.npmjs.org/sax/-/sax-0.1.5.tgz", + "resolved": "https://registry.npmjs.org/sax/-/sax-0.1.5.tgz", "integrity": "sha1-0YKaYSD6AWZetNv/bEPyn9bWFHE=", "dev": true }, diff --git a/src/modules/_nomodule/PixelManipulation.js b/src/modules/_nomodule/PixelManipulation.js index f272c422fd..cd9ef7dac8 100644 --- a/src/modules/_nomodule/PixelManipulation.js +++ b/src/modules/_nomodule/PixelManipulation.js @@ -1,7 +1,7 @@ /* -* General purpose per-pixel manipulation -* accepting a changePixel() method to remix a pixel's channels -*/ + * General purpose per-pixel manipulation + * accepting a changePixel() method to remix a pixel's channels + */ module.exports = function PixelManipulation(image, options) { // To handle the case where pixelmanipulation is called on the input object itself @@ -16,7 +16,7 @@ module.exports = function PixelManipulation(image, options) { const getPixels = require('get-pixels'), savePixels = require('save-pixels'); - getPixels(image.src, function(err, pixels) { + getPixels(image.src, function (err, pixels) { if (err) { console.log('Bad image path', image); return; @@ -47,25 +47,41 @@ module.exports = function PixelManipulation(image, options) { /* Allows for Flexibility if per pixel manipulation is not required */ - for (var x = 0; x < pixels.shape[0]; x++) { - for (var y = 0; y < pixels.shape[1]; y++) { - let pixel = options.changePixel( - pixels.get(x, y, 0), - pixels.get(x, y, 1), - pixels.get(x, y, 2), - pixels.get(x, y, 3), - x, - y - ); - - pixels.set(x, y, 0, pixel[0]); - pixels.set(x, y, 1, pixel[1]); - pixels.set(x, y, 2, pixel[2]); - pixels.set(x, y, 3, pixel[3]); - - if (!options.inBrowser && !process.env.TEST) pace.op(); + const imports = { + env:{ + changePixel:options.changePixel, + getPixels: pixels.get, + setPixels: pixels.set, + paceOp: require('pace').op, + consoleLog:console.log } - } + }; + const inBrowser = (options.inBrowser)?1:0; + const test = (process.env.TEST)?1:0; + WebAssembly.instantiateStreaming(fetch('./program.wasm'), imports) + .then(wasm => { + wasm.instance.exports.manipulatePixel(pixels.shape[0],pixels.shape[1],inBrowser, test); + }); + + // for (var x = 0; x < pixels.shape[0]; x++) { + // for (var y = 0; y < pixels.shape[1]; y++) { + // let pixel = options.changePixel( + // pixels.get(x, y, 0), + // pixels.get(x, y, 1), + // pixels.get(x, y, 2), + // pixels.get(x, y, 3), + // x, + // y + // ); + + // pixels.set(x, y, 0, pixel[0]); + // pixels.set(x, y, 1, pixel[1]); + // pixels.set(x, y, 2, pixel[2]); + // pixels.set(x, y, 3, pixel[3]); + + // if (!options.inBrowser && !process.env.TEST) pace.op(); + // } + // } } // perform any extra operations on the entire array: var res; @@ -76,14 +92,16 @@ module.exports = function PixelManipulation(image, options) { var chunks = []; var totalLength = 0; - var r = savePixels(pixels, options.format, { quality: 100 }); + var r = savePixels(pixels, options.format, { + quality: 100 + }); - r.on('data', function(chunk) { + r.on('data', function (chunk) { totalLength += chunk.length; chunks.push(chunk); }); - r.on('end', function() { + r.on('end', function () { var data = Buffer.concat(chunks, totalLength).toString('base64'); var datauri = 'data:image/' + options.format + ';base64,' + data; if (options.output) @@ -94,7 +112,6 @@ module.exports = function PixelManipulation(image, options) { if (res) { pixels = res; generateOutput(); - } - else if (!options.extraManipulation) generateOutput(); + } else if (!options.extraManipulation) generateOutput(); }); -}; +}; \ No newline at end of file diff --git a/src/modules/_nomodule/program.wasm b/src/modules/_nomodule/program.wasm new file mode 100644 index 0000000000000000000000000000000000000000..0b87360ea15a899f8ff301c4c323afd4527b82c8 GIT binary patch literal 518 zcmchRO-{ow5QX2&I05QLWX;Oyieoej1PdfMLZiqkMfp=x5Uf&uj==$7#aXxm2f=n) z#0l_X-uvc_#)G1-2>`usw_C&u8nB3m@Mu_wGftFer@&~zUw%3g+uZB&rf8P-di7u{ zknc>&w&~l-UbaiXH;$He6Y?JHIqr(mUUg6*?0-X%XTO#r^%}GTqL<)6@sl?=c=N(> zZR>XZ$T+TxX4TzQ#b$RwH2HK(Kp&yXkbfg3o*U$Jk-&)Ib*2nC%Ay<@%iM)g0$0^p z0@o6m8#a<-tSJYjo$^j))D*M$l#!~FamqMSdty(AdlFAmPvo}K?M%)SOj+yy_%oHi PziMsRU%&?L2CelEn#Em? literal 0 HcmV?d00001 From f7f8f3a98c06a8fe3add6061ddabf5f5f49e1903 Mon Sep 17 00:00:00 2001 From: Divy123 Date: Fri, 31 May 2019 11:26:22 +0530 Subject: [PATCH 02/26] First working model --- examples/program.wasm | Bin 0 -> 223 bytes src/modules/_nomodule/PixelManipulation.js | 22 ++++++++++++++++----- src/modules/_nomodule/program.wasm | Bin 518 -> 223 bytes 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 examples/program.wasm diff --git a/examples/program.wasm b/examples/program.wasm new file mode 100644 index 0000000000000000000000000000000000000000..a31f06275e2a8244fd117d7bd6e01f443594bc75 GIT binary patch literal 223 zcmW-YF>ZrE5JmsY?ivY%%n>F&2~I5hPYzLF`;0eTp0>O64P&-6`Jt z^EHEJas+_Bmt}#fX-3WS3O%m_{tY!N+n>^-?;oW6+Pw`usw_C&u8nB3m@Mu_wGftFer@&~zUw%3g+uZB&rf8P-di7u{ zknc>&w&~l-UbaiXH;$He6Y?JHIqr(mUUg6*?0-X%XTO#r^%}GTqL<)6@sl?=c=N(> zZR>XZ$T+TxX4TzQ#b$RwH2HK(Kp&yXkbfg3o*U$Jk-&)Ib*2nC%Ay<@%iM)g0$0^p z0@o6m8#a<-tSJYjo$^j))D*M$l#!~FamqMSdty(AdlFAmPvo}K?M%)SOj+yy_%oHi PziMsRU%&?L2CelEn#Em? From 2f4066ff60db870dbaa6f1c7b9cdae0df5609d4e Mon Sep 17 00:00:00 2001 From: Divy123 Date: Tue, 4 Jun 2019 00:33:13 +0530 Subject: [PATCH 03/26] Add PixelManipulation web assembly code to browser and node --- examples/manipulation.wasm | Bin 0 -> 200 bytes examples/program.wasm | Bin 223 -> 0 bytes package-lock.json | 13 +- src/modules/_nomodule/PixelManipulation.js | 140 ++++++++++++--------- src/modules/_nomodule/manipulation.wasm | Bin 0 -> 200 bytes src/modules/_nomodule/program.wasm | Bin 223 -> 0 bytes 6 files changed, 90 insertions(+), 63 deletions(-) create mode 100644 examples/manipulation.wasm delete mode 100644 examples/program.wasm create mode 100644 src/modules/_nomodule/manipulation.wasm delete mode 100644 src/modules/_nomodule/program.wasm diff --git a/examples/manipulation.wasm b/examples/manipulation.wasm new file mode 100644 index 0000000000000000000000000000000000000000..6b04a7cf4f62c0c5bd7576ac81062d1c9266bc28 GIT binary patch literal 200 zcmW-YOAdlC6h-fAOGzX|m+)XEFw&t*fI&?#6bOEzqvB_3+<*&mOm1o5W GU-Ad7J}oQ& literal 0 HcmV?d00001 diff --git a/examples/program.wasm b/examples/program.wasm deleted file mode 100644 index a31f06275e2a8244fd117d7bd6e01f443594bc75..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 223 zcmW-YF>ZrE5JmsY?ivY%%n>F&2~I5hPYzLF`;0eTp0>O64P&-6`Jt z^EHEJas+_Bmt}#fX-3WS3O%m_{tY!N+n>^-?;oW6+Pw { - wasm.instance.exports.manipulatePixel(pixels.shape[0],pixels.shape[1],inBrowser, test); - }); - // for (var x = 0; x < pixels.shape[0]; x++) { - // for (var y = 0; y < pixels.shape[1]; y++) { - // let pixel = options.changePixel( - // pixels.get(x, y, 0), - // pixels.get(x, y, 1), - // pixels.get(x, y, 2), - // pixels.get(x, y, 3), - // x, - // y - // ); - - // pixels.set(x, y, 0, pixel[0]); - // pixels.set(x, y, 1, pixel[1]); - // pixels.set(x, y, 2, pixel[2]); - // pixels.set(x, y, 3, pixel[3]); - - // if (!options.inBrowser && !process.env.TEST) pace.op(); - // } - // } - } - // perform any extra operations on the entire array: - var res; - if (options.extraManipulation) res = options.extraManipulation(pixels, generateOutput); - // there may be a more efficient means to encode an image object, - // but node modules and their documentation are essentially arcane on this point - function generateOutput() { - var chunks = []; - var totalLength = 0; - - var r = savePixels(pixels, options.format, { - quality: 100 - }); - - r.on('data', function (chunk) { - totalLength += chunk.length; - chunks.push(chunk); - }); - - r.on('end', function () { - var data = Buffer.concat(chunks, totalLength).toString('base64'); - var datauri = 'data:image/' + options.format + ';base64,' + data; - if (options.output) - options.output(options.image, datauri, options.format); - if (options.callback) options.callback(); - }); + if (options.inBrowser) { + const inBrowser = (options.inBrowser) ? 1 : 0; + const test = (process.env.TEST) ? 1 : 0; + fetch('./manipulation.wasm').then(response => + response.arrayBuffer() + ).then(bytes => + WebAssembly.instantiate(bytes, imports) + ).then(results => { + results.instance.exports.manipulatePixel(pixels.shape[0], pixels.shape[1], inBrowser, test); + extraOperation(); + }).catch(err => { + + for (var x = 0; x < pixels.shape[0]; x++) { + for (var y = 0; y < pixels.shape[1]; y++) { + let pixel = options.changePixel( + pixels.get(x, y, 0), + pixels.get(x, y, 1), + pixels.get(x, y, 2), + pixels.get(x, y, 3), + x, + y + ); + + pixels.set(x, y, 0, pixel[0]); + pixels.set(x, y, 1, pixel[1]); + pixels.set(x, y, 2, pixel[2]); + pixels.set(x, y, 3, pixel[3]); + + } + } + extraOperation(); + // console.log(err) + }); + } else { + const fs = require('fs'); + const buf = fs.readFileSync('./manipulation.wasm'); + WebAssembly.instantiate(buf, imports).then(results => { + results.instance.exports.manipulatePixel(pixels.shape[0], pixels.shape[1], inBrowser, test); + extraOperation(); + }).catch(err => { + console.log(err); + }); + } } - if (res) { - pixels = res; - generateOutput(); - } else if (!options.extraManipulation) generateOutput(); }); }; \ No newline at end of file diff --git a/src/modules/_nomodule/manipulation.wasm b/src/modules/_nomodule/manipulation.wasm new file mode 100644 index 0000000000000000000000000000000000000000..6b04a7cf4f62c0c5bd7576ac81062d1c9266bc28 GIT binary patch literal 200 zcmW-YOAdlC6h-fAOGzX|m+)XEFw&t*fI&?#6bOEzqvB_3+<*&mOm1o5W GU-Ad7J}oQ& literal 0 HcmV?d00001 diff --git a/src/modules/_nomodule/program.wasm b/src/modules/_nomodule/program.wasm deleted file mode 100644 index a31f06275e2a8244fd117d7bd6e01f443594bc75..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 223 zcmW-YF>ZrE5JmsY?ivY%%n>F&2~I5hPYzLF`;0eTp0>O64P&-6`Jt z^EHEJas+_Bmt}#fX-3WS3O%m_{tY!N+n>^-?;oW6+Pw Date: Tue, 4 Jun 2019 02:45:14 +0530 Subject: [PATCH 04/26] Tests corrected for modules --- manipulation.wasm | Bin 0 -> 200 bytes package.json | 2 +- src/modules/_nomodule/PixelManipulation.js | 6 ++++-- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 manipulation.wasm diff --git a/manipulation.wasm b/manipulation.wasm new file mode 100644 index 0000000000000000000000000000000000000000..6b04a7cf4f62c0c5bd7576ac81062d1c9266bc28 GIT binary patch literal 200 zcmW-YOAdlC6h-fAOGzX|m+)XEFw&t*fI&?#6bOEzqvB_3+<*&mOm1o5W GU-Ad7J}oQ& literal 0 HcmV?d00001 diff --git a/package.json b/package.json index 7906899195..29e208a8e1 100644 --- a/package.json +++ b/package.json @@ -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; browserify test/core/sequencer/image-sequencer.js test/core/sequencer/chain.js test/core/sequencer/meta-modules.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 test/core/sequencer/benchmark.js | tape-run --render=\"tap-spec\"", + "test": "TEST=true istanbul cover tape test/core/modules/*.js test/core/*.js test/core/ui/user-interface.js test/core/modules/*.js | tap-spec; browserify test/core/sequencer/image-sequencer.js test/core/sequencer/chain.js test/core/sequencer/meta-modules.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 test/core/sequencer/benchmark.js | tape-run --render=\"tap-spec\"", "test-ui": "jasmine test/spec/*.js", "setup": "npm i && npm i -g grunt grunt-cli && grunt build", "start": "grunt serve" diff --git a/src/modules/_nomodule/PixelManipulation.js b/src/modules/_nomodule/PixelManipulation.js index cccfcdbc5a..032d563b4c 100644 --- a/src/modules/_nomodule/PixelManipulation.js +++ b/src/modules/_nomodule/PixelManipulation.js @@ -103,9 +103,11 @@ module.exports = function PixelManipulation(image, options) { } }; + const inBrowser = (options.inBrowser) ? 1 : 0; + const test = (process.env.TEST) ? 1 : 0; + if (options.inBrowser) { - const inBrowser = (options.inBrowser) ? 1 : 0; - const test = (process.env.TEST) ? 1 : 0; + fetch('./manipulation.wasm').then(response => response.arrayBuffer() ).then(bytes => From f6a4104a500361a9313097429602d79170d8832f Mon Sep 17 00:00:00 2001 From: Divy123 Date: Wed, 5 Jun 2019 21:50:49 +0530 Subject: [PATCH 05/26] Corrected test script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 29e208a8e1..b43665f02d 100644 --- a/package.json +++ b/package.json @@ -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/modules/*.js test/core/*.js test/core/ui/user-interface.js test/core/modules/*.js | tap-spec; browserify test/core/sequencer/image-sequencer.js test/core/sequencer/chain.js test/core/sequencer/meta-modules.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 test/core/sequencer/benchmark.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; browserify test/core/sequencer/image-sequencer.js test/core/sequencer/chain.js test/core/sequencer/meta-modules.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 test/core/sequencer/benchmark.js | tape-run --render=\"tap-spec\"", "test-ui": "jasmine test/spec/*.js", "setup": "npm i && npm i -g grunt grunt-cli && grunt build", "start": "grunt serve" From b640aaf41f448c884b39677f1d6bb9cf464b9d49 Mon Sep 17 00:00:00 2001 From: Divy123 Date: Tue, 11 Jun 2019 19:18:42 +0530 Subject: [PATCH 06/26] Add wasm bechmarks --- package.json | 2 +- test/core/modules1/add-qr.js | 4 +++ test/core/modules1/average.js | 3 +++ test/core/modules1/blend.js | 21 +++++++++++++++ test/core/modules1/blur.js | 4 +++ test/core/modules1/brightness.js | 3 +++ test/core/modules1/canvas-resize.js | 34 ++++++++++++++++++++++++ test/core/modules1/channel.js | 3 +++ test/core/modules1/color-temperature.js | 6 +++++ test/core/modules1/colorbar.js | 10 +++++++ test/core/modules1/colormap.js | 5 ++++ test/core/modules1/contrast.js | 3 +++ test/core/modules1/convolution.js | 9 +++++++ test/core/modules1/crop.js | 10 +++++++ test/core/modules1/decode-qr.js | 24 +++++++++++++++++ test/core/modules1/dither.js | 3 +++ test/core/modules1/draw-rectangle.js | 11 ++++++++ test/core/modules1/dynamic.js | 9 +++++++ test/core/modules1/edge-detect.js | 9 +++++++ test/core/modules1/exposure.js | 7 +++++ test/core/modules1/flip-image.js | 8 ++++++ test/core/modules1/gamma-correction.js | 6 +++++ test/core/modules1/gradient.js | 3 +++ test/core/modules1/grid-overlay.js | 2 ++ test/core/modules1/histogram.js | 2 ++ test/core/modules1/manipulation.wasm | Bin 0 -> 200 bytes test/core/modules1/ndvi-colormap.js | 4 +++ test/core/modules1/ndvi.js | 7 +++++ test/core/modules1/overlay.js | 22 +++++++++++++++ test/core/modules1/paint-bucket.js | 10 +++++++ test/core/modules1/replace-color.js | 7 +++++ test/core/modules1/resize.js | 2 ++ test/core/modules1/rotate.js | 2 ++ test/core/modules1/saturation.js | 5 ++++ test/core/modules1/threshold.js | 3 +++ test/core/modules1/tint.js | 7 +++++ test/core/modules1/white-balance.js | 3 +++ test/core/templates/module-test.1.js | 32 ++++++++++++++++++++++ test/core/templates/module-test.js | 1 - 39 files changed, 304 insertions(+), 2 deletions(-) create mode 100644 test/core/modules1/add-qr.js create mode 100644 test/core/modules1/average.js create mode 100644 test/core/modules1/blend.js create mode 100644 test/core/modules1/blur.js create mode 100644 test/core/modules1/brightness.js create mode 100644 test/core/modules1/canvas-resize.js create mode 100644 test/core/modules1/channel.js create mode 100644 test/core/modules1/color-temperature.js create mode 100644 test/core/modules1/colorbar.js create mode 100644 test/core/modules1/colormap.js create mode 100644 test/core/modules1/contrast.js create mode 100644 test/core/modules1/convolution.js create mode 100644 test/core/modules1/crop.js create mode 100644 test/core/modules1/decode-qr.js create mode 100644 test/core/modules1/dither.js create mode 100644 test/core/modules1/draw-rectangle.js create mode 100644 test/core/modules1/dynamic.js create mode 100644 test/core/modules1/edge-detect.js create mode 100644 test/core/modules1/exposure.js create mode 100644 test/core/modules1/flip-image.js create mode 100644 test/core/modules1/gamma-correction.js create mode 100644 test/core/modules1/gradient.js create mode 100644 test/core/modules1/grid-overlay.js create mode 100644 test/core/modules1/histogram.js create mode 100644 test/core/modules1/manipulation.wasm create mode 100644 test/core/modules1/ndvi-colormap.js create mode 100644 test/core/modules1/ndvi.js create mode 100644 test/core/modules1/overlay.js create mode 100644 test/core/modules1/paint-bucket.js create mode 100644 test/core/modules1/replace-color.js create mode 100644 test/core/modules1/resize.js create mode 100644 test/core/modules1/rotate.js create mode 100644 test/core/modules1/saturation.js create mode 100644 test/core/modules1/threshold.js create mode 100644 test/core/modules1/tint.js create mode 100644 test/core/modules1/white-balance.js create mode 100644 test/core/templates/module-test.1.js diff --git a/package.json b/package.json index b43665f02d..4f8c282681 100644 --- a/package.json +++ b/package.json @@ -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; browserify test/core/sequencer/image-sequencer.js test/core/sequencer/chain.js test/core/sequencer/meta-modules.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 test/core/sequencer/benchmark.js | tape-run --render=\"tap-spec\"", + "test": "TEST=true istanbul cover tape test/core/modules1/*.js test/core/*.js test/core/ui/user-interface.js test/core/modules/*.js | tap-spec; browserify test/core/sequencer/image-sequencer.js test/core/sequencer/chain.js test/core/sequencer/meta-modules.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 test/core/sequencer/benchmark.js | tape-run --render=\"tap-spec\"", "test-ui": "jasmine test/spec/*.js", "setup": "npm i && npm i -g grunt grunt-cli && grunt build", "start": "grunt serve" diff --git a/test/core/modules1/add-qr.js b/test/core/modules1/add-qr.js new file mode 100644 index 0000000000..750e45c8c8 --- /dev/null +++ b/test/core/modules1/add-qr.js @@ -0,0 +1,4 @@ +const testModule = require('../templates/module-test.1'), + options = {size:200, qrCodeString:'https://github.com/publiclab/image-sequencer'}; +console.log('############ WASM Benchmarks ############'); +testModule('add-qr', options); \ No newline at end of file diff --git a/test/core/modules1/average.js b/test/core/modules1/average.js new file mode 100644 index 0000000000..c62c947857 --- /dev/null +++ b/test/core/modules1/average.js @@ -0,0 +1,3 @@ +const testModule = require('../templates/module-test.1'), + ISQR = require('../images/IS-QR'); +testModule('average', {}, ISQR); \ No newline at end of file diff --git a/test/core/modules1/blend.js b/test/core/modules1/blend.js new file mode 100644 index 0000000000..ecd8b293b4 --- /dev/null +++ b/test/core/modules1/blend.js @@ -0,0 +1,21 @@ +const test = require('tape'), + ImageSequencer = require('../../../src/ImageSequencer'), + image = require('../images/IS-QR'), + options = { + offset: -1 + }; + +let sequencer = ImageSequencer({ui: false}); +sequencer.loadImages(image); +sequencer.addSteps('brightness', {}); +sequencer.addSteps('blend', options); + +test('blend module', t => { + var startTime = new Date().getMilliseconds(); + sequencer.run({mode: 'test'}, () => { + var endTime = new Date().getMilliseconds(); + console.log(`blend module ran in ${(endTime - startTime)} milliseconds`); + sequencer = null; + t.end(); + }); +}); \ No newline at end of file diff --git a/test/core/modules1/blur.js b/test/core/modules1/blur.js new file mode 100644 index 0000000000..e96a3ac5f7 --- /dev/null +++ b/test/core/modules1/blur.js @@ -0,0 +1,4 @@ +const moduleTest = require('../templates/module-test.1'); + +moduleTest('blur', {blur: 3.25}); + diff --git a/test/core/modules1/brightness.js b/test/core/modules1/brightness.js new file mode 100644 index 0000000000..761a79f74c --- /dev/null +++ b/test/core/modules1/brightness.js @@ -0,0 +1,3 @@ +const testModule = require('../templates/module-test.1'); + +testModule('brightness', {brightness: 1}); \ No newline at end of file diff --git a/test/core/modules1/canvas-resize.js b/test/core/modules1/canvas-resize.js new file mode 100644 index 0000000000..3773f168b2 --- /dev/null +++ b/test/core/modules1/canvas-resize.js @@ -0,0 +1,34 @@ +var test = require('tape'); + +require('../../../src/ImageSequencer.js'); + +var sequencer = ImageSequencer({ ui: false }); +var options = { width: 500, height: 500 }; +var red = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEX+AAD///+KQee0AAAAAWJLR0QB/wIt3gAAAAd0SU1FB+EGHRIVAvrm6EMAAAAMSURBVAjXY2AgDQAAADAAAceqhY4AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMDYtMjlUMTg6MjE6MDIrMDI6MDDGD83DAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTA2LTI5VDE4OjIxOjAyKzAyOjAwt1J1fwAAAABJRU5ErkJggg=='; +sequencer.loadImages(red); +sequencer.addSteps('canvas-resize', options); + +// // Test 1 to check brightness module is getting loaded +// test('Load canvas-resize module', function(t) { + +// t.equal(sequencer.steps[1].options.name, 'canvas-resize', 'Canvas resize module is getting loaded'); +// t.end(); +// }); + +// Test 2 to check options are correct +// test('Check Options', function(t) { +// t.equal(sequencer.steps[1].options.width, 500, 'Options are correct'); +// t.equal(sequencer.steps[1].options.height, 500, 'Options are correct'); +// t.end(); +// }); + +// Test 3 to check brightness module works as expected +test('canvas-resize ', function(t) { + var startTime = new Date().getMilliseconds(); + sequencer.run({ mode: 'test' }, function(out) { + var endTime = new Date().getMilliseconds(); + console.log(`canvas-resize module ran in ${(endTime - startTime)} milliseconds`); + sequencer = null; + t.end(); + }); +}); \ No newline at end of file diff --git a/test/core/modules1/channel.js b/test/core/modules1/channel.js new file mode 100644 index 0000000000..b3b8e03c95 --- /dev/null +++ b/test/core/modules1/channel.js @@ -0,0 +1,3 @@ +const testModule = require('../templates/module-test.1'); + +testModule('channel', {channel: 'red'}); diff --git a/test/core/modules1/color-temperature.js b/test/core/modules1/color-temperature.js new file mode 100644 index 0000000000..9ae7e9dfc1 --- /dev/null +++ b/test/core/modules1/color-temperature.js @@ -0,0 +1,6 @@ +const testModule = require('../templates/module-test.1'), + options = { + temperature: 20000 + }; + +testModule('color-temperature', options); \ No newline at end of file diff --git a/test/core/modules1/colorbar.js b/test/core/modules1/colorbar.js new file mode 100644 index 0000000000..350befa50e --- /dev/null +++ b/test/core/modules1/colorbar.js @@ -0,0 +1,10 @@ +const testModule = require('../templates/module-test.1'), + image = require('../images/IS-QR'), + options = { + colormap: 'greyscale', + x: '20', + y: '30', + h: '50' + }; + +testModule('colorbar', options, image); \ No newline at end of file diff --git a/test/core/modules1/colormap.js b/test/core/modules1/colormap.js new file mode 100644 index 0000000000..2603d59e9f --- /dev/null +++ b/test/core/modules1/colormap.js @@ -0,0 +1,5 @@ +const testModule = require('../templates/module-test.1'); + +testModule('colormap', {colormap: 'blutoredjet'}); + + diff --git a/test/core/modules1/contrast.js b/test/core/modules1/contrast.js new file mode 100644 index 0000000000..754c6e10a4 --- /dev/null +++ b/test/core/modules1/contrast.js @@ -0,0 +1,3 @@ +const testModule = require('../templates/module-test.1'); + +testModule('contrast', {contrast: -40}); \ No newline at end of file diff --git a/test/core/modules1/convolution.js b/test/core/modules1/convolution.js new file mode 100644 index 0000000000..7292a44e11 --- /dev/null +++ b/test/core/modules1/convolution.js @@ -0,0 +1,9 @@ +const testModule = require('../templates/module-test.1'), + + image = require('../images/IS-QR'), + options = { + constantFactor: 0.4, + kernelValues: '1 0 1 0 1 0 1 0 1' + }; + +testModule('convolution', options, image); \ No newline at end of file diff --git a/test/core/modules1/crop.js b/test/core/modules1/crop.js new file mode 100644 index 0000000000..6b0eb8f5df --- /dev/null +++ b/test/core/modules1/crop.js @@ -0,0 +1,10 @@ +const testModule = require('../templates/module-test.1'), + image = require('../images/IS-QR'), + options = { + x: '20', + y: '15', + w: '40', + h: '45' + }; + +testModule('crop', options, image); \ No newline at end of file diff --git a/test/core/modules1/decode-qr.js b/test/core/modules1/decode-qr.js new file mode 100644 index 0000000000..0abeb4e4c3 --- /dev/null +++ b/test/core/modules1/decode-qr.js @@ -0,0 +1,24 @@ +var test = require('tape'); + +require('../../../src/ImageSequencer.js'); + +var sequencer = ImageSequencer({ + ui: false +}); + +var Qr = require('../images/IS-QR'); +sequencer.loadImages(Qr); +sequencer.addSteps('decode-qr'); + + +test('Decode-qr ', function (t) { + var startTime = new Date().getMilliseconds(); + sequencer.run({ + mode: 'test' + }, function (out) { + var endTime = new Date().getMilliseconds(); + console.log(`decode-qr module ran in ${(endTime - startTime)} milliseconds`); + sequencer = null; + t.end(); + }); +}); \ No newline at end of file diff --git a/test/core/modules1/dither.js b/test/core/modules1/dither.js new file mode 100644 index 0000000000..91e3a019d5 --- /dev/null +++ b/test/core/modules1/dither.js @@ -0,0 +1,3 @@ +const testModule = require('../templates/module-test.1'); + +testModule('dither', {dither: 'bayer'}); \ No newline at end of file diff --git a/test/core/modules1/draw-rectangle.js b/test/core/modules1/draw-rectangle.js new file mode 100644 index 0000000000..fcf176d8ec --- /dev/null +++ b/test/core/modules1/draw-rectangle.js @@ -0,0 +1,11 @@ +const testModule = require('../templates/module-test.1'), + image = require('../images/IS-QR'), + options = { + startingX: 2, + endX: 60, + startingY: 2, + endY: 60, + color: '0 255 0 255', + thickness: 6 + }; +testModule('draw-rectangle', options, image); \ No newline at end of file diff --git a/test/core/modules1/dynamic.js b/test/core/modules1/dynamic.js new file mode 100644 index 0000000000..2c8f12d0b8 --- /dev/null +++ b/test/core/modules1/dynamic.js @@ -0,0 +1,9 @@ +const testModule = require('../templates/module-test.1'), + image = require('../images/IS-QR'), + options = { + red: 'r * 2', + blue: 'b * 2', + green: 'g * 3' + }; + +testModule('dynamic', options, image); \ No newline at end of file diff --git a/test/core/modules1/edge-detect.js b/test/core/modules1/edge-detect.js new file mode 100644 index 0000000000..4f865ba497 --- /dev/null +++ b/test/core/modules1/edge-detect.js @@ -0,0 +1,9 @@ +const testModule = require('../templates/module-test.1'); +image = require('../images/IS-QR'), +options = { + blur: 1.8, + highThresholdRatio: 0.18, + lowThresholdRatio: 0.16 +}; + +testModule('edge-detect', options, image); \ No newline at end of file diff --git a/test/core/modules1/exposure.js b/test/core/modules1/exposure.js new file mode 100644 index 0000000000..fc5062df10 --- /dev/null +++ b/test/core/modules1/exposure.js @@ -0,0 +1,7 @@ +const testModule = require('../templates/module-test.1'), + image = require('../images/IS-QR'), + options = { + exposure: 3 + }; + +testModule('exposure', options, image); \ No newline at end of file diff --git a/test/core/modules1/flip-image.js b/test/core/modules1/flip-image.js new file mode 100644 index 0000000000..9391694642 --- /dev/null +++ b/test/core/modules1/flip-image.js @@ -0,0 +1,8 @@ +const testModule = require('../templates/module-test.1'), + image = require('../images/IS-QR'), + + options = { + Axis: 'horizontal' + }; + +testModule('flip-image', options, image); \ No newline at end of file diff --git a/test/core/modules1/gamma-correction.js b/test/core/modules1/gamma-correction.js new file mode 100644 index 0000000000..238ac283c4 --- /dev/null +++ b/test/core/modules1/gamma-correction.js @@ -0,0 +1,6 @@ +const testModule = require('../templates/module-test.1'), + image = require('../images/IS-QR'), + options = { + adjustment: 0.6 + }; +testModule('gamma-correction', options, image); \ No newline at end of file diff --git a/test/core/modules1/gradient.js b/test/core/modules1/gradient.js new file mode 100644 index 0000000000..e817fbc93e --- /dev/null +++ b/test/core/modules1/gradient.js @@ -0,0 +1,3 @@ +const testModule = require('../templates/module-test.1'); + +testModule('gradient', {}); \ No newline at end of file diff --git a/test/core/modules1/grid-overlay.js b/test/core/modules1/grid-overlay.js new file mode 100644 index 0000000000..5540c7a2ba --- /dev/null +++ b/test/core/modules1/grid-overlay.js @@ -0,0 +1,2 @@ +const testModule = require('../templates/module-test.1'); +testModule('grid-overlay', {x: 1}); \ No newline at end of file diff --git a/test/core/modules1/histogram.js b/test/core/modules1/histogram.js new file mode 100644 index 0000000000..de0d449bb6 --- /dev/null +++ b/test/core/modules1/histogram.js @@ -0,0 +1,2 @@ +const testModule = require('../templates/module-test.1'); +testModule('histogram', {}); \ No newline at end of file diff --git a/test/core/modules1/manipulation.wasm b/test/core/modules1/manipulation.wasm new file mode 100644 index 0000000000000000000000000000000000000000..6b04a7cf4f62c0c5bd7576ac81062d1c9266bc28 GIT binary patch literal 200 zcmW-YOAdlC6h-fAOGzX|m+)XEFw&t*fI&?#6bOEzqvB_3+<*&mOm1o5W GU-Ad7J}oQ& literal 0 HcmV?d00001 diff --git a/test/core/modules1/ndvi-colormap.js b/test/core/modules1/ndvi-colormap.js new file mode 100644 index 0000000000..d81f352faa --- /dev/null +++ b/test/core/modules1/ndvi-colormap.js @@ -0,0 +1,4 @@ +const testModule = require('../templates/module-test.1'), + image = require('../images/IS-QR'); + +testModule('ndvi-colormap', {}, image); \ No newline at end of file diff --git a/test/core/modules1/ndvi.js b/test/core/modules1/ndvi.js new file mode 100644 index 0000000000..a53198b92d --- /dev/null +++ b/test/core/modules1/ndvi.js @@ -0,0 +1,7 @@ +const testModule = require('../templates/module-test.1'); +image = require('../images/IS-QR'), +options = { + filter: 'blue' +}; + +testModule('ndvi', options, image); \ No newline at end of file diff --git a/test/core/modules1/overlay.js b/test/core/modules1/overlay.js new file mode 100644 index 0000000000..76c0cc3aa0 --- /dev/null +++ b/test/core/modules1/overlay.js @@ -0,0 +1,22 @@ +const test = require('tape'), + ImageSequencer = require('../../../src/ImageSequencer'), + image = require('../images/IS-QR'), + options = { + offset: -1 + }; + +let sequencer = ImageSequencer({ui: false}); +sequencer.loadImages(image); +sequencer.addSteps('colorbar', {}); +sequencer.addSteps('overlay', options); + + +test('overlay module', t => { + var startTime = new Date().getMilliseconds(); + sequencer.run({mode: 'test'}, () => { + var endTime = new Date().getMilliseconds(); + console.log(`overlay module ran in ${(endTime - startTime)} milliseconds`); + sequencer = null; + t.end(); + }); +}); \ No newline at end of file diff --git a/test/core/modules1/paint-bucket.js b/test/core/modules1/paint-bucket.js new file mode 100644 index 0000000000..d92649a97f --- /dev/null +++ b/test/core/modules1/paint-bucket.js @@ -0,0 +1,10 @@ +const testModule = require('../templates/module-test.1'), + image = require('../images/IS-QR'), + options = { + startingX: 15, + startingY: 20, + fillColor: '80 180 80 255', + tolerance: 20 + }; + +testModule('paint-bucket', options, image); \ No newline at end of file diff --git a/test/core/modules1/replace-color.js b/test/core/modules1/replace-color.js new file mode 100644 index 0000000000..5c4349ee47 --- /dev/null +++ b/test/core/modules1/replace-color.js @@ -0,0 +1,7 @@ +const testModule = require('../templates/module-test.1'), + options = { + 'replaceMethod': 'greyscale', + 'color': '255 0 0', + 'tolerance': '50' + }; +testModule('replace-color', options); \ No newline at end of file diff --git a/test/core/modules1/resize.js b/test/core/modules1/resize.js new file mode 100644 index 0000000000..208935df6f --- /dev/null +++ b/test/core/modules1/resize.js @@ -0,0 +1,2 @@ +const testModule = require('../templates/module-test.1'); +testModule('resize', {resize: '129%'}); \ No newline at end of file diff --git a/test/core/modules1/rotate.js b/test/core/modules1/rotate.js new file mode 100644 index 0000000000..261b1f1f54 --- /dev/null +++ b/test/core/modules1/rotate.js @@ -0,0 +1,2 @@ +const testModule = require('../templates/module-test.1'); +testModule('rotate', {rotate: 45}); \ No newline at end of file diff --git a/test/core/modules1/saturation.js b/test/core/modules1/saturation.js new file mode 100644 index 0000000000..b7981a96c4 --- /dev/null +++ b/test/core/modules1/saturation.js @@ -0,0 +1,5 @@ +const testModule = require('../templates/module-test.1'), options = { + saturation: 1.2 +}; + +testModule('saturation', options); \ No newline at end of file diff --git a/test/core/modules1/threshold.js b/test/core/modules1/threshold.js new file mode 100644 index 0000000000..7b110c1e86 --- /dev/null +++ b/test/core/modules1/threshold.js @@ -0,0 +1,3 @@ +const testModule = require('../templates/module-test.1'); + +testModule('threshold', {threshold: 'Automatic Thresholding'}); diff --git a/test/core/modules1/tint.js b/test/core/modules1/tint.js new file mode 100644 index 0000000000..73397d79d9 --- /dev/null +++ b/test/core/modules1/tint.js @@ -0,0 +1,7 @@ +const testModule = require('../templates/module-test.1'), + options = { + color: '30, 40, 190', + factor: 0.6 + }; + +testModule('tint', options); \ No newline at end of file diff --git a/test/core/modules1/white-balance.js b/test/core/modules1/white-balance.js new file mode 100644 index 0000000000..4bb7460c24 --- /dev/null +++ b/test/core/modules1/white-balance.js @@ -0,0 +1,3 @@ +const testModule = require('../templates/module-test.1'), + options = {red: 240, green: 240, blue: 240}; +testModule('white-balance', options); diff --git a/test/core/templates/module-test.1.js b/test/core/templates/module-test.1.js new file mode 100644 index 0000000000..00b16f76f0 --- /dev/null +++ b/test/core/templates/module-test.1.js @@ -0,0 +1,32 @@ +const test = require('tape'), + ImageSequencer = require('../../../src/ImageSequencer'); + +const red = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEX+AAD///+KQee0AAAAAWJLR0QB/wIt3gAAAAd0SU1FB+EGHRIVAvrm6EMAAAAMSURBVAjXY2AgDQAAADAAAceqhY4AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMDYtMjlUMTg6MjE6MDIrMDI6MDDGD83DAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTA2LTI5VDE4OjIxOjAyKzAyOjAwt1J1fwAAAABJRU5ErkJggg=='; + +/** + * @method moduleTest + * @description a common test for modules + * @param {String} moduleName name of the module + * @param {"Object"} options module options + * @param {String} [input="red_image"] optional input image. Default is a red image. + */ +module.exports = (moduleName, options, input) => { + let sequencer = ImageSequencer({ + ui: false + }); + sequencer.loadImages(input || red); + sequencer.addSteps(moduleName, options); + + test(`${moduleName}`,t => { + var startTime = new Date().getMilliseconds(); + sequencer.run({ + mode: 'test' + }, () => { + var endTime = new Date().getMilliseconds(); + console.log(`${moduleName} ran in ${(endTime - startTime)} milliseconds`); + sequencer = null; + t.end(); + }); + }); + +}; \ No newline at end of file diff --git a/test/core/templates/module-test.js b/test/core/templates/module-test.js index a84edc2307..befe8da13d 100644 --- a/test/core/templates/module-test.js +++ b/test/core/templates/module-test.js @@ -36,7 +36,6 @@ module.exports = (moduleName, options, benchmark, input) => { test(`${moduleName} module works correctly`, t => { sequencer.run({mode: 'test'}, () => { - let result = sequencer.steps[1].output.src; base64Img.imgSync(result, target, 'result'); From d78c5877e5a2f0f3b7f5e534b90f4d0551ca5b8b Mon Sep 17 00:00:00 2001 From: Divy123 Date: Wed, 12 Jun 2019 01:47:48 +0530 Subject: [PATCH 07/26] Update Readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index a0e8e70e0c..5cd66daa1c 100644 --- a/README.md +++ b/README.md @@ -578,3 +578,11 @@ sequencer2.run(); This method returns an object which defines the name and inputs of the modules. If a module name (hyphenated) is passed in the method, then only the details of that module are returned. The `notify` function takes two parameters `msg` and `id`, former being the message to be displayed on console (in case of CLI and node ) and a HTML component(in browser). The id is optional and is useful for HTML interface to give appropriate IDs. + +## Using WebAssembly for heavy pixel processing + +As of now, any of the modules, which uses changePixel function uses wasm as well. Both node and browser code use WebAssembly and the only region of fallback to the initial code is the one under browserified unit tests. + +The main advantage we get using wasm is blazing fast speed attained in processing pixels for many modules that is very clear from the benchmarks itself. + +The only limitation encountered was that the browser and node code for implementing wasm had to be written separately. This is because in browser we use ```fetch``` and in node we use ```fs``` module which both can't be used in other environment. \ No newline at end of file From 9da895f9a3e5f76fbd617d5dae46887f283ea66d Mon Sep 17 00:00:00 2001 From: Divy123 Date: Thu, 13 Jun 2019 18:15:13 +0530 Subject: [PATCH 08/26] Applies toggling functionality and refactored PixelManipulation code --- src/modules/AddQR/Module.js | 3 +- src/modules/Average/Module.js | 3 +- src/modules/Blend/Module.js | 3 +- src/modules/Blur/Module.js | 3 +- src/modules/Brightness/Module.js | 3 +- src/modules/CanvasResize/Module.js | 3 +- src/modules/Channel/Module.js | 3 +- src/modules/ColorTemperature/Module.js | 3 +- src/modules/Colormap/Module.js | 3 +- src/modules/Contrast/Module.js | 3 +- src/modules/Convolution/Module.js | 3 +- src/modules/DecodeQr/Module.js | 3 +- src/modules/Dither/Module.js | 3 +- src/modules/DrawRectangle/Module.js | 3 +- src/modules/Dynamic/Module.js | 3 +- src/modules/EdgeDetect/Module.js | 3 +- src/modules/Exposure/Module.js | 3 +- src/modules/FlipImage/Module.js | 3 +- src/modules/GammaCorrection/Module.js | 3 +- src/modules/GridOverlay/Module.js | 3 +- src/modules/Histogram/Module.js | 3 +- src/modules/Invert/Module.js | 3 +- src/modules/Ndvi/Module.js | 3 +- src/modules/Overlay/Module.js | 3 +- src/modules/PaintBucket/Module.js | 3 +- src/modules/ReplaceColor/Module.js | 3 +- src/modules/Resize/Module.js | 3 +- src/modules/Rotate/Module.js | 3 +- src/modules/Saturation/Module.js | 3 +- src/modules/TextOverlay/Module.js | 3 +- src/modules/Threshold/Module.js | 3 +- src/modules/Tint/Module.js | 3 +- src/modules/WhiteBalance/Module.js | 3 +- src/modules/_nomodule/PixelManipulation.js | 76 ++++++++++------------ 34 files changed, 100 insertions(+), 75 deletions(-) diff --git a/src/modules/AddQR/Module.js b/src/modules/AddQR/Module.js index 53a9fbbe91..f8819b278a 100644 --- a/src/modules/AddQR/Module.js +++ b/src/modules/AddQR/Module.js @@ -36,7 +36,8 @@ module.exports = function AddQR(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); }); diff --git a/src/modules/Average/Module.js b/src/modules/Average/Module.js index e799286375..3dcc1dec87 100755 --- a/src/modules/Average/Module.js +++ b/src/modules/Average/Module.js @@ -61,7 +61,8 @@ module.exports = function Average(options, UI) { extraManipulation: extraManipulation, format: input.format, image: options.image, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Blend/Module.js b/src/modules/Blend/Module.js index 0836019699..a6edc38365 100644 --- a/src/modules/Blend/Module.js +++ b/src/modules/Blend/Module.js @@ -61,7 +61,8 @@ module.exports = function Dynamic(options, UI, util) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); }); } diff --git a/src/modules/Blur/Module.js b/src/modules/Blur/Module.js index 4d4eda634f..8a5539df80 100755 --- a/src/modules/Blur/Module.js +++ b/src/modules/Blur/Module.js @@ -32,7 +32,8 @@ module.exports = function Blur(options, UI) { extraManipulation: extraManipulation, format: input.format, image: options.image, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Brightness/Module.js b/src/modules/Brightness/Module.js index 71fbf8303b..cb4b5d7da4 100644 --- a/src/modules/Brightness/Module.js +++ b/src/modules/Brightness/Module.js @@ -44,7 +44,8 @@ module.exports = function Brightness(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/CanvasResize/Module.js b/src/modules/CanvasResize/Module.js index 5d6aed9591..11fa950c4b 100644 --- a/src/modules/CanvasResize/Module.js +++ b/src/modules/CanvasResize/Module.js @@ -49,7 +49,8 @@ module.exports = function canvasResize(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Channel/Module.js b/src/modules/Channel/Module.js index 4d12ab0202..1fd908a38e 100644 --- a/src/modules/Channel/Module.js +++ b/src/modules/Channel/Module.js @@ -35,7 +35,8 @@ module.exports = function Channel(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/ColorTemperature/Module.js b/src/modules/ColorTemperature/Module.js index c035fbfa0f..e088ba8188 100644 --- a/src/modules/ColorTemperature/Module.js +++ b/src/modules/ColorTemperature/Module.js @@ -67,7 +67,8 @@ module.exports = function ColorTemperature(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Colormap/Module.js b/src/modules/Colormap/Module.js index 68fc455113..5d67448495 100644 --- a/src/modules/Colormap/Module.js +++ b/src/modules/Colormap/Module.js @@ -28,7 +28,8 @@ module.exports = function Colormap(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Contrast/Module.js b/src/modules/Contrast/Module.js index f45b08419e..2fdd355af7 100644 --- a/src/modules/Contrast/Module.js +++ b/src/modules/Contrast/Module.js @@ -32,7 +32,8 @@ module.exports = function Contrast(options, UI) { extraManipulation: extraManipulation, format: input.format, image: options.image, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Convolution/Module.js b/src/modules/Convolution/Module.js index 4fa741b24a..f2243599c3 100644 --- a/src/modules/Convolution/Module.js +++ b/src/modules/Convolution/Module.js @@ -30,7 +30,8 @@ module.exports = function Convolution(options, UI) { extraManipulation: extraManipulation, format: input.format, image: options.image, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/DecodeQr/Module.js b/src/modules/DecodeQr/Module.js index d4aeb49b58..3b426f1463 100644 --- a/src/modules/DecodeQr/Module.js +++ b/src/modules/DecodeQr/Module.js @@ -39,7 +39,8 @@ module.exports = function DoNothing(options,UI) { output: output, format: input.format, image: options.image, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Dither/Module.js b/src/modules/Dither/Module.js index 916f762a7c..63f3813654 100644 --- a/src/modules/Dither/Module.js +++ b/src/modules/Dither/Module.js @@ -26,7 +26,8 @@ module.exports = function Dither(options, UI){ extraManipulation: extraManipulation, format: input.format, image: options.image, - callback: callback + callback: callback, + useWasm:true }); } return { diff --git a/src/modules/DrawRectangle/Module.js b/src/modules/DrawRectangle/Module.js index 68923316a6..6bbb8dc7b3 100644 --- a/src/modules/DrawRectangle/Module.js +++ b/src/modules/DrawRectangle/Module.js @@ -31,7 +31,8 @@ module.exports = function DrawRectangle(options, UI) { extraManipulation: extraManipulation, format: input.format, image: options.image, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Dynamic/Module.js b/src/modules/Dynamic/Module.js index 477158f2e0..1ab3d9eb5e 100644 --- a/src/modules/Dynamic/Module.js +++ b/src/modules/Dynamic/Module.js @@ -85,7 +85,8 @@ module.exports = function Dynamic(options,UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/EdgeDetect/Module.js b/src/modules/EdgeDetect/Module.js index 84d086ce3c..0185b8485c 100644 --- a/src/modules/EdgeDetect/Module.js +++ b/src/modules/EdgeDetect/Module.js @@ -49,7 +49,8 @@ module.exports = function edgeDetect(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); }); }); diff --git a/src/modules/Exposure/Module.js b/src/modules/Exposure/Module.js index 01b949533f..99d0defc30 100644 --- a/src/modules/Exposure/Module.js +++ b/src/modules/Exposure/Module.js @@ -37,7 +37,8 @@ module.exports = function Exposure(options,UI){ format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/FlipImage/Module.js b/src/modules/FlipImage/Module.js index 96667a119e..703025946d 100644 --- a/src/modules/FlipImage/Module.js +++ b/src/modules/FlipImage/Module.js @@ -36,7 +36,8 @@ module.exports = function FlipImage(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); }); diff --git a/src/modules/GammaCorrection/Module.js b/src/modules/GammaCorrection/Module.js index 463c81e500..e8dca1eb96 100644 --- a/src/modules/GammaCorrection/Module.js +++ b/src/modules/GammaCorrection/Module.js @@ -34,7 +34,8 @@ module.exports = function Gamma(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/GridOverlay/Module.js b/src/modules/GridOverlay/Module.js index 150518b2a3..24174afb4e 100644 --- a/src/modules/GridOverlay/Module.js +++ b/src/modules/GridOverlay/Module.js @@ -28,7 +28,8 @@ module.exports = function GridOverlay(options,UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); diff --git a/src/modules/Histogram/Module.js b/src/modules/Histogram/Module.js index eb8e3feac9..06a36c5a56 100644 --- a/src/modules/Histogram/Module.js +++ b/src/modules/Histogram/Module.js @@ -79,7 +79,8 @@ module.exports = function Channel(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Invert/Module.js b/src/modules/Invert/Module.js index e5c4d40604..63af1dcb92 100644 --- a/src/modules/Invert/Module.js +++ b/src/modules/Invert/Module.js @@ -30,7 +30,8 @@ function Invert(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Ndvi/Module.js b/src/modules/Ndvi/Module.js index d599ec0637..00c4495af5 100644 --- a/src/modules/Ndvi/Module.js +++ b/src/modules/Ndvi/Module.js @@ -45,7 +45,8 @@ module.exports = function Ndvi(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: modifiedCallback + callback: modifiedCallback, + useWasm:true }); } diff --git a/src/modules/Overlay/Module.js b/src/modules/Overlay/Module.js index 3f5dee2b17..efaae655a7 100644 --- a/src/modules/Overlay/Module.js +++ b/src/modules/Overlay/Module.js @@ -69,7 +69,8 @@ module.exports = function Dynamic(options, UI, util) { format: baseStepOutput.format, image: baseStepImage, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); }); } diff --git a/src/modules/PaintBucket/Module.js b/src/modules/PaintBucket/Module.js index e720a53568..bcf4d6dc7a 100644 --- a/src/modules/PaintBucket/Module.js +++ b/src/modules/PaintBucket/Module.js @@ -27,7 +27,8 @@ module.exports = function PaintBucket(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/ReplaceColor/Module.js b/src/modules/ReplaceColor/Module.js index cfb944f1d8..dfc5503234 100644 --- a/src/modules/ReplaceColor/Module.js +++ b/src/modules/ReplaceColor/Module.js @@ -31,7 +31,8 @@ module.exports = function ReplaceColor(options, UI) { extraManipulation: extraManipulation, format: input.format, image: options.image, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Resize/Module.js b/src/modules/Resize/Module.js index 66a54e21cf..2bb9a83757 100644 --- a/src/modules/Resize/Module.js +++ b/src/modules/Resize/Module.js @@ -59,7 +59,8 @@ module.exports = function Resize(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Rotate/Module.js b/src/modules/Rotate/Module.js index f578a07f74..78fcf8f87f 100644 --- a/src/modules/Rotate/Module.js +++ b/src/modules/Rotate/Module.js @@ -50,7 +50,8 @@ module.exports = function Rotate(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Saturation/Module.js b/src/modules/Saturation/Module.js index 5a62bc51c0..ee8af2f21a 100644 --- a/src/modules/Saturation/Module.js +++ b/src/modules/Saturation/Module.js @@ -44,7 +44,8 @@ module.exports = function Saturation(options,UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/TextOverlay/Module.js b/src/modules/TextOverlay/Module.js index ed13b1aac9..27f5fa3c69 100644 --- a/src/modules/TextOverlay/Module.js +++ b/src/modules/TextOverlay/Module.js @@ -35,7 +35,8 @@ module.exports = function TextOverlay(options,UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/Threshold/Module.js b/src/modules/Threshold/Module.js index f05479b51e..34f609043e 100644 --- a/src/modules/Threshold/Module.js +++ b/src/modules/Threshold/Module.js @@ -32,7 +32,8 @@ module.exports = function ImageThreshold(options, UI) { extraManipulation: extraManipulation, format: input.format, image: options.image, - callback: callback + callback: callback, + useWasm:true }); } return { diff --git a/src/modules/Tint/Module.js b/src/modules/Tint/Module.js index a22c2a5310..abc7020421 100644 --- a/src/modules/Tint/Module.js +++ b/src/modules/Tint/Module.js @@ -36,7 +36,8 @@ module.exports = function Tint(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/WhiteBalance/Module.js b/src/modules/WhiteBalance/Module.js index 78c1300a5c..1c7e5c857a 100644 --- a/src/modules/WhiteBalance/Module.js +++ b/src/modules/WhiteBalance/Module.js @@ -44,7 +44,8 @@ module.exports = function Balance(options, UI) { format: input.format, image: options.image, inBrowser: options.inBrowser, - callback: callback + callback: callback, + useWasm:true }); } diff --git a/src/modules/_nomodule/PixelManipulation.js b/src/modules/_nomodule/PixelManipulation.js index 032d563b4c..8a79e8519c 100644 --- a/src/modules/_nomodule/PixelManipulation.js +++ b/src/modules/_nomodule/PixelManipulation.js @@ -83,7 +83,6 @@ module.exports = function PixelManipulation(image, options) { const imports = { env: { - // paceOp: require('pace').op, consoleLog: console.log, perform: function (x, y) { let pixel = options.changePixel( @@ -103,50 +102,43 @@ module.exports = function PixelManipulation(image, options) { } }; + function perPixelManipulation() { + for (var x = 0; x < pixels.shape[0]; x++) { + for (var y = 0; y < pixels.shape[1]; y++) { + imports.env.perform(x,y); + } + } + } + const inBrowser = (options.inBrowser) ? 1 : 0; const test = (process.env.TEST) ? 1 : 0; - - if (options.inBrowser) { - - fetch('./manipulation.wasm').then(response => - response.arrayBuffer() - ).then(bytes => - WebAssembly.instantiate(bytes, imports) - ).then(results => { - results.instance.exports.manipulatePixel(pixels.shape[0], pixels.shape[1], inBrowser, test); - extraOperation(); - }).catch(err => { - - for (var x = 0; x < pixels.shape[0]; x++) { - for (var y = 0; y < pixels.shape[1]; y++) { - let pixel = options.changePixel( - pixels.get(x, y, 0), - pixels.get(x, y, 1), - pixels.get(x, y, 2), - pixels.get(x, y, 3), - x, - y - ); - - pixels.set(x, y, 0, pixel[0]); - pixels.set(x, y, 1, pixel[1]); - pixels.set(x, y, 2, pixel[2]); - pixels.set(x, y, 3, pixel[3]); - - } - } - extraOperation(); - // console.log(err) - }); + if (options.useWasm) { + if (options.inBrowser) { + + fetch('./manipulation.wasm').then(response => + response.arrayBuffer() + ).then(bytes => + WebAssembly.instantiate(bytes, imports) + ).then(results => { + results.instance.exports.manipulatePixel(pixels.shape[0], pixels.shape[1], inBrowser, test); + extraOperation(); + }).catch(err => { + perPixelManipulation(); + extraOperation(); + }); + } else { + const fs = require('fs'); + const buf = fs.readFileSync('./manipulation.wasm'); + WebAssembly.instantiate(buf, imports).then(results => { + results.instance.exports.manipulatePixel(pixels.shape[0], pixels.shape[1], inBrowser, test); + extraOperation(); + }).catch(err => { + console.log(err); + }); + } } else { - const fs = require('fs'); - const buf = fs.readFileSync('./manipulation.wasm'); - WebAssembly.instantiate(buf, imports).then(results => { - results.instance.exports.manipulatePixel(pixels.shape[0], pixels.shape[1], inBrowser, test); - extraOperation(); - }).catch(err => { - console.log(err); - }); + perPixelManipulation(); + extraOperation(); } } }); From 0ea5419826fdeecb58db38cb517ba36047199429 Mon Sep 17 00:00:00 2001 From: Divy123 Date: Fri, 14 Jun 2019 03:45:08 +0530 Subject: [PATCH 09/26] Added documentation and corrected wasm toggling --- README.md | 13 ++++++++++++- examples/demo.js | 2 +- examples/lib/insertPreview.js | 2 +- examples/replace.html | 2 +- index.js | 2 +- spec/defaultHtmlSequencerUi.spec.js | 2 +- spec/defaultHtmlStepUi.spec.js | 2 +- spec/insertPreview.spec.js | 2 +- spec/intermediateHtmlStepUi.spec.js | 2 +- src/ImageSequencer.js | 1 - src/InsertStep.js | 2 +- src/ReplaceImage.js | 2 +- src/modules/AddQR/Module.js | 3 +-- src/modules/Average/Module.js | 2 +- src/modules/Blend/Module.js | 2 +- src/modules/Blur/Module.js | 2 +- src/modules/Brightness/Module.js | 2 +- src/modules/CanvasResize/Module.js | 2 +- src/modules/Channel/Module.js | 2 +- src/modules/ColorTemperature/Module.js | 2 +- src/modules/Colormap/Module.js | 2 +- src/modules/Contrast/Module.js | 2 +- src/modules/Convolution/Module.js | 2 +- src/modules/DecodeQr/Module.js | 2 +- src/modules/Dither/Module.js | 2 +- src/modules/DrawRectangle/Module.js | 2 +- src/modules/Dynamic/Module.js | 2 +- src/modules/EdgeDetect/Module.js | 4 ++-- src/modules/Exposure/Module.js | 2 +- src/modules/FlipImage/Module.js | 2 +- src/modules/GammaCorrection/Module.js | 2 +- src/modules/GridOverlay/Module.js | 2 +- src/modules/Histogram/Module.js | 2 +- src/modules/ImportImage/Module.js | 2 +- src/modules/Invert/Module.js | 2 +- src/modules/Ndvi/Module.js | 2 +- src/modules/Overlay/Module.js | 2 +- src/modules/PaintBucket/Module.js | 2 +- src/modules/ReplaceColor/Module.js | 2 +- src/modules/Resize/Module.js | 2 +- src/modules/Rotate/Module.js | 2 +- src/modules/Saturation/Module.js | 2 +- src/modules/TextOverlay/Module.js | 2 +- src/modules/Threshold/Module.js | 2 +- src/modules/Tint/Module.js | 2 +- src/modules/WhiteBalance/Module.js | 2 +- src/util/createMetaModule.js | 2 +- test/core/modules/blend.js | 2 +- test/core/modules/canvas-resize.js | 2 +- test/core/modules/decode-qr.js | 2 +- test/core/modules/invert.js | 2 +- test/core/modules/overlay.js | 2 +- test/core/modules/text-overlay.js | 2 +- test/core/modules1/blend.js | 2 +- test/core/modules1/decode-qr.js | 3 ++- test/core/modules1/overlay.js | 2 +- test/core/sequencer/benchmark.js | 2 +- test/core/sequencer/chain.js | 2 +- test/core/sequencer/dynamic-imports.js | 2 +- test/core/sequencer/image-sequencer.js | 2 +- test/core/sequencer/import-export.js | 2 +- test/core/sequencer/meta-modules.js | 4 ++-- test/core/sequencer/replace.js | 2 +- test/core/sequencer/run.js | 2 +- test/core/templates/module-test.1.js | 3 ++- test/core/templates/module-test.js | 2 +- test/core/ui/user-interface.js | 2 +- 67 files changed, 81 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index 5cd66daa1c..10edea497c 100644 --- a/README.md +++ b/README.md @@ -585,4 +585,15 @@ As of now, any of the modules, which uses changePixel function uses wasm as well The main advantage we get using wasm is blazing fast speed attained in processing pixels for many modules that is very clear from the benchmarks itself. -The only limitation encountered was that the browser and node code for implementing wasm had to be written separately. This is because in browser we use ```fetch``` and in node we use ```fs``` module which both can't be used in other environment. \ No newline at end of file +The only limitation encountered was that the browser and node code for implementing wasm had to be written separately. This is because in browser we use ```fetch``` and in node we use ```fs``` module which both can't be used in other environment. + +Also, one can toggle between the two modes, the wasm one and the non-wasm in the following way: + +```js +let sequencer = ImageSequencer({useWasm:true}) // for wasm mode or + +let sequencer = ImageSequencer({useWasm:false}) //for non-wasm mode or simply + +let sequencer = ImageSequencer() // also for non-wasm mode + +``` \ No newline at end of file diff --git a/examples/demo.js b/examples/demo.js index af298f8b29..ed25e5710c 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -6,7 +6,7 @@ var defaultHtmlSequencerUi = require('./lib/defaultHtmlSequencerUi.js'), insertPreview = require('./lib/insertPreview.js'); window.onload = function() { - sequencer = ImageSequencer(); + sequencer = ImageSequencer({useWasm:true}); function refreshOptions() { // Load information of all modules (Name, Inputs, Outputs) diff --git a/examples/lib/insertPreview.js b/examples/lib/insertPreview.js index 2eab5f0335..3763ded248 100644 --- a/examples/lib/insertPreview.js +++ b/examples/lib/insertPreview.js @@ -1,6 +1,6 @@ function generatePreview(previewStepName, customValues, path, selector) { - var previewSequencer = ImageSequencer(); + var previewSequencer = ImageSequencer({useWasm:true}); function insertPreview(src) { var img = document.createElement('img'); img.classList.add('img-thumbnail'); diff --git a/examples/replace.html b/examples/replace.html index d6f7948d20..d43f782e14 100644 --- a/examples/replace.html +++ b/examples/replace.html @@ -52,7 +52,7 @@

sequencer.replaceImage('#pencils','invert');