smart-downscaler 0.1.0 → 0.1.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.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Pixagram"
6
6
  ],
7
7
  "description": "Intelligent pixel art downscaler with region-aware color quantization",
8
- "version": "0.1.0",
8
+ "version": "0.1.2",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -30,4 +30,4 @@
30
30
  "quantization",
31
31
  "wasm"
32
32
  ]
33
- }
33
+ }
@@ -104,6 +104,36 @@ export class WasmDownscaleResult {
104
104
  readonly palette_size: number;
105
105
  }
106
106
 
107
+ export class WasmTurboConfig {
108
+ free(): void;
109
+ [Symbol.dispose](): void;
110
+ constructor();
111
+ /**
112
+ * Fastest possible settings
113
+ */
114
+ static fastest(): WasmTurboConfig;
115
+ /**
116
+ * Balanced speed/quality
117
+ */
118
+ static balanced(): WasmTurboConfig;
119
+ /**
120
+ * Number of colors in output palette
121
+ */
122
+ palette_size: number;
123
+ /**
124
+ * Enable neighbor coherence (small quality boost, small perf cost)
125
+ */
126
+ neighbor_coherence: boolean;
127
+ /**
128
+ * Neighbor weight [0.0-1.0]
129
+ */
130
+ neighbor_weight: number;
131
+ /**
132
+ * Enable dithering
133
+ */
134
+ dither: boolean;
135
+ }
136
+
107
137
  /**
108
138
  * Main downscaling function for WebAssembly
109
139
  *
@@ -155,6 +185,29 @@ export function log(message: string): void;
155
185
  */
156
186
  export function quantize_to_palette(image_data: Uint8Array, width: number, height: number, palette_data: Uint8Array): WasmDownscaleResult;
157
187
 
188
+ /**
189
+ * TURBO: Ultra-fast downscaling (3-9x faster than standard)
190
+ *
191
+ * Use this when speed is more important than maximum quality.
192
+ * Still produces good results, just uses faster algorithms.
193
+ */
194
+ export function turbo_downscale(image_data: Uint8Array, width: number, height: number, target_width: number, target_height: number, config?: WasmTurboConfig | null): WasmDownscaleResult;
195
+
196
+ /**
197
+ * TURBO: Maximum speed variant
198
+ */
199
+ export function turbo_downscale_fastest(image_data: Uint8Array, width: number, height: number, target_width: number, target_height: number, num_colors: number): WasmDownscaleResult;
200
+
201
+ /**
202
+ * TURBO: Same as turbo_downscale but accepts Uint8ClampedArray from ImageData
203
+ */
204
+ export function turbo_downscale_rgba(image_data: Uint8ClampedArray, width: number, height: number, target_width: number, target_height: number, config?: WasmTurboConfig | null): WasmDownscaleResult;
205
+
206
+ /**
207
+ * TURBO: Simplest API - just specify dimensions and colors
208
+ */
209
+ export function turbo_downscale_simple(image_data: Uint8Array, width: number, height: number, target_width: number, target_height: number, num_colors: number): WasmDownscaleResult;
210
+
158
211
  /**
159
212
  * Get library version
160
213
  */
@@ -111,6 +111,10 @@ const WasmDownscaleResultFinalization = (typeof FinalizationRegistry === 'undefi
111
111
  ? { register: () => {}, unregister: () => {} }
112
112
  : new FinalizationRegistry(ptr => wasm.__wbg_wasmdownscaleresult_free(ptr >>> 0, 1));
113
113
 
114
+ const WasmTurboConfigFinalization = (typeof FinalizationRegistry === 'undefined')
115
+ ? { register: () => {}, unregister: () => {} }
116
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmturboconfig_free(ptr >>> 0, 1));
117
+
114
118
  /**
115
119
  * Configuration options for the downscaler (JavaScript-compatible)
116
120
  */
@@ -439,6 +443,112 @@ export class WasmDownscaleResult {
439
443
  }
440
444
  if (Symbol.dispose) WasmDownscaleResult.prototype[Symbol.dispose] = WasmDownscaleResult.prototype.free;
441
445
 
