@wonfsy/wonfy-tools 0.1.0 → 0.1.2
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/README.md +13 -1
- package/package.json +1 -1
- package/wonfy_tools.d.ts +23 -4
- package/wonfy_tools.js +202 -23
- package/wonfy_tools_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -6,7 +6,19 @@ You can checkout deployed version with UI on https://tools.won.fyi
|
|
|
6
6
|
#### You can install is as a cli
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
cargo install wonfy-tools
|
|
9
|
+
cargo install wonfy-tools --features cli
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
then use it as
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
wonfy-tools-cli -f ./0.png ./1.png ...
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
can use `--help` to list all possible inputs for the cli
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
wonfy-tools-cli --help
|
|
10
22
|
```
|
|
11
23
|
|
|
12
24
|
#### Or add it as a library
|
package/package.json
CHANGED
package/wonfy_tools.d.ts
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
export function stitch(images: Uint8Array[], direction: string, order: string, window_size
|
|
3
|
+
export function stitch(images: Uint8Array[], direction: string, order: string, window_size: number | null | undefined, match_mode: string | null | undefined, crop_padding: number | null | undefined, preview: Preview | null | undefined, format: EncodeFormat): StitchReturn;
|
|
4
|
+
export function rgba_bytes_to_image(bytes: Uint8Array, width: number, height: number, format: EncodeFormat): ImageWithDHash;
|
|
4
5
|
export function start(): void;
|
|
6
|
+
export function encode_format_content_type(format: EncodeFormat): string;
|
|
7
|
+
export function encode_format_file_extension(format: EncodeFormat): string;
|
|
8
|
+
export enum EncodeFormat {
|
|
9
|
+
Png = 0,
|
|
10
|
+
Jpeg = 1,
|
|
11
|
+
Gif = 2,
|
|
12
|
+
WebP = 3,
|
|
13
|
+
}
|
|
5
14
|
export enum PreviewType {
|
|
6
15
|
Resize = 0,
|
|
7
16
|
MaxWidth = 1,
|
|
8
17
|
MaxHeight = 2,
|
|
9
18
|
}
|
|
19
|
+
export class ImageWithDHash {
|
|
20
|
+
private constructor();
|
|
21
|
+
free(): void;
|
|
22
|
+
images(): [Uint8Array, BigInt];
|
|
23
|
+
}
|
|
10
24
|
export class Preview {
|
|
11
25
|
free(): void;
|
|
12
26
|
constructor(type: PreviewType, value: number);
|
|
@@ -38,12 +52,17 @@ export interface InitOutput {
|
|
|
38
52
|
readonly stitchedimage_toJson: (a: number) => any;
|
|
39
53
|
readonly __wbg_stitchreturn_free: (a: number, b: number) => void;
|
|
40
54
|
readonly stitchreturn_images: (a: number) => any;
|
|
41
|
-
readonly stitch: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => [number, number, number];
|
|
55
|
+
readonly stitch: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => [number, number, number];
|
|
56
|
+
readonly __wbg_imagewithdhash_free: (a: number, b: number) => void;
|
|
57
|
+
readonly imagewithdhash_images: (a: number) => any;
|
|
58
|
+
readonly rgba_bytes_to_image: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
42
59
|
readonly start: () => void;
|
|
43
|
-
readonly
|
|
60
|
+
readonly encode_format_content_type: (a: number) => [number, number];
|
|
61
|
+
readonly encode_format_file_extension: (a: number) => [number, number];
|
|
44
62
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
45
63
|
readonly __externref_table_alloc: () => number;
|
|
46
|
-
readonly
|
|
64
|
+
readonly __wbindgen_export_2: WebAssembly.Table;
|
|
65
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
47
66
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
48
67
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
49
68
|
readonly __externref_table_dealloc: (a: number) => void;
|
package/wonfy_tools.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
let wasm;
|
|
2
2
|
|
|
3
|
+
function addToExternrefTable0(obj) {
|
|
4
|
+
const idx = wasm.__externref_table_alloc();
|
|
5
|
+
wasm.__wbindgen_export_2.set(idx, obj);
|
|
6
|
+
return idx;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function handleError(f, args) {
|
|
10
|
+
try {
|
|
11
|
+
return f.apply(this, args);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
const idx = addToExternrefTable0(e);
|
|
14
|
+
wasm.__wbindgen_exn_store(idx);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
3
18
|
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
4
19
|
|
|
5
20
|
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
@@ -18,21 +33,6 @@ function getStringFromWasm0(ptr, len) {
|
|
|
18
33
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
19
34
|
}
|
|
20
35
|
|
|
21
|
-
function addToExternrefTable0(obj) {
|
|
22
|
-
const idx = wasm.__externref_table_alloc();
|
|
23
|
-
wasm.__wbindgen_export_3.set(idx, obj);
|
|
24
|
-
return idx;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function handleError(f, args) {
|
|
28
|
-
try {
|
|
29
|
-
return f.apply(this, args);
|
|
30
|
-
} catch (e) {
|
|
31
|
-
const idx = addToExternrefTable0(e);
|
|
32
|
-
wasm.__wbindgen_exn_store(idx);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
36
|
let WASM_VECTOR_LEN = 0;
|
|
37
37
|
|
|
38
38
|
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
@@ -98,6 +98,71 @@ function getDataViewMemory0() {
|
|
|
98
98
|
return cachedDataViewMemory0;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
function debugString(val) {
|
|
102
|
+
// primitive types
|
|
103
|
+
const type = typeof val;
|
|
104
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
105
|
+
return `${val}`;
|
|
106
|
+
}
|
|
107
|
+
if (type == 'string') {
|
|
108
|
+
return `"${val}"`;
|
|
109
|
+
}
|
|
110
|
+
if (type == 'symbol') {
|
|
111
|
+
const description = val.description;
|
|
112
|
+
if (description == null) {
|
|
113
|
+
return 'Symbol';
|
|
114
|
+
} else {
|
|
115
|
+
return `Symbol(${description})`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (type == 'function') {
|
|
119
|
+
const name = val.name;
|
|
120
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
121
|
+
return `Function(${name})`;
|
|
122
|
+
} else {
|
|
123
|
+
return 'Function';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// objects
|
|
127
|
+
if (Array.isArray(val)) {
|
|
128
|
+
const length = val.length;
|
|
129
|
+
let debug = '[';
|
|
130
|
+
if (length > 0) {
|
|
131
|
+
debug += debugString(val[0]);
|
|
132
|
+
}
|
|
133
|
+
for(let i = 1; i < length; i++) {
|
|
134
|
+
debug += ', ' + debugString(val[i]);
|
|
135
|
+
}
|
|
136
|
+
debug += ']';
|
|
137
|
+
return debug;
|
|
138
|
+
}
|
|
139
|
+
// Test for built-in
|
|
140
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
141
|
+
let className;
|
|
142
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
143
|
+
className = builtInMatches[1];
|
|
144
|
+
} else {
|
|
145
|
+
// Failed to match the standard '[object ClassName]'
|
|
146
|
+
return toString.call(val);
|
|
147
|
+
}
|
|
148
|
+
if (className == 'Object') {
|
|
149
|
+
// we're a user defined class or Object
|
|
150
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
151
|
+
// easier than looping through ownProperties of `val`.
|
|
152
|
+
try {
|
|
153
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
154
|
+
} catch (_) {
|
|
155
|
+
return 'Object';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// errors
|
|
159
|
+
if (val instanceof Error) {
|
|
160
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
161
|
+
}
|
|
162
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
163
|
+
return className;
|
|
164
|
+
}
|
|
165
|
+
|
|
101
166
|
function getArrayU8FromWasm0(ptr, len) {
|
|
102
167
|
ptr = ptr >>> 0;
|
|
103
168
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
@@ -124,7 +189,7 @@ function _assertClass(instance, klass) {
|
|
|
124
189
|
}
|
|
125
190
|
|
|
126
191
|
function takeFromExternrefTable0(idx) {
|
|
127
|
-
const value = wasm.
|
|
192
|
+
const value = wasm.__wbindgen_export_2.get(idx);
|
|
128
193
|
wasm.__externref_table_dealloc(idx);
|
|
129
194
|
return value;
|
|
130
195
|
}
|
|
@@ -132,13 +197,14 @@ function takeFromExternrefTable0(idx) {
|
|
|
132
197
|
* @param {Uint8Array[]} images
|
|
133
198
|
* @param {string} direction
|
|
134
199
|
* @param {string} order
|
|
135
|
-
* @param {number | null}
|
|
136
|
-
* @param {string | null}
|
|
137
|
-
* @param {number | null}
|
|
138
|
-
* @param {Preview | null}
|
|
200
|
+
* @param {number | null | undefined} window_size
|
|
201
|
+
* @param {string | null | undefined} match_mode
|
|
202
|
+
* @param {number | null | undefined} crop_padding
|
|
203
|
+
* @param {Preview | null | undefined} preview
|
|
204
|
+
* @param {EncodeFormat} format
|
|
139
205
|
* @returns {StitchReturn}
|
|
140
206
|
*/
|
|
141
|
-
export function stitch(images, direction, order, window_size, match_mode, crop_padding, preview) {
|
|
207
|
+
export function stitch(images, direction, order, window_size, match_mode, crop_padding, preview, format) {
|
|
142
208
|
const ptr0 = passArrayJsValueToWasm0(images, wasm.__wbindgen_malloc);
|
|
143
209
|
const len0 = WASM_VECTOR_LEN;
|
|
144
210
|
const ptr1 = passStringToWasm0(direction, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -152,17 +218,80 @@ export function stitch(images, direction, order, window_size, match_mode, crop_p
|
|
|
152
218
|
_assertClass(preview, Preview);
|
|
153
219
|
ptr4 = preview.__destroy_into_raw();
|
|
154
220
|
}
|
|
155
|
-
const ret = wasm.stitch(ptr0, len0, ptr1, len1, ptr2, len2, isLikeNone(window_size) ? 0x100000001 : (window_size) >>> 0, ptr3, len3, isLikeNone(crop_padding) ? 0x100000001 : (crop_padding) >>> 0, ptr4);
|
|
221
|
+
const ret = wasm.stitch(ptr0, len0, ptr1, len1, ptr2, len2, isLikeNone(window_size) ? 0x100000001 : (window_size) >>> 0, ptr3, len3, isLikeNone(crop_padding) ? 0x100000001 : (crop_padding) >>> 0, ptr4, format);
|
|
156
222
|
if (ret[2]) {
|
|
157
223
|
throw takeFromExternrefTable0(ret[1]);
|
|
158
224
|
}
|
|
159
225
|
return StitchReturn.__wrap(ret[0]);
|
|
160
226
|
}
|
|
161
227
|
|
|
228
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
229
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
230
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
231
|
+
WASM_VECTOR_LEN = arg.length;
|
|
232
|
+
return ptr;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* @param {Uint8Array} bytes
|
|
236
|
+
* @param {number} width
|
|
237
|
+
* @param {number} height
|
|
238
|
+
* @param {EncodeFormat} format
|
|
239
|
+
* @returns {ImageWithDHash}
|
|
240
|
+
*/
|
|
241
|
+
export function rgba_bytes_to_image(bytes, width, height, format) {
|
|
242
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
243
|
+
const len0 = WASM_VECTOR_LEN;
|
|
244
|
+
const ret = wasm.rgba_bytes_to_image(ptr0, len0, width, height, format);
|
|
245
|
+
return ImageWithDHash.__wrap(ret);
|
|
246
|
+
}
|
|
247
|
+
|
|
162
248
|
export function start() {
|
|
163
249
|
wasm.start();
|
|
164
250
|
}
|
|
165
251
|
|
|
252
|
+
/**
|
|
253
|
+
* @param {EncodeFormat} format
|
|
254
|
+
* @returns {string}
|
|
255
|
+
*/
|
|
256
|
+
export function encode_format_content_type(format) {
|
|
257
|
+
let deferred1_0;
|
|
258
|
+
let deferred1_1;
|
|
259
|
+
try {
|
|
260
|
+
const ret = wasm.encode_format_content_type(format);
|
|
261
|
+
deferred1_0 = ret[0];
|
|
262
|
+
deferred1_1 = ret[1];
|
|
263
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
264
|
+
} finally {
|
|
265
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @param {EncodeFormat} format
|
|
271
|
+
* @returns {string}
|
|
272
|
+
*/
|
|
273
|
+
export function encode_format_file_extension(format) {
|
|
274
|
+
let deferred1_0;
|
|
275
|
+
let deferred1_1;
|
|
276
|
+
try {
|
|
277
|
+
const ret = wasm.encode_format_file_extension(format);
|
|
278
|
+
deferred1_0 = ret[0];
|
|
279
|
+
deferred1_1 = ret[1];
|
|
280
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
281
|
+
} finally {
|
|
282
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @enum {0 | 1 | 2 | 3}
|
|
288
|
+
*/
|
|
289
|
+
export const EncodeFormat = Object.freeze({
|
|
290
|
+
Png: 0, "0": "Png",
|
|
291
|
+
Jpeg: 1, "1": "Jpeg",
|
|
292
|
+
Gif: 2, "2": "Gif",
|
|
293
|
+
WebP: 3, "3": "WebP",
|
|
294
|
+
});
|
|
166
295
|
/**
|
|
167
296
|
* @enum {0 | 1 | 2}
|
|
168
297
|
*/
|
|
@@ -172,6 +301,41 @@ export const PreviewType = Object.freeze({
|
|
|
172
301
|
MaxHeight: 2, "2": "MaxHeight",
|
|
173
302
|
});
|
|
174
303
|
|
|
304
|
+
const ImageWithDHashFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
305
|
+
? { register: () => {}, unregister: () => {} }
|
|
306
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_imagewithdhash_free(ptr >>> 0, 1));
|
|
307
|
+
|
|
308
|
+
export class ImageWithDHash {
|
|
309
|
+
|
|
310
|
+
static __wrap(ptr) {
|
|
311
|
+
ptr = ptr >>> 0;
|
|
312
|
+
const obj = Object.create(ImageWithDHash.prototype);
|
|
313
|
+
obj.__wbg_ptr = ptr;
|
|
314
|
+
ImageWithDHashFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
315
|
+
return obj;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
__destroy_into_raw() {
|
|
319
|
+
const ptr = this.__wbg_ptr;
|
|
320
|
+
this.__wbg_ptr = 0;
|
|
321
|
+
ImageWithDHashFinalization.unregister(this);
|
|
322
|
+
return ptr;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
free() {
|
|
326
|
+
const ptr = this.__destroy_into_raw();
|
|
327
|
+
wasm.__wbg_imagewithdhash_free(ptr, 0);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* @returns {[Uint8Array, BigInt]}
|
|
331
|
+
*/
|
|
332
|
+
images() {
|
|
333
|
+
const ptr = this.__destroy_into_raw();
|
|
334
|
+
const ret = wasm.imagewithdhash_images(ptr);
|
|
335
|
+
return ret;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
175
339
|
const PreviewFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
176
340
|
? { register: () => {}, unregister: () => {} }
|
|
177
341
|
: new FinalizationRegistry(ptr => wasm.__wbg_preview_free(ptr >>> 0, 1));
|
|
@@ -331,6 +495,10 @@ async function __wbg_load(module, imports) {
|
|
|
331
495
|
function __wbg_get_imports() {
|
|
332
496
|
const imports = {};
|
|
333
497
|
imports.wbg = {};
|
|
498
|
+
imports.wbg.__wbg_BigInt_ddea6d2f55558acb = function() { return handleError(function (arg0) {
|
|
499
|
+
const ret = BigInt(arg0);
|
|
500
|
+
return ret;
|
|
501
|
+
}, arguments) };
|
|
334
502
|
imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
|
|
335
503
|
const ret = arg0.buffer;
|
|
336
504
|
return ret;
|
|
@@ -436,8 +604,19 @@ function __wbg_get_imports() {
|
|
|
436
604
|
const ret = StitchedImage.__wrap(arg0);
|
|
437
605
|
return ret;
|
|
438
606
|
};
|
|
607
|
+
imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
|
|
608
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
609
|
+
return ret;
|
|
610
|
+
};
|
|
611
|
+
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
|
|
612
|
+
const ret = debugString(arg1);
|
|
613
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
614
|
+
const len1 = WASM_VECTOR_LEN;
|
|
615
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
616
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
617
|
+
};
|
|
439
618
|
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
440
|
-
const table = wasm.
|
|
619
|
+
const table = wasm.__wbindgen_export_2;
|
|
441
620
|
const offset = table.grow(4);
|
|
442
621
|
table.set(0, undefined);
|
|
443
622
|
table.set(offset + 0, undefined);
|
package/wonfy_tools_bg.wasm
CHANGED
|
Binary file
|