From 416fdd3c6c4f6fa933477861a132732b8a239ca2 Mon Sep 17 00:00:00 2001 From: Federico Aguzzi <62149513+f-aguzzi@users.noreply.github.com> Date: Fri, 23 Feb 2024 10:10:11 +0100 Subject: [PATCH 1/3] update: fixed wasm-pack.yml action workflow --- .github/workflows/wasm-pack.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/wasm-pack.yml b/.github/workflows/wasm-pack.yml index c346172..de18ec9 100644 --- a/.github/workflows/wasm-pack.yml +++ b/.github/workflows/wasm-pack.yml @@ -3,6 +3,7 @@ on: push: paths: - 'lib/src/lib.rs' + - '.github/workflows/wasm-pack.yml' jobs: build: @@ -17,11 +18,12 @@ jobs: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh wasm-pack build lib/ --release --target web - - name: Copy necessary files + - name: Copy necessary files and stage them run: | cp lib/pkg/editpix_wasm_bg.wasm src/core/editpix_wasm_bg.wasm cp lib/pkg/editpix_wasm.js src/core/editpix_wasm.js rm -r lib/pkg + git add * - name: Check for changes id: check_changes @@ -39,9 +41,8 @@ jobs: run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - git add * git commit -m "CI push" - name: Push changes if: steps.check_changes.outputs.changes == 'true' - uses: ad-m/github-push-action@master \ No newline at end of file + uses: ad-m/github-push-action@master From f6bbf1ab7b7fce0087af5ed17e0a12cfaa521d2e Mon Sep 17 00:00:00 2001 From: Federico Aguzzi <62149513+f-aguzzi@users.noreply.github.com> Date: Fri, 23 Feb 2024 10:23:51 +0100 Subject: [PATCH 2/3] add: wasm plugin & boilerplate js --- src/core/editpix_wasm.js | 156 ++++++++++++++++++++++++++++++++++ src/core/editpix_wasm_bg.wasm | Bin 0 -> 17438 bytes 2 files changed, 156 insertions(+) create mode 100644 src/core/editpix_wasm.js create mode 100644 src/core/editpix_wasm_bg.wasm diff --git a/src/core/editpix_wasm.js b/src/core/editpix_wasm.js new file mode 100644 index 0000000..6085545 --- /dev/null +++ b/src/core/editpix_wasm.js @@ -0,0 +1,156 @@ +let wasm; + +const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); + +if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; + +let cachedUint8Memory0 = null; + +function getUint8Memory0() { + if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { + cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8Memory0; +} + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); +} + +let WASM_VECTOR_LEN = 0; + +function passArray8ToWasm0(arg, malloc) { + const ptr = malloc(arg.length * 1, 1) >>> 0; + getUint8Memory0().set(arg, ptr / 1); + WASM_VECTOR_LEN = arg.length; + return ptr; +} + +let cachedInt32Memory0 = null; + +function getInt32Memory0() { + if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { + cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); + } + return cachedInt32Memory0; +} + +function getArrayU8FromWasm0(ptr, len) { + ptr = ptr >>> 0; + return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); +} +/** +* @param {Uint8Array} colors_r +* @param {number} color_number +* @param {number} max_iterations +* @returns {Uint8Array} +*/ +export function k_means(colors_r, color_number, max_iterations) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passArray8ToWasm0(colors_r, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.k_means(retptr, ptr0, len0, color_number, max_iterations); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v2 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v2; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +async function __wbg_load(module, imports) { + if (typeof Response === 'function' && module instanceof Response) { + if (typeof WebAssembly.instantiateStreaming === 'function') { + try { + return await WebAssembly.instantiateStreaming(module, imports); + + } catch (e) { + if (module.headers.get('Content-Type') != 'application/wasm') { + console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); + + } else { + throw e; + } + } + } + + const bytes = await module.arrayBuffer(); + return await WebAssembly.instantiate(bytes, imports); + + } else { + const instance = await WebAssembly.instantiate(module, imports); + + if (instance instanceof WebAssembly.Instance) { + return { instance, module }; + + } else { + return instance; + } + } +} + +function __wbg_get_imports() { + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbindgen_throw = function(arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }; + + return imports; +} + +function __wbg_init_memory(imports, maybe_memory) { + +} + +function __wbg_finalize_init(instance, module) { + wasm = instance.exports; + __wbg_init.__wbindgen_wasm_module = module; + cachedInt32Memory0 = null; + cachedUint8Memory0 = null; + + + return wasm; +} + +function initSync(module) { + if (wasm !== undefined) return wasm; + + const imports = __wbg_get_imports(); + + __wbg_init_memory(imports); + + if (!(module instanceof WebAssembly.Module)) { + module = new WebAssembly.Module(module); + } + + const instance = new WebAssembly.Instance(module, imports); + + return __wbg_finalize_init(instance, module); +} + +async function __wbg_init(input) { + if (wasm !== undefined) return wasm; + + if (typeof input === 'undefined') { + input = new URL('editpix_wasm_bg.wasm', import.meta.url); + } + const imports = __wbg_get_imports(); + + if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) { + input = fetch(input); + } + + __wbg_init_memory(imports); + + const { instance, module } = await __wbg_load(await input, imports); + + return __wbg_finalize_init(instance, module); +} + +export { initSync } +export default __wbg_init; diff --git a/src/core/editpix_wasm_bg.wasm b/src/core/editpix_wasm_bg.wasm new file mode 100644 index 0000000000000000000000000000000000000000..b34cbf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Q5qvwO+5VK1|TTl9<17bE9}?lbP{ z;_8*9RUg?A*hYgY>a|S1o=-ujU%8>r8ci+7A+FdlFrH_!;3x|3QNF z^=LI3joOXHmoIF!m!M&3@#^BzmF_EkZL7WU!ixTn2=0q<(|A8lDf&JSed5&#e)jUC z|1`JGpZ}Rc`?_Dd))mh#u3cNbwE2|pzS#CF?Nxte6E@PNdKgHHbGMn7!o5wY`Nqe` zC&nkor^ctpXU1p8=f>y9Pfd(ZOiWBpOifHr%uLKq%uUQsoSGb;oS2-PoSK}ToSB@R zoSU4VJT)~wH8C|gH8nLoH8V9kH8(Xsb!vKidSZHVdTM%ldS-fddTx4t`qa!gXq=px znwg%NnVFrLo0*?EH9I~#F*`XsH9I{!GdnvwH#3;9-2D9fsZ)@6iser+^(kIEMbqZmwT-2=H$-dym%A_e<0t&3 zHE^`L*7Ywfc9&lCm)e`%E2{x#JBPlJ1dRPU Date: Fri, 23 Feb 2024 11:38:05 +0100 Subject: [PATCH 3/3] refactor: refactoring of demo scripts --- demo/scripts/black_white_demo.js | 2 +- demo/scripts/color_palette_demo.js | 4 ++-- demo/scripts/dominant_color_demo.js | 2 +- demo/scripts/gray_scale_demo.js | 2 +- demo/scripts/resize_image_demo.js | 9 +++++++-- src/core/decript.js | 20 -------------------- src/core/encript.js | 27 --------------------------- 7 files changed, 12 insertions(+), 54 deletions(-) delete mode 100644 src/core/decript.js delete mode 100644 src/core/encript.js diff --git a/demo/scripts/black_white_demo.js b/demo/scripts/black_white_demo.js index 78eccb2..e6f8d6c 100644 --- a/demo/scripts/black_white_demo.js +++ b/demo/scripts/black_white_demo.js @@ -2,7 +2,7 @@ import EditPix from "../../src/editpix.js"; const editpix = new EditPix(); -const url = "../images/img1.jpg"; +const url = "images/img1.jpg"; var image = new Image(); image.src = url; diff --git a/demo/scripts/color_palette_demo.js b/demo/scripts/color_palette_demo.js index 5c0bd5a..ce11d23 100644 --- a/demo/scripts/color_palette_demo.js +++ b/demo/scripts/color_palette_demo.js @@ -2,7 +2,7 @@ import EditPix from "../../src/editpix.js"; const editpix = new EditPix(); -const url = "../images/img1.jpg"; +const url = "images/img1.jpg"; var image = new Image(); image.src = url; @@ -13,7 +13,7 @@ container.classList.add("container") //waiting image load image.onload = () => { //calculate color palette - editpix.getColorPalette(image, 15,9) + editpix.getColorPalette(image, 15, 1) .then(colorPalette => { //log color palette in rbg format displayPalette(colorPalette); diff --git a/demo/scripts/dominant_color_demo.js b/demo/scripts/dominant_color_demo.js index cb32fb2..e41a927 100644 --- a/demo/scripts/dominant_color_demo.js +++ b/demo/scripts/dominant_color_demo.js @@ -2,7 +2,7 @@ import EditPix from "../../src/editpix.js"; const editpix = new EditPix(); -const url = "../images/img1.jpg"; +const url = "images/img1.jpg"; var image = new Image(); image.src = url; diff --git a/demo/scripts/gray_scale_demo.js b/demo/scripts/gray_scale_demo.js index 66427fb..b7f9fe8 100644 --- a/demo/scripts/gray_scale_demo.js +++ b/demo/scripts/gray_scale_demo.js @@ -2,7 +2,7 @@ import EditPix from "../../src/editpix.js"; const editpix = new EditPix(); -const url = "../images/img1.jpg"; +const url = "images/img1.jpg"; var image = new Image(); image.src = url; diff --git a/demo/scripts/resize_image_demo.js b/demo/scripts/resize_image_demo.js index 86143c5..fdf4a4b 100644 --- a/demo/scripts/resize_image_demo.js +++ b/demo/scripts/resize_image_demo.js @@ -2,7 +2,7 @@ import EditPix from "../../src/editpix.js"; const editpix = new EditPix(); -const url = "../images/img3.jpeg"; +const url = "images/img3.jpeg"; var image = new Image(); image.src = url; @@ -17,11 +17,14 @@ image.onload = () => { // image dimension before resizing console.log("Dimension before resizing: " + image.naturalWidth + "x" + image.naturalHeight); + document.body.appendChild(image) + // resize image by quality - editpix.resizeByQuality(image, 10) + editpix.resizeByQuality(image, 8) .then(resizedImage => { // image dimension after resizing console.log("Dimension after resizing by 90%: " + resizedImage.naturalWidth + "x" + resizedImage.naturalHeight); + document.body.appendChild(resizedImage) }) .catch(error => { console.log(error) }) @@ -29,6 +32,7 @@ image.onload = () => { editpix.resizeByWidth(image, 100) .then(resizedImage => { console.log("Dimension after resizing width equals to 100px: " + resizedImage.naturalWidth + "x" + resizedImage.naturalHeight); + document.body.appendChild(resizedImage) }) .catch(error => { console.log(error) }) @@ -36,6 +40,7 @@ image.onload = () => { editpix.resizeByHeight(image, 100) .then(resizedImage => { console.log("Dimension after resizing height equals to 100px: " + resizedImage.naturalWidth + "x" + resizedImage.naturalHeight); + document.body.appendChild(resizedImage) }) .catch(error => { console.log(error) }) }; diff --git a/src/core/decript.js b/src/core/decript.js deleted file mode 100644 index ed81d76..0000000 --- a/src/core/decript.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Functiom that given array in the format [[R,G,B],..., [R,G,B]] it converts it in [R,G,B,Alfa] - * @param {number[]} image_to_decrypt: image that has to be encrypt in the format [[R,G,B],..., [R,G,B]] - * @returns {number[][]} decripted_image: decripted image in the format [R,G,B,Alfa] - */ -function decript(image_to_decrypt) { - var decripted_image = []; - - for (let i = 0; i < image_to_decrypt.length; i++) { - var elem_to_add = image_to_decrypt[i]; - decripted_image.push(elem_to_add[0]); - decripted_image.push(elem_to_add[1]); - decripted_image.push(elem_to_add[2]); - decripted_image.push(255); - } - - return decripted_image; -} - -export default decript; diff --git a/src/core/encript.js b/src/core/encript.js deleted file mode 100644 index d53a9c8..0000000 --- a/src/core/encript.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Functiom that given array in the format [R,G,B,Alfa] it converts it in [[R,G,B],..., [R,G,B]] - * @param {number[]} image_to_encrypt: image that has to be encrypt in the format [R,G,B,Alfa] - * @returns {number[][]} encrypted_image: encrypted image in the format [[R,G,B],..., [R,G,B]] - */ -function encript(image_to_encrypt) { - var encripted_image = []; - - for (let i = 0; i < image_to_encrypt.length / 4; i++) { - if (i == 0) - encripted_image.push([ - image_to_encrypt[0], - image_to_encrypt[1], - image_to_encrypt[2], - ]); - else - encripted_image.push([ - image_to_encrypt[4 * i], - image_to_encrypt[4 * i + 1], - image_to_encrypt[4 * i + 2], - ]); - } - - return encripted_image; -} - -export default encript;