qr-decoder-js 1.0.5 → 1.0.7
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 +10 -4
- package/README_ZH.md +7 -2
- package/dist/index.d.ts +3 -3
- package/dist/qr-decoder.js +164 -105
- package/dist/qr-decoder.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,6 +60,12 @@ Decode a QR code from RGBA image data.
|
|
|
60
60
|
|
|
61
61
|
Both methods return `Promise<DecodeResult>`.
|
|
62
62
|
|
|
63
|
+
By default, decoding uses `mode: 'aggressive'`. It tries the original image,
|
|
64
|
+
red/blue channel contrast rescue, edge sharpening, CLAHE, tilt compensation,
|
|
65
|
+
quiet-zone padding, morphology, Otsu thresholding, local adaptive thresholding,
|
|
66
|
+
and inversion. Use `mode: 'fast'` or `mode: 'balanced'` when lower latency is
|
|
67
|
+
more important than rescue coverage.
|
|
68
|
+
|
|
63
69
|
Common reader options include `tryRotate`, `tryInvert`, `tryHarder`,
|
|
64
70
|
`tryDownscale`, `tryDenoise`, `maxNumberOfSymbols`, `formats`, and
|
|
65
71
|
`characterSet`:
|
|
@@ -97,8 +103,10 @@ On failure, check `success` and read `error`:
|
|
|
97
103
|
## Browser support
|
|
98
104
|
|
|
99
105
|
The target browser must support WebAssembly, `fetch`, `TextDecoder`, and
|
|
100
|
-
`ImageData`. The package
|
|
101
|
-
|
|
106
|
+
`ImageData`. The package uses `zxing-wasm` for QR detection and native
|
|
107
|
+
`TextDecoder` for encoding fallback; it does not use Google ML Kit,
|
|
108
|
+
`compact_enc_det`, or `ced-wasm`. The package is intended for browser
|
|
109
|
+
applications and does not provide a Node.js image adapter.
|
|
102
110
|
|
|
103
111
|
## Development
|
|
104
112
|
|
|
@@ -117,5 +125,3 @@ MIT
|
|
|
117
125
|
This project uses and is inspired by:
|
|
118
126
|
|
|
119
127
|
- [zxing-wasm](https://github.com/Sec-ant/zxing-wasm) for QR code detection.
|
|
120
|
-
- [Google compact_enc_det](https://github.com/google/compact_enc_det) for character encoding detection.
|
|
121
|
-
- [ced-wasm](https://github.com/neichen/ced-wasm), a WebAssembly port of `compact_enc_det`.
|
package/README_ZH.md
CHANGED
|
@@ -58,6 +58,11 @@ const result = await decodeQRImageData(imageData);
|
|
|
58
58
|
|
|
59
59
|
两个方法都返回 `Promise<DecodeResult>`。
|
|
60
60
|
|
|
61
|
+
默认使用 `mode: 'aggressive'`,会依次尝试原图、红/蓝通道对比度增强、锐化、
|
|
62
|
+
CLAHE、倾斜校正、静区补边、形态学修复、Otsu 二值化、局部自适应二值化和反色。
|
|
63
|
+
如果更重视解码延迟而不是困难图片的检出率,可以使用 `mode: 'fast'` 或
|
|
64
|
+
`mode: 'balanced'`。
|
|
65
|
+
|
|
61
66
|
常用选项包括 `tryRotate`、`tryInvert`、`tryHarder`、`tryDownscale`、
|
|
62
67
|
`tryDenoise`、`maxNumberOfSymbols`、`formats` 和 `characterSet`:
|
|
63
68
|
|
|
@@ -94,6 +99,8 @@ interface DecodeResult {
|
|
|
94
99
|
## 浏览器要求
|
|
95
100
|
|
|
96
101
|
目标浏览器需要支持 WebAssembly、`fetch`、`TextDecoder` 和 `ImageData`。
|
|
102
|
+
二维码识别使用 `zxing-wasm`,文本编码回退使用浏览器原生 `TextDecoder`,
|
|
103
|
+
当前不使用 Google ML Kit、`compact_enc_det` 或 `ced-wasm`。
|
|
97
104
|
本包面向浏览器应用,不提供 Node.js 图片解码适配层。
|
|
98
105
|
|
|
99
106
|
## 本地开发
|
|
@@ -113,5 +120,3 @@ MIT
|
|
|
113
120
|
本项目使用或参考了以下开源项目:
|
|
114
121
|
|
|
115
122
|
- [zxing-wasm](https://github.com/Sec-ant/zxing-wasm):用于二维码识别。
|
|
116
|
-
- [Google compact_enc_det](https://github.com/google/compact_enc_det):用于文本编码检测。
|
|
117
|
-
- [ced-wasm](https://github.com/neichen/ced-wasm):`compact_enc_det` 的 WebAssembly 移植版本。
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface DecodeResult {
|
|
|
6
6
|
encoding?: string;
|
|
7
7
|
/** Detected encoding identifier. */
|
|
8
8
|
detectedEncoding?: string | null;
|
|
9
|
-
/** Preprocess version that matched
|
|
9
|
+
/** Preprocess version that matched, such as original, color rescue, adaptive binary, or inverted. */
|
|
10
10
|
version?: string;
|
|
11
11
|
error?: string;
|
|
12
12
|
}
|
|
@@ -14,8 +14,8 @@ export interface DecodeResult {
|
|
|
14
14
|
export interface ReaderOptions {
|
|
15
15
|
/** Rescue depth:
|
|
16
16
|
* - fast: original only (fastest for high-framerate video stream)
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
* - balanced: original + color rescue + sharpening + CLAHE + fast shear + center crop
|
|
18
|
+
* - aggressive: balanced + quiet-zone, dot-matrix, Otsu, adaptive binary, and inverted variants
|
|
19
19
|
*/
|
|
20
20
|
mode?: 'fast' | 'balanced' | 'aggressive';
|
|
21
21
|
formats?: string[];
|
package/dist/qr-decoder.js
CHANGED
|
@@ -676,15 +676,15 @@ async function x(e = {}) {
|
|
|
676
676
|
}
|
|
677
677
|
var S, C, w, de, fe, T, E, D, pe = (e) => {
|
|
678
678
|
for (; e.length > 0;) e.shift()(i);
|
|
679
|
-
}, me = [], he = (e) => me.push(e), ge = [], _e = (e) => ge.push(e), O = (e) => Fn(e), k = () => In(), A = [], j = 0,
|
|
680
|
-
var t = new
|
|
679
|
+
}, me = [], he = (e) => me.push(e), ge = [], _e = (e) => ge.push(e), O = (e) => Fn(e), k = () => In(), A = [], j = 0, M = (e) => {
|
|
680
|
+
var t = new P(e);
|
|
681
681
|
return t.get_caught() || (t.set_caught(!0), j--), t.set_rethrown(!1), A.push(t), Nn(e);
|
|
682
|
-
},
|
|
682
|
+
}, N = 0, ve = () => {
|
|
683
683
|
$(0, 0);
|
|
684
684
|
var e = A.pop();
|
|
685
|
-
Ln(e.excPtr),
|
|
685
|
+
Ln(e.excPtr), N = 0;
|
|
686
686
|
};
|
|
687
|
-
class
|
|
687
|
+
class P {
|
|
688
688
|
constructor(e) {
|
|
689
689
|
this.excPtr = e, this.ptr = e - 24;
|
|
690
690
|
}
|
|
@@ -722,29 +722,29 @@ async function x(e = {}) {
|
|
|
722
722
|
return E[this.ptr + 16 >> 2];
|
|
723
723
|
}
|
|
724
724
|
}
|
|
725
|
-
var
|
|
726
|
-
var t =
|
|
727
|
-
if (!t) return
|
|
728
|
-
var n = new
|
|
725
|
+
var F = (e) => Pn(e), ye = (e) => {
|
|
726
|
+
var t = N;
|
|
727
|
+
if (!t) return F(0), 0;
|
|
728
|
+
var n = new P(t);
|
|
729
729
|
n.set_adjusted_ptr(t);
|
|
730
730
|
var r = n.get_type();
|
|
731
|
-
if (!r) return
|
|
731
|
+
if (!r) return F(0), t;
|
|
732
732
|
for (var i of e) {
|
|
733
733
|
if (i === 0 || i === r) break;
|
|
734
734
|
var a = n.ptr + 16;
|
|
735
|
-
if (zn(i, r, a)) return
|
|
735
|
+
if (zn(i, r, a)) return F(i), t;
|
|
736
736
|
}
|
|
737
|
-
return
|
|
738
|
-
},
|
|
737
|
+
return F(r), t;
|
|
738
|
+
}, be = () => ye([]), xe = (e) => ye([e]), Se = (e, t) => ye([e, t]), Ce = () => {
|
|
739
739
|
var e = A.pop();
|
|
740
740
|
e || re("no exception to throw");
|
|
741
741
|
var t = e.excPtr;
|
|
742
|
-
throw e.get_rethrown() || (A.push(e), e.set_rethrown(!0), e.set_caught(!1), j++), Rn(t),
|
|
743
|
-
},
|
|
744
|
-
throw new
|
|
745
|
-
},
|
|
746
|
-
throw
|
|
747
|
-
},
|
|
742
|
+
throw e.get_rethrown() || (A.push(e), e.set_rethrown(!0), e.set_caught(!1), j++), Rn(t), N = t, N;
|
|
743
|
+
}, we = (e, t, n) => {
|
|
744
|
+
throw new P(e).init(t, n), Rn(e), N = e, j++, N;
|
|
745
|
+
}, Te = () => j, Ee = (e) => {
|
|
746
|
+
throw N ||= e, N;
|
|
747
|
+
}, De = () => re(""), Oe = {}, ke = (e) => {
|
|
748
748
|
for (; e.length;) {
|
|
749
749
|
var t = e.pop();
|
|
750
750
|
e.pop()(t);
|
|
@@ -778,8 +778,8 @@ async function x(e = {}) {
|
|
|
778
778
|
}
|
|
779
779
|
a.length === 0 && r(i);
|
|
780
780
|
}, Ne = (e) => {
|
|
781
|
-
var t =
|
|
782
|
-
delete
|
|
781
|
+
var t = Oe[e];
|
|
782
|
+
delete Oe[e];
|
|
783
783
|
var n = t.rawConstructor, r = t.rawDestructor, i = t.fields, a = i.map((e) => e.getterReturnType).concat(i.map((e) => e.setterArgumentType));
|
|
784
784
|
z([e], a, (e) => {
|
|
785
785
|
var a = {};
|
|
@@ -1449,14 +1449,14 @@ async function x(e = {}) {
|
|
|
1449
1449
|
}
|
|
1450
1450
|
});
|
|
1451
1451
|
}, on = (e, t, n, r, i, a) => {
|
|
1452
|
-
|
|
1452
|
+
Oe[e] = {
|
|
1453
1453
|
name: B(t),
|
|
1454
1454
|
rawConstructor: q(n, r),
|
|
1455
1455
|
rawDestructor: q(i, a),
|
|
1456
1456
|
fields: []
|
|
1457
1457
|
};
|
|
1458
1458
|
}, sn = (e, t, n, r, i, a, o, s, c, l) => {
|
|
1459
|
-
|
|
1459
|
+
Oe[e].fields.push({
|
|
1460
1460
|
fieldName: B(t),
|
|
1461
1461
|
getterReturnType: n,
|
|
1462
1462
|
getter: q(r, i),
|
|
@@ -1572,16 +1572,16 @@ async function x(e = {}) {
|
|
|
1572
1572
|
jn = e.Aa, Q = i._free = e.Ba, Mn = i._malloc = e.Da, Nn = e.Ea, $ = e.Fa, Pn = e.Ga, Fn = e.Ha, In = e.Ia, Ln = e.Ja, Rn = e.Ka, zn = e.La, G.viijii = e.Ma, Bn = G.viijjijjjjjj = e.Na, Vn = G.iiijj = e.Oa, Hn = G.jiiii = e.Pa, G.iiiiij = e.Qa, G.iiiiijj = e.Ra, G.iiiiiijj = e.Sa, Un = e.ya, Wn = e.Ca;
|
|
1573
1573
|
}
|
|
1574
1574
|
var Kn = {
|
|
1575
|
-
q:
|
|
1576
|
-
x:
|
|
1577
|
-
a:
|
|
1578
|
-
i:
|
|
1579
|
-
m:
|
|
1580
|
-
S:
|
|
1581
|
-
p:
|
|
1582
|
-
fa:
|
|
1583
|
-
d:
|
|
1584
|
-
ba:
|
|
1575
|
+
q: M,
|
|
1576
|
+
x: ve,
|
|
1577
|
+
a: be,
|
|
1578
|
+
i: xe,
|
|
1579
|
+
m: Se,
|
|
1580
|
+
S: Ce,
|
|
1581
|
+
p: we,
|
|
1582
|
+
fa: Te,
|
|
1583
|
+
d: Ee,
|
|
1584
|
+
ba: De,
|
|
1585
1585
|
va: Ne,
|
|
1586
1586
|
aa: Pe,
|
|
1587
1587
|
pa: Ie,
|
|
@@ -2100,33 +2100,46 @@ function D(e, t) {
|
|
|
2100
2100
|
return null;
|
|
2101
2101
|
}
|
|
2102
2102
|
function pe(e) {
|
|
2103
|
-
let { data: t, width: n, height: r } = e, i = t.length, a = E(n, r), o = a.data, s = E(n, r), c = s.data, l =
|
|
2103
|
+
let { data: t, width: n, height: r } = e, i = t.length, a = E(n, r), o = a.data, s = E(n, r), c = s.data, l = E(n, r), u = l.data, d = E(n, r), f = d.data, p = 255, m = 0, h = 500, g = -500, _ = new Int16Array(n * r);
|
|
2104
2104
|
for (let e = 0, n = 0; e < i; e += 4, n++) {
|
|
2105
2105
|
let r = t[e], i = t[e + 2], a = 2 * r - i;
|
|
2106
|
-
|
|
2106
|
+
_[n] = a, r < p && (p = r), r > m && (m = r), a < h && (h = a), a > g && (g = a);
|
|
2107
2107
|
}
|
|
2108
|
-
let
|
|
2108
|
+
let v = m - p > 15 ? m - p : 255, y = m - p > 15 ? p : 0, b = g - h > 15 ? g - h : 255, ee = g - h > 15 ? h : 0;
|
|
2109
2109
|
for (let e = 0, n = 0; n < i; n += 4, e++) {
|
|
2110
|
-
let r = t[n + 3] || 255, i = Math.max(0, Math.min(255,
|
|
2111
|
-
o[n] = i, o[n + 1] = i, o[n + 2] = i, o[n + 3] = r;
|
|
2112
|
-
let
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2110
|
+
let r = t[n + 3] || 255, i = t[n], a = Math.max(0, Math.min(255, 2 * i - t[n + 2]));
|
|
2111
|
+
o[n] = i, o[n + 1] = i, o[n + 2] = i, o[n + 3] = r, c[n] = a, c[n + 1] = a, c[n + 2] = a, c[n + 3] = r;
|
|
2112
|
+
let s = Math.max(0, Math.min(255, Math.round((i - y) * 255 / v)));
|
|
2113
|
+
u[n] = s, u[n + 1] = s, u[n + 2] = s, u[n + 3] = r;
|
|
2114
|
+
let l = Math.max(0, Math.min(255, Math.round((_[e] - ee) * 255 / b)));
|
|
2115
|
+
f[n] = l, f[n + 1] = l, f[n + 2] = l, f[n + 3] = r;
|
|
2116
|
+
}
|
|
2117
|
+
return [
|
|
2118
|
+
{
|
|
2119
|
+
data: s,
|
|
2120
|
+
label: "blue-enhanced"
|
|
2121
|
+
},
|
|
2122
|
+
{
|
|
2123
|
+
data: a,
|
|
2124
|
+
label: "red-channel"
|
|
2125
|
+
},
|
|
2126
|
+
{
|
|
2127
|
+
data: d,
|
|
2128
|
+
label: "blue-enhanced-stretched"
|
|
2129
|
+
},
|
|
2130
|
+
{
|
|
2131
|
+
data: l,
|
|
2132
|
+
label: "red-stretched"
|
|
2133
|
+
}
|
|
2134
|
+
];
|
|
2122
2135
|
}
|
|
2123
2136
|
function me(e, t = 1.2) {
|
|
2124
2137
|
let { width: n, height: r, data: i } = e, a = E(n, r), o = a.data;
|
|
2125
|
-
for (let e =
|
|
2126
|
-
let
|
|
2127
|
-
for (let e =
|
|
2128
|
-
let
|
|
2129
|
-
o[
|
|
2138
|
+
for (let e = 0; e < r; e++) {
|
|
2139
|
+
let a = e * n, s = Math.max(0, e - 1) * n, c = Math.min(r - 1, e + 1) * n;
|
|
2140
|
+
for (let e = 0; e < n; e++) {
|
|
2141
|
+
let r = (a + e) * 4, l = i[r], u = i[(s + e) * 4], d = i[(c + e) * 4], f = i[(a + Math.max(0, e - 1)) * 4], p = i[(a + Math.min(n - 1, e + 1)) * 4], m = 5 * l - u - d - f - p, h = Math.max(0, Math.min(255, Math.round(l * (1 - t) + m * t)));
|
|
2142
|
+
o[r] = h, o[r + 1] = h, o[r + 2] = h, o[r + 3] = i[r + 3] || 255;
|
|
2130
2143
|
}
|
|
2131
2144
|
}
|
|
2132
2145
|
return a;
|
|
@@ -2134,18 +2147,18 @@ function me(e, t = 1.2) {
|
|
|
2134
2147
|
function he(e) {
|
|
2135
2148
|
let { width: t, height: n, data: r } = e, i = new Uint8ClampedArray(t * n);
|
|
2136
2149
|
for (let e = 0, t = 0; t < i.length; e += 4, t++) i[t] = r[e];
|
|
2137
|
-
let a =
|
|
2150
|
+
let a = P(i, t, n, {
|
|
2138
2151
|
clipLimit: 2.5,
|
|
2139
2152
|
tileSize: 8
|
|
2140
|
-
}), o =
|
|
2153
|
+
}), o = P(j(e), t, n, {
|
|
2141
2154
|
clipLimit: 2.5,
|
|
2142
2155
|
tileSize: 8
|
|
2143
2156
|
});
|
|
2144
2157
|
return [{
|
|
2145
|
-
data:
|
|
2158
|
+
data: M(a, t, n),
|
|
2146
2159
|
label: "clahe-red"
|
|
2147
2160
|
}, {
|
|
2148
|
-
data:
|
|
2161
|
+
data: M(o, t, n),
|
|
2149
2162
|
label: "clahe-gray"
|
|
2150
2163
|
}];
|
|
2151
2164
|
}
|
|
@@ -2292,7 +2305,7 @@ function j(e) {
|
|
|
2292
2305
|
for (let e = 0, n = 0; e < t.length; e += 4, n++) i[n] = Math.round(.299 * t[e] + .587 * t[e + 1] + .114 * t[e + 2]);
|
|
2293
2306
|
return i;
|
|
2294
2307
|
}
|
|
2295
|
-
function
|
|
2308
|
+
function M(e, t, n) {
|
|
2296
2309
|
let r = E(t, n), i = r.data;
|
|
2297
2310
|
for (let t = 0, n = 0; t < e.length; t++, n += 4) {
|
|
2298
2311
|
let r = e[t];
|
|
@@ -2300,7 +2313,7 @@ function ve(e, t, n) {
|
|
|
2300
2313
|
}
|
|
2301
2314
|
return r;
|
|
2302
2315
|
}
|
|
2303
|
-
function
|
|
2316
|
+
function N(e, t, n) {
|
|
2304
2317
|
let r = e.length, i = /* @__PURE__ */ new Int32Array(256);
|
|
2305
2318
|
for (let t = 0; t < r; t++) i[e[t]]++;
|
|
2306
2319
|
let a = 0;
|
|
@@ -2318,35 +2331,50 @@ function M(e, t, n) {
|
|
|
2318
2331
|
for (let t = 0; t < r; t++) u[t] = e[t] > l ? 255 : 0;
|
|
2319
2332
|
return u;
|
|
2320
2333
|
}
|
|
2321
|
-
function
|
|
2322
|
-
let
|
|
2323
|
-
for (let r =
|
|
2324
|
-
let
|
|
2334
|
+
function ve(e, t, n, r = 8, i = .15) {
|
|
2335
|
+
let a = t + 1, o = new Int32Array((t + 1) * (n + 1)), s = new Uint8ClampedArray(e.length);
|
|
2336
|
+
for (let r = 1; r <= n; r++) {
|
|
2337
|
+
let n = 0, i = (r - 1) * t, s = r * a, c = (r - 1) * a;
|
|
2338
|
+
for (let r = 1; r <= t; r++) n += e[i + r - 1], o[s + r] = o[c + r] + n;
|
|
2339
|
+
}
|
|
2340
|
+
for (let c = 0; c < n; c++) {
|
|
2341
|
+
let l = Math.max(0, c - r), u = Math.min(n - 1, c + r), d = l * a, f = (u + 1) * a;
|
|
2342
|
+
for (let n = 0; n < t; n++) {
|
|
2343
|
+
let a = Math.max(0, n - r), p = Math.min(t - 1, n + r), m = (p - a + 1) * (u - l + 1), h = (o[f + p + 1] - o[d + p + 1] - o[f + a] + o[d + a]) / m * (1 - i);
|
|
2344
|
+
s[c * t + n] = e[c * t + n] <= h ? 0 : 255;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
return s;
|
|
2348
|
+
}
|
|
2349
|
+
function P(e, t, n, r = {}) {
|
|
2350
|
+
let { clipLimit: i = 2.5, tileSize: a = 8 } = r, o = new Uint8ClampedArray(e.length), s = [];
|
|
2351
|
+
for (let r = 0; r < a; r++) for (let o = 0; o < a; o++) {
|
|
2352
|
+
let c = /* @__PURE__ */ new Int32Array(256), l = Math.floor(o * t / a), u = Math.floor((o + 1) * t / a), d = Math.floor(r * n / a), f = Math.floor((r + 1) * n / a), p = (u - l) * (f - d), m = Math.max(1, Math.round(i * p / 256));
|
|
2325
2353
|
for (let n = d; n < f; n++) {
|
|
2326
2354
|
let r = n * t;
|
|
2327
|
-
for (let t = l; t < u; t++)
|
|
2355
|
+
for (let t = l; t < u; t++) c[e[r + t]]++;
|
|
2328
2356
|
}
|
|
2329
|
-
let
|
|
2330
|
-
for (let e = 0; e < 256; e++)
|
|
2331
|
-
let
|
|
2332
|
-
for (let e = 0; e < 256; e++)
|
|
2333
|
-
for (let e = 0; e < 256 &&
|
|
2334
|
-
let
|
|
2335
|
-
for (let e = 0; e < 256; e++)
|
|
2336
|
-
|
|
2357
|
+
let h = 0;
|
|
2358
|
+
for (let e = 0; e < 256; e++) c[e] > m && (h += c[e] - m, c[e] = m);
|
|
2359
|
+
let g = Math.floor(h / 256), _ = h - g * 256;
|
|
2360
|
+
for (let e = 0; e < 256; e++) c[e] += g;
|
|
2361
|
+
for (let e = 0; e < 256 && _ > 0; e++, _--) c[e] += 1;
|
|
2362
|
+
let v = (u - l) * (f - d) || 1, y = 0, b = /* @__PURE__ */ new Uint8ClampedArray(256);
|
|
2363
|
+
for (let e = 0; e < 256; e++) y += c[e], b[e] = Math.round(y * 255 / v);
|
|
2364
|
+
s.push(b);
|
|
2337
2365
|
}
|
|
2338
2366
|
for (let r = 0; r < n; r++) {
|
|
2339
|
-
let i = (r + .5) / n * a - .5,
|
|
2367
|
+
let i = (r + .5) / n * a - .5, c = Math.max(0, Math.min(a - 1, Math.floor(i))), l = Math.max(0, Math.min(a - 1, c + 1)), u = Math.max(0, Math.min(1, i - c));
|
|
2340
2368
|
for (let n = 0; n < t; n++) {
|
|
2341
|
-
let i = (n + .5) / t * a - .5, d = Math.max(0, Math.min(a - 1, Math.floor(i))), f = Math.max(0, Math.min(a - 1, d + 1)), p = Math.max(0, Math.min(1, i - d)), m = e[r * t + n], h = c
|
|
2342
|
-
|
|
2369
|
+
let i = (n + .5) / t * a - .5, d = Math.max(0, Math.min(a - 1, Math.floor(i))), f = Math.max(0, Math.min(a - 1, d + 1)), p = Math.max(0, Math.min(1, i - d)), m = e[r * t + n], h = s[c * a + d][m], g = s[c * a + f][m], _ = s[l * a + d][m], v = s[l * a + f][m], y = h + (g - h) * p, b = _ + (v - _) * p;
|
|
2370
|
+
o[r * t + n] = y + (b - y) * u;
|
|
2343
2371
|
}
|
|
2344
2372
|
}
|
|
2345
|
-
return
|
|
2373
|
+
return o;
|
|
2346
2374
|
}
|
|
2347
2375
|
//#endregion
|
|
2348
2376
|
//#region src/core/encoding.js
|
|
2349
|
-
var
|
|
2377
|
+
var F = {
|
|
2350
2378
|
GB: "gbk",
|
|
2351
2379
|
GBK: "gbk",
|
|
2352
2380
|
GB2312: "gb2312",
|
|
@@ -2387,10 +2415,10 @@ var N = {
|
|
|
2387
2415
|
"ISO-2022-JP": "iso-2022-jp",
|
|
2388
2416
|
"ISO-2022-KR": "iso-2022-kr"
|
|
2389
2417
|
};
|
|
2390
|
-
function
|
|
2418
|
+
function ye(e) {
|
|
2391
2419
|
if (!e) return "utf-8";
|
|
2392
2420
|
let t = String(e).trim().toUpperCase();
|
|
2393
|
-
return t = t.replace(/\(.*?\)/g, "").trim(),
|
|
2421
|
+
return t = t.replace(/\(.*?\)/g, "").trim(), F[t] ? F[t] : t.replace(/_/g, "-").toLowerCase();
|
|
2394
2422
|
}
|
|
2395
2423
|
var be = [
|
|
2396
2424
|
"utf-8",
|
|
@@ -2434,7 +2462,7 @@ function we(e, t) {
|
|
|
2434
2462
|
try {
|
|
2435
2463
|
new TextDecoder("utf-8", { fatal: !0 }).decode(e), n = !0;
|
|
2436
2464
|
} catch {}
|
|
2437
|
-
let r = [
|
|
2465
|
+
let r = [ye(t), ...be], i = [];
|
|
2438
2466
|
for (let e of r) e && !i.includes(e) && i.push(e);
|
|
2439
2467
|
let a = {
|
|
2440
2468
|
text: "",
|
|
@@ -2471,7 +2499,7 @@ async function De(e, t = {}) {
|
|
|
2471
2499
|
success: !1,
|
|
2472
2500
|
error: "Invalid image data (expected ImageData or {width,height,data})"
|
|
2473
2501
|
};
|
|
2474
|
-
let { mode: n = "
|
|
2502
|
+
let { mode: n = "aggressive", ...r } = t, i = Ee.includes(n) ? n : "balanced", a = {
|
|
2475
2503
|
...Te,
|
|
2476
2504
|
...r
|
|
2477
2505
|
}, o = Oe(e, i), s = null, c = null;
|
|
@@ -2515,7 +2543,7 @@ function* Oe(e, t = "balanced") {
|
|
|
2515
2543
|
data: e.data,
|
|
2516
2544
|
label: e.label
|
|
2517
2545
|
};
|
|
2518
|
-
let a = i
|
|
2546
|
+
let a = i.find((e) => e.label === "red-stretched") || i.find((e) => e.label === "red-channel");
|
|
2519
2547
|
a && (yield {
|
|
2520
2548
|
data: me(a.data, 1.2),
|
|
2521
2549
|
label: "sharpen-red"
|
|
@@ -2550,12 +2578,12 @@ function* Oe(e, t = "balanced") {
|
|
|
2550
2578
|
label: `${t.label}-red`
|
|
2551
2579
|
};
|
|
2552
2580
|
if (n >= 380 && r >= 380) {
|
|
2553
|
-
let
|
|
2554
|
-
|
|
2555
|
-
data:
|
|
2581
|
+
let t = pe(ge(e, .6)), n = t.find((e) => e.label === "red-stretched") || t.find((e) => e.label === "red-channel");
|
|
2582
|
+
n && (yield {
|
|
2583
|
+
data: n.data,
|
|
2556
2584
|
label: "center-crop-red"
|
|
2557
2585
|
}, yield {
|
|
2558
|
-
data: me(
|
|
2586
|
+
data: me(n.data, 1.2),
|
|
2559
2587
|
label: "center-crop-sharpen-red"
|
|
2560
2588
|
});
|
|
2561
2589
|
}
|
|
@@ -2564,48 +2592,79 @@ function* Oe(e, t = "balanced") {
|
|
|
2564
2592
|
data: t.data,
|
|
2565
2593
|
label: t.label
|
|
2566
2594
|
};
|
|
2567
|
-
let o =
|
|
2568
|
-
|
|
2569
|
-
data: o,
|
|
2595
|
+
let o = [{
|
|
2596
|
+
data: e,
|
|
2570
2597
|
label: "quiet-zone"
|
|
2571
|
-
})
|
|
2572
|
-
|
|
2598
|
+
}, ...i.map((e) => ({
|
|
2599
|
+
data: e.data,
|
|
2600
|
+
label: `quiet-zone-${e.label}`
|
|
2601
|
+
}))];
|
|
2602
|
+
for (let e of o) {
|
|
2603
|
+
let t = O(e.data);
|
|
2604
|
+
t && (yield {
|
|
2605
|
+
data: t,
|
|
2606
|
+
label: e.label
|
|
2607
|
+
});
|
|
2608
|
+
}
|
|
2609
|
+
let s = [{
|
|
2610
|
+
data: e,
|
|
2611
|
+
label: ""
|
|
2612
|
+
}, ...i.map((e) => ({
|
|
2613
|
+
data: e.data,
|
|
2614
|
+
label: `${e.label}-`
|
|
2615
|
+
}))];
|
|
2616
|
+
for (let e of s) for (let t of A(e.data)) yield {
|
|
2573
2617
|
data: t.data,
|
|
2574
|
-
label: t.label
|
|
2618
|
+
label: `${e.label}${t.label}`
|
|
2619
|
+
};
|
|
2620
|
+
let c = [{
|
|
2621
|
+
data: e,
|
|
2622
|
+
label: "gray"
|
|
2623
|
+
}, ...i.map((e) => ({
|
|
2624
|
+
data: e.data,
|
|
2625
|
+
label: e.label
|
|
2626
|
+
}))];
|
|
2627
|
+
for (let e of c) yield {
|
|
2628
|
+
data: M(N(j(e.data), n, r), n, r),
|
|
2629
|
+
label: `otsu-binary-${e.label}`
|
|
2630
|
+
};
|
|
2631
|
+
for (let e of c) yield {
|
|
2632
|
+
data: M(ve(j(e.data), n, r), n, r),
|
|
2633
|
+
label: `adaptive-binary-${e.label}`
|
|
2634
|
+
};
|
|
2635
|
+
for (let e of c) yield {
|
|
2636
|
+
data: k(e.data).data,
|
|
2637
|
+
label: `inverted-${e.label}`
|
|
2575
2638
|
};
|
|
2576
|
-
yield {
|
|
2577
|
-
data: ve(M(j(e), n, r), n, r),
|
|
2578
|
-
label: "otsu-binary"
|
|
2579
|
-
}, yield k(e);
|
|
2580
2639
|
}
|
|
2581
|
-
async function
|
|
2582
|
-
return De(await
|
|
2640
|
+
async function ke(e, t = {}) {
|
|
2641
|
+
return De(await I(e), {
|
|
2583
2642
|
mode: "aggressive",
|
|
2584
2643
|
...t
|
|
2585
2644
|
});
|
|
2586
2645
|
}
|
|
2587
|
-
async function
|
|
2646
|
+
async function I(e) {
|
|
2588
2647
|
if (typeof ImageData < "u" && e instanceof ImageData || e && typeof e.width == "number" && typeof e.height == "number" && e.data) return e;
|
|
2589
|
-
if (typeof HTMLImageElement < "u" && e instanceof HTMLImageElement) return
|
|
2648
|
+
if (typeof HTMLImageElement < "u" && e instanceof HTMLImageElement) return L(e);
|
|
2590
2649
|
if (typeof HTMLCanvasElement < "u" && e instanceof HTMLCanvasElement || typeof OffscreenCanvas < "u" && e instanceof OffscreenCanvas) return e.getContext("2d").getImageData(0, 0, e.width, e.height);
|
|
2591
|
-
if (typeof Blob < "u" && e instanceof Blob) return
|
|
2650
|
+
if (typeof Blob < "u" && e instanceof Blob) return R(e);
|
|
2592
2651
|
throw TypeError("Unsupported input type; expected File, Blob, ImageData, HTMLImageElement, or Canvas");
|
|
2593
2652
|
}
|
|
2594
|
-
function
|
|
2653
|
+
function L(e) {
|
|
2595
2654
|
let t = document.createElement("canvas");
|
|
2596
2655
|
t.width = e.naturalWidth || e.width, t.height = e.naturalHeight || e.height;
|
|
2597
2656
|
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
2598
2657
|
return n.drawImage(e, 0, 0), n.getImageData(0, 0, t.width, t.height);
|
|
2599
2658
|
}
|
|
2600
|
-
function
|
|
2659
|
+
function R(e) {
|
|
2601
2660
|
return new Promise((t, n) => {
|
|
2602
2661
|
let r = URL.createObjectURL(e), i = new Image();
|
|
2603
2662
|
i.onload = () => {
|
|
2604
|
-
URL.revokeObjectURL(r), t(
|
|
2663
|
+
URL.revokeObjectURL(r), t(L(i));
|
|
2605
2664
|
}, i.onerror = () => {
|
|
2606
2665
|
URL.revokeObjectURL(r), n(/* @__PURE__ */ Error("Failed to load image from blob"));
|
|
2607
2666
|
}, i.src = r;
|
|
2608
2667
|
});
|
|
2609
2668
|
}
|
|
2610
2669
|
//#endregion
|
|
2611
|
-
export {
|
|
2670
|
+
export { ke as decodeQRFile, De as decodeQRImageData };
|