@blazediff/core-wasm 5.2.0 → 5.4.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 +9 -8
- package/package.json +2 -2
- package/wasm/blazediff.d.ts +8 -8
- package/wasm/blazediff.js +20 -20
- package/wasm/blazediff_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
|
-
WebAssembly build of the BlazeDiff Rust algorithm for browsers, edge runtimes, and any wasm host. Same two-pass block algorithm as [`@blazediff/core-native`](https://www.npmjs.com/package/@blazediff/core-native), compiled to `wasm32` with `v128` SIMD (`+simd128`). **~
|
|
11
|
+
WebAssembly build of the BlazeDiff Rust algorithm for browsers, edge runtimes, and any wasm host. Same two-pass block algorithm as [`@blazediff/core-native`](https://www.npmjs.com/package/@blazediff/core-native), compiled to `wasm32` with `v128` SIMD (`+simd128`). **~51%** faster than [pixelmatch](https://github.com/mapbox/pixelmatch) on the same RGBA buffers (up to ~90% on 4K); diff counts agree with pixelmatch to within ~0.05%.
|
|
12
12
|
|
|
13
13
|
**Features:**
|
|
14
14
|
- Same Rust algorithm as `@blazediff/core-native` (YIQ perceptual delta + block-based cold/hot pass)
|
|
@@ -271,13 +271,14 @@ vs `pixelmatch` on M1 Max, image I/O excluded (pre-decoded RGBA buffers):
|
|
|
271
271
|
|
|
272
272
|
| Fixture | pixelmatch | core-wasm | Improvement |
|
|
273
273
|
|---------------|------------|-----------|-------------|
|
|
274
|
-
| 4k/1 |
|
|
275
|
-
| 4k/3 |
|
|
276
|
-
| page/2 |
|
|
277
|
-
| blazediff/3 |
|
|
278
|
-
| pixelmatch/1 | 0.
|
|
279
|
-
|
|
280
|
-
Average **~
|
|
274
|
+
| 4k/1 | 338.53ms | 34.42ms | **89.8%** |
|
|
275
|
+
| 4k/3 | 415.01ms | 45.34ms | **89.1%** |
|
|
276
|
+
| page/2 | 511.88ms | 70.89ms | **86.2%** |
|
|
277
|
+
| blazediff/3 | 12.08ms | 5.76ms | **52.3%** |
|
|
278
|
+
| pixelmatch/1 | 0.57ms | 0.11ms | **80.5%** |
|
|
279
|
+
|
|
280
|
+
Average **~51%** faster across the full fixture set (~60% across differing pairs). Counts agree with pixelmatch within ~0.05% (e.g. `4k/1`: 69 932 vs 69 912 of 17 920 000 pixels).
|
|
281
|
+
Full benchmarks in [BENCHMARKS.md](https://github.com/teimurjan/blazediff/blob/main/BENCHMARKS.md).
|
|
281
282
|
|
|
282
283
|
## Algorithm
|
|
283
284
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blazediff/core-wasm",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.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.4.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"typecheck": "tsc --noEmit",
|
package/wasm/blazediff.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
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;
|
|
11
3
|
/**
|
|
12
4
|
* Interpret the diff between two RGBA buffers into structured change regions.
|
|
13
5
|
*
|
|
@@ -17,6 +9,14 @@ export function diffRgba(rgba_a: Uint8Array, rgba_b: Uint8Array, width: number,
|
|
|
17
9
|
*/
|
|
18
10
|
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;
|
|
19
11
|
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, diff_color_alt?: Uint8Array | null, out_diff?: Uint8Array | null): number;
|
|
20
20
|
|
|
21
21
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
22
22
|
|
package/wasm/blazediff.js
CHANGED
|
@@ -123,11 +123,11 @@ function isLikeNone(x) {
|
|
|
123
123
|
return x === undefined || x === null;
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
126
|
+
* Interpret the diff between two RGBA buffers into structured change regions.
|
|
127
127
|
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
128
|
+
* Returns the `InterpretResult` (summary, regions with positions, change
|
|
129
|
+
* types, severity, etc.) serialized as a plain JS object - the same shape the
|
|
130
|
+
* native binding produces.
|
|
131
131
|
* @param {Uint8Array} rgba_a
|
|
132
132
|
* @param {Uint8Array} rgba_b
|
|
133
133
|
* @param {number} width
|
|
@@ -137,9 +137,9 @@ function isLikeNone(x) {
|
|
|
137
137
|
* @param {boolean} diff_mask
|
|
138
138
|
* @param {Uint8Array | null} [diff_color_alt]
|
|
139
139
|
* @param {Uint8Array | null} [out_diff]
|
|
140
|
-
* @returns {
|
|
140
|
+
* @returns {any}
|
|
141
141
|
*/
|
|
142
|
-
export function
|
|
142
|
+
export function interpretRgba(rgba_a, rgba_b, width, height, threshold, include_aa, diff_mask, diff_color_alt, out_diff) {
|
|
143
143
|
try {
|
|
144
144
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
145
145
|
const ptr0 = passArray8ToWasm0(rgba_a, wasm.__wbindgen_export_0);
|
|
@@ -148,25 +148,29 @@ export function diffRgba(rgba_a, rgba_b, width, height, threshold, include_aa, d
|
|
|
148
148
|
const len1 = WASM_VECTOR_LEN;
|
|
149
149
|
var ptr2 = isLikeNone(diff_color_alt) ? 0 : passArray8ToWasm0(diff_color_alt, wasm.__wbindgen_export_0);
|
|
150
150
|
var len2 = WASM_VECTOR_LEN;
|
|
151
|
-
wasm.
|
|
151
|
+
wasm.interpretRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, include_aa, diff_mask, ptr2, len2, isLikeNone(out_diff) ? 0 : addHeapObject(out_diff));
|
|
152
152
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
153
153
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
154
154
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
155
155
|
if (r2) {
|
|
156
156
|
throw takeObject(r1);
|
|
157
157
|
}
|
|
158
|
-
return r0
|
|
158
|
+
return takeObject(r0);
|
|
159
159
|
} finally {
|
|
160
160
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
export function _start() {
|
|
165
|
+
wasm._start();
|
|
166
|
+
}
|
|
167
|
+
|
|
164
168
|
/**
|
|
165
|
-
*
|
|
169
|
+
* Diff two RGBA buffers. Returns the count of differing pixels.
|
|
166
170
|
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
171
|
+
* If `out_diff` is provided, the visualization is written into it in-place
|
|
172
|
+
* (must be width*height*4 bytes). Pass `null`/`undefined` to skip the
|
|
173
|
+
* visualization and just get a count.
|
|
170
174
|
* @param {Uint8Array} rgba_a
|
|
171
175
|
* @param {Uint8Array} rgba_b
|
|
172
176
|
* @param {number} width
|
|
@@ -176,9 +180,9 @@ export function diffRgba(rgba_a, rgba_b, width, height, threshold, include_aa, d
|
|
|
176
180
|
* @param {boolean} diff_mask
|
|
177
181
|
* @param {Uint8Array | null} [diff_color_alt]
|
|
178
182
|
* @param {Uint8Array | null} [out_diff]
|
|
179
|
-
* @returns {
|
|
183
|
+
* @returns {number}
|
|
180
184
|
*/
|
|
181
|
-
export function
|
|
185
|
+
export function diffRgba(rgba_a, rgba_b, width, height, threshold, include_aa, diff_mask, diff_color_alt, out_diff) {
|
|
182
186
|
try {
|
|
183
187
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
184
188
|
const ptr0 = passArray8ToWasm0(rgba_a, wasm.__wbindgen_export_0);
|
|
@@ -187,23 +191,19 @@ export function interpretRgba(rgba_a, rgba_b, width, height, threshold, include_
|
|
|
187
191
|
const len1 = WASM_VECTOR_LEN;
|
|
188
192
|
var ptr2 = isLikeNone(diff_color_alt) ? 0 : passArray8ToWasm0(diff_color_alt, wasm.__wbindgen_export_0);
|
|
189
193
|
var len2 = WASM_VECTOR_LEN;
|
|
190
|
-
wasm.
|
|
194
|
+
wasm.diffRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, include_aa, diff_mask, ptr2, len2, isLikeNone(out_diff) ? 0 : addHeapObject(out_diff));
|
|
191
195
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
192
196
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
193
197
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
194
198
|
if (r2) {
|
|
195
199
|
throw takeObject(r1);
|
|
196
200
|
}
|
|
197
|
-
return
|
|
201
|
+
return r0 >>> 0;
|
|
198
202
|
} finally {
|
|
199
203
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
200
204
|
}
|
|
201
205
|
}
|
|
202
206
|
|
|
203
|
-
export function _start() {
|
|
204
|
-
wasm._start();
|
|
205
|
-
}
|
|
206
|
-
|
|
207
207
|
async function __wbg_load(module, imports) {
|
|
208
208
|
if (typeof Response === 'function' && module instanceof Response) {
|
|
209
209
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
package/wasm/blazediff_bg.wasm
CHANGED
|
Binary file
|