@blazediff/core-wasm 4.3.4 → 5.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/dist/index.d.ts CHANGED
@@ -6,9 +6,73 @@ interface DiffOptions {
6
6
  /** Render output with transparent background instead of grayscale base. Default: false */
7
7
  diffMask?: boolean;
8
8
  }
9
+ interface InterpretOptions {
10
+ /** Color difference threshold (0-1). Lower = stricter. Default: 0.1 */
11
+ threshold?: number;
12
+ /** Count anti-aliased pixels as differences. Default: false */
13
+ includeAA?: boolean;
14
+ }
15
+ interface BoundingBox {
16
+ x: number;
17
+ y: number;
18
+ width: number;
19
+ height: number;
20
+ }
21
+ interface ShapeStats {
22
+ fillRatio: number;
23
+ borderRatio: number;
24
+ innerFillRatio: number;
25
+ centerDensity: number;
26
+ rowOccupancy: number;
27
+ colOccupancy: number;
28
+ }
29
+ interface ColorDeltaStats {
30
+ meanDelta: number;
31
+ maxDelta: number;
32
+ deltaStddev: number;
33
+ }
34
+ interface GradientStats {
35
+ edgeScore: number;
36
+ edgeScoreImg2: number;
37
+ edgeCorrelation: number;
38
+ }
39
+ interface ClassificationSignals {
40
+ blendsWithBgInImg1: boolean;
41
+ blendsWithBgInImg2: boolean;
42
+ lowColorDelta: boolean;
43
+ lowEdgeChange: boolean;
44
+ denseFill: boolean;
45
+ sparseFill: boolean;
46
+ tinyRegion: boolean;
47
+ edgesCorrelated: boolean;
48
+ confidence: number;
49
+ }
50
+ interface ChangeRegion {
51
+ bbox: BoundingBox;
52
+ pixelCount: number;
53
+ percentage: number;
54
+ position: string;
55
+ shape: string;
56
+ shapeStats: ShapeStats;
57
+ changeType: string;
58
+ signals: ClassificationSignals;
59
+ confidence: number;
60
+ colorDelta: ColorDeltaStats;
61
+ gradient: GradientStats;
62
+ }
63
+ interface InterpretResult {
64
+ summary: string;
65
+ diffCount: number;
66
+ totalRegions: number;
67
+ regions: ChangeRegion[];
68
+ severity: string;
69
+ diffPercentage: number;
70
+ width: number;
71
+ height: number;
72
+ }
9
73
  type WasmInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
10
74
  /**
11
- * Initialize the wasm module. Safe to call multiple times — subsequent calls
75
+ * Initialize the wasm module. Safe to call multiple times - subsequent calls
12
76
  * return the same promise. By default fetches the bundled `blazediff_bg.wasm`
13
77
  * via the module's import path. Pass a custom `URL`, `Response`, or bytes to
14
78
  * load the wasm from a different location (CDN, custom asset pipeline, etc.).
@@ -25,5 +89,16 @@ declare function initBlazediff(input?: WasmInput): Promise<void>;
25
89
  * diff visualization is written into it in place.
26
90
  */
27
91
  declare function diff(a: Uint8Array, b: Uint8Array, width: number, height: number, output?: Uint8Array, options?: DiffOptions): Promise<number>;
92
+ /**
93
+ * Interpret the diff between two RGBA pixel buffers into structured change
94
+ * regions - what changed, where, and how much. Returns the same shape as the
95
+ * native `@blazediff/core-native` `interpret`, with semantic change types,
96
+ * spatial positions, and severity.
97
+ *
98
+ * Both buffers must be `width * height * 4` bytes in RGBA8 order. Decode
99
+ * PNG/JPEG with `createImageBitmap` + `OffscreenCanvas.getImageData()` (or the
100
+ * `ImageDecoder` API) and pass the resulting `Uint8Array` here.
101
+ */
102
+ declare function interpret(a: Uint8Array, b: Uint8Array, width: number, height: number, options?: InterpretOptions): Promise<InterpretResult>;
28
103
 
