@blazediff/core-wasm 4.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/LICENSE.md +21 -0
- package/README.md +264 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +1 -0
- package/package.json +57 -0
- package/wasm/blazediff.d.ts +45 -0
- package/wasm/blazediff.js +323 -0
- package/wasm/blazediff_bg.wasm +0 -0
- package/wasm/blazediff_bg.wasm.d.ts +10 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Teimur Gasanov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# @blazediff/core-wasm
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@blazediff/core-wasm)
|
|
6
|
+
[](https://www.npmjs.com/package/@blazediff/core-wasm)
|
|
7
|
+
[](https://crates.io/crates/blazediff)
|
|
8
|
+
|
|
9
|
+
</div>
|
|
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`). **~58%** faster than [pixelmatch](https://github.com/mapbox/pixelmatch) on the same RGBA buffers; diff counts agree with pixelmatch to within ~0.05%.
|
|
12
|
+
|
|
13
|
+
**Features:**
|
|
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 ~16x faster than pixelmatch on 4K
|
|
16
|
+
- Buffers-only API: caller decodes images, hands in `Uint8Array`. No PNG/JPEG codecs bundled
|
|
17
|
+
- ~32 KB optimized wasm + ~10 KB JS glue. No native binaries, no postinstall, no platform packages
|
|
18
|
+
- Runs anywhere wasm runs: browsers, Node 18+, Cloudflare Workers, Deno, Bun
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @blazediff/core-wasm
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Loading the wasm module
|
|
27
|
+
|
|
28
|
+
Pick the recipe that matches your runtime. All four are equivalent; the wasm itself is the same.
|
|
29
|
+
|
|
30
|
+
### Browser (default fetch)
|
|
31
|
+
|
|
32
|
+
The wasm-bindgen `--target web` glue fetches the sibling `.wasm` via `import.meta.url` automatically:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { initBlazediff } from '@blazediff/core-wasm';
|
|
36
|
+
await initBlazediff();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Universal CDN URL (recommended for Node, Workers, Deno, Bun)
|
|
40
|
+
|
|
41
|
+
jsDelivr serves the published `.wasm` over HTTPS, so any `fetch()`-capable runtime can load it. One network round-trip on cold start, cached by the runtime after that:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { initBlazediff } from '@blazediff/core-wasm';
|
|
45
|
+
|
|
46
|
+
await initBlazediff(
|
|
47
|
+
new URL(
|
|
48
|
+
'https://cdn.jsdelivr.net/npm/@blazediff/core-wasm@4.2.0/wasm/blazediff_bg.wasm',
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Pin the version (`@4.2.0`) for reproducibility. `unpkg.com/@blazediff/core-wasm@4.2.0/wasm/blazediff_bg.wasm` works identically.
|
|
54
|
+
|
|
55
|
+
### Bundlers (Vite, Webpack 5+, esbuild, Rollup with plugin)
|
|
56
|
+
|
|
57
|
+
The `new URL(asset, import.meta.url)` pattern is bundler-aware: the asset is emitted into the build output and the URL is rewritten at build time:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { initBlazediff } from '@blazediff/core-wasm';
|
|
61
|
+
|
|
62
|
+
const wasmUrl = new URL(
|
|
63
|
+
'@blazediff/core-wasm/wasm/blazediff_bg.wasm',
|
|
64
|
+
import.meta.url,
|
|
65
|
+
);
|
|
66
|
+
await initBlazediff(wasmUrl);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Node from the local filesystem
|
|
70
|
+
|
|
71
|
+
Offline, no CDN dependency. Read the bytes and pass them in:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
// ESM (Node 20.6+):
|
|
75
|
+
import { readFileSync } from 'node:fs';
|
|
76
|
+
import { fileURLToPath } from 'node:url';
|
|
77
|
+
import { initBlazediff } from '@blazediff/core-wasm';
|
|
78
|
+
|
|
79
|
+
const wasmPath = fileURLToPath(
|
|
80
|
+
import.meta.resolve('@blazediff/core-wasm/wasm/blazediff_bg.wasm'),
|
|
81
|
+
);
|
|
82
|
+
await initBlazediff(readFileSync(wasmPath));
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
// CommonJS:
|
|
87
|
+
const { readFileSync } = require('node:fs');
|
|
88
|
+
const { initBlazediff } = require('@blazediff/core-wasm');
|
|
89
|
+
|
|
90
|
+
const wasmPath = require.resolve(
|
|
91
|
+
'@blazediff/core-wasm/wasm/blazediff_bg.wasm',
|
|
92
|
+
);
|
|
93
|
+
await initBlazediff(readFileSync(wasmPath));
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## API
|
|
97
|
+
|
|
98
|
+
### `initBlazediff(input?)`
|
|
99
|
+
|
|
100
|
+
Initializes the wasm module. Safe to call multiple times; subsequent calls return the cached promise. Accepts a `URL`, `Response`, `ArrayBuffer`, `Uint8Array`, or compiled `WebAssembly.Module`. Without `input`, the default `--target web` glue fetches the sibling `blazediff_bg.wasm` via `import.meta.url` (works in browsers; other runtimes need an explicit input, see above).
|
|
101
|
+
|
|
102
|
+
**Returns:** `Promise<void>`
|
|
103
|
+
|
|
104
|
+
### `diff(a, b, width, height, output?, options?)`
|
|
105
|
+
|
|
106
|
+
Compares two RGBA pixel buffers and returns the number of differing pixels.
|
|
107
|
+
|
|
108
|
+
<table>
|
|
109
|
+
<tr>
|
|
110
|
+
<th width="500">Parameter</th>
|
|
111
|
+
<th width="500">Type</th>
|
|
112
|
+
<th width="500">Description</th>
|
|
113
|
+
</tr>
|
|
114
|
+
<tr>
|
|
115
|
+
<td><code>a</code></td>
|
|
116
|
+
<td>Uint8Array</td>
|
|
117
|
+
<td>First image in RGBA8 order (<code>width * height * 4</code> bytes)</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>
|
|
138
|
+
</tr>
|
|
139
|
+
<tr>
|
|
140
|
+
<td><code>options</code></td>
|
|
141
|
+
<td>DiffOptions</td>
|
|
142
|
+
<td>Comparison options (optional)</td>
|
|
143
|
+
</tr>
|
|
144
|
+
</table>
|
|
145
|
+
|
|
146
|
+
**Returns:** `Promise<number>` (count of differing pixels)
|
|
147
|
+
|
|
148
|
+
<table>
|
|
149
|
+
<tr>
|
|
150
|
+
<th width="500">Option</th>
|
|
151
|
+
<th width="500">Type</th>
|
|
152
|
+
<th width="500">Default</th>
|
|
153
|
+
<th width="500">Description</th>
|
|
154
|
+
</tr>
|
|
155
|
+
<tr>
|
|
156
|
+
<td><code>threshold</code></td>
|
|
157
|
+
<td>number</td>
|
|
158
|
+
<td>0.1</td>
|
|
159
|
+
<td>Color difference threshold (0.0-1.0). Lower = more strict</td>
|
|
160
|
+
</tr>
|
|
161
|
+
<tr>
|
|
162
|
+
<td><code>includeAA</code></td>
|
|
163
|
+
<td>boolean</td>
|
|
164
|
+
<td>false</td>
|
|
165
|
+
<td>Count anti-aliased pixels as differences</td>
|
|
166
|
+
</tr>
|
|
167
|
+
<tr>
|
|
168
|
+
<td><code>diffMask</code></td>
|
|
169
|
+
<td>boolean</td>
|
|
170
|
+
<td>false</td>
|
|
171
|
+
<td>Render diff with transparent background instead of grayscale base</td>
|
|
172
|
+
</tr>
|
|
173
|
+
</table>
|
|
174
|
+
|
|
175
|
+
## Usage
|
|
176
|
+
|
|
177
|
+
### Browser
|
|
178
|
+
|
|
179
|
+
Decode images via `createImageBitmap` + `OffscreenCanvas` (or the `ImageDecoder` API), then pass the RGBA buffer to `diff()`:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { diff, initBlazediff } from '@blazediff/core-wasm';
|
|
183
|
+
|
|
184
|
+
await initBlazediff();
|
|
185
|
+
|
|
186
|
+
async function toRgba(url: string) {
|
|
187
|
+
const bitmap = await createImageBitmap(await (await fetch(url)).blob());
|
|
188
|
+
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
|
|
189
|
+
const ctx = canvas.getContext('2d')!;
|
|
190
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
191
|
+
const { data } = ctx.getImageData(0, 0, bitmap.width, bitmap.height);
|
|
192
|
+
return { data: new Uint8Array(data.buffer), width: bitmap.width, height: bitmap.height };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const a = await toRgba('/baseline.png');
|
|
196
|
+
const b = await toRgba('/current.png');
|
|
197
|
+
const out = new Uint8Array(a.width * a.height * 4);
|
|
198
|
+
|
|
199
|
+
const diffCount = await diff(a.data, b.data, a.width, a.height, out, {
|
|
200
|
+
threshold: 0.1,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
console.log(`${diffCount} pixels differ`);
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Node
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { readFileSync } from 'node:fs';
|
|
210
|
+
import { diff, initBlazediff } from '@blazediff/core-wasm';
|
|
211
|
+
import { PNG } from 'pngjs';
|
|
212
|
+
|
|
213
|
+
await initBlazediff(
|
|
214
|
+
new URL(
|
|
215
|
+
'https://cdn.jsdelivr.net/npm/@blazediff/core-wasm@4.2.0/wasm/blazediff_bg.wasm',
|
|
216
|
+
),
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
const a = PNG.sync.read(readFileSync('baseline.png'));
|
|
220
|
+
const b = PNG.sync.read(readFileSync('current.png'));
|
|
221
|
+
const diffCount = await diff(
|
|
222
|
+
new Uint8Array(a.data),
|
|
223
|
+
new Uint8Array(b.data),
|
|
224
|
+
a.width,
|
|
225
|
+
a.height,
|
|
226
|
+
);
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Performance
|
|
230
|
+
|
|
231
|
+
vs `pixelmatch` on M1 Max, image I/O excluded (pre-decoded RGBA buffers):
|
|
232
|
+
|
|
233
|
+
| Fixture | pixelmatch | core-wasm | Improvement |
|
|
234
|
+
|---------------|------------|-----------|-------------|
|
|
235
|
+
| 4k/1 | 287.72ms | 51.75ms | **82.0%** |
|
|
236
|
+
| 4k/3 | 366.81ms | 69.90ms | **80.9%** |
|
|
237
|
+
| page/2 | 443.83ms | 109.74ms | **75.3%** |
|
|
238
|
+
| blazediff/3 | 14.60ms | 5.52ms | **62.2%** |
|
|
239
|
+
| pixelmatch/1 | 0.87ms | 0.13ms | **84.6%** |
|
|
240
|
+
|
|
241
|
+
Average **~58%** faster across the full fixture set. Counts agree with pixelmatch within ~0.05% (e.g. `4k/1`: 69 932 vs 69 912 of 17 920 000 pixels). Full benchmarks in [BENCHMARKS.md](https://github.com/teimurjan/blazediff/blob/main/BENCHMARKS.md).
|
|
242
|
+
|
|
243
|
+
## Algorithm
|
|
244
|
+
|
|
245
|
+
Same two-pass block-based approach as `@blazediff/core-native`, recompiled for wasm:
|
|
246
|
+
|
|
247
|
+
1. **Cold pass:** scans the image in 8x8 blocks using 32-bit integer comparison to identify changed regions
|
|
248
|
+
2. **Hot pass:** only processes blocks marked as changed, applying YIQ perceptual color difference
|
|
249
|
+
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)`
|
|
250
|
+
4. **Anti-aliasing:** Vysniauskas (2009) algorithm to detect AA artifacts
|
|
251
|
+
|
|
252
|
+
## Picking the right package
|
|
253
|
+
|
|
254
|
+
| Use case | Package |
|
|
255
|
+
|-----------------------------------|-------------------------------------------------------------------------------|
|
|
256
|
+
| Browser, edge worker, wasm host | **`@blazediff/core-wasm`** |
|
|
257
|
+
| Node CLI / server with native bin | [`@blazediff/core-native`](https://www.npmjs.com/package/@blazediff/core-native) |
|
|
258
|
+
| Pure JS / no wasm support | [`@blazediff/core`](https://www.npmjs.com/package/@blazediff/core) |
|
|
259
|
+
|
|
260
|
+
## References
|
|
261
|
+
|
|
262
|
+
- **YIQ Color Space:** [Kotsarenko & Ramos (2009)](https://doaj.org/article/b2e3b5088ba943eebd9af2927fef08ad)
|
|
263
|
+
- **Anti-Aliasing Detection:** [Vysniauskas (2009)](https://www.researchgate.net/publication/234073157_Anti-aliased_Pixel_and_Intensity_Slope_Detector)
|
|
264
|
+
- **WebAssembly SIMD:** [WebAssembly/simd](https://github.com/WebAssembly/simd) (v128 / simd128 specification)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
interface DiffOptions {
|
|
2
|
+
/** Color difference threshold (0-1). Lower = stricter. Default: 0.1 */
|
|
3
|
+
threshold?: number;
|
|
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
|
+
}
|
|
9
|
+
type WasmInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
10
|
+
/**
|
|
11
|
+
* Initialize the wasm module. Safe to call multiple times — subsequent calls
|
|
12
|
+
* return the same promise. By default fetches the bundled `blazediff_bg.wasm`
|
|
13
|
+
* via the module's import path. Pass a custom `URL`, `Response`, or bytes to
|
|
14
|
+
* load the wasm from a different location (CDN, custom asset pipeline, etc.).
|
|
15
|
+
*/
|
|
16
|
+
declare function initBlazediff(input?: WasmInput): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Compare two RGBA pixel buffers and return the number of differing pixels.
|
|
19
|
+
*
|
|
20
|
+
* Both buffers must be `width * height * 4` bytes in RGBA8 order. Decode
|
|
21
|
+
* PNG/JPEG with `createImageBitmap` + `OffscreenCanvas.getImageData()` (or
|
|
22
|
+
* the `ImageDecoder` API) and pass the resulting `Uint8Array` here.
|
|
23
|
+
*
|
|
24
|
+
* If `output` is provided it must be `width * height * 4` bytes long and the
|
|
25
|
+
* diff visualization is written into it in place.
|
|
26
|
+
*/
|
|
27
|
+
declare function diff(a: Uint8Array, b: Uint8Array, width: number, height: number, output?: Uint8Array, options?: DiffOptions): Promise<number>;
|
|
28
|
+
|
|
29
|
+
export { type DiffOptions, type WasmInput, diff, initBlazediff };
|
package/dist/index.js
ADDED
|
@@ -0,0 +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};
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blazediff/core-wasm",
|
|
3
|
+
"version": "4.3.0",
|
|
4
|
+
"description": "WebAssembly build of blazediff for browsers, edge runtimes, and any wasm host. Same algorithm as @blazediff/core-native.",
|
|
5
|
+
"private": false,
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"module": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./wasm/blazediff_bg.wasm": "./wasm/blazediff_bg.wasm"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"wasm"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"image",
|
|
25
|
+
"comparison",
|
|
26
|
+
"diff",
|
|
27
|
+
"pixel",
|
|
28
|
+
"visual-testing",
|
|
29
|
+
"visual-regression",
|
|
30
|
+
"screenshot",
|
|
31
|
+
"wasm",
|
|
32
|
+
"webassembly",
|
|
33
|
+
"browser",
|
|
34
|
+
"simd"
|
|
35
|
+
],
|
|
36
|
+
"author": "Teimur Gasanov <me@teimurjan.dev> (https://github.com/teimurjan)",
|
|
37
|
+
"repository": "https://github.com/teimurjan/blazediff",
|
|
38
|
+
"homepage": "https://blazediff.dev",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^24.3.0",
|
|
42
|
+
"@types/pngjs": "^6.0.5",
|
|
43
|
+
"pngjs": "^7.0.0",
|
|
44
|
+
"tsup": "8.5.0",
|
|
45
|
+
"typescript": "5.9.2",
|
|
46
|
+
"vitest": "^3.2.4",
|
|
47
|
+
"@blazediff/core-native": "4.3.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"build": "tsup",
|
|
52
|
+
"build:wasm": "cd ../../crates/blazediff && ./scripts/build-wasm.sh",
|
|
53
|
+
"clean": "rm -rf dist",
|
|
54
|
+
"test": "vitest run",
|
|
55
|
+
"test:watch": "vitest"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
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, out_diff?: Uint8Array | null): number;
|
|
11
|
+
export function _start(): void;
|
|
12
|
+
|
|
13
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
14
|
+
|
|
15
|
+
export interface InitOutput {
|
|
16
|
+
readonly memory: WebAssembly.Memory;
|
|
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) => 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;
|
|
22
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
23
|
+
readonly __wbindgen_start: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
27
|
+
/**
|
|
28
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
29
|
+
* a precompiled `WebAssembly.Module`.
|
|
30
|
+
*
|
|
31
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
32
|
+
*
|
|
33
|
+
* @returns {InitOutput}
|
|
34
|
+
*/
|
|
35
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
39
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
40
|
+
*
|
|
41
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
42
|
+
*
|
|
43
|
+
* @returns {Promise<InitOutput>}
|
|
44
|
+
*/
|
|
45
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
const heap = new Array(128).fill(undefined);
|
|
4
|
+
|
|
5
|
+
heap.push(undefined, null, true, false);
|
|
6
|
+
|
|
7
|
+
function getObject(idx) { return heap[idx]; }
|
|
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(); };
|
|
23
|
+
|
|
24
|
+
let cachedUint8ArrayMemory0 = null;
|
|
25
|
+
|
|
26
|
+
function getUint8ArrayMemory0() {
|
|
27
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
28
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
29
|
+
}
|
|
30
|
+
return cachedUint8ArrayMemory0;
|
|
31
|
+
}
|
|
32
|
+
|
|
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
|
+
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
41
|
+
|
|
42
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
43
|
+
? function (arg, view) {
|
|
44
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
45
|
+
}
|
|
46
|
+
: function (arg, view) {
|
|
47
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
48
|
+
view.set(buf);
|
|
49
|
+
return {
|
|
50
|
+
read: arg.length,
|
|
51
|
+
written: buf.length
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
56
|
+
|
|
57
|
+
if (realloc === undefined) {
|
|
58
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
59
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
60
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
61
|
+
WASM_VECTOR_LEN = buf.length;
|
|
62
|
+
return ptr;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let len = arg.length;
|
|
66
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
67
|
+
|
|
68
|
+
const mem = getUint8ArrayMemory0();
|
|
69
|
+
|
|
70
|
+
let offset = 0;
|
|
71
|
+
|
|
72
|
+
for (; offset < len; offset++) {
|
|
73
|
+
const code = arg.charCodeAt(offset);
|
|
74
|
+
if (code > 0x7F) break;
|
|
75
|
+
mem[ptr + offset] = code;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (offset !== len) {
|
|
79
|
+
if (offset !== 0) {
|
|
80
|
+
arg = arg.slice(offset);
|
|
81
|
+
}
|
|
82
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
83
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
84
|
+
const ret = encodeString(arg, view);
|
|
85
|
+
|
|
86
|
+
offset += ret.written;
|
|
87
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
WASM_VECTOR_LEN = offset;
|
|
91
|
+
return ptr;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let cachedDataViewMemory0 = null;
|
|
95
|
+
|
|
96
|
+
function getDataViewMemory0() {
|
|
97
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
98
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
99
|
+
}
|
|
100
|
+
return cachedDataViewMemory0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function dropObject(idx) {
|
|
104
|
+
if (idx < 132) return;
|
|
105
|
+
heap[idx] = heap_next;
|
|
106
|
+
heap_next = idx;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function takeObject(idx) {
|
|
110
|
+
const ret = getObject(idx);
|
|
111
|
+
dropObject(idx);
|
|
112
|
+
return ret;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
116
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
117
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
118
|
+
WASM_VECTOR_LEN = arg.length;
|
|
119
|
+
return ptr;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function isLikeNone(x) {
|
|
123
|
+
return x === undefined || x === null;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Diff two RGBA buffers. Returns the count of differing pixels.
|
|
127
|
+
*
|
|
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.
|
|
131
|
+
* @param {Uint8Array} rgba_a
|
|
132
|
+
* @param {Uint8Array} rgba_b
|
|
133
|
+
* @param {number} width
|
|
134
|
+
* @param {number} height
|
|
135
|
+
* @param {number} threshold
|
|
136
|
+
* @param {boolean} include_aa
|
|
137
|
+
* @param {boolean} diff_mask
|
|
138
|
+
* @param {Uint8Array | null} [out_diff]
|
|
139
|
+
* @returns {number}
|
|
140
|
+
*/
|
|
141
|
+
export function diffRgba(rgba_a, rgba_b, width, height, threshold, include_aa, diff_mask, out_diff) {
|
|
142
|
+
try {
|
|
143
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
144
|
+
const ptr0 = passArray8ToWasm0(rgba_a, wasm.__wbindgen_export_1);
|
|
145
|
+
const len0 = WASM_VECTOR_LEN;
|
|
146
|
+
const ptr1 = passArray8ToWasm0(rgba_b, wasm.__wbindgen_export_1);
|
|
147
|
+
const len1 = WASM_VECTOR_LEN;
|
|
148
|
+
wasm.diffRgba(retptr, ptr0, len0, ptr1, len1, width, height, threshold, include_aa, diff_mask, isLikeNone(out_diff) ? 0 : addHeapObject(out_diff));
|
|
149
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
150
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
151
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
152
|
+
if (r2) {
|
|
153
|
+
throw takeObject(r1);
|
|
154
|
+
}
|
|
155
|
+
return r0 >>> 0;
|
|
156
|
+
} finally {
|
|
157
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function _start() {
|
|
162
|
+
wasm._start();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function __wbg_load(module, imports) {
|
|
166
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
167
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
168
|
+
try {
|
|
169
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
170
|
+
|
|
171
|
+
} catch (e) {
|
|
172
|
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
173
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
174
|
+
|
|
175
|
+
} else {
|
|
176
|
+
throw e;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const bytes = await module.arrayBuffer();
|
|
182
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
183
|
+
|
|
184
|
+
} else {
|
|
185
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
186
|
+
|
|
187
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
188
|
+
return { instance, module };
|
|
189
|
+
|
|
190
|
+
} else {
|
|
191
|
+
return instance;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function __wbg_get_imports() {
|
|
197
|
+
const imports = {};
|
|
198
|
+
imports.wbg = {};
|
|
199
|
+
imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
|
|
200
|
+
const ret = getObject(arg0).buffer;
|
|
201
|
+
return addHeapObject(ret);
|
|
202
|
+
};
|
|
203
|
+
imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
|
204
|
+
let deferred0_0;
|
|
205
|
+
let deferred0_1;
|
|
206
|
+
try {
|
|
207
|
+
deferred0_0 = arg0;
|
|
208
|
+
deferred0_1 = arg1;
|
|
209
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
210
|
+
} finally {
|
|
211
|
+
wasm.__wbindgen_export_0(deferred0_0, deferred0_1, 1);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
imports.wbg.__wbg_length_a446193dc22c12f8 = function(arg0) {
|
|
215
|
+
const ret = getObject(arg0).length;
|
|
216
|
+
return ret;
|
|
217
|
+
};
|
|
218
|
+
imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
|
|
219
|
+
const ret = new Error();
|
|
220
|
+
return addHeapObject(ret);
|
|
221
|
+
};
|
|
222
|
+
imports.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
|
|
223
|
+
const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
|
|
224
|
+
return addHeapObject(ret);
|
|
225
|
+
};
|
|
226
|
+
imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
|
|
227
|
+
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
|
|
228
|
+
};
|
|
229
|
+
imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
|
230
|
+
const ret = getObject(arg1).stack;
|
|
231
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
232
|
+
const len1 = WASM_VECTOR_LEN;
|
|
233
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
234
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
235
|
+
};
|
|
236
|
+
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
|
237
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
238
|
+
return addHeapObject(ret);
|
|
239
|
+
};
|
|
240
|
+
imports.wbg.__wbindgen_memory = function() {
|
|
241
|
+
const ret = wasm.memory;
|
|
242
|
+
return addHeapObject(ret);
|
|
243
|
+
};
|
|
244
|
+
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
245
|
+
takeObject(arg0);
|
|
246
|
+
};
|
|
247
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
248
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
return imports;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function __wbg_init_memory(imports, memory) {
|
|
255
|
+
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function __wbg_finalize_init(instance, module) {
|
|
259
|
+
wasm = instance.exports;
|
|
260
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
261
|
+
cachedDataViewMemory0 = null;
|
|
262
|
+
cachedUint8ArrayMemory0 = null;
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
wasm.__wbindgen_start();
|
|
266
|
+
return wasm;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function initSync(module) {
|
|
270
|
+
if (wasm !== undefined) return wasm;
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
if (typeof module !== 'undefined') {
|
|
274
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
275
|
+
({module} = module)
|
|
276
|
+
} else {
|
|
277
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const imports = __wbg_get_imports();
|
|
282
|
+
|
|
283
|
+
__wbg_init_memory(imports);
|
|
284
|
+
|
|
285
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
286
|
+
module = new WebAssembly.Module(module);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
290
|
+
|
|
291
|
+
return __wbg_finalize_init(instance, module);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function __wbg_init(module_or_path) {
|
|
295
|
+
if (wasm !== undefined) return wasm;
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
if (typeof module_or_path !== 'undefined') {
|
|
299
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
300
|
+
({module_or_path} = module_or_path)
|
|
301
|
+
} else {
|
|
302
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (typeof module_or_path === 'undefined') {
|
|
307
|
+
module_or_path = new URL('blazediff_bg.wasm', import.meta.url);
|
|
308
|
+
}
|
|
309
|
+
const imports = __wbg_get_imports();
|
|
310
|
+
|
|
311
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
312
|
+
module_or_path = fetch(module_or_path);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
__wbg_init_memory(imports);
|
|
316
|
+
|
|
317
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
318
|
+
|
|
319
|
+
return __wbg_finalize_init(instance, module);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export { initSync };
|
|
323
|
+
export default __wbg_init;
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
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 __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;
|
|
9
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
10
|
+
export const __wbindgen_start: () => void;
|