diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ad317ec..05197d2 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -162,59 +162,6 @@ jobs: name: bindings-${{ matrix.settings.target }} path: ${{ env.APP_NAME }}.*.node if-no-files-found: error - # build-freebsd: - # runs-on: macos-12 - # name: Build FreeBSD - # steps: - # - uses: actions/checkout@v3 - # with: - # submodules: true - # - name: Build - # id: build - # uses: vmactions/freebsd-vm@v0 - # env: - # DEBUG: napi:* - # RUSTUP_HOME: /usr/local/rustup - # CARGO_HOME: /usr/local/cargo - # RUSTUP_IO_THREADS: 1 - # with: - # envs: DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS - # usesh: true - # mem: 3000 - # prepare: | - # pkg install -y -f curl node libnghttp2 llvm cmake # Install the llvm package to fix the libclang error - # curl -qL https://www.npmjs.com/install.sh | sh - # npm install --location=global --ignore-scripts yarn - # curl https://sh.rustup.rs -sSf --output rustup.sh - # sh rustup.sh -y --profile minimal --default-toolchain beta - # rustup component add rustfmt - # export PATH="/usr/local/cargo/bin:$PATH" - # echo "~~~~ rustc --version ~~~~" - # rustc --version - # echo "~~~~ node -v ~~~~" - # node -v - # echo "~~~~ yarn --version ~~~~" - # yarn --version - # run: | - # export PATH="/usr/local/cargo/bin:$PATH" - # pwd - # ls -lah - # whoami - # env - # freebsd-version - # yarn install - # yarn build - # strip -x *.node - # yarn test - # rm -rf node_modules - # rm -rf target - # rm -rf .yarn/cache - # - name: Upload artifact - # uses: actions/upload-artifact@v3 - # with: - # name: bindings-freebsd - # path: ${{ env.APP_NAME }}.*.node - # if-no-files-found: error test-macOS-windows-binding: name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }} needs: diff --git a/README.md b/README.md index 2269db7..8f82031 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # @neplex/vectorizer -A simple Node.js library to convert raster images into svg using [VTracer](https://github.com/visioncortex/vtracer). +A simple Node.js library to convert raster images into svg using [VTracer](https://github.com/visioncortex/vtracer), with time complexity of `O(n)`. ## Installation diff --git a/__test__/data/result-bw.svg b/__test__/data/result-bw.svg index 1bc24a6..eca2d29 100644 --- a/__test__/data/result-bw.svg +++ b/__test__/data/result-bw.svg @@ -1,5 +1,5 @@ - + diff --git a/__test__/data/result-firefox.svg b/__test__/data/result-firefox.svg index aedb063..d086bbb 100644 --- a/__test__/data/result-firefox.svg +++ b/__test__/data/result-firefox.svg @@ -1,5 +1,5 @@ - + diff --git a/__test__/data/result-photo.svg b/__test__/data/result-photo.svg index 5c766ab..122f870 100644 --- a/__test__/data/result-photo.svg +++ b/__test__/data/result-photo.svg @@ -1,5 +1,5 @@ - + diff --git a/__test__/data/result-poster.svg b/__test__/data/result-poster.svg index 922dd79..2a2a84c 100644 --- a/__test__/data/result-poster.svg +++ b/__test__/data/result-poster.svg @@ -1,5 +1,5 @@ - + diff --git a/__test__/data/result-raw.svg b/__test__/data/result-raw.svg index cb82a0b..a34812a 100644 --- a/__test__/data/result-raw.svg +++ b/__test__/data/result-raw.svg @@ -1,5 +1,5 @@ - + diff --git a/__test__/data/result.svg b/__test__/data/result.svg index cb82a0b..a34812a 100644 --- a/__test__/data/result.svg +++ b/__test__/data/result.svg @@ -1,5 +1,5 @@ - + diff --git a/example/index.mjs b/example/index.mjs index 95dda6d..cdb93dd 100644 --- a/example/index.mjs +++ b/example/index.mjs @@ -16,6 +16,10 @@ const config = { maxIterations: 2, }; +const begin = performance.now(); const result = await vectorize(src, config); +const end = performance.now(); + +console.log(`[Anime Girl Vectorization] Time: ${(end - begin).toFixed(2)}ms`); await writeFile('./example/result.svg', result); diff --git a/example/result.svg b/example/result.svg index 483ae5c..516d58e 100644 --- a/example/result.svg +++ b/example/result.svg @@ -1,5 +1,5 @@ - + diff --git a/index.d.ts b/index.d.ts index d442831..b4ff108 100644 --- a/index.d.ts +++ b/index.d.ts @@ -22,16 +22,27 @@ export const enum PathSimplifyMode { Spline = 2 } export interface Config { + /** True color image or binary image (black and white) */ colorMode: ColorMode + /** Hierarchial clustering or non-stacked. Only applicable to color images. */ hierarchical: Hierarchical + /** Discard patches smaller than X pixels in size (cleaner) */ filterSpeckle: number + /** The number of significant bits to use in an RGB channel (more accurate) */ colorPrecision: number + /** The color difference between gradient layers (less layers) */ layerDifference: number + /** Curve fitting mode */ mode: PathSimplifyMode + /** Minimum momentary angle (degree) to be considered a corner (smoother) */ cornerThreshold: number + /** Perform iterative subdivide smooth until all segments are shorter than this length */ lengthThreshold: number + /** The maximum number of iterations to perform */ maxIterations: number + /** Minimum angle displacement (degree) to splice a spline (less accurate) */ spliceThreshold: number + /** Number of decimal places to use in path string */ pathPrecision?: number } export interface RawDataConfig { diff --git a/npm/android-arm-eabi/package.json b/npm/android-arm-eabi/package.json index e43a26b..fd747c0 100644 --- a/npm/android-arm-eabi/package.json +++ b/npm/android-arm-eabi/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-android-arm-eabi", - "version": "0.0.0", + "version": "0.0.4", "os": [ "android" ], diff --git a/npm/android-arm64/package.json b/npm/android-arm64/package.json index 487c034..fb0d320 100644 --- a/npm/android-arm64/package.json +++ b/npm/android-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-android-arm64", - "version": "0.0.0", + "version": "0.0.4", "os": [ "android" ], diff --git a/npm/darwin-arm64/package.json b/npm/darwin-arm64/package.json index 47a57ce..a1f01aa 100644 --- a/npm/darwin-arm64/package.json +++ b/npm/darwin-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-darwin-arm64", - "version": "0.0.0", + "version": "0.0.4", "os": [ "darwin" ], diff --git a/npm/darwin-universal/package.json b/npm/darwin-universal/package.json index fa572a8..9b77114 100644 --- a/npm/darwin-universal/package.json +++ b/npm/darwin-universal/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-darwin-universal", - "version": "0.0.0", + "version": "0.0.4", "os": [ "darwin" ], diff --git a/npm/darwin-x64/package.json b/npm/darwin-x64/package.json index a3168b4..d309f25 100644 --- a/npm/darwin-x64/package.json +++ b/npm/darwin-x64/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-darwin-x64", - "version": "0.0.0", + "version": "0.0.4", "os": [ "darwin" ], diff --git a/npm/freebsd-x64/README.md b/npm/freebsd-x64/README.md deleted file mode 100644 index 533fd96..0000000 --- a/npm/freebsd-x64/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# `@neplex/vectorizer-freebsd-x64` - -This is the **x86_64-unknown-freebsd** binary for `@neplex/vectorizer` diff --git a/npm/freebsd-x64/package.json b/npm/freebsd-x64/package.json deleted file mode 100644 index 10da1d4..0000000 --- a/npm/freebsd-x64/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "@neplex/vectorizer-freebsd-x64", - "version": "0.0.0", - "os": [ - "freebsd" - ], - "cpu": [ - "x64" - ], - "main": "vectorizer.freebsd-x64.node", - "files": [ - "vectorizer.freebsd-x64.node" - ], - "description": "A simple Node.js library to convert raster images into svg", - "author": "twlite ", - "license": "MIT", - "engines": { - "node": ">= 10" - }, - "repository": { - "type": "git", - "url": "https://github.com/neplextech/vectorizer" - } -} \ No newline at end of file diff --git a/npm/linux-arm-gnueabihf/package.json b/npm/linux-arm-gnueabihf/package.json index 3de9848..cfa9501 100644 --- a/npm/linux-arm-gnueabihf/package.json +++ b/npm/linux-arm-gnueabihf/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-linux-arm-gnueabihf", - "version": "0.0.0", + "version": "0.0.4", "os": [ "linux" ], diff --git a/npm/linux-arm64-gnu/package.json b/npm/linux-arm64-gnu/package.json index ff6b163..b00bc13 100644 --- a/npm/linux-arm64-gnu/package.json +++ b/npm/linux-arm64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-linux-arm64-gnu", - "version": "0.0.0", + "version": "0.0.4", "os": [ "linux" ], diff --git a/npm/linux-arm64-musl/package.json b/npm/linux-arm64-musl/package.json index 7c9ba75..6d38420 100644 --- a/npm/linux-arm64-musl/package.json +++ b/npm/linux-arm64-musl/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-linux-arm64-musl", - "version": "0.0.0", + "version": "0.0.4", "os": [ "linux" ], diff --git a/npm/linux-riscv64-gnu/package.json b/npm/linux-riscv64-gnu/package.json index 15013f8..83e68cb 100644 --- a/npm/linux-riscv64-gnu/package.json +++ b/npm/linux-riscv64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-linux-riscv64-gnu", - "version": "0.0.0", + "version": "0.0.4", "os": [ "linux" ], diff --git a/npm/linux-x64-gnu/package.json b/npm/linux-x64-gnu/package.json index f25d14a..cf5c2d2 100644 --- a/npm/linux-x64-gnu/package.json +++ b/npm/linux-x64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-linux-x64-gnu", - "version": "0.0.0", + "version": "0.0.4", "os": [ "linux" ], diff --git a/npm/linux-x64-musl/package.json b/npm/linux-x64-musl/package.json index 655efb4..e468f7a 100644 --- a/npm/linux-x64-musl/package.json +++ b/npm/linux-x64-musl/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-linux-x64-musl", - "version": "0.0.0", + "version": "0.0.4", "os": [ "linux" ], diff --git a/npm/win32-arm64-msvc/package.json b/npm/win32-arm64-msvc/package.json index 43ecd39..25a779e 100644 --- a/npm/win32-arm64-msvc/package.json +++ b/npm/win32-arm64-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-win32-arm64-msvc", - "version": "0.0.0", + "version": "0.0.4", "os": [ "win32" ], diff --git a/npm/win32-ia32-msvc/package.json b/npm/win32-ia32-msvc/package.json index ef43fc0..eb6fabc 100644 --- a/npm/win32-ia32-msvc/package.json +++ b/npm/win32-ia32-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-win32-ia32-msvc", - "version": "0.0.0", + "version": "0.0.4", "os": [ "win32" ], diff --git a/npm/win32-x64-msvc/package.json b/npm/win32-x64-msvc/package.json index 2ad983f..c9374f4 100644 --- a/npm/win32-x64-msvc/package.json +++ b/npm/win32-x64-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer-win32-x64-msvc", - "version": "0.0.0", + "version": "0.0.4", "os": [ "win32" ], diff --git a/package.json b/package.json index 7edb7c7..f0603d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@neplex/vectorizer", - "version": "0.0.3", + "version": "0.0.4", "description": "A simple Node.js library to convert raster images into svg", "main": "index.js", "types": "index.d.ts", @@ -52,4 +52,4 @@ "version": "napi version" }, "packageManager": "yarn@4.0.2" -} +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 67f69fe..63ee451 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,16 +26,27 @@ pub enum JsPathSimplifyMode { #[derive(Clone)] #[napi(object, js_name = "Config")] pub struct JsConfig { + /// True color image or binary image (black and white) pub color_mode: ColorMode, + /// Hierarchial clustering or non-stacked. Only applicable to color images. pub hierarchical: Hierarchical, + /// Discard patches smaller than X pixels in size (cleaner) pub filter_speckle: i32, + /// The number of significant bits to use in an RGB channel (more accurate) pub color_precision: i32, + /// The color difference between gradient layers (less layers) pub layer_difference: i32, + /// Curve fitting mode pub mode: JsPathSimplifyMode, + /// Minimum momentary angle (degree) to be considered a corner (smoother) pub corner_threshold: i32, + /// Perform iterative subdivide smooth until all segments are shorter than this length pub length_threshold: f64, + /// The maximum number of iterations to perform pub max_iterations: i32, + /// Minimum angle displacement (degree) to splice a spline (less accurate) pub splice_threshold: i32, + /// Number of decimal places to use in path string pub path_precision: Option, } @@ -106,10 +117,6 @@ pub fn vectorize_raw_sync( vectorize_inner(source.as_ref(), config, Some(args)) } -fn create_config_with_preset(preset: Preset) -> Config { - Config::from_preset(preset) -} - fn vectorize_inner( source: &[u8], config: Option>, @@ -163,7 +170,7 @@ fn resolve_config(config: Option>) -> Config { splice_threshold: config.splice_threshold, path_precision: config.path_precision, }, - Some(Either::B(preset)) => create_config_with_preset(preset), + Some(Either::B(preset)) => Config::from_preset(preset), None => Config::default(), } }