pica 10.0.0 → 10.0.2
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 +4 -0
- package/dist/pica.cjs.d.ts +2 -1
- package/dist/pica.es.d.ts +2 -1
- package/dist/pica.js +215 -300
- package/dist/pica.js.map +1 -1
- package/dist/pica.min.js +1 -1
- package/dist/pica.min.js.map +1 -1
- package/dist/pica.min.mjs +1 -1
- package/dist/pica.min.mjs.map +1 -1
- package/dist/pica.mjs +215 -300
- package/dist/pica.mjs.map +1 -1
- package/dist/pica_main.js +214 -299
- package/dist/pica_main.js.map +1 -1
- package/dist/pica_main.mjs +214 -299
- package/dist/pica_main.mjs.map +1 -1
- package/dist/pica_worker.js +209 -294
- package/dist/pica_worker.js.map +1 -1
- package/package.json +24 -5
package/dist/pica_main.js
CHANGED
|
@@ -7,183 +7,105 @@ https://github.com/nodeca/pica
|
|
|
7
7
|
(function(global, factory) {
|
|
8
8
|
typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define([], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global.pica = factory());
|
|
9
9
|
})(this, function() {
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
-
key = keys[i];
|
|
20
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
-
get: ((k) => from[k]).bind(null, key),
|
|
22
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
/*
|
|
32
|
-
object-assign
|
|
33
|
-
(c) Sindre Sorhus
|
|
34
|
-
@license MIT
|
|
35
|
-
*/
|
|
36
|
-
var require_object_assign = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
37
|
-
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|
38
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
39
|
-
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
40
|
-
function toObject(val) {
|
|
41
|
-
if (val === null || val === void 0) throw new TypeError("Object.assign cannot be called with null or undefined");
|
|
42
|
-
return Object(val);
|
|
43
|
-
}
|
|
44
|
-
function shouldUseNative() {
|
|
45
|
-
try {
|
|
46
|
-
if (!Object.assign) return false;
|
|
47
|
-
var test1 = /* @__PURE__ */ new String("abc");
|
|
48
|
-
test1[5] = "de";
|
|
49
|
-
if (Object.getOwnPropertyNames(test1)[0] === "5") return false;
|
|
50
|
-
var test2 = {};
|
|
51
|
-
for (var i = 0; i < 10; i++) test2["_" + String.fromCharCode(i)] = i;
|
|
52
|
-
if (Object.getOwnPropertyNames(test2).map(function(n) {
|
|
53
|
-
return test2[n];
|
|
54
|
-
}).join("") !== "0123456789") return false;
|
|
55
|
-
var test3 = {};
|
|
56
|
-
"abcdefghijklmnopqrst".split("").forEach(function(letter) {
|
|
57
|
-
test3[letter] = letter;
|
|
58
|
-
});
|
|
59
|
-
if (Object.keys(Object.assign({}, test3)).join("") !== "abcdefghijklmnopqrst") return false;
|
|
60
|
-
return true;
|
|
61
|
-
} catch (err) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
module.exports = shouldUseNative() ? Object.assign : function(target, source) {
|
|
66
|
-
var from;
|
|
67
|
-
var to = toObject(target);
|
|
68
|
-
var symbols;
|
|
69
|
-
for (var s = 1; s < arguments.length; s++) {
|
|
70
|
-
from = Object(arguments[s]);
|
|
71
|
-
for (var key in from) if (hasOwnProperty.call(from, key)) to[key] = from[key];
|
|
72
|
-
if (getOwnPropertySymbols) {
|
|
73
|
-
symbols = getOwnPropertySymbols(from);
|
|
74
|
-
for (var i = 0; i < symbols.length; i++) if (propIsEnumerable.call(from, symbols[i])) to[symbols[i]] = from[symbols[i]];
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return to;
|
|
78
|
-
};
|
|
79
|
-
}));
|
|
80
|
-
var require_base64decode = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
81
|
-
var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
82
|
-
module.exports = function base64decode(str) {
|
|
83
|
-
var input = str.replace(/[\r\n=]/g, ""), max = input.length;
|
|
84
|
-
var out = new Uint8Array(max * 3 >> 2);
|
|
85
|
-
var bits = 0;
|
|
86
|
-
var ptr = 0;
|
|
87
|
-
for (var idx = 0; idx < max; idx++) {
|
|
88
|
-
if (idx % 4 === 0 && idx) {
|
|
89
|
-
out[ptr++] = bits >> 16 & 255;
|
|
90
|
-
out[ptr++] = bits >> 8 & 255;
|
|
91
|
-
out[ptr++] = bits & 255;
|
|
92
|
-
}
|
|
93
|
-
bits = bits << 6 | BASE64_MAP.indexOf(input.charAt(idx));
|
|
94
|
-
}
|
|
95
|
-
var tailbits = max % 4 * 6;
|
|
96
|
-
if (tailbits === 0) {
|
|
10
|
+
var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
11
|
+
function base64decode(str) {
|
|
12
|
+
const input = str.replace(/[\r\n=]/g, ""), max = input.length;
|
|
13
|
+
const out = new Uint8Array(max * 3 >> 2);
|
|
14
|
+
let bits = 0;
|
|
15
|
+
let ptr = 0;
|
|
16
|
+
for (let idx = 0; idx < max; idx++) {
|
|
17
|
+
if (idx % 4 === 0 && idx) {
|
|
97
18
|
out[ptr++] = bits >> 16 & 255;
|
|
98
19
|
out[ptr++] = bits >> 8 & 255;
|
|
99
20
|
out[ptr++] = bits & 255;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
21
|
+
}
|
|
22
|
+
bits = bits << 6 | BASE64_MAP.indexOf(input.charAt(idx));
|
|
23
|
+
}
|
|
24
|
+
const tailbits = max % 4 * 6;
|
|
25
|
+
if (tailbits === 0) {
|
|
26
|
+
out[ptr++] = bits >> 16 & 255;
|
|
27
|
+
out[ptr++] = bits >> 8 & 255;
|
|
28
|
+
out[ptr++] = bits & 255;
|
|
29
|
+
} else if (tailbits === 18) {
|
|
30
|
+
out[ptr++] = bits >> 10 & 255;
|
|
31
|
+
out[ptr++] = bits >> 2 & 255;
|
|
32
|
+
} else if (tailbits === 12) out[ptr++] = bits >> 4 & 255;
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
var wa;
|
|
36
|
+
function hasWebAssembly() {
|
|
37
|
+
if (typeof wa !== "undefined") return wa;
|
|
38
|
+
wa = false;
|
|
39
|
+
if (typeof WebAssembly === "undefined") return wa;
|
|
40
|
+
try {
|
|
41
|
+
const bin = new Uint8Array([
|
|
42
|
+
0,
|
|
43
|
+
97,
|
|
44
|
+
115,
|
|
45
|
+
109,
|
|
46
|
+
1,
|
|
47
|
+
0,
|
|
48
|
+
0,
|
|
49
|
+
0,
|
|
50
|
+
1,
|
|
51
|
+
6,
|
|
52
|
+
1,
|
|
53
|
+
96,
|
|
54
|
+
1,
|
|
55
|
+
127,
|
|
56
|
+
1,
|
|
57
|
+
127,
|
|
58
|
+
3,
|
|
59
|
+
2,
|
|
60
|
+
1,
|
|
61
|
+
0,
|
|
62
|
+
5,
|
|
63
|
+
3,
|
|
64
|
+
1,
|
|
65
|
+
0,
|
|
66
|
+
1,
|
|
67
|
+
7,
|
|
68
|
+
8,
|
|
69
|
+
1,
|
|
70
|
+
4,
|
|
71
|
+
116,
|
|
72
|
+
101,
|
|
73
|
+
115,
|
|
74
|
+
116,
|
|
75
|
+
0,
|
|
76
|
+
0,
|
|
77
|
+
10,
|
|
78
|
+
16,
|
|
79
|
+
1,
|
|
80
|
+
14,
|
|
81
|
+
0,
|
|
82
|
+
32,
|
|
83
|
+
0,
|
|
84
|
+
65,
|
|
85
|
+
1,
|
|
86
|
+
54,
|
|
87
|
+
2,
|
|
88
|
+
0,
|
|
89
|
+
32,
|
|
90
|
+
0,
|
|
91
|
+
40,
|
|
92
|
+
2,
|
|
93
|
+
0,
|
|
94
|
+
11
|
|
95
|
+
]);
|
|
96
|
+
const module = new WebAssembly.Module(bin);
|
|
97
|
+
if (new WebAssembly.Instance(module, {}).exports.test(4) !== 0) wa = true;
|
|
173
98
|
return wa;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
function MultiMath(options) {
|
|
185
|
-
if (!(this instanceof MultiMath)) return new MultiMath(options);
|
|
186
|
-
var opts = assign({}, DEFAULT_OPTIONS, options || {});
|
|
99
|
+
} catch (__) {}
|
|
100
|
+
return wa;
|
|
101
|
+
}
|
|
102
|
+
var DEFAULT_OPTIONS = {
|
|
103
|
+
js: true,
|
|
104
|
+
wasm: true
|
|
105
|
+
};
|
|
106
|
+
var MultiMath = class {
|
|
107
|
+
constructor(options) {
|
|
108
|
+
const opts = Object.assign({}, DEFAULT_OPTIONS, options || {});
|
|
187
109
|
this.options = opts;
|
|
188
110
|
this.__cache = {};
|
|
189
111
|
this.__init_promise = null;
|
|
@@ -198,47 +120,45 @@ https://github.com/nodeca/pica
|
|
|
198
120
|
]).buffer)[0] === 1;
|
|
199
121
|
if (!this.options.js && !this.options.wasm) throw new Error("mathlib: at least \"js\" or \"wasm\" should be enabled");
|
|
200
122
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
123
|
+
has_wasm() {
|
|
124
|
+
return hasWebAssembly();
|
|
125
|
+
}
|
|
126
|
+
use(module) {
|
|
127
|
+
this.__modules[module.name] = module;
|
|
128
|
+
if (this.options.wasm && this.has_wasm() && module.wasm_fn) this[module.name] = module.wasm_fn;
|
|
129
|
+
else this[module.name] = module.fn;
|
|
206
130
|
return this;
|
|
207
|
-
}
|
|
208
|
-
|
|
131
|
+
}
|
|
132
|
+
init() {
|
|
209
133
|
if (this.__init_promise) return this.__init_promise;
|
|
210
134
|
if (!this.options.js && this.options.wasm && !this.has_wasm()) return Promise.reject(/* @__PURE__ */ new Error("mathlib: only \"wasm\" was enabled, but it's not supported"));
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
self.__wasm[name] = m;
|
|
135
|
+
this.__init_promise = Promise.all(Object.keys(this.__modules).map((name) => {
|
|
136
|
+
const module = this.__modules[name];
|
|
137
|
+
if (!this.options.wasm || !this.has_wasm() || !module.wasm_fn) return null;
|
|
138
|
+
if (this.__wasm[name]) return null;
|
|
139
|
+
return WebAssembly.compile(base64decode(module.wasm_src)).then((m) => {
|
|
140
|
+
this.__wasm[name] = m;
|
|
218
141
|
});
|
|
219
|
-
})).then(
|
|
220
|
-
return self;
|
|
221
|
-
});
|
|
142
|
+
})).then(() => this);
|
|
222
143
|
return this.__init_promise;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
MultiMath.prototype.__reallocate = function mem_grow_to(bytes) {
|
|
144
|
+
}
|
|
145
|
+
__reallocate(bytes) {
|
|
226
146
|
if (!this.__memory) {
|
|
227
147
|
this.__memory = new WebAssembly.Memory({ initial: Math.ceil(bytes / (64 * 1024)) });
|
|
228
148
|
return this.__memory;
|
|
229
149
|
}
|
|
230
|
-
|
|
150
|
+
const mem_size = this.__memory.buffer.byteLength;
|
|
231
151
|
if (mem_size < bytes) this.__memory.grow(Math.ceil((bytes - mem_size) / (64 * 1024)));
|
|
232
152
|
return this.__memory;
|
|
233
|
-
}
|
|
234
|
-
|
|
153
|
+
}
|
|
154
|
+
__instance(name, memsize, env_extra) {
|
|
235
155
|
if (memsize) this.__reallocate(memsize);
|
|
236
156
|
if (!this.__wasm[name]) {
|
|
237
|
-
|
|
238
|
-
this.__wasm[name] = new WebAssembly.Module(
|
|
157
|
+
const module = this.__modules[name];
|
|
158
|
+
this.__wasm[name] = new WebAssembly.Module(base64decode(module.wasm_src));
|
|
239
159
|
}
|
|
240
160
|
if (!this.__cache[name]) {
|
|
241
|
-
|
|
161
|
+
const env_base = {
|
|
242
162
|
memoryBase: 0,
|
|
243
163
|
memory: this.__memory,
|
|
244
164
|
tableBase: 0,
|
|
@@ -247,100 +167,93 @@ https://github.com/nodeca/pica
|
|
|
247
167
|
element: "anyfunc"
|
|
248
168
|
})
|
|
249
169
|
};
|
|
250
|
-
this.__cache[name] = new WebAssembly.Instance(this.__wasm[name], { env: assign(env_base, env_extra || {}) });
|
|
170
|
+
this.__cache[name] = new WebAssembly.Instance(this.__wasm[name], { env: Object.assign(env_base, env_extra || {}) });
|
|
251
171
|
}
|
|
252
172
|
return this.__cache[name];
|
|
253
|
-
}
|
|
254
|
-
|
|
173
|
+
}
|
|
174
|
+
__align(number, base) {
|
|
255
175
|
base = base || 8;
|
|
256
|
-
|
|
176
|
+
const reminder = number % base;
|
|
257
177
|
return number + (reminder ? base - reminder : 0);
|
|
258
|
-
};
|
|
259
|
-
module.exports = MultiMath;
|
|
260
|
-
}));
|
|
261
|
-
var require_mono16 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
262
|
-
var a0, a1, a2, a3, b1, b2, left_corner, right_corner;
|
|
263
|
-
function gaussCoef(sigma) {
|
|
264
|
-
if (sigma < .5) sigma = .5;
|
|
265
|
-
var a = Math.exp(.726 * .726) / sigma, g1 = Math.exp(-a), g2 = Math.exp(-2 * a), k = (1 - g1) * (1 - g1) / (1 + 2 * a * g1 - g2);
|
|
266
|
-
a0 = k;
|
|
267
|
-
a1 = k * (a - 1) * g1;
|
|
268
|
-
a2 = k * (a + 1) * g1;
|
|
269
|
-
a3 = -k * g2;
|
|
270
|
-
b1 = 2 * g1;
|
|
271
|
-
b2 = -g2;
|
|
272
|
-
left_corner = (a0 + a1) / (1 - b1 - b2);
|
|
273
|
-
right_corner = (a2 + a3) / (1 - b1 - b2);
|
|
274
|
-
return new Float32Array([
|
|
275
|
-
a0,
|
|
276
|
-
a1,
|
|
277
|
-
a2,
|
|
278
|
-
a3,
|
|
279
|
-
b1,
|
|
280
|
-
b2,
|
|
281
|
-
left_corner,
|
|
282
|
-
right_corner
|
|
283
|
-
]);
|
|
284
178
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
179
|
+
};
|
|
180
|
+
function gaussCoef(sigma) {
|
|
181
|
+
if (sigma < .5) sigma = .5;
|
|
182
|
+
const a = Math.exp(.726 * .726) / sigma, g1 = Math.exp(-a), g2 = Math.exp(-2 * a), k = (1 - g1) * (1 - g1) / (1 + 2 * a * g1 - g2);
|
|
183
|
+
const a0 = k;
|
|
184
|
+
const a1 = k * (a - 1) * g1;
|
|
185
|
+
const a2 = k * (a + 1) * g1;
|
|
186
|
+
const a3 = -k * g2;
|
|
187
|
+
const b1 = 2 * g1;
|
|
188
|
+
const b2 = -g2;
|
|
189
|
+
const left_corner = (a0 + a1) / (1 - b1 - b2);
|
|
190
|
+
const right_corner = (a2 + a3) / (1 - b1 - b2);
|
|
191
|
+
return new Float32Array([
|
|
192
|
+
a0,
|
|
193
|
+
a1,
|
|
194
|
+
a2,
|
|
195
|
+
a3,
|
|
196
|
+
b1,
|
|
197
|
+
b2,
|
|
198
|
+
left_corner,
|
|
199
|
+
right_corner
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
202
|
+
function convolveMono16(src, out, line, coeff, width, height) {
|
|
203
|
+
let prev_src, curr_src, curr_out, prev_out, prev_prev_out;
|
|
204
|
+
let src_index, out_index, line_index;
|
|
205
|
+
let i, j;
|
|
206
|
+
let coeff_a0, coeff_a1, coeff_b1, coeff_b2;
|
|
207
|
+
for (i = 0; i < height; i++) {
|
|
208
|
+
src_index = i * width;
|
|
209
|
+
out_index = i;
|
|
210
|
+
line_index = 0;
|
|
211
|
+
prev_src = src[src_index];
|
|
212
|
+
prev_prev_out = prev_src * coeff[6];
|
|
213
|
+
prev_out = prev_prev_out;
|
|
214
|
+
coeff_a0 = coeff[0];
|
|
215
|
+
coeff_a1 = coeff[1];
|
|
216
|
+
coeff_b1 = coeff[4];
|
|
217
|
+
coeff_b2 = coeff[5];
|
|
218
|
+
for (j = 0; j < width; j++) {
|
|
219
|
+
curr_src = src[src_index];
|
|
220
|
+
curr_out = curr_src * coeff_a0 + prev_src * coeff_a1 + prev_out * coeff_b1 + prev_prev_out * coeff_b2;
|
|
221
|
+
prev_prev_out = prev_out;
|
|
222
|
+
prev_out = curr_out;
|
|
223
|
+
prev_src = curr_src;
|
|
224
|
+
line[line_index] = prev_out;
|
|
225
|
+
line_index++;
|
|
226
|
+
src_index++;
|
|
227
|
+
}
|
|
228
|
+
src_index--;
|
|
229
|
+
line_index--;
|
|
230
|
+
out_index += height * (width - 1);
|
|
231
|
+
prev_src = src[src_index];
|
|
232
|
+
prev_prev_out = prev_src * coeff[7];
|
|
233
|
+
prev_out = prev_prev_out;
|
|
234
|
+
curr_src = prev_src;
|
|
235
|
+
coeff_a0 = coeff[2];
|
|
236
|
+
coeff_a1 = coeff[3];
|
|
237
|
+
for (j = width - 1; j >= 0; j--) {
|
|
238
|
+
curr_out = curr_src * coeff_a0 + prev_src * coeff_a1 + prev_out * coeff_b1 + prev_prev_out * coeff_b2;
|
|
239
|
+
prev_prev_out = prev_out;
|
|
240
|
+
prev_out = curr_out;
|
|
241
|
+
prev_src = curr_src;
|
|
242
|
+
curr_src = src[src_index];
|
|
243
|
+
out[out_index] = line[line_index] + prev_out;
|
|
311
244
|
src_index--;
|
|
312
245
|
line_index--;
|
|
313
|
-
out_index
|
|
314
|
-
prev_src = src[src_index];
|
|
315
|
-
prev_prev_out = prev_src * coeff[7];
|
|
316
|
-
prev_out = prev_prev_out;
|
|
317
|
-
curr_src = prev_src;
|
|
318
|
-
coeff_a0 = coeff[2];
|
|
319
|
-
coeff_a1 = coeff[3];
|
|
320
|
-
for (j = width - 1; j >= 0; j--) {
|
|
321
|
-
curr_out = curr_src * coeff_a0 + prev_src * coeff_a1 + prev_out * coeff_b1 + prev_prev_out * coeff_b2;
|
|
322
|
-
prev_prev_out = prev_out;
|
|
323
|
-
prev_out = curr_out;
|
|
324
|
-
prev_src = curr_src;
|
|
325
|
-
curr_src = src[src_index];
|
|
326
|
-
out[out_index] = line[line_index] + prev_out;
|
|
327
|
-
src_index--;
|
|
328
|
-
line_index--;
|
|
329
|
-
out_index -= height;
|
|
330
|
-
}
|
|
246
|
+
out_index -= height;
|
|
331
247
|
}
|
|
332
248
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}));
|
|
342
|
-
var import_multimath = /* @__PURE__ */ __toESM(require_multimath());
|
|
343
|
-
var import_mono16 = /* @__PURE__ */ __toESM(require_mono16());
|
|
249
|
+
}
|
|
250
|
+
function blurMono16(src, width, height, radius) {
|
|
251
|
+
if (!radius) return;
|
|
252
|
+
const out = new Uint16Array(src.length), tmp_line = new Float32Array(Math.max(width, height));
|
|
253
|
+
const coeff = gaussCoef(radius);
|
|
254
|
+
convolveMono16(src, out, tmp_line, coeff, width, height, radius);
|
|
255
|
+
convolveMono16(out, src, tmp_line, coeff, height, width, radius);
|
|
256
|
+
}
|
|
344
257
|
function hsv_v16(img, width, height) {
|
|
345
258
|
const size = width * height;
|
|
346
259
|
const out = new Uint16Array(size);
|
|
@@ -361,7 +274,7 @@ https://github.com/nodeca/pica
|
|
|
361
274
|
if (radius > 2) radius = 2;
|
|
362
275
|
const brightness = hsv_v16(img, width, height);
|
|
363
276
|
const blured = new Uint16Array(brightness);
|
|
364
|
-
(
|
|
277
|
+
blurMono16(blured, width, height, radius);
|
|
365
278
|
const amountFp = amount / 100 * 4096 + .5 | 0;
|
|
366
279
|
const thresholdFp = threshold << 8;
|
|
367
280
|
const size = width * height;
|
|
@@ -788,7 +701,7 @@ https://github.com/nodeca/pica
|
|
|
788
701
|
wasm_fn: resize_wasm,
|
|
789
702
|
wasm_src: "AGFzbQEAAAAADAZkeWxpbmsAAAAAAAEYA2AGf39/f39/AGAAAGAIf39/f39/f38AAg8BA2VudgZtZW1vcnkCAAADBwYBAAAAAAIGBgF/AEEACweUAQgRX193YXNtX2NhbGxfY3RvcnMAAAtjb252b2x2ZUhvcgABDGNvbnZvbHZlVmVydAACEmNvbnZvbHZlSG9yV2l0aFByZQADE2NvbnZvbHZlVmVydFdpdGhQcmUABApjb252b2x2ZUhWAAUMX19kc29faGFuZGxlAwAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAKyA4GAwABC4wDARB/AkAgA0UNACAERQ0AIANBAnQhFQNAQQAhE0EAIQsDQCALQQJqIQcCfyALQQF0IAVqIgYuAQIiC0UEQEEAIQhBACEGQQAhCUEAIQogBwwBCyASIAYuAQBqIQhBACEJQQAhCiALIRRBACEOIAchBkEAIQ8DQCAFIAZBAXRqLgEAIhAgACAIQQJ0aigCACIRQRh2bCAPaiEPIBFB/wFxIBBsIAlqIQkgEUEQdkH/AXEgEGwgDmohDiARQQh2Qf8BcSAQbCAKaiEKIAhBAWohCCAGQQFqIQYgFEEBayIUDQALIAlBB3UhCCAKQQd1IQYgDkEHdSEJIA9BB3UhCiAHIAtqCyELIAEgDEEBdCIHaiAIQQAgCEEAShs7AQAgASAHQQJyaiAGQQAgBkEAShs7AQAgASAHQQRyaiAJQQAgCUEAShs7AQAgASAHQQZyaiAKQQAgCkEAShs7AQAgDCAVaiEMIBNBAWoiEyAERw0ACyANQQFqIg0gAmwhEiANQQJ0IQwgAyANRw0ACwsL2gMBD38CQCADRQ0AIARFDQAgAkECdCEUA0AgCyEMQQAhE0EAIQIDQCACQQJqIQYCfyACQQF0IAVqIgcuAQIiAkUEQEEAIQhBACEHQQAhCkEAIQkgBgwBCyAHLgEAQQJ0IBJqIQhBACEJIAIhCkEAIQ0gBiEHQQAhDkEAIQ8DQCAFIAdBAXRqLgEAIhAgACAIQQF0IhFqLwEAbCAJaiEJIAAgEUEGcmovAQAgEGwgDmohDiAAIBFBBHJqLwEAIBBsIA9qIQ8gACARQQJyai8BACAQbCANaiENIAhBBGohCCAHQQFqIQcgCkEBayIKDQALIAlBB3UhCCANQQd1IQcgDkEHdSEKIA9BB3UhCSACIAZqCyECIAEgDEECdGogB0GAQGtBDnUiBkH/ASAGQf8BSBsiBkEAIAZBAEobQQh0QYD+A3EgCUGAQGtBDnUiBkH/ASAGQf8BSBsiBkEAIAZBAEobQRB0QYCA/AdxIApBgEBrQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG0EYdHJyIAhBgEBrQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG3I2AgAgAyAMaiEMIBNBAWoiEyAERw0ACyAUIAtBAWoiC2whEiADIAtHDQALCwuSAwEQfwJAIANFDQAgBEUNACADQQJ0IRUDQEEAIRNBACEGA0AgBkECaiEIAn8gBkEBdCAFaiIGLgECIgdFBEBBACEJQQAhDEEAIQ1BACEOIAgMAQsgEiAGLgEAaiEJQQAhDkEAIQ1BACEMIAchFEEAIQ8gCCEGA0AgBSAGQQF0ai4BACAAIAlBAnRqKAIAIhBBGHZsIhEgD2ohDyARIBBBEHZB/wFxbCAMaiEMIBEgEEEIdkH/AXFsIA1qIQ0gESAQQf8BcWwgDmohDiAJQQFqIQkgBkEBaiEGIBRBAWsiFA0ACyAPQQd1IQkgByAIagshBiABIApBAXQiCGogDkH/AW1BB3UiB0EAIAdBAEobOwEAIAEgCEECcmogDUH/AW1BB3UiB0EAIAdBAEobOwEAIAEgCEEEcmogDEH/AW1BB3UiB0EAIAdBAEobOwEAIAEgCEEGcmogCUEAIAlBAEobOwEAIAogFWohCiATQQFqIhMgBEcNAAsgC0EBaiILIAJsIRIgC0ECdCEKIAMgC0cNAAsLC4IEAQ9/AkAgA0UNACAERQ0AIAJBAnQhFANAIAshDEEAIRJBACEHA0AgB0ECaiEKAn8gB0EBdCAFaiICLgECIhNFBEBBACEIQQAhCUEAIQYgCiEHQQAMAQsgAi4BAEECdCARaiEJQQAhByATIQJBACENIAohBkEAIQ5BACEPA0AgBSAGQQF0ai4BACIIIAAgCUEBdCIQai8BAGwgB2ohByAAIBBBBnJqLwEAIAhsIA5qIQ4gACAQQQRyai8BACAIbCAPaiEPIAAgEEECcmovAQAgCGwgDWohDSAJQQRqIQkgBkEBaiEGIAJBAWsiAg0ACyAHQQd1IQggDUEHdSEJIA9BB3UhBiAKIBNqIQcgDkEHdQtBgEBrQQ51IgJB/wEgAkH/AUgbIgJBACACQQBKGyIKQf8BcQRAIAlB/wFsIAJtIQkgCEH/AWwgAm0hCCAGQf8BbCACbSEGCyABIAxBAnRqIAlBgEBrQQ51IgJB/wEgAkH/AUgbIgJBACACQQBKG0EIdEGA/gNxIAZBgEBrQQ51IgJB/wEgAkH/AUgbIgJBACACQQBKG0EQdEGAgPwHcSAKQRh0ciAIQYBAa0EOdSICQf8BIAJB/wFIGyICQQAgAkEAShtycjYCACADIAxqIQwgEkEBaiISIARHDQALIBQgC0EBaiILbCERIAMgC0cNAAsLC0AAIAcEQEEAIAIgAyAEIAUgABADIAJBACAEIAUgBiABEAQPC0EAIAIgAyAEIAUgABABIAJBACAEIAUgBiABEAIL"
|
|
790
703
|
};
|
|
791
|
-
var MathLib = class extends
|
|
704
|
+
var MathLib = class extends MultiMath {
|
|
792
705
|
constructor(requested_features) {
|
|
793
706
|
const __requested_features = requested_features || [];
|
|
794
707
|
const features = {
|
|
@@ -1055,13 +968,14 @@ https://github.com/nodeca/pica
|
|
|
1055
968
|
};
|
|
1056
969
|
var checked = false;
|
|
1057
970
|
var checking = null;
|
|
971
|
+
var ctxOpts$1 = { willReadFrequently: true };
|
|
1058
972
|
function check_canvas() {
|
|
1059
973
|
if (typeof document === "undefined" || !document.createElement) return false;
|
|
1060
974
|
try {
|
|
1061
975
|
const canvas = document.createElement("canvas");
|
|
1062
976
|
canvas.width = 2;
|
|
1063
977
|
canvas.height = 1;
|
|
1064
|
-
const ctx = canvas.getContext("2d");
|
|
978
|
+
const ctx = canvas.getContext("2d", ctxOpts$1);
|
|
1065
979
|
let d = ctx.createImageData(2, 1);
|
|
1066
980
|
d.data[0] = 12;
|
|
1067
981
|
d.data[1] = 23;
|
|
@@ -1081,7 +995,7 @@ https://github.com/nodeca/pica
|
|
|
1081
995
|
function check_offscreen_canvas() {
|
|
1082
996
|
if (typeof OffscreenCanvas === "undefined") return false;
|
|
1083
997
|
try {
|
|
1084
|
-
const ctx = new OffscreenCanvas(2, 1).getContext("2d");
|
|
998
|
+
const ctx = new OffscreenCanvas(2, 1).getContext("2d", ctxOpts$1);
|
|
1085
999
|
let d = ctx.createImageData(2, 1);
|
|
1086
1000
|
d.data[0] = 12;
|
|
1087
1001
|
d.data[1] = 23;
|
|
@@ -1120,7 +1034,7 @@ https://github.com/nodeca/pica
|
|
|
1120
1034
|
return createImageBitmap(new Blob([bytes], { type: "image/jpeg" })).then((bitmap) => {
|
|
1121
1035
|
const canvas = new OffscreenCanvas(1, 1);
|
|
1122
1036
|
try {
|
|
1123
|
-
const ctx = canvas.getContext("2d");
|
|
1037
|
+
const ctx = canvas.getContext("2d", ctxOpts$1);
|
|
1124
1038
|
ctx.drawImage(bitmap, 1, 1, 1, 1, 0, 0, 1, 1);
|
|
1125
1039
|
return ctx.getImageData(0, 0, 1, 1).data[0] < 240;
|
|
1126
1040
|
} finally {
|
|
@@ -1135,7 +1049,7 @@ https://github.com/nodeca/pica
|
|
|
1135
1049
|
const canvas = document.createElement("canvas");
|
|
1136
1050
|
canvas.width = 1;
|
|
1137
1051
|
canvas.height = 1;
|
|
1138
|
-
const ctx = canvas.getContext("2d");
|
|
1052
|
+
const ctx = canvas.getContext("2d", ctxOpts$1);
|
|
1139
1053
|
ctx.drawImage(image, 1, 1, 1, 1, 0, 0, 1, 1);
|
|
1140
1054
|
resolve(ctx.getImageData(0, 0, 1, 1).data[0] < 240);
|
|
1141
1055
|
} catch (__) {
|
|
@@ -1167,7 +1081,7 @@ https://github.com/nodeca/pica
|
|
|
1167
1081
|
canvas.height = 1;
|
|
1168
1082
|
}
|
|
1169
1083
|
try {
|
|
1170
|
-
const ctx = canvas.getContext("2d");
|
|
1084
|
+
const ctx = canvas.getContext("2d", ctxOpts$1);
|
|
1171
1085
|
ctx.drawImage(bitmap, 0, 0);
|
|
1172
1086
|
return bitmap.width !== 1 || bitmap.height !== 1 || ctx.getImageData(0, 0, 1, 1).data[0] < 240;
|
|
1173
1087
|
} finally {
|
|
@@ -1192,7 +1106,7 @@ https://github.com/nodeca/pica
|
|
|
1192
1106
|
canvas.height = SRC_SIZE;
|
|
1193
1107
|
} else if (features.offscreen_canvas || check_offscreen_canvas()) {
|
|
1194
1108
|
canvas = new OffscreenCanvas(SRC_SIZE, SRC_SIZE);
|
|
1195
|
-
canvas.getContext("2d").clearRect(0, 0, SRC_SIZE, SRC_SIZE);
|
|
1109
|
+
canvas.getContext("2d", ctxOpts$1).clearRect(0, 0, SRC_SIZE, SRC_SIZE);
|
|
1196
1110
|
} else return false;
|
|
1197
1111
|
return createImageBitmap(canvas, 0, 0, SRC_SIZE, SRC_SIZE, {
|
|
1198
1112
|
resizeWidth: DST_SIZE,
|
|
@@ -1279,6 +1193,7 @@ https://github.com/nodeca/pica
|
|
|
1279
1193
|
unsharpRadius: 0,
|
|
1280
1194
|
unsharpThreshold: 0
|
|
1281
1195
|
};
|
|
1196
|
+
var ctxOpts = { willReadFrequently: true };
|
|
1282
1197
|
var Pica = class {
|
|
1283
1198
|
constructor(options) {
|
|
1284
1199
|
_defineProperty(this, "options", void 0);
|
|
@@ -1423,7 +1338,7 @@ https://github.com/nodeca/pica
|
|
|
1423
1338
|
if (this.resize_features.ww && this.capabilities.ww_offscreen_canvas) {
|
|
1424
1339
|
this.debug("Create tile imageBitmap");
|
|
1425
1340
|
const tileCanvas = this.createCanvas(tile.width, tile.height, { preferOffscreen: true });
|
|
1426
|
-
tileCanvas.getContext("2d").drawImage(stageEnv.srcImageBitmap || from, tile.x, tile.y, tile.width, tile.height, 0, 0, tile.width, tile.height);
|
|
1341
|
+
tileCanvas.getContext("2d", ctxOpts).drawImage(stageEnv.srcImageBitmap || from, tile.x, tile.y, tile.width, tile.height, 0, 0, tile.width, tile.height);
|
|
1427
1342
|
if (!("transferToImageBitmap" in tileCanvas)) throw new Error("Pica: offscreen canvas is not available for worker transfer");
|
|
1428
1343
|
return Object.assign({}, extractTo, {
|
|
1429
1344
|
kind: "bitmap",
|
|
@@ -1431,7 +1346,7 @@ https://github.com/nodeca/pica
|
|
|
1431
1346
|
});
|
|
1432
1347
|
}
|
|
1433
1348
|
if (isCanvas(from)) {
|
|
1434
|
-
if (!stageEnv.srcCtx) stageEnv.srcCtx = from.getContext("2d");
|
|
1349
|
+
if (!stageEnv.srcCtx) stageEnv.srcCtx = from.getContext("2d", ctxOpts);
|
|
1435
1350
|
this.debug("Get tile pixel data");
|
|
1436
1351
|
return Object.assign({}, extractTo, {
|
|
1437
1352
|
kind: "array",
|
|
@@ -1440,7 +1355,7 @@ https://github.com/nodeca/pica
|
|
|
1440
1355
|
}
|
|
1441
1356
|
this.debug("Draw tile imageBitmap/image to temporary canvas");
|
|
1442
1357
|
const tmpCanvas = this.createCanvas(tile.width, tile.height, { preferOffscreen: true });
|
|
1443
|
-
const tmpCtx = tmpCanvas.getContext("2d");
|
|
1358
|
+
const tmpCtx = tmpCanvas.getContext("2d", ctxOpts);
|
|
1444
1359
|
tmpCtx.globalCompositeOperation = "copy";
|
|
1445
1360
|
tmpCtx.drawImage(stageEnv.srcImageBitmap || from, tile.x, tile.y, tile.width, tile.height, 0, 0, tile.width, tile.height);
|
|
1446
1361
|
this.debug("Get tile pixel data");
|
|
@@ -1497,7 +1412,7 @@ https://github.com/nodeca/pica
|
|
|
1497
1412
|
return _this3.__landTileData(tile, result, stageEnv);
|
|
1498
1413
|
}));
|
|
1499
1414
|
yield Promise.resolve();
|
|
1500
|
-
stageEnv.toCtx = to.getContext("2d");
|
|
1415
|
+
stageEnv.toCtx = to.getContext("2d", ctxOpts);
|
|
1501
1416
|
if (isCanvas(from)) {} else if (isImageBitmap(from)) {
|
|
1502
1417
|
stageEnv.srcImageBitmap = from;
|
|
1503
1418
|
stageEnv.isImageBitmapReused = true;
|
|
@@ -1577,7 +1492,7 @@ https://github.com/nodeca/pica
|
|
|
1577
1492
|
var _this5 = this;
|
|
1578
1493
|
return _asyncToGenerator(function* () {
|
|
1579
1494
|
var _utils$filter_to_cib_;
|
|
1580
|
-
let toCtx = to.getContext("2d");
|
|
1495
|
+
let toCtx = to.getContext("2d", ctxOpts);
|
|
1581
1496
|
_this5.debug("Resize via createImageBitmap()");
|
|
1582
1497
|
const imageBitmap = yield createImageBitmap(from, {
|
|
1583
1498
|
resizeWidth: resizeParams.toWidth,
|
|
@@ -1594,7 +1509,7 @@ https://github.com/nodeca/pica
|
|
|
1594
1509
|
}
|
|
1595
1510
|
_this5.debug("Unsharp result");
|
|
1596
1511
|
let tmpCanvas = _this5.createCanvas(resizeParams.toWidth, resizeParams.toHeight);
|
|
1597
|
-
let tmpCtx = tmpCanvas.getContext("2d");
|
|
1512
|
+
let tmpCtx = tmpCanvas.getContext("2d", ctxOpts);
|
|
1598
1513
|
tmpCtx.drawImage(imageBitmap, 0, 0);
|
|
1599
1514
|
imageBitmap.close();
|
|
1600
1515
|
let iData = tmpCtx.getImageData(0, 0, resizeParams.toWidth, resizeParams.toHeight);
|
|
@@ -1645,7 +1560,7 @@ https://github.com/nodeca/pica
|
|
|
1645
1560
|
if (ctx.canceled) return ctx.cancelToken;
|
|
1646
1561
|
if (_this6.capabilities.bug_image_bitmap_orientation_region && (isImage(from) || isImageBitmap(from))) {
|
|
1647
1562
|
const tmpCanvas = _this6.createCanvas(resizeParams.width, resizeParams.height);
|
|
1648
|
-
tmpCanvas.getContext("2d").drawImage(from, 0, 0);
|
|
1563
|
+
tmpCanvas.getContext("2d", ctxOpts).drawImage(from, 0, 0);
|
|
1649
1564
|
from = tmpCanvas;
|
|
1650
1565
|
}
|
|
1651
1566
|
if (_this6.resize_features.cib) {
|