29
- export { type DiffOptions, type WasmInput, diff, initBlazediff };
104
+ export { type BoundingBox, type ChangeRegion, type ClassificationSignals, type ColorDeltaStats, type DiffOptions, type GradientStats, type InterpretOptions, type InterpretResult, type ShapeStats, type WasmInput, diff, initBlazediff, interpret };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import a,{diffRgba}from'../wasm/blazediff.js';var i;function d(e){return i||(i=a(e===void 0?void 0:{module_or_path:e}).then(()=>{})),i}async function m(e,r,f,o,t,n={}){return await d(),diffRgba(e,r,f,o,n.threshold??.1,n.includeAA??false,n.diffMask??false,t)}export{m as diff,d as initBlazediff};
1
+ import l,{diffRgba,interpretRgba}from'../wasm/blazediff.js';var o;function s(e){return o||(o=l(e===void 0?void 0:{module_or_path:e}).then(()=>{})),o}async function d(e,n,t,i,r,a={}){return await s(),diffRgba(e,n,t,i,a.threshold??.1,a.includeAA??false,a.diffMask??false,r)}async function f(e,n,t,i,r={}){return await s(),interpretRgba(e,n,t,i,r.threshold??.1,r.includeAA??false)}export{d as diff,s as initBlazediff,f as interpret};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazediff/core-wasm",
3
- "version": "4.3.4",
3
+ "version": "5.1.0",
4
4
  "description": "WebAssembly build of blazediff for browsers, edge runtimes, and any wasm host. Same algorithm as @blazediff/core-native.",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -44,7 +44,7 @@
44
44
  "tsup": "8.5.0",
45
45
  "typescript": "5.9.2",
46
46
  "vitest": "^3.2.4",
47
- "@blazediff/core-native": "4.3.4"
47
+ "@blazediff/core-native": "5.1.0"
48
48
  },
