smart-downscaler 0.3.0 → 0.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/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.3.0",
8
+ "version": "0.3.1",
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
+ }
@@ -1,6 +1,40 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ export class ColorAnalysisResult {
5
+ private constructor();
6
+ free(): void;
7
+ [Symbol.dispose](): void;
8
+ /**
9
+ * Get color at index
10
+ */
11
+ get_color(index: number): ColorEntry | undefined;
12
+ /**
13
+ * Get all colors as a flat array: [r, g, b, count(4 bytes), percentage(4 bytes), ...]
14
+ * Each color is 11 bytes
15
+ */
16
+ get_colors_flat(): Uint8Array;
17
+ /**
18
+ * Get colors as JSON-compatible array
19
+ */
20
+ to_json(): any;
21
+ readonly success: boolean;
22
+ readonly color_count: number;
23
+ readonly total_pixels: number;
24
+ }
25
+
26
+ export class ColorEntry {
27
+ private constructor();
28
+ free(): void;
29
+ [Symbol.dispose](): void;
30
+ readonly r: number;
31
+ readonly g: number;
32
+ readonly b: number;
33
+ readonly count: number;
34
+ readonly percentage: number;
35
+ readonly hex: string;
36
+ }
37
+
4
38
  export class WasmDownscaleConfig {
5
39
  free(): void;
6
40
  [Symbol.dispose](): void;
@@ -116,6 +150,25 @@ export class WasmDownscaleResult {
116
150
  readonly palette_size: number;
117
151
  }
118
152
 
153
+ /**
154
+ * Analyze colors in an image
155
+ *
156
+ * # Arguments
157
+ * * `image_data` - RGBA pixel data
158
+ * * `max_colors` - Maximum number of unique colors to track (stops if exceeded)
159
+ * * `sort_method` - Sorting method: "frequency", "morton", or "hilbert"
160
+ *
161
+ * # Returns
162
+ * ColorAnalysisResult with array of colors (r, g, b, count, percentage, hex)
163
+ * If unique colors exceed max_colors, returns early with success=false
164
+ */
165
+ export function analyze_colors(image_data: Uint8Array, max_colors: number, sort_method: string): ColorAnalysisResult;
166
+
167
+ /**
168
+ * Compute perceptual color distance between two RGB colors
169
+ */
170
+ export function color_distance(r1: number, g1: number, b1: number, r2: number, g2: number, b2: number): number;
171
+
119
172
  /**
120
173
  * Main downscaling function for WebAssembly
121
174
  *
@@ -152,6 +205,16 @@ export function downscale_with_palette(image_data: Uint8Array, width: number, he
152
205
  */
153
206
  export function extract_palette_from_image(image_data: Uint8Array, _width: number, _height: number, num_colors: number, kmeans_iterations: number, strategy?: string | null): Uint8Array;
154
207
 
208
+ /**
209
+ * Get chroma (saturation) of an RGB color
210
+ */
211
+ export function get_chroma(r: number, g: number, b: number): number;
212
+
213
+ /**
214
+ * Get lightness of an RGB color in Oklab space
215
+ */
216
+ export function get_lightness(r: number, g: number, b: number): number;
217
+
155
218
  /**
156
219
  * Get available palette strategies
157
220
  */
@@ -167,11 +230,21 @@ export function init(): void;
167
230
  */
168
231
  export function log(message: string): void;
169
232
 
233
+ /**
234
+ * Convert Oklab to RGB (utility function for JS)
235
+ */
236
+ export function oklab_to_rgb(l: number, a: number, b: number): Uint8Array;
237
+
170
238
  /**
171
239
  * Quantize an image to a specific palette without resizing
172
240
  */
173
241
  export function quantize_to_palette(image_data: Uint8Array, width: number, height: number, palette_data: Uint8Array): WasmDownscaleResult;
174
242
 
243
+ /**
244
+ * Convert RGB to Oklab (utility function for JS)
245
+ */
246
+ export function rgb_to_oklab(r: number, g: number, b: number): Float32Array;
247
+
175
248
  /**
176
249
  * Get library version
177
250
  */
@@ -3,6 +3,12 @@ export function __wbg_set_wasm(val) {
3
3
  wasm = val;
4
4
  }
5
5
 
6
+ function addToExternrefTable0(obj) {
7
+ const idx = wasm.__externref_table_alloc();
8
+ wasm.__wbindgen_externrefs.set(idx, obj);
9
+ return idx;
10
+ }
11
+
6
12
  function _assertClass(instance, klass) {
7
13
  if (!(instance instanceof klass)) {
8
14
  throw new Error(`expected instance of ${klass.name}`);
@@ -27,6 +33,15 @@ function getUint8ArrayMemory0() {
27
33
  return cachedUint8ArrayMemory0;
28
34
  }
29
35
 
36
+ function handleError(f, args) {
37
+ try {
38
+ return f.apply(this, args);
39
+ } catch (e) {
40
+ const idx = addToExternrefTable0(e);
41
+ wasm.__wbindgen_exn_store(idx);
42
+ }
43
+ }
44
+
30
45
  function isLikeNone(x) {
31
46
  return x === undefined || x === null;
32
47
  }
@@ -103,6 +118,14 @@ if (!('encodeInto' in cachedTextEncoder)) {
103
118
 
104
119
  let WASM_VECTOR_LEN = 0;
105
120
 
121
+ const ColorAnalysisResultFinalization = (typeof FinalizationRegistry === 'undefined')
122
+ ? { register: () => {}, unregister: () => {} }
123
+ : new FinalizationRegistry(ptr => wasm.__wbg_coloranalysisresult_free(ptr >>> 0, 1));
124
+
125
+ const ColorEntryFinalization = (typeof FinalizationRegistry === 'undefined')
126
+ ? { register: () => {}, unregister: () => {} }
127
+ : new FinalizationRegistry(ptr => wasm.__wbg_colorentry_free(ptr >>> 0, 1));
128
+
106
129
  const WasmDownscaleConfigFinalization = (typeof FinalizationRegistry === 'undefined')
107
130
  ? { register: () => {}, unregister: () => {} }
108
131
  : new FinalizationRegistry(ptr => wasm.__wbg_wasmdownscaleconfig_free(ptr >>> 0, 1));
@@ -111,6 +134,154 @@ const WasmDownscaleResultFinalization = (typeof FinalizationRegistry === 'undefi
111
134
  ? { register: () => {}, unregister: () => {} }
112
135
  : new FinalizationRegistry(ptr => wasm.__wbg_wasmdownscaleresult_free(ptr >>> 0, 1));
113
136
 
137
+ /**
138
+ * Result of color analysis
139
+ */
140
+ export class ColorAnalysisResult {
141
+ static __wrap(ptr) {
142
+ ptr = ptr >>> 0;
143
+ const obj = Object.create(ColorAnalysisResult.prototype);
144
+ obj.__wbg_ptr = ptr;
145
+ ColorAnalysisResultFinalization.register(obj, obj.__wbg_ptr, obj);
146
+ return obj;
147
+ }
148
+ __destroy_into_raw() {
149
+ const ptr = this.__wbg_ptr;
150
+ this.__wbg_ptr = 0;
151
+ ColorAnalysisResultFinalization.unregister(this);
152
+ return ptr;
153
+ }
154
+ free() {
155
+ const ptr = this.__destroy_into_raw();
156
+ wasm.__wbg_coloranalysisresult_free(ptr, 0);
157
+ }
158
+ /**
159
+ * @returns {boolean}
160
+ */
161
+ get success() {
162
+ const ret = wasm.coloranalysisresult_success(this.__wbg_ptr);
163
+ return ret !== 0;
164
+ }
165
+ /**
166
+ * @returns {number}
167
+ */
168
+ get color_count() {
169
+ const ret = wasm.coloranalysisresult_color_count(this.__wbg_ptr);
170
+ return ret >>> 0;
171
+ }
172
+ /**
173
+ * @returns {number}
174
+ */
175
+ get total_pixels() {
176
+ const ret = wasm.coloranalysisresult_total_pixels(this.__wbg_ptr);
177
+ return ret >>> 0;
178
+ }
179
+ /**
180
+ * Get color at index
181
+ * @param {number} index
182
+ * @returns {ColorEntry | undefined}
183
+ */
184
+ get_color(index) {
185
+ const ret = wasm.coloranalysisresult_get_color(this.__wbg_ptr, index);
186
+ return ret === 0 ? undefined : ColorEntry.__wrap(ret);
187
+ }
188
+ /**
189
+ * Get all colors as a flat array: [r, g, b, count(4 bytes), percentage(4 bytes), ...]
190
+ * Each color is 11 bytes
191
+ * @returns {Uint8Array}
192
+ */
193
+ get_colors_flat() {
194
+ const ret = wasm.coloranalysisresult_get_colors_flat(this.__wbg_ptr);
195
+ return ret;
196
+ }
197
+ /**
198
+ * Get colors as JSON-compatible array
199
+ * @returns {any}
200
+ */
201
+ to_json() {
202
+ const ret = wasm.coloranalysisresult_to_json(this.__wbg_ptr);
203
+ if (ret[2]) {
204
+ throw takeFromExternrefTable0(ret[1]);
205
+ }
206
+ return takeFromExternrefTable0(ret[0]);
207
+ }
208
+ }
209
+ if (Symbol.dispose) ColorAnalysisResult.prototype[Symbol.dispose] = ColorAnalysisResult.prototype.free;
210
+
211
+ /**
212
+ * A single color entry with statistics
213
+ */
214
+ export class ColorEntry {
215
+ static __wrap(ptr) {
216
+ ptr = ptr >>> 0;
217
+ const obj = Object.create(ColorEntry.prototype);
218
+ obj.__wbg_ptr = ptr;
219
+ ColorEntryFinalization.register(obj, obj.__wbg_ptr, obj);
220
+ return obj;
221
+ }
222
+ __destroy_into_raw() {
223
+ const ptr = this.__wbg_ptr;
224
+ this.__wbg_ptr = 0;
225
+ ColorEntryFinalization.unregister(this);
226
+ return ptr;
227
+ }
228
+ free() {
229
+ const ptr = this.__destroy_into_raw();
230
+ wasm.__wbg_colorentry_free(ptr, 0);
231
+ }
232
+ /**
233
+ * @returns {number}
234
+ */
235
+ get r() {
236
+ const ret = wasm.colorentry_r(this.__wbg_ptr);
237
+ return ret;
238
+ }
239
+ /**
240
+ * @returns {number}
241
+ */
242
+ get g() {
243
+ const ret = wasm.colorentry_g(this.__wbg_ptr);
244
+ return ret;
245
+ }
246
+ /**
247
+ * @returns {number}
248
+ */
249
+ get b() {
250
+ const ret = wasm.colorentry_b(this.__wbg_ptr);
251
+ return ret;
252
+ }
253
+ /**
254
+ * @returns {number}
255
+ */
256
+ get count() {
257
+ const ret = wasm.colorentry_count(this.__wbg_ptr);
258
+ return ret >>> 0;
259
+ }
260
+ /**
261
+ * @returns {number}
262
+ */
263
+ get percentage() {
264
+ const ret = wasm.colorentry_percentage(this.__wbg_ptr);
265
+ return ret;
266
+ }
267
+ /**
268
+ * @returns {string}
269
+ */
270
+ get hex() {
271
+ let deferred1_0;
272
+ let deferred1_1;
273
+ try {
274
+ const ret = wasm.colorentry_hex(this.__wbg_ptr);
275
+ deferred1_0 = ret[0];
276
+ deferred1_1 = ret[1];
277
+ return getStringFromWasm0(ret[0], ret[1]);
278
+ } finally {
279
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
280
+ }
281
+ }
282
+ }
283
+ if (Symbol.dispose) ColorEntry.prototype[Symbol.dispose] = ColorEntry.prototype.free;
284
+
114
285
  /**
115
286
  * Configuration options for the downscaler (JavaScript-compatible)
116
287
  */
@@ -480,6 +651,47 @@ export class WasmDownscaleResult {
480
651
  }
481
652
  if (Symbol.dispose) WasmDownscaleResult.prototype[Symbol.dispose] = WasmDownscaleResult.prototype.free;
482
653
 
654
+ /**
655
+ * Analyze colors in an image
656
+ *
657
+ * # Arguments
658
+ * * `image_data` - RGBA pixel data
659
+ * * `max_colors` - Maximum number of unique colors to track (stops if exceeded)
660
+ * * `sort_method` - Sorting method: "frequency", "morton", or "hilbert"
661
+ *
662
+ * # Returns
663
+ * ColorAnalysisResult with array of colors (r, g, b, count, percentage, hex)
664
+ * If unique colors exceed max_colors, returns early with success=false
665
+ * @param {Uint8Array} image_data
666
+ * @param {number} max_colors
667
+ * @param {string} sort_method
668
+ * @returns {ColorAnalysisResult}
669
+ */
670
+ export function analyze_colors(image_data, max_colors, sort_method) {
671
+ const ptr0 = passStringToWasm0(sort_method, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
672
+ const len0 = WASM_VECTOR_LEN;
673
+ const ret = wasm.analyze_colors(image_data, max_colors, ptr0, len0);
674
+ if (ret[2]) {
675
+ throw takeFromExternrefTable0(ret[1]);
676
+ }
677
+ return ColorAnalysisResult.__wrap(ret[0]);
678
+ }
679
+
680
+ /**
681
+ * Compute perceptual color distance between two RGB colors
682
+ * @param {number} r1
683
+ * @param {number} g1
684
+ * @param {number} b1
685
+ * @param {number} r2
686
+ * @param {number} g2
687
+ * @param {number} b2
688
+ * @returns {number}
689
+ */
690
+ export function color_distance(r1, g1, b1, r2, g2, b2) {
691
+ const ret = wasm.color_distance(r1, g1, b1, r2, g2, b2);
692
+ return ret;
693
+ }
694
+
483
695
  /**
484
696
  * Main downscaling function for WebAssembly
485
697
  *
@@ -599,6 +811,30 @@ export function extract_palette_from_image(image_data, _width, _height, num_colo
599
811
  return takeFromExternrefTable0(ret[0]);
600
812
  }
601
813
 
814
+ /**
815
+ * Get chroma (saturation) of an RGB color
816
+ * @param {number} r
817
+ * @param {number} g
818
+ * @param {number} b
819
+ * @returns {number}
820
+ */
821
+ export function get_chroma(r, g, b) {
822
+ const ret = wasm.get_chroma(r, g, b);
823
+ return ret;
824
+ }
825
+
826
+ /**
827
+ * Get lightness of an RGB color in Oklab space
828
+ * @param {number} r
829
+ * @param {number} g
830
+ * @param {number} b
831
+ * @returns {number}
832
+ */
833
+ export function get_lightness(r, g, b) {
834
+ const ret = wasm.get_lightness(r, g, b);
835
+ return ret;
836
+ }
837
+
602
838
  /**
603
839
  * Get available palette strategies
604
840
  * @returns {Array<any>}
@@ -625,6 +861,18 @@ export function log(message) {
625
861
  wasm.log(ptr0, len0);
626
862
  }
627
863
 
864
+ /**
865
+ * Convert Oklab to RGB (utility function for JS)
866
+ * @param {number} l
867
+ * @param {number} a
868
+ * @param {number} b
869
+ * @returns {Uint8Array}
870
+ */
871
+ export function oklab_to_rgb(l, a, b) {
872
+ const ret = wasm.oklab_to_rgb(l, a, b);
873
+ return ret;
874
+ }
875
+
628
876
  /**
629
877
  * Quantize an image to a specific palette without resizing
630
878
  * @param {Uint8Array} image_data
@@ -641,6 +889,18 @@ export function quantize_to_palette(image_data, width, height, palette_data) {
641
889
  return WasmDownscaleResult.__wrap(ret[0]);
642
890
  }
643
891
 
892
+ /**
893
+ * Convert RGB to Oklab (utility function for JS)
894
+ * @param {number} r
895
+ * @param {number} g
896
+ * @param {number} b
897
+ * @returns {Float32Array}
898
+ */
899
+ export function rgb_to_oklab(r, g, b) {
900
+ const ret = wasm.rgb_to_oklab(r, g, b);
901
+ return ret;
902
+ }
903
+
644
904
  /**
645
905
  * Get library version
646
906
  * @returns {string}
@@ -671,6 +931,11 @@ export function __wbg_log_1d990106d99dacb7(arg0) {
671
931
  console.log(arg0);
672
932
  };
673
933
 
934
+ export function __wbg_new_1ba21ce319a06297() {
935
+ const ret = new Object();
936
+ return ret;
937
+ };
938
+
674
939
  export function __wbg_new_25f239778d6112b9() {
675
940
  const ret = new Array();
676
941
  return ret;
@@ -691,6 +956,11 @@ export function __wbg_new_from_slice_f9c22b9153b26992(arg0, arg1) {
691
956
  return ret;
692
957
  };
693
958
 
959
+ export function __wbg_new_with_length_95ba657dfb7d3dfb(arg0) {
960
+ const ret = new Float32Array(arg0 >>> 0);
961
+ return ret;
962
+ };
963
+
694
964
  export function __wbg_new_with_length_aa5eaf41d35235e5(arg0) {
695
965
  const ret = new Uint8Array(arg0 >>> 0);
696
966
  return ret;
@@ -705,12 +975,31 @@ export function __wbg_push_7d9be8f38fc13975(arg0, arg1) {
705
975
  return ret;
706
976
  };
707
977
 
978
+ export function __wbg_set_781438a03c0c3c81() { return handleError(function (arg0, arg1, arg2) {
979
+ const ret = Reflect.set(arg0, arg1, arg2);
980
+ return ret;
981
+ }, arguments) };
982
+
983
+ export function __wbg_set_index_04c4b93e64d08a52(arg0, arg1, arg2) {
984
+ arg0[arg1 >>> 0] = arg2;
985
+ };
986
+
987
+ export function __wbg_set_index_165b46b0114d368c(arg0, arg1, arg2) {
988
+ arg0[arg1 >>> 0] = arg2;
989
+ };
990
+
708
991
  export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) {
709
992
  // Cast intrinsic for `Ref(String) -> Externref`.
710
993
  const ret = getStringFromWasm0(arg0, arg1);
711
994
  return ret;
712
995
  };
713
996
 
997
+ export function __wbindgen_cast_d6cd19b81560fd6e(arg0) {
998
+ // Cast intrinsic for `F64 -> Externref`.
999
+ const ret = arg0;
1000
+ return ret;
1001
+ };
1002
+
714
1003
  export function __wbindgen_init_externref_table() {
715
1004
  const table = wasm.__wbindgen_externrefs;
716
1005
  const offset = table.grow(4);
Binary file