k-centroid-scaler 1.2.0 → 1.2.1

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.
@@ -0,0 +1,103 @@
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>;
@@ -218,92 +218,34 @@ 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
240
221
  * @param {number} num_colors
241
- * @param {boolean} dithering
242
- * @returns {ImageResult}
222
+ * @param {number} min_coverage
223
+ * @returns {ColorAnalysis}
243
224
  */
244
- export function quantize_colors_median_cut(image_data, width, height, num_colors, dithering) {
225
+ export function get_dominant_colors(image_data, num_colors, min_coverage) {
245
226
  const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
246
227
  const len0 = WASM_VECTOR_LEN;
247
- const ret = wasm.quantize_colors_median_cut(ptr0, len0, width, height, num_colors, dithering);
248
- return ImageResult.__wrap(ret);
228
+ const ret = wasm.get_dominant_colors(ptr0, len0, num_colors, min_coverage);
229
+ return ColorAnalysis.__wrap(ret);
249
230
  }
250
231
 
251
232
  /**
252
233
  * @param {Uint8Array} image_data
253
- * @param {number} width
254
- * @param {number} height
255
- * @param {number} num_colors
234
+ * @param {number} original_width
235
+ * @param {number} original_height
236
+ * @param {number} target_width
237
+ * @param {number} target_height
238
+ * @param {number} centroids
256
239
  * @param {number} iterations
257
- * @param {boolean} dithering
258
240
  * @returns {ImageResult}
259
241
  */
260
- export function quantize_colors_kmeans(image_data, width, height, num_colors, iterations, dithering) {
242
+ export function k_centroid_resize(image_data, original_width, original_height, target_width, target_height, centroids, iterations) {
261
243
  const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
262
244
  const len0 = WASM_VECTOR_LEN;
263
- const ret = wasm.quantize_colors_kmeans(ptr0, len0, width, height, num_colors, iterations, dithering);
245
+ const ret = wasm.k_centroid_resize(ptr0, len0, original_width, original_height, target_width, target_height, centroids, iterations);
264
246
  return ImageResult.__wrap(ret);
265
247
  }
266
248
 
267
- /**
268
- * @param {Uint8Array} image_data
269
- * @param {number} max_colors
270
- * @returns {ColorPalette}
271
- */
272
- export function extract_palette(image_data, max_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, max_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
-
307
249
  /**
308
250
  * @param {Uint8Array} data
309
251
  * @param {number} width
@@ -321,6 +263,26 @@ export function process_image(data, width, height, target_width, target_height,
321
263
  return takeObject(ret);
322
264
  }
323
265
 
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
+
324
286
  const ColorAnalysisFinalization = (typeof FinalizationRegistry === 'undefined')
325
287
  ? { register: () => {}, unregister: () => {} }
326
288
  : new FinalizationRegistry(ptr => wasm.__wbg_coloranalysis_free(ptr >>> 0, 1));
@@ -471,14 +433,6 @@ const ColorPaletteFinalization = (typeof FinalizationRegistry === 'undefined')
471
433
 
472
434
  export class ColorPalette {
473
435
 
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
-
482
436
  __destroy_into_raw() {
483
437
  const ptr = this.__wbg_ptr;
484
438
  this.__wbg_ptr = 0;
Binary file
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "k-centroid-scaler",
3
3
  "type": "module",
4
- "version": "1.2.0",
4
+ "version": "1.2.1",
5
5
  "files": [
6
6
  "k_centroid_scaler_bg.wasm",
7
- "k_centroid_scaler.js"
7
+ "k_centroid_scaler.js",
8
+ "k_centroid_scaler.d.ts"
8
9
  ],
9
10
  "main": "k_centroid_scaler.js",
11
+ "types": "k_centroid_scaler.d.ts",
10
12
  "sideEffects": [
11
13
  "./snippets/*"
12
14
  ]