49
49
  "scripts": {
50
50
  "typecheck": "tsc --noEmit",
@@ -1,5 +1,13 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ /**
4
+ * Interpret the diff between two RGBA buffers into structured change regions.
5
+ *
6
+ * Returns the `InterpretResult` (summary, regions with positions, change
7
+ * types, severity, etc.) serialized as a plain JS object - the same shape the
8
+ * native binding produces.
9
+ */
10
+ export function interpretRgba(rgba_a: Uint8Array, rgba_b: Uint8Array, width: number, height: number, threshold: number, include_aa: boolean): any;
3
11
  export function _start(): void;
4
12
  /**
5
13
  * Diff two RGBA buffers. Returns the count of differing pixels.
@@ -16,9 +24,10 @@ export interface InitOutput {
16
24
  readonly memory: WebAssembly.Memory;
17
25
  readonly _start: () => void;
18
26
  readonly diffRgba: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void;
19
- readonly __wbindgen_export_0: (a: number, b: number, c: number) => void;
20
- readonly __wbindgen_export_1: (a: number, b: number) => number;
21
- readonly __wbindgen_export_2: (a: number, b: number, c: number, d: number) => number;
27
+ readonly interpretRgba: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
28
+ readonly __wbindgen_export_0: (a: number, b: number) => number;
29
+ readonly __wbindgen_export_1: (a: number, b: number, c: number, d: number) => number;
30
+ readonly __wbindgen_export_2: (a: number, b: number, c: number) => void;
22
31
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
23
32
  readonly __wbindgen_start: () => void;
24
33
  }
package/wasm/blazediff.js CHANGED
@@ -6,20 +6,7 @@ heap.push(undefined, null, true, false);
6
6
 
7
7
  function getObject(idx) { return heap[idx]; }
8
8
 
9
- let heap_next = heap.length;
10
-
11
- function addHeapObject(obj) {
12
- if (heap_next === heap.length) heap.push(heap.length + 1);
13
- const idx = heap_next;
14
- heap_next = heap[idx];
15
-
16
- heap[idx] = obj;
17
- return idx;
18
- }
19
-
20
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
21
-
22
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
9
+ let WASM_VECTOR_LEN = 0;
23
10
 
24
11
  let cachedUint8ArrayMemory0 = null;
25
12
 
@@ -30,13 +17,6 @@ function getUint8ArrayMemory0() {
30
17
  return cachedUint8ArrayMemory0;
31
18
  }
32
19
 
33
- function getStringFromWasm0(ptr, len) {
34
- ptr = ptr >>> 0;
35
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
36
- }
37
-
38
- let WASM_VECTOR_LEN = 0;
39
-
40
20
  const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
41
21
 
42
22
  const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
@@ -100,6 +80,26 @@ function getDataViewMemory0() {
100
80
  return cachedDataViewMemory0;
101
81
  }
102
82
 
83
+ let heap_next = heap.length;
84
+
85
+ function addHeapObject(obj) {
86
+ if (heap_next === heap.length) heap.push(heap.length + 1);
87
+ const idx = heap_next;
88
+ heap_next = heap[idx];
89
+
90
+ heap[idx] = obj;
91
+ return idx;
92
+ }
93
+
94
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
95
+
96
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
97
+
98
+ function getStringFromWasm0(ptr, len) {
99
+ ptr = ptr >>> 0;
100
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
101
+ }
102
+
103
103
  function dropObject(idx) {
104
104
  if (idx < 132) return;
105
105
  heap[idx] = heap_next;
@@ -112,16 +112,49 @@ function takeObject(idx) {
112
112
  return ret;
113
113
  }
114
114
 
115
- export function _start() {
116
- wasm._start();
117
- }
118
-
119
115
  function passArray8ToWasm0(arg, malloc) {
120
116
  const ptr = malloc(arg.length * 1, 1) >>> 0;
121
117
  getUint8ArrayMemory0().set(arg, ptr / 1);
122
118
  WASM_VECTOR_LEN = arg.length;
123
119
  return ptr;
124
120
  }
121
+ /**
122
+ * Interpret the diff between two RGBA buffers into structured change regions.
123
+ *
124
+ * Returns the `InterpretResult` (summary, regions with positions, change
125
+ * types, severity, etc.) serialized as a plain JS object - the same shape the
126
+ * native binding produces.
127
+ * @param {Uint8Array} rgba_a
128
+ * @param {Uint8Array} rgba_b
129
+ * @param {number} width
130
+ * @param {number} height
131
+ * @param {number} threshold
132
+ * @param {boolean} include_aa
133
+ * @returns {any}
134
+ */
135
+ export function interpretRgba(rgba_a, rgba_b, width, height, threshold, include_aa) {
136
+ try {
137
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
138
+ const ptr0 = passArray8ToWasm0(rgba_a, wasm.__wbindgen_export_0);
139
+ const len0 = WASM_VECTOR_LEN;
140
+ const ptr1 = passArray8ToWasm0(rgba_b, wasm.__wbindgen_export_0);
141
+ const len1 = WASM_VECTOR_LEN;
142
+ wasm.interpretRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, include_aa);
143
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
144
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
145
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
146
+ if (r2) {
147
+ throw takeObject(r1);
148
+ }
149
+ return takeObject(r0);
150
+ } finally {
151
+ wasm.__wbindgen_add_to_stack_pointer(16);
152
+ }
153
+ }
154
+
155
+ export function _start() {
156
+ wasm._start();
157
+ }
125
158
 
