k-centroid-scaler 1.3.7 → 1.3.8
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 +87 -159
- package/k_centroid_scaler_bg.wasm +0 -0
- package/package.json +1 -1
package/k_centroid_scaler.js
CHANGED
|
@@ -25,73 +25,6 @@ function handleError(f, args) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function debugString(val) {
|
|
29
|
-
// primitive types
|
|
30
|
-
const type = typeof val;
|
|
31
|
-
if (type == 'number' || type == 'boolean' || val == null) {
|
|
32
|
-
return `${val}`;
|
|
33
|
-
}
|
|
34
|
-
if (type == 'string') {
|
|
35
|
-
return `"${val}"`;
|
|
36
|
-
}
|
|
37
|
-
if (type == 'symbol') {
|
|
38
|
-
const description = val.description;
|
|
39
|
-
if (description == null) {
|
|
40
|
-
return 'Symbol';
|
|
41
|
-
} else {
|
|
42
|
-
return `Symbol(${description})`;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (type == 'function') {
|
|
46
|
-
const name = val.name;
|
|
47
|
-
if (typeof name == 'string' && name.length > 0) {
|
|
48
|
-
return `Function(${name})`;
|
|
49
|
-
} else {
|
|
50
|
-
return 'Function';
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// objects
|
|
54
|
-
if (Array.isArray(val)) {
|
|
55
|
-
const length = val.length;
|
|
56
|
-
let debug = '[';
|
|
57
|
-
if (length > 0) {
|
|
58
|
-
debug += debugString(val[0]);
|
|
59
|
-
}
|
|
60
|
-
for(let i = 1; i < length; i++) {
|
|
61
|
-
debug += ', ' + debugString(val[i]);
|
|
62
|
-
}
|
|
63
|
-
debug += ']';
|
|
64
|
-
return debug;
|
|
65
|
-
}
|
|
66
|
-
// Test for built-in
|
|
67
|
-
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
68
|
-
let className;
|
|
69
|
-
if (builtInMatches && builtInMatches.length > 1) {
|
|
70
|
-
className = builtInMatches[1];
|
|
71
|
-
} else {
|
|
72
|
-
// Failed to match the standard '[object ClassName]'
|
|
73
|
-
return toString.call(val);
|
|
74
|
-
}
|
|
75
|
-
if (className == 'Object') {
|
|
76
|
-
// we're a user defined class or Object
|
|
77
|
-
// JSON.stringify avoids problems with cycles, and is generally much
|
|
78
|
-
// easier than looping through ownProperties of `val`.
|
|
79
|
-
try {
|
|
80
|
-
return 'Object(' + JSON.stringify(val) + ')';
|
|
81
|
-
} catch (_) {
|
|
82
|
-
return 'Object';
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// errors
|
|
86
|
-
if (val instanceof Error) {
|
|
87
|
-
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
88
|
-
}
|
|
89
|
-
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
90
|
-
return className;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let WASM_VECTOR_LEN = 0;
|
|
94
|
-
|
|
95
28
|
let cachedUint8ArrayMemory0 = null;
|
|
96
29
|
|
|
97
30
|
function getUint8ArrayMemory0() {
|
|
@@ -101,67 +34,6 @@ function getUint8ArrayMemory0() {
|
|
|
101
34
|
return cachedUint8ArrayMemory0;
|
|
102
35
|
}
|
|
103
36
|
|
|
104
|
-
const cachedTextEncoder = new TextEncoder();
|
|
105
|
-
|
|
106
|
-
if (!('encodeInto' in cachedTextEncoder)) {
|
|
107
|
-
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
108
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
109
|
-
view.set(buf);
|
|
110
|
-
return {
|
|
111
|
-
read: arg.length,
|
|
112
|
-
written: buf.length
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
118
|
-
|
|
119
|
-
if (realloc === undefined) {
|
|
120
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
121
|
-
const ptr = malloc(buf.length, 1) >>> 0;
|
|
122
|
-
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
123
|
-
WASM_VECTOR_LEN = buf.length;
|
|
124
|
-
return ptr;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
let len = arg.length;
|
|
128
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
129
|
-
|
|
130
|
-
const mem = getUint8ArrayMemory0();
|
|
131
|
-
|
|
132
|
-
let offset = 0;
|
|
133
|
-
|
|
134
|
-
for (; offset < len; offset++) {
|
|
135
|
-
const code = arg.charCodeAt(offset);
|
|
136
|
-
if (code > 0x7F) break;
|
|
137
|
-
mem[ptr + offset] = code;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (offset !== len) {
|
|
141
|
-
if (offset !== 0) {
|
|
142
|
-
arg = arg.slice(offset);
|
|
143
|
-
}
|
|
144
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
145
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
146
|
-
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
147
|
-
|
|
148
|
-
offset += ret.written;
|
|
149
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
WASM_VECTOR_LEN = offset;
|
|
153
|
-
return ptr;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
let cachedDataViewMemory0 = null;
|
|
157
|
-
|
|
158
|
-
function getDataViewMemory0() {
|
|
159
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
160
|
-
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
161
|
-
}
|
|
162
|
-
return cachedDataViewMemory0;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
37
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
166
38
|
|
|
167
39
|
cachedTextDecoder.decode();
|
|
@@ -195,6 +67,15 @@ function takeObject(idx) {
|
|
|
195
67
|
return ret;
|
|
196
68
|
}
|
|
197
69
|
|
|
70
|
+
let cachedDataViewMemory0 = null;
|
|
71
|
+
|
|
72
|
+
function getDataViewMemory0() {
|
|
73
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
74
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
75
|
+
}
|
|
76
|
+
return cachedDataViewMemory0;
|
|
77
|
+
}
|
|
78
|
+
|
|
198
79
|
function getArrayU8FromWasm0(ptr, len) {
|
|
199
80
|
ptr = ptr >>> 0;
|
|
200
81
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
@@ -210,12 +91,81 @@ function getArrayJsValueFromWasm0(ptr, len) {
|
|
|
210
91
|
return result;
|
|
211
92
|
}
|
|
212
93
|
|
|
94
|
+
let WASM_VECTOR_LEN = 0;
|
|
95
|
+
|
|
213
96
|
function passArray8ToWasm0(arg, malloc) {
|
|
214
97
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
215
98
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
216
99
|
WASM_VECTOR_LEN = arg.length;
|
|
217
100
|
return ptr;
|
|
218
101
|
}
|
|
102
|
+
|
|
103
|
+
const cachedTextEncoder = new TextEncoder();
|
|
104
|
+
|
|
105
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
106
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
107
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
108
|
+
view.set(buf);
|
|
109
|
+
return {
|
|
110
|
+
read: arg.length,
|
|
111
|
+
written: buf.length
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
117
|
+
|
|
118
|
+
if (realloc === undefined) {
|
|
119
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
120
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
121
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
122
|
+
WASM_VECTOR_LEN = buf.length;
|
|
123
|
+
return ptr;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let len = arg.length;
|
|
127
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
128
|
+
|
|
129
|
+
const mem = getUint8ArrayMemory0();
|
|
130
|
+
|
|
131
|
+
let offset = 0;
|
|
132
|
+
|
|
133
|
+
for (; offset < len; offset++) {
|
|
134
|
+
const code = arg.charCodeAt(offset);
|
|
135
|
+
if (code > 0x7F) break;
|
|
136
|
+
mem[ptr + offset] = code;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (offset !== len) {
|
|
140
|
+
if (offset !== 0) {
|
|
141
|
+
arg = arg.slice(offset);
|
|
142
|
+
}
|
|
143
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
144
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
145
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
146
|
+
|
|
147
|
+
offset += ret.written;
|
|
148
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
WASM_VECTOR_LEN = offset;
|
|
152
|
+
return ptr;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* @param {Uint8Array} image_data
|
|
156
|
+
* @param {number} max_colors
|
|
157
|
+
* @param {string} sort_method
|
|
158
|
+
* @returns {ColorAnalysis}
|
|
159
|
+
*/
|
|
160
|
+
export function analyze_colors(image_data, max_colors, sort_method) {
|
|
161
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_2);
|
|
162
|
+
const len0 = WASM_VECTOR_LEN;
|
|
163
|
+
const ptr1 = passStringToWasm0(sort_method, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
|
|
164
|
+
const len1 = WASM_VECTOR_LEN;
|
|
165
|
+
const ret = wasm.analyze_colors(ptr0, len0, max_colors, ptr1, len1);
|
|
166
|
+
return ColorAnalysis.__wrap(ret);
|
|
167
|
+
}
|
|
168
|
+
|
|
219
169
|
/**
|
|
220
170
|
* @param {Uint8Array} image_data
|
|
221
171
|
* @param {number} original_width
|
|
@@ -227,7 +177,7 @@ function passArray8ToWasm0(arg, malloc) {
|
|
|
227
177
|
* @returns {ImageResult}
|
|
228
178
|
*/
|
|
229
179
|
export function k_centroid_resize(image_data, original_width, original_height, target_width, target_height, centroids, iterations) {
|
|
230
|
-
const ptr0 = passArray8ToWasm0(image_data, wasm.
|
|
180
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_2);
|
|
231
181
|
const len0 = WASM_VECTOR_LEN;
|
|
232
182
|
const ret = wasm.k_centroid_resize(ptr0, len0, original_width, original_height, target_width, target_height, centroids, iterations);
|
|
233
183
|
return ImageResult.__wrap(ret);
|
|
@@ -242,7 +192,7 @@ export function k_centroid_resize(image_data, original_width, original_height, t
|
|
|
242
192
|
* @returns {ImageResult}
|
|
243
193
|
*/
|
|
244
194
|
export function quantize_perceptual(image_data, width, height, num_colors, dithering) {
|
|
245
|
-
const ptr0 = passArray8ToWasm0(image_data, wasm.
|
|
195
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_2);
|
|
246
196
|
const len0 = WASM_VECTOR_LEN;
|
|
247
197
|
const ret = wasm.quantize_perceptual(ptr0, len0, width, height, num_colors, dithering);
|
|
248
198
|
return ImageResult.__wrap(ret);
|
|
@@ -257,7 +207,7 @@ export function quantize_perceptual(image_data, width, height, num_colors, dithe
|
|
|
257
207
|
* @returns {ImageResult}
|
|
258
208
|
*/
|
|
259
209
|
export function quantize_colors_median_cut(image_data, width, height, num_colors, dithering) {
|
|
260
|
-
const ptr0 = passArray8ToWasm0(image_data, wasm.
|
|
210
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_2);
|
|
261
211
|
const len0 = WASM_VECTOR_LEN;
|
|
262
212
|
const ret = wasm.quantize_colors_median_cut(ptr0, len0, width, height, num_colors, dithering);
|
|
263
213
|
return ImageResult.__wrap(ret);
|
|
@@ -269,27 +219,12 @@ export function quantize_colors_median_cut(image_data, width, height, num_colors
|
|
|
269
219
|
* @returns {ColorPalette}
|
|
270
220
|
*/
|
|
271
221
|
export function extract_palette(image_data, num_colors) {
|
|
272
|
-
const ptr0 = passArray8ToWasm0(image_data, wasm.
|
|
222
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_2);
|
|
273
223
|
const len0 = WASM_VECTOR_LEN;
|
|
274
224
|
const ret = wasm.extract_palette(ptr0, len0, num_colors);
|
|
275
225
|
return ColorPalette.__wrap(ret);
|
|
276
226
|
}
|
|
277
227
|
|
|
278
|
-
/**
|
|
279
|
-
* @param {Uint8Array} image_data
|
|
280
|
-
* @param {number} max_colors
|
|
281
|
-
* @param {string} sort_method
|
|
282
|
-
* @returns {ColorAnalysis}
|
|
283
|
-
*/
|
|
284
|
-
export function analyze_colors(image_data, max_colors, sort_method) {
|
|
285
|
-
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
|
|
286
|
-
const len0 = WASM_VECTOR_LEN;
|
|
287
|
-
const ptr1 = passStringToWasm0(sort_method, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
288
|
-
const len1 = WASM_VECTOR_LEN;
|
|
289
|
-
const ret = wasm.analyze_colors(ptr0, len0, max_colors, ptr1, len1);
|
|
290
|
-
return ColorAnalysis.__wrap(ret);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
228
|
/**
|
|
294
229
|
* @param {Uint8Array} image_data
|
|
295
230
|
* @param {number} num_colors
|
|
@@ -297,7 +232,7 @@ export function analyze_colors(image_data, max_colors, sort_method) {
|
|
|
297
232
|
* @returns {ColorAnalysis}
|
|
298
233
|
*/
|
|
299
234
|
export function get_dominant_colors(image_data, num_colors, min_coverage) {
|
|
300
|
-
const ptr0 = passArray8ToWasm0(image_data, wasm.
|
|
235
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_2);
|
|
301
236
|
const len0 = WASM_VECTOR_LEN;
|
|
302
237
|
const ret = wasm.get_dominant_colors(ptr0, len0, num_colors, min_coverage);
|
|
303
238
|
return ColorAnalysis.__wrap(ret);
|
|
@@ -364,7 +299,7 @@ export class ColorAnalysis {
|
|
|
364
299
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
365
300
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
366
301
|
var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
367
|
-
wasm.
|
|
302
|
+
wasm.__wbindgen_export_1(r0, r1 * 4, 4);
|
|
368
303
|
return v1;
|
|
369
304
|
} finally {
|
|
370
305
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -406,7 +341,7 @@ export class ColorInfo {
|
|
|
406
341
|
return getStringFromWasm0(r0, r1);
|
|
407
342
|
} finally {
|
|
408
343
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
409
|
-
wasm.
|
|
344
|
+
wasm.__wbindgen_export_1(deferred1_0, deferred1_1, 1);
|
|
410
345
|
}
|
|
411
346
|
}
|
|
412
347
|
/**
|
|
@@ -495,7 +430,7 @@ export class ColorPalette {
|
|
|
495
430
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
496
431
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
497
432
|
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
498
|
-
wasm.
|
|
433
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
499
434
|
return v1;
|
|
500
435
|
} finally {
|
|
501
436
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -565,7 +500,7 @@ export class ImageResult {
|
|
|
565
500
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
566
501
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
567
502
|
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
568
|
-
wasm.
|
|
503
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
569
504
|
return v1;
|
|
570
505
|
} finally {
|
|
571
506
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -620,13 +555,6 @@ function __wbg_get_imports() {
|
|
|
620
555
|
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
621
556
|
return ret;
|
|
622
557
|
}, arguments) };
|
|
623
|
-
imports.wbg.__wbg_wbindgendebugstring_99ef257a3ddda34d = function(arg0, arg1) {
|
|
624
|
-
const ret = debugString(getObject(arg1));
|
|
625
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
626
|
-
const len1 = WASM_VECTOR_LEN;
|
|
627
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
628
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
629
|
-
};
|
|
630
558
|
imports.wbg.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
|
|
631
559
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
632
560
|
};
|
|
Binary file
|