@namelivia/vue-components 1.0.2 → 1.1.1
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/dist/index.esm.js +3774 -116
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3796 -137
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
- package/src/ResizeImageUpload.vue +60 -0
- package/src/index.js +1 -0
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineComponent, openBlock, createElementBlock, toDisplayString, createStaticVNode, createElementVNode, renderSlot, withDirectives, Fragment, renderList, vModelSelect, createCommentVNode, normalizeClass, resolveComponent, createBlock, Transition, withCtx, createVNode } from 'vue';
|
|
2
2
|
|
|
3
|
-
var script$
|
|
3
|
+
var script$r = defineComponent({
|
|
4
4
|
name: 'SectionTitle',
|
|
5
5
|
props: {
|
|
6
6
|
text: {
|
|
@@ -12,14 +12,14 @@ var script$q = defineComponent({
|
|
|
12
12
|
|
|
13
13
|
const _hoisted_1$n = { class: "text-center text-6xl leading-relaxed" };
|
|
14
14
|
|
|
15
|
-
function render$
|
|
15
|
+
function render$r(_ctx, _cache) {
|
|
16
16
|
return (openBlock(), createElementBlock("h1", _hoisted_1$n, toDisplayString(_ctx.text), 1 /* TEXT */))
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
script$
|
|
20
|
-
script$
|
|
19
|
+
script$r.render = render$r;
|
|
20
|
+
script$r.__file = "src/SectionTitle.vue";
|
|
21
21
|
|
|
22
|
-
var script$
|
|
22
|
+
var script$q = defineComponent({
|
|
23
23
|
name: "Loading",
|
|
24
24
|
props: {
|
|
25
25
|
text: String,
|
|
@@ -31,14 +31,14 @@ const _hoisted_3$9 = [
|
|
|
31
31
|
_hoisted_1$m
|
|
32
32
|
];
|
|
33
33
|
|
|
34
|
-
function render$
|
|
34
|
+
function render$q(_ctx, _cache) {
|
|
35
35
|
return (openBlock(), createElementBlock("div", null, _hoisted_3$9))
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
script$
|
|
39
|
-
script$
|
|
38
|
+
script$q.render = render$q;
|
|
39
|
+
script$q.__file = "src/Loading.vue";
|
|
40
40
|
|
|
41
|
-
var script$
|
|
41
|
+
var script$p = defineComponent({
|
|
42
42
|
name: "ResetButton",
|
|
43
43
|
props: {
|
|
44
44
|
text: String,
|
|
@@ -50,14 +50,14 @@ const _hoisted_1$l = {
|
|
|
50
50
|
type: "reset"
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
function render$
|
|
53
|
+
function render$p(_ctx, _cache) {
|
|
54
54
|
return (openBlock(), createElementBlock("button", _hoisted_1$l, toDisplayString(_ctx.text), 1 /* TEXT */))
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
script$
|
|
58
|
-
script$
|
|
57
|
+
script$p.render = render$p;
|
|
58
|
+
script$p.__file = "src/ResetButton.vue";
|
|
59
59
|
|
|
60
|
-
var script$
|
|
60
|
+
var script$o = defineComponent({
|
|
61
61
|
name: "SubmitButton",
|
|
62
62
|
props: {
|
|
63
63
|
text: String,
|
|
@@ -69,14 +69,14 @@ const _hoisted_1$k = {
|
|
|
69
69
|
type: "submit"
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
function render$
|
|
72
|
+
function render$o(_ctx, _cache) {
|
|
73
73
|
return (openBlock(), createElementBlock("button", _hoisted_1$k, toDisplayString(_ctx.text), 1 /* TEXT */))
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
script$
|
|
77
|
-
script$
|
|
76
|
+
script$o.render = render$o;
|
|
77
|
+
script$o.__file = "src/SubmitButton.vue";
|
|
78
78
|
|
|
79
|
-
var script$
|
|
79
|
+
var script$n = defineComponent({
|
|
80
80
|
name: "RegularButton",
|
|
81
81
|
props: {
|
|
82
82
|
text: String,
|
|
@@ -89,17 +89,17 @@ var script$m = defineComponent({
|
|
|
89
89
|
}
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
-
function render$
|
|
92
|
+
function render$n(_ctx, _cache) {
|
|
93
93
|
return (openBlock(), createElementBlock("button", {
|
|
94
94
|
class: "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded",
|
|
95
95
|
onClick: _cache[0] || (_cache[0] = (...args) => (_ctx.onClick && _ctx.onClick(...args)))
|
|
96
96
|
}, toDisplayString(_ctx.text), 1 /* TEXT */))
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
script$
|
|
100
|
-
script$
|
|
99
|
+
script$n.render = render$n;
|
|
100
|
+
script$n.__file = "src/RegularButton.vue";
|
|
101
101
|
|
|
102
|
-
var script$
|
|
102
|
+
var script$m = defineComponent({
|
|
103
103
|
name: "SecondaryButton",
|
|
104
104
|
props: {
|
|
105
105
|
text: String,
|
|
@@ -112,17 +112,17 @@ var script$l = defineComponent({
|
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
-
function render$
|
|
115
|
+
function render$m(_ctx, _cache) {
|
|
116
116
|
return (openBlock(), createElementBlock("button", {
|
|
117
117
|
class: "bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded",
|
|
118
118
|
onClick: _cache[0] || (_cache[0] = (...args) => (_ctx.onClick && _ctx.onClick(...args)))
|
|
119
119
|
}, toDisplayString(_ctx.text), 1 /* TEXT */))
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
script$
|
|
123
|
-
script$
|
|
122
|
+
script$m.render = render$m;
|
|
123
|
+
script$m.__file = "src/SecondaryButton.vue";
|
|
124
124
|
|
|
125
|
-
var script$
|
|
125
|
+
var script$l = defineComponent({
|
|
126
126
|
name: "DangerButton",
|
|
127
127
|
props: {
|
|
128
128
|
text: String,
|
|
@@ -135,24 +135,24 @@ var script$k = defineComponent({
|
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
-
function render$
|
|
138
|
+
function render$l(_ctx, _cache) {
|
|
139
139
|
return (openBlock(), createElementBlock("button", {
|
|
140
140
|
class: "bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded",
|
|
141
141
|
onClick: _cache[0] || (_cache[0] = (...args) => (_ctx.onClick && _ctx.onClick(...args)))
|
|
142
142
|
}, toDisplayString(_ctx.text), 1 /* TEXT */))
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
script$
|
|
146
|
-
script$
|
|
145
|
+
script$l.render = render$l;
|
|
146
|
+
script$l.__file = "src/DangerButton.vue";
|
|
147
147
|
|
|
148
|
-
var script$
|
|
148
|
+
var script$k = defineComponent({
|
|
149
149
|
name: "Card"
|
|
150
150
|
});
|
|
151
151
|
|
|
152
152
|
const _hoisted_1$j = { class: "m-8" };
|
|
153
153
|
const _hoisted_2$d = { class: "max-w-sm rounded overflow-hidden shadow-lg" };
|
|
154
154
|
|
|
155
|
-
function render$
|
|
155
|
+
function render$k(_ctx, _cache) {
|
|
156
156
|
return (openBlock(), createElementBlock("div", _hoisted_1$j, [
|
|
157
157
|
createElementVNode("div", _hoisted_2$d, [
|
|
158
158
|
renderSlot(_ctx.$slots, "default")
|
|
@@ -160,10 +160,10 @@ function render$j(_ctx, _cache) {
|
|
|
160
160
|
]))
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
script$
|
|
164
|
-
script$
|
|
163
|
+
script$k.render = render$k;
|
|
164
|
+
script$k.__file = "src/Card.vue";
|
|
165
165
|
|
|
166
|
-
var script$
|
|
166
|
+
var script$j = defineComponent({
|
|
167
167
|
name: "CardImage",
|
|
168
168
|
props: {
|
|
169
169
|
src: String,
|
|
@@ -187,7 +187,7 @@ var script$i = defineComponent({
|
|
|
187
187
|
|
|
188
188
|
const _hoisted_1$i = ["src", "alt"];
|
|
189
189
|
|
|
190
|
-
function render$
|
|
190
|
+
function render$j(_ctx, _cache) {
|
|
191
191
|
return (openBlock(), createElementBlock("img", {
|
|
192
192
|
class: "w-full",
|
|
193
193
|
src: _ctx.src,
|
|
@@ -196,10 +196,10 @@ function render$i(_ctx, _cache) {
|
|
|
196
196
|
}, null, 8 /* PROPS */, _hoisted_1$i))
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
script$
|
|
200
|
-
script$
|
|
199
|
+
script$j.render = render$j;
|
|
200
|
+
script$j.__file = "src/CardImage.vue";
|
|
201
201
|
|
|
202
|
-
var script$
|
|
202
|
+
var script$i = defineComponent({
|
|
203
203
|
name: "CardBody",
|
|
204
204
|
props: {
|
|
205
205
|
title: String,
|
|
@@ -210,7 +210,7 @@ const _hoisted_1$h = { class: "px-6 py-4" };
|
|
|
210
210
|
const _hoisted_2$c = { class: "font-bold text-xl mb-2" };
|
|
211
211
|
const _hoisted_3$8 = { class: "text-gray-700 text-base" };
|
|
212
212
|
|
|
213
|
-
function render$
|
|
213
|
+
function render$i(_ctx, _cache) {
|
|
214
214
|
return (openBlock(), createElementBlock("div", _hoisted_1$h, [
|
|
215
215
|
createElementVNode("div", _hoisted_2$c, toDisplayString(_ctx.title), 1 /* TEXT */),
|
|
216
216
|
createElementVNode("p", _hoisted_3$8, [
|
|
@@ -219,10 +219,10 @@ function render$h(_ctx, _cache) {
|
|
|
219
219
|
]))
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
script$
|
|
223
|
-
script$
|
|
222
|
+
script$i.render = render$i;
|
|
223
|
+
script$i.__file = "src/CardBody.vue";
|
|
224
224
|
|
|
225
|
-
var script$
|
|
225
|
+
var script$h = defineComponent({
|
|
226
226
|
name: "Selector",
|
|
227
227
|
props: {
|
|
228
228
|
id: {
|
|
@@ -263,7 +263,7 @@ const _hoisted_6 = /*#__PURE__*/createElementVNode("div", { class: "pointer-even
|
|
|
263
263
|
])
|
|
264
264
|
], -1 /* HOISTED */);
|
|
265
265
|
|
|
266
|
-
function render$
|
|
266
|
+
function render$h(_ctx, _cache) {
|
|
267
267
|
return (openBlock(), createElementBlock("div", _hoisted_1$g, [
|
|
268
268
|
createElementVNode("label", {
|
|
269
269
|
class: "block text-gray-700 text-sm font-bold mb-2",
|
|
@@ -291,10 +291,10 @@ function render$g(_ctx, _cache) {
|
|
|
291
291
|
]))
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
script$
|
|
295
|
-
script$
|
|
294
|
+
script$h.render = render$h;
|
|
295
|
+
script$h.__file = "src/Selector.vue";
|
|
296
296
|
|
|
297
|
-
var script$
|
|
297
|
+
var script$g = defineComponent({
|
|
298
298
|
name: "TextInput",
|
|
299
299
|
props: {
|
|
300
300
|
id: {
|
|
@@ -326,7 +326,7 @@ const _hoisted_1$f = { class: "mb-4" };
|
|
|
326
326
|
const _hoisted_2$a = ["for"];
|
|
327
327
|
const _hoisted_3$6 = ["id", "name", "required", "placeholder", "value"];
|
|
328
328
|
|
|
329
|
-
function render$
|
|
329
|
+
function render$g(_ctx, _cache) {
|
|
330
330
|
return (openBlock(), createElementBlock("div", _hoisted_1$f, [
|
|
331
331
|
createElementVNode("label", {
|
|
332
332
|
class: "block text-gray-700 text-sm font-bold mb-2",
|
|
@@ -345,10 +345,10 @@ function render$f(_ctx, _cache) {
|
|
|
345
345
|
]))
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
script$
|
|
349
|
-
script$
|
|
348
|
+
script$g.render = render$g;
|
|
349
|
+
script$g.__file = "src/TextInput.vue";
|
|
350
350
|
|
|
351
|
-
var script$
|
|
351
|
+
var script$f = defineComponent({
|
|
352
352
|
name: "CheckBoxInput",
|
|
353
353
|
props: {
|
|
354
354
|
id: {
|
|
@@ -378,7 +378,7 @@ var script$e = defineComponent({
|
|
|
378
378
|
const _hoisted_1$e = { class: "mb-4" };
|
|
379
379
|
const _hoisted_2$9 = ["id", "name", "required", "value"];
|
|
380
380
|
|
|
381
|
-
function render$
|
|
381
|
+
function render$f(_ctx, _cache) {
|
|
382
382
|
return (openBlock(), createElementBlock("div", _hoisted_1$e, [
|
|
383
383
|
createElementVNode("input", {
|
|
384
384
|
id: _ctx.id,
|
|
@@ -394,10 +394,10 @@ function render$e(_ctx, _cache) {
|
|
|
394
394
|
]))
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
script$
|
|
398
|
-
script$
|
|
397
|
+
script$f.render = render$f;
|
|
398
|
+
script$f.__file = "src/CheckBoxInput.vue";
|
|
399
399
|
|
|
400
|
-
var script$
|
|
400
|
+
var script$e = defineComponent({
|
|
401
401
|
name: "NumberInput",
|
|
402
402
|
props: {
|
|
403
403
|
id: {
|
|
@@ -435,7 +435,7 @@ const _hoisted_1$d = { class: "mb-4" };
|
|
|
435
435
|
const _hoisted_2$8 = ["for"];
|
|
436
436
|
const _hoisted_3$5 = ["id", "name", "required", "placeholder", "value", "min", "step"];
|
|
437
437
|
|
|
438
|
-
function render$
|
|
438
|
+
function render$e(_ctx, _cache) {
|
|
439
439
|
return (openBlock(), createElementBlock("div", _hoisted_1$d, [
|
|
440
440
|
createElementVNode("label", {
|
|
441
441
|
class: "block text-gray-700 text-sm font-bold mb-2",
|
|
@@ -456,10 +456,10 @@ function render$d(_ctx, _cache) {
|
|
|
456
456
|
]))
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
-
script$
|
|
460
|
-
script$
|
|
459
|
+
script$e.render = render$e;
|
|
460
|
+
script$e.__file = "src/NumberInput.vue";
|
|
461
461
|
|
|
462
|
-
var script$
|
|
462
|
+
var script$d = defineComponent({
|
|
463
463
|
name: "ImageInput",
|
|
464
464
|
props: {
|
|
465
465
|
id: {
|
|
@@ -493,7 +493,7 @@ const _hoisted_1$c = { class: "mb-4" };
|
|
|
493
493
|
const _hoisted_2$7 = ["for"];
|
|
494
494
|
const _hoisted_3$4 = ["id", "name", "required", "placeholder", "value", "drop-placeholder"];
|
|
495
495
|
|
|
496
|
-
function render$
|
|
496
|
+
function render$d(_ctx, _cache, $props, $setup, $data, $options) {
|
|
497
497
|
return (openBlock(), createElementBlock("div", _hoisted_1$c, [
|
|
498
498
|
createElementVNode("label", {
|
|
499
499
|
class: "block text-gray-700 text-sm font-bold mb-2",
|
|
@@ -514,40 +514,40 @@ function render$c(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
514
514
|
]))
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
-
script$
|
|
518
|
-
script$
|
|
517
|
+
script$d.render = render$d;
|
|
518
|
+
script$d.__file = "src/ImageInput.vue";
|
|
519
519
|
|
|
520
|
-
var script$
|
|
520
|
+
var script$c = defineComponent({
|
|
521
521
|
name: "CardGrid"
|
|
522
522
|
});
|
|
523
523
|
|
|
524
524
|
const _hoisted_1$b = { class: "flex flex-wrap lg:justify-between justify-center align-content:center" };
|
|
525
525
|
|
|
526
|
-
function render$
|
|
526
|
+
function render$c(_ctx, _cache) {
|
|
527
527
|
return (openBlock(), createElementBlock("div", _hoisted_1$b, [
|
|
528
528
|
renderSlot(_ctx.$slots, "default")
|
|
529
529
|
]))
|
|
530
530
|
}
|
|
531
531
|
|
|
532
|
-
script$
|
|
533
|
-
script$
|
|
532
|
+
script$c.render = render$c;
|
|
533
|
+
script$c.__file = "src/CardGrid.vue";
|
|
534
534
|
|
|
535
|
-
var script$
|
|
535
|
+
var script$b = defineComponent({
|
|
536
536
|
name: "Container"
|
|
537
537
|
});
|
|
538
538
|
|
|
539
539
|
const _hoisted_1$a = { class: "container mx-auto" };
|
|
540
540
|
|
|
541
|
-
function render$
|
|
541
|
+
function render$b(_ctx, _cache) {
|
|
542
542
|
return (openBlock(), createElementBlock("div", _hoisted_1$a, [
|
|
543
543
|
renderSlot(_ctx.$slots, "default")
|
|
544
544
|
]))
|
|
545
545
|
}
|
|
546
546
|
|
|
547
|
-
script$
|
|
548
|
-
script$
|
|
547
|
+
script$b.render = render$b;
|
|
548
|
+
script$b.__file = "src/Container.vue";
|
|
549
549
|
|
|
550
|
-
var script$
|
|
550
|
+
var script$a = defineComponent({
|
|
551
551
|
name: "MobileNavigationLink",
|
|
552
552
|
props: {
|
|
553
553
|
text: {
|
|
@@ -572,7 +572,7 @@ var script$9 = defineComponent({
|
|
|
572
572
|
|
|
573
573
|
const _hoisted_1$9 = ["href"];
|
|
574
574
|
|
|
575
|
-
function render$
|
|
575
|
+
function render$a(_ctx, _cache) {
|
|
576
576
|
return (openBlock(), createElementBlock("a", {
|
|
577
577
|
href: _ctx.href,
|
|
578
578
|
class: normalizeClass(_ctx.linkClass),
|
|
@@ -580,13 +580,13 @@ function render$9(_ctx, _cache) {
|
|
|
580
580
|
}, toDisplayString(_ctx.text), 11 /* TEXT, CLASS, PROPS */, _hoisted_1$9))
|
|
581
581
|
}
|
|
582
582
|
|
|
583
|
-
script$
|
|
584
|
-
script$
|
|
583
|
+
script$a.render = render$a;
|
|
584
|
+
script$a.__file = "src/MobileNavigationLink.vue";
|
|
585
585
|
|
|
586
|
-
var script$
|
|
586
|
+
var script$9 = defineComponent({
|
|
587
587
|
name: "MobileNavigationLinks",
|
|
588
588
|
components: {
|
|
589
|
-
MobileNavigationLink: script$
|
|
589
|
+
MobileNavigationLink: script$a,
|
|
590
590
|
},
|
|
591
591
|
props: {
|
|
592
592
|
links: {
|
|
@@ -606,7 +606,7 @@ const _hoisted_1$8 = {
|
|
|
606
606
|
};
|
|
607
607
|
const _hoisted_2$6 = { class: "px-2 pt-2 pb-3 space-y-1" };
|
|
608
608
|
|
|
609
|
-
function render$
|
|
609
|
+
function render$9(_ctx, _cache) {
|
|
610
610
|
const _component_mobile_navigation_link = resolveComponent("mobile-navigation-link");
|
|
611
611
|
|
|
612
612
|
return (openBlock(), createBlock(Transition, {
|
|
@@ -636,10 +636,10 @@ function render$8(_ctx, _cache) {
|
|
|
636
636
|
}))
|
|
637
637
|
}
|
|
638
638
|
|
|
639
|
-
script$
|
|
640
|
-
script$
|
|
639
|
+
script$9.render = render$9;
|
|
640
|
+
script$9.__file = "src/MobileNavigationLinks.vue";
|
|
641
641
|
|
|
642
|
-
var script$
|
|
642
|
+
var script$8 = defineComponent({
|
|
643
643
|
name: "NavigationLink",
|
|
644
644
|
props: {
|
|
645
645
|
text: {
|
|
@@ -664,7 +664,7 @@ var script$7 = defineComponent({
|
|
|
664
664
|
|
|
665
665
|
const _hoisted_1$7 = ["href"];
|
|
666
666
|
|
|
667
|
-
function render$
|
|
667
|
+
function render$8(_ctx, _cache) {
|
|
668
668
|
return (openBlock(), createElementBlock("a", {
|
|
669
669
|
href: _ctx.href,
|
|
670
670
|
class: normalizeClass(_ctx.linkClass),
|
|
@@ -672,13 +672,13 @@ function render$7(_ctx, _cache) {
|
|
|
672
672
|
}, toDisplayString(_ctx.text), 11 /* TEXT, CLASS, PROPS */, _hoisted_1$7))
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
-
script$
|
|
676
|
-
script$
|
|
675
|
+
script$8.render = render$8;
|
|
676
|
+
script$8.__file = "src/NavigationLink.vue";
|
|
677
677
|
|
|
678
|
-
var script$
|
|
678
|
+
var script$7 = defineComponent({
|
|
679
679
|
name: "NavigationLinks",
|
|
680
680
|
components: {
|
|
681
|
-
NavigationLink: script$
|
|
681
|
+
NavigationLink: script$8,
|
|
682
682
|
},
|
|
683
683
|
props: {
|
|
684
684
|
links: {
|
|
@@ -690,7 +690,7 @@ var script$6 = defineComponent({
|
|
|
690
690
|
const _hoisted_1$6 = { class: "hidden sm:block sm:ml-6" };
|
|
691
691
|
const _hoisted_2$5 = { class: "flex space-x-4" };
|
|
692
692
|
|
|
693
|
-
function render$
|
|
693
|
+
function render$7(_ctx, _cache) {
|
|
694
694
|
const _component_navigation_link = resolveComponent("navigation-link");
|
|
695
695
|
|
|
696
696
|
return (openBlock(), createElementBlock("div", _hoisted_1$6, [
|
|
@@ -706,10 +706,10 @@ function render$6(_ctx, _cache) {
|
|
|
706
706
|
]))
|
|
707
707
|
}
|
|
708
708
|
|
|
709
|
-
script$
|
|
710
|
-
script$
|
|
709
|
+
script$7.render = render$7;
|
|
710
|
+
script$7.__file = "src/NavigationLinks.vue";
|
|
711
711
|
|
|
712
|
-
var script$
|
|
712
|
+
var script$6 = defineComponent({
|
|
713
713
|
name: "NavbarTitle"
|
|
714
714
|
});
|
|
715
715
|
|
|
@@ -729,14 +729,14 @@ const _hoisted_4$1 = [
|
|
|
729
729
|
_hoisted_3$3
|
|
730
730
|
];
|
|
731
731
|
|
|
732
|
-
function render$
|
|
732
|
+
function render$6(_ctx, _cache) {
|
|
733
733
|
return (openBlock(), createElementBlock("div", _hoisted_1$5, _hoisted_4$1))
|
|
734
734
|
}
|
|
735
735
|
|
|
736
|
-
script$
|
|
737
|
-
script$
|
|
736
|
+
script$6.render = render$6;
|
|
737
|
+
script$6.__file = "src/NavbarTitle.vue";
|
|
738
738
|
|
|
739
|
-
var script$
|
|
739
|
+
var script$5 = defineComponent({
|
|
740
740
|
name: "RightContent",
|
|
741
741
|
props: {
|
|
742
742
|
locale: {
|
|
@@ -752,17 +752,17 @@ const _hoisted_1$4 = { class: "absolute inset-y-0 right-0 flex items-center pr-2
|
|
|
752
752
|
const _hoisted_2$3 = { class: "bg-gray-800 p-1 text-gray-400" };
|
|
753
753
|
const _hoisted_3$2 = { class: "bg-gray-800 p-1 text-gray-400" };
|
|
754
754
|
|
|
755
|
-
function render$
|
|
755
|
+
function render$5(_ctx, _cache) {
|
|
756
756
|
return (openBlock(), createElementBlock("div", _hoisted_1$4, [
|
|
757
757
|
createElementVNode("span", _hoisted_2$3, toDisplayString(_ctx.$i18n.locale), 1 /* TEXT */),
|
|
758
758
|
createElementVNode("span", _hoisted_3$2, toDisplayString(_ctx.currentUserEmail), 1 /* TEXT */)
|
|
759
759
|
]))
|
|
760
760
|
}
|
|
761
761
|
|
|
762
|
-
script$
|
|
763
|
-
script$
|
|
762
|
+
script$5.render = render$5;
|
|
763
|
+
script$5.__file = "src/RightContent.vue";
|
|
764
764
|
|
|
765
|
-
var script$
|
|
765
|
+
var script$4 = defineComponent({
|
|
766
766
|
name: "MobileMenuButton",
|
|
767
767
|
props: {
|
|
768
768
|
open: {
|
|
@@ -796,7 +796,7 @@ const _hoisted_2$2 = [
|
|
|
796
796
|
_hoisted_1$3
|
|
797
797
|
];
|
|
798
798
|
|
|
799
|
-
function render$
|
|
799
|
+
function render$4(_ctx, _cache) {
|
|
800
800
|
return (openBlock(), createElementBlock("button", {
|
|
801
801
|
class: "inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-white hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-white",
|
|
802
802
|
type: "button",
|
|
@@ -804,17 +804,17 @@ function render$3(_ctx, _cache) {
|
|
|
804
804
|
}, _hoisted_2$2))
|
|
805
805
|
}
|
|
806
806
|
|
|
807
|
-
script$
|
|
808
|
-
script$
|
|
807
|
+
script$4.render = render$4;
|
|
808
|
+
script$4.__file = "src/MobileMenuButton.vue";
|
|
809
809
|
|
|
810
|
-
var script$
|
|
810
|
+
var script$3 = defineComponent({
|
|
811
811
|
name: "Navbar",
|
|
812
812
|
components: {
|
|
813
|
-
NavbarTitle: script$
|
|
814
|
-
NavigationLinks: script$
|
|
815
|
-
MobileNavigationLinks: script$
|
|
816
|
-
RightContent: script$
|
|
817
|
-
MobileMenuButton: script$
|
|
813
|
+
NavbarTitle: script$6,
|
|
814
|
+
NavigationLinks: script$7,
|
|
815
|
+
MobileNavigationLinks: script$9,
|
|
816
|
+
RightContent: script$5,
|
|
817
|
+
MobileMenuButton: script$4,
|
|
818
818
|
},
|
|
819
819
|
data() {
|
|
820
820
|
return {
|
|
@@ -845,7 +845,7 @@ const _hoisted_3$1 = { class: "relative flex items-center justify-between h-16"
|
|
|
845
845
|
const _hoisted_4 = { class: "absolute inset-y-0 left-0 flex items-center sm:hidden" };
|
|
846
846
|
const _hoisted_5 = { class: "flex-1 flex items-center justify-center sm:items-stretch sm:justify-start" };
|
|
847
847
|
|
|
848
|
-
function render$
|
|
848
|
+
function render$3(_ctx, _cache) {
|
|
849
849
|
const _component_mobile_menu_button = resolveComponent("mobile-menu-button");
|
|
850
850
|
const _component_navbar_title = resolveComponent("navbar-title");
|
|
851
851
|
const _component_navigation_links = resolveComponent("navigation-links");
|
|
@@ -878,25 +878,25 @@ function render$2(_ctx, _cache) {
|
|
|
878
878
|
]))
|
|
879
879
|
}
|
|
880
880
|
|
|
881
|
-
script$
|
|
882
|
-
script$
|
|
881
|
+
script$3.render = render$3;
|
|
882
|
+
script$3.__file = "src/Navbar.vue";
|
|
883
883
|
|
|
884
|
-
var script$
|
|
884
|
+
var script$2 = defineComponent({
|
|
885
885
|
name: "StyledTable"
|
|
886
886
|
});
|
|
887
887
|
|
|
888
888
|
const _hoisted_1$1 = { class: "w-full border-collapse" };
|
|
889
889
|
|
|
890
|
-
function render$
|
|
890
|
+
function render$2(_ctx, _cache) {
|
|
891
891
|
return (openBlock(), createElementBlock("table", _hoisted_1$1, [
|
|
892
892
|
renderSlot(_ctx.$slots, "default")
|
|
893
893
|
]))
|
|
894
894
|
}
|
|
895
895
|
|
|
896
|
-
script$
|
|
897
|
-
script$
|
|
896
|
+
script$2.render = render$2;
|
|
897
|
+
script$2.__file = "src/StyledTable.vue";
|
|
898
898
|
|
|
899
|
-
var script = defineComponent({
|
|
899
|
+
var script$1 = defineComponent({
|
|
900
900
|
name: "Pagination",
|
|
901
901
|
props: {
|
|
902
902
|
previousLabel: String,
|
|
@@ -906,7 +906,7 @@ var script = defineComponent({
|
|
|
906
906
|
nextLink: String,
|
|
907
907
|
},
|
|
908
908
|
components: {
|
|
909
|
-
RegularButton: script$
|
|
909
|
+
RegularButton: script$n
|
|
910
910
|
}
|
|
911
911
|
});
|
|
912
912
|
|
|
@@ -914,7 +914,7 @@ const _hoisted_1 = { class: "flex justify-between mt-4" };
|
|
|
914
914
|
const _hoisted_2 = ["href"];
|
|
915
915
|
const _hoisted_3 = ["href"];
|
|
916
916
|
|
|
917
|
-
function render(_ctx, _cache) {
|
|
917
|
+
function render$1(_ctx, _cache) {
|
|
918
918
|
const _component_regular_button = resolveComponent("regular-button");
|
|
919
919
|
|
|
920
920
|
return (openBlock(), createElementBlock("div", _hoisted_1, [
|
|
@@ -932,8 +932,3666 @@ function render(_ctx, _cache) {
|
|
|
932
932
|
]))
|
|
933
933
|
}
|
|
934
934
|
|
|
935
|
+
script$1.render = render$1;
|
|
936
|
+
script$1.__file = "src/Pagination.vue";
|
|
937
|
+
|
|
938
|
+
/*! image-blob-reduce 4.1.0 https://github.com/nodeca/image-blob-reduce @license MIT */
|
|
939
|
+
function commonjsRequire (path) {
|
|
940
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
var utils$1 = {};
|
|
944
|
+
|
|
945
|
+
utils$1.assign = function assign(to) {
|
|
946
|
+
var from;
|
|
947
|
+
|
|
948
|
+
for (var s = 1; s < arguments.length; s++) {
|
|
949
|
+
from = Object(arguments[s]);
|
|
950
|
+
|
|
951
|
+
for (var key in from) {
|
|
952
|
+
if (Object.prototype.hasOwnProperty.call(from, key)) to[key] = from[key];
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
return to;
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
function pick(from, props) {
|
|
961
|
+
var to = {};
|
|
962
|
+
|
|
963
|
+
props.forEach(function (key) {
|
|
964
|
+
if (Object.prototype.hasOwnProperty.call(from, key)) to[key] = from[key];
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
return to;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
function pick_pica_resize_options(from) {
|
|
972
|
+
return pick(from, [
|
|
973
|
+
'alpha',
|
|
974
|
+
'unsharpAmount',
|
|
975
|
+
'unsharpRadius',
|
|
976
|
+
'unsharpThreshold',
|
|
977
|
+
'cancelToken'
|
|
978
|
+
]);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
utils$1.pick = pick;
|
|
983
|
+
utils$1.pick_pica_resize_options = pick_pica_resize_options;
|
|
984
|
+
|
|
985
|
+
var pica$1 = {exports: {}};
|
|
986
|
+
|
|
987
|
+
/*!
|
|
988
|
+
|
|
989
|
+
pica
|
|
990
|
+
https://github.com/nodeca/pica
|
|
991
|
+
|
|
992
|
+
*/
|
|
993
|
+
|
|
994
|
+
(function (module, exports) {
|
|
995
|
+
(function(f){{module.exports=f();}})(function(){return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof commonjsRequire&&commonjsRequire;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t);}return n[i].exports}for(var u="function"==typeof commonjsRequire&&commonjsRequire,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){
|
|
996
|
+
|
|
997
|
+
var Multimath = _dereq_('multimath');
|
|
998
|
+
|
|
999
|
+
var mm_unsharp_mask = _dereq_('./mm_unsharp_mask');
|
|
1000
|
+
|
|
1001
|
+
var mm_resize = _dereq_('./mm_resize');
|
|
1002
|
+
|
|
1003
|
+
function MathLib(requested_features) {
|
|
1004
|
+
var __requested_features = requested_features || [];
|
|
1005
|
+
|
|
1006
|
+
var features = {
|
|
1007
|
+
js: __requested_features.indexOf('js') >= 0,
|
|
1008
|
+
wasm: __requested_features.indexOf('wasm') >= 0
|
|
1009
|
+
};
|
|
1010
|
+
Multimath.call(this, features);
|
|
1011
|
+
this.features = {
|
|
1012
|
+
js: features.js,
|
|
1013
|
+
wasm: features.wasm && this.has_wasm()
|
|
1014
|
+
};
|
|
1015
|
+
this.use(mm_unsharp_mask);
|
|
1016
|
+
this.use(mm_resize);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
MathLib.prototype = Object.create(Multimath.prototype);
|
|
1020
|
+
MathLib.prototype.constructor = MathLib;
|
|
1021
|
+
|
|
1022
|
+
MathLib.prototype.resizeAndUnsharp = function resizeAndUnsharp(options, cache) {
|
|
1023
|
+
var result = this.resize(options, cache);
|
|
1024
|
+
|
|
1025
|
+
if (options.unsharpAmount) {
|
|
1026
|
+
this.unsharp_mask(result, options.toWidth, options.toHeight, options.unsharpAmount, options.unsharpRadius, options.unsharpThreshold);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
return result;
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
module.exports = MathLib;
|
|
1033
|
+
|
|
1034
|
+
},{"./mm_resize":4,"./mm_unsharp_mask":9,"multimath":19}],2:[function(_dereq_,module,exports){
|
|
1035
|
+
//var FIXED_FRAC_BITS = 14;
|
|
1036
|
+
|
|
1037
|
+
function clampTo8(i) {
|
|
1038
|
+
return i < 0 ? 0 : i > 255 ? 255 : i;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
function clampNegative(i) {
|
|
1042
|
+
return i >= 0 ? i : 0;
|
|
1043
|
+
} // Convolve image data in horizontal direction. Can be used for:
|
|
1044
|
+
//
|
|
1045
|
+
// 1. bitmap with premultiplied alpha
|
|
1046
|
+
// 2. bitmap without alpha (all values 255)
|
|
1047
|
+
//
|
|
1048
|
+
// Notes:
|
|
1049
|
+
//
|
|
1050
|
+
// - output is transposed
|
|
1051
|
+
// - output resolution is ~15 bits per channel(for better precision).
|
|
1052
|
+
//
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
function convolveHor(src, dest, srcW, srcH, destW, filters) {
|
|
1056
|
+
var r, g, b, a;
|
|
1057
|
+
var filterPtr, filterShift, filterSize;
|
|
1058
|
+
var srcPtr, srcY, destX, filterVal;
|
|
1059
|
+
var srcOffset = 0,
|
|
1060
|
+
destOffset = 0; // For each row
|
|
1061
|
+
|
|
1062
|
+
for (srcY = 0; srcY < srcH; srcY++) {
|
|
1063
|
+
filterPtr = 0; // Apply precomputed filters to each destination row point
|
|
1064
|
+
|
|
1065
|
+
for (destX = 0; destX < destW; destX++) {
|
|
1066
|
+
// Get the filter that determines the current output pixel.
|
|
1067
|
+
filterShift = filters[filterPtr++];
|
|
1068
|
+
filterSize = filters[filterPtr++];
|
|
1069
|
+
srcPtr = srcOffset + filterShift * 4 | 0;
|
|
1070
|
+
r = g = b = a = 0; // Apply the filter to the row to get the destination pixel r, g, b, a
|
|
1071
|
+
|
|
1072
|
+
for (; filterSize > 0; filterSize--) {
|
|
1073
|
+
filterVal = filters[filterPtr++]; // Use reverse order to workaround deopts in old v8 (node v.10)
|
|
1074
|
+
// Big thanks to @mraleph (Vyacheslav Egorov) for the tip.
|
|
1075
|
+
|
|
1076
|
+
a = a + filterVal * src[srcPtr + 3] | 0;
|
|
1077
|
+
b = b + filterVal * src[srcPtr + 2] | 0;
|
|
1078
|
+
g = g + filterVal * src[srcPtr + 1] | 0;
|
|
1079
|
+
r = r + filterVal * src[srcPtr] | 0;
|
|
1080
|
+
srcPtr = srcPtr + 4 | 0;
|
|
1081
|
+
} // Store 15 bits between passes for better precision
|
|
1082
|
+
// Instead of shift to 14 (FIXED_FRAC_BITS), shift to 7 only
|
|
1083
|
+
//
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
dest[destOffset + 3] = clampNegative(a >> 7);
|
|
1087
|
+
dest[destOffset + 2] = clampNegative(b >> 7);
|
|
1088
|
+
dest[destOffset + 1] = clampNegative(g >> 7);
|
|
1089
|
+
dest[destOffset] = clampNegative(r >> 7);
|
|
1090
|
+
destOffset = destOffset + srcH * 4 | 0;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
destOffset = (srcY + 1) * 4 | 0;
|
|
1094
|
+
srcOffset = (srcY + 1) * srcW * 4 | 0;
|
|
1095
|
+
}
|
|
1096
|
+
} // Supplementary method for `convolveHor()`
|
|
1097
|
+
//
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
function convolveVert(src, dest, srcW, srcH, destW, filters) {
|
|
1101
|
+
var r, g, b, a;
|
|
1102
|
+
var filterPtr, filterShift, filterSize;
|
|
1103
|
+
var srcPtr, srcY, destX, filterVal;
|
|
1104
|
+
var srcOffset = 0,
|
|
1105
|
+
destOffset = 0; // For each row
|
|
1106
|
+
|
|
1107
|
+
for (srcY = 0; srcY < srcH; srcY++) {
|
|
1108
|
+
filterPtr = 0; // Apply precomputed filters to each destination row point
|
|
1109
|
+
|
|
1110
|
+
for (destX = 0; destX < destW; destX++) {
|
|
1111
|
+
// Get the filter that determines the current output pixel.
|
|
1112
|
+
filterShift = filters[filterPtr++];
|
|
1113
|
+
filterSize = filters[filterPtr++];
|
|
1114
|
+
srcPtr = srcOffset + filterShift * 4 | 0;
|
|
1115
|
+
r = g = b = a = 0; // Apply the filter to the row to get the destination pixel r, g, b, a
|
|
1116
|
+
|
|
1117
|
+
for (; filterSize > 0; filterSize--) {
|
|
1118
|
+
filterVal = filters[filterPtr++]; // Use reverse order to workaround deopts in old v8 (node v.10)
|
|
1119
|
+
// Big thanks to @mraleph (Vyacheslav Egorov) for the tip.
|
|
1120
|
+
|
|
1121
|
+
a = a + filterVal * src[srcPtr + 3] | 0;
|
|
1122
|
+
b = b + filterVal * src[srcPtr + 2] | 0;
|
|
1123
|
+
g = g + filterVal * src[srcPtr + 1] | 0;
|
|
1124
|
+
r = r + filterVal * src[srcPtr] | 0;
|
|
1125
|
+
srcPtr = srcPtr + 4 | 0;
|
|
1126
|
+
} // Sync with premultiplied version for exact result match
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
r >>= 7;
|
|
1130
|
+
g >>= 7;
|
|
1131
|
+
b >>= 7;
|
|
1132
|
+
a >>= 7; // Bring this value back in range + round result.
|
|
1133
|
+
//
|
|
1134
|
+
|
|
1135
|
+
dest[destOffset + 3] = clampTo8(a + (1 << 13) >> 14);
|
|
1136
|
+
dest[destOffset + 2] = clampTo8(b + (1 << 13) >> 14);
|
|
1137
|
+
dest[destOffset + 1] = clampTo8(g + (1 << 13) >> 14);
|
|
1138
|
+
dest[destOffset] = clampTo8(r + (1 << 13) >> 14);
|
|
1139
|
+
destOffset = destOffset + srcH * 4 | 0;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
destOffset = (srcY + 1) * 4 | 0;
|
|
1143
|
+
srcOffset = (srcY + 1) * srcW * 4 | 0;
|
|
1144
|
+
}
|
|
1145
|
+
} // Premultiply & convolve image data in horizontal direction. Can be used for:
|
|
1146
|
+
//
|
|
1147
|
+
// - Any bitmap data, extracted with `.getImageData()` method (with
|
|
1148
|
+
// non-premultiplied alpha)
|
|
1149
|
+
//
|
|
1150
|
+
// For images without alpha channel this method is slower than `convolveHor()`
|
|
1151
|
+
//
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
function convolveHorWithPre(src, dest, srcW, srcH, destW, filters) {
|
|
1155
|
+
var r, g, b, a, alpha;
|
|
1156
|
+
var filterPtr, filterShift, filterSize;
|
|
1157
|
+
var srcPtr, srcY, destX, filterVal;
|
|
1158
|
+
var srcOffset = 0,
|
|
1159
|
+
destOffset = 0; // For each row
|
|
1160
|
+
|
|
1161
|
+
for (srcY = 0; srcY < srcH; srcY++) {
|
|
1162
|
+
filterPtr = 0; // Apply precomputed filters to each destination row point
|
|
1163
|
+
|
|
1164
|
+
for (destX = 0; destX < destW; destX++) {
|
|
1165
|
+
// Get the filter that determines the current output pixel.
|
|
1166
|
+
filterShift = filters[filterPtr++];
|
|
1167
|
+
filterSize = filters[filterPtr++];
|
|
1168
|
+
srcPtr = srcOffset + filterShift * 4 | 0;
|
|
1169
|
+
r = g = b = a = 0; // Apply the filter to the row to get the destination pixel r, g, b, a
|
|
1170
|
+
|
|
1171
|
+
for (; filterSize > 0; filterSize--) {
|
|
1172
|
+
filterVal = filters[filterPtr++]; // Use reverse order to workaround deopts in old v8 (node v.10)
|
|
1173
|
+
// Big thanks to @mraleph (Vyacheslav Egorov) for the tip.
|
|
1174
|
+
|
|
1175
|
+
alpha = src[srcPtr + 3];
|
|
1176
|
+
a = a + filterVal * alpha | 0;
|
|
1177
|
+
b = b + filterVal * src[srcPtr + 2] * alpha | 0;
|
|
1178
|
+
g = g + filterVal * src[srcPtr + 1] * alpha | 0;
|
|
1179
|
+
r = r + filterVal * src[srcPtr] * alpha | 0;
|
|
1180
|
+
srcPtr = srcPtr + 4 | 0;
|
|
1181
|
+
} // Premultiply is (* alpha / 255).
|
|
1182
|
+
// Postpone division for better performance
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
b = b / 255 | 0;
|
|
1186
|
+
g = g / 255 | 0;
|
|
1187
|
+
r = r / 255 | 0; // Store 15 bits between passes for better precision
|
|
1188
|
+
// Instead of shift to 14 (FIXED_FRAC_BITS), shift to 7 only
|
|
1189
|
+
//
|
|
1190
|
+
|
|
1191
|
+
dest[destOffset + 3] = clampNegative(a >> 7);
|
|
1192
|
+
dest[destOffset + 2] = clampNegative(b >> 7);
|
|
1193
|
+
dest[destOffset + 1] = clampNegative(g >> 7);
|
|
1194
|
+
dest[destOffset] = clampNegative(r >> 7);
|
|
1195
|
+
destOffset = destOffset + srcH * 4 | 0;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
destOffset = (srcY + 1) * 4 | 0;
|
|
1199
|
+
srcOffset = (srcY + 1) * srcW * 4 | 0;
|
|
1200
|
+
}
|
|
1201
|
+
} // Supplementary method for `convolveHorWithPre()`
|
|
1202
|
+
//
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
function convolveVertWithPre(src, dest, srcW, srcH, destW, filters) {
|
|
1206
|
+
var r, g, b, a;
|
|
1207
|
+
var filterPtr, filterShift, filterSize;
|
|
1208
|
+
var srcPtr, srcY, destX, filterVal;
|
|
1209
|
+
var srcOffset = 0,
|
|
1210
|
+
destOffset = 0; // For each row
|
|
1211
|
+
|
|
1212
|
+
for (srcY = 0; srcY < srcH; srcY++) {
|
|
1213
|
+
filterPtr = 0; // Apply precomputed filters to each destination row point
|
|
1214
|
+
|
|
1215
|
+
for (destX = 0; destX < destW; destX++) {
|
|
1216
|
+
// Get the filter that determines the current output pixel.
|
|
1217
|
+
filterShift = filters[filterPtr++];
|
|
1218
|
+
filterSize = filters[filterPtr++];
|
|
1219
|
+
srcPtr = srcOffset + filterShift * 4 | 0;
|
|
1220
|
+
r = g = b = a = 0; // Apply the filter to the row to get the destination pixel r, g, b, a
|
|
1221
|
+
|
|
1222
|
+
for (; filterSize > 0; filterSize--) {
|
|
1223
|
+
filterVal = filters[filterPtr++]; // Use reverse order to workaround deopts in old v8 (node v.10)
|
|
1224
|
+
// Big thanks to @mraleph (Vyacheslav Egorov) for the tip.
|
|
1225
|
+
|
|
1226
|
+
a = a + filterVal * src[srcPtr + 3] | 0;
|
|
1227
|
+
b = b + filterVal * src[srcPtr + 2] | 0;
|
|
1228
|
+
g = g + filterVal * src[srcPtr + 1] | 0;
|
|
1229
|
+
r = r + filterVal * src[srcPtr] | 0;
|
|
1230
|
+
srcPtr = srcPtr + 4 | 0;
|
|
1231
|
+
} // Downscale to leave room for un-premultiply
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
r >>= 7;
|
|
1235
|
+
g >>= 7;
|
|
1236
|
+
b >>= 7;
|
|
1237
|
+
a >>= 7; // Un-premultiply
|
|
1238
|
+
|
|
1239
|
+
a = clampTo8(a + (1 << 13) >> 14);
|
|
1240
|
+
|
|
1241
|
+
if (a > 0) {
|
|
1242
|
+
r = r * 255 / a | 0;
|
|
1243
|
+
g = g * 255 / a | 0;
|
|
1244
|
+
b = b * 255 / a | 0;
|
|
1245
|
+
} // Bring this value back in range + round result.
|
|
1246
|
+
// Shift value = FIXED_FRAC_BITS + 7
|
|
1247
|
+
//
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
dest[destOffset + 3] = a;
|
|
1251
|
+
dest[destOffset + 2] = clampTo8(b + (1 << 13) >> 14);
|
|
1252
|
+
dest[destOffset + 1] = clampTo8(g + (1 << 13) >> 14);
|
|
1253
|
+
dest[destOffset] = clampTo8(r + (1 << 13) >> 14);
|
|
1254
|
+
destOffset = destOffset + srcH * 4 | 0;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
destOffset = (srcY + 1) * 4 | 0;
|
|
1258
|
+
srcOffset = (srcY + 1) * srcW * 4 | 0;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
module.exports = {
|
|
1263
|
+
convolveHor: convolveHor,
|
|
1264
|
+
convolveVert: convolveVert,
|
|
1265
|
+
convolveHorWithPre: convolveHorWithPre,
|
|
1266
|
+
convolveVertWithPre: convolveVertWithPre
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
},{}],3:[function(_dereq_,module,exports){
|
|
1270
|
+
/* eslint-disable max-len */
|
|
1271
|
+
|
|
1272
|
+
module.exports = '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';
|
|
1273
|
+
|
|
1274
|
+
},{}],4:[function(_dereq_,module,exports){
|
|
1275
|
+
|
|
1276
|
+
module.exports = {
|
|
1277
|
+
name: 'resize',
|
|
1278
|
+
fn: _dereq_('./resize'),
|
|
1279
|
+
wasm_fn: _dereq_('./resize_wasm'),
|
|
1280
|
+
wasm_src: _dereq_('./convolve_wasm_base64')
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
},{"./convolve_wasm_base64":3,"./resize":5,"./resize_wasm":8}],5:[function(_dereq_,module,exports){
|
|
1284
|
+
|
|
1285
|
+
var createFilters = _dereq_('./resize_filter_gen');
|
|
1286
|
+
|
|
1287
|
+
var _require = _dereq_('./convolve'),
|
|
1288
|
+
convolveHor = _require.convolveHor,
|
|
1289
|
+
convolveVert = _require.convolveVert,
|
|
1290
|
+
convolveHorWithPre = _require.convolveHorWithPre,
|
|
1291
|
+
convolveVertWithPre = _require.convolveVertWithPre;
|
|
1292
|
+
|
|
1293
|
+
function hasAlpha(src, width, height) {
|
|
1294
|
+
var ptr = 3,
|
|
1295
|
+
len = width * height * 4 | 0;
|
|
1296
|
+
|
|
1297
|
+
while (ptr < len) {
|
|
1298
|
+
if (src[ptr] !== 255) return true;
|
|
1299
|
+
ptr = ptr + 4 | 0;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
return false;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
function resetAlpha(dst, width, height) {
|
|
1306
|
+
var ptr = 3,
|
|
1307
|
+
len = width * height * 4 | 0;
|
|
1308
|
+
|
|
1309
|
+
while (ptr < len) {
|
|
1310
|
+
dst[ptr] = 0xFF;
|
|
1311
|
+
ptr = ptr + 4 | 0;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
module.exports = function resize(options) {
|
|
1316
|
+
var src = options.src;
|
|
1317
|
+
var srcW = options.width;
|
|
1318
|
+
var srcH = options.height;
|
|
1319
|
+
var destW = options.toWidth;
|
|
1320
|
+
var destH = options.toHeight;
|
|
1321
|
+
var scaleX = options.scaleX || options.toWidth / options.width;
|
|
1322
|
+
var scaleY = options.scaleY || options.toHeight / options.height;
|
|
1323
|
+
var offsetX = options.offsetX || 0;
|
|
1324
|
+
var offsetY = options.offsetY || 0;
|
|
1325
|
+
var dest = options.dest || new Uint8Array(destW * destH * 4);
|
|
1326
|
+
var filter = typeof options.filter === 'undefined' ? 'mks2013' : options.filter;
|
|
1327
|
+
var filtersX = createFilters(filter, srcW, destW, scaleX, offsetX),
|
|
1328
|
+
filtersY = createFilters(filter, srcH, destH, scaleY, offsetY);
|
|
1329
|
+
var tmp = new Uint16Array(destW * srcH * 4); // Autodetect if alpha channel exists, and use appropriate method
|
|
1330
|
+
|
|
1331
|
+
if (hasAlpha(src, srcW, srcH)) {
|
|
1332
|
+
convolveHorWithPre(src, tmp, srcW, srcH, destW, filtersX);
|
|
1333
|
+
convolveVertWithPre(tmp, dest, srcH, destW, destH, filtersY);
|
|
1334
|
+
} else {
|
|
1335
|
+
convolveHor(src, tmp, srcW, srcH, destW, filtersX);
|
|
1336
|
+
convolveVert(tmp, dest, srcH, destW, destH, filtersY);
|
|
1337
|
+
resetAlpha(dest, destW, destH);
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
return dest;
|
|
1341
|
+
};
|
|
1342
|
+
|
|
1343
|
+
},{"./convolve":2,"./resize_filter_gen":6}],6:[function(_dereq_,module,exports){
|
|
1344
|
+
|
|
1345
|
+
var FILTER_INFO = _dereq_('./resize_filter_info'); // Precision of fixed FP values
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
var FIXED_FRAC_BITS = 14;
|
|
1349
|
+
|
|
1350
|
+
function toFixedPoint(num) {
|
|
1351
|
+
return Math.round(num * ((1 << FIXED_FRAC_BITS) - 1));
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
module.exports = function resizeFilterGen(filter, srcSize, destSize, scale, offset) {
|
|
1355
|
+
var filterFunction = FILTER_INFO.filter[filter].fn;
|
|
1356
|
+
var scaleInverted = 1.0 / scale;
|
|
1357
|
+
var scaleClamped = Math.min(1.0, scale); // For upscale
|
|
1358
|
+
// Filter window (averaging interval), scaled to src image
|
|
1359
|
+
|
|
1360
|
+
var srcWindow = FILTER_INFO.filter[filter].win / scaleClamped;
|
|
1361
|
+
var destPixel, srcPixel, srcFirst, srcLast, filterElementSize, floatFilter, fxpFilter, total, pxl, idx, floatVal, filterTotal, filterVal;
|
|
1362
|
+
var leftNotEmpty, rightNotEmpty, filterShift, filterSize;
|
|
1363
|
+
var maxFilterElementSize = Math.floor((srcWindow + 1) * 2);
|
|
1364
|
+
var packedFilter = new Int16Array((maxFilterElementSize + 2) * destSize);
|
|
1365
|
+
var packedFilterPtr = 0;
|
|
1366
|
+
var slowCopy = !packedFilter.subarray || !packedFilter.set; // For each destination pixel calculate source range and built filter values
|
|
1367
|
+
|
|
1368
|
+
for (destPixel = 0; destPixel < destSize; destPixel++) {
|
|
1369
|
+
// Scaling should be done relative to central pixel point
|
|
1370
|
+
srcPixel = (destPixel + 0.5) * scaleInverted + offset;
|
|
1371
|
+
srcFirst = Math.max(0, Math.floor(srcPixel - srcWindow));
|
|
1372
|
+
srcLast = Math.min(srcSize - 1, Math.ceil(srcPixel + srcWindow));
|
|
1373
|
+
filterElementSize = srcLast - srcFirst + 1;
|
|
1374
|
+
floatFilter = new Float32Array(filterElementSize);
|
|
1375
|
+
fxpFilter = new Int16Array(filterElementSize);
|
|
1376
|
+
total = 0.0; // Fill filter values for calculated range
|
|
1377
|
+
|
|
1378
|
+
for (pxl = srcFirst, idx = 0; pxl <= srcLast; pxl++, idx++) {
|
|
1379
|
+
floatVal = filterFunction((pxl + 0.5 - srcPixel) * scaleClamped);
|
|
1380
|
+
total += floatVal;
|
|
1381
|
+
floatFilter[idx] = floatVal;
|
|
1382
|
+
} // Normalize filter, convert to fixed point and accumulate conversion error
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
filterTotal = 0;
|
|
1386
|
+
|
|
1387
|
+
for (idx = 0; idx < floatFilter.length; idx++) {
|
|
1388
|
+
filterVal = floatFilter[idx] / total;
|
|
1389
|
+
filterTotal += filterVal;
|
|
1390
|
+
fxpFilter[idx] = toFixedPoint(filterVal);
|
|
1391
|
+
} // Compensate normalization error, to minimize brightness drift
|
|
1392
|
+
|
|
1393
|
+
|
|
1394
|
+
fxpFilter[destSize >> 1] += toFixedPoint(1.0 - filterTotal); //
|
|
1395
|
+
// Now pack filter to useable form
|
|
1396
|
+
//
|
|
1397
|
+
// 1. Trim heading and tailing zero values, and compensate shitf/length
|
|
1398
|
+
// 2. Put all to single array in this format:
|
|
1399
|
+
//
|
|
1400
|
+
// [ pos shift, data length, value1, value2, value3, ... ]
|
|
1401
|
+
//
|
|
1402
|
+
|
|
1403
|
+
leftNotEmpty = 0;
|
|
1404
|
+
|
|
1405
|
+
while (leftNotEmpty < fxpFilter.length && fxpFilter[leftNotEmpty] === 0) {
|
|
1406
|
+
leftNotEmpty++;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
if (leftNotEmpty < fxpFilter.length) {
|
|
1410
|
+
rightNotEmpty = fxpFilter.length - 1;
|
|
1411
|
+
|
|
1412
|
+
while (rightNotEmpty > 0 && fxpFilter[rightNotEmpty] === 0) {
|
|
1413
|
+
rightNotEmpty--;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
filterShift = srcFirst + leftNotEmpty;
|
|
1417
|
+
filterSize = rightNotEmpty - leftNotEmpty + 1;
|
|
1418
|
+
packedFilter[packedFilterPtr++] = filterShift; // shift
|
|
1419
|
+
|
|
1420
|
+
packedFilter[packedFilterPtr++] = filterSize; // size
|
|
1421
|
+
|
|
1422
|
+
if (!slowCopy) {
|
|
1423
|
+
packedFilter.set(fxpFilter.subarray(leftNotEmpty, rightNotEmpty + 1), packedFilterPtr);
|
|
1424
|
+
packedFilterPtr += filterSize;
|
|
1425
|
+
} else {
|
|
1426
|
+
// fallback for old IE < 11, without subarray/set methods
|
|
1427
|
+
for (idx = leftNotEmpty; idx <= rightNotEmpty; idx++) {
|
|
1428
|
+
packedFilter[packedFilterPtr++] = fxpFilter[idx];
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
} else {
|
|
1432
|
+
// zero data, write header only
|
|
1433
|
+
packedFilter[packedFilterPtr++] = 0; // shift
|
|
1434
|
+
|
|
1435
|
+
packedFilter[packedFilterPtr++] = 0; // size
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
return packedFilter;
|
|
1440
|
+
};
|
|
1441
|
+
|
|
1442
|
+
},{"./resize_filter_info":7}],7:[function(_dereq_,module,exports){
|
|
1443
|
+
|
|
1444
|
+
var filter = {
|
|
1445
|
+
// Nearest neibor
|
|
1446
|
+
box: {
|
|
1447
|
+
win: 0.5,
|
|
1448
|
+
fn: function fn(x) {
|
|
1449
|
+
if (x < 0) x = -x;
|
|
1450
|
+
return x < 0.5 ? 1.0 : 0.0;
|
|
1451
|
+
}
|
|
1452
|
+
},
|
|
1453
|
+
// // Hamming
|
|
1454
|
+
hamming: {
|
|
1455
|
+
win: 1.0,
|
|
1456
|
+
fn: function fn(x) {
|
|
1457
|
+
if (x < 0) x = -x;
|
|
1458
|
+
|
|
1459
|
+
if (x >= 1.0) {
|
|
1460
|
+
return 0.0;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
if (x < 1.19209290E-07) {
|
|
1464
|
+
return 1.0;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
var xpi = x * Math.PI;
|
|
1468
|
+
return Math.sin(xpi) / xpi * (0.54 + 0.46 * Math.cos(xpi / 1.0));
|
|
1469
|
+
}
|
|
1470
|
+
},
|
|
1471
|
+
// Lanczos, win = 2
|
|
1472
|
+
lanczos2: {
|
|
1473
|
+
win: 2.0,
|
|
1474
|
+
fn: function fn(x) {
|
|
1475
|
+
if (x < 0) x = -x;
|
|
1476
|
+
|
|
1477
|
+
if (x >= 2.0) {
|
|
1478
|
+
return 0.0;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
if (x < 1.19209290E-07) {
|
|
1482
|
+
return 1.0;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
var xpi = x * Math.PI;
|
|
1486
|
+
return Math.sin(xpi) / xpi * Math.sin(xpi / 2.0) / (xpi / 2.0);
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
// Lanczos, win = 3
|
|
1490
|
+
lanczos3: {
|
|
1491
|
+
win: 3.0,
|
|
1492
|
+
fn: function fn(x) {
|
|
1493
|
+
if (x < 0) x = -x;
|
|
1494
|
+
|
|
1495
|
+
if (x >= 3.0) {
|
|
1496
|
+
return 0.0;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
if (x < 1.19209290E-07) {
|
|
1500
|
+
return 1.0;
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
var xpi = x * Math.PI;
|
|
1504
|
+
return Math.sin(xpi) / xpi * Math.sin(xpi / 3.0) / (xpi / 3.0);
|
|
1505
|
+
}
|
|
1506
|
+
},
|
|
1507
|
+
// Magic Kernel Sharp 2013, win = 2.5
|
|
1508
|
+
// http://johncostella.com/magic/
|
|
1509
|
+
mks2013: {
|
|
1510
|
+
win: 2.5,
|
|
1511
|
+
fn: function fn(x) {
|
|
1512
|
+
if (x < 0) x = -x;
|
|
1513
|
+
|
|
1514
|
+
if (x >= 2.5) {
|
|
1515
|
+
return 0.0;
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
if (x >= 1.5) {
|
|
1519
|
+
return -0.125 * (x - 2.5) * (x - 2.5);
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
if (x >= 0.5) {
|
|
1523
|
+
return 0.25 * (4 * x * x - 11 * x + 7);
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
return 1.0625 - 1.75 * x * x;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1530
|
+
module.exports = {
|
|
1531
|
+
filter: filter,
|
|
1532
|
+
// Legacy mapping
|
|
1533
|
+
f2q: {
|
|
1534
|
+
box: 0,
|
|
1535
|
+
hamming: 1,
|
|
1536
|
+
lanczos2: 2,
|
|
1537
|
+
lanczos3: 3
|
|
1538
|
+
},
|
|
1539
|
+
q2f: ['box', 'hamming', 'lanczos2', 'lanczos3']
|
|
1540
|
+
};
|
|
1541
|
+
|
|
1542
|
+
},{}],8:[function(_dereq_,module,exports){
|
|
1543
|
+
|
|
1544
|
+
var createFilters = _dereq_('./resize_filter_gen');
|
|
1545
|
+
|
|
1546
|
+
function hasAlpha(src, width, height) {
|
|
1547
|
+
var ptr = 3,
|
|
1548
|
+
len = width * height * 4 | 0;
|
|
1549
|
+
|
|
1550
|
+
while (ptr < len) {
|
|
1551
|
+
if (src[ptr] !== 255) return true;
|
|
1552
|
+
ptr = ptr + 4 | 0;
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
return false;
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
function resetAlpha(dst, width, height) {
|
|
1559
|
+
var ptr = 3,
|
|
1560
|
+
len = width * height * 4 | 0;
|
|
1561
|
+
|
|
1562
|
+
while (ptr < len) {
|
|
1563
|
+
dst[ptr] = 0xFF;
|
|
1564
|
+
ptr = ptr + 4 | 0;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
function asUint8Array(src) {
|
|
1569
|
+
return new Uint8Array(src.buffer, 0, src.byteLength);
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
var IS_LE = true; // should not crash everything on module load in old browsers
|
|
1573
|
+
|
|
1574
|
+
try {
|
|
1575
|
+
IS_LE = new Uint32Array(new Uint8Array([1, 0, 0, 0]).buffer)[0] === 1;
|
|
1576
|
+
} catch (__) {}
|
|
1577
|
+
|
|
1578
|
+
function copyInt16asLE(src, target, target_offset) {
|
|
1579
|
+
if (IS_LE) {
|
|
1580
|
+
target.set(asUint8Array(src), target_offset);
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
for (var ptr = target_offset, i = 0; i < src.length; i++) {
|
|
1585
|
+
var data = src[i];
|
|
1586
|
+
target[ptr++] = data & 0xFF;
|
|
1587
|
+
target[ptr++] = data >> 8 & 0xFF;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
module.exports = function resize_wasm(options) {
|
|
1592
|
+
var src = options.src;
|
|
1593
|
+
var srcW = options.width;
|
|
1594
|
+
var srcH = options.height;
|
|
1595
|
+
var destW = options.toWidth;
|
|
1596
|
+
var destH = options.toHeight;
|
|
1597
|
+
var scaleX = options.scaleX || options.toWidth / options.width;
|
|
1598
|
+
var scaleY = options.scaleY || options.toHeight / options.height;
|
|
1599
|
+
var offsetX = options.offsetX || 0.0;
|
|
1600
|
+
var offsetY = options.offsetY || 0.0;
|
|
1601
|
+
var dest = options.dest || new Uint8Array(destW * destH * 4);
|
|
1602
|
+
var filter = typeof options.filter === 'undefined' ? 'mks2013' : options.filter;
|
|
1603
|
+
var filtersX = createFilters(filter, srcW, destW, scaleX, offsetX),
|
|
1604
|
+
filtersY = createFilters(filter, srcH, destH, scaleY, offsetY); // destination is 0 too.
|
|
1605
|
+
|
|
1606
|
+
var src_offset = 0;
|
|
1607
|
+
var src_size = Math.max(src.byteLength, dest.byteLength); // buffer between convolve passes
|
|
1608
|
+
|
|
1609
|
+
var tmp_offset = this.__align(src_offset + src_size);
|
|
1610
|
+
|
|
1611
|
+
var tmp_size = srcH * destW * 4 * 2; // 2 bytes per channel
|
|
1612
|
+
|
|
1613
|
+
var filtersX_offset = this.__align(tmp_offset + tmp_size);
|
|
1614
|
+
|
|
1615
|
+
var filtersY_offset = this.__align(filtersX_offset + filtersX.byteLength);
|
|
1616
|
+
|
|
1617
|
+
var alloc_bytes = filtersY_offset + filtersY.byteLength;
|
|
1618
|
+
|
|
1619
|
+
var instance = this.__instance('resize', alloc_bytes); //
|
|
1620
|
+
// Fill memory block with data to process
|
|
1621
|
+
//
|
|
1622
|
+
|
|
1623
|
+
|
|
1624
|
+
var mem = new Uint8Array(this.__memory.buffer);
|
|
1625
|
+
var mem32 = new Uint32Array(this.__memory.buffer); // 32-bit copy is much faster in chrome
|
|
1626
|
+
|
|
1627
|
+
var src32 = new Uint32Array(src.buffer);
|
|
1628
|
+
mem32.set(src32); // We should guarantee LE bytes order. Filters are not big, so
|
|
1629
|
+
// speed difference is not significant vs direct .set()
|
|
1630
|
+
|
|
1631
|
+
copyInt16asLE(filtersX, mem, filtersX_offset);
|
|
1632
|
+
copyInt16asLE(filtersY, mem, filtersY_offset); // Now call webassembly method
|
|
1633
|
+
// emsdk does method names with '_'
|
|
1634
|
+
|
|
1635
|
+
var fn = instance.exports.convolveHV || instance.exports._convolveHV;
|
|
1636
|
+
|
|
1637
|
+
if (hasAlpha(src, srcW, srcH)) {
|
|
1638
|
+
fn(filtersX_offset, filtersY_offset, tmp_offset, srcW, srcH, destW, destH, 1);
|
|
1639
|
+
} else {
|
|
1640
|
+
fn(filtersX_offset, filtersY_offset, tmp_offset, srcW, srcH, destW, destH, 0);
|
|
1641
|
+
resetAlpha(dest, destW, destH);
|
|
1642
|
+
} //
|
|
1643
|
+
// Copy data back to typed array
|
|
1644
|
+
//
|
|
1645
|
+
// 32-bit copy is much faster in chrome
|
|
1646
|
+
|
|
1647
|
+
|
|
1648
|
+
var dest32 = new Uint32Array(dest.buffer);
|
|
1649
|
+
dest32.set(new Uint32Array(this.__memory.buffer, 0, destH * destW));
|
|
1650
|
+
return dest;
|
|
1651
|
+
};
|
|
1652
|
+
|
|
1653
|
+
},{"./resize_filter_gen":6}],9:[function(_dereq_,module,exports){
|
|
1654
|
+
|
|
1655
|
+
module.exports = {
|
|
1656
|
+
name: 'unsharp_mask',
|
|
1657
|
+
fn: _dereq_('./unsharp_mask'),
|
|
1658
|
+
wasm_fn: _dereq_('./unsharp_mask_wasm'),
|
|
1659
|
+
wasm_src: _dereq_('./unsharp_mask_wasm_base64')
|
|
1660
|
+
};
|
|
1661
|
+
|
|
1662
|
+
},{"./unsharp_mask":10,"./unsharp_mask_wasm":11,"./unsharp_mask_wasm_base64":12}],10:[function(_dereq_,module,exports){
|
|
1663
|
+
|
|
1664
|
+
var glur_mono16 = _dereq_('glur/mono16');
|
|
1665
|
+
|
|
1666
|
+
function hsv_v16(img, width, height) {
|
|
1667
|
+
var size = width * height;
|
|
1668
|
+
var out = new Uint16Array(size);
|
|
1669
|
+
var r, g, b, max;
|
|
1670
|
+
|
|
1671
|
+
for (var i = 0; i < size; i++) {
|
|
1672
|
+
r = img[4 * i];
|
|
1673
|
+
g = img[4 * i + 1];
|
|
1674
|
+
b = img[4 * i + 2];
|
|
1675
|
+
max = r >= g && r >= b ? r : g >= b && g >= r ? g : b;
|
|
1676
|
+
out[i] = max << 8;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
return out;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
module.exports = function unsharp(img, width, height, amount, radius, threshold) {
|
|
1683
|
+
var v1, v2, vmul;
|
|
1684
|
+
var diff, iTimes4;
|
|
1685
|
+
|
|
1686
|
+
if (amount === 0 || radius < 0.5) {
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
if (radius > 2.0) {
|
|
1691
|
+
radius = 2.0;
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
var brightness = hsv_v16(img, width, height);
|
|
1695
|
+
var blured = new Uint16Array(brightness); // copy, because blur modify src
|
|
1696
|
+
|
|
1697
|
+
glur_mono16(blured, width, height, radius);
|
|
1698
|
+
var amountFp = amount / 100 * 0x1000 + 0.5 | 0;
|
|
1699
|
+
var thresholdFp = threshold << 8;
|
|
1700
|
+
var size = width * height;
|
|
1701
|
+
/* eslint-disable indent */
|
|
1702
|
+
|
|
1703
|
+
for (var i = 0; i < size; i++) {
|
|
1704
|
+
v1 = brightness[i];
|
|
1705
|
+
diff = v1 - blured[i];
|
|
1706
|
+
|
|
1707
|
+
if (Math.abs(diff) >= thresholdFp) {
|
|
1708
|
+
// add unsharp mask to the brightness channel
|
|
1709
|
+
v2 = v1 + (amountFp * diff + 0x800 >> 12); // Both v1 and v2 are within [0.0 .. 255.0] (0000-FF00) range, never going into
|
|
1710
|
+
// [255.003 .. 255.996] (FF01-FFFF). This allows to round this value as (x+.5)|0
|
|
1711
|
+
// later without overflowing.
|
|
1712
|
+
|
|
1713
|
+
v2 = v2 > 0xff00 ? 0xff00 : v2;
|
|
1714
|
+
v2 = v2 < 0x0000 ? 0x0000 : v2; // Avoid division by 0. V=0 means rgb(0,0,0), unsharp with unsharpAmount>0 cannot
|
|
1715
|
+
// change this value (because diff between colors gets inflated), so no need to verify correctness.
|
|
1716
|
+
|
|
1717
|
+
v1 = v1 !== 0 ? v1 : 1; // Multiplying V in HSV model by a constant is equivalent to multiplying each component
|
|
1718
|
+
// in RGB by the same constant (same for HSL), see also:
|
|
1719
|
+
// https://beesbuzz.biz/code/16-hsv-color-transforms
|
|
1720
|
+
|
|
1721
|
+
vmul = (v2 << 12) / v1 | 0; // Result will be in [0..255] range because:
|
|
1722
|
+
// - all numbers are positive
|
|
1723
|
+
// - r,g,b <= (v1/256)
|
|
1724
|
+
// - r,g,b,(v1/256),(v2/256) <= 255
|
|
1725
|
+
// So highest this number can get is X*255/X+0.5=255.5 which is < 256 and rounds down.
|
|
1726
|
+
|
|
1727
|
+
iTimes4 = i * 4;
|
|
1728
|
+
img[iTimes4] = img[iTimes4] * vmul + 0x800 >> 12; // R
|
|
1729
|
+
|
|
1730
|
+
img[iTimes4 + 1] = img[iTimes4 + 1] * vmul + 0x800 >> 12; // G
|
|
1731
|
+
|
|
1732
|
+
img[iTimes4 + 2] = img[iTimes4 + 2] * vmul + 0x800 >> 12; // B
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
|
|
1737
|
+
},{"glur/mono16":18}],11:[function(_dereq_,module,exports){
|
|
1738
|
+
|
|
1739
|
+
module.exports = function unsharp(img, width, height, amount, radius, threshold) {
|
|
1740
|
+
if (amount === 0 || radius < 0.5) {
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
if (radius > 2.0) {
|
|
1745
|
+
radius = 2.0;
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
var pixels = width * height;
|
|
1749
|
+
var img_bytes_cnt = pixels * 4;
|
|
1750
|
+
var hsv_bytes_cnt = pixels * 2;
|
|
1751
|
+
var blur_bytes_cnt = pixels * 2;
|
|
1752
|
+
var blur_line_byte_cnt = Math.max(width, height) * 4; // float32 array
|
|
1753
|
+
|
|
1754
|
+
var blur_coeffs_byte_cnt = 8 * 4; // float32 array
|
|
1755
|
+
|
|
1756
|
+
var img_offset = 0;
|
|
1757
|
+
var hsv_offset = img_bytes_cnt;
|
|
1758
|
+
var blur_offset = hsv_offset + hsv_bytes_cnt;
|
|
1759
|
+
var blur_tmp_offset = blur_offset + blur_bytes_cnt;
|
|
1760
|
+
var blur_line_offset = blur_tmp_offset + blur_bytes_cnt;
|
|
1761
|
+
var blur_coeffs_offset = blur_line_offset + blur_line_byte_cnt;
|
|
1762
|
+
|
|
1763
|
+
var instance = this.__instance('unsharp_mask', img_bytes_cnt + hsv_bytes_cnt + blur_bytes_cnt * 2 + blur_line_byte_cnt + blur_coeffs_byte_cnt, {
|
|
1764
|
+
exp: Math.exp
|
|
1765
|
+
}); // 32-bit copy is much faster in chrome
|
|
1766
|
+
|
|
1767
|
+
|
|
1768
|
+
var img32 = new Uint32Array(img.buffer);
|
|
1769
|
+
var mem32 = new Uint32Array(this.__memory.buffer);
|
|
1770
|
+
mem32.set(img32); // HSL
|
|
1771
|
+
|
|
1772
|
+
var fn = instance.exports.hsv_v16 || instance.exports._hsv_v16;
|
|
1773
|
+
fn(img_offset, hsv_offset, width, height); // BLUR
|
|
1774
|
+
|
|
1775
|
+
fn = instance.exports.blurMono16 || instance.exports._blurMono16;
|
|
1776
|
+
fn(hsv_offset, blur_offset, blur_tmp_offset, blur_line_offset, blur_coeffs_offset, width, height, radius); // UNSHARP
|
|
1777
|
+
|
|
1778
|
+
fn = instance.exports.unsharp || instance.exports._unsharp;
|
|
1779
|
+
fn(img_offset, img_offset, hsv_offset, blur_offset, width, height, amount, threshold); // 32-bit copy is much faster in chrome
|
|
1780
|
+
|
|
1781
|
+
img32.set(new Uint32Array(this.__memory.buffer, 0, pixels));
|
|
1782
|
+
};
|
|
1783
|
+
|
|
1784
|
+
},{}],12:[function(_dereq_,module,exports){
|
|
1785
|
+
/* eslint-disable max-len */
|
|
1786
|
+
|
|
1787
|
+
module.exports = 'AGFzbQEAAAAADAZkeWxpbmsAAAAAAAE0B2AAAGAEf39/fwBgBn9/f39/fwBgCH9/f39/f39/AGAIf39/f39/f30AYAJ9fwBgAXwBfAIZAgNlbnYDZXhwAAYDZW52Bm1lbW9yeQIAAAMHBgAFAgQBAwYGAX8AQQALB4oBCBFfX3dhc21fY2FsbF9jdG9ycwABFl9fYnVpbGRfZ2F1c3NpYW5fY29lZnMAAg5fX2dhdXNzMTZfbGluZQADCmJsdXJNb25vMTYABAdoc3ZfdjE2AAUHdW5zaGFycAAGDF9fZHNvX2hhbmRsZQMAGF9fd2FzbV9hcHBseV9kYXRhX3JlbG9jcwABCsUMBgMAAQvWAQEHfCABRNuGukOCGvs/IAC7oyICRAAAAAAAAADAohAAIgW2jDgCFCABIAKaEAAiAyADoCIGtjgCECABRAAAAAAAAPA/IAOhIgQgBKIgAyACIAKgokQAAAAAAADwP6AgBaGjIgS2OAIAIAEgBSAEmqIiB7Y4AgwgASADIAJEAAAAAAAA8D+gIASioiIItjgCCCABIAMgAkQAAAAAAADwv6AgBKKiIgK2OAIEIAEgByAIoCAFRAAAAAAAAPA/IAahoCIDo7Y4AhwgASAEIAKgIAOjtjgCGAuGBQMGfwl8An0gAyoCDCEVIAMqAgghFiADKgIUuyERIAMqAhC7IRACQCAEQQFrIghBAEgiCQRAIAIhByAAIQYMAQsgAiAALwEAuCIPIAMqAhi7oiIMIBGiIg0gDCAQoiAPIAMqAgS7IhOiIhQgAyoCALsiEiAPoqCgoCIOtjgCACACQQRqIQcgAEECaiEGIAhFDQAgCEEBIAhBAUgbIgpBf3MhCwJ/IAQgCmtBAXFFBEAgDiENIAgMAQsgAiANIA4gEKIgFCASIAAvAQK4Ig+ioKCgIg22OAIEIAJBCGohByAAQQRqIQYgDiEMIARBAmsLIQIgC0EAIARrRg0AA0AgByAMIBGiIA0gEKIgDyAToiASIAYvAQC4Ig6ioKCgIgy2OAIAIAcgDSARoiAMIBCiIA4gE6IgEiAGLwECuCIPoqCgoCINtjgCBCAHQQhqIQcgBkEEaiEGIAJBAkohACACQQJrIQIgAA0ACwsCQCAJDQAgASAFIAhsQQF0aiIAAn8gBkECay8BACICuCINIBW7IhKiIA0gFrsiE6KgIA0gAyoCHLuiIgwgEKKgIAwgEaKgIg8gB0EEayIHKgIAu6AiDkQAAAAAAADwQWMgDkQAAAAAAAAAAGZxBEAgDqsMAQtBAAs7AQAgCEUNACAGQQRrIQZBACAFa0EBdCEBA0ACfyANIBKiIAJB//8DcbgiDSAToqAgDyIOIBCioCAMIBGioCIPIAdBBGsiByoCALugIgxEAAAAAAAA8EFjIAxEAAAAAAAAAABmcQRAIAyrDAELQQALIQMgBi8BACECIAAgAWoiACADOwEAIAZBAmshBiAIQQFKIQMgDiEMIAhBAWshCCADDQALCwvRAgIBfwd8AkAgB0MAAAAAWw0AIARE24a6Q4Ia+z8gB0MAAAA/l7ujIglEAAAAAAAAAMCiEAAiDLaMOAIUIAQgCZoQACIKIAqgIg22OAIQIAREAAAAAAAA8D8gCqEiCyALoiAKIAkgCaCiRAAAAAAAAPA/oCAMoaMiC7Y4AgAgBCAMIAuaoiIOtjgCDCAEIAogCUQAAAAAAADwP6AgC6KiIg+2OAIIIAQgCiAJRAAAAAAAAPC/oCALoqIiCbY4AgQgBCAOIA+gIAxEAAAAAAAA8D8gDaGgIgqjtjgCHCAEIAsgCaAgCqO2OAIYIAYEQANAIAAgBSAIbEEBdGogAiAIQQF0aiADIAQgBSAGEAMgCEEBaiIIIAZHDQALCyAFRQ0AQQAhCANAIAIgBiAIbEEBdGogASAIQQF0aiADIAQgBiAFEAMgCEEBaiIIIAVHDQALCwtxAQN/IAIgA2wiBQRAA0AgASAAKAIAIgRBEHZB/wFxIgIgAiAEQQh2Qf8BcSIDIAMgBEH/AXEiBEkbIAIgA0sbIgYgBiAEIAIgBEsbIAMgBEsbQQh0OwEAIAFBAmohASAAQQRqIQAgBUEBayIFDQALCwuZAgIDfwF8IAQgBWwhBAJ/IAazQwAAgEWUQwAAyEKVu0QAAAAAAADgP6AiC5lEAAAAAAAA4EFjBEAgC6oMAQtBgICAgHgLIQUgBARAIAdBCHQhCUEAIQYDQCAJIAIgBkEBdCIHai8BACIBIAMgB2ovAQBrIgcgB0EfdSIIaiAIc00EQCAAIAZBAnQiCGoiCiAFIAdsQYAQakEMdSABaiIHQYD+AyAHQYD+A0gbIgdBACAHQQBKG0EMdCABQQEgARtuIgEgCi0AAGxBgBBqQQx2OgAAIAAgCEEBcmoiByABIActAABsQYAQakEMdjoAACAAIAhBAnJqIgcgASAHLQAAbEGAEGpBDHY6AAALIAZBAWoiBiAERw0ACwsL';
|
|
1788
|
+
|
|
1789
|
+
},{}],13:[function(_dereq_,module,exports){
|
|
1790
|
+
|
|
1791
|
+
var GC_INTERVAL = 100;
|
|
1792
|
+
|
|
1793
|
+
function Pool(create, idle) {
|
|
1794
|
+
this.create = create;
|
|
1795
|
+
this.available = [];
|
|
1796
|
+
this.acquired = {};
|
|
1797
|
+
this.lastId = 1;
|
|
1798
|
+
this.timeoutId = 0;
|
|
1799
|
+
this.idle = idle || 2000;
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
Pool.prototype.acquire = function () {
|
|
1803
|
+
var _this = this;
|
|
1804
|
+
|
|
1805
|
+
var resource;
|
|
1806
|
+
|
|
1807
|
+
if (this.available.length !== 0) {
|
|
1808
|
+
resource = this.available.pop();
|
|
1809
|
+
} else {
|
|
1810
|
+
resource = this.create();
|
|
1811
|
+
resource.id = this.lastId++;
|
|
1812
|
+
|
|
1813
|
+
resource.release = function () {
|
|
1814
|
+
return _this.release(resource);
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
this.acquired[resource.id] = resource;
|
|
1819
|
+
return resource;
|
|
1820
|
+
};
|
|
1821
|
+
|
|
1822
|
+
Pool.prototype.release = function (resource) {
|
|
1823
|
+
var _this2 = this;
|
|
1824
|
+
|
|
1825
|
+
delete this.acquired[resource.id];
|
|
1826
|
+
resource.lastUsed = Date.now();
|
|
1827
|
+
this.available.push(resource);
|
|
1828
|
+
|
|
1829
|
+
if (this.timeoutId === 0) {
|
|
1830
|
+
this.timeoutId = setTimeout(function () {
|
|
1831
|
+
return _this2.gc();
|
|
1832
|
+
}, GC_INTERVAL);
|
|
1833
|
+
}
|
|
1834
|
+
};
|
|
1835
|
+
|
|
1836
|
+
Pool.prototype.gc = function () {
|
|
1837
|
+
var _this3 = this;
|
|
1838
|
+
|
|
1839
|
+
var now = Date.now();
|
|
1840
|
+
this.available = this.available.filter(function (resource) {
|
|
1841
|
+
if (now - resource.lastUsed > _this3.idle) {
|
|
1842
|
+
resource.destroy();
|
|
1843
|
+
return false;
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
return true;
|
|
1847
|
+
});
|
|
1848
|
+
|
|
1849
|
+
if (this.available.length !== 0) {
|
|
1850
|
+
this.timeoutId = setTimeout(function () {
|
|
1851
|
+
return _this3.gc();
|
|
1852
|
+
}, GC_INTERVAL);
|
|
1853
|
+
} else {
|
|
1854
|
+
this.timeoutId = 0;
|
|
1855
|
+
}
|
|
1856
|
+
};
|
|
1857
|
+
|
|
1858
|
+
module.exports = Pool;
|
|
1859
|
+
|
|
1860
|
+
},{}],14:[function(_dereq_,module,exports){
|
|
1861
|
+
// min size = 1 can consume large amount of memory
|
|
1862
|
+
|
|
1863
|
+
var MIN_INNER_TILE_SIZE = 2;
|
|
1864
|
+
|
|
1865
|
+
module.exports = function createStages(fromWidth, fromHeight, toWidth, toHeight, srcTileSize, destTileBorder) {
|
|
1866
|
+
var scaleX = toWidth / fromWidth;
|
|
1867
|
+
var scaleY = toHeight / fromHeight; // derived from createRegions equation:
|
|
1868
|
+
// innerTileWidth = pixelFloor(srcTileSize * scaleX) - 2 * destTileBorder;
|
|
1869
|
+
|
|
1870
|
+
var minScale = (2 * destTileBorder + MIN_INNER_TILE_SIZE + 1) / srcTileSize; // refuse to scale image multiple times by less than twice each time,
|
|
1871
|
+
// it could only happen because of invalid options
|
|
1872
|
+
|
|
1873
|
+
if (minScale > 0.5) return [[toWidth, toHeight]];
|
|
1874
|
+
var stageCount = Math.ceil(Math.log(Math.min(scaleX, scaleY)) / Math.log(minScale)); // no additional resizes are necessary,
|
|
1875
|
+
// stageCount can be zero or be negative when enlarging the image
|
|
1876
|
+
|
|
1877
|
+
if (stageCount <= 1) return [[toWidth, toHeight]];
|
|
1878
|
+
var result = [];
|
|
1879
|
+
|
|
1880
|
+
for (var i = 0; i < stageCount; i++) {
|
|
1881
|
+
var width = Math.round(Math.pow(Math.pow(fromWidth, stageCount - i - 1) * Math.pow(toWidth, i + 1), 1 / stageCount));
|
|
1882
|
+
var height = Math.round(Math.pow(Math.pow(fromHeight, stageCount - i - 1) * Math.pow(toHeight, i + 1), 1 / stageCount));
|
|
1883
|
+
result.push([width, height]);
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
return result;
|
|
1887
|
+
};
|
|
1888
|
+
|
|
1889
|
+
},{}],15:[function(_dereq_,module,exports){
|
|
1890
|
+
/*
|
|
1891
|
+
* pixelFloor and pixelCeil are modified versions of Math.floor and Math.ceil
|
|
1892
|
+
* functions which take into account floating point arithmetic errors.
|
|
1893
|
+
* Those errors can cause undesired increments/decrements of sizes and offsets:
|
|
1894
|
+
* Math.ceil(36 / (36 / 500)) = 501
|
|
1895
|
+
* pixelCeil(36 / (36 / 500)) = 500
|
|
1896
|
+
*/
|
|
1897
|
+
|
|
1898
|
+
var PIXEL_EPSILON = 1e-5;
|
|
1899
|
+
|
|
1900
|
+
function pixelFloor(x) {
|
|
1901
|
+
var nearest = Math.round(x);
|
|
1902
|
+
|
|
1903
|
+
if (Math.abs(x - nearest) < PIXEL_EPSILON) {
|
|
1904
|
+
return nearest;
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
return Math.floor(x);
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
function pixelCeil(x) {
|
|
1911
|
+
var nearest = Math.round(x);
|
|
1912
|
+
|
|
1913
|
+
if (Math.abs(x - nearest) < PIXEL_EPSILON) {
|
|
1914
|
+
return nearest;
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
return Math.ceil(x);
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
module.exports = function createRegions(options) {
|
|
1921
|
+
var scaleX = options.toWidth / options.width;
|
|
1922
|
+
var scaleY = options.toHeight / options.height;
|
|
1923
|
+
var innerTileWidth = pixelFloor(options.srcTileSize * scaleX) - 2 * options.destTileBorder;
|
|
1924
|
+
var innerTileHeight = pixelFloor(options.srcTileSize * scaleY) - 2 * options.destTileBorder; // prevent infinite loop, this should never happen
|
|
1925
|
+
|
|
1926
|
+
if (innerTileWidth < 1 || innerTileHeight < 1) {
|
|
1927
|
+
throw new Error('Internal error in pica: target tile width/height is too small.');
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
var x, y;
|
|
1931
|
+
var innerX, innerY, toTileWidth, toTileHeight;
|
|
1932
|
+
var tiles = [];
|
|
1933
|
+
var tile; // we go top-to-down instead of left-to-right to make image displayed from top to
|
|
1934
|
+
// doesn in the browser
|
|
1935
|
+
|
|
1936
|
+
for (innerY = 0; innerY < options.toHeight; innerY += innerTileHeight) {
|
|
1937
|
+
for (innerX = 0; innerX < options.toWidth; innerX += innerTileWidth) {
|
|
1938
|
+
x = innerX - options.destTileBorder;
|
|
1939
|
+
|
|
1940
|
+
if (x < 0) {
|
|
1941
|
+
x = 0;
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
toTileWidth = innerX + innerTileWidth + options.destTileBorder - x;
|
|
1945
|
+
|
|
1946
|
+
if (x + toTileWidth >= options.toWidth) {
|
|
1947
|
+
toTileWidth = options.toWidth - x;
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
y = innerY - options.destTileBorder;
|
|
1951
|
+
|
|
1952
|
+
if (y < 0) {
|
|
1953
|
+
y = 0;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
toTileHeight = innerY + innerTileHeight + options.destTileBorder - y;
|
|
1957
|
+
|
|
1958
|
+
if (y + toTileHeight >= options.toHeight) {
|
|
1959
|
+
toTileHeight = options.toHeight - y;
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
tile = {
|
|
1963
|
+
toX: x,
|
|
1964
|
+
toY: y,
|
|
1965
|
+
toWidth: toTileWidth,
|
|
1966
|
+
toHeight: toTileHeight,
|
|
1967
|
+
toInnerX: innerX,
|
|
1968
|
+
toInnerY: innerY,
|
|
1969
|
+
toInnerWidth: innerTileWidth,
|
|
1970
|
+
toInnerHeight: innerTileHeight,
|
|
1971
|
+
offsetX: x / scaleX - pixelFloor(x / scaleX),
|
|
1972
|
+
offsetY: y / scaleY - pixelFloor(y / scaleY),
|
|
1973
|
+
scaleX: scaleX,
|
|
1974
|
+
scaleY: scaleY,
|
|
1975
|
+
x: pixelFloor(x / scaleX),
|
|
1976
|
+
y: pixelFloor(y / scaleY),
|
|
1977
|
+
width: pixelCeil(toTileWidth / scaleX),
|
|
1978
|
+
height: pixelCeil(toTileHeight / scaleY)
|
|
1979
|
+
};
|
|
1980
|
+
tiles.push(tile);
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
return tiles;
|
|
1985
|
+
};
|
|
1986
|
+
|
|
1987
|
+
},{}],16:[function(_dereq_,module,exports){
|
|
1988
|
+
|
|
1989
|
+
function objClass(obj) {
|
|
1990
|
+
return Object.prototype.toString.call(obj);
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
module.exports.isCanvas = function isCanvas(element) {
|
|
1994
|
+
var cname = objClass(element);
|
|
1995
|
+
return cname === '[object HTMLCanvasElement]'
|
|
1996
|
+
/* browser */
|
|
1997
|
+
|| cname === '[object OffscreenCanvas]' || cname === '[object Canvas]'
|
|
1998
|
+
/* node-canvas */
|
|
1999
|
+
;
|
|
2000
|
+
};
|
|
2001
|
+
|
|
2002
|
+
module.exports.isImage = function isImage(element) {
|
|
2003
|
+
return objClass(element) === '[object HTMLImageElement]';
|
|
2004
|
+
};
|
|
2005
|
+
|
|
2006
|
+
module.exports.isImageBitmap = function isImageBitmap(element) {
|
|
2007
|
+
return objClass(element) === '[object ImageBitmap]';
|
|
2008
|
+
};
|
|
2009
|
+
|
|
2010
|
+
module.exports.limiter = function limiter(concurrency) {
|
|
2011
|
+
var active = 0,
|
|
2012
|
+
queue = [];
|
|
2013
|
+
|
|
2014
|
+
function roll() {
|
|
2015
|
+
if (active < concurrency && queue.length) {
|
|
2016
|
+
active++;
|
|
2017
|
+
queue.shift()();
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
return function limit(fn) {
|
|
2022
|
+
return new Promise(function (resolve, reject) {
|
|
2023
|
+
queue.push(function () {
|
|
2024
|
+
fn().then(function (result) {
|
|
2025
|
+
resolve(result);
|
|
2026
|
+
active--;
|
|
2027
|
+
roll();
|
|
2028
|
+
}, function (err) {
|
|
2029
|
+
reject(err);
|
|
2030
|
+
active--;
|
|
2031
|
+
roll();
|
|
2032
|
+
});
|
|
2033
|
+
});
|
|
2034
|
+
roll();
|
|
2035
|
+
});
|
|
2036
|
+
};
|
|
2037
|
+
};
|
|
2038
|
+
|
|
2039
|
+
module.exports.cib_quality_name = function cib_quality_name(num) {
|
|
2040
|
+
switch (num) {
|
|
2041
|
+
case 0:
|
|
2042
|
+
return 'pixelated';
|
|
2043
|
+
|
|
2044
|
+
case 1:
|
|
2045
|
+
return 'low';
|
|
2046
|
+
|
|
2047
|
+
case 2:
|
|
2048
|
+
return 'medium';
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
return 'high';
|
|
2052
|
+
};
|
|
2053
|
+
|
|
2054
|
+
module.exports.cib_support = function cib_support(createCanvas) {
|
|
2055
|
+
return Promise.resolve().then(function () {
|
|
2056
|
+
if (typeof createImageBitmap === 'undefined') {
|
|
2057
|
+
return false;
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
var c = createCanvas(100, 100);
|
|
2061
|
+
return createImageBitmap(c, 0, 0, 100, 100, {
|
|
2062
|
+
resizeWidth: 10,
|
|
2063
|
+
resizeHeight: 10,
|
|
2064
|
+
resizeQuality: 'high'
|
|
2065
|
+
}).then(function (bitmap) {
|
|
2066
|
+
var status = bitmap.width === 10; // Branch below is filtered on upper level. We do not call resize
|
|
2067
|
+
// detection for basic ImageBitmap.
|
|
2068
|
+
//
|
|
2069
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap
|
|
2070
|
+
// old Crome 51 has ImageBitmap without .close(). Then this code
|
|
2071
|
+
// will throw and return 'false' as expected.
|
|
2072
|
+
//
|
|
2073
|
+
|
|
2074
|
+
bitmap.close();
|
|
2075
|
+
c = null;
|
|
2076
|
+
return status;
|
|
2077
|
+
});
|
|
2078
|
+
})["catch"](function () {
|
|
2079
|
+
return false;
|
|
2080
|
+
});
|
|
2081
|
+
};
|
|
2082
|
+
|
|
2083
|
+
module.exports.worker_offscreen_canvas_support = function worker_offscreen_canvas_support() {
|
|
2084
|
+
return new Promise(function (resolve, reject) {
|
|
2085
|
+
if (typeof OffscreenCanvas === 'undefined') {
|
|
2086
|
+
// if OffscreenCanvas is present, we assume browser supports Worker and built-in Promise as well
|
|
2087
|
+
resolve(false);
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
function workerPayload(self) {
|
|
2092
|
+
if (typeof createImageBitmap === 'undefined') {
|
|
2093
|
+
self.postMessage(false);
|
|
2094
|
+
return;
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
Promise.resolve().then(function () {
|
|
2098
|
+
var canvas = new OffscreenCanvas(10, 10); // test that 2d context can be used in worker
|
|
2099
|
+
|
|
2100
|
+
var ctx = canvas.getContext('2d');
|
|
2101
|
+
ctx.rect(0, 0, 1, 1); // test that cib can be used to return image bitmap from worker
|
|
2102
|
+
|
|
2103
|
+
return createImageBitmap(canvas, 0, 0, 1, 1);
|
|
2104
|
+
}).then(function () {
|
|
2105
|
+
return self.postMessage(true);
|
|
2106
|
+
}, function () {
|
|
2107
|
+
return self.postMessage(false);
|
|
2108
|
+
});
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
var code = btoa("(".concat(workerPayload.toString(), ")(self);"));
|
|
2112
|
+
var w = new Worker("data:text/javascript;base64,".concat(code));
|
|
2113
|
+
|
|
2114
|
+
w.onmessage = function (ev) {
|
|
2115
|
+
return resolve(ev.data);
|
|
2116
|
+
};
|
|
2117
|
+
|
|
2118
|
+
w.onerror = reject;
|
|
2119
|
+
}).then(function (result) {
|
|
2120
|
+
return result;
|
|
2121
|
+
}, function () {
|
|
2122
|
+
return false;
|
|
2123
|
+
});
|
|
2124
|
+
}; // Check if canvas.getContext('2d').getImageData can be used,
|
|
2125
|
+
// FireFox randomizes the output of that function in `privacy.resistFingerprinting` mode
|
|
2126
|
+
|
|
2127
|
+
|
|
2128
|
+
module.exports.can_use_canvas = function can_use_canvas(createCanvas) {
|
|
2129
|
+
var usable = false;
|
|
2130
|
+
|
|
2131
|
+
try {
|
|
2132
|
+
var canvas = createCanvas(2, 1);
|
|
2133
|
+
var ctx = canvas.getContext('2d');
|
|
2134
|
+
var d = ctx.createImageData(2, 1);
|
|
2135
|
+
d.data[0] = 12;
|
|
2136
|
+
d.data[1] = 23;
|
|
2137
|
+
d.data[2] = 34;
|
|
2138
|
+
d.data[3] = 255;
|
|
2139
|
+
d.data[4] = 45;
|
|
2140
|
+
d.data[5] = 56;
|
|
2141
|
+
d.data[6] = 67;
|
|
2142
|
+
d.data[7] = 255;
|
|
2143
|
+
ctx.putImageData(d, 0, 0);
|
|
2144
|
+
d = null;
|
|
2145
|
+
d = ctx.getImageData(0, 0, 2, 1);
|
|
2146
|
+
|
|
2147
|
+
if (d.data[0] === 12 && d.data[1] === 23 && d.data[2] === 34 && d.data[3] === 255 && d.data[4] === 45 && d.data[5] === 56 && d.data[6] === 67 && d.data[7] === 255) {
|
|
2148
|
+
usable = true;
|
|
2149
|
+
}
|
|
2150
|
+
} catch (err) {}
|
|
2151
|
+
|
|
2152
|
+
return usable;
|
|
2153
|
+
}; // Check if createImageBitmap(img, sx, sy, sw, sh) signature works correctly
|
|
2154
|
+
// with JPEG images oriented with Exif;
|
|
2155
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=1220671
|
|
2156
|
+
// TODO: remove after it's fixed in chrome for at least 2 releases
|
|
2157
|
+
|
|
2158
|
+
|
|
2159
|
+
module.exports.cib_can_use_region = function cib_can_use_region() {
|
|
2160
|
+
return new Promise(function (resolve) {
|
|
2161
|
+
if (typeof createImageBitmap === 'undefined') {
|
|
2162
|
+
resolve(false);
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
var image = new Image();
|
|
2167
|
+
image.src = 'data:image/jpeg;base64,' + '/9j/4QBiRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAYAAAEaAAUAAAABAAAASgEbAAUAA' + 'AABAAAAUgEoAAMAAAABAAIAAAITAAMAAAABAAEAAAAAAAAAAABIAAAAAQAAAEgAAAAB/9' + 'sAQwAEAwMEAwMEBAMEBQQEBQYKBwYGBgYNCQoICg8NEBAPDQ8OERMYFBESFxIODxUcFRc' + 'ZGRsbGxAUHR8dGh8YGhsa/9sAQwEEBQUGBQYMBwcMGhEPERoaGhoaGhoaGhoaGhoaGhoa' + 'GhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoa/8IAEQgAAQACAwERAAIRAQMRA' + 'f/EABQAAQAAAAAAAAAAAAAAAAAAAAf/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAA' + 'IQAxAAAAF/P//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAQUCf//EABQRAQAAAAA' + 'AAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIB' + 'AT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEABj8Cf//EABQQAQAAAAAAAAAAA' + 'AAAAAAAAAD/2gAIAQEAAT8hf//aAAwDAQACAAMAAAAQH//EABQRAQAAAAAAAAAAAAAAAA' + 'AAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQ' + 'QAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8Qf//Z';
|
|
2168
|
+
|
|
2169
|
+
image.onload = function () {
|
|
2170
|
+
createImageBitmap(image, 0, 0, image.width, image.height).then(function (bitmap) {
|
|
2171
|
+
if (bitmap.width === image.width && bitmap.height === image.height) {
|
|
2172
|
+
resolve(true);
|
|
2173
|
+
} else {
|
|
2174
|
+
resolve(false);
|
|
2175
|
+
}
|
|
2176
|
+
}, function () {
|
|
2177
|
+
return resolve(false);
|
|
2178
|
+
});
|
|
2179
|
+
};
|
|
2180
|
+
|
|
2181
|
+
image.onerror = function () {
|
|
2182
|
+
return resolve(false);
|
|
2183
|
+
};
|
|
2184
|
+
});
|
|
2185
|
+
};
|
|
2186
|
+
|
|
2187
|
+
},{}],17:[function(_dereq_,module,exports){
|
|
2188
|
+
|
|
2189
|
+
module.exports = function () {
|
|
2190
|
+
var MathLib = _dereq_('./mathlib');
|
|
2191
|
+
|
|
2192
|
+
var mathLib;
|
|
2193
|
+
/* eslint-disable no-undef */
|
|
2194
|
+
|
|
2195
|
+
onmessage = function onmessage(ev) {
|
|
2196
|
+
var tileOpts = ev.data.opts;
|
|
2197
|
+
|
|
2198
|
+
if (!tileOpts.src && tileOpts.srcBitmap) {
|
|
2199
|
+
var canvas = new OffscreenCanvas(tileOpts.width, tileOpts.height);
|
|
2200
|
+
var ctx = canvas.getContext('2d');
|
|
2201
|
+
ctx.drawImage(tileOpts.srcBitmap, 0, 0);
|
|
2202
|
+
tileOpts.src = ctx.getImageData(0, 0, tileOpts.width, tileOpts.height).data;
|
|
2203
|
+
canvas.width = canvas.height = 0;
|
|
2204
|
+
canvas = null;
|
|
2205
|
+
tileOpts.srcBitmap.close();
|
|
2206
|
+
tileOpts.srcBitmap = null; // Temporary force out data to typed array, because Chrome have artefacts
|
|
2207
|
+
// https://github.com/nodeca/pica/issues/223
|
|
2208
|
+
// returnBitmap = true;
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
if (!mathLib) mathLib = new MathLib(ev.data.features); // Use multimath's sync auto-init. Avoid Promise use in old browsers,
|
|
2212
|
+
// because polyfills are not propagated to webworker.
|
|
2213
|
+
|
|
2214
|
+
var data = mathLib.resizeAndUnsharp(tileOpts);
|
|
2215
|
+
|
|
2216
|
+
{
|
|
2217
|
+
postMessage({
|
|
2218
|
+
data: data
|
|
2219
|
+
}, [data.buffer]);
|
|
2220
|
+
}
|
|
2221
|
+
};
|
|
2222
|
+
};
|
|
2223
|
+
|
|
2224
|
+
},{"./mathlib":1}],18:[function(_dereq_,module,exports){
|
|
2225
|
+
// Calculate Gaussian blur of an image using IIR filter
|
|
2226
|
+
// The method is taken from Intel's white paper and code example attached to it:
|
|
2227
|
+
// https://software.intel.com/en-us/articles/iir-gaussian-blur-filter
|
|
2228
|
+
// -implementation-using-intel-advanced-vector-extensions
|
|
2229
|
+
|
|
2230
|
+
var a0, a1, a2, a3, b1, b2, left_corner, right_corner;
|
|
2231
|
+
|
|
2232
|
+
function gaussCoef(sigma) {
|
|
2233
|
+
if (sigma < 0.5) {
|
|
2234
|
+
sigma = 0.5;
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
var a = Math.exp(0.726 * 0.726) / sigma,
|
|
2238
|
+
g1 = Math.exp(-a),
|
|
2239
|
+
g2 = Math.exp(-2 * a),
|
|
2240
|
+
k = (1 - g1) * (1 - g1) / (1 + 2 * a * g1 - g2);
|
|
2241
|
+
|
|
2242
|
+
a0 = k;
|
|
2243
|
+
a1 = k * (a - 1) * g1;
|
|
2244
|
+
a2 = k * (a + 1) * g1;
|
|
2245
|
+
a3 = -k * g2;
|
|
2246
|
+
b1 = 2 * g1;
|
|
2247
|
+
b2 = -g2;
|
|
2248
|
+
left_corner = (a0 + a1) / (1 - b1 - b2);
|
|
2249
|
+
right_corner = (a2 + a3) / (1 - b1 - b2);
|
|
2250
|
+
|
|
2251
|
+
// Attempt to force type to FP32.
|
|
2252
|
+
return new Float32Array([ a0, a1, a2, a3, b1, b2, left_corner, right_corner ]);
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
function convolveMono16(src, out, line, coeff, width, height) {
|
|
2256
|
+
// takes src image and writes the blurred and transposed result into out
|
|
2257
|
+
|
|
2258
|
+
var prev_src, curr_src, curr_out, prev_out, prev_prev_out;
|
|
2259
|
+
var src_index, out_index, line_index;
|
|
2260
|
+
var i, j;
|
|
2261
|
+
var coeff_a0, coeff_a1, coeff_b1, coeff_b2;
|
|
2262
|
+
|
|
2263
|
+
for (i = 0; i < height; i++) {
|
|
2264
|
+
src_index = i * width;
|
|
2265
|
+
out_index = i;
|
|
2266
|
+
line_index = 0;
|
|
2267
|
+
|
|
2268
|
+
// left to right
|
|
2269
|
+
prev_src = src[src_index];
|
|
2270
|
+
prev_prev_out = prev_src * coeff[6];
|
|
2271
|
+
prev_out = prev_prev_out;
|
|
2272
|
+
|
|
2273
|
+
coeff_a0 = coeff[0];
|
|
2274
|
+
coeff_a1 = coeff[1];
|
|
2275
|
+
coeff_b1 = coeff[4];
|
|
2276
|
+
coeff_b2 = coeff[5];
|
|
2277
|
+
|
|
2278
|
+
for (j = 0; j < width; j++) {
|
|
2279
|
+
curr_src = src[src_index];
|
|
2280
|
+
|
|
2281
|
+
curr_out = curr_src * coeff_a0 +
|
|
2282
|
+
prev_src * coeff_a1 +
|
|
2283
|
+
prev_out * coeff_b1 +
|
|
2284
|
+
prev_prev_out * coeff_b2;
|
|
2285
|
+
|
|
2286
|
+
prev_prev_out = prev_out;
|
|
2287
|
+
prev_out = curr_out;
|
|
2288
|
+
prev_src = curr_src;
|
|
2289
|
+
|
|
2290
|
+
line[line_index] = prev_out;
|
|
2291
|
+
line_index++;
|
|
2292
|
+
src_index++;
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
src_index--;
|
|
2296
|
+
line_index--;
|
|
2297
|
+
out_index += height * (width - 1);
|
|
2298
|
+
|
|
2299
|
+
// right to left
|
|
2300
|
+
prev_src = src[src_index];
|
|
2301
|
+
prev_prev_out = prev_src * coeff[7];
|
|
2302
|
+
prev_out = prev_prev_out;
|
|
2303
|
+
curr_src = prev_src;
|
|
2304
|
+
|
|
2305
|
+
coeff_a0 = coeff[2];
|
|
2306
|
+
coeff_a1 = coeff[3];
|
|
2307
|
+
|
|
2308
|
+
for (j = width - 1; j >= 0; j--) {
|
|
2309
|
+
curr_out = curr_src * coeff_a0 +
|
|
2310
|
+
prev_src * coeff_a1 +
|
|
2311
|
+
prev_out * coeff_b1 +
|
|
2312
|
+
prev_prev_out * coeff_b2;
|
|
2313
|
+
|
|
2314
|
+
prev_prev_out = prev_out;
|
|
2315
|
+
prev_out = curr_out;
|
|
2316
|
+
|
|
2317
|
+
prev_src = curr_src;
|
|
2318
|
+
curr_src = src[src_index];
|
|
2319
|
+
|
|
2320
|
+
out[out_index] = line[line_index] + prev_out;
|
|
2321
|
+
|
|
2322
|
+
src_index--;
|
|
2323
|
+
line_index--;
|
|
2324
|
+
out_index -= height;
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
|
|
2330
|
+
function blurMono16(src, width, height, radius) {
|
|
2331
|
+
// Quick exit on zero radius
|
|
2332
|
+
if (!radius) { return; }
|
|
2333
|
+
|
|
2334
|
+
var out = new Uint16Array(src.length),
|
|
2335
|
+
tmp_line = new Float32Array(Math.max(width, height));
|
|
2336
|
+
|
|
2337
|
+
var coeff = gaussCoef(radius);
|
|
2338
|
+
|
|
2339
|
+
convolveMono16(src, out, tmp_line, coeff, width, height);
|
|
2340
|
+
convolveMono16(out, src, tmp_line, coeff, height, width);
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
module.exports = blurMono16;
|
|
2344
|
+
|
|
2345
|
+
},{}],19:[function(_dereq_,module,exports){
|
|
2346
|
+
|
|
2347
|
+
|
|
2348
|
+
var assign = _dereq_('object-assign');
|
|
2349
|
+
var base64decode = _dereq_('./lib/base64decode');
|
|
2350
|
+
var hasWebAssembly = _dereq_('./lib/wa_detect');
|
|
2351
|
+
|
|
2352
|
+
|
|
2353
|
+
var DEFAULT_OPTIONS = {
|
|
2354
|
+
js: true,
|
|
2355
|
+
wasm: true
|
|
2356
|
+
};
|
|
2357
|
+
|
|
2358
|
+
|
|
2359
|
+
function MultiMath(options) {
|
|
2360
|
+
if (!(this instanceof MultiMath)) return new MultiMath(options);
|
|
2361
|
+
|
|
2362
|
+
var opts = assign({}, DEFAULT_OPTIONS, options || {});
|
|
2363
|
+
|
|
2364
|
+
this.options = opts;
|
|
2365
|
+
|
|
2366
|
+
this.__cache = {};
|
|
2367
|
+
|
|
2368
|
+
this.__init_promise = null;
|
|
2369
|
+
this.__modules = opts.modules || {};
|
|
2370
|
+
this.__memory = null;
|
|
2371
|
+
this.__wasm = {};
|
|
2372
|
+
|
|
2373
|
+
this.__isLE = ((new Uint32Array((new Uint8Array([ 1, 0, 0, 0 ])).buffer))[0] === 1);
|
|
2374
|
+
|
|
2375
|
+
if (!this.options.js && !this.options.wasm) {
|
|
2376
|
+
throw new Error('mathlib: at least "js" or "wasm" should be enabled');
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
|
|
2381
|
+
MultiMath.prototype.has_wasm = hasWebAssembly;
|
|
2382
|
+
|
|
2383
|
+
|
|
2384
|
+
MultiMath.prototype.use = function (module) {
|
|
2385
|
+
this.__modules[module.name] = module;
|
|
2386
|
+
|
|
2387
|
+
// Pin the best possible implementation
|
|
2388
|
+
if (this.options.wasm && this.has_wasm() && module.wasm_fn) {
|
|
2389
|
+
this[module.name] = module.wasm_fn;
|
|
2390
|
+
} else {
|
|
2391
|
+
this[module.name] = module.fn;
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
return this;
|
|
2395
|
+
};
|
|
2396
|
+
|
|
2397
|
+
|
|
2398
|
+
MultiMath.prototype.init = function () {
|
|
2399
|
+
if (this.__init_promise) return this.__init_promise;
|
|
2400
|
+
|
|
2401
|
+
if (!this.options.js && this.options.wasm && !this.has_wasm()) {
|
|
2402
|
+
return Promise.reject(new Error('mathlib: only "wasm" was enabled, but it\'s not supported'));
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
var self = this;
|
|
2406
|
+
|
|
2407
|
+
this.__init_promise = Promise.all(Object.keys(self.__modules).map(function (name) {
|
|
2408
|
+
var module = self.__modules[name];
|
|
2409
|
+
|
|
2410
|
+
if (!self.options.wasm || !self.has_wasm() || !module.wasm_fn) return null;
|
|
2411
|
+
|
|
2412
|
+
// If already compiled - exit
|
|
2413
|
+
if (self.__wasm[name]) return null;
|
|
2414
|
+
|
|
2415
|
+
// Compile wasm source
|
|
2416
|
+
return WebAssembly.compile(self.__base64decode(module.wasm_src))
|
|
2417
|
+
.then(function (m) { self.__wasm[name] = m; });
|
|
2418
|
+
}))
|
|
2419
|
+
.then(function () { return self; });
|
|
2420
|
+
|
|
2421
|
+
return this.__init_promise;
|
|
2422
|
+
};
|
|
2423
|
+
|
|
2424
|
+
|
|
2425
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
2426
|
+
// Methods below are for internal use from plugins
|
|
2427
|
+
|
|
2428
|
+
|
|
2429
|
+
// Simple decode base64 to typed array. Useful to load embedded webassembly
|
|
2430
|
+
// code. You probably don't need to call this method directly.
|
|
2431
|
+
//
|
|
2432
|
+
MultiMath.prototype.__base64decode = base64decode;
|
|
2433
|
+
|
|
2434
|
+
|
|
2435
|
+
// Increase current memory to include specified number of bytes. Do nothing if
|
|
2436
|
+
// size is already ok. You probably don't need to call this method directly,
|
|
2437
|
+
// because it will be invoked from `.__instance()`.
|
|
2438
|
+
//
|
|
2439
|
+
MultiMath.prototype.__reallocate = function mem_grow_to(bytes) {
|
|
2440
|
+
if (!this.__memory) {
|
|
2441
|
+
this.__memory = new WebAssembly.Memory({
|
|
2442
|
+
initial: Math.ceil(bytes / (64 * 1024))
|
|
2443
|
+
});
|
|
2444
|
+
return this.__memory;
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
var mem_size = this.__memory.buffer.byteLength;
|
|
2448
|
+
|
|
2449
|
+
if (mem_size < bytes) {
|
|
2450
|
+
this.__memory.grow(Math.ceil((bytes - mem_size) / (64 * 1024)));
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
return this.__memory;
|
|
2454
|
+
};
|
|
2455
|
+
|
|
2456
|
+
|
|
2457
|
+
// Returns instantinated webassembly item by name, with specified memory size
|
|
2458
|
+
// and environment.
|
|
2459
|
+
// - use cache if available
|
|
2460
|
+
// - do sync module init, if async init was not called earlier
|
|
2461
|
+
// - allocate memory if not enougth
|
|
2462
|
+
// - can export functions to webassembly via "env_extra",
|
|
2463
|
+
// for example, { exp: Math.exp }
|
|
2464
|
+
//
|
|
2465
|
+
MultiMath.prototype.__instance = function instance(name, memsize, env_extra) {
|
|
2466
|
+
if (memsize) this.__reallocate(memsize);
|
|
2467
|
+
|
|
2468
|
+
// If .init() was not called, do sync compile
|
|
2469
|
+
if (!this.__wasm[name]) {
|
|
2470
|
+
var module = this.__modules[name];
|
|
2471
|
+
this.__wasm[name] = new WebAssembly.Module(this.__base64decode(module.wasm_src));
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
if (!this.__cache[name]) {
|
|
2475
|
+
var env_base = {
|
|
2476
|
+
memoryBase: 0,
|
|
2477
|
+
memory: this.__memory,
|
|
2478
|
+
tableBase: 0,
|
|
2479
|
+
table: new WebAssembly.Table({ initial: 0, element: 'anyfunc' })
|
|
2480
|
+
};
|
|
2481
|
+
|
|
2482
|
+
this.__cache[name] = new WebAssembly.Instance(this.__wasm[name], {
|
|
2483
|
+
env: assign(env_base, env_extra || {})
|
|
2484
|
+
});
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
return this.__cache[name];
|
|
2488
|
+
};
|
|
2489
|
+
|
|
2490
|
+
|
|
2491
|
+
// Helper to calculate memory aligh for pointers. Webassembly does not require
|
|
2492
|
+
// this, but you may wish to experiment. Default base = 8;
|
|
2493
|
+
//
|
|
2494
|
+
MultiMath.prototype.__align = function align(number, base) {
|
|
2495
|
+
base = base || 8;
|
|
2496
|
+
var reminder = number % base;
|
|
2497
|
+
return number + (reminder ? base - reminder : 0);
|
|
2498
|
+
};
|
|
2499
|
+
|
|
2500
|
+
|
|
2501
|
+
module.exports = MultiMath;
|
|
2502
|
+
|
|
2503
|
+
},{"./lib/base64decode":20,"./lib/wa_detect":21,"object-assign":22}],20:[function(_dereq_,module,exports){
|
|
2504
|
+
|
|
2505
|
+
|
|
2506
|
+
var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
2507
|
+
|
|
2508
|
+
|
|
2509
|
+
module.exports = function base64decode(str) {
|
|
2510
|
+
var input = str.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan
|
|
2511
|
+
max = input.length;
|
|
2512
|
+
|
|
2513
|
+
var out = new Uint8Array((max * 3) >> 2);
|
|
2514
|
+
|
|
2515
|
+
// Collect by 6*4 bits (3 bytes)
|
|
2516
|
+
|
|
2517
|
+
var bits = 0;
|
|
2518
|
+
var ptr = 0;
|
|
2519
|
+
|
|
2520
|
+
for (var idx = 0; idx < max; idx++) {
|
|
2521
|
+
if ((idx % 4 === 0) && idx) {
|
|
2522
|
+
out[ptr++] = (bits >> 16) & 0xFF;
|
|
2523
|
+
out[ptr++] = (bits >> 8) & 0xFF;
|
|
2524
|
+
out[ptr++] = bits & 0xFF;
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
bits = (bits << 6) | BASE64_MAP.indexOf(input.charAt(idx));
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
// Dump tail
|
|
2531
|
+
|
|
2532
|
+
var tailbits = (max % 4) * 6;
|
|
2533
|
+
|
|
2534
|
+
if (tailbits === 0) {
|
|
2535
|
+
out[ptr++] = (bits >> 16) & 0xFF;
|
|
2536
|
+
out[ptr++] = (bits >> 8) & 0xFF;
|
|
2537
|
+
out[ptr++] = bits & 0xFF;
|
|
2538
|
+
} else if (tailbits === 18) {
|
|
2539
|
+
out[ptr++] = (bits >> 10) & 0xFF;
|
|
2540
|
+
out[ptr++] = (bits >> 2) & 0xFF;
|
|
2541
|
+
} else if (tailbits === 12) {
|
|
2542
|
+
out[ptr++] = (bits >> 4) & 0xFF;
|
|
2543
|
+
}
|
|
2544
|
+
|
|
2545
|
+
return out;
|
|
2546
|
+
};
|
|
2547
|
+
|
|
2548
|
+
},{}],21:[function(_dereq_,module,exports){
|
|
2549
|
+
|
|
2550
|
+
|
|
2551
|
+
var wa;
|
|
2552
|
+
|
|
2553
|
+
|
|
2554
|
+
module.exports = function hasWebAssembly() {
|
|
2555
|
+
// use cache if called before;
|
|
2556
|
+
if (typeof wa !== 'undefined') return wa;
|
|
2557
|
+
|
|
2558
|
+
wa = false;
|
|
2559
|
+
|
|
2560
|
+
if (typeof WebAssembly === 'undefined') return wa;
|
|
2561
|
+
|
|
2562
|
+
// If WebAssenbly is disabled, code can throw on compile
|
|
2563
|
+
try {
|
|
2564
|
+
// https://github.com/brion/min-wasm-fail/blob/master/min-wasm-fail.in.js
|
|
2565
|
+
// Additional check that WA internals are correct
|
|
2566
|
+
|
|
2567
|
+
/* eslint-disable comma-spacing, max-len */
|
|
2568
|
+
var bin = new Uint8Array([ 0,97,115,109,1,0,0,0,1,6,1,96,1,127,1,127,3,2,1,0,5,3,1,0,1,7,8,1,4,116,101,115,116,0,0,10,16,1,14,0,32,0,65,1,54,2,0,32,0,40,2,0,11 ]);
|
|
2569
|
+
var module = new WebAssembly.Module(bin);
|
|
2570
|
+
var instance = new WebAssembly.Instance(module, {});
|
|
2571
|
+
|
|
2572
|
+
// test storing to and loading from a non-zero location via a parameter.
|
|
2573
|
+
// Safari on iOS 11.2.5 returns 0 unexpectedly at non-zero locations
|
|
2574
|
+
if (instance.exports.test(4) !== 0) wa = true;
|
|
2575
|
+
|
|
2576
|
+
return wa;
|
|
2577
|
+
} catch (__) {}
|
|
2578
|
+
|
|
2579
|
+
return wa;
|
|
2580
|
+
};
|
|
2581
|
+
|
|
2582
|
+
},{}],22:[function(_dereq_,module,exports){
|
|
2583
|
+
/* eslint-disable no-unused-vars */
|
|
2584
|
+
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|
2585
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2586
|
+
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
2587
|
+
|
|
2588
|
+
function toObject(val) {
|
|
2589
|
+
if (val === null || val === undefined) {
|
|
2590
|
+
throw new TypeError('Object.assign cannot be called with null or undefined');
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
return Object(val);
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
function shouldUseNative() {
|
|
2597
|
+
try {
|
|
2598
|
+
if (!Object.assign) {
|
|
2599
|
+
return false;
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
// Detect buggy property enumeration order in older V8 versions.
|
|
2603
|
+
|
|
2604
|
+
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
|
|
2605
|
+
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
|
|
2606
|
+
test1[5] = 'de';
|
|
2607
|
+
if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
|
2608
|
+
return false;
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2611
|
+
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
|
2612
|
+
var test2 = {};
|
|
2613
|
+
for (var i = 0; i < 10; i++) {
|
|
2614
|
+
test2['_' + String.fromCharCode(i)] = i;
|
|
2615
|
+
}
|
|
2616
|
+
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
|
2617
|
+
return test2[n];
|
|
2618
|
+
});
|
|
2619
|
+
if (order2.join('') !== '0123456789') {
|
|
2620
|
+
return false;
|
|
2621
|
+
}
|
|
2622
|
+
|
|
2623
|
+
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
|
2624
|
+
var test3 = {};
|
|
2625
|
+
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
|
2626
|
+
test3[letter] = letter;
|
|
2627
|
+
});
|
|
2628
|
+
if (Object.keys(Object.assign({}, test3)).join('') !==
|
|
2629
|
+
'abcdefghijklmnopqrst') {
|
|
2630
|
+
return false;
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
return true;
|
|
2634
|
+
} catch (err) {
|
|
2635
|
+
// We don't expect any of the above to throw, but better to be safe.
|
|
2636
|
+
return false;
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
module.exports = shouldUseNative() ? Object.assign : function (target, source) {
|
|
2641
|
+
var from;
|
|
2642
|
+
var to = toObject(target);
|
|
2643
|
+
var symbols;
|
|
2644
|
+
|
|
2645
|
+
for (var s = 1; s < arguments.length; s++) {
|
|
2646
|
+
from = Object(arguments[s]);
|
|
2647
|
+
|
|
2648
|
+
for (var key in from) {
|
|
2649
|
+
if (hasOwnProperty.call(from, key)) {
|
|
2650
|
+
to[key] = from[key];
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2654
|
+
if (getOwnPropertySymbols) {
|
|
2655
|
+
symbols = getOwnPropertySymbols(from);
|
|
2656
|
+
for (var i = 0; i < symbols.length; i++) {
|
|
2657
|
+
if (propIsEnumerable.call(from, symbols[i])) {
|
|
2658
|
+
to[symbols[i]] = from[symbols[i]];
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
return to;
|
|
2665
|
+
};
|
|
2666
|
+
|
|
2667
|
+
},{}],23:[function(_dereq_,module,exports){
|
|
2668
|
+
var bundleFn = arguments[3];
|
|
2669
|
+
var sources = arguments[4];
|
|
2670
|
+
var cache = arguments[5];
|
|
2671
|
+
|
|
2672
|
+
var stringify = JSON.stringify;
|
|
2673
|
+
|
|
2674
|
+
module.exports = function (fn, options) {
|
|
2675
|
+
var wkey;
|
|
2676
|
+
var cacheKeys = Object.keys(cache);
|
|
2677
|
+
|
|
2678
|
+
for (var i = 0, l = cacheKeys.length; i < l; i++) {
|
|
2679
|
+
var key = cacheKeys[i];
|
|
2680
|
+
var exp = cache[key].exports;
|
|
2681
|
+
// Using babel as a transpiler to use esmodule, the export will always
|
|
2682
|
+
// be an object with the default export as a property of it. To ensure
|
|
2683
|
+
// the existing api and babel esmodule exports are both supported we
|
|
2684
|
+
// check for both
|
|
2685
|
+
if (exp === fn || exp && exp.default === fn) {
|
|
2686
|
+
wkey = key;
|
|
2687
|
+
break;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
if (!wkey) {
|
|
2692
|
+
wkey = Math.floor(Math.pow(16, 8) * Math.random()).toString(16);
|
|
2693
|
+
var wcache = {};
|
|
2694
|
+
for (var i = 0, l = cacheKeys.length; i < l; i++) {
|
|
2695
|
+
var key = cacheKeys[i];
|
|
2696
|
+
wcache[key] = key;
|
|
2697
|
+
}
|
|
2698
|
+
sources[wkey] = [
|
|
2699
|
+
'function(require,module,exports){' + fn + '(self); }',
|
|
2700
|
+
wcache
|
|
2701
|
+
];
|
|
2702
|
+
}
|
|
2703
|
+
var skey = Math.floor(Math.pow(16, 8) * Math.random()).toString(16);
|
|
2704
|
+
|
|
2705
|
+
var scache = {}; scache[wkey] = wkey;
|
|
2706
|
+
sources[skey] = [
|
|
2707
|
+
'function(require,module,exports){' +
|
|
2708
|
+
// try to call default if defined to also support babel esmodule exports
|
|
2709
|
+
'var f = require(' + stringify(wkey) + ');' +
|
|
2710
|
+
'(f.default ? f.default : f)(self);' +
|
|
2711
|
+
'}',
|
|
2712
|
+
scache
|
|
2713
|
+
];
|
|
2714
|
+
|
|
2715
|
+
var workerSources = {};
|
|
2716
|
+
resolveSources(skey);
|
|
2717
|
+
|
|
2718
|
+
function resolveSources(key) {
|
|
2719
|
+
workerSources[key] = true;
|
|
2720
|
+
|
|
2721
|
+
for (var depPath in sources[key][1]) {
|
|
2722
|
+
var depKey = sources[key][1][depPath];
|
|
2723
|
+
if (!workerSources[depKey]) {
|
|
2724
|
+
resolveSources(depKey);
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
|
|
2729
|
+
var src = '(' + bundleFn + ')({'
|
|
2730
|
+
+ Object.keys(workerSources).map(function (key) {
|
|
2731
|
+
return stringify(key) + ':['
|
|
2732
|
+
+ sources[key][0]
|
|
2733
|
+
+ ',' + stringify(sources[key][1]) + ']'
|
|
2734
|
+
;
|
|
2735
|
+
}).join(',')
|
|
2736
|
+
+ '},{},[' + stringify(skey) + '])'
|
|
2737
|
+
;
|
|
2738
|
+
|
|
2739
|
+
var URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
|
2740
|
+
|
|
2741
|
+
var blob = new Blob([src], { type: 'text/javascript' });
|
|
2742
|
+
if (options && options.bare) { return blob; }
|
|
2743
|
+
var workerUrl = URL.createObjectURL(blob);
|
|
2744
|
+
var worker = new Worker(workerUrl);
|
|
2745
|
+
worker.objectURL = workerUrl;
|
|
2746
|
+
return worker;
|
|
2747
|
+
};
|
|
2748
|
+
|
|
2749
|
+
},{}],"/index.js":[function(_dereq_,module,exports){
|
|
2750
|
+
|
|
2751
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2752
|
+
|
|
2753
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
2754
|
+
|
|
2755
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
2756
|
+
|
|
2757
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
2758
|
+
|
|
2759
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
2760
|
+
|
|
2761
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
2762
|
+
|
|
2763
|
+
var assign = _dereq_('object-assign');
|
|
2764
|
+
|
|
2765
|
+
var webworkify = _dereq_('webworkify');
|
|
2766
|
+
|
|
2767
|
+
var MathLib = _dereq_('./lib/mathlib');
|
|
2768
|
+
|
|
2769
|
+
var Pool = _dereq_('./lib/pool');
|
|
2770
|
+
|
|
2771
|
+
var utils = _dereq_('./lib/utils');
|
|
2772
|
+
|
|
2773
|
+
var worker = _dereq_('./lib/worker');
|
|
2774
|
+
|
|
2775
|
+
var createStages = _dereq_('./lib/stepper');
|
|
2776
|
+
|
|
2777
|
+
var createRegions = _dereq_('./lib/tiler');
|
|
2778
|
+
|
|
2779
|
+
var filter_info = _dereq_('./lib/mm_resize/resize_filter_info'); // Deduplicate pools & limiters with the same configs
|
|
2780
|
+
// when user creates multiple pica instances.
|
|
2781
|
+
|
|
2782
|
+
|
|
2783
|
+
var singletones = {};
|
|
2784
|
+
var NEED_SAFARI_FIX = false;
|
|
2785
|
+
|
|
2786
|
+
try {
|
|
2787
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent) {
|
|
2788
|
+
NEED_SAFARI_FIX = navigator.userAgent.indexOf('Safari') >= 0;
|
|
2789
|
+
}
|
|
2790
|
+
} catch (e) {}
|
|
2791
|
+
|
|
2792
|
+
var concurrency = 1;
|
|
2793
|
+
|
|
2794
|
+
if (typeof navigator !== 'undefined') {
|
|
2795
|
+
concurrency = Math.min(navigator.hardwareConcurrency || 1, 4);
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
var DEFAULT_PICA_OPTS = {
|
|
2799
|
+
tile: 1024,
|
|
2800
|
+
concurrency: concurrency,
|
|
2801
|
+
features: ['js', 'wasm', 'ww'],
|
|
2802
|
+
idle: 2000,
|
|
2803
|
+
createCanvas: function createCanvas(width, height) {
|
|
2804
|
+
var tmpCanvas = document.createElement('canvas');
|
|
2805
|
+
tmpCanvas.width = width;
|
|
2806
|
+
tmpCanvas.height = height;
|
|
2807
|
+
return tmpCanvas;
|
|
2808
|
+
}
|
|
2809
|
+
};
|
|
2810
|
+
var DEFAULT_RESIZE_OPTS = {
|
|
2811
|
+
filter: 'mks2013',
|
|
2812
|
+
unsharpAmount: 0,
|
|
2813
|
+
unsharpRadius: 0.0,
|
|
2814
|
+
unsharpThreshold: 0
|
|
2815
|
+
};
|
|
2816
|
+
var CAN_NEW_IMAGE_DATA = false;
|
|
2817
|
+
var CAN_CREATE_IMAGE_BITMAP = false;
|
|
2818
|
+
var CAN_USE_CANVAS_GET_IMAGE_DATA = false;
|
|
2819
|
+
var CAN_USE_OFFSCREEN_CANVAS = false;
|
|
2820
|
+
var CAN_USE_CIB_REGION_FOR_IMAGE = false;
|
|
2821
|
+
|
|
2822
|
+
function workerFabric() {
|
|
2823
|
+
return {
|
|
2824
|
+
value: webworkify(worker),
|
|
2825
|
+
destroy: function destroy() {
|
|
2826
|
+
this.value.terminate();
|
|
2827
|
+
|
|
2828
|
+
if (typeof window !== 'undefined') {
|
|
2829
|
+
var url = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
|
2830
|
+
|
|
2831
|
+
if (url && url.revokeObjectURL && this.value.objectURL) {
|
|
2832
|
+
url.revokeObjectURL(this.value.objectURL);
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2837
|
+
} ////////////////////////////////////////////////////////////////////////////////
|
|
2838
|
+
// API methods
|
|
2839
|
+
|
|
2840
|
+
|
|
2841
|
+
function Pica(options) {
|
|
2842
|
+
if (!(this instanceof Pica)) return new Pica(options);
|
|
2843
|
+
this.options = assign({}, DEFAULT_PICA_OPTS, options || {});
|
|
2844
|
+
var limiter_key = "lk_".concat(this.options.concurrency); // Share limiters to avoid multiple parallel workers when user creates
|
|
2845
|
+
// multiple pica instances.
|
|
2846
|
+
|
|
2847
|
+
this.__limit = singletones[limiter_key] || utils.limiter(this.options.concurrency);
|
|
2848
|
+
if (!singletones[limiter_key]) singletones[limiter_key] = this.__limit; // List of supported features, according to options & browser/node.js
|
|
2849
|
+
|
|
2850
|
+
this.features = {
|
|
2851
|
+
js: false,
|
|
2852
|
+
// pure JS implementation, can be disabled for testing
|
|
2853
|
+
wasm: false,
|
|
2854
|
+
// webassembly implementation for heavy functions
|
|
2855
|
+
cib: false,
|
|
2856
|
+
// resize via createImageBitmap (only FF at this moment)
|
|
2857
|
+
ww: false // webworkers
|
|
2858
|
+
|
|
2859
|
+
};
|
|
2860
|
+
this.__workersPool = null; // Store requested features for webworkers
|
|
2861
|
+
|
|
2862
|
+
this.__requested_features = [];
|
|
2863
|
+
this.__mathlib = null;
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
Pica.prototype.init = function () {
|
|
2867
|
+
var _this = this;
|
|
2868
|
+
|
|
2869
|
+
if (this.__initPromise) return this.__initPromise; // Test if we can create ImageData without canvas and memory copy
|
|
2870
|
+
|
|
2871
|
+
if (typeof ImageData !== 'undefined' && typeof Uint8ClampedArray !== 'undefined') {
|
|
2872
|
+
try {
|
|
2873
|
+
/* eslint-disable no-new */
|
|
2874
|
+
new ImageData(new Uint8ClampedArray(400), 10, 10);
|
|
2875
|
+
CAN_NEW_IMAGE_DATA = true;
|
|
2876
|
+
} catch (__) {}
|
|
2877
|
+
} // ImageBitmap can be effective in 2 places:
|
|
2878
|
+
//
|
|
2879
|
+
// 1. Threaded jpeg unpack (basic)
|
|
2880
|
+
// 2. Built-in resize (blocked due problem in chrome, see issue #89)
|
|
2881
|
+
//
|
|
2882
|
+
// For basic use we also need ImageBitmap wo support .close() method,
|
|
2883
|
+
// see https://developer.mozilla.org/ru/docs/Web/API/ImageBitmap
|
|
2884
|
+
|
|
2885
|
+
|
|
2886
|
+
if (typeof ImageBitmap !== 'undefined') {
|
|
2887
|
+
if (ImageBitmap.prototype && ImageBitmap.prototype.close) {
|
|
2888
|
+
CAN_CREATE_IMAGE_BITMAP = true;
|
|
2889
|
+
} else {
|
|
2890
|
+
this.debug('ImageBitmap does not support .close(), disabled');
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
var features = this.options.features.slice();
|
|
2895
|
+
|
|
2896
|
+
if (features.indexOf('all') >= 0) {
|
|
2897
|
+
features = ['cib', 'wasm', 'js', 'ww'];
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
this.__requested_features = features;
|
|
2901
|
+
this.__mathlib = new MathLib(features); // Check WebWorker support if requested
|
|
2902
|
+
|
|
2903
|
+
if (features.indexOf('ww') >= 0) {
|
|
2904
|
+
if (typeof window !== 'undefined' && 'Worker' in window) {
|
|
2905
|
+
// IE <= 11 don't allow to create webworkers from string. We should check it.
|
|
2906
|
+
// https://connect.microsoft.com/IE/feedback/details/801810/web-workers-from-blob-urls-in-ie-10-and-11
|
|
2907
|
+
try {
|
|
2908
|
+
var wkr = _dereq_('webworkify')(function () {});
|
|
2909
|
+
|
|
2910
|
+
wkr.terminate();
|
|
2911
|
+
this.features.ww = true; // pool uniqueness depends on pool config + webworker config
|
|
2912
|
+
|
|
2913
|
+
var wpool_key = "wp_".concat(JSON.stringify(this.options));
|
|
2914
|
+
|
|
2915
|
+
if (singletones[wpool_key]) {
|
|
2916
|
+
this.__workersPool = singletones[wpool_key];
|
|
2917
|
+
} else {
|
|
2918
|
+
this.__workersPool = new Pool(workerFabric, this.options.idle);
|
|
2919
|
+
singletones[wpool_key] = this.__workersPool;
|
|
2920
|
+
}
|
|
2921
|
+
} catch (__) {}
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2925
|
+
var initMath = this.__mathlib.init().then(function (mathlib) {
|
|
2926
|
+
// Copy detected features
|
|
2927
|
+
assign(_this.features, mathlib.features);
|
|
2928
|
+
});
|
|
2929
|
+
|
|
2930
|
+
var checkCibResize;
|
|
2931
|
+
|
|
2932
|
+
if (!CAN_CREATE_IMAGE_BITMAP) {
|
|
2933
|
+
checkCibResize = Promise.resolve(false);
|
|
2934
|
+
} else {
|
|
2935
|
+
checkCibResize = utils.cib_support(this.options.createCanvas).then(function (status) {
|
|
2936
|
+
if (_this.features.cib && features.indexOf('cib') < 0) {
|
|
2937
|
+
_this.debug('createImageBitmap() resize supported, but disabled by config');
|
|
2938
|
+
|
|
2939
|
+
return;
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
if (features.indexOf('cib') >= 0) _this.features.cib = status;
|
|
2943
|
+
});
|
|
2944
|
+
}
|
|
2945
|
+
|
|
2946
|
+
CAN_USE_CANVAS_GET_IMAGE_DATA = utils.can_use_canvas(this.options.createCanvas);
|
|
2947
|
+
var checkOffscreenCanvas;
|
|
2948
|
+
|
|
2949
|
+
if (CAN_CREATE_IMAGE_BITMAP && CAN_NEW_IMAGE_DATA && features.indexOf('ww') !== -1) {
|
|
2950
|
+
checkOffscreenCanvas = utils.worker_offscreen_canvas_support();
|
|
2951
|
+
} else {
|
|
2952
|
+
checkOffscreenCanvas = Promise.resolve(false);
|
|
2953
|
+
}
|
|
2954
|
+
|
|
2955
|
+
checkOffscreenCanvas = checkOffscreenCanvas.then(function (result) {
|
|
2956
|
+
CAN_USE_OFFSCREEN_CANVAS = result;
|
|
2957
|
+
}); // we use createImageBitmap to crop image data and pass it to workers,
|
|
2958
|
+
// so need to check whether function works correctly;
|
|
2959
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=1220671
|
|
2960
|
+
|
|
2961
|
+
var checkCibRegion = utils.cib_can_use_region().then(function (result) {
|
|
2962
|
+
CAN_USE_CIB_REGION_FOR_IMAGE = result;
|
|
2963
|
+
}); // Init math lib. That's async because can load some
|
|
2964
|
+
|
|
2965
|
+
this.__initPromise = Promise.all([initMath, checkCibResize, checkOffscreenCanvas, checkCibRegion]).then(function () {
|
|
2966
|
+
return _this;
|
|
2967
|
+
});
|
|
2968
|
+
return this.__initPromise;
|
|
2969
|
+
}; // Call resizer in webworker or locally, depending on config
|
|
2970
|
+
|
|
2971
|
+
|
|
2972
|
+
Pica.prototype.__invokeResize = function (tileOpts, opts) {
|
|
2973
|
+
var _this2 = this;
|
|
2974
|
+
|
|
2975
|
+
// Share cache between calls:
|
|
2976
|
+
//
|
|
2977
|
+
// - wasm instance
|
|
2978
|
+
// - wasm memory object
|
|
2979
|
+
//
|
|
2980
|
+
opts.__mathCache = opts.__mathCache || {};
|
|
2981
|
+
return Promise.resolve().then(function () {
|
|
2982
|
+
if (!_this2.features.ww) {
|
|
2983
|
+
// not possible to have ImageBitmap here if user disabled WW
|
|
2984
|
+
return {
|
|
2985
|
+
data: _this2.__mathlib.resizeAndUnsharp(tileOpts, opts.__mathCache)
|
|
2986
|
+
};
|
|
2987
|
+
}
|
|
2988
|
+
|
|
2989
|
+
return new Promise(function (resolve, reject) {
|
|
2990
|
+
var w = _this2.__workersPool.acquire();
|
|
2991
|
+
|
|
2992
|
+
if (opts.cancelToken) opts.cancelToken["catch"](function (err) {
|
|
2993
|
+
return reject(err);
|
|
2994
|
+
});
|
|
2995
|
+
|
|
2996
|
+
w.value.onmessage = function (ev) {
|
|
2997
|
+
w.release();
|
|
2998
|
+
if (ev.data.err) reject(ev.data.err);else resolve(ev.data);
|
|
2999
|
+
};
|
|
3000
|
+
|
|
3001
|
+
var transfer = [];
|
|
3002
|
+
if (tileOpts.src) transfer.push(tileOpts.src.buffer);
|
|
3003
|
+
if (tileOpts.srcBitmap) transfer.push(tileOpts.srcBitmap);
|
|
3004
|
+
w.value.postMessage({
|
|
3005
|
+
opts: tileOpts,
|
|
3006
|
+
features: _this2.__requested_features,
|
|
3007
|
+
preload: {
|
|
3008
|
+
wasm_nodule: _this2.__mathlib.__
|
|
3009
|
+
}
|
|
3010
|
+
}, transfer);
|
|
3011
|
+
});
|
|
3012
|
+
});
|
|
3013
|
+
}; // this function can return promise if createImageBitmap is used
|
|
3014
|
+
|
|
3015
|
+
|
|
3016
|
+
Pica.prototype.__extractTileData = function (tile, from, opts, stageEnv, extractTo) {
|
|
3017
|
+
if (this.features.ww && CAN_USE_OFFSCREEN_CANVAS && ( // createImageBitmap doesn't work for images (Image, ImageBitmap) with Exif orientation in Chrome,
|
|
3018
|
+
// can use canvas because canvas doesn't have orientation;
|
|
3019
|
+
// see https://bugs.chromium.org/p/chromium/issues/detail?id=1220671
|
|
3020
|
+
utils.isCanvas(from) || CAN_USE_CIB_REGION_FOR_IMAGE)) {
|
|
3021
|
+
this.debug('Create tile for OffscreenCanvas');
|
|
3022
|
+
return createImageBitmap(stageEnv.srcImageBitmap || from, tile.x, tile.y, tile.width, tile.height).then(function (bitmap) {
|
|
3023
|
+
extractTo.srcBitmap = bitmap;
|
|
3024
|
+
return extractTo;
|
|
3025
|
+
});
|
|
3026
|
+
} // Extract tile RGBA buffer, depending on input type
|
|
3027
|
+
|
|
3028
|
+
|
|
3029
|
+
if (utils.isCanvas(from)) {
|
|
3030
|
+
if (!stageEnv.srcCtx) stageEnv.srcCtx = from.getContext('2d'); // If input is Canvas - extract region data directly
|
|
3031
|
+
|
|
3032
|
+
this.debug('Get tile pixel data');
|
|
3033
|
+
extractTo.src = stageEnv.srcCtx.getImageData(tile.x, tile.y, tile.width, tile.height).data;
|
|
3034
|
+
return extractTo;
|
|
3035
|
+
} // If input is Image or decoded to ImageBitmap,
|
|
3036
|
+
// draw region to temporary canvas and extract data from it
|
|
3037
|
+
//
|
|
3038
|
+
// Note! Attempt to reuse this canvas causes significant slowdown in chrome
|
|
3039
|
+
//
|
|
3040
|
+
|
|
3041
|
+
|
|
3042
|
+
this.debug('Draw tile imageBitmap/image to temporary canvas');
|
|
3043
|
+
var tmpCanvas = this.options.createCanvas(tile.width, tile.height);
|
|
3044
|
+
var tmpCtx = tmpCanvas.getContext('2d');
|
|
3045
|
+
tmpCtx.globalCompositeOperation = 'copy';
|
|
3046
|
+
tmpCtx.drawImage(stageEnv.srcImageBitmap || from, tile.x, tile.y, tile.width, tile.height, 0, 0, tile.width, tile.height);
|
|
3047
|
+
this.debug('Get tile pixel data');
|
|
3048
|
+
extractTo.src = tmpCtx.getImageData(0, 0, tile.width, tile.height).data; // Safari 12 workaround
|
|
3049
|
+
// https://github.com/nodeca/pica/issues/199
|
|
3050
|
+
|
|
3051
|
+
tmpCanvas.width = tmpCanvas.height = 0;
|
|
3052
|
+
return extractTo;
|
|
3053
|
+
};
|
|
3054
|
+
|
|
3055
|
+
Pica.prototype.__landTileData = function (tile, result, stageEnv) {
|
|
3056
|
+
var toImageData;
|
|
3057
|
+
this.debug('Convert raw rgba tile result to ImageData');
|
|
3058
|
+
|
|
3059
|
+
if (result.bitmap) {
|
|
3060
|
+
stageEnv.toCtx.drawImage(result.bitmap, tile.toX, tile.toY);
|
|
3061
|
+
return null;
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
if (CAN_NEW_IMAGE_DATA) {
|
|
3065
|
+
// this branch is for modern browsers
|
|
3066
|
+
// If `new ImageData()` & Uint8ClampedArray suported
|
|
3067
|
+
toImageData = new ImageData(new Uint8ClampedArray(result.data), tile.toWidth, tile.toHeight);
|
|
3068
|
+
} else {
|
|
3069
|
+
// fallback for `node-canvas` and old browsers
|
|
3070
|
+
// (IE11 has ImageData but does not support `new ImageData()`)
|
|
3071
|
+
toImageData = stageEnv.toCtx.createImageData(tile.toWidth, tile.toHeight);
|
|
3072
|
+
|
|
3073
|
+
if (toImageData.data.set) {
|
|
3074
|
+
toImageData.data.set(result.data);
|
|
3075
|
+
} else {
|
|
3076
|
+
// IE9 don't have `.set()`
|
|
3077
|
+
for (var i = toImageData.data.length - 1; i >= 0; i--) {
|
|
3078
|
+
toImageData.data[i] = result.data[i];
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
this.debug('Draw tile');
|
|
3084
|
+
|
|
3085
|
+
if (NEED_SAFARI_FIX) {
|
|
3086
|
+
// Safari draws thin white stripes between tiles without this fix
|
|
3087
|
+
stageEnv.toCtx.putImageData(toImageData, tile.toX, tile.toY, tile.toInnerX - tile.toX, tile.toInnerY - tile.toY, tile.toInnerWidth + 1e-5, tile.toInnerHeight + 1e-5);
|
|
3088
|
+
} else {
|
|
3089
|
+
stageEnv.toCtx.putImageData(toImageData, tile.toX, tile.toY, tile.toInnerX - tile.toX, tile.toInnerY - tile.toY, tile.toInnerWidth, tile.toInnerHeight);
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
return null;
|
|
3093
|
+
};
|
|
3094
|
+
|
|
3095
|
+
Pica.prototype.__tileAndResize = function (from, to, opts) {
|
|
3096
|
+
var _this3 = this;
|
|
3097
|
+
|
|
3098
|
+
var stageEnv = {
|
|
3099
|
+
srcCtx: null,
|
|
3100
|
+
srcImageBitmap: null,
|
|
3101
|
+
isImageBitmapReused: false,
|
|
3102
|
+
toCtx: null
|
|
3103
|
+
};
|
|
3104
|
+
|
|
3105
|
+
var processTile = function processTile(tile) {
|
|
3106
|
+
return _this3.__limit(function () {
|
|
3107
|
+
if (opts.canceled) return opts.cancelToken;
|
|
3108
|
+
var tileOpts = {
|
|
3109
|
+
width: tile.width,
|
|
3110
|
+
height: tile.height,
|
|
3111
|
+
toWidth: tile.toWidth,
|
|
3112
|
+
toHeight: tile.toHeight,
|
|
3113
|
+
scaleX: tile.scaleX,
|
|
3114
|
+
scaleY: tile.scaleY,
|
|
3115
|
+
offsetX: tile.offsetX,
|
|
3116
|
+
offsetY: tile.offsetY,
|
|
3117
|
+
filter: opts.filter,
|
|
3118
|
+
unsharpAmount: opts.unsharpAmount,
|
|
3119
|
+
unsharpRadius: opts.unsharpRadius,
|
|
3120
|
+
unsharpThreshold: opts.unsharpThreshold
|
|
3121
|
+
};
|
|
3122
|
+
|
|
3123
|
+
_this3.debug('Invoke resize math');
|
|
3124
|
+
|
|
3125
|
+
return Promise.resolve(tileOpts).then(function (tileOpts) {
|
|
3126
|
+
return _this3.__extractTileData(tile, from, opts, stageEnv, tileOpts);
|
|
3127
|
+
}).then(function (tileOpts) {
|
|
3128
|
+
_this3.debug('Invoke resize math');
|
|
3129
|
+
|
|
3130
|
+
return _this3.__invokeResize(tileOpts, opts);
|
|
3131
|
+
}).then(function (result) {
|
|
3132
|
+
if (opts.canceled) return opts.cancelToken;
|
|
3133
|
+
stageEnv.srcImageData = null;
|
|
3134
|
+
return _this3.__landTileData(tile, result, stageEnv);
|
|
3135
|
+
});
|
|
3136
|
+
});
|
|
3137
|
+
}; // Need to normalize data source first. It can be canvas or image.
|
|
3138
|
+
// If image - try to decode in background if possible
|
|
3139
|
+
|
|
3140
|
+
|
|
3141
|
+
return Promise.resolve().then(function () {
|
|
3142
|
+
stageEnv.toCtx = to.getContext('2d');
|
|
3143
|
+
if (utils.isCanvas(from)) return null;
|
|
3144
|
+
|
|
3145
|
+
if (utils.isImageBitmap(from)) {
|
|
3146
|
+
stageEnv.srcImageBitmap = from;
|
|
3147
|
+
stageEnv.isImageBitmapReused = true;
|
|
3148
|
+
return null;
|
|
3149
|
+
}
|
|
3150
|
+
|
|
3151
|
+
if (utils.isImage(from)) {
|
|
3152
|
+
// try do decode image in background for faster next operations;
|
|
3153
|
+
// if we're using offscreen canvas, cib is called per tile, so not needed here
|
|
3154
|
+
if (!CAN_CREATE_IMAGE_BITMAP) return null;
|
|
3155
|
+
|
|
3156
|
+
_this3.debug('Decode image via createImageBitmap');
|
|
3157
|
+
|
|
3158
|
+
return createImageBitmap(from).then(function (imageBitmap) {
|
|
3159
|
+
stageEnv.srcImageBitmap = imageBitmap;
|
|
3160
|
+
}) // Suppress error to use fallback, if method fails
|
|
3161
|
+
// https://github.com/nodeca/pica/issues/190
|
|
3162
|
+
|
|
3163
|
+
/* eslint-disable no-unused-vars */
|
|
3164
|
+
["catch"](function (e) {
|
|
3165
|
+
return null;
|
|
3166
|
+
});
|
|
3167
|
+
}
|
|
3168
|
+
|
|
3169
|
+
throw new Error('Pica: ".from" should be Image, Canvas or ImageBitmap');
|
|
3170
|
+
}).then(function () {
|
|
3171
|
+
if (opts.canceled) return opts.cancelToken;
|
|
3172
|
+
|
|
3173
|
+
_this3.debug('Calculate tiles'); //
|
|
3174
|
+
// Here we are with "normalized" source,
|
|
3175
|
+
// follow to tiling
|
|
3176
|
+
//
|
|
3177
|
+
|
|
3178
|
+
|
|
3179
|
+
var regions = createRegions({
|
|
3180
|
+
width: opts.width,
|
|
3181
|
+
height: opts.height,
|
|
3182
|
+
srcTileSize: _this3.options.tile,
|
|
3183
|
+
toWidth: opts.toWidth,
|
|
3184
|
+
toHeight: opts.toHeight,
|
|
3185
|
+
destTileBorder: opts.__destTileBorder
|
|
3186
|
+
});
|
|
3187
|
+
var jobs = regions.map(function (tile) {
|
|
3188
|
+
return processTile(tile);
|
|
3189
|
+
});
|
|
3190
|
+
|
|
3191
|
+
function cleanup(stageEnv) {
|
|
3192
|
+
if (stageEnv.srcImageBitmap) {
|
|
3193
|
+
if (!stageEnv.isImageBitmapReused) stageEnv.srcImageBitmap.close();
|
|
3194
|
+
stageEnv.srcImageBitmap = null;
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
|
|
3198
|
+
_this3.debug('Process tiles');
|
|
3199
|
+
|
|
3200
|
+
return Promise.all(jobs).then(function () {
|
|
3201
|
+
_this3.debug('Finished!');
|
|
3202
|
+
|
|
3203
|
+
cleanup(stageEnv);
|
|
3204
|
+
return to;
|
|
3205
|
+
}, function (err) {
|
|
3206
|
+
cleanup(stageEnv);
|
|
3207
|
+
throw err;
|
|
3208
|
+
});
|
|
3209
|
+
});
|
|
3210
|
+
};
|
|
3211
|
+
|
|
3212
|
+
Pica.prototype.__processStages = function (stages, from, to, opts) {
|
|
3213
|
+
var _this4 = this;
|
|
3214
|
+
|
|
3215
|
+
if (opts.canceled) return opts.cancelToken;
|
|
3216
|
+
|
|
3217
|
+
var _stages$shift = stages.shift(),
|
|
3218
|
+
_stages$shift2 = _slicedToArray(_stages$shift, 2),
|
|
3219
|
+
toWidth = _stages$shift2[0],
|
|
3220
|
+
toHeight = _stages$shift2[1];
|
|
3221
|
+
|
|
3222
|
+
var isLastStage = stages.length === 0; // Optimization for legacy filters -
|
|
3223
|
+
// only use user-defined quality for the last stage,
|
|
3224
|
+
// use simpler (Hamming) filter for the first stages where
|
|
3225
|
+
// scale factor is large enough (more than 2-3)
|
|
3226
|
+
//
|
|
3227
|
+
// For advanced filters (mks2013 and custom) - skip optimization,
|
|
3228
|
+
// because need to apply sharpening every time
|
|
3229
|
+
|
|
3230
|
+
var filter;
|
|
3231
|
+
if (isLastStage || filter_info.q2f.indexOf(opts.filter) < 0) filter = opts.filter;else if (opts.filter === 'box') filter = 'box';else filter = 'hamming';
|
|
3232
|
+
opts = assign({}, opts, {
|
|
3233
|
+
toWidth: toWidth,
|
|
3234
|
+
toHeight: toHeight,
|
|
3235
|
+
filter: filter
|
|
3236
|
+
});
|
|
3237
|
+
var tmpCanvas;
|
|
3238
|
+
|
|
3239
|
+
if (!isLastStage) {
|
|
3240
|
+
// create temporary canvas
|
|
3241
|
+
tmpCanvas = this.options.createCanvas(toWidth, toHeight);
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3244
|
+
return this.__tileAndResize(from, isLastStage ? to : tmpCanvas, opts).then(function () {
|
|
3245
|
+
if (isLastStage) return to;
|
|
3246
|
+
opts.width = toWidth;
|
|
3247
|
+
opts.height = toHeight;
|
|
3248
|
+
return _this4.__processStages(stages, tmpCanvas, to, opts);
|
|
3249
|
+
}).then(function (res) {
|
|
3250
|
+
if (tmpCanvas) {
|
|
3251
|
+
// Safari 12 workaround
|
|
3252
|
+
// https://github.com/nodeca/pica/issues/199
|
|
3253
|
+
tmpCanvas.width = tmpCanvas.height = 0;
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3256
|
+
return res;
|
|
3257
|
+
});
|
|
3258
|
+
};
|
|
3259
|
+
|
|
3260
|
+
Pica.prototype.__resizeViaCreateImageBitmap = function (from, to, opts) {
|
|
3261
|
+
var _this5 = this;
|
|
3262
|
+
|
|
3263
|
+
var toCtx = to.getContext('2d');
|
|
3264
|
+
this.debug('Resize via createImageBitmap()');
|
|
3265
|
+
return createImageBitmap(from, {
|
|
3266
|
+
resizeWidth: opts.toWidth,
|
|
3267
|
+
resizeHeight: opts.toHeight,
|
|
3268
|
+
resizeQuality: utils.cib_quality_name(filter_info.f2q[opts.filter])
|
|
3269
|
+
}).then(function (imageBitmap) {
|
|
3270
|
+
if (opts.canceled) return opts.cancelToken; // if no unsharp - draw directly to output canvas
|
|
3271
|
+
|
|
3272
|
+
if (!opts.unsharpAmount) {
|
|
3273
|
+
toCtx.drawImage(imageBitmap, 0, 0);
|
|
3274
|
+
imageBitmap.close();
|
|
3275
|
+
toCtx = null;
|
|
3276
|
+
|
|
3277
|
+
_this5.debug('Finished!');
|
|
3278
|
+
|
|
3279
|
+
return to;
|
|
3280
|
+
}
|
|
3281
|
+
|
|
3282
|
+
_this5.debug('Unsharp result');
|
|
3283
|
+
|
|
3284
|
+
var tmpCanvas = _this5.options.createCanvas(opts.toWidth, opts.toHeight);
|
|
3285
|
+
|
|
3286
|
+
var tmpCtx = tmpCanvas.getContext('2d');
|
|
3287
|
+
tmpCtx.drawImage(imageBitmap, 0, 0);
|
|
3288
|
+
imageBitmap.close();
|
|
3289
|
+
var iData = tmpCtx.getImageData(0, 0, opts.toWidth, opts.toHeight);
|
|
3290
|
+
|
|
3291
|
+
_this5.__mathlib.unsharp_mask(iData.data, opts.toWidth, opts.toHeight, opts.unsharpAmount, opts.unsharpRadius, opts.unsharpThreshold);
|
|
3292
|
+
|
|
3293
|
+
toCtx.putImageData(iData, 0, 0); // Safari 12 workaround
|
|
3294
|
+
// https://github.com/nodeca/pica/issues/199
|
|
3295
|
+
|
|
3296
|
+
tmpCanvas.width = tmpCanvas.height = 0;
|
|
3297
|
+
iData = tmpCtx = tmpCanvas = toCtx = null;
|
|
3298
|
+
|
|
3299
|
+
_this5.debug('Finished!');
|
|
3300
|
+
|
|
3301
|
+
return to;
|
|
3302
|
+
});
|
|
3303
|
+
};
|
|
3304
|
+
|
|
3305
|
+
Pica.prototype.resize = function (from, to, options) {
|
|
3306
|
+
var _this6 = this;
|
|
3307
|
+
|
|
3308
|
+
this.debug('Start resize...');
|
|
3309
|
+
var opts = assign({}, DEFAULT_RESIZE_OPTS);
|
|
3310
|
+
|
|
3311
|
+
if (!isNaN(options)) {
|
|
3312
|
+
opts = assign(opts, {
|
|
3313
|
+
quality: options
|
|
3314
|
+
});
|
|
3315
|
+
} else if (options) {
|
|
3316
|
+
opts = assign(opts, options);
|
|
3317
|
+
}
|
|
3318
|
+
|
|
3319
|
+
opts.toWidth = to.width;
|
|
3320
|
+
opts.toHeight = to.height;
|
|
3321
|
+
opts.width = from.naturalWidth || from.width;
|
|
3322
|
+
opts.height = from.naturalHeight || from.height; // Legacy `.quality` option
|
|
3323
|
+
|
|
3324
|
+
if (Object.prototype.hasOwnProperty.call(opts, 'quality')) {
|
|
3325
|
+
if (opts.quality < 0 || opts.quality > 3) {
|
|
3326
|
+
throw new Error("Pica: .quality should be [0..3], got ".concat(opts.quality));
|
|
3327
|
+
}
|
|
3328
|
+
|
|
3329
|
+
opts.filter = filter_info.q2f[opts.quality];
|
|
3330
|
+
} // Prevent stepper from infinite loop
|
|
3331
|
+
|
|
3332
|
+
|
|
3333
|
+
if (to.width === 0 || to.height === 0) {
|
|
3334
|
+
return Promise.reject(new Error("Invalid output size: ".concat(to.width, "x").concat(to.height)));
|
|
3335
|
+
}
|
|
3336
|
+
|
|
3337
|
+
if (opts.unsharpRadius > 2) opts.unsharpRadius = 2;
|
|
3338
|
+
opts.canceled = false;
|
|
3339
|
+
|
|
3340
|
+
if (opts.cancelToken) {
|
|
3341
|
+
// Wrap cancelToken to avoid successive resolve & set flag
|
|
3342
|
+
opts.cancelToken = opts.cancelToken.then(function (data) {
|
|
3343
|
+
opts.canceled = true;
|
|
3344
|
+
throw data;
|
|
3345
|
+
}, function (err) {
|
|
3346
|
+
opts.canceled = true;
|
|
3347
|
+
throw err;
|
|
3348
|
+
});
|
|
3349
|
+
}
|
|
3350
|
+
|
|
3351
|
+
var DEST_TILE_BORDER = 3; // Max possible filter window size
|
|
3352
|
+
|
|
3353
|
+
opts.__destTileBorder = Math.ceil(Math.max(DEST_TILE_BORDER, 2.5 * opts.unsharpRadius | 0));
|
|
3354
|
+
return this.init().then(function () {
|
|
3355
|
+
if (opts.canceled) return opts.cancelToken; // if createImageBitmap supports resize, just do it and return
|
|
3356
|
+
|
|
3357
|
+
if (_this6.features.cib) {
|
|
3358
|
+
if (filter_info.q2f.indexOf(opts.filter) >= 0) {
|
|
3359
|
+
return _this6.__resizeViaCreateImageBitmap(from, to, opts);
|
|
3360
|
+
}
|
|
3361
|
+
|
|
3362
|
+
_this6.debug('cib is enabled, but not supports provided filter, fallback to manual math');
|
|
3363
|
+
}
|
|
3364
|
+
|
|
3365
|
+
if (!CAN_USE_CANVAS_GET_IMAGE_DATA) {
|
|
3366
|
+
var err = new Error('Pica: cannot use getImageData on canvas, ' + "make sure fingerprinting protection isn't enabled");
|
|
3367
|
+
err.code = 'ERR_GET_IMAGE_DATA';
|
|
3368
|
+
throw err;
|
|
3369
|
+
} //
|
|
3370
|
+
// No easy way, let's resize manually via arrays
|
|
3371
|
+
//
|
|
3372
|
+
|
|
3373
|
+
|
|
3374
|
+
var stages = createStages(opts.width, opts.height, opts.toWidth, opts.toHeight, _this6.options.tile, opts.__destTileBorder);
|
|
3375
|
+
return _this6.__processStages(stages, from, to, opts);
|
|
3376
|
+
});
|
|
3377
|
+
}; // RGBA buffer resize
|
|
3378
|
+
//
|
|
3379
|
+
|
|
3380
|
+
|
|
3381
|
+
Pica.prototype.resizeBuffer = function (options) {
|
|
3382
|
+
var _this7 = this;
|
|
3383
|
+
|
|
3384
|
+
var opts = assign({}, DEFAULT_RESIZE_OPTS, options); // Legacy `.quality` option
|
|
3385
|
+
|
|
3386
|
+
if (Object.prototype.hasOwnProperty.call(opts, 'quality')) {
|
|
3387
|
+
if (opts.quality < 0 || opts.quality > 3) {
|
|
3388
|
+
throw new Error("Pica: .quality should be [0..3], got ".concat(opts.quality));
|
|
3389
|
+
}
|
|
3390
|
+
|
|
3391
|
+
opts.filter = filter_info.q2f[opts.quality];
|
|
3392
|
+
}
|
|
3393
|
+
|
|
3394
|
+
return this.init().then(function () {
|
|
3395
|
+
return _this7.__mathlib.resizeAndUnsharp(opts);
|
|
3396
|
+
});
|
|
3397
|
+
};
|
|
3398
|
+
|
|
3399
|
+
Pica.prototype.toBlob = function (canvas, mimeType, quality) {
|
|
3400
|
+
mimeType = mimeType || 'image/png';
|
|
3401
|
+
return new Promise(function (resolve) {
|
|
3402
|
+
if (canvas.toBlob) {
|
|
3403
|
+
canvas.toBlob(function (blob) {
|
|
3404
|
+
return resolve(blob);
|
|
3405
|
+
}, mimeType, quality);
|
|
3406
|
+
return;
|
|
3407
|
+
}
|
|
3408
|
+
|
|
3409
|
+
if (canvas.convertToBlob) {
|
|
3410
|
+
resolve(canvas.convertToBlob({
|
|
3411
|
+
type: mimeType,
|
|
3412
|
+
quality: quality
|
|
3413
|
+
}));
|
|
3414
|
+
return;
|
|
3415
|
+
} // Fallback for old browsers
|
|
3416
|
+
|
|
3417
|
+
|
|
3418
|
+
var asString = atob(canvas.toDataURL(mimeType, quality).split(',')[1]);
|
|
3419
|
+
var len = asString.length;
|
|
3420
|
+
var asBuffer = new Uint8Array(len);
|
|
3421
|
+
|
|
3422
|
+
for (var i = 0; i < len; i++) {
|
|
3423
|
+
asBuffer[i] = asString.charCodeAt(i);
|
|
3424
|
+
}
|
|
3425
|
+
|
|
3426
|
+
resolve(new Blob([asBuffer], {
|
|
3427
|
+
type: mimeType
|
|
3428
|
+
}));
|
|
3429
|
+
});
|
|
3430
|
+
};
|
|
3431
|
+
|
|
3432
|
+
Pica.prototype.debug = function () {};
|
|
3433
|
+
|
|
3434
|
+
module.exports = Pica;
|
|
3435
|
+
|
|
3436
|
+
},{"./lib/mathlib":1,"./lib/mm_resize/resize_filter_info":7,"./lib/pool":13,"./lib/stepper":14,"./lib/tiler":15,"./lib/utils":16,"./lib/worker":17,"object-assign":22,"webworkify":23}]},{},[])("/index.js")
|
|
3437
|
+
});
|
|
3438
|
+
}(pica$1));
|
|
3439
|
+
|
|
3440
|
+
var jpeg_plugins = {};
|
|
3441
|
+
|
|
3442
|
+
var image_traverse$1 = {exports: {}};
|
|
3443
|
+
|
|
3444
|
+
(function (module) {
|
|
3445
|
+
|
|
3446
|
+
//////////////////////////////////////////////////////////////////////////
|
|
3447
|
+
// Helpers
|
|
3448
|
+
//
|
|
3449
|
+
function error(message, code) {
|
|
3450
|
+
var err = new Error(message);
|
|
3451
|
+
err.code = code;
|
|
3452
|
+
return err;
|
|
3453
|
+
}
|
|
3454
|
+
|
|
3455
|
+
|
|
3456
|
+
// Convert number to 0xHH string
|
|
3457
|
+
//
|
|
3458
|
+
function to_hex(number) {
|
|
3459
|
+
var n = number.toString(16).toUpperCase();
|
|
3460
|
+
for (var i = 2 - n.length; i > 0; i--) n = '0' + n;
|
|
3461
|
+
return '0x' + n;
|
|
3462
|
+
}
|
|
3463
|
+
|
|
3464
|
+
|
|
3465
|
+
function utf8_encode(str) {
|
|
3466
|
+
try {
|
|
3467
|
+
return unescape(encodeURIComponent(str));
|
|
3468
|
+
} catch (_) {
|
|
3469
|
+
return str;
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
|
|
3473
|
+
|
|
3474
|
+
function utf8_decode(str) {
|
|
3475
|
+
try {
|
|
3476
|
+
return decodeURIComponent(escape(str));
|
|
3477
|
+
} catch (_) {
|
|
3478
|
+
return str;
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
|
|
3482
|
+
|
|
3483
|
+
// Check if input is a Uint8Array
|
|
3484
|
+
//
|
|
3485
|
+
function is_uint8array(bin) {
|
|
3486
|
+
return Object.prototype.toString.call(bin) === '[object Uint8Array]';
|
|
3487
|
+
}
|
|
3488
|
+
|
|
3489
|
+
|
|
3490
|
+
//////////////////////////////////////////////////////////////////////////
|
|
3491
|
+
// Exif parser
|
|
3492
|
+
//
|
|
3493
|
+
// Input:
|
|
3494
|
+
// - jpeg_bin: Uint8Array - jpeg file
|
|
3495
|
+
// - exif_start: Number - start of TIFF header (after Exif\0\0)
|
|
3496
|
+
// - exif_end: Number - end of Exif segment
|
|
3497
|
+
// - on_entry: Number - callback
|
|
3498
|
+
//
|
|
3499
|
+
function ExifParser(jpeg_bin, exif_start, exif_end) {
|
|
3500
|
+
// Uint8Array, exif without signature (which isn't included in offsets)
|
|
3501
|
+
this.input = jpeg_bin.subarray(exif_start, exif_end);
|
|
3502
|
+
|
|
3503
|
+
// offset correction for `on_entry` callback
|
|
3504
|
+
this.start = exif_start;
|
|
3505
|
+
|
|
3506
|
+
// Check TIFF header (includes byte alignment and first IFD offset)
|
|
3507
|
+
var sig = String.fromCharCode.apply(null, this.input.subarray(0, 4));
|
|
3508
|
+
|
|
3509
|
+
if (sig !== 'II\x2A\0' && sig !== 'MM\0\x2A') {
|
|
3510
|
+
throw error('invalid TIFF signature', 'EBADDATA');
|
|
3511
|
+
}
|
|
3512
|
+
|
|
3513
|
+
// true if motorola (big endian) byte alignment, false if intel
|
|
3514
|
+
this.big_endian = sig[0] === 'M';
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
|
|
3518
|
+
ExifParser.prototype.each = function (on_entry) {
|
|
3519
|
+
// allow premature exit
|
|
3520
|
+
this.aborted = false;
|
|
3521
|
+
|
|
3522
|
+
var offset = this.read_uint32(4);
|
|
3523
|
+
|
|
3524
|
+
this.ifds_to_read = [ {
|
|
3525
|
+
id: 0,
|
|
3526
|
+
offset: offset
|
|
3527
|
+
} ];
|
|
3528
|
+
|
|
3529
|
+
while (this.ifds_to_read.length > 0 && !this.aborted) {
|
|
3530
|
+
var i = this.ifds_to_read.shift();
|
|
3531
|
+
if (!i.offset) continue;
|
|
3532
|
+
this.scan_ifd(i.id, i.offset, on_entry);
|
|
3533
|
+
}
|
|
3534
|
+
};
|
|
3535
|
+
|
|
3536
|
+
|
|
3537
|
+
ExifParser.prototype.filter = function (on_entry) {
|
|
3538
|
+
var ifds = {};
|
|
3539
|
+
|
|
3540
|
+
// make sure IFD0 always exists
|
|
3541
|
+
ifds.ifd0 = { id: 0, entries: [] };
|
|
3542
|
+
|
|
3543
|
+
this.each(function (entry) {
|
|
3544
|
+
if (on_entry(entry) === false && !entry.is_subifd_link) return;
|
|
3545
|
+
if (entry.is_subifd_link && entry.count !== 1 && entry.format !== 4) return; // filter out bogus links
|
|
3546
|
+
|
|
3547
|
+
if (!ifds['ifd' + entry.ifd]) {
|
|
3548
|
+
ifds['ifd' + entry.ifd] = { id: entry.ifd, entries: [] };
|
|
3549
|
+
}
|
|
3550
|
+
|
|
3551
|
+
ifds['ifd' + entry.ifd].entries.push(entry);
|
|
3552
|
+
});
|
|
3553
|
+
|
|
3554
|
+
// thumbnails are not supported just yet, so delete all information related to it
|
|
3555
|
+
delete ifds.ifd1;
|
|
3556
|
+
|
|
3557
|
+
// Calculate output size
|
|
3558
|
+
var length = 8;
|
|
3559
|
+
Object.keys(ifds).forEach(function (ifd_no) {
|
|
3560
|
+
length += 2;
|
|
3561
|
+
|
|
3562
|
+
ifds[ifd_no].entries.forEach(function (entry) {
|
|
3563
|
+
length += 12 + (entry.data_length > 4 ? Math.ceil(entry.data_length / 2) * 2 : 0);
|
|
3564
|
+
});
|
|
3565
|
+
|
|
3566
|
+
length += 4;
|
|
3567
|
+
});
|
|
3568
|
+
|
|
3569
|
+
this.output = new Uint8Array(length);
|
|
3570
|
+
this.output[0] = this.output[1] = (this.big_endian ? 'M' : 'I').charCodeAt(0);
|
|
3571
|
+
this.write_uint16(2, 0x2A);
|
|
3572
|
+
|
|
3573
|
+
var offset = 8;
|
|
3574
|
+
var self = this;
|
|
3575
|
+
this.write_uint32(4, offset);
|
|
3576
|
+
|
|
3577
|
+
Object.keys(ifds).forEach(function (ifd_no) {
|
|
3578
|
+
ifds[ifd_no].written_offset = offset;
|
|
3579
|
+
|
|
3580
|
+
var ifd_start = offset;
|
|
3581
|
+
var ifd_end = ifd_start + 2 + ifds[ifd_no].entries.length * 12 + 4;
|
|
3582
|
+
offset = ifd_end;
|
|
3583
|
+
|
|
3584
|
+
self.write_uint16(ifd_start, ifds[ifd_no].entries.length);
|
|
3585
|
+
|
|
3586
|
+
ifds[ifd_no].entries.sort(function (a, b) {
|
|
3587
|
+
// IFD entries must be in order of increasing tag IDs
|
|
3588
|
+
return a.tag - b.tag;
|
|
3589
|
+
}).forEach(function (entry, idx) {
|
|
3590
|
+
var entry_offset = ifd_start + 2 + idx * 12;
|
|
3591
|
+
|
|
3592
|
+
self.write_uint16(entry_offset, entry.tag);
|
|
3593
|
+
self.write_uint16(entry_offset + 2, entry.format);
|
|
3594
|
+
self.write_uint32(entry_offset + 4, entry.count);
|
|
3595
|
+
|
|
3596
|
+
if (entry.is_subifd_link) {
|
|
3597
|
+
// filled in later
|
|
3598
|
+
if (ifds['ifd' + entry.tag]) ifds['ifd' + entry.tag].link_offset = entry_offset + 8;
|
|
3599
|
+
} else if (entry.data_length <= 4) {
|
|
3600
|
+
self.output.set(
|
|
3601
|
+
self.input.subarray(entry.data_offset - self.start, entry.data_offset - self.start + 4),
|
|
3602
|
+
entry_offset + 8
|
|
3603
|
+
);
|
|
3604
|
+
} else {
|
|
3605
|
+
self.write_uint32(entry_offset + 8, offset);
|
|
3606
|
+
self.output.set(
|
|
3607
|
+
self.input.subarray(entry.data_offset - self.start, entry.data_offset - self.start + entry.data_length),
|
|
3608
|
+
offset
|
|
3609
|
+
);
|
|
3610
|
+
offset += Math.ceil(entry.data_length / 2) * 2;
|
|
3611
|
+
}
|
|
3612
|
+
});
|
|
3613
|
+
|
|
3614
|
+
var next_ifd = ifds['ifd' + (ifds[ifd_no].id + 1)];
|
|
3615
|
+
if (next_ifd) next_ifd.link_offset = ifd_end - 4;
|
|
3616
|
+
});
|
|
3617
|
+
|
|
3618
|
+
Object.keys(ifds).forEach(function (ifd_no) {
|
|
3619
|
+
if (ifds[ifd_no].written_offset && ifds[ifd_no].link_offset) {
|
|
3620
|
+
self.write_uint32(ifds[ifd_no].link_offset, ifds[ifd_no].written_offset);
|
|
3621
|
+
}
|
|
3622
|
+
});
|
|
3623
|
+
|
|
3624
|
+
if (this.output.length !== offset) throw error('internal error: incorrect buffer size allocated');
|
|
3625
|
+
|
|
3626
|
+
return this.output;
|
|
3627
|
+
};
|
|
3628
|
+
|
|
3629
|
+
|
|
3630
|
+
ExifParser.prototype.read_uint16 = function (offset) {
|
|
3631
|
+
var d = this.input;
|
|
3632
|
+
if (offset + 2 > d.length) throw error('unexpected EOF', 'EBADDATA');
|
|
3633
|
+
|
|
3634
|
+
return this.big_endian ?
|
|
3635
|
+
d[offset] * 0x100 + d[offset + 1] :
|
|
3636
|
+
d[offset] + d[offset + 1] * 0x100;
|
|
3637
|
+
};
|
|
3638
|
+
|
|
3639
|
+
|
|
3640
|
+
ExifParser.prototype.read_uint32 = function (offset) {
|
|
3641
|
+
var d = this.input;
|
|
3642
|
+
if (offset + 4 > d.length) throw error('unexpected EOF', 'EBADDATA');
|
|
3643
|
+
|
|
3644
|
+
return this.big_endian ?
|
|
3645
|
+
d[offset] * 0x1000000 + d[offset + 1] * 0x10000 + d[offset + 2] * 0x100 + d[offset + 3] :
|
|
3646
|
+
d[offset] + d[offset + 1] * 0x100 + d[offset + 2] * 0x10000 + d[offset + 3] * 0x1000000;
|
|
3647
|
+
};
|
|
3648
|
+
|
|
3649
|
+
|
|
3650
|
+
ExifParser.prototype.write_uint16 = function (offset, value) {
|
|
3651
|
+
var d = this.output;
|
|
3652
|
+
|
|
3653
|
+
if (this.big_endian) {
|
|
3654
|
+
d[offset] = (value >>> 8) & 0xFF;
|
|
3655
|
+
d[offset + 1] = value & 0xFF;
|
|
3656
|
+
} else {
|
|
3657
|
+
d[offset] = value & 0xFF;
|
|
3658
|
+
d[offset + 1] = (value >>> 8) & 0xFF;
|
|
3659
|
+
}
|
|
3660
|
+
};
|
|
3661
|
+
|
|
3662
|
+
|
|
3663
|
+
ExifParser.prototype.write_uint32 = function (offset, value) {
|
|
3664
|
+
var d = this.output;
|
|
3665
|
+
|
|
3666
|
+
if (this.big_endian) {
|
|
3667
|
+
d[offset] = (value >>> 24) & 0xFF;
|
|
3668
|
+
d[offset + 1] = (value >>> 16) & 0xFF;
|
|
3669
|
+
d[offset + 2] = (value >>> 8) & 0xFF;
|
|
3670
|
+
d[offset + 3] = value & 0xFF;
|
|
3671
|
+
} else {
|
|
3672
|
+
d[offset] = value & 0xFF;
|
|
3673
|
+
d[offset + 1] = (value >>> 8) & 0xFF;
|
|
3674
|
+
d[offset + 2] = (value >>> 16) & 0xFF;
|
|
3675
|
+
d[offset + 3] = (value >>> 24) & 0xFF;
|
|
3676
|
+
}
|
|
3677
|
+
};
|
|
3678
|
+
|
|
3679
|
+
|
|
3680
|
+
ExifParser.prototype.is_subifd_link = function (ifd, tag) {
|
|
3681
|
+
return (ifd === 0 && tag === 0x8769) || // SubIFD
|
|
3682
|
+
(ifd === 0 && tag === 0x8825) || // GPS Info
|
|
3683
|
+
(ifd === 0x8769 && tag === 0xA005); // Interop IFD
|
|
3684
|
+
};
|
|
3685
|
+
|
|
3686
|
+
|
|
3687
|
+
// Returns byte length of a single component of a given format
|
|
3688
|
+
//
|
|
3689
|
+
ExifParser.prototype.exif_format_length = function (format) {
|
|
3690
|
+
switch (format) {
|
|
3691
|
+
case 1: // byte
|
|
3692
|
+
case 2: // ascii
|
|
3693
|
+
case 6: // sbyte
|
|
3694
|
+
case 7: // undefined
|
|
3695
|
+
return 1;
|
|
3696
|
+
|
|
3697
|
+
case 3: // short
|
|
3698
|
+
case 8: // sshort
|
|
3699
|
+
return 2;
|
|
3700
|
+
|
|
3701
|
+
case 4: // long
|
|
3702
|
+
case 9: // slong
|
|
3703
|
+
case 11: // float
|
|
3704
|
+
return 4;
|
|
3705
|
+
|
|
3706
|
+
case 5: // rational
|
|
3707
|
+
case 10: // srational
|
|
3708
|
+
case 12: // double
|
|
3709
|
+
return 8;
|
|
3710
|
+
|
|
3711
|
+
default:
|
|
3712
|
+
// unknown type
|
|
3713
|
+
return 0;
|
|
3714
|
+
}
|
|
3715
|
+
};
|
|
3716
|
+
|
|
3717
|
+
|
|
3718
|
+
// Reads Exif data
|
|
3719
|
+
//
|
|
3720
|
+
ExifParser.prototype.exif_format_read = function (format, offset) {
|
|
3721
|
+
var v;
|
|
3722
|
+
|
|
3723
|
+
switch (format) {
|
|
3724
|
+
case 1: // byte
|
|
3725
|
+
case 2: // ascii
|
|
3726
|
+
v = this.input[offset];
|
|
3727
|
+
return v;
|
|
3728
|
+
|
|
3729
|
+
case 6: // sbyte
|
|
3730
|
+
v = this.input[offset];
|
|
3731
|
+
return v | (v & 0x80) * 0x1fffffe;
|
|
3732
|
+
|
|
3733
|
+
case 3: // short
|
|
3734
|
+
v = this.read_uint16(offset);
|
|
3735
|
+
return v;
|
|
3736
|
+
|
|
3737
|
+
case 8: // sshort
|
|
3738
|
+
v = this.read_uint16(offset);
|
|
3739
|
+
return v | (v & 0x8000) * 0x1fffe;
|
|
3740
|
+
|
|
3741
|
+
case 4: // long
|
|
3742
|
+
v = this.read_uint32(offset);
|
|
3743
|
+
return v;
|
|
3744
|
+
|
|
3745
|
+
case 9: // slong
|
|
3746
|
+
v = this.read_uint32(offset);
|
|
3747
|
+
return v | 0;
|
|
3748
|
+
|
|
3749
|
+
case 5: // rational
|
|
3750
|
+
case 10: // srational
|
|
3751
|
+
case 11: // float
|
|
3752
|
+
case 12: // double
|
|
3753
|
+
return null; // not implemented
|
|
3754
|
+
|
|
3755
|
+
case 7: // undefined
|
|
3756
|
+
return null; // blob
|
|
3757
|
+
|
|
3758
|
+
default:
|
|
3759
|
+
// unknown type
|
|
3760
|
+
return null;
|
|
3761
|
+
}
|
|
3762
|
+
};
|
|
3763
|
+
|
|
3764
|
+
|
|
3765
|
+
ExifParser.prototype.scan_ifd = function (ifd_no, offset, on_entry) {
|
|
3766
|
+
var entry_count = this.read_uint16(offset);
|
|
3767
|
+
|
|
3768
|
+
offset += 2;
|
|
3769
|
+
|
|
3770
|
+
for (var i = 0; i < entry_count; i++) {
|
|
3771
|
+
var tag = this.read_uint16(offset);
|
|
3772
|
+
var format = this.read_uint16(offset + 2);
|
|
3773
|
+
var count = this.read_uint32(offset + 4);
|
|
3774
|
+
|
|
3775
|
+
var comp_length = this.exif_format_length(format);
|
|
3776
|
+
var data_length = count * comp_length;
|
|
3777
|
+
var data_offset = data_length <= 4 ? offset + 8 : this.read_uint32(offset + 8);
|
|
3778
|
+
var is_subifd_link = false;
|
|
3779
|
+
|
|
3780
|
+
if (data_offset + data_length > this.input.length) {
|
|
3781
|
+
throw error('unexpected EOF', 'EBADDATA');
|
|
3782
|
+
}
|
|
3783
|
+
|
|
3784
|
+
var value = [];
|
|
3785
|
+
var comp_offset = data_offset;
|
|
3786
|
+
|
|
3787
|
+
for (var j = 0; j < count; j++, comp_offset += comp_length) {
|
|
3788
|
+
var item = this.exif_format_read(format, comp_offset);
|
|
3789
|
+
if (item === null) {
|
|
3790
|
+
value = null;
|
|
3791
|
+
break;
|
|
3792
|
+
}
|
|
3793
|
+
value.push(item);
|
|
3794
|
+
}
|
|
3795
|
+
|
|
3796
|
+
if (Array.isArray(value) && format === 2) {
|
|
3797
|
+
try {
|
|
3798
|
+
value = utf8_decode(String.fromCharCode.apply(null, value));
|
|
3799
|
+
} catch (_) {
|
|
3800
|
+
value = null;
|
|
3801
|
+
}
|
|
3802
|
+
|
|
3803
|
+
if (value && value[value.length - 1] === '\0') value = value.slice(0, -1);
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
if (this.is_subifd_link(ifd_no, tag)) {
|
|
3807
|
+
if (Array.isArray(value) && Number.isInteger(value[0]) && value[0] > 0) {
|
|
3808
|
+
this.ifds_to_read.push({
|
|
3809
|
+
id: tag,
|
|
3810
|
+
offset: value[0]
|
|
3811
|
+
});
|
|
3812
|
+
is_subifd_link = true;
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
|
|
3816
|
+
var entry = {
|
|
3817
|
+
is_big_endian: this.big_endian,
|
|
3818
|
+
ifd: ifd_no,
|
|
3819
|
+
tag: tag,
|
|
3820
|
+
format: format,
|
|
3821
|
+
count: count,
|
|
3822
|
+
entry_offset: offset + this.start,
|
|
3823
|
+
data_length: data_length,
|
|
3824
|
+
data_offset: data_offset + this.start,
|
|
3825
|
+
value: value,
|
|
3826
|
+
is_subifd_link: is_subifd_link
|
|
3827
|
+
};
|
|
3828
|
+
|
|
3829
|
+
if (on_entry(entry) === false) {
|
|
3830
|
+
this.aborted = true;
|
|
3831
|
+
return;
|
|
3832
|
+
}
|
|
3833
|
+
|
|
3834
|
+
offset += 12;
|
|
3835
|
+
}
|
|
3836
|
+
|
|
3837
|
+
if (ifd_no === 0) {
|
|
3838
|
+
this.ifds_to_read.push({
|
|
3839
|
+
id: 1,
|
|
3840
|
+
offset: this.read_uint32(offset)
|
|
3841
|
+
});
|
|
3842
|
+
}
|
|
3843
|
+
};
|
|
3844
|
+
|
|
3845
|
+
|
|
3846
|
+
// Check whether input is a JPEG image
|
|
3847
|
+
//
|
|
3848
|
+
// Input:
|
|
3849
|
+
// - jpeg_bin: Uint8Array - jpeg file
|
|
3850
|
+
//
|
|
3851
|
+
// Returns true if it is and false otherwise
|
|
3852
|
+
//
|
|
3853
|
+
module.exports.is_jpeg = function (jpeg_bin) {
|
|
3854
|
+
return jpeg_bin.length >= 4 && jpeg_bin[0] === 0xFF && jpeg_bin[1] === 0xD8 && jpeg_bin[2] === 0xFF;
|
|
3855
|
+
};
|
|
3856
|
+
|
|
3857
|
+
|
|
3858
|
+
// Call an iterator on each segment in the given JPEG image
|
|
3859
|
+
//
|
|
3860
|
+
// Input:
|
|
3861
|
+
// - jpeg_bin: Uint8Array - jpeg file
|
|
3862
|
+
// - on_segment: Function - callback executed on each JPEG marker segment
|
|
3863
|
+
// - segment: Object
|
|
3864
|
+
// - code: Number - marker type (2nd byte, e.g. 0xE0 for APP0)
|
|
3865
|
+
// - offset: Number - offset of the first byte (0xFF) relative to `jpeg_bin` start
|
|
3866
|
+
// - length: Number - length of the entire marker segment including first two bytes and length
|
|
3867
|
+
// - 2 for standalone markers
|
|
3868
|
+
// - 4+length for markers with data
|
|
3869
|
+
//
|
|
3870
|
+
// Iteration stops when `EOI` (0xFFD9) marker is reached or if `on_segment`
|
|
3871
|
+
// function returns `false`.
|
|
3872
|
+
//
|
|
3873
|
+
module.exports.jpeg_segments_each = function (jpeg_bin, on_segment) {
|
|
3874
|
+
if (!is_uint8array(jpeg_bin)) {
|
|
3875
|
+
throw error('Invalid argument (jpeg_bin), Uint8Array expected', 'EINVAL');
|
|
3876
|
+
}
|
|
3877
|
+
|
|
3878
|
+
if (typeof on_segment !== 'function') {
|
|
3879
|
+
throw error('Invalid argument (on_segment), Function expected', 'EINVAL');
|
|
3880
|
+
}
|
|
3881
|
+
|
|
3882
|
+
if (!module.exports.is_jpeg(jpeg_bin)) {
|
|
3883
|
+
throw error('Unknown file format', 'ENOTJPEG');
|
|
3884
|
+
}
|
|
3885
|
+
|
|
3886
|
+
var offset = 0, length = jpeg_bin.length, inside_scan = false;
|
|
3887
|
+
|
|
3888
|
+
for (;;) {
|
|
3889
|
+
var segment_code, segment_length;
|
|
3890
|
+
|
|
3891
|
+
if (offset + 1 >= length) throw error('Unexpected EOF', 'EBADDATA');
|
|
3892
|
+
var byte1 = jpeg_bin[offset];
|
|
3893
|
+
var byte2 = jpeg_bin[offset + 1];
|
|
3894
|
+
|
|
3895
|
+
if (byte1 === 0xFF && byte2 === 0xFF) {
|
|
3896
|
+
// padding
|
|
3897
|
+
segment_code = 0xFF;
|
|
3898
|
+
segment_length = 1;
|
|
3899
|
+
|
|
3900
|
+
} else if (byte1 === 0xFF && byte2 !== 0) {
|
|
3901
|
+
// marker
|
|
3902
|
+
segment_code = byte2;
|
|
3903
|
+
segment_length = 2;
|
|
3904
|
+
|
|
3905
|
+
if ((0xD0 <= segment_code && segment_code <= 0xD9) || segment_code === 0x01) ; else {
|
|
3906
|
+
if (offset + 3 >= length) throw error('Unexpected EOF', 'EBADDATA');
|
|
3907
|
+
segment_length += jpeg_bin[offset + 2] * 0x100 + jpeg_bin[offset + 3];
|
|
3908
|
+
if (segment_length < 2) throw error('Invalid segment length', 'EBADDATA');
|
|
3909
|
+
if (offset + segment_length - 1 >= length) throw error('Unexpected EOF', 'EBADDATA');
|
|
3910
|
+
}
|
|
3911
|
+
|
|
3912
|
+
if (inside_scan) {
|
|
3913
|
+
if (segment_code >= 0xD0 && segment_code <= 0xD7) ; else {
|
|
3914
|
+
inside_scan = false;
|
|
3915
|
+
}
|
|
3916
|
+
}
|
|
3917
|
+
|
|
3918
|
+
if (segment_code === 0xDA /* SOS */) inside_scan = true;
|
|
3919
|
+
} else if (inside_scan) {
|
|
3920
|
+
// entropy-encoded segment
|
|
3921
|
+
for (var pos = offset + 1; ; pos++) {
|
|
3922
|
+
// scan until we find FF
|
|
3923
|
+
if (pos >= length) throw error('Unexpected EOF', 'EBADDATA');
|
|
3924
|
+
if (jpeg_bin[pos] === 0xFF) {
|
|
3925
|
+
if (pos + 1 >= length) throw error('Unexpected EOF', 'EBADDATA');
|
|
3926
|
+
if (jpeg_bin[pos + 1] !== 0) {
|
|
3927
|
+
segment_code = 0;
|
|
3928
|
+
segment_length = pos - offset;
|
|
3929
|
+
break;
|
|
3930
|
+
}
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
} else {
|
|
3934
|
+
throw error('Unexpected byte at segment start: ' + to_hex(byte1) +
|
|
3935
|
+
' (offset ' + to_hex(offset) + ')', 'EBADDATA');
|
|
3936
|
+
}
|
|
3937
|
+
|
|
3938
|
+
if (on_segment({ code: segment_code, offset: offset, length: segment_length }) === false) break;
|
|
3939
|
+
if (segment_code === 0xD9 /* EOI */) break;
|
|
3940
|
+
offset += segment_length;
|
|
3941
|
+
}
|
|
3942
|
+
};
|
|
3943
|
+
|
|
3944
|
+
|
|
3945
|
+
// Replace or remove segments in the given JPEG image
|
|
3946
|
+
//
|
|
3947
|
+
// Input:
|
|
3948
|
+
// - jpeg_bin: Uint8Array - jpeg file
|
|
3949
|
+
// - on_segment: Function - callback executed on each JPEG marker segment
|
|
3950
|
+
// - segment: Object
|
|
3951
|
+
// - code: Number - marker type (2nd byte, e.g. 0xE0 for APP0)
|
|
3952
|
+
// - offset: Number - offset of the first byte (0xFF) relative to `jpeg_bin` start
|
|
3953
|
+
// - length: Number - length of the entire marker segment including first two bytes and length
|
|
3954
|
+
// - 2 for standalone markers
|
|
3955
|
+
// - 4+length for markers with data
|
|
3956
|
+
//
|
|
3957
|
+
// `on_segment` function should return one of the following:
|
|
3958
|
+
// - `false` - segment is removed from the output
|
|
3959
|
+
// - Uint8Array - segment is replaced with the new data
|
|
3960
|
+
// - [ Uint8Array ] - segment is replaced with the new data
|
|
3961
|
+
// - anything else - segment is copied to the output as is
|
|
3962
|
+
//
|
|
3963
|
+
// Any data after `EOI` (0xFFD9) marker is removed.
|
|
3964
|
+
//
|
|
3965
|
+
module.exports.jpeg_segments_filter = function (jpeg_bin, on_segment) {
|
|
3966
|
+
if (!is_uint8array(jpeg_bin)) {
|
|
3967
|
+
throw error('Invalid argument (jpeg_bin), Uint8Array expected', 'EINVAL');
|
|
3968
|
+
}
|
|
3969
|
+
|
|
3970
|
+
if (typeof on_segment !== 'function') {
|
|
3971
|
+
throw error('Invalid argument (on_segment), Function expected', 'EINVAL');
|
|
3972
|
+
}
|
|
3973
|
+
|
|
3974
|
+
var ranges = [];
|
|
3975
|
+
var out_length = 0;
|
|
3976
|
+
|
|
3977
|
+
module.exports.jpeg_segments_each(jpeg_bin, function (segment) {
|
|
3978
|
+
var new_segment = on_segment(segment);
|
|
3979
|
+
|
|
3980
|
+
if (is_uint8array(new_segment)) {
|
|
3981
|
+
ranges.push({ data: new_segment });
|
|
3982
|
+
out_length += new_segment.length;
|
|
3983
|
+
} else if (Array.isArray(new_segment)) {
|
|
3984
|
+
new_segment.filter(is_uint8array).forEach(function (s) {
|
|
3985
|
+
ranges.push({ data: s });
|
|
3986
|
+
out_length += s.length;
|
|
3987
|
+
});
|
|
3988
|
+
} else if (new_segment !== false) {
|
|
3989
|
+
var new_range = { start: segment.offset, end: segment.offset + segment.length };
|
|
3990
|
+
|
|
3991
|
+
if (ranges.length > 0 && ranges[ranges.length - 1].end === new_range.start) {
|
|
3992
|
+
ranges[ranges.length - 1].end = new_range.end;
|
|
3993
|
+
} else {
|
|
3994
|
+
ranges.push(new_range);
|
|
3995
|
+
}
|
|
3996
|
+
|
|
3997
|
+
out_length += segment.length;
|
|
3998
|
+
}
|
|
3999
|
+
});
|
|
4000
|
+
|
|
4001
|
+
var result = new Uint8Array(out_length);
|
|
4002
|
+
var offset = 0;
|
|
4003
|
+
|
|
4004
|
+
ranges.forEach(function (range) {
|
|
4005
|
+
var data = range.data || jpeg_bin.subarray(range.start, range.end);
|
|
4006
|
+
result.set(data, offset);
|
|
4007
|
+
offset += data.length;
|
|
4008
|
+
});
|
|
4009
|
+
|
|
4010
|
+
return result;
|
|
4011
|
+
};
|
|
4012
|
+
|
|
4013
|
+
|
|
4014
|
+
// Call an iterator on each Exif entry in the given JPEG image
|
|
4015
|
+
//
|
|
4016
|
+
// Input:
|
|
4017
|
+
// - jpeg_bin: Uint8Array - jpeg file
|
|
4018
|
+
// - on_entry: Function - callback executed on each Exif entry
|
|
4019
|
+
// - entry: Object
|
|
4020
|
+
// - is_big_endian: Boolean - whether Exif uses big or little endian byte alignment
|
|
4021
|
+
// - ifd: Number - IFD identifier (0 for IFD0, 1 for IFD1, 0x8769 for SubIFD,
|
|
4022
|
+
// 0x8825 for GPS Info, 0xA005 for Interop IFD)
|
|
4023
|
+
// - tag: Number - exif entry tag (0x0110 - camera name, 0x0112 - orientation, etc. - see Exif spec)
|
|
4024
|
+
// - format: Number - exif entry format (1 - byte, 2 - ascii, 3 - short, etc. - see Exif spec)
|
|
4025
|
+
// - count: Number - number of components of the given format inside data
|
|
4026
|
+
// (usually 1, or string length for ascii format)
|
|
4027
|
+
// - entry_offset: Number - start of Exif entry (entry length is always 12, so not included)
|
|
4028
|
+
// - data_offset: Number - start of data attached to Exif entry (will overlap with entry if length <= 4)
|
|
4029
|
+
// - data_length: Number - length of data attached to Exif entry
|
|
4030
|
+
// - value: Array|String|Null - our best attempt at parsing data (not all formats supported right now)
|
|
4031
|
+
// - is_subifd_link: Boolean - whether this entry is recognized to be a link to subifd (can't filter these out)
|
|
4032
|
+
//
|
|
4033
|
+
// Iteration stops early if iterator returns `false`.
|
|
4034
|
+
//
|
|
4035
|
+
// If Exif wasn't found anywhere (before start of the image data, SOS),
|
|
4036
|
+
// iterator is never executed.
|
|
4037
|
+
//
|
|
4038
|
+
module.exports.jpeg_exif_tags_each = function (jpeg_bin, on_exif_entry) {
|
|
4039
|
+
if (!is_uint8array(jpeg_bin)) {
|
|
4040
|
+
throw error('Invalid argument (jpeg_bin), Uint8Array expected', 'EINVAL');
|
|
4041
|
+
}
|
|
4042
|
+
|
|
4043
|
+
if (typeof on_exif_entry !== 'function') {
|
|
4044
|
+
throw error('Invalid argument (on_exif_entry), Function expected', 'EINVAL');
|
|
4045
|
+
}
|
|
4046
|
+
|
|
4047
|
+
/* eslint-disable consistent-return */
|
|
4048
|
+
module.exports.jpeg_segments_each(jpeg_bin, function (segment) {
|
|
4049
|
+
if (segment.code === 0xDA /* SOS */) return false;
|
|
4050
|
+
|
|
4051
|
+
// look for APP1 segment and compare header with 'Exif\0\0'
|
|
4052
|
+
if (segment.code === 0xE1 && segment.length >= 10 &&
|
|
4053
|
+
jpeg_bin[segment.offset + 4] === 0x45 && jpeg_bin[segment.offset + 5] === 0x78 &&
|
|
4054
|
+
jpeg_bin[segment.offset + 6] === 0x69 && jpeg_bin[segment.offset + 7] === 0x66 &&
|
|
4055
|
+
jpeg_bin[segment.offset + 8] === 0x00 && jpeg_bin[segment.offset + 9] === 0x00) {
|
|
4056
|
+
|
|
4057
|
+
new ExifParser(jpeg_bin, segment.offset + 10, segment.offset + segment.length).each(on_exif_entry);
|
|
4058
|
+
return false;
|
|
4059
|
+
}
|
|
4060
|
+
});
|
|
4061
|
+
};
|
|
4062
|
+
|
|
4063
|
+
|
|
4064
|
+
// Remove Exif entries in the given JPEG image
|
|
4065
|
+
//
|
|
4066
|
+
// Input:
|
|
4067
|
+
// - jpeg_bin: Uint8Array - jpeg file
|
|
4068
|
+
// - on_entry: Function - callback executed on each Exif entry
|
|
4069
|
+
// - entry: Object
|
|
4070
|
+
// - is_big_endian: Boolean - whether Exif uses big or little endian byte alignment
|
|
4071
|
+
// - ifd: Number - IFD identifier (0 for IFD0, 1 for IFD1, 0x8769 for SubIFD,
|
|
4072
|
+
// 0x8825 for GPS Info, 0xA005 for Interop IFD)
|
|
4073
|
+
// - tag: Number - exif entry tag (0x0110 - camera name, 0x0112 - orientation, etc. - see Exif spec)
|
|
4074
|
+
// - format: Number - exif entry format (1 - byte, 2 - ascii, 3 - short, etc. - see Exif spec)
|
|
4075
|
+
// - count: Number - number of components of the given format inside data
|
|
4076
|
+
// (usually 1, or string length for ascii format)
|
|
4077
|
+
// - entry_offset: Number - start of Exif entry (entry length is always 12, so not included)
|
|
4078
|
+
// - data_offset: Number - start of data attached to Exif entry (will overlap with entry if length <= 4)
|
|
4079
|
+
// - data_length: Number - length of data attached to Exif entry
|
|
4080
|
+
// - value: Array|String|Null - our best attempt at parsing data (not all formats supported right now)
|
|
4081
|
+
// - is_subifd_link: Boolean - whether this entry is recognized to be a link to subifd (can't filter these out)
|
|
4082
|
+
//
|
|
4083
|
+
// This function removes following from Exif:
|
|
4084
|
+
// - all entries where iterator returned false (except subifd links which are mandatory)
|
|
4085
|
+
// - IFD1 and thumbnail image (the purpose of this function is to reduce file size,
|
|
4086
|
+
// so thumbnail is usually the first thing to go)
|
|
4087
|
+
// - all other data that isn't in IFD0, SubIFD, GPSIFD, InteropIFD
|
|
4088
|
+
// (theoretically possible proprietary extensions, I haven't seen any of these yet)
|
|
4089
|
+
//
|
|
4090
|
+
// Changing data inside Exif entries is NOT supported yet (modifying `entry` object inside callback may break stuff).
|
|
4091
|
+
//
|
|
4092
|
+
// If Exif wasn't found anywhere (before start of the image data, SOS),
|
|
4093
|
+
// iterator is never executed, and original JPEG is returned as is.
|
|
4094
|
+
//
|
|
4095
|
+
module.exports.jpeg_exif_tags_filter = function (jpeg_bin, on_exif_entry) {
|
|
4096
|
+
if (!is_uint8array(jpeg_bin)) {
|
|
4097
|
+
throw error('Invalid argument (jpeg_bin), Uint8Array expected', 'EINVAL');
|
|
4098
|
+
}
|
|
4099
|
+
|
|
4100
|
+
if (typeof on_exif_entry !== 'function') {
|
|
4101
|
+
throw error('Invalid argument (on_exif_entry), Function expected', 'EINVAL');
|
|
4102
|
+
}
|
|
4103
|
+
|
|
4104
|
+
var stop_search = false;
|
|
4105
|
+
|
|
4106
|
+
return module.exports.jpeg_segments_filter(jpeg_bin, function (segment) {
|
|
4107
|
+
if (stop_search) return;
|
|
4108
|
+
if (segment.code === 0xDA /* SOS */) stop_search = true;
|
|
4109
|
+
|
|
4110
|
+
// look for APP1 segment and compare header with 'Exif\0\0'
|
|
4111
|
+
if (segment.code === 0xE1 && segment.length >= 10 &&
|
|
4112
|
+
jpeg_bin[segment.offset + 4] === 0x45 && jpeg_bin[segment.offset + 5] === 0x78 &&
|
|
4113
|
+
jpeg_bin[segment.offset + 6] === 0x69 && jpeg_bin[segment.offset + 7] === 0x66 &&
|
|
4114
|
+
jpeg_bin[segment.offset + 8] === 0x00 && jpeg_bin[segment.offset + 9] === 0x00) {
|
|
4115
|
+
|
|
4116
|
+
var new_exif = new ExifParser(jpeg_bin, segment.offset + 10, segment.offset + segment.length)
|
|
4117
|
+
.filter(on_exif_entry);
|
|
4118
|
+
if (!new_exif) return false;
|
|
4119
|
+
|
|
4120
|
+
var header = new Uint8Array(10);
|
|
4121
|
+
|
|
4122
|
+
header.set(jpeg_bin.slice(segment.offset, segment.offset + 10));
|
|
4123
|
+
header[2] = ((new_exif.length + 8) >>> 8) & 0xFF;
|
|
4124
|
+
header[3] = (new_exif.length + 8) & 0xFF;
|
|
4125
|
+
|
|
4126
|
+
stop_search = true;
|
|
4127
|
+
return [ header, new_exif ];
|
|
4128
|
+
}
|
|
4129
|
+
});
|
|
4130
|
+
};
|
|
4131
|
+
|
|
4132
|
+
|
|
4133
|
+
// Inserts a custom comment marker segment into JPEG file.
|
|
4134
|
+
//
|
|
4135
|
+
// Input:
|
|
4136
|
+
// - jpeg_bin: Uint8Array - jpeg file
|
|
4137
|
+
// - comment: String
|
|
4138
|
+
//
|
|
4139
|
+
// Comment is inserted after first two bytes (FFD8, SOI).
|
|
4140
|
+
//
|
|
4141
|
+
// If JFIF (APP0) marker exists immediately after SOI (as mandated by the JFIF
|
|
4142
|
+
// spec), we insert comment after it instead.
|
|
4143
|
+
//
|
|
4144
|
+
module.exports.jpeg_add_comment = function (jpeg_bin, comment) {
|
|
4145
|
+
var comment_inserted = false, segment_count = 0;
|
|
4146
|
+
|
|
4147
|
+
return module.exports.jpeg_segments_filter(jpeg_bin, function (segment) {
|
|
4148
|
+
segment_count++;
|
|
4149
|
+
if (segment_count === 1 && segment.code === 0xD8 /* SOI */) return;
|
|
4150
|
+
if (segment_count === 2 && segment.code === 0xE0 /* APP0 */) return;
|
|
4151
|
+
|
|
4152
|
+
if (comment_inserted) return;
|
|
4153
|
+
comment = utf8_encode(comment);
|
|
4154
|
+
|
|
4155
|
+
// comment segment
|
|
4156
|
+
var csegment = new Uint8Array(5 + comment.length);
|
|
4157
|
+
var offset = 0;
|
|
4158
|
+
|
|
4159
|
+
csegment[offset++] = 0xFF;
|
|
4160
|
+
csegment[offset++] = 0xFE;
|
|
4161
|
+
csegment[offset++] = ((comment.length + 3) >>> 8) & 0xFF;
|
|
4162
|
+
csegment[offset++] = (comment.length + 3) & 0xFF;
|
|
4163
|
+
|
|
4164
|
+
comment.split('').forEach(function (c) {
|
|
4165
|
+
csegment[offset++] = c.charCodeAt(0) & 0xFF;
|
|
4166
|
+
});
|
|
4167
|
+
|
|
4168
|
+
csegment[offset++] = 0;
|
|
4169
|
+
comment_inserted = true;
|
|
4170
|
+
|
|
4171
|
+
return [ csegment, jpeg_bin.subarray(segment.offset, segment.offset + segment.length) ];
|
|
4172
|
+
});
|
|
4173
|
+
};
|
|
4174
|
+
}(image_traverse$1));
|
|
4175
|
+
|
|
4176
|
+
var image_traverse = image_traverse$1.exports;
|
|
4177
|
+
|
|
4178
|
+
|
|
4179
|
+
function jpeg_patch_exif(env) {
|
|
4180
|
+
return this._getUint8Array(env.blob).then(function (data) {
|
|
4181
|
+
env.is_jpeg = image_traverse.is_jpeg(data);
|
|
4182
|
+
|
|
4183
|
+
if (!env.is_jpeg) return Promise.resolve(env);
|
|
4184
|
+
|
|
4185
|
+
env.orig_blob = env.blob;
|
|
4186
|
+
|
|
4187
|
+
try {
|
|
4188
|
+
var exif_is_big_endian, orientation_offset;
|
|
4189
|
+
|
|
4190
|
+
/* eslint-disable consistent-return */
|
|
4191
|
+
image_traverse.jpeg_exif_tags_each(data, function (entry) {
|
|
4192
|
+
if (entry.ifd === 0 && entry.tag === 0x112 && Array.isArray(entry.value)) {
|
|
4193
|
+
env.orientation = entry.value[0] || 1;
|
|
4194
|
+
exif_is_big_endian = entry.is_big_endian;
|
|
4195
|
+
orientation_offset = entry.data_offset;
|
|
4196
|
+
return false;
|
|
4197
|
+
}
|
|
4198
|
+
});
|
|
4199
|
+
|
|
4200
|
+
if (orientation_offset) {
|
|
4201
|
+
var orientation_patch = exif_is_big_endian ?
|
|
4202
|
+
new Uint8Array([ 0, 1 ]) :
|
|
4203
|
+
new Uint8Array([ 1, 0 ]);
|
|
4204
|
+
|
|
4205
|
+
env.blob = new Blob([
|
|
4206
|
+
data.slice(0, orientation_offset),
|
|
4207
|
+
orientation_patch,
|
|
4208
|
+
data.slice(orientation_offset + 2)
|
|
4209
|
+
], { type: 'image/jpeg' });
|
|
4210
|
+
}
|
|
4211
|
+
} catch (_) {}
|
|
4212
|
+
|
|
4213
|
+
return env;
|
|
4214
|
+
});
|
|
4215
|
+
}
|
|
4216
|
+
|
|
4217
|
+
|
|
4218
|
+
function jpeg_rotate_canvas(env) {
|
|
4219
|
+
if (!env.is_jpeg) return Promise.resolve(env);
|
|
4220
|
+
|
|
4221
|
+
var orientation = env.orientation - 1;
|
|
4222
|
+
if (!orientation) return Promise.resolve(env);
|
|
4223
|
+
|
|
4224
|
+
var canvas;
|
|
4225
|
+
|
|
4226
|
+
if (orientation & 4) {
|
|
4227
|
+
canvas = this.pica.options.createCanvas(env.out_canvas.height, env.out_canvas.width);
|
|
4228
|
+
} else {
|
|
4229
|
+
canvas = this.pica.options.createCanvas(env.out_canvas.width, env.out_canvas.height);
|
|
4230
|
+
}
|
|
4231
|
+
|
|
4232
|
+
var ctx = canvas.getContext('2d');
|
|
4233
|
+
|
|
4234
|
+
ctx.save();
|
|
4235
|
+
|
|
4236
|
+
if (orientation & 1) ctx.transform(-1, 0, 0, 1, canvas.width, 0);
|
|
4237
|
+
if (orientation & 2) ctx.transform(-1, 0, 0, -1, canvas.width, canvas.height);
|
|
4238
|
+
if (orientation & 4) ctx.transform(0, 1, 1, 0, 0, 0);
|
|
4239
|
+
|
|
4240
|
+
ctx.drawImage(env.out_canvas, 0, 0);
|
|
4241
|
+
ctx.restore();
|
|
4242
|
+
|
|
4243
|
+
// Safari 12 workaround
|
|
4244
|
+
// https://github.com/nodeca/pica/issues/199
|
|
4245
|
+
env.out_canvas.width = env.out_canvas.height = 0;
|
|
4246
|
+
|
|
4247
|
+
env.out_canvas = canvas;
|
|
4248
|
+
|
|
4249
|
+
return Promise.resolve(env);
|
|
4250
|
+
}
|
|
4251
|
+
|
|
4252
|
+
|
|
4253
|
+
function jpeg_attach_orig_segments(env) {
|
|
4254
|
+
if (!env.is_jpeg) return Promise.resolve(env);
|
|
4255
|
+
|
|
4256
|
+
return Promise.all([
|
|
4257
|
+
this._getUint8Array(env.blob),
|
|
4258
|
+
this._getUint8Array(env.out_blob)
|
|
4259
|
+
]).then(function (res) {
|
|
4260
|
+
var data = res[0];
|
|
4261
|
+
var data_out = res[1];
|
|
4262
|
+
|
|
4263
|
+
if (!image_traverse.is_jpeg(data)) return Promise.resolve(env);
|
|
4264
|
+
|
|
4265
|
+
var segments = [];
|
|
4266
|
+
|
|
4267
|
+
image_traverse.jpeg_segments_each(data, function (segment) {
|
|
4268
|
+
if (segment.code === 0xDA /* SOS */) return false;
|
|
4269
|
+
segments.push(segment);
|
|
4270
|
+
});
|
|
4271
|
+
|
|
4272
|
+
segments = segments
|
|
4273
|
+
.filter(function (segment) {
|
|
4274
|
+
// Drop ICC_PROFILE
|
|
4275
|
+
//
|
|
4276
|
+
if (segment.code === 0xE2) return false;
|
|
4277
|
+
|
|
4278
|
+
// Keep all APPn segments excluding APP2 (ICC_PROFILE),
|
|
4279
|
+
// remove others because most of them depend on image data (DCT and such).
|
|
4280
|
+
//
|
|
4281
|
+
// APP0 - JFIF, APP1 - Exif, the rest are photoshop metadata and such
|
|
4282
|
+
//
|
|
4283
|
+
// See full list at https://www.w3.org/Graphics/JPEG/itu-t81.pdf (table B.1 on page 32)
|
|
4284
|
+
//
|
|
4285
|
+
if (segment.code >= 0xE0 && segment.code < 0xF0) return true;
|
|
4286
|
+
|
|
4287
|
+
// Keep comments
|
|
4288
|
+
//
|
|
4289
|
+
if (segment.code === 0xFE) return true;
|
|
4290
|
+
|
|
4291
|
+
return false;
|
|
4292
|
+
})
|
|
4293
|
+
.map(function (segment) {
|
|
4294
|
+
return data.slice(segment.offset, segment.offset + segment.length);
|
|
4295
|
+
});
|
|
4296
|
+
|
|
4297
|
+
env.out_blob = new Blob(
|
|
4298
|
+
// intentionally omitting expected JFIF segment (offset 2 to 20)
|
|
4299
|
+
[ data_out.slice(0, 2) ].concat(segments).concat([ data_out.slice(20) ]),
|
|
4300
|
+
{ type: 'image/jpeg' }
|
|
4301
|
+
);
|
|
4302
|
+
|
|
4303
|
+
return env;
|
|
4304
|
+
});
|
|
4305
|
+
}
|
|
4306
|
+
|
|
4307
|
+
|
|
4308
|
+
function assign(reducer) {
|
|
4309
|
+
reducer.before('_blob_to_image', jpeg_patch_exif);
|
|
4310
|
+
reducer.after('_transform', jpeg_rotate_canvas);
|
|
4311
|
+
reducer.after('_create_blob', jpeg_attach_orig_segments);
|
|
4312
|
+
}
|
|
4313
|
+
|
|
4314
|
+
|
|
4315
|
+
jpeg_plugins.jpeg_patch_exif = jpeg_patch_exif;
|
|
4316
|
+
jpeg_plugins.jpeg_rotate_canvas = jpeg_rotate_canvas;
|
|
4317
|
+
jpeg_plugins.jpeg_attach_orig_segments = jpeg_attach_orig_segments;
|
|
4318
|
+
jpeg_plugins.assign = assign;
|
|
4319
|
+
|
|
4320
|
+
var utils = utils$1;
|
|
4321
|
+
var pica = pica$1.exports;
|
|
4322
|
+
|
|
4323
|
+
function ImageBlobReduce(options) {
|
|
4324
|
+
if (!(this instanceof ImageBlobReduce)) return new ImageBlobReduce(options);
|
|
4325
|
+
|
|
4326
|
+
options = options || {};
|
|
4327
|
+
|
|
4328
|
+
this.pica = options.pica || pica({});
|
|
4329
|
+
this.initialized = false;
|
|
4330
|
+
|
|
4331
|
+
this.utils = utils;
|
|
4332
|
+
}
|
|
4333
|
+
|
|
4334
|
+
|
|
4335
|
+
ImageBlobReduce.prototype.use = function (plugin /*, params, ... */) {
|
|
4336
|
+
var args = [ this ].concat(Array.prototype.slice.call(arguments, 1));
|
|
4337
|
+
plugin.apply(plugin, args);
|
|
4338
|
+
return this;
|
|
4339
|
+
};
|
|
4340
|
+
|
|
4341
|
+
|
|
4342
|
+
ImageBlobReduce.prototype.init = function () {
|
|
4343
|
+
this.use(jpeg_plugins.assign);
|
|
4344
|
+
};
|
|
4345
|
+
|
|
4346
|
+
|
|
4347
|
+
ImageBlobReduce.prototype.toBlob = function (blob, options) {
|
|
4348
|
+
var opts = utils.assign({ max: Infinity }, options);
|
|
4349
|
+
var env = {
|
|
4350
|
+
blob: blob,
|
|
4351
|
+
opts: opts
|
|
4352
|
+
};
|
|
4353
|
+
|
|
4354
|
+
if (!this.initialized) {
|
|
4355
|
+
this.init();
|
|
4356
|
+
this.initialized = true;
|
|
4357
|
+
}
|
|
4358
|
+
|
|
4359
|
+
return Promise.resolve(env)
|
|
4360
|
+
.then(this._blob_to_image)
|
|
4361
|
+
.then(this._calculate_size)
|
|
4362
|
+
.then(this._transform)
|
|
4363
|
+
.then(this._cleanup)
|
|
4364
|
+
.then(this._create_blob)
|
|
4365
|
+
.then(function (_env) {
|
|
4366
|
+
// Safari 12 workaround
|
|
4367
|
+
// https://github.com/nodeca/pica/issues/199
|
|
4368
|
+
_env.out_canvas.width = _env.out_canvas.height = 0;
|
|
4369
|
+
|
|
4370
|
+
return _env.out_blob;
|
|
4371
|
+
});
|
|
4372
|
+
};
|
|
4373
|
+
|
|
4374
|
+
|
|
4375
|
+
ImageBlobReduce.prototype.toCanvas = function (blob, options) {
|
|
4376
|
+
var opts = utils.assign({ max: Infinity }, options);
|
|
4377
|
+
var env = {
|
|
4378
|
+
blob: blob,
|
|
4379
|
+
opts: opts
|
|
4380
|
+
};
|
|
4381
|
+
|
|
4382
|
+
if (!this.initialized) {
|
|
4383
|
+
this.init();
|
|
4384
|
+
this.initialized = true;
|
|
4385
|
+
}
|
|
4386
|
+
|
|
4387
|
+
return Promise.resolve(env)
|
|
4388
|
+
.then(this._blob_to_image)
|
|
4389
|
+
.then(this._calculate_size)
|
|
4390
|
+
.then(this._transform)
|
|
4391
|
+
.then(this._cleanup)
|
|
4392
|
+
.then(function (_env) { return _env.out_canvas; });
|
|
4393
|
+
};
|
|
4394
|
+
|
|
4395
|
+
|
|
4396
|
+
ImageBlobReduce.prototype.before = function (method_name, fn) {
|
|
4397
|
+
if (!this[method_name]) throw new Error('Method "' + method_name + '" does not exist');
|
|
4398
|
+
if (typeof fn !== 'function') throw new Error('Invalid argument "fn", function expected');
|
|
4399
|
+
|
|
4400
|
+
var old_fn = this[method_name];
|
|
4401
|
+
var self = this;
|
|
4402
|
+
|
|
4403
|
+
this[method_name] = function (env) {
|
|
4404
|
+
return fn.call(self, env).then(function (_env) {
|
|
4405
|
+
return old_fn.call(self, _env);
|
|
4406
|
+
});
|
|
4407
|
+
};
|
|
4408
|
+
|
|
4409
|
+
return this;
|
|
4410
|
+
};
|
|
4411
|
+
|
|
4412
|
+
|
|
4413
|
+
ImageBlobReduce.prototype.after = function (method_name, fn) {
|
|
4414
|
+
if (!this[method_name]) throw new Error('Method "' + method_name + '" does not exist');
|
|
4415
|
+
if (typeof fn !== 'function') throw new Error('Invalid argument "fn", function expected');
|
|
4416
|
+
|
|
4417
|
+
var old_fn = this[method_name];
|
|
4418
|
+
var self = this;
|
|
4419
|
+
|
|
4420
|
+
this[method_name] = function (env) {
|
|
4421
|
+
return old_fn.call(self, env).then(function (_env) {
|
|
4422
|
+
return fn.call(self, _env);
|
|
4423
|
+
});
|
|
4424
|
+
};
|
|
4425
|
+
|
|
4426
|
+
return this;
|
|
4427
|
+
};
|
|
4428
|
+
|
|
4429
|
+
|
|
4430
|
+
ImageBlobReduce.prototype._blob_to_image = function (env) {
|
|
4431
|
+
var URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
|
4432
|
+
|
|
4433
|
+
env.image = document.createElement('img');
|
|
4434
|
+
env.image_url = URL.createObjectURL(env.blob);
|
|
4435
|
+
env.image.src = env.image_url;
|
|
4436
|
+
|
|
4437
|
+
return new Promise(function (resolve, reject) {
|
|
4438
|
+
env.image.onerror = function () { reject(new Error('ImageBlobReduce: failed to create Image() from blob')); };
|
|
4439
|
+
env.image.onload = function () { resolve(env); };
|
|
4440
|
+
});
|
|
4441
|
+
};
|
|
4442
|
+
|
|
4443
|
+
|
|
4444
|
+
ImageBlobReduce.prototype._calculate_size = function (env) {
|
|
4445
|
+
//
|
|
4446
|
+
// Note, if your need not "symmetric" resize logic, you MUST check
|
|
4447
|
+
// `env.orientation` (set by plugins) and swap width/height appropriately.
|
|
4448
|
+
//
|
|
4449
|
+
var scale_factor = env.opts.max / Math.max(env.image.width, env.image.height);
|
|
4450
|
+
|
|
4451
|
+
if (scale_factor > 1) scale_factor = 1;
|
|
4452
|
+
|
|
4453
|
+
env.transform_width = Math.max(Math.round(env.image.width * scale_factor), 1);
|
|
4454
|
+
env.transform_height = Math.max(Math.round(env.image.height * scale_factor), 1);
|
|
4455
|
+
|
|
4456
|
+
// Info for user plugins, to check if scaling applied
|
|
4457
|
+
env.scale_factor = scale_factor;
|
|
4458
|
+
|
|
4459
|
+
return Promise.resolve(env);
|
|
4460
|
+
};
|
|
4461
|
+
|
|
4462
|
+
|
|
4463
|
+
ImageBlobReduce.prototype._transform = function (env) {
|
|
4464
|
+
env.out_canvas = this.pica.options.createCanvas(env.transform_width, env.transform_height);
|
|
4465
|
+
|
|
4466
|
+
// Dim env temporary vars to prohibit use and avoid confusion when orientation
|
|
4467
|
+
// changed. You should take real size from canvas.
|
|
4468
|
+
env.transform_width = null;
|
|
4469
|
+
env.transform_height = null;
|
|
4470
|
+
|
|
4471
|
+
// By default use alpha for png only
|
|
4472
|
+
var pica_opts = { alpha: env.blob.type === 'image/png' };
|
|
4473
|
+
|
|
4474
|
+
// Extract pica options if been passed
|
|
4475
|
+
this.utils.assign(pica_opts, this.utils.pick_pica_resize_options(env.opts));
|
|
4476
|
+
|
|
4477
|
+
return this.pica
|
|
4478
|
+
.resize(env.image, env.out_canvas, pica_opts)
|
|
4479
|
+
.then(function () { return env; });
|
|
4480
|
+
};
|
|
4481
|
+
|
|
4482
|
+
|
|
4483
|
+
ImageBlobReduce.prototype._cleanup = function (env) {
|
|
4484
|
+
env.image.src = '';
|
|
4485
|
+
env.image = null;
|
|
4486
|
+
|
|
4487
|
+
var URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
|
4488
|
+
if (URL.revokeObjectURL) URL.revokeObjectURL(env.image_url);
|
|
4489
|
+
|
|
4490
|
+
env.image_url = null;
|
|
4491
|
+
|
|
4492
|
+
return Promise.resolve(env);
|
|
4493
|
+
};
|
|
4494
|
+
|
|
4495
|
+
|
|
4496
|
+
ImageBlobReduce.prototype._create_blob = function (env) {
|
|
4497
|
+
return this.pica.toBlob(env.out_canvas, env.blob.type)
|
|
4498
|
+
.then(function (blob) {
|
|
4499
|
+
env.out_blob = blob;
|
|
4500
|
+
return env;
|
|
4501
|
+
});
|
|
4502
|
+
};
|
|
4503
|
+
|
|
4504
|
+
|
|
4505
|
+
ImageBlobReduce.prototype._getUint8Array = function (blob) {
|
|
4506
|
+
if (blob.arrayBuffer) {
|
|
4507
|
+
return blob.arrayBuffer().then(function (buf) {
|
|
4508
|
+
return new Uint8Array(buf);
|
|
4509
|
+
});
|
|
4510
|
+
}
|
|
4511
|
+
|
|
4512
|
+
return new Promise(function (resolve, reject) {
|
|
4513
|
+
var fr = new FileReader();
|
|
4514
|
+
|
|
4515
|
+
fr.readAsArrayBuffer(blob);
|
|
4516
|
+
|
|
4517
|
+
fr.onload = function () { resolve(new Uint8Array(fr.result)); };
|
|
4518
|
+
fr.onerror = function () {
|
|
4519
|
+
reject(new Error('ImageBlobReduce: failed to load data from input blob'));
|
|
4520
|
+
fr.abort();
|
|
4521
|
+
};
|
|
4522
|
+
fr.onabort = function () {
|
|
4523
|
+
reject(new Error('ImageBlobReduce: failed to load data from input blob (aborted)'));
|
|
4524
|
+
};
|
|
4525
|
+
});
|
|
4526
|
+
};
|
|
4527
|
+
|
|
4528
|
+
|
|
4529
|
+
ImageBlobReduce.pica = pica;
|
|
4530
|
+
|
|
4531
|
+
var imageBlobReduce = ImageBlobReduce;
|
|
4532
|
+
|
|
4533
|
+
var script = defineComponent({
|
|
4534
|
+
name: "ResizeImageUpload",
|
|
4535
|
+
props: {
|
|
4536
|
+
id: {
|
|
4537
|
+
type: String,
|
|
4538
|
+
},
|
|
4539
|
+
required: {
|
|
4540
|
+
type: Boolean,
|
|
4541
|
+
},
|
|
4542
|
+
placeholder: {
|
|
4543
|
+
type: String,
|
|
4544
|
+
},
|
|
4545
|
+
dropPlaceholder: {
|
|
4546
|
+
type: String,
|
|
4547
|
+
},
|
|
4548
|
+
label: {
|
|
4549
|
+
type: String,
|
|
4550
|
+
},
|
|
4551
|
+
file: {
|
|
4552
|
+
type: Object,
|
|
4553
|
+
}
|
|
4554
|
+
},
|
|
4555
|
+
data() {
|
|
4556
|
+
return {
|
|
4557
|
+
rawImage: null,
|
|
4558
|
+
resizing: false,
|
|
4559
|
+
}
|
|
4560
|
+
},
|
|
4561
|
+
emits: ['loaded', 'error'],
|
|
4562
|
+
methods: {
|
|
4563
|
+
async onInput(file) {
|
|
4564
|
+
try {
|
|
4565
|
+
this.resizing = true;
|
|
4566
|
+
const reduce = new imageBlobReduce();
|
|
4567
|
+
const blob = await reduce.toBlob(file, { max: 1024 });
|
|
4568
|
+
const newFile = new File([blob], file.name, { type: file.type });
|
|
4569
|
+
this.$emit('loaded', newFile);
|
|
4570
|
+
} catch (err) {
|
|
4571
|
+
this.$emit('error');
|
|
4572
|
+
} finally {
|
|
4573
|
+
this.resizing = false;
|
|
4574
|
+
}
|
|
4575
|
+
},
|
|
4576
|
+
},
|
|
4577
|
+
});
|
|
4578
|
+
|
|
4579
|
+
function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
4580
|
+
const _component_image_input = resolveComponent("image-input");
|
|
4581
|
+
|
|
4582
|
+
return (openBlock(), createBlock(_component_image_input, {
|
|
4583
|
+
id: _ctx.id,
|
|
4584
|
+
name: _ctx.id,
|
|
4585
|
+
required: _ctx.required,
|
|
4586
|
+
placeholder: _ctx.placeholder,
|
|
4587
|
+
"drop-placeholder": _ctx.dropPlaceholder,
|
|
4588
|
+
label: _ctx.label,
|
|
4589
|
+
onUpdate: _ctx.onInput
|
|
4590
|
+
}, null, 8 /* PROPS */, ["id", "name", "required", "placeholder", "drop-placeholder", "label", "onUpdate"]))
|
|
4591
|
+
}
|
|
4592
|
+
|
|
935
4593
|
script.render = render;
|
|
936
|
-
script.__file = "src/
|
|
4594
|
+
script.__file = "src/ResizeImageUpload.vue";
|
|
937
4595
|
|
|
938
|
-
export { script$
|
|
4596
|
+
export { script$k as Card, script$i as CardBody, script$c as CardGrid, script$j as CardImage, script$f as CheckBoxInput, script$b as Container, script$l as DangerButton, script$d as ImageInput, script$q as Loading, script$3 as Navbar, script$e as NumberInput, script$1 as Pagination, script$n as RegularButton, script$p as ResetButton, script as ResizeImageUpload, script$m as SecondaryButton, script$r as SectionTitle, script$h as Selector, script$2 as StyledTable, script$o as SubmitButton, script$g as TextInput };
|
|
939
4597
|
//# sourceMappingURL=index.esm.js.map
|