@blazediff/core-wasm 6.0.2 → 8.0.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 +74 -68
- package/dist/index.d.ts +9 -19
- package/dist/index.js +1 -1
- package/package.json +5 -2
- package/wasm/blazediff.d.ts +6 -6
- package/wasm/blazediff.js +46 -14
- package/wasm/blazediff_bg.wasm +0 -0
- package/wasm/blazediff_bg.wasm.d.ts +1 -1
package/README.md
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
|
-
WebAssembly build of the BlazeDiff Rust algorithm for browsers, edge runtimes, and any wasm host. Same
|
|
11
|
+
WebAssembly build of the BlazeDiff Rust algorithm for browsers, edge runtimes, and any wasm host. Same block-band algorithm as [`@blazediff/core-native`](https://www.npmjs.com/package/@blazediff/core-native), compiled to `wasm32` with `v128` SIMD (`+simd128`). About **6.8x** faster than [pixelmatch](https://github.com/mapbox/pixelmatch) in total time on the same RGBA buffers (5x to 10x 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)
|
|
15
|
-
- `wasm32` v128 SIMD: 4-lane vectorized cold and hot loops; up to ~
|
|
16
|
-
-
|
|
15
|
+
- `wasm32` v128 SIMD: 4-lane vectorized cold and hot loops; up to ~11x faster than pixelmatch on 4K
|
|
16
|
+
- Same `Image`, `DiffOptions` and `DiffResult` as `@blazediff/core`. Caller decodes images; no PNG/JPEG codecs bundled
|
|
17
17
|
- ~32 KB optimized wasm + ~10 KB JS glue. No native binaries, no postinstall, no platform packages
|
|
18
18
|
- Runs anywhere wasm runs: browsers, Node 18+, Cloudflare Workers, Deno, Bun
|
|
19
19
|
|
|
@@ -45,12 +45,12 @@ import { initBlazediff } from '@blazediff/core-wasm';
|
|
|
45
45
|
|
|
46
46
|
await initBlazediff(
|
|
47
47
|
new URL(
|
|
48
|
-
'https://cdn.jsdelivr.net/npm/@blazediff/core-wasm@
|
|
48
|
+
'https://cdn.jsdelivr.net/npm/@blazediff/core-wasm@7.0.0/wasm/blazediff_bg.wasm',
|
|
49
49
|
),
|
|
50
50
|
);
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
Pin the version (`@
|
|
53
|
+
Pin the version (`@7.0.0`). It must match the installed package, because the JS glue and the `.wasm` change together. `unpkg.com/@blazediff/core-wasm@7.0.0/wasm/blazediff_bg.wasm` works identically.
|
|
54
54
|
|
|
55
55
|
### Bundlers (Vite, Webpack 5+, esbuild, Rollup with plugin)
|
|
56
56
|
|
|
@@ -101,9 +101,9 @@ Initializes the wasm module. Safe to call multiple times; subsequent calls retur
|
|
|
101
101
|
|
|
102
102
|
**Returns:** `Promise<void>`
|
|
103
103
|
|
|
104
|
-
### `diff(a, b,
|
|
104
|
+
### `diff(a, b, options?)`
|
|
105
105
|
|
|
106
|
-
Compares two RGBA
|
|
106
|
+
Compares two RGBA images. Takes and returns the same types as [`@blazediff/core`](https://www.npmjs.com/package/@blazediff/core)'s `diff`, which they are imported from.
|
|
107
107
|
|
|
108
108
|
<table>
|
|
109
109
|
<tr>
|
|
@@ -112,29 +112,9 @@ Compares two RGBA pixel buffers and returns the number of differing pixels.
|
|
|
112
112
|
<th width="500">Description</th>
|
|
113
113
|
</tr>
|
|
114
114
|
<tr>
|
|
115
|
-
<td><code>a</code></td>
|
|
116
|
-
<td>
|
|
117
|
-
<td>
|
|
118
|
-
</tr>
|
|
119
|
-
<tr>
|
|
120
|
-
<td><code>b</code></td>
|
|
121
|
-
<td>Uint8Array</td>
|
|
122
|
-
<td>Second image in RGBA8 order (same length)</td>
|
|
123
|
-
</tr>
|
|
124
|
-
<tr>
|
|
125
|
-
<td><code>width</code></td>
|
|
126
|
-
<td>number</td>
|
|
127
|
-
<td>Image width in pixels</td>
|
|
128
|
-
</tr>
|
|
129
|
-
<tr>
|
|
130
|
-
<td><code>height</code></td>
|
|
131
|
-
<td>number</td>
|
|
132
|
-
<td>Image height in pixels</td>
|
|
133
|
-
</tr>
|
|
134
|
-
<tr>
|
|
135
|
-
<td><code>output</code></td>
|
|
136
|
-
<td>Uint8Array | undefined</td>
|
|
137
|
-
<td>Optional diff visualization buffer (same length). Written in place</td>
|
|
115
|
+
<td><code>a</code>, <code>b</code></td>
|
|
116
|
+
<td>Image</td>
|
|
117
|
+
<td><code>{ data, width, height }</code> with RGBA8 pixels (<code>width * height * 4</code> bytes). Browser <code>ImageData</code> fits as is</td>
|
|
138
118
|
</tr>
|
|
139
119
|
<tr>
|
|
140
120
|
<td><code>options</code></td>
|
|
@@ -143,7 +123,7 @@ Compares two RGBA pixel buffers and returns the number of differing pixels.
|
|
|
143
123
|
</tr>
|
|
144
124
|
</table>
|
|
145
125
|
|
|
146
|
-
**Returns:** `Promise<
|
|
126
|
+
**Returns:** `Promise<DiffResult>`
|
|
147
127
|
|
|
148
128
|
<table>
|
|
149
129
|
<tr>
|
|
@@ -156,31 +136,65 @@ Compares two RGBA pixel buffers and returns the number of differing pixels.
|
|
|
156
136
|
<td><code>threshold</code></td>
|
|
157
137
|
<td>number</td>
|
|
158
138
|
<td>0.1</td>
|
|
159
|
-
<td>Color difference threshold (0
|
|
139
|
+
<td>Color difference threshold (0-1). Lower is stricter</td>
|
|
160
140
|
</tr>
|
|
161
141
|
<tr>
|
|
162
|
-
<td><code>
|
|
142
|
+
<td><code>antialiasing</code></td>
|
|
163
143
|
<td>boolean</td>
|
|
164
|
-
<td>
|
|
165
|
-
<td>
|
|
144
|
+
<td>true</td>
|
|
145
|
+
<td>Detect anti-aliased pixels and leave them out of the count</td>
|
|
166
146
|
</tr>
|
|
167
147
|
<tr>
|
|
168
|
-
<td><code>
|
|
169
|
-
<td>
|
|
170
|
-
<td>
|
|
171
|
-
<td>
|
|
148
|
+
<td><code>metric</code></td>
|
|
149
|
+
<td>"yiq" | "oklab"</td>
|
|
150
|
+
<td>"yiq"</td>
|
|
151
|
+
<td>Color difference metric. <code>oklab</code> gives the same counts as pixelmatch 8</td>
|
|
172
152
|
</tr>
|
|
173
153
|
<tr>
|
|
174
|
-
<td><code>
|
|
175
|
-
<td>
|
|
176
|
-
<td
|
|
177
|
-
<td>
|
|
154
|
+
<td><code>mask</code></td>
|
|
155
|
+
<td>Uint8Array</td>
|
|
156
|
+
<td>-</td>
|
|
157
|
+
<td>One byte per pixel (width × height). Non-zero pixels are skipped</td>
|
|
158
|
+
</tr>
|
|
159
|
+
<tr>
|
|
160
|
+
<td><code>window</code></td>
|
|
161
|
+
<td>number</td>
|
|
162
|
+
<td>-</td>
|
|
163
|
+
<td>Also report the N×N window with the most diff pixels</td>
|
|
164
|
+
</tr>
|
|
165
|
+
<tr>
|
|
166
|
+
<td><code>output</code></td>
|
|
167
|
+
<td>Image</td>
|
|
168
|
+
<td>-</td>
|
|
169
|
+
<td>Draw the diff into this image in place. Identical images leave it unwritten</td>
|
|
170
|
+
</tr>
|
|
171
|
+
<tr>
|
|
172
|
+
<td><code>render</code></td>
|
|
173
|
+
<td>{ alpha?, diffColor?, diffColorAlt?, aaColor?, background? }</td>
|
|
174
|
+
<td>-</td>
|
|
175
|
+
<td>Output styling. <code>background: "transparent"</code> draws the diff alone</td>
|
|
178
176
|
</tr>
|
|
179
177
|
</table>
|
|
180
178
|
|
|
181
179
|
```typescript
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
type DiffResult =
|
|
181
|
+
| {
|
|
182
|
+
kind: "compared";
|
|
183
|
+
count: number;
|
|
184
|
+
percentage: number;
|
|
185
|
+
identical: boolean;
|
|
186
|
+
/** Top-left corner and count of the busiest window, when `window` is set. */
|
|
187
|
+
window?: { x: number; y: number; count: number };
|
|
188
|
+
}
|
|
189
|
+
| { kind: "dimension-mismatch"; a: Size; b: Size };
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Invalid options or buffers reject with a `BlazeDiffError` that has a `code`: `invalid-image`, `invalid-output`, `invalid-mask` or `invalid-option`.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
const result = await diff(a, b, {
|
|
196
|
+
output: { data: out, width, height },
|
|
197
|
+
render: { diffColorAlt: [0, 128, 255] },
|
|
184
198
|
});
|
|
185
199
|
```
|
|
186
200
|
|
|
@@ -205,19 +219,16 @@ async function toRgba(url: string) {
|
|
|
205
219
|
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
|
|
206
220
|
const ctx = canvas.getContext('2d')!;
|
|
207
221
|
ctx.drawImage(bitmap, 0, 0);
|
|
208
|
-
|
|
209
|
-
return { data: new Uint8Array(data.buffer), width: bitmap.width, height: bitmap.height };
|
|
222
|
+
return ctx.getImageData(0, 0, bitmap.width, bitmap.height);
|
|
210
223
|
}
|
|
211
224
|
|
|
212
225
|
const a = await toRgba('/baseline.png');
|
|
213
226
|
const b = await toRgba('/current.png');
|
|
214
|
-
const
|
|
227
|
+
const output = new ImageData(a.width, a.height);
|
|
215
228
|
|
|
216
|
-
const
|
|
217
|
-
threshold: 0.1,
|
|
218
|
-
});
|
|
229
|
+
const result = await diff(a, b, { output, threshold: 0.1 });
|
|
219
230
|
|
|
220
|
-
console.log(`${
|
|
231
|
+
if (result.kind === 'compared') console.log(`${result.count} pixels differ`);
|
|
221
232
|
```
|
|
222
233
|
|
|
223
234
|
### Node
|
|
@@ -229,18 +240,13 @@ import { PNG } from 'pngjs';
|
|
|
229
240
|
|
|
230
241
|
await initBlazediff(
|
|
231
242
|
new URL(
|
|
232
|
-
'https://cdn.jsdelivr.net/npm/@blazediff/core-wasm@
|
|
243
|
+
'https://cdn.jsdelivr.net/npm/@blazediff/core-wasm@7.0.0/wasm/blazediff_bg.wasm',
|
|
233
244
|
),
|
|
234
245
|
);
|
|
235
246
|
|
|
236
247
|
const a = PNG.sync.read(readFileSync('baseline.png'));
|
|
237
248
|
const b = PNG.sync.read(readFileSync('current.png'));
|
|
238
|
-
const
|
|
239
|
-
new Uint8Array(a.data),
|
|
240
|
-
new Uint8Array(b.data),
|
|
241
|
-
a.width,
|
|
242
|
-
a.height,
|
|
243
|
-
);
|
|
249
|
+
const result = await diff(a, b);
|
|
244
250
|
```
|
|
245
251
|
|
|
246
252
|
## Performance
|
|
@@ -249,21 +255,21 @@ vs `pixelmatch` on M1 Max, image I/O excluded (pre-decoded RGBA buffers):
|
|
|
249
255
|
|
|
250
256
|
| Fixture | pixelmatch | core-wasm | Improvement |
|
|
251
257
|
|---------------|------------|-----------|-------------|
|
|
252
|
-
| 4k/1
|
|
253
|
-
| 4k/3
|
|
254
|
-
| page/2
|
|
255
|
-
| blazediff/3
|
|
256
|
-
| pixelmatch/1
|
|
258
|
+
| 4k/1 | 346.12ms | 34.73ms | **90.0%** |
|
|
259
|
+
| 4k/3 | 423.70ms | 44.48ms | **89.5%** |
|
|
260
|
+
| page/2 | 529.30ms | 65.49ms | **87.6%** |
|
|
261
|
+
| blazediff/3 | 10.86ms | 5.94ms | **45.3%** |
|
|
262
|
+
| pixelmatch/1 | 0.82ms | 0.10ms | **88.3%** |
|
|
257
263
|
|
|
258
|
-
|
|
264
|
+
About **6.8x** faster in total time across the full fixture set, ~77% per fixture on average (~72% across differing pairs). Counts agree with pixelmatch within ~0.05% (e.g. `4k/1`: 69 932 vs 69 912 of 17 920 000 pixels).
|
|
259
265
|
Full benchmarks in [BENCHMARKS.md](https://github.com/teimurjan/blazediff/blob/main/BENCHMARKS.md).
|
|
260
266
|
|
|
261
267
|
## Algorithm
|
|
262
268
|
|
|
263
|
-
Same
|
|
269
|
+
Same block-band approach as `@blazediff/core-native`, recompiled for wasm. The diff walks one row of blocks at a time. The block size grows with the image area, from 8 to 128 pixels.
|
|
264
270
|
|
|
265
|
-
1. **Cold pass:**
|
|
266
|
-
2. **Hot pass:**
|
|
271
|
+
1. **Cold pass:** a SIMD scan reads the band in pixel-row order and flags each block that holds a pixel over the threshold
|
|
272
|
+
2. **Hot pass:** YIQ perceptual color difference on the flagged blocks only, while the band is still in cache
|
|
267
273
|
3. **SIMD:** `v128` intrinsics (`f32x4_*`, `i32x4_*`) for parallel 4-lane RGBA extraction, alpha blend, YIQ transform, and threshold compare. Baseline simd128 has no native FMA, so weighted sums use `add(mul, c)`
|
|
268
274
|
4. **Anti-aliasing:** Vysniauskas (2009) algorithm to detect AA artifacts
|
|
269
275
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/** Count anti-aliased pixels as differences. Default: false */
|
|
5
|
-
includeAA?: boolean;
|
|
6
|
-
/** Render output with transparent background instead of grayscale base. Default: false */
|
|
7
|
-
diffMask?: boolean;
|
|
8
|
-
/** Alternative RGB color for darkening differences. Default: diff color */
|
|
9
|
-
diffColorAlt?: [number, number, number];
|
|
10
|
-
}
|
|
1
|
+
import { Image, DiffOptions, DiffResult } from '@blazediff/core';
|
|
2
|
+
export { BlazeDiffError, DiffOptions, DiffResult, Image } from '@blazediff/core';
|
|
3
|
+
|
|
11
4
|
type WasmInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
12
5
|
/**
|
|
13
6
|
* Initialize the wasm module. Safe to call multiple times - subsequent calls
|
|
@@ -17,15 +10,12 @@ type WasmInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Modul
|
|
|
17
10
|
*/
|
|
18
11
|
declare function initBlazediff(input?: WasmInput): Promise<void>;
|
|
19
12
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* Both buffers must be `width * height * 4` bytes in RGBA8 order. Decode
|
|
23
|
-
* PNG/JPEG with `createImageBitmap` + `OffscreenCanvas.getImageData()` (or
|
|
24
|
-
* the `ImageDecoder` API) and pass the resulting `Uint8Array` here.
|
|
13
|
+
* Compares two RGBA images with the same algorithm as `@blazediff/core-native`.
|
|
25
14
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
15
|
+
* Takes and returns the `@blazediff/core` types. Decode PNG or JPEG with
|
|
16
|
+
* `createImageBitmap` + `OffscreenCanvas.getImageData()` (or `ImageDecoder`)
|
|
17
|
+
* and pass the pixels here. With `output`, the diff is drawn into its buffer.
|
|
28
18
|
*/
|
|
29
|
-
declare function diff(a:
|
|
19
|
+
declare function diff(a: Image, b: Image, options?: DiffOptions): Promise<DiffResult>;
|
|
30
20
|
|
|
31
|
-
export { type
|
|
21
|
+
export { type WasmInput, diff, initBlazediff };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {assertImage,assertOptions,assertTargets,windowSide}from'@blazediff/core';export{BlazeDiffError}from'@blazediff/core';import C,{diffRgba}from'../wasm/blazediff.js';var s;function v(e){return s||(s=C(e===void 0?void 0:{module_or_path:e}).then(()=>{})),s}function u(e){return e&&Uint8Array.from(e)}async function z(e,t,i={}){if(assertImage(e,"a","invalid-image"),assertImage(t,"b","invalid-image"),e.width!==t.width||e.height!==t.height)return {kind:"dimension-mismatch",a:{width:e.width,height:e.height},b:{width:t.width,height:t.height}};let{threshold:g=.1,antialiasing:y=true,metric:l="yiq",mask:m,window:p,output:f,render:r={}}=i,{width:a,height:o}=e,c=a*o;assertOptions(i),assertTargets(i,a,o);let w=r.background??"faded";if(await v(),!f&&p===void 0&&O(e.data,t.data))return {kind:"compared",count:0,percentage:0,identical:true};let A=windowSide(p,a,o),[d,U,b,R,B]=diffRgba(n(e.data),n(t.data),a,o,g,y,l,m&&n(m),A||void 0,r.alpha??.1,u(r.diffColor),u(r.diffColorAlt),u(r.aaColor),w==="transparent",f&&n(f.data));return {kind:"compared",count:d,percentage:c>0?100*d/c:0,identical:d===0,...U===1&&{window:{x:b,y:R,count:B}}}}function O(e,t){let i=globalThis.Buffer;return i!==void 0&&i.compare(n(e),n(t))===0}function n(e){return e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}export{z as diff,v as initBlazediff};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blazediff/core-wasm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.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": {
|
|
@@ -37,6 +37,9 @@
|
|
|
37
37
|
"repository": "https://github.com/teimurjan/blazediff",
|
|
38
38
|
"homepage": "https://blazediff.dev",
|
|
39
39
|
"license": "MIT",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@blazediff/core": "2.0.1"
|
|
42
|
+
},
|
|
40
43
|
"devDependencies": {
|
|
41
44
|
"@types/node": "^24.3.0",
|
|
42
45
|
"@types/pngjs": "^6.0.5",
|
|
@@ -44,7 +47,7 @@
|
|
|
44
47
|
"tsup": "8.5.0",
|
|
45
48
|
"typescript": "5.9.2",
|
|
46
49
|
"vitest": "^3.2.4",
|
|
47
|
-
"@blazediff/core-native": "
|
|
50
|
+
"@blazediff/core-native": "8.0.0"
|
|
48
51
|
},
|
|
49
52
|
"scripts": {
|
|
50
53
|
"typecheck": "tsc --noEmit",
|
package/wasm/blazediff.d.ts
CHANGED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export function _start(): void;
|
|
4
4
|
/**
|
|
5
|
-
* Diff two RGBA buffers.
|
|
5
|
+
* Diff two equally sized RGBA buffers.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Returns `[count, has_window, window_x, window_y, window_count]`. If
|
|
8
|
+
* `out_diff` is provided, the visualization is written into it in place
|
|
9
|
+
* (must be width*height*4 bytes).
|
|
10
10
|
*/
|
|
11
|
-
export function diffRgba(rgba_a: Uint8Array, rgba_b: Uint8Array, width: number, height: number, threshold: number,
|
|
11
|
+
export function diffRgba(rgba_a: Uint8Array, rgba_b: Uint8Array, width: number, height: number, threshold: number, antialiasing: boolean, metric: string | null | undefined, mask: Uint8Array | null | undefined, window: number | null | undefined, alpha: number, diff_color: Uint8Array | null | undefined, diff_color_alt: Uint8Array | null | undefined, aa_color: Uint8Array | null | undefined, transparent: boolean, out_diff?: Uint8Array | null): Uint32Array;
|
|
12
12
|
|
|
13
13
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
14
14
|
|
|
15
15
|
export interface InitOutput {
|
|
16
16
|
readonly memory: WebAssembly.Memory;
|
|
17
17
|
readonly _start: () => void;
|
|
18
|
-
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;
|
|
18
|
+
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, n: number, o: number, p: number, q: number, r: number, s: number, t: number, u: number, v: number, w: number) => void;
|
|
19
19
|
readonly __wbindgen_export_0: (a: number, b: number, c: number) => void;
|
|
20
20
|
readonly __wbindgen_export_1: (a: number, b: number) => number;
|
|
21
21
|
readonly __wbindgen_export_2: (a: number, b: number, c: number, d: number) => number;
|
package/wasm/blazediff.js
CHANGED
|
@@ -126,40 +126,71 @@ function passArray8ToWasm0(arg, malloc) {
|
|
|
126
126
|
function isLikeNone(x) {
|
|
127
127
|
return x === undefined || x === null;
|
|
128
128
|
}
|
|
129
|
+
|
|
130
|
+
let cachedUint32ArrayMemory0 = null;
|
|
131
|
+
|
|
132
|
+
function getUint32ArrayMemory0() {
|
|
133
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
134
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
135
|
+
}
|
|
136
|
+
return cachedUint32ArrayMemory0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function getArrayU32FromWasm0(ptr, len) {
|
|
140
|
+
ptr = ptr >>> 0;
|
|
141
|
+
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
142
|
+
}
|
|
129
143
|
/**
|
|
130
|
-
* Diff two RGBA buffers.
|
|
144
|
+
* Diff two equally sized RGBA buffers.
|
|
131
145
|
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
146
|
+
* Returns `[count, has_window, window_x, window_y, window_count]`. If
|
|
147
|
+
* `out_diff` is provided, the visualization is written into it in place
|
|
148
|
+
* (must be width*height*4 bytes).
|
|
135
149
|
* @param {Uint8Array} rgba_a
|
|
136
150
|
* @param {Uint8Array} rgba_b
|
|
137
151
|
* @param {number} width
|
|
138
152
|
* @param {number} height
|
|
139
153
|
* @param {number} threshold
|
|
140
|
-
* @param {boolean}
|
|
141
|
-
* @param {
|
|
142
|
-
* @param {Uint8Array | null}
|
|
154
|
+
* @param {boolean} antialiasing
|
|
155
|
+
* @param {string | null | undefined} metric
|
|
156
|
+
* @param {Uint8Array | null | undefined} mask
|
|
157
|
+
* @param {number | null | undefined} window
|
|
158
|
+
* @param {number} alpha
|
|
159
|
+
* @param {Uint8Array | null | undefined} diff_color
|
|
160
|
+
* @param {Uint8Array | null | undefined} diff_color_alt
|
|
161
|
+
* @param {Uint8Array | null | undefined} aa_color
|
|
162
|
+
* @param {boolean} transparent
|
|
143
163
|
* @param {Uint8Array | null} [out_diff]
|
|
144
|
-
* @returns {
|
|
164
|
+
* @returns {Uint32Array}
|
|
145
165
|
*/
|
|
146
|
-
export function diffRgba(rgba_a, rgba_b, width, height, threshold,
|
|
166
|
+
export function diffRgba(rgba_a, rgba_b, width, height, threshold, antialiasing, metric, mask, window, alpha, diff_color, diff_color_alt, aa_color, transparent, out_diff) {
|
|
147
167
|
try {
|
|
148
168
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
149
169
|
const ptr0 = passArray8ToWasm0(rgba_a, wasm.__wbindgen_export_1);
|
|
150
170
|
const len0 = WASM_VECTOR_LEN;
|
|
151
171
|
const ptr1 = passArray8ToWasm0(rgba_b, wasm.__wbindgen_export_1);
|
|
152
172
|
const len1 = WASM_VECTOR_LEN;
|
|
153
|
-
var ptr2 = isLikeNone(
|
|
173
|
+
var ptr2 = isLikeNone(metric) ? 0 : passStringToWasm0(metric, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
154
174
|
var len2 = WASM_VECTOR_LEN;
|
|
155
|
-
|
|
175
|
+
var ptr3 = isLikeNone(mask) ? 0 : passArray8ToWasm0(mask, wasm.__wbindgen_export_1);
|
|
176
|
+
var len3 = WASM_VECTOR_LEN;
|
|
177
|
+
var ptr4 = isLikeNone(diff_color) ? 0 : passArray8ToWasm0(diff_color, wasm.__wbindgen_export_1);
|
|
178
|
+
var len4 = WASM_VECTOR_LEN;
|
|
179
|
+
var ptr5 = isLikeNone(diff_color_alt) ? 0 : passArray8ToWasm0(diff_color_alt, wasm.__wbindgen_export_1);
|
|
180
|
+
var len5 = WASM_VECTOR_LEN;
|
|
181
|
+
var ptr6 = isLikeNone(aa_color) ? 0 : passArray8ToWasm0(aa_color, wasm.__wbindgen_export_1);
|
|
182
|
+
var len6 = WASM_VECTOR_LEN;
|
|
183
|
+
wasm.diffRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, antialiasing, ptr2, len2, ptr3, len3, isLikeNone(window) ? 0x100000001 : (window) >>> 0, alpha, ptr4, len4, ptr5, len5, ptr6, len6, transparent, isLikeNone(out_diff) ? 0 : addHeapObject(out_diff));
|
|
156
184
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
157
185
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
158
186
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
159
|
-
|
|
160
|
-
|
|
187
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
188
|
+
if (r3) {
|
|
189
|
+
throw takeObject(r2);
|
|
161
190
|
}
|
|
162
|
-
|
|
191
|
+
var v8 = getArrayU32FromWasm0(r0, r1).slice();
|
|
192
|
+
wasm.__wbindgen_export_0(r0, r1 * 4, 4);
|
|
193
|
+
return v8;
|
|
163
194
|
} finally {
|
|
164
195
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
165
196
|
}
|
|
@@ -262,6 +293,7 @@ function __wbg_finalize_init(instance, module) {
|
|
|
262
293
|
wasm = instance.exports;
|
|
263
294
|
__wbg_init.__wbindgen_wasm_module = module;
|
|
264
295
|
cachedDataViewMemory0 = null;
|
|
296
|
+
cachedUint32ArrayMemory0 = null;
|
|
265
297
|
cachedUint8ArrayMemory0 = null;
|
|
266
298
|
|
|
267
299
|
|
package/wasm/blazediff_bg.wasm
CHANGED
|
Binary file
|
|
@@ -2,7 +2,7 @@
|
|
|
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, l: number, m: 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, n: number, o: number, p: number, q: number, r: number, s: number, t: number, u: number, v: number, w: number) => void;
|
|
6
6
|
export const __wbindgen_export_0: (a: number, b: number, c: number) => void;
|
|
7
7
|
export const __wbindgen_export_1: (a: number, b: number) => number;
|
|
8
8
|
export const __wbindgen_export_2: (a: number, b: number, c: number, d: number) => number;
|