k-centroid-scaler 1.0.0 → 1.1.0
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 +101 -1
- package/k_centroid_scaler_bg.wasm +0 -0
- package/package.json +2 -2
package/k_centroid_scaler.js
CHANGED
|
@@ -223,6 +223,49 @@ export function k_centroid_resize(image_data, original_width, original_height, t
|
|
|
223
223
|
return ImageResult.__wrap(ret);
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
/**
|
|
227
|
+
* @param {Uint8Array} image_data
|
|
228
|
+
* @param {number} width
|
|
229
|
+
* @param {number} height
|
|
230
|
+
* @param {number} num_colors
|
|
231
|
+
* @param {boolean} dithering
|
|
232
|
+
* @returns {ImageResult}
|
|
233
|
+
*/
|
|
234
|
+
export function quantize_colors_median_cut(image_data, width, height, num_colors, dithering) {
|
|
235
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
|
|
236
|
+
const len0 = WASM_VECTOR_LEN;
|
|
237
|
+
const ret = wasm.quantize_colors_median_cut(ptr0, len0, width, height, num_colors, dithering);
|
|
238
|
+
return ImageResult.__wrap(ret);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* @param {Uint8Array} image_data
|
|
243
|
+
* @param {number} width
|
|
244
|
+
* @param {number} height
|
|
245
|
+
* @param {number} num_colors
|
|
246
|
+
* @param {number} iterations
|
|
247
|
+
* @param {boolean} dithering
|
|
248
|
+
* @returns {ImageResult}
|
|
249
|
+
*/
|
|
250
|
+
export function quantize_colors_kmeans(image_data, width, height, num_colors, iterations, dithering) {
|
|
251
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
|
|
252
|
+
const len0 = WASM_VECTOR_LEN;
|
|
253
|
+
const ret = wasm.quantize_colors_kmeans(ptr0, len0, width, height, num_colors, iterations, dithering);
|
|
254
|
+
return ImageResult.__wrap(ret);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* @param {Uint8Array} image_data
|
|
259
|
+
* @param {number} max_colors
|
|
260
|
+
* @returns {ColorPalette}
|
|
261
|
+
*/
|
|
262
|
+
export function extract_palette(image_data, max_colors) {
|
|
263
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export_1);
|
|
264
|
+
const len0 = WASM_VECTOR_LEN;
|
|
265
|
+
const ret = wasm.extract_palette(ptr0, len0, max_colors);
|
|
266
|
+
return ColorPalette.__wrap(ret);
|
|
267
|
+
}
|
|
268
|
+
|
|
226
269
|
/**
|
|
227
270
|
* @param {Uint8Array} data
|
|
228
271
|
* @param {number} width
|
|
@@ -240,6 +283,63 @@ export function process_image(data, width, height, target_width, target_height,
|
|
|
240
283
|
return takeObject(ret);
|
|
241
284
|
}
|
|
242
285
|
|
|
286
|
+
const ColorPaletteFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
287
|
+
? { register: () => {}, unregister: () => {} }
|
|
288
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_colorpalette_free(ptr >>> 0, 1));
|
|
289
|
+
|
|
290
|
+
export class ColorPalette {
|
|
291
|
+
|
|
292
|
+
static __wrap(ptr) {
|
|
293
|
+
ptr = ptr >>> 0;
|
|
294
|
+
const obj = Object.create(ColorPalette.prototype);
|
|
295
|
+
obj.__wbg_ptr = ptr;
|
|
296
|
+
ColorPaletteFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
297
|
+
return obj;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
__destroy_into_raw() {
|
|
301
|
+
const ptr = this.__wbg_ptr;
|
|
302
|
+
this.__wbg_ptr = 0;
|
|
303
|
+
ColorPaletteFinalization.unregister(this);
|
|
304
|
+
return ptr;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
free() {
|
|
308
|
+
const ptr = this.__destroy_into_raw();
|
|
309
|
+
wasm.__wbg_colorpalette_free(ptr, 0);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* @returns {number}
|
|
313
|
+
*/
|
|
314
|
+
get count() {
|
|
315
|
+
const ret = wasm.__wbg_get_colorpalette_count(this.__wbg_ptr);
|
|
316
|
+
return ret >>> 0;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* @param {number} arg0
|
|
320
|
+
*/
|
|
321
|
+
set count(arg0) {
|
|
322
|
+
wasm.__wbg_set_colorpalette_count(this.__wbg_ptr, arg0);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* @returns {Uint8Array}
|
|
326
|
+
*/
|
|
327
|
+
get colors() {
|
|
328
|
+
try {
|
|
329
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
330
|
+
wasm.colorpalette_colors(retptr, this.__wbg_ptr);
|
|
331
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
332
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
333
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
334
|
+
wasm.__wbindgen_export_3(r0, r1 * 1, 1);
|
|
335
|
+
return v1;
|
|
336
|
+
} finally {
|
|
337
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (Symbol.dispose) ColorPalette.prototype[Symbol.dispose] = ColorPalette.prototype.free;
|
|
342
|
+
|
|
243
343
|
const ImageResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
244
344
|
? { register: () => {}, unregister: () => {} }
|
|
245
345
|
: new FinalizationRegistry(ptr => wasm.__wbg_imageresult_free(ptr >>> 0, 1));
|
|
@@ -269,7 +369,7 @@ export class ImageResult {
|
|
|
269
369
|
* @returns {number}
|
|
270
370
|
*/
|
|
271
371
|
get width() {
|
|
272
|
-
const ret = wasm.
|
|
372
|
+
const ret = wasm.__wbg_get_colorpalette_count(this.__wbg_ptr);
|
|
273
373
|
return ret >>> 0;
|
|
274
374
|
}
|
|
275
375
|
/**
|
|
Binary file
|
package/package.json
CHANGED