smart-downscaler 0.5.0 → 0.6.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/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.5.0",
8
+ "version": "0.6.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -1,34 +1,18 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
- /**
5
- * Result of color analysis
6
- */
7
4
  export class ColorAnalysisResult {
8
5
  private constructor();
9
6
  free(): void;
10
7
  [Symbol.dispose](): void;
11
- /**
12
- * Get color at index
13
- */
14
8
  get_color(index: number): ColorEntry | undefined;
15
- /**
16
- * Get all colors as a flat array: [r, g, b, count(4 bytes), percentage(4 bytes), ...]
17
- * Each color is 11 bytes
18
- */
19
9
  get_colors_flat(): Uint8Array;
20
- /**
21
- * Get colors as JSON-compatible array
22
- */
23
10
  to_json(): any;
24
11
  readonly color_count: number;
25
12
  readonly success: boolean;
26
13
  readonly total_pixels: number;
27
14
  }
28
15
 
29
- /**
30
- * A single color entry with statistics
31
- */
32
16
  export class ColorEntry {
33
17
  private constructor();
34
18
  free(): void;
@@ -52,13 +36,7 @@ export class WasmDownscaleConfig {
52
36
  edge_weight: number;
53
37
  hierarchy_min_size: number;
54
38
  hierarchy_threshold: number;
55
- /**
56
- * Iterations for tile centroid
57
- */
58
39
  k_centroid_iterations: number;
59
- /**
60
- * K-Means centroid mode (1=Avg, 2=Dom, 3=Foremost)
61
- */
62
40
  k_centroid: number;
63
41
  kmeans_iterations: number;
64
42
  max_color_preprocess: number;
@@ -88,78 +66,39 @@ export class WasmDownscaleResult {
88
66
  }
89
67
 
90
68
  /**
91
- * Analyze colors in an image
92
- *
93
- * # Arguments
94
- * * `image_data` - RGBA pixel data
95
- * * `max_colors` - Maximum number of unique colors to track (stops if exceeded)
96
- * * `sort_method` - Sorting method: "frequency", "morton", or "hilbert"
97
- *
98
- * # Returns
99
- * ColorAnalysisResult with array of colors (r, g, b, count, percentage, hex)
100
- * If unique colors exceed max_colors, returns early with success=false
69
+ * Analyze colors FIX: uses HashMap<u32, usize> for O(1) lookup (was O(n) linear scan)
101
70
  */
102
71
  export function analyze_colors(image_data: Uint8Array, max_colors: number, sort_method: string): ColorAnalysisResult;
103
72
 
104
- /**
105
- * Compute perceptual color distance between two RGB colors
106
- */
107
73
  export function color_distance(r1: number, g1: number, b1: number, r2: number, g2: number, b2: number): number;
108
74
 
109
75
  export function downscale(image_data: Uint8Array, width: number, height: number, target_width: number, target_height: number, config?: WasmDownscaleConfig | null): WasmDownscaleResult;
110
76
 
111
77
  export function downscale_rgba(image_data: Uint8ClampedArray, width: number, height: number, target_width: number, target_height: number, config?: WasmDownscaleConfig | null): WasmDownscaleResult;
112
78
 
113
- /**
114
- * Simple downscale function with minimal parameters
115
- */
116
79
  export function downscale_simple(image_data: Uint8Array, width: number, height: number, target_width: number, target_height: number, num_colors: number): WasmDownscaleResult;
117
80
 
118
81
  export function downscale_with_palette(image_data: Uint8Array, width: number, height: number, target_width: number, target_height: number, palette_data: Uint8Array, config?: WasmDownscaleConfig | null): WasmDownscaleResult;
119
82
 
120
- /**
121
- * Extract a color palette from an image without downscaling
122
- */
123
83
  export function extract_palette_from_image(image_data: Uint8Array, _width: number, _height: number, num_colors: number, kmeans_iterations: number, strategy?: string | null): Uint8Array;
124
84
 
125
- /**
126
- * Get chroma (saturation) of an RGB color
127
- */
128
85
  export function get_chroma(r: number, g: number, b: number): number;
129
86
 
130
- /**
131
- * Get lightness of an RGB color in Oklab space
132
- */
133
87
  export function get_lightness(r: number, g: number, b: number): number;
134
88
 
135
- /**
136
- * Get available palette strategies
137
- */
138
89
  export function get_palette_strategies(): Array<any>;
139
90
 
140
91
  export function init(): void;
141
92
 
142
- /**
143
- * Log a message to the browser console (for debugging)
144
- */
145
93
  export function log(message: string): void;
146
94
 
147
- /**
148
- * Convert Oklab to RGB (utility function for JS)
149
- */
150
95
  export function oklab_to_rgb(l: number, a: number, b: number): Uint8Array;
151
96
 
152
97
  /**
153
- * Quantize an image to a specific palette without resizing
98
+ * Quantize to palette FIX: compute Oklab once per pixel (was twice)
154
99
  */
155
100
  export function quantize_to_palette(image_data: Uint8Array, width: number, height: number, palette_data: Uint8Array): WasmDownscaleResult;
156
101
 
157
- /**
158
- * Convert RGB to Oklab (utility function for JS)
159
- */
160
102
  export function rgb_to_oklab(r: number, g: number, b: number): Float32Array;
161
103
 
162
- /**
163
- * Get library version
164
- */
165
104
  export function version(): string;
@@ -1,6 +1,3 @@
1
- /**
2
- * Result of color analysis
3
- */
4
1
  export class ColorAnalysisResult {
5
2
  static __wrap(ptr) {
6
3
  ptr = ptr >>> 0;
@@ -27,7 +24,6 @@ export class ColorAnalysisResult {
27
24
  return ret >>> 0;
28
25
  }
29
26
  /**
30
- * Get color at index
31
27
  * @param {number} index
32
28
  * @returns {ColorEntry | undefined}
33
29
  */
@@ -36,8 +32,6 @@ export class ColorAnalysisResult {
36
32
  return ret === 0 ? undefined : ColorEntry.__wrap(ret);
37
33
  }
38
34
  /**
39
- * Get all colors as a flat array: [r, g, b, count(4 bytes), percentage(4 bytes), ...]
40
- * Each color is 11 bytes
41
35
  * @returns {Uint8Array}
42
36
  */
43
37
  get_colors_flat() {
@@ -52,7 +46,6 @@ export class ColorAnalysisResult {
52
46
  return ret !== 0;
53
47
  }
54
48
  /**
55
- * Get colors as JSON-compatible array
56
49
  * @returns {any}
57
50
  */
58
51
  to_json() {
@@ -72,9 +65,6 @@ export class ColorAnalysisResult {
72
65
  }
73
66
  if (Symbol.dispose) ColorAnalysisResult.prototype[Symbol.dispose] = ColorAnalysisResult.prototype.free;
74
67
 
75
- /**
76
- * A single color entry with statistics
77
- */
78
68
  export class ColorEntry {
79
69
  static __wrap(ptr) {
80
70
  ptr = ptr >>> 0;
@@ -186,7 +176,6 @@ export class WasmDownscaleConfig {
186
176
  return ret;
187
177
  }
188
178
  /**
189
- * Iterations for tile centroid
190
179
  * @returns {number}
191
180
  */
192
181
  get k_centroid_iterations() {
@@ -194,7 +183,6 @@ export class WasmDownscaleConfig {
194
183
  return ret >>> 0;
195
184
  }
196
185
  /**
197
- * K-Means centroid mode (1=Avg, 2=Dom, 3=Foremost)
198
186
  * @returns {number}
199
187
  */
200
188
  get k_centroid() {
@@ -290,14 +278,12 @@ export class WasmDownscaleConfig {
290
278
  wasm.__wbg_set_wasmdownscaleconfig_hierarchy_threshold(this.__wbg_ptr, arg0);
291
279
  }
292
280
  /**
293
- * Iterations for tile centroid
294
281
  * @param {number} arg0
295
282
  */
296
283
  set k_centroid_iterations(arg0) {
297
284
  wasm.__wbg_set_wasmdownscaleconfig_k_centroid_iterations(this.__wbg_ptr, arg0);
298
285
  }
299
286
  /**
300
- * K-Means centroid mode (1=Avg, 2=Dom, 3=Foremost)
301
287
  * @param {number} arg0
302
288
  */
303
289
  set k_centroid(arg0) {
@@ -517,16 +503,7 @@ export class WasmDownscaleResult {
517
503
  if (Symbol.dispose) WasmDownscaleResult.prototype[Symbol.dispose] = WasmDownscaleResult.prototype.free;
518
504
 
519
505
  /**
520
- * Analyze colors in an image
521
- *
522
- * # Arguments
523
- * * `image_data` - RGBA pixel data
524
- * * `max_colors` - Maximum number of unique colors to track (stops if exceeded)
525
- * * `sort_method` - Sorting method: "frequency", "morton", or "hilbert"
526
- *
527
- * # Returns
528
- * ColorAnalysisResult with array of colors (r, g, b, count, percentage, hex)
529
- * If unique colors exceed max_colors, returns early with success=false
506
+ * Analyze colors FIX: uses HashMap<u32, usize> for O(1) lookup (was O(n) linear scan)
530
507
  * @param {Uint8Array} image_data
531
508
  * @param {number} max_colors
532
509
  * @param {string} sort_method
@@ -543,7 +520,6 @@ export function analyze_colors(image_data, max_colors, sort_method) {
543
520
  }
544
521
 
545
522
  /**
546
- * Compute perceptual color distance between two RGB colors
547
523
  * @param {number} r1
548
524
  * @param {number} g1
549
525
  * @param {number} b1
@@ -602,7 +578,6 @@ export function downscale_rgba(image_data, width, height, target_width, target_h
602
578
  }
603
579
 
604
580
  /**
605
- * Simple downscale function with minimal parameters
606
581
  * @param {Uint8Array} image_data
607
582
  * @param {number} width
608
583
  * @param {number} height
@@ -643,7 +618,6 @@ export function downscale_with_palette(image_data, width, height, target_width,
643
618
  }
644
619
 
645
620
  /**
646
- * Extract a color palette from an image without downscaling
647
621
  * @param {Uint8Array} image_data
648
622
  * @param {number} _width
649
623
  * @param {number} _height
@@ -663,7 +637,6 @@ export function extract_palette_from_image(image_data, _width, _height, num_colo
663
637
  }
664
638
 
665
639
  /**
666
- * Get chroma (saturation) of an RGB color
667
640
  * @param {number} r
668
641
  * @param {number} g
669
642
  * @param {number} b
@@ -675,7 +648,6 @@ export function get_chroma(r, g, b) {
675
648
  }
676
649
 
677
650
  /**
678
- * Get lightness of an RGB color in Oklab space
679
651
  * @param {number} r
680
652
  * @param {number} g
681
653
  * @param {number} b
@@ -687,7 +659,6 @@ export function get_lightness(r, g, b) {
687
659
  }
688
660
 
689
661
  /**
690
- * Get available palette strategies
691
662
  * @returns {Array<any>}
692
663
  */
693
664
  export function get_palette_strategies() {
@@ -700,7 +671,6 @@ export function init() {
700
671
  }
701
672
 
702
673
  /**
703
- * Log a message to the browser console (for debugging)
704
674
  * @param {string} message
705
675
  */
706
676
  export function log(message) {
@@ -710,7 +680,6 @@ export function log(message) {
710
680
  }
711
681
 
712
682
  /**
713
- * Convert Oklab to RGB (utility function for JS)
714
683
  * @param {number} l
715
684
  * @param {number} a
716
685
  * @param {number} b
@@ -722,7 +691,7 @@ export function oklab_to_rgb(l, a, b) {
722
691
  }
723
692
 
724
693
  /**
725
- * Quantize an image to a specific palette without resizing
694
+ * Quantize to palette FIX: compute Oklab once per pixel (was twice)
726
695
  * @param {Uint8Array} image_data
727
696
  * @param {number} width
728
697
  * @param {number} height
@@ -738,7 +707,6 @@ export function quantize_to_palette(image_data, width, height, palette_data) {
738
707
  }
739
708
 
740
709
  /**
741
- * Convert RGB to Oklab (utility function for JS)
742
710
  * @param {number} r
743
711
  * @param {number} g
744
712
  * @param {number} b
@@ -750,7 +718,6 @@ export function rgb_to_oklab(r, g, b) {
750
718
  }
751
719
 
752
720
  /**
753
- * Get library version
754
721
  * @returns {string}
755
722
  */
756
723
  export function version() {
Binary file