@blazediff/core-wasm 5.1.0 → 5.3.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/README.md CHANGED
@@ -103,7 +103,7 @@ Initializes the wasm module. Safe to call multiple times; subsequent calls retur
103
103
 
104
104
  ### `diff(a, b, width, height, output?, options?)`
105
105
 
106
- Compares two RGBA pixel buffers and returns the number of differing pixels.
106
+ Compares two RGBA pixel buffers and returns the number of differing pixels. Set `interpret: true` to return structured interpretation while producing the diff output in the same pass.
107
107
 
108
108
  <table>
109
109
  <tr>
@@ -138,12 +138,12 @@ Compares two RGBA pixel buffers and returns the number of differing pixels.
138
138
  </tr>
139
139
  <tr>
140
140
  <td><code>options</code></td>
141
- <td>DiffOptions</td>
141
+ <td>DiffOptions | InterpretedDiffOptions</td>
142
142
  <td>Comparison options (optional)</td>
143
143
  </tr>
144
144
  </table>
145
145
 
146
- **Returns:** `Promise<number>` (count of differing pixels)
146
+ **Returns:** `Promise<number>` by default, or `Promise<DiffResult>` with `interpret: true`
147
147
 
148
148
  <table>
149
149
  <tr>
@@ -170,8 +170,47 @@ Compares two RGBA pixel buffers and returns the number of differing pixels.
170
170
  <td>false</td>
171
171
  <td>Render diff with transparent background instead of grayscale base</td>
172
172
  </tr>
173
+ <tr>
174
+ <td><code>diffColorAlt</code></td>
175
+ <td>[number, number, number]</td>
176
+ <td>diff color</td>
177
+ <td>Alternative RGB color for darkening differences</td>
178
+ </tr>
179
+ <tr>
180
+ <td><code>interpret</code></td>
181
+ <td>boolean</td>
182
+ <td>false</td>
183
+ <td>Return structured interpretation from the same diff pass</td>
184
+ </tr>
173
185
  </table>
174
186
 
187
+ With `interpret: true`, `diff()` returns:
188
+
189
+ ```typescript
190
+ type DiffResult =
191
+ | { match: true; interpretation: InterpretResult }
192
+ | {
193
+ match: false;
194
+ reason: 'pixel-diff';
195
+ diffCount: number;
196
+ diffPercentage: number;
197
+ interpretation: InterpretResult;
198
+ };
199
+ ```
200
+
201
+ ```typescript
202
+ const result = await diff(a, b, width, height, output, {
203
+ diffColorAlt: [0, 128, 255],
204
+ interpret: true,
205
+ });
206
+ ```
207
+
208
+ ### `interpret(a, b, width, height, options?)`
209
+
210
+ Returns structured change regions without retaining a diff visualization. It is a convenience wrapper over `diff()` with `interpret: true`.
211
+
212
+ **Returns:** `Promise<InterpretResult>`
213
+
175
214
  ## Usage
176
215
 
177
216
  ### Browser
package/dist/index.d.ts CHANGED
@@ -5,6 +5,12 @@ interface DiffOptions {
5
5
  includeAA?: boolean;
6
6
  /** Render output with transparent background instead of grayscale base. Default: false */
7
7
  diffMask?: boolean;
8
+ /** Alternative RGB color for darkening differences. Default: diff color */
9
+ diffColorAlt?: [number, number, number];
10
+ }
11
+ interface InterpretedDiffOptions extends DiffOptions {
12
+ /** Return structured interpretation from the same diff pass. */
13
+ interpret: true;
8
14
  }