446
+ /**
447
+ * Turbo mode configuration
448
+ */
449
+ export class WasmTurboConfig {
450
+ static __wrap(ptr) {
451
+ ptr = ptr >>> 0;
452
+ const obj = Object.create(WasmTurboConfig.prototype);
453
+ obj.__wbg_ptr = ptr;
454
+ WasmTurboConfigFinalization.register(obj, obj.__wbg_ptr, obj);
455
+ return obj;
456
+ }
457
+ __destroy_into_raw() {
458
+ const ptr = this.__wbg_ptr;
459
+ this.__wbg_ptr = 0;
460
+ WasmTurboConfigFinalization.unregister(this);
461
+ return ptr;
462
+ }
463
+ free() {
464
+ const ptr = this.__destroy_into_raw();
465
+ wasm.__wbg_wasmturboconfig_free(ptr, 0);
466
+ }
467
+ /**
468
+ * Number of colors in output palette
469
+ * @returns {number}
470
+ */
471
+ get palette_size() {
472
+ const ret = wasm.__wbg_get_wasmturboconfig_palette_size(this.__wbg_ptr);
473
+ return ret >>> 0;
474
+ }
475
+ /**
476
+ * Number of colors in output palette
477
+ * @param {number} arg0
478
+ */
479
+ set palette_size(arg0) {
480
+ wasm.__wbg_set_wasmturboconfig_palette_size(this.__wbg_ptr, arg0);
481
+ }
482
+ /**
483
+ * Enable neighbor coherence (small quality boost, small perf cost)
484
+ * @returns {boolean}
485
+ */
486
+ get neighbor_coherence() {
487
+ const ret = wasm.__wbg_get_wasmturboconfig_neighbor_coherence(this.__wbg_ptr);
488
+ return ret !== 0;
489
+ }
490
+ /**
491
+ * Enable neighbor coherence (small quality boost, small perf cost)
492
+ * @param {boolean} arg0
493
+ */
494
+ set neighbor_coherence(arg0) {
495
+ wasm.__wbg_set_wasmturboconfig_neighbor_coherence(this.__wbg_ptr, arg0);
496
+ }
497
+ /**
498
+ * Neighbor weight [0.0-1.0]
499
+ * @returns {number}
500
+ */
501
+ get neighbor_weight() {
502
+ const ret = wasm.__wbg_get_wasmturboconfig_neighbor_weight(this.__wbg_ptr);
503
+ return ret;
504
+ }
505
+ /**
506
+ * Neighbor weight [0.0-1.0]
507
+ * @param {number} arg0
508
+ */
509
+ set neighbor_weight(arg0) {
510
+ wasm.__wbg_set_wasmturboconfig_neighbor_weight(this.__wbg_ptr, arg0);
511
+ }
512
+ /**
513
+ * Enable dithering
514
+ * @returns {boolean}
515
+ */
516
+ get dither() {
517
+ const ret = wasm.__wbg_get_wasmturboconfig_dither(this.__wbg_ptr);
518
+ return ret !== 0;
519
+ }
520
+ /**
521
+ * Enable dithering
522
+ * @param {boolean} arg0
523
+ */
524
+ set dither(arg0) {
525
+ wasm.__wbg_set_wasmturboconfig_dither(this.__wbg_ptr, arg0);
526
+ }
527
+ constructor() {
528
+ const ret = wasm.wasmturboconfig_balanced();
529
+ this.__wbg_ptr = ret >>> 0;
530
+ WasmTurboConfigFinalization.register(this, this.__wbg_ptr, this);
531
+ return this;
532
+ }
533
+ /**
534
+ * Fastest possible settings
535
+ * @returns {WasmTurboConfig}
536
+ */
537
+ static fastest() {
538
+ const ret = wasm.wasmturboconfig_fastest();
539
+ return WasmTurboConfig.__wrap(ret);
540
+ }
541
+ /**
542
+ * Balanced speed/quality
543
+ * @returns {WasmTurboConfig}
544
+ */
545
+ static balanced() {
546
+ const ret = wasm.wasmturboconfig_balanced();
547
+ return WasmTurboConfig.__wrap(ret);
548
+ }
549
+ }
550
+ if (Symbol.dispose) WasmTurboConfig.prototype[Symbol.dispose] = WasmTurboConfig.prototype.free;
551
+
442
552
  /**
443
553
  * Main downscaling function for WebAssembly
444
554
  *
@@ -588,6 +698,91 @@ export function quantize_to_palette(image_data, width, height, palette_data) {
588
698
  return WasmDownscaleResult.__wrap(ret[0]);
589
699
  }
590
700
 
701
+ /**
702
+ * TURBO: Ultra-fast downscaling (3-9x faster than standard)
703
+ *
704
+ * Use this when speed is more important than maximum quality.
705
+ * Still produces good results, just uses faster algorithms.
706
+ * @param {Uint8Array} image_data
707
+ * @param {number} width
708
+ * @param {number} height
709
+ * @param {number} target_width
710
+ * @param {number} target_height
711
+ * @param {WasmTurboConfig | null} [config]
712
+ * @returns {WasmDownscaleResult}
713
+ */
714
+ export function turbo_downscale(image_data, width, height, target_width, target_height, config) {
715
+ let ptr0 = 0;
716
+ if (!isLikeNone(config)) {
717
+ _assertClass(config, WasmTurboConfig);
718
+ ptr0 = config.__destroy_into_raw();
719
+ }
720
+ const ret = wasm.turbo_downscale(image_data, width, height, target_width, target_height, ptr0);
721
+ if (ret[2]) {
722
+ throw takeFromExternrefTable0(ret[1]);
723
+ }
724
+ return WasmDownscaleResult.__wrap(ret[0]);
725
+ }
726
+
727
+ /**
728
+ * TURBO: Maximum speed variant
729
+ * @param {Uint8Array} image_data
730
+ * @param {number} width
731
+ * @param {number} height
732
+ * @param {number} target_width
733
+ * @param {number} target_height
734
+ * @param {number} num_colors
735
+ * @returns {WasmDownscaleResult}
736
+ */
737
+ export function turbo_downscale_fastest(image_data, width, height, target_width, target_height, num_colors) {
738
+ const ret = wasm.turbo_downscale_fastest(image_data, width, height, target_width, target_height, num_colors);
739
+ if (ret[2]) {
740
+ throw takeFromExternrefTable0(ret[1]);
741
+ }
742
+ return WasmDownscaleResult.__wrap(ret[0]);
743
+ }
744
+
745
+ /**
746
+ * TURBO: Same as turbo_downscale but accepts Uint8ClampedArray from ImageData
747
+ * @param {Uint8ClampedArray} image_data
748
+ * @param {number} width
749
+ * @param {number} height
750
+ * @param {number} target_width
751
+ * @param {number} target_height
752
+ * @param {WasmTurboConfig | null} [config]
753
+ * @returns {WasmDownscaleResult}
754
+ */
755
+ export function turbo_downscale_rgba(image_data, width, height, target_width, target_height, config) {
756
+ let ptr0 = 0;
757
+ if (!isLikeNone(config)) {
758
+ _assertClass(config, WasmTurboConfig);
759
+ ptr0 = config.__destroy_into_raw();
760
+ }
761
+ const ret = wasm.turbo_downscale_rgba(image_data, width, height, target_width, target_height, ptr0);
762
+ if (ret[2]) {
763
+ throw takeFromExternrefTable0(ret[1]);
764
+ }
765
+ return WasmDownscaleResult.__wrap(ret[0]);
766
+ }
767
+
768
+ /**
769
+ * TURBO: Simplest API - just specify dimensions and colors
770
+ * @param {Uint8Array} image_data
771
+ * @param {number} width
772
+ * @param {number} height
773
+ * @param {number} target_width
774
+ * @param {number} target_height
775
+ * @param {number} num_colors
776
+ * @returns {WasmDownscaleResult}
777
+ */
778
+ export function turbo_downscale_simple(image_data, width, height, target_width, target_height, num_colors) {
779
+ const ret = wasm.turbo_downscale_simple(image_data, width, height, target_width, target_height, num_colors);
780
+ if (ret[2]) {
781
+ throw takeFromExternrefTable0(ret[1]);
782
+ }
783
+ return WasmDownscaleResult.__wrap(ret[0]);
784
+ }
785
+
591
786
  /**
592
787
  * Get library version
593
788
  * @returns {string}
Binary file