img2num 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/dist/browser/__vite-browser-external-CSF28Lpk.js +1 -0
- package/dist/browser/img2num.js +179 -0
- package/dist/browser/wasmWorker-BVnzGxvB.js +2 -0
- package/{wasmWorker.js → dist/browser/wasmWorker.js} +31 -5
- package/dist/node/img2num.js +514 -0
- package/dist/node/index.js +2 -0
- package/dist/node/index.wasm +0 -0
- package/dist/node/wasmWorker-CpNpexYK.js +4471 -0
- package/dist/node/wasmWorker.js +198 -0
- package/dist/node/webgpu-BjVEVfI9.js +23 -0
- package/package.json +23 -13
- package/{safeWasmWrappers.js → src/safeWasmWrappers.js} +9 -7
- package/src/target/browser/worker.js +10 -0
- package/src/target/node/webgpu.js +35 -0
- package/src/target/node/worker.js +20 -0
- package/{wasmClient.js → src/wasmClient.js} +30 -15
- package/src/workers/wasmWorker.js +243 -0
- package/tsconfig.typedoc.json +23 -0
- package/vite.config.js +74 -0
- package/build-wasm/index.js +0 -14
- package/build-wasm/index.wasm +0 -0
- /package/{imageToUint8ClampedArray.js → src/imageToUint8ClampedArray.js} +0 -0
- /package/{index.js → src/index.js} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.2.0](https://github.com/Ryan-Millard/Img2Num/compare/packages-js-v0.1.0...packages-js-v0.2.0) (2026-06-27)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
* **core:** prevent holes during SVG generation ([#429](https://github.com/Ryan-Millard/Img2Num/issues/429))
|
|
9
|
+
|
|
10
|
+
### 🐛 Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **ci:** add NPM_TOKEN to npm publish step so packages/js can authenticate and publish to the npm registry ([2427d1d](https://github.com/Ryan-Millard/Img2Num/commit/2427d1d3c67b9ebafcbf3a5021ed335a3d0683fc))
|
|
13
|
+
* **core:** add MSVC support via conditional compiler directives ([2427d1d](https://github.com/Ryan-Millard/Img2Num/commit/2427d1d3c67b9ebafcbf3a5021ed335a3d0683fc))
|
|
14
|
+
* **core:** prevent holes during SVG generation ([#429](https://github.com/Ryan-Millard/Img2Num/issues/429)) ([14e49f9](https://github.com/Ryan-Millard/Img2Num/commit/14e49f9a05496524e0190ddddf14283fbc907c0b))
|
|
15
|
+
* fix broken v0.1.0 release pipeline ([#417](https://github.com/Ryan-Millard/Img2Num/issues/417)) ([2427d1d](https://github.com/Ryan-Millard/Img2Num/commit/2427d1d3c67b9ebafcbf3a5021ed335a3d0683fc))
|
|
16
|
+
* **packages/js:** support browser and node builds from shared Vite setup ([#449](https://github.com/Ryan-Millard/Img2Num/issues/449)) ([0b2467c](https://github.com/Ryan-Millard/Img2Num/commit/0b2467c672474ef438f17ade91bfb7ed966632ca))
|
|
17
|
+
* **packages/py:** include third_party/ in sdist and disable example ([2427d1d](https://github.com/Ryan-Millard/Img2Num/commit/2427d1d3c67b9ebafcbf3a5021ed335a3d0683fc))
|
|
18
|
+
|
|
19
|
+
## 0.1.0 (2026-05-29)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### ⚠ BREAKING CHANGES
|
|
23
|
+
|
|
24
|
+
* **api:** remove draw_contour_borders from labels_to_svg ([#283](https://github.com/Ryan-Millard/Img2Num/issues/283))
|
|
25
|
+
|
|
26
|
+
### ✨ Features
|
|
27
|
+
|
|
28
|
+
* unified image_to_svg function as complete pipeline ([#335](https://github.com/Ryan-Millard/Img2Num/issues/335)) ([bdba68c](https://github.com/Ryan-Millard/Img2Num/commit/bdba68c8adbbf79a163aba9df25849c5ff36a6b9))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### 🐛 Bug Fixes
|
|
32
|
+
|
|
33
|
+
* **packages/js:** Remote property injection in wasmWorker.js ([#346](https://github.com/Ryan-Millard/Img2Num/issues/346)) ([dfe3afe](https://github.com/Ryan-Millard/Img2Num/commit/dfe3afe55dc380c89e9d8cb38df350a178ee3caf))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### ⚡ Performance Improvements
|
|
37
|
+
|
|
38
|
+
* **gpu:** add WebGPU acceleration with automatic fallback to CPU ([#272](https://github.com/Ryan-Millard/Img2Num/issues/272)) ([c385319](https://github.com/Ryan-Millard/Img2Num/commit/c3853198aaf72e00888352653bf44fe129261201))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### ♻️ Refactoring
|
|
42
|
+
|
|
43
|
+
* **api:** remove draw_contour_borders from labels_to_svg ([#283](https://github.com/Ryan-Millard/Img2Num/issues/283)) ([eee9b31](https://github.com/Ryan-Millard/Img2Num/commit/eee9b3135b5b651a20cc8ffab74bcef073b74b6a))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./wasmWorker-BVnzGxvB.js";var t=e(((e,t)=>{t.exports={}}));export default t();
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
//#region src/imageToUint8ClampedArray.js
|
|
2
|
+
function e(e) {
|
|
3
|
+
return new Promise((t) => {
|
|
4
|
+
let n = new Image();
|
|
5
|
+
n.onload = () => {
|
|
6
|
+
let e = document.createElement("canvas");
|
|
7
|
+
e.width = n.width, e.height = n.height;
|
|
8
|
+
let r = e.getContext("2d");
|
|
9
|
+
r.drawImage(n, 0, 0);
|
|
10
|
+
let { data: i } = r.getImageData(0, 0, n.width, n.height);
|
|
11
|
+
t({
|
|
12
|
+
pixels: i,
|
|
13
|
+
width: n.width,
|
|
14
|
+
height: n.height
|
|
15
|
+
});
|
|
16
|
+
}, n.src = URL.createObjectURL(e);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/target/browser/worker.js
|
|
21
|
+
async function t() {
|
|
22
|
+
let e = new Worker(new URL(
|
|
23
|
+
/* @vite-ignore */
|
|
24
|
+
"" + new URL("wasmWorker-BVnzGxvB.js", import.meta.url).href,
|
|
25
|
+
"" + import.meta.url
|
|
26
|
+
), { type: "module" });
|
|
27
|
+
return {
|
|
28
|
+
postMessage: (t) => e.postMessage(t),
|
|
29
|
+
onMessage: (t) => e.onmessage = (e) => t(e.data),
|
|
30
|
+
onError: (t) => e.onerror = t,
|
|
31
|
+
terminate: () => e.terminate()
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/wasmClient.js
|
|
36
|
+
var n, r = 0, i = /* @__PURE__ */ new Map(), a = !1;
|
|
37
|
+
function o(e) {
|
|
38
|
+
let t = i.get(e.id);
|
|
39
|
+
t && (i.delete(e.id), e.error ? t.reject(Error(e.error)) : t.resolve({
|
|
40
|
+
output: e.output,
|
|
41
|
+
returnValue: e.returnValue
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
async function s() {
|
|
45
|
+
a ||= (n = await t(), n.onMessage(o), n.onError((e) => {
|
|
46
|
+
let t = e.message || "WASM worker error", n = /* @__PURE__ */ Error(`[Img2Num wasmClient] Error: ${t}`);
|
|
47
|
+
for (let [e, t] of i) t.reject(n);
|
|
48
|
+
i.clear();
|
|
49
|
+
}), !0);
|
|
50
|
+
}
|
|
51
|
+
async function c({ funcName: e, args: t = {}, bufferKeys: o = [], returnType: s = "void" }) {
|
|
52
|
+
if (!a) throw Error("WASM worker not initialized. Call initWasmWorker() first.");
|
|
53
|
+
let c = r++;
|
|
54
|
+
return new Promise((r, a) => {
|
|
55
|
+
i.set(c, {
|
|
56
|
+
resolve: r,
|
|
57
|
+
reject: a
|
|
58
|
+
}), n.postMessage({
|
|
59
|
+
id: c,
|
|
60
|
+
funcName: e,
|
|
61
|
+
args: t,
|
|
62
|
+
bufferKeys: o,
|
|
63
|
+
returnType: s
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/safeWasmWrappers.js
|
|
69
|
+
await s();
|
|
70
|
+
var l = async ({ pixels: e, width: t, height: n, sigma_pixels: r = t * .005 }) => (await c({
|
|
71
|
+
funcName: "gaussian_blur_fft",
|
|
72
|
+
args: {
|
|
73
|
+
pixels: e,
|
|
74
|
+
width: t,
|
|
75
|
+
height: n,
|
|
76
|
+
sigma_pixels: r
|
|
77
|
+
},
|
|
78
|
+
bufferKeys: [{
|
|
79
|
+
key: "pixels",
|
|
80
|
+
type: "Uint8ClampedArray"
|
|
81
|
+
}]
|
|
82
|
+
})).output.pixels, u = async ({ pixels: e, width: t, height: n, sigma_spatial: r = 3, sigma_range: i = 50, color_space: a = 0 }) => (await c({
|
|
83
|
+
funcName: "bilateral_filter",
|
|
84
|
+
args: {
|
|
85
|
+
pixels: e,
|
|
86
|
+
width: t,
|
|
87
|
+
height: n,
|
|
88
|
+
sigma_spatial: r,
|
|
89
|
+
sigma_range: i,
|
|
90
|
+
color_space: a
|
|
91
|
+
},
|
|
92
|
+
bufferKeys: [{
|
|
93
|
+
key: "pixels",
|
|
94
|
+
type: "Uint8ClampedArray"
|
|
95
|
+
}]
|
|
96
|
+
})).output.pixels, d = async ({ pixels: e, width: t, height: n, num_colors: r }) => (await c({
|
|
97
|
+
funcName: "black_threshold_image",
|
|
98
|
+
args: {
|
|
99
|
+
pixels: e,
|
|
100
|
+
width: t,
|
|
101
|
+
height: n,
|
|
102
|
+
num_colors: r
|
|
103
|
+
},
|
|
104
|
+
bufferKeys: [{
|
|
105
|
+
key: "pixels",
|
|
106
|
+
type: "Uint8ClampedArray"
|
|
107
|
+
}]
|
|
108
|
+
})).output.pixels, f = async ({ pixels: e, out_pixels: t = new Uint8ClampedArray(e.length), out_labels: n = new Int32Array(e.length / 4), width: r, height: i, num_colors: a, max_iter: o = 100, color_space: s = 0 }) => {
|
|
109
|
+
let l = await c({
|
|
110
|
+
funcName: "kmeans",
|
|
111
|
+
args: {
|
|
112
|
+
pixels: e,
|
|
113
|
+
out_pixels: t,
|
|
114
|
+
out_labels: n,
|
|
115
|
+
width: r,
|
|
116
|
+
height: i,
|
|
117
|
+
num_colors: a,
|
|
118
|
+
max_iter: o,
|
|
119
|
+
color_space: s
|
|
120
|
+
},
|
|
121
|
+
bufferKeys: [
|
|
122
|
+
{
|
|
123
|
+
key: "pixels",
|
|
124
|
+
type: "Uint8ClampedArray"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
key: "out_pixels",
|
|
128
|
+
type: "Uint8ClampedArray"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
key: "out_labels",
|
|
132
|
+
type: "Int32Array"
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
pixels: l.output.out_pixels,
|
|
138
|
+
labels: l.output.out_labels
|
|
139
|
+
};
|
|
140
|
+
}, p = async ({ pixels: e, labels: t, width: n, height: r, min_area: i = 100, min_thickness: a = 10 }) => ({ svg: (await c({
|
|
141
|
+
funcName: "labels_to_svg",
|
|
142
|
+
args: {
|
|
143
|
+
pixels: e,
|
|
144
|
+
labels: t,
|
|
145
|
+
width: n,
|
|
146
|
+
height: r,
|
|
147
|
+
min_area: i,
|
|
148
|
+
min_thickness: a
|
|
149
|
+
},
|
|
150
|
+
bufferKeys: [{
|
|
151
|
+
key: "pixels",
|
|
152
|
+
type: "Uint8ClampedArray"
|
|
153
|
+
}, {
|
|
154
|
+
key: "labels",
|
|
155
|
+
type: "Int32Array"
|
|
156
|
+
}],
|
|
157
|
+
returnType: "string"
|
|
158
|
+
})).returnValue }), m = async ({ pixels: e, width: t, height: n, sigma_spatial: r = 3, sigma_range: i = 50, num_colors: a = 16, max_iter: o = 100, min_area: s = 100, min_thickness: l = 10, color_space: u = 0 }) => ({ svg: (await c({
|
|
159
|
+
funcName: "image_to_svg",
|
|
160
|
+
args: {
|
|
161
|
+
pixels: e,
|
|
162
|
+
width: t,
|
|
163
|
+
height: n,
|
|
164
|
+
sigma_spatial: r,
|
|
165
|
+
sigma_range: i,
|
|
166
|
+
num_colors: a,
|
|
167
|
+
max_iter: o,
|
|
168
|
+
min_area: s,
|
|
169
|
+
min_thickness: l,
|
|
170
|
+
color_space: u
|
|
171
|
+
},
|
|
172
|
+
bufferKeys: [{
|
|
173
|
+
key: "pixels",
|
|
174
|
+
type: "Uint8ClampedArray"
|
|
175
|
+
}],
|
|
176
|
+
returnType: "string"
|
|
177
|
+
})).returnValue });
|
|
178
|
+
//#endregion
|
|
179
|
+
export { u as bilateralFilter, d as blackThreshold, p as findContours, l as gaussianBlur, m as imageToSvg, e as imageToUint8ClampedArray, f as kmeans };
|