@blazediff/core-wasm 5.1.0 → 5.2.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 +42 -3
- package/dist/index.d.ts +26 -3
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/wasm/blazediff.d.ts +11 -11
- package/wasm/blazediff.js +32 -23
- package/wasm/blazediff_bg.wasm +0 -0
- package/wasm/blazediff_bg.wasm.d.ts +2 -2
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>`
|
|
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
|
|
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
|
|
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.
|
|
3
|
+
"version": "5.2.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.
|
|
47
|
+
"@blazediff/core-native": "5.2.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"typecheck": "tsc --noEmit",
|
package/wasm/blazediff.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Diff two RGBA buffers. Returns the count of differing pixels.
|
|
5
|
+
*
|
|
6
|
+
* If `out_diff` is provided, the visualization is written into it in-place
|
|
7
|
+
* (must be width*height*4 bytes). Pass `null`/`undefined` to skip the
|
|
8
|
+
* visualization and just get a count.
|
|
9
|
+
*/
|
|
10
|
+
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;
|
|
3
11
|
/**
|
|
4
12
|
* Interpret the diff between two RGBA buffers into structured change regions.
|
|
5
13
|
*
|
|
@@ -7,24 +15,16 @@
|
|
|
7
15
|
* types, severity, etc.) serialized as a plain JS object - the same shape the
|
|
8
16
|
* native binding produces.
|
|
9
17
|
*/
|
|
10
|
-
export function interpretRgba(rgba_a: Uint8Array, rgba_b: Uint8Array, width: number, height: number, threshold: number, include_aa: boolean): any;
|
|
18
|
+
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;
|
|
11
19
|
export function _start(): void;
|
|
12
|
-
/**
|
|
13
|
-
* Diff two RGBA buffers. Returns the count of differing pixels.
|
|
14
|
-
*
|
|
15
|
-
* If `out_diff` is provided, the visualization is written into it in-place
|
|
16
|
-
* (must be width*height*4 bytes). Pass `null`/`undefined` to skip the
|
|
17
|
-
* visualization and just get a count.
|
|
18
|
-
*/
|
|
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;
|
|
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
|
@@ -118,53 +118,55 @@ function passArray8ToWasm0(arg, malloc) {
|
|
|
118
118
|
WASM_VECTOR_LEN = arg.length;
|
|
119
119
|
return ptr;
|
|
120
120
|
}
|
|
121
|
+
|
|
122
|
+
function isLikeNone(x) {
|
|
123
|
+
return x === undefined || x === null;
|
|
124
|
+
}
|
|
121
125
|
/**
|
|
122
|
-
*
|
|
126
|
+
* Diff two RGBA buffers. Returns the count of differing pixels.
|
|
123
127
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
128
|
+
* If `out_diff` is provided, the visualization is written into it in-place
|
|
129
|
+
* (must be width*height*4 bytes). Pass `null`/`undefined` to skip the
|
|
130
|
+
* visualization and just get a count.
|
|
127
131
|
* @param {Uint8Array} rgba_a
|
|
128
132
|
* @param {Uint8Array} rgba_b
|
|
129
133
|
* @param {number} width
|
|
130
134
|
* @param {number} height
|
|
131
135
|
* @param {number} threshold
|
|
132
136
|
* @param {boolean} include_aa
|
|
133
|
-
* @
|
|
137
|
+
* @param {boolean} diff_mask
|
|
138
|
+
* @param {Uint8Array | null} [diff_color_alt]
|
|
139
|
+
* @param {Uint8Array | null} [out_diff]
|
|
140
|
+
* @returns {number}
|
|
134
141
|
*/
|
|
135
|
-
export function
|
|
142
|
+
export function diffRgba(rgba_a, rgba_b, width, height, threshold, include_aa, diff_mask, diff_color_alt, out_diff) {
|
|
136
143
|
try {
|
|
137
144
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
138
145
|
const ptr0 = passArray8ToWasm0(rgba_a, wasm.__wbindgen_export_0);
|
|
139
146
|
const len0 = WASM_VECTOR_LEN;
|
|
140
147
|
const ptr1 = passArray8ToWasm0(rgba_b, wasm.__wbindgen_export_0);
|
|
141
148
|
const len1 = WASM_VECTOR_LEN;
|
|
142
|
-
|
|
149
|
+
var ptr2 = isLikeNone(diff_color_alt) ? 0 : passArray8ToWasm0(diff_color_alt, wasm.__wbindgen_export_0);
|
|
150
|
+
var len2 = WASM_VECTOR_LEN;
|
|
151
|
+
wasm.diffRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, include_aa, diff_mask, ptr2, len2, isLikeNone(out_diff) ? 0 : addHeapObject(out_diff));
|
|
143
152
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
144
153
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
145
154
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
146
155
|
if (r2) {
|
|
147
156
|
throw takeObject(r1);
|
|
148
157
|
}
|
|
149
|
-
return
|
|
158
|
+
return r0 >>> 0;
|
|
150
159
|
} finally {
|
|
151
160
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
152
161
|
}
|
|
153
162
|
}
|
|
154
163
|
|
|
155
|
-
export function _start() {
|
|
156
|
-
wasm._start();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function isLikeNone(x) {
|
|
160
|
-
return x === undefined || x === null;
|
|
161
|
-
}
|
|
162
164
|
/**
|
|
163
|
-
*
|
|
165
|
+
* Interpret the diff between two RGBA buffers into structured change regions.
|
|
164
166
|
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
167
|
+
* Returns the `InterpretResult` (summary, regions with positions, change
|
|
168
|
+
* types, severity, etc.) serialized as a plain JS object - the same shape the
|
|
169
|
+
* native binding produces.
|
|
168
170
|
* @param {Uint8Array} rgba_a
|
|
169
171
|
* @param {Uint8Array} rgba_b
|
|
170
172
|
* @param {number} width
|
|
@@ -172,29 +174,36 @@ function isLikeNone(x) {
|
|
|
172
174
|
* @param {number} threshold
|
|
173
175
|
* @param {boolean} include_aa
|
|
174
176
|
* @param {boolean} diff_mask
|
|
177
|
+
* @param {Uint8Array | null} [diff_color_alt]
|
|
175
178
|
* @param {Uint8Array | null} [out_diff]
|
|
176
|
-
* @returns {
|
|
179
|
+
* @returns {any}
|
|
177
180
|
*/
|
|
178
|
-
export function
|
|
181
|
+
export function interpretRgba(rgba_a, rgba_b, width, height, threshold, include_aa, diff_mask, diff_color_alt, out_diff) {
|
|
179
182
|
try {
|
|
180
183
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
181
184
|
const ptr0 = passArray8ToWasm0(rgba_a, wasm.__wbindgen_export_0);
|
|
182
185
|
const len0 = WASM_VECTOR_LEN;
|
|
183
186
|
const ptr1 = passArray8ToWasm0(rgba_b, wasm.__wbindgen_export_0);
|
|
184
187
|
const len1 = WASM_VECTOR_LEN;
|
|
185
|
-
|
|
188
|
+
var ptr2 = isLikeNone(diff_color_alt) ? 0 : passArray8ToWasm0(diff_color_alt, wasm.__wbindgen_export_0);
|
|
189
|
+
var len2 = WASM_VECTOR_LEN;
|
|
190
|
+
wasm.interpretRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, include_aa, diff_mask, ptr2, len2, isLikeNone(out_diff) ? 0 : addHeapObject(out_diff));
|
|
186
191
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
187
192
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
188
193
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
189
194
|
if (r2) {
|
|
190
195
|
throw takeObject(r1);
|
|
191
196
|
}
|
|
192
|
-
return r0
|
|
197
|
+
return takeObject(r0);
|
|
193
198
|
} finally {
|
|
194
199
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
195
200
|
}
|
|
196
201
|
}
|
|
197
202
|
|
|
203
|
+
export function _start() {
|
|
204
|
+
wasm._start();
|
|
205
|
+
}
|
|
206
|
+
|
|
198
207
|
async function __wbg_load(module, imports) {
|
|
199
208
|
if (typeof Response === 'function' && module instanceof Response) {
|
|
200
209
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
package/wasm/blazediff_bg.wasm
CHANGED
|
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;
|