9
15
  interface InterpretOptions {
10
16
  /** Color difference threshold (0-1). Lower = stricter. Default: 0.1 */
@@ -70,6 +76,16 @@ interface InterpretResult {
70
76
  width: number;
71
77
  height: number;
72
78
  }
79
+ type DiffResult = {
80
+ match: true;
81
+ interpretation: InterpretResult;
82
+ } | {
83
+ match: false;
84
+ reason: "pixel-diff";
85
+ diffCount: number;
86
+ diffPercentage: number;
87
+ interpretation: InterpretResult;
88
+ };
73
89
  type WasmInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
74
90
  /**
75
91
  * Initialize the wasm module. Safe to call multiple times - subsequent calls
@@ -86,9 +102,16 @@ declare function initBlazediff(input?: WasmInput): Promise<void>;
86
102
  * the `ImageDecoder` API) and pass the resulting `Uint8Array` here.
87
103
  *
88
104
  * If `output` is provided it must be `width * height * 4` bytes long and the
89
- * diff visualization is written into it in place.
105
+ * diff visualization is written into it in place. Set `interpret: true` to
106
+ * return structured interpretation from the same diff pass.
90
107
  */
91
- declare function diff(a: Uint8Array, b: Uint8Array, width: number, height: number, output?: Uint8Array, options?: DiffOptions): Promise<number>;
108
+ declare function diff(a: Uint8Array, b: Uint8Array, width: number, height: number, output: Uint8Array | undefined, options: InterpretedDiffOptions): Promise<DiffResult>;
109
+ declare function diff(a: Uint8Array, b: Uint8Array, width: number, height: number, output?: Uint8Array, options?: DiffOptions & {
110
+ interpret?: false;
111
+ }): Promise<number>;
112
+ declare function diff(a: Uint8Array, b: Uint8Array, width: number, height: number, output?: Uint8Array, options?: DiffOptions & {
113
+ interpret?: boolean;
114
+ }): Promise<number | DiffResult>;
92
115
  /**
93
116
  * Interpret the diff between two RGBA pixel buffers into structured change
94
117
  * regions - what changed, where, and how much. Returns the same shape as the
@@ -101,4 +124,4 @@ declare function diff(a: Uint8Array, b: Uint8Array, width: number, height: numbe
101
124
  */
102
125
  declare function interpret(a: Uint8Array, b: Uint8Array, width: number, height: number, options?: InterpretOptions): Promise<InterpretResult>;
103
126
 
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 };
127
+ export { type BoundingBox, type ChangeRegion, type ClassificationSignals, type ColorDeltaStats, type DiffOptions, type DiffResult, type GradientStats, type InterpretOptions, type InterpretResult, type InterpretedDiffOptions, type ShapeStats, type WasmInput, diff, initBlazediff, interpret };
package/dist/index.js CHANGED
@@ -1 +1 @@
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};
1
+ import s,{diffRgba,interpretRgba}from'../wasm/blazediff.js';var o;function f(e){if(e){if(e.length!==3||e.some(r=>!Number.isInteger(r)||r<0||r>255))throw new RangeError("diffColorAlt must contain three integer RGB channels");return Uint8Array.from(e)}}function b(e){return e.diffCount===0?{match:true,interpretation:e}:{match:false,reason:"pixel-diff",diffCount:e.diffCount,diffPercentage:e.diffPercentage,interpretation:e}}function m(e){return o||(o=s(e===void 0?void 0:{module_or_path:e}).then(()=>{})),o}async function p(e,r,t,i,a,n={}){if(await m(),!n.interpret)return diffRgba(e,r,t,i,n.threshold??.1,n.includeAA??false,n.diffMask??false,f(n.diffColorAlt),a);let u=interpretRgba(e,r,t,i,n.threshold??.1,n.includeAA??false,n.diffMask??false,f(n.diffColorAlt),a);return b(u)}async function c(e,r,t,i,a={}){return (await p(e,r,t,i,void 0,{...a,interpret:true})).interpretation}export{p as diff,m as initBlazediff,c as interpret};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazediff/core-wasm",
3
- "version": "5.1.0",
3
+ "version": "5.3.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": "5.1.0"
47
+ "@blazediff/core-native": "5.3.0"
48
48
  },