126
159
  function isLikeNone(x) {
127
160
  return x === undefined || x === null;
@@ -145,9 +178,9 @@ function isLikeNone(x) {
145
178
  export function diffRgba(rgba_a, rgba_b, width, height, threshold, include_aa, diff_mask, out_diff) {
146
179
  try {
147
180
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
148
- const ptr0 = passArray8ToWasm0(rgba_a, wasm.__wbindgen_export_1);
181
+ const ptr0 = passArray8ToWasm0(rgba_a, wasm.__wbindgen_export_0);
149
182
  const len0 = WASM_VECTOR_LEN;
150
- const ptr1 = passArray8ToWasm0(rgba_b, wasm.__wbindgen_export_1);
183
+ const ptr1 = passArray8ToWasm0(rgba_b, wasm.__wbindgen_export_0);
151
184
  const len1 = WASM_VECTOR_LEN;
152
185
  wasm.diffRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, include_aa, diff_mask, isLikeNone(out_diff) ? 0 : addHeapObject(out_diff));
153
186
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
@@ -196,6 +229,13 @@ async function __wbg_load(module, imports) {
196
229
  function __wbg_get_imports() {
197
230
  const imports = {};
198
231
  imports.wbg = {};
232
+ imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
233
+ const ret = String(getObject(arg1));
234
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
235
+ const len1 = WASM_VECTOR_LEN;
236
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
237
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
238
+ };
199
239
  imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
200
240
  const ret = getObject(arg0).buffer;
201
241
  return addHeapObject(ret);
@@ -208,13 +248,21 @@ function __wbg_get_imports() {
208
248
  deferred0_1 = arg1;
209
249
  console.error(getStringFromWasm0(arg0, arg1));
210
250
  } finally {
211
- wasm.__wbindgen_export_0(deferred0_0, deferred0_1, 1);
251
+ wasm.__wbindgen_export_2(deferred0_0, deferred0_1, 1);
212
252
  }
213
253
  };
214
254
  imports.wbg.__wbg_length_a446193dc22c12f8 = function(arg0) {
215
255
  const ret = getObject(arg0).length;
216
256
  return ret;
217
257
  };
258
+ imports.wbg.__wbg_new_405e22f390576ce2 = function() {
259
+ const ret = new Object();
260
+ return addHeapObject(ret);
261
+ };
262
+ imports.wbg.__wbg_new_78feb108b6472713 = function() {
263
+ const ret = new Array();
264
+ return addHeapObject(ret);
265
+ };
218
266
  imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
219
267
  const ret = new Error();
220
268
  return addHeapObject(ret);
@@ -223,16 +271,26 @@ function __wbg_get_imports() {
223
271
  const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
224
272
  return addHeapObject(ret);
225
273
  };
274
+ imports.wbg.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) {
275
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
276
+ };
277
+ imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
278
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
279
+ };
226
280
  imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
227
281
  getObject(arg0).set(getObject(arg1), arg2 >>> 0);
228
282
  };
229
283
  imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
230
284
  const ret = getObject(arg1).stack;
231
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
285
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
232
286
  const len1 = WASM_VECTOR_LEN;
233
287
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
234
288
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
235
289
  };
290
+ imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
291
+ const ret = BigInt.asUintN(64, arg0);
292
+ return addHeapObject(ret);
293
+ };
236
294
  imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
237
295
  const ret = new Error(getStringFromWasm0(arg0, arg1));
238
296
  return addHeapObject(ret);
@@ -241,9 +299,21 @@ function __wbg_get_imports() {
241
299
  const ret = wasm.memory;
242
300
  return addHeapObject(ret);
243
301
  };
302
+ imports.wbg.__wbindgen_number_new = function(arg0) {
303
+ const ret = arg0;
304
+ return addHeapObject(ret);
305
+ };
306
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
307
+ const ret = getObject(arg0);
308
+ return addHeapObject(ret);
309
+ };
244
310
  imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
245
311
  takeObject(arg0);
246
312
  };
313
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
314
+ const ret = getStringFromWasm0(arg0, arg1);
315
+ return addHeapObject(ret);
316
+ };
247
317
  imports.wbg.__wbindgen_throw = function(arg0, arg1) {
248
318
  throw new Error(getStringFromWasm0(arg0, arg1));
249
319
  };
Binary file
@@ -3,8 +3,9 @@
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const _start: () => void;
5
5
  export const diffRgba: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void;
6
- export const __wbindgen_export_0: (a: number, b: number, c: number) => void;
7
- export const __wbindgen_export_1: (a: number, b: number) => number;
8
- export const __wbindgen_export_2: (a: number, b: number, c: number, d: number) => number;
6
+ export const interpretRgba: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
7
+ export const __wbindgen_export_0: (a: number, b: number) => number;
8
+ export const __wbindgen_export_1: (a: number, b: number, c: number, d: number) => number;
9
+ export const __wbindgen_export_2: (a: number, b: number, c: number) => void;
9
10
  export const __wbindgen_add_to_stack_pointer: (a: number) => number;
10
11
  export const __wbindgen_start: () => void;