k-centroid-scaler 1.2.1 → 1.2.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/k_centroid_scaler.js +78 -32
- package/k_centroid_scaler_bg.wasm +0 -0
- package/package.json +2 -4
- package/k_centroid_scaler.d.ts +0 -103
package/k_centroid_scaler.js
CHANGED
|
@@ -218,34 +218,92 @@ function passArray8ToWasm0(arg, malloc) {
|
|
|
218
218
|
}
|
|
219
219
|
/**
|
|
220
220
|
* @param {Uint8Array} image_data
|
|
221
|
+
* @param {number} original_width
|
|
222
|
+
* @param {number} original_height
|
|
223
|
+
* @param {number} target_width
|
|
224
|
+
* @param {number} target_height
|
|
225
|
+
* @param {number} centroids
|
|
226
|
+
* @param {number} iterations
|
|
227
|
+
* @returns {ImageResult}
|
|
228
|
+
*/
|
|
229
|
+
export function k_centroid_resize(image_data, original_width, original_height, target_width, target_height, centroids, iterations) {
|
|
230
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
|
|
231
|
+
const len0 = WASM_VECTOR_LEN;
|
|
232
|
+
const ret = wasm.k_centroid_resize(ptr0, len0, original_width, original_height, target_width, target_height, centroids, iterations);
|
|
233
|
+
return ImageResult.__wrap(ret);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @param {Uint8Array} image_data
|
|
238
|
+
* @param {number} width
|
|
239
|
+
* @param {number} height
|
|
221
240
|
* @param {number} num_colors
|
|
222
|
-
* @param {
|
|
223
|
-
* @returns {
|
|
241
|
+
* @param {boolean} dithering
|
|
242
|
+
* @returns {ImageResult}
|
|
224
243
|
*/
|
|
225
|
-
export function
|
|
244
|
+
export function quantize_colors_median_cut(image_data, width, height, num_colors, dithering) {
|
|
226
245
|
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
|
|
227
246
|
const len0 = WASM_VECTOR_LEN;
|
|
228
|
-
const ret = wasm.
|
|
229
|
-
return
|
|
247
|
+
const ret = wasm.quantize_colors_median_cut(ptr0, len0, width, height, num_colors, dithering);
|
|
248
|
+
return ImageResult.__wrap(ret);
|
|
230
249
|
}
|
|
231
250
|
|
|
232
251
|
/**
|
|
233
252
|
* @param {Uint8Array} image_data
|
|
234
|
-
* @param {number}
|
|
235
|
-
* @param {number}
|
|
236
|
-
* @param {number}
|
|
237
|
-
* @param {number} target_height
|
|
238
|
-
* @param {number} centroids
|
|
253
|
+
* @param {number} width
|
|
254
|
+
* @param {number} height
|
|
255
|
+
* @param {number} num_colors
|
|
239
256
|
* @param {number} iterations
|
|
257
|
+
* @param {boolean} dithering
|
|
240
258
|
* @returns {ImageResult}
|
|
241
259
|
*/
|
|
242
|
-
export function
|
|
260
|
+
export function quantize_colors_kmeans(image_data, width, height, num_colors, iterations, dithering) {
|
|
243
261
|
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
|
|
244
262
|
const len0 = WASM_VECTOR_LEN;
|
|
245
|
-
const ret = wasm.
|
|
263
|
+
const ret = wasm.quantize_colors_kmeans(ptr0, len0, width, height, num_colors, iterations, dithering);
|
|
246
264
|
return ImageResult.__wrap(ret);
|
|
247
265
|
}
|
|
248
266
|
|
|
267
|
+
/**
|
|
268
|
+
* @param {Uint8Array} image_data
|
|
269
|
+
* @param {number} num_colors
|
|
270
|
+
* @returns {ColorPalette}
|
|
271
|
+
*/
|
|
272
|
+
export function extract_palette(image_data, num_colors) {
|
|
273
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
|
|
274
|
+
const len0 = WASM_VECTOR_LEN;
|
|
275
|
+
const ret = wasm.extract_palette(ptr0, len0, num_colors);
|
|
276
|
+
return ColorPalette.__wrap(ret);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* @param {Uint8Array} image_data
|
|
281
|
+
* @param {number} max_colors
|
|
282
|
+
* @param {string} sort_method
|
|
283
|
+
* @returns {ColorAnalysis}
|
|
284
|
+
*/
|
|
285
|
+
export function analyze_colors(image_data, max_colors, sort_method) {
|
|
286
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
|
|
287
|
+
const len0 = WASM_VECTOR_LEN;
|
|
288
|
+
const ptr1 = passStringToWasm0(sort_method, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
289
|
+
const len1 = WASM_VECTOR_LEN;
|
|
290
|
+
const ret = wasm.analyze_colors(ptr0, len0, max_colors, ptr1, len1);
|
|
291
|
+
return ColorAnalysis.__wrap(ret);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* @param {Uint8Array} image_data
|
|
296
|
+
* @param {number} num_colors
|
|
297
|
+
* @param {number} min_coverage
|
|
298
|
+
* @returns {ColorAnalysis}
|
|
299
|
+
*/
|
|
300
|
+
export function get_dominant_colors(image_data, num_colors, min_coverage) {
|
|
301
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
|
|
302
|
+
const len0 = WASM_VECTOR_LEN;
|
|
303
|
+
const ret = wasm.get_dominant_colors(ptr0, len0, num_colors, min_coverage);
|
|
304
|
+
return ColorAnalysis.__wrap(ret);
|
|
305
|
+
}
|
|
306
|
+
|
|
249
307
|
/**
|
|
250
308
|
* @param {Uint8Array} data
|
|
251
309
|
* @param {number} width
|
|
@@ -263,26 +321,6 @@ export function process_image(data, width, height, target_width, target_height,
|
|
|
263
321
|
return takeObject(ret);
|
|
264
322
|
}
|
|
265
323
|
|
|
266
|
-
const CentroidFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
267
|
-
? { register: () => {}, unregister: () => {} }
|
|
268
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_centroid_free(ptr >>> 0, 1));
|
|
269
|
-
|
|
270
|
-
export class Centroid {
|
|
271
|
-
|
|
272
|
-
__destroy_into_raw() {
|
|
273
|
-
const ptr = this.__wbg_ptr;
|
|
274
|
-
this.__wbg_ptr = 0;
|
|
275
|
-
CentroidFinalization.unregister(this);
|
|
276
|
-
return ptr;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
free() {
|
|
280
|
-
const ptr = this.__destroy_into_raw();
|
|
281
|
-
wasm.__wbg_centroid_free(ptr, 0);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
if (Symbol.dispose) Centroid.prototype[Symbol.dispose] = Centroid.prototype.free;
|
|
285
|
-
|
|
286
324
|
const ColorAnalysisFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
287
325
|
? { register: () => {}, unregister: () => {} }
|
|
288
326
|
: new FinalizationRegistry(ptr => wasm.__wbg_coloranalysis_free(ptr >>> 0, 1));
|
|
@@ -433,6 +471,14 @@ const ColorPaletteFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
|
433
471
|
|
|
434
472
|
export class ColorPalette {
|
|
435
473
|
|
|
474
|
+
static __wrap(ptr) {
|
|
475
|
+
ptr = ptr >>> 0;
|
|
476
|
+
const obj = Object.create(ColorPalette.prototype);
|
|
477
|
+
obj.__wbg_ptr = ptr;
|
|
478
|
+
ColorPaletteFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
479
|
+
return obj;
|
|
480
|
+
}
|
|
481
|
+
|
|
436
482
|
__destroy_into_raw() {
|
|
437
483
|
const ptr = this.__wbg_ptr;
|
|
438
484
|
this.__wbg_ptr = 0;
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "k-centroid-scaler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.2",
|
|
5
5
|
"files": [
|
|
6
6
|
"k_centroid_scaler_bg.wasm",
|
|
7
|
-
"k_centroid_scaler.js"
|
|
8
|
-
"k_centroid_scaler.d.ts"
|
|
7
|
+
"k_centroid_scaler.js"
|
|
9
8
|
],
|
|
10
9
|
"main": "k_centroid_scaler.js",
|
|
11
|
-
"types": "k_centroid_scaler.d.ts",
|
|
12
10
|
"sideEffects": [
|
|
13
11
|
"./snippets/*"
|
|
14
12
|
]
|
package/k_centroid_scaler.d.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
export function get_dominant_colors(image_data: Uint8Array, num_colors: number, min_coverage: number): ColorAnalysis;
|
|
4
|
-
export function k_centroid_resize(image_data: Uint8Array, original_width: number, original_height: number, target_width: number, target_height: number, centroids: number, iterations: number): ImageResult;
|
|
5
|
-
export function process_image(data: Uint8Array, width: number, height: number, target_width: number, target_height: number, centroids: number, iterations: number): any;
|
|
6
|
-
export class Centroid {
|
|
7
|
-
private constructor();
|
|
8
|
-
free(): void;
|
|
9
|
-
[Symbol.dispose](): void;
|
|
10
|
-
}
|
|
11
|
-
export class ColorAnalysis {
|
|
12
|
-
private constructor();
|
|
13
|
-
free(): void;
|
|
14
|
-
[Symbol.dispose](): void;
|
|
15
|
-
total_colors: number;
|
|
16
|
-
total_pixels: number;
|
|
17
|
-
readonly colors: any[];
|
|
18
|
-
}
|
|
19
|
-
export class ColorInfo {
|
|
20
|
-
private constructor();
|
|
21
|
-
free(): void;
|
|
22
|
-
[Symbol.dispose](): void;
|
|
23
|
-
readonly hex: string;
|
|
24
|
-
readonly percentage: number;
|
|
25
|
-
readonly count: number;
|
|
26
|
-
readonly r: number;
|
|
27
|
-
readonly g: number;
|
|
28
|
-
readonly b: number;
|
|
29
|
-
}
|
|
30
|
-
export class ColorPalette {
|
|
31
|
-
private constructor();
|
|
32
|
-
free(): void;
|
|
33
|
-
[Symbol.dispose](): void;
|
|
34
|
-
count: number;
|
|
35
|
-
readonly colors: Uint8Array;
|
|
36
|
-
}
|
|
37
|
-
export class ImageResult {
|
|
38
|
-
private constructor();
|
|
39
|
-
free(): void;
|
|
40
|
-
[Symbol.dispose](): void;
|
|
41
|
-
width: number;
|
|
42
|
-
height: number;
|
|
43
|
-
readonly data: Uint8Array;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
47
|
-
|
|
48
|
-
export interface InitOutput {
|
|
49
|
-
readonly memory: WebAssembly.Memory;
|
|
50
|
-
readonly __wbg_imageresult_free: (a: number, b: number) => void;
|
|
51
|
-
readonly imageresult_data: (a: number, b: number) => void;
|
|
52
|
-
readonly __wbg_colorpalette_free: (a: number, b: number) => void;
|
|
53
|
-
readonly __wbg_set_colorpalette_count: (a: number, b: number) => void;
|
|
54
|
-
readonly colorpalette_colors: (a: number, b: number) => void;
|
|
55
|
-
readonly __wbg_colorinfo_free: (a: number, b: number) => void;
|
|
56
|
-
readonly colorinfo_hex: (a: number, b: number) => void;
|
|
57
|
-
readonly colorinfo_percentage: (a: number) => number;
|
|
58
|
-
readonly colorinfo_count: (a: number) => number;
|
|
59
|
-
readonly colorinfo_r: (a: number) => number;
|
|
60
|
-
readonly colorinfo_g: (a: number) => number;
|
|
61
|
-
readonly colorinfo_b: (a: number) => number;
|
|
62
|
-
readonly __wbg_coloranalysis_free: (a: number, b: number) => void;
|
|
63
|
-
readonly __wbg_get_coloranalysis_total_colors: (a: number) => number;
|
|
64
|
-
readonly __wbg_set_coloranalysis_total_colors: (a: number, b: number) => void;
|
|
65
|
-
readonly __wbg_get_coloranalysis_total_pixels: (a: number) => number;
|
|
66
|
-
readonly __wbg_set_coloranalysis_total_pixels: (a: number, b: number) => void;
|
|
67
|
-
readonly coloranalysis_colors: (a: number, b: number) => void;
|
|
68
|
-
readonly get_dominant_colors: (a: number, b: number, c: number, d: number) => number;
|
|
69
|
-
readonly __wbg_centroid_free: (a: number, b: number) => void;
|
|
70
|
-
readonly k_centroid_resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
|
|
71
|
-
readonly process_image: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
|
|
72
|
-
readonly __wbg_set_imageresult_width: (a: number, b: number) => void;
|
|
73
|
-
readonly __wbg_set_imageresult_height: (a: number, b: number) => void;
|
|
74
|
-
readonly __wbg_get_colorpalette_count: (a: number) => number;
|
|
75
|
-
readonly __wbg_get_imageresult_height: (a: number) => number;
|
|
76
|
-
readonly __wbg_get_imageresult_width: (a: number) => number;
|
|
77
|
-
readonly __wbindgen_export_0: (a: number) => void;
|
|
78
|
-
readonly __wbindgen_export_1: (a: number, b: number) => number;
|
|
79
|
-
readonly __wbindgen_export_2: (a: number, b: number, c: number, d: number) => number;
|
|
80
|
-
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
81
|
-
readonly __wbindgen_export_3: (a: number, b: number, c: number) => void;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
85
|
-
/**
|
|
86
|
-
* Instantiates the given `module`, which can either be bytes or
|
|
87
|
-
* a precompiled `WebAssembly.Module`.
|
|
88
|
-
*
|
|
89
|
-
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
90
|
-
*
|
|
91
|
-
* @returns {InitOutput}
|
|
92
|
-
*/
|
|
93
|
-
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
97
|
-
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
98
|
-
*
|
|
99
|
-
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
100
|
-
*
|
|
101
|
-
* @returns {Promise<InitOutput>}
|
|
102
|
-
*/
|
|
103
|
-
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|