49
49
  "scripts": {
50
50
  "typecheck": "tsc --noEmit",
@@ -1,13 +1,5 @@
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;
11
3
  export function _start(): void;
12
4
  /**
13
5
  * Diff two RGBA buffers. Returns the count of differing pixels.
@@ -16,15 +8,23 @@ export function _start(): void;
16
8
  * (must be width*height*4 bytes). Pass `null`/`undefined` to skip the
17
9
  * visualization and just get a count.
18
10
  */
19
- export function diffRgba(rgba_a: Uint8Array, rgba_b: Uint8Array, width: number, height: number, threshold: number, include_aa: boolean, diff_mask: boolean, out_diff?: Uint8Array | null): number;
11
+ export function diffRgba(rgba_a: Uint8Array, rgba_b: Uint8Array, width: number, height: number, threshold: number, include_aa: boolean, diff_mask: boolean, diff_color_alt?: Uint8Array | null, out_diff?: Uint8Array | null): number;
12
+ /**
13
+ * Interpret the diff between two RGBA buffers into structured change regions.
14
+ *
15
+ * Returns the `InterpretResult` (summary, regions with positions, change
16
+ * types, severity, etc.) serialized as a plain JS object - the same shape the
17
+ * native binding produces.
18
+ */
19
+ export function interpretRgba(rgba_a: Uint8Array, rgba_b: Uint8Array, width: number, height: number, threshold: number, include_aa: boolean, diff_mask: boolean, diff_color_alt?: Uint8Array | null, out_diff?: Uint8Array | null): any;
20
20
 
21
21
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
22
22
 
23
23
  export interface InitOutput {
24
24
  readonly memory: WebAssembly.Memory;
25
25
  readonly _start: () => void;
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;
27
- readonly interpretRgba: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
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, l: number, m: number) => void;
27
+ readonly interpretRgba: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => void;
28
28
  readonly __wbindgen_export_0: (a: number, b: number) => number;
29
29
  readonly __wbindgen_export_1: (a: number, b: number, c: number, d: number) => number;
30
30
  readonly __wbindgen_export_2: (a: number, b: number, c: number) => void;
package/wasm/blazediff.js CHANGED
@@ -112,59 +112,65 @@ function takeObject(idx) {
112
112
  return ret;
113
113
  }
114
114
 
115
+ export function _start() {
116
+ wasm._start();
117
+ }
118
+
115
119
  function passArray8ToWasm0(arg, malloc) {
116
120
  const ptr = malloc(arg.length * 1, 1) >>> 0;
117
121
  getUint8ArrayMemory0().set(arg, ptr / 1);
118
122
  WASM_VECTOR_LEN = arg.length;
119
123
  return ptr;
120
124
  }
125
+
126
+ function isLikeNone(x) {
127
+ return x === undefined || x === null;
128
+ }
121
129
  /**
122
- * Interpret the diff between two RGBA buffers into structured change regions.
130
+ * Diff two RGBA buffers. Returns the count of differing pixels.
123
131
  *
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.
132
+ * If `out_diff` is provided, the visualization is written into it in-place
133
+ * (must be width*height*4 bytes). Pass `null`/`undefined` to skip the
134
+ * visualization and just get a count.
127
135
  * @param {Uint8Array} rgba_a
128
136
  * @param {Uint8Array} rgba_b
129
137
  * @param {number} width
130
138
  * @param {number} height
131
139
  * @param {number} threshold
132
140
  * @param {boolean} include_aa
133
- * @returns {any}
141
+ * @param {boolean} diff_mask
142
+ * @param {Uint8Array | null} [diff_color_alt]
143
+ * @param {Uint8Array | null} [out_diff]
144
+ * @returns {number}
134
145
  */
135
- export function interpretRgba(rgba_a, rgba_b, width, height, threshold, include_aa) {
146
+ export function diffRgba(rgba_a, rgba_b, width, height, threshold, include_aa, diff_mask, diff_color_alt, out_diff) {
136
147
  try {
137
148
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
138
149
  const ptr0 = passArray8ToWasm0(rgba_a, wasm.__wbindgen_export_0);
139
150
  const len0 = WASM_VECTOR_LEN;
140
151
  const ptr1 = passArray8ToWasm0(rgba_b, wasm.__wbindgen_export_0);
141
152
  const len1 = WASM_VECTOR_LEN;
142
- wasm.interpretRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, include_aa);
153
+ var ptr2 = isLikeNone(diff_color_alt) ? 0 : passArray8ToWasm0(diff_color_alt, wasm.__wbindgen_export_0);
154
+ var len2 = WASM_VECTOR_LEN;
155
+ wasm.diffRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, include_aa, diff_mask, ptr2, len2, isLikeNone(out_diff) ? 0 : addHeapObject(out_diff));
143
156
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
144
157
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
145
158
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
146
159
  if (r2) {
147
160
  throw takeObject(r1);
148
161
  }
149
- return takeObject(r0);
162
+ return r0 >>> 0;
150
163
  } finally {
151
164
  wasm.__wbindgen_add_to_stack_pointer(16);
152
165
  }
153
166
  }
154
167
 
155
- export function _start() {
156
- wasm._start();
157
- }
158
-
159
- function isLikeNone(x) {
160
- return x === undefined || x === null;
161
- }
162
168
  /**
163
- * Diff two RGBA buffers. Returns the count of differing pixels.
169
+ * Interpret the diff between two RGBA buffers into structured change regions.
164
170
  *
165
- * If `out_diff` is provided, the visualization is written into it in-place
166
- * (must be width*height*4 bytes). Pass `null`/`undefined` to skip the
167
- * visualization and just get a count.
171
+ * Returns the `InterpretResult` (summary, regions with positions, change
172
+ * types, severity, etc.) serialized as a plain JS object - the same shape the
173
+ * native binding produces.
168
174
  * @param {Uint8Array} rgba_a
169
175
  * @param {Uint8Array} rgba_b
170
176
  * @param {number} width
@@ -172,24 +178,27 @@ function isLikeNone(x) {
172
178
  * @param {number} threshold
173
179
  * @param {boolean} include_aa
174
180
  * @param {boolean} diff_mask
181
+ * @param {Uint8Array | null} [diff_color_alt]
175
182
  * @param {Uint8Array | null} [out_diff]
176
- * @returns {number}
183
+ * @returns {any}
177
184
  */
178
- export function diffRgba(rgba_a, rgba_b, width, height, threshold, include_aa, diff_mask, out_diff) {
185
+ export function interpretRgba(rgba_a, rgba_b, width, height, threshold, include_aa, diff_mask, diff_color_alt, out_diff) {
179
186
  try {
180
187
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
181
188
  const ptr0 = passArray8ToWasm0(rgba_a, wasm.__wbindgen_export_0);
182
189
  const len0 = WASM_VECTOR_LEN;
183
190
  const ptr1 = passArray8ToWasm0(rgba_b, wasm.__wbindgen_export_0);
184
191
  const len1 = WASM_VECTOR_LEN;
185
- wasm.diffRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, include_aa, diff_mask, isLikeNone(out_diff) ? 0 : addHeapObject(out_diff));
192
+ var ptr2 = isLikeNone(diff_color_alt) ? 0 : passArray8ToWasm0(diff_color_alt, wasm.__wbindgen_export_0);
193
+ var len2 = WASM_VECTOR_LEN;
194
+ wasm.interpretRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, include_aa, diff_mask, ptr2, len2, isLikeNone(out_diff) ? 0 : addHeapObject(out_diff));
186
195
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
187
196
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
188
197
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
189
198
  if (r2) {
190
199
  throw takeObject(r1);
191
200
  }
192
- return r0 >>> 0;
201
+ return takeObject(r0);
193
202
  } finally {
194
203
  wasm.__wbindgen_add_to_stack_pointer(16);
195
204
  }
Binary file
@@ -2,8 +2,8 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const _start: () => void;
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 interpretRgba: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
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, l: number, m: number) => void;
6
+ export const interpretRgba: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => void;
7
7
  export const __wbindgen_export_0: (a: number, b: number) => number;
8
8
  export const __wbindgen_export_1: (a: number, b: number, c: number, d: number) => number;
9
9
  export const __wbindgen_export_2: (a: number, b: number, c: number) => void;