k-centroid-scaler 1.3.0 → 1.3.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.
@@ -4,8 +4,6 @@ let heap = new Array(128).fill(undefined);
4
4
 
5
5
  heap.push(undefined, null, true, false);
6
6
 
7
- function getObject(idx) { return heap[idx]; }
8
-
9
7
  let heap_next = heap.length;
10
8
 
11
9
  function addHeapObject(obj) {
@@ -17,19 +15,7 @@ function addHeapObject(obj) {
17
15
  return idx;
18
16
  }
19
17
 
20
- let cachedUint8ArrayMemory0 = null;
21
-
22
- function getUint8ArrayMemory0() {
23
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
24
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
25
- }
26
- return cachedUint8ArrayMemory0;
27
- }
28
-
29
- function getArrayU8FromWasm0(ptr, len) {
30
- ptr = ptr >>> 0;
31
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
32
- }
18
+ function getObject(idx) { return heap[idx]; }
33
19
 
34
20
  function handleError(f, args) {
35
21
  try {
@@ -106,6 +92,15 @@ function debugString(val) {
106
92
 
107
93
  let WASM_VECTOR_LEN = 0;
108
94
 
95
+ let cachedUint8ArrayMemory0 = null;
96
+
97
+ function getUint8ArrayMemory0() {
98
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
99
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
100
+ }
101
+ return cachedUint8ArrayMemory0;
102
+ }
103
+
109
104
  const cachedTextEncoder = new TextEncoder();
110
105
 
111
106
  if (!('encodeInto' in cachedTextEncoder)) {
@@ -200,6 +195,11 @@ function takeObject(idx) {
200
195
  return ret;
201
196
  }
202
197
 
198
+ function getArrayU8FromWasm0(ptr, len) {
199
+ ptr = ptr >>> 0;
200
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
201
+ }
202
+
203
203
  function getArrayJsValueFromWasm0(ptr, len) {
204
204
  ptr = ptr >>> 0;
205
205
  const mem = getDataViewMemory0();
@@ -234,51 +234,17 @@ export function k_centroid_resize(image_data, original_width, original_height, t
234
234
  }
235
235
 
236
236
  /**
237
- * Stage 1: Fast quantization to 256 colors or less using k-means++ in RGB space
238
- * This stage is fast and doesn't alter tints significantly
239
237
  * @param {Uint8Array} image_data
240
238
  * @param {number} width
241
239
  * @param {number} height
242
- * @param {number} target_colors
243
- * @returns {ImageResult}
244
- */
245
- export function quantize_colors_stage1(image_data, width, height, target_colors) {
246
- const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
247
- const len0 = WASM_VECTOR_LEN;
248
- const ret = wasm.quantize_colors_stage1(ptr0, len0, width, height, target_colors);
249
- return ImageResult.__wrap(ret);
250
- }
251
-
252
- /**
253
- * Stage 2: Perceptually accurate quantization using CIELAB color space
254
- * Best for final color reduction where human perception matters
255
- * @param {Uint8Array} image_data
256
- * @param {number} width
257
- * @param {number} height
258
- * @param {number} target_colors
259
- * @param {boolean} dithering
260
- * @returns {ImageResult}
261
- */
262
- export function quantize_colors_stage2_lab(image_data, width, height, target_colors, dithering) {
263
- const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
264
- const len0 = WASM_VECTOR_LEN;
265
- const ret = wasm.quantize_colors_stage2_lab(ptr0, len0, width, height, target_colors, dithering);
266
- return ImageResult.__wrap(ret);
267
- }
268
-
269
- /**
270
- * Complete two-stage quantization: Stage 1 (fast) -> Stage 2 (perceptual)
271
- * @param {Uint8Array} image_data
272
- * @param {number} width
273
- * @param {number} height
274
- * @param {number} target_colors
240
+ * @param {number} num_colors
275
241
  * @param {boolean} dithering
276
242
  * @returns {ImageResult}
277
243
  */
278
- export function quantize_colors_two_stage(image_data, width, height, target_colors, dithering) {
244
+ export function quantize_perceptual(image_data, width, height, num_colors, dithering) {
279
245
  const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
280
246
  const len0 = WASM_VECTOR_LEN;
281
- const ret = wasm.quantize_colors_median_cut(ptr0, len0, width, height, target_colors, dithering);
247
+ const ret = wasm.quantize_perceptual(ptr0, len0, width, height, num_colors, dithering);
282
248
  return ImageResult.__wrap(ret);
283
249
  }
284
250
 
@@ -299,29 +265,13 @@ export function quantize_colors_median_cut(image_data, width, height, num_colors
299
265
 
300
266
  /**
301
267
  * @param {Uint8Array} image_data
302
- * @param {number} width
303
- * @param {number} height
304
268
  * @param {number} num_colors
305
- * @param {number} _iterations
306
- * @param {boolean} dithering
307
- * @returns {ImageResult}
308
- */
309
- export function quantize_colors_kmeans(image_data, width, height, num_colors, _iterations, dithering) {
310
- const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
311
- const len0 = WASM_VECTOR_LEN;
312
- const ret = wasm.quantize_colors_kmeans(ptr0, len0, width, height, num_colors, _iterations, dithering);
313
- return ImageResult.__wrap(ret);
314
- }
315
-
316
- /**
317
- * @param {Uint8Array} image_data
318
- * @param {number} max_colors
319
269
  * @returns {ColorPalette}
320
270
  */
321
- export function extract_palette(image_data, max_colors) {
271
+ export function extract_palette(image_data, num_colors) {
322
272
  const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
323
273
  const len0 = WASM_VECTOR_LEN;
324
- const ret = wasm.extract_palette(ptr0, len0, max_colors);
274
+ const ret = wasm.extract_palette(ptr0, len0, num_colors);
325
275
  return ColorPalette.__wrap(ret);
326
276
  }
327
277
 
@@ -353,23 +303,6 @@ export function get_dominant_colors(image_data, num_colors, min_coverage) {
353
303
  return ColorAnalysis.__wrap(ret);
354
304
  }
355
305
 
356
- /**
357
- * @param {Uint8Array} data
358
- * @param {number} width
359
- * @param {number} height
360
- * @param {number} target_width
361
- * @param {number} target_height
362
- * @param {number} centroids
363
- * @param {number} iterations
364
- * @returns {any}
365
- */
366
- export function process_image(data, width, height, target_width, target_height, centroids, iterations) {
367
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_1);
368
- const len0 = WASM_VECTOR_LEN;
369
- const ret = wasm.process_image(ptr0, len0, width, height, target_width, target_height, centroids, iterations);
370
- return takeObject(ret);
371
- }
372
-
373
306
  const ColorAnalysisFinalization = (typeof FinalizationRegistry === 'undefined')
374
307
  ? { register: () => {}, unregister: () => {} }
375
308
  : new FinalizationRegistry(ptr => wasm.__wbg_coloranalysis_free(ptr >>> 0, 1));
@@ -679,21 +612,10 @@ async function __wbg_load(module, imports) {
679
612
  function __wbg_get_imports() {
680
613
  const imports = {};
681
614
  imports.wbg = {};
682
- imports.wbg.__wbg_length_6bb7e81f9d7713e4 = function(arg0) {
683
- const ret = getObject(arg0).length;
684
- return ret;
685
- };
686
615
  imports.wbg.__wbg_new_19c25a3f2fa63a02 = function() {
687
616
  const ret = new Object();
688
617
  return addHeapObject(ret);
689
618
  };
690
- imports.wbg.__wbg_newwithlength_a167dcc7aaa3ba77 = function(arg0) {
691
- const ret = new Uint8Array(arg0 >>> 0);
692
- return addHeapObject(ret);
693
- };
694
- imports.wbg.__wbg_set_1353b2a5e96bc48c = function(arg0, arg1, arg2) {
695
- getObject(arg0).set(getArrayU8FromWasm0(arg1, arg2));
696
- };
697
619
  imports.wbg.__wbg_set_453345bcda80b89a = function() { return handleError(function (arg0, arg1, arg2) {
698
620
  const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
699
621
  return ret;
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.3.0",
4
+ "version": "1.3.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
  ]
@@ -1,122 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- 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;
4
- /**
5
- * Stage 1: Fast quantization to 256 colors or less using k-means++ in RGB space
6
- * This stage is fast and doesn't alter tints significantly
7
- */
8
- export function quantize_colors_stage1(image_data: Uint8Array, width: number, height: number, target_colors: number): ImageResult;
9
- /**
10
- * Stage 2: Perceptually accurate quantization using CIELAB color space
11
- * Best for final color reduction where human perception matters
12
- */
13
- export function quantize_colors_stage2_lab(image_data: Uint8Array, width: number, height: number, target_colors: number, dithering: boolean): ImageResult;
14
- /**
15
- * Complete two-stage quantization: Stage 1 (fast) -> Stage 2 (perceptual)
16
- */
17
- export function quantize_colors_two_stage(image_data: Uint8Array, width: number, height: number, target_colors: number, dithering: boolean): ImageResult;
18
- export function quantize_colors_median_cut(image_data: Uint8Array, width: number, height: number, num_colors: number, dithering: boolean): ImageResult;
19
- export function quantize_colors_kmeans(image_data: Uint8Array, width: number, height: number, num_colors: number, _iterations: number, dithering: boolean): ImageResult;
20
- export function extract_palette(image_data: Uint8Array, max_colors: number): ColorPalette;
21
- export function analyze_colors(image_data: Uint8Array, max_colors: number, sort_method: string): ColorAnalysis;
22
- export function get_dominant_colors(image_data: Uint8Array, num_colors: number, min_coverage: number): ColorAnalysis;
23
- export function process_image(data: Uint8Array, width: number, height: number, target_width: number, target_height: number, centroids: number, iterations: number): any;
24
- export class ColorAnalysis {
25
- private constructor();
26
- free(): void;
27
- [Symbol.dispose](): void;
28
- total_colors: number;
29
- total_pixels: number;
30
- readonly colors: any[];
31
- }
32
- export class ColorInfo {
33
- private constructor();
34
- free(): void;
35
- [Symbol.dispose](): void;
36
- readonly hex: string;
37
- readonly percentage: number;
38
- readonly count: number;
39
- readonly r: number;
40
- readonly g: number;
41
- readonly b: number;
42
- }
43
- export class ColorPalette {
44
- private constructor();
45
- free(): void;
46
- [Symbol.dispose](): void;
47
- count: number;
48
- readonly colors: Uint8Array;
49
- }
50
- export class ImageResult {
51
- private constructor();
52
- free(): void;
53
- [Symbol.dispose](): void;
54
- width: number;
55
- height: number;
56
- readonly data: Uint8Array;
57
- }
58
-
59
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
60
-
61
- export interface InitOutput {
62
- readonly memory: WebAssembly.Memory;
63
- readonly __wbg_imageresult_free: (a: number, b: number) => void;
64
- readonly imageresult_data: (a: number, b: number) => void;
65
- readonly __wbg_colorpalette_free: (a: number, b: number) => void;
66
- readonly __wbg_set_colorpalette_count: (a: number, b: number) => void;
67
- readonly colorpalette_colors: (a: number, b: number) => void;
68
- readonly __wbg_colorinfo_free: (a: number, b: number) => void;
69
- readonly colorinfo_hex: (a: number, b: number) => void;
70
- readonly colorinfo_percentage: (a: number) => number;
71
- readonly colorinfo_count: (a: number) => number;
72
- readonly colorinfo_r: (a: number) => number;
73
- readonly colorinfo_g: (a: number) => number;
74
- readonly colorinfo_b: (a: number) => number;
75
- readonly __wbg_coloranalysis_free: (a: number, b: number) => void;
76
- readonly __wbg_get_coloranalysis_total_colors: (a: number) => number;
77
- readonly __wbg_set_coloranalysis_total_colors: (a: number, b: number) => void;
78
- readonly __wbg_get_coloranalysis_total_pixels: (a: number) => number;
79
- readonly __wbg_set_coloranalysis_total_pixels: (a: number, b: number) => void;
80
- readonly coloranalysis_colors: (a: number, b: number) => void;
81
- readonly k_centroid_resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
82
- readonly quantize_colors_stage1: (a: number, b: number, c: number, d: number, e: number) => number;
83
- readonly quantize_colors_stage2_lab: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
84
- readonly quantize_colors_median_cut: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
85
- readonly quantize_colors_kmeans: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
86
- readonly extract_palette: (a: number, b: number, c: number) => number;
87
- readonly analyze_colors: (a: number, b: number, c: number, d: number, e: number) => number;
88
- readonly get_dominant_colors: (a: number, b: number, c: number, d: number) => number;
89
- readonly process_image: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
90
- readonly __wbg_set_imageresult_width: (a: number, b: number) => void;
91
- readonly __wbg_set_imageresult_height: (a: number, b: number) => void;
92
- readonly quantize_colors_two_stage: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
93
- readonly __wbg_get_colorpalette_count: (a: number) => number;
94
- readonly __wbg_get_imageresult_height: (a: number) => number;
95
- readonly __wbg_get_imageresult_width: (a: number) => number;
96
- readonly __wbindgen_export_0: (a: number) => void;
97
- readonly __wbindgen_export_1: (a: number, b: number) => number;
98
- readonly __wbindgen_export_2: (a: number, b: number, c: number, d: number) => number;
99
- readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
100
- readonly __wbindgen_export_3: (a: number, b: number, c: number) => void;
101
- }
102
-
103
- export type SyncInitInput = BufferSource | WebAssembly.Module;
104
- /**
105
- * Instantiates the given `module`, which can either be bytes or
106
- * a precompiled `WebAssembly.Module`.
107
- *
108
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
109
- *
110
- * @returns {InitOutput}
111
- */
112
- export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
113
-
114
- /**
115
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
116
- * for everything else, calls `WebAssembly.instantiate` directly.
117
- *
118
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
119
- *
120
- * @returns {Promise<InitOutput>}
121
- */
122
- export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;