k-centroid-scaler 1.3.0 → 1.3.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.
- package/k_centroid_scaler.d.ts +3 -22
- package/k_centroid_scaler.js +20 -98
- package/k_centroid_scaler_bg.wasm +0 -0
- package/package.json +1 -1
package/k_centroid_scaler.d.ts
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
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;
|
|
4
|
+
export function quantize_perceptual(image_data: Uint8Array, width: number, height: number, num_colors: number, dithering: boolean): ImageResult;
|
|
18
5
|
export function quantize_colors_median_cut(image_data: Uint8Array, width: number, height: number, num_colors: number, dithering: boolean): ImageResult;
|
|
19
|
-
export function
|
|
20
|
-
export function extract_palette(image_data: Uint8Array, max_colors: number): ColorPalette;
|
|
6
|
+
export function extract_palette(image_data: Uint8Array, num_colors: number): ColorPalette;
|
|
21
7
|
export function analyze_colors(image_data: Uint8Array, max_colors: number, sort_method: string): ColorAnalysis;
|
|
22
8
|
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
9
|
export class ColorAnalysis {
|
|
25
10
|
private constructor();
|
|
26
11
|
free(): void;
|
|
@@ -79,17 +64,13 @@ export interface InitOutput {
|
|
|
79
64
|
readonly __wbg_set_coloranalysis_total_pixels: (a: number, b: number) => void;
|
|
80
65
|
readonly coloranalysis_colors: (a: number, b: number) => void;
|
|
81
66
|
readonly k_centroid_resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
|
|
82
|
-
readonly
|
|
83
|
-
readonly quantize_colors_stage2_lab: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
|
67
|
+
readonly quantize_perceptual: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
|
84
68
|
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
69
|
readonly extract_palette: (a: number, b: number, c: number) => number;
|
|
87
70
|
readonly analyze_colors: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
88
71
|
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
72
|
readonly __wbg_set_imageresult_width: (a: number, b: number) => void;
|
|
91
73
|
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
74
|
readonly __wbg_get_colorpalette_count: (a: number) => number;
|
|
94
75
|
readonly __wbg_get_imageresult_height: (a: number) => number;
|
|
95
76
|
readonly __wbg_get_imageresult_width: (a: number) => number;
|
package/k_centroid_scaler.js
CHANGED
|
@@ -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
|
-
|
|
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}
|
|
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
|
|
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.
|
|
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,
|
|
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,
|
|
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
|