From ccf0aec0d55ddc0f21f5d4fae71a9f42bb129287 Mon Sep 17 00:00:00 2001 From: Invalid Name <76132013+coder0107git@users.noreply.github.com> Date: Tue, 21 Nov 2023 05:27:48 +0000 Subject: [PATCH 1/3] Intital Wasm Updates --- go.mod | 2 +- main.go | 2 +- primitive/util.go | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index b49608ac..6914d98e 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/hashbite/primitive +module self/primitive go 1.17 diff --git a/main.go b/main.go index 0075c4d8..c6d31841 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( "strings" "time" - "github.com/hashbite/primitive/primitive" + "self/primitive/primitive" "github.com/nfnt/resize" ) diff --git a/primitive/util.go b/primitive/util.go index 83446cdf..d97b3271 100644 --- a/primitive/util.go +++ b/primitive/util.go @@ -1,6 +1,9 @@ package primitive import ( + "encoding/base64" + //"bytes" + "strings" "fmt" "image" "image/color" @@ -20,6 +23,21 @@ func LoadImage(path string) (image.Image, error) { if path == "-" { im, _, err := image.Decode(os.Stdin) return im, err + } else if path == "env_var_base64" { + //file, err := os.Open(path) + /*file, err := base64.RawStdEncoding.DecodeString(path) + if err != nil { + return nil, err + } + + r := bytes.NewReader(byteData) + + defer r.Close()*/ + + reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(os.Getenv("IMAGE"))) + + im, _, err := image.Decode(reader) //(r) + return im, err } else { file, err := os.Open(path) if err != nil { From 012f9461c8b3a0b2adf86cba2f0e6b8a7275402d Mon Sep 17 00:00:00 2001 From: Invalid Name <76132013+coder0107git@users.noreply.github.com> Date: Tue, 21 Nov 2023 05:53:36 +0000 Subject: [PATCH 2/3] Added wasm building instructions --- BUILDING.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 BUILDING.md diff --git a/BUILDING.md b/BUILDING.md new file mode 100644 index 00000000..7452380e --- /dev/null +++ b/BUILDING.md @@ -0,0 +1,27 @@ +# BUILDING + +## WASI +```bash +GOOS=wasip1 GOARCH=wasm go build -o ./primitive.wasi.wasm ./main.go +``` + +### Usage +```bash +IMAGE="[some base64 encoded image]" wasmtime run --env IMAGE ./primitive.wasi.wasm -i env_var_base64 -o - -n 50 -m 1 -s 2500 -rep 0 -a 128 -bg 344b57 -j 0 -vv +``` +or +```bash +wasmtime run ./primitive.wasi.wasm -i ./mountains.jpg -o - -n 50 -m 1 -s 2500 -rep 0 -a 128 -bg 344b57 -j 0 -vv +``` +or +```bash +cat ./mountains.jpg | wasmtime run ./primitive.wasi.wasm -i - -o - -n 50 -m 1 -s 2500 -rep 0 -a 128 -bg 344b57 -j 0 -vv +``` + +## Web WASM +```bash +GOOS=js GOARCH=wasm go build -o ./primitive.web.wasm ./main.go +``` + +### Usage +*To be determined when web MVP works* From ff5634fd3c39e53f8c70909998b9fd8aef97566b Mon Sep 17 00:00:00 2001 From: Invalid Name <76132013+coder0107git@users.noreply.github.com> Date: Fri, 23 Aug 2024 01:35:50 +0000 Subject: [PATCH 3/3] Fixed building instructions. --- BUILDING.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/BUILDING.md b/BUILDING.md index 7452380e..b42f3eab 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -1,6 +1,10 @@ # BUILDING +Any mention of *mountains.jpg* is the following file: +https://github.com/coder0107git/sqip/blob/wasm-primitive/packages/sqip-plugin-primitive/mountains.jpg + ## WASI +### Building ```bash GOOS=wasip1 GOARCH=wasm go build -o ./primitive.wasi.wasm ./main.go ``` @@ -11,7 +15,7 @@ IMAGE="[some base64 encoded image]" wasmtime run --env IMAGE ./primitive.wasi.wa ``` or ```bash -wasmtime run ./primitive.wasi.wasm -i ./mountains.jpg -o - -n 50 -m 1 -s 2500 -rep 0 -a 128 -bg 344b57 -j 0 -vv +wasmtime --dir .::/ ./primitive.wasi.wasm -i /mountains.jpg -o mountains.primitive.svg -n 50 -m 1 -s 2500 -rep 0 -a 128 -bg 344b57 -j 0 -vv ``` or ```bash @@ -25,3 +29,5 @@ GOOS=js GOARCH=wasm go build -o ./primitive.web.wasm ./main.go ### Usage *To be determined when web MVP works* + +MVP: https://github.com/coder0107git/sqip/blob/wasm-primitive/packages/sqip-plugin-primitive/index.html