@loaders.gl/video 3.3.0-alpha.1 → 3.3.0-alpha.11
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/dist.min.js +4 -2
- package/dist/es5/bundle.js +0 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/gif-builder.js +17 -37
- package/dist/es5/gif-builder.js.map +1 -1
- package/dist/es5/index.js +4 -7
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/gifshot/gifshot-loader.js +2 -17
- package/dist/es5/lib/gifshot/gifshot-loader.js.map +1 -1
- package/dist/es5/lib/gifshot/gifshot.js +8 -269
- package/dist/es5/lib/gifshot/gifshot.js.map +1 -1
- package/dist/es5/lib/parsers/parse-video.js +0 -6
- package/dist/es5/lib/parsers/parse-video.js.map +1 -1
- package/dist/es5/lib/utils/assert.js +0 -1
- package/dist/es5/lib/utils/assert.js.map +1 -1
- package/dist/es5/video-loader.js +2 -4
- package/dist/es5/video-loader.js.map +1 -1
- package/dist/esm/bundle.js +1 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/gif-builder.js +20 -13
- package/dist/esm/gif-builder.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/gifshot/gifshot-loader.js +4 -4
- package/dist/esm/lib/gifshot/gifshot-loader.js.map +1 -1
- package/dist/esm/lib/gifshot/gifshot.js +9 -269
- package/dist/esm/lib/gifshot/gifshot.js.map +1 -1
- package/dist/esm/lib/parsers/parse-video.js +1 -0
- package/dist/esm/lib/parsers/parse-video.js.map +1 -1
- package/dist/esm/lib/utils/assert.js.map +1 -1
- package/dist/esm/video-loader.js +3 -1
- package/dist/esm/video-loader.js.map +1 -1
- package/dist/lib/gifshot/gifshot.d.ts.map +1 -1
- package/dist/lib/gifshot/gifshot.js +7 -5
- package/dist/video-loader.d.ts +1 -1
- package/dist/video-loader.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/lib/gifshot/gifshot.ts +6 -5
|
@@ -1,28 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
var utils = {
|
|
2
4
|
URL: globalThis.URL || globalThis.webkitURL || globalThis.mozURL || globalThis.msURL,
|
|
3
5
|
getUserMedia: function () {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
if (!globalThis.navigator) return globalThis.navigator;
|
|
7
|
+
const getUserMedia = globalThis.navigator.getUserMedia || globalThis.navigator.webkitGetUserMedia || globalThis.navigator.mozGetUserMedia || globalThis.navigator.msGetUserMedia;
|
|
8
|
+
return getUserMedia ? getUserMedia.bind(globalThis.navigator) : getUserMedia;
|
|
6
9
|
}(),
|
|
7
10
|
requestAnimFrame: globalThis.requestAnimationFrame || globalThis.webkitRequestAnimationFrame || globalThis.mozRequestAnimationFrame || globalThis.oRequestAnimationFrame || globalThis.msRequestAnimationFrame,
|
|
8
11
|
requestTimeout: function requestTimeout(callback, delay) {
|
|
9
12
|
callback = callback || utils.noop;
|
|
10
13
|
delay = delay || 0;
|
|
11
|
-
|
|
12
14
|
if (!utils.requestAnimFrame) {
|
|
13
15
|
return setTimeout(callback, delay);
|
|
14
16
|
}
|
|
15
|
-
|
|
16
17
|
const start = new Date().getTime();
|
|
17
18
|
const handle = new Object();
|
|
18
19
|
const requestAnimFrame = utils.requestAnimFrame;
|
|
19
|
-
|
|
20
20
|
const loop = function loop() {
|
|
21
21
|
const current = new Date().getTime();
|
|
22
22
|
const delta = current - start;
|
|
23
23
|
delta >= delay ? callback.call() : handle.value = requestAnimFrame(loop);
|
|
24
24
|
};
|
|
25
|
-
|
|
26
25
|
handle.value = requestAnimFrame(loop);
|
|
27
26
|
return handle;
|
|
28
27
|
},
|
|
@@ -40,7 +39,6 @@ var utils = {
|
|
|
40
39
|
let enc2 = void 0;
|
|
41
40
|
let enc3 = void 0;
|
|
42
41
|
let enc4 = void 0;
|
|
43
|
-
|
|
44
42
|
while (i < l) {
|
|
45
43
|
chr1 = input.charCodeAt(i++);
|
|
46
44
|
chr2 = input.charCodeAt(i++);
|
|
@@ -49,19 +47,15 @@ var utils = {
|
|
|
49
47
|
enc2 = (chr1 & 3) << 4 | chr2 >> 4;
|
|
50
48
|
enc3 = (chr2 & 15) << 2 | chr3 >> 6;
|
|
51
49
|
enc4 = chr3 & 63;
|
|
52
|
-
|
|
53
50
|
if (isNaN(chr2)) {
|
|
54
51
|
enc3 = enc4 = 64;
|
|
55
52
|
} else if (isNaN(chr3)) {
|
|
56
53
|
enc4 = 64;
|
|
57
54
|
}
|
|
58
|
-
|
|
59
55
|
output = output + key.charAt(enc1) + key.charAt(enc2) + key.charAt(enc3) + key.charAt(enc4);
|
|
60
56
|
}
|
|
61
|
-
|
|
62
57
|
return output;
|
|
63
58
|
};
|
|
64
|
-
|
|
65
59
|
return btoa ? btoa.bind(globalThis) : utils.noop;
|
|
66
60
|
}(),
|
|
67
61
|
isObject: function isObject(obj) {
|
|
@@ -108,7 +102,6 @@ var utils = {
|
|
|
108
102
|
ogg: false,
|
|
109
103
|
webm: false
|
|
110
104
|
};
|
|
111
|
-
|
|
112
105
|
try {
|
|
113
106
|
if (testEl && testEl.canPlayType) {
|
|
114
107
|
supportObj.mp4 = testEl.canPlayType('video/mp4; codecs="mp4v.20.8"') !== '';
|
|
@@ -118,7 +111,6 @@ var utils = {
|
|
|
118
111
|
supportObj.webm = testEl.canPlayType('video/webm; codecs="vp8, vorbis"') !== -1;
|
|
119
112
|
}
|
|
120
113
|
} catch (e) {}
|
|
121
|
-
|
|
122
114
|
return supportObj;
|
|
123
115
|
}()
|
|
124
116
|
},
|
|
@@ -126,11 +118,9 @@ var utils = {
|
|
|
126
118
|
each: function each(collection, callback) {
|
|
127
119
|
let x = void 0;
|
|
128
120
|
let len = void 0;
|
|
129
|
-
|
|
130
121
|
if (utils.isArray(collection)) {
|
|
131
122
|
x = -1;
|
|
132
123
|
len = collection.length;
|
|
133
|
-
|
|
134
124
|
while (++x < len) {
|
|
135
125
|
if (callback(x, collection[x]) === false) {
|
|
136
126
|
break;
|
|
@@ -150,14 +140,12 @@ var utils = {
|
|
|
150
140
|
if (!utils.isObject(defaultOptions) || !utils.isObject(userOptions) || !Object.keys) {
|
|
151
141
|
return;
|
|
152
142
|
}
|
|
153
|
-
|
|
154
143
|
const newObj = {};
|
|
155
144
|
utils.each(defaultOptions, function (key, val) {
|
|
156
145
|
newObj[key] = defaultOptions[key];
|
|
157
146
|
});
|
|
158
147
|
utils.each(userOptions, function (key, val) {
|
|
159
148
|
const currentUserOption = userOptions[key];
|
|
160
|
-
|
|
161
149
|
if (!utils.isObject(currentUserOption)) {
|
|
162
150
|
newObj[key] = currentUserOption;
|
|
163
151
|
} else if (!defaultOptions[key]) {
|
|
@@ -172,7 +160,6 @@ var utils = {
|
|
|
172
160
|
if (!utils.isElement(elem)) {
|
|
173
161
|
return;
|
|
174
162
|
}
|
|
175
|
-
|
|
176
163
|
if (utils.isString(attr) && utils.isString(val)) {
|
|
177
164
|
elem.style[attr] = val;
|
|
178
165
|
} else if (utils.isObject(attr)) {
|
|
@@ -185,7 +172,6 @@ var utils = {
|
|
|
185
172
|
if (!utils.isElement(node)) {
|
|
186
173
|
return;
|
|
187
174
|
}
|
|
188
|
-
|
|
189
175
|
if (node.parentNode) {
|
|
190
176
|
node.parentNode.removeChild(node);
|
|
191
177
|
}
|
|
@@ -194,7 +180,6 @@ var utils = {
|
|
|
194
180
|
if (!utils.isString(content)) {
|
|
195
181
|
return {};
|
|
196
182
|
}
|
|
197
|
-
|
|
198
183
|
try {
|
|
199
184
|
const blob = new utils.Blob([content], {
|
|
200
185
|
type: 'text/javascript'
|
|
@@ -214,11 +199,9 @@ var utils = {
|
|
|
214
199
|
},
|
|
215
200
|
getFontSize: function getFontSize() {
|
|
216
201
|
const options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
217
|
-
|
|
218
202
|
if (!document.body || options.resizeFont === false) {
|
|
219
203
|
return options.fontSize;
|
|
220
204
|
}
|
|
221
|
-
|
|
222
205
|
const text = options.text;
|
|
223
206
|
const containerWidth = options.gifWidth;
|
|
224
207
|
let fontSize = parseInt(options.fontSize, 10);
|
|
@@ -232,11 +215,9 @@ var utils = {
|
|
|
232
215
|
span.style.textIndent = '-9999px';
|
|
233
216
|
span.style.visibility = 'hidden';
|
|
234
217
|
document.body.appendChild(span);
|
|
235
|
-
|
|
236
218
|
while (span.offsetWidth > containerWidth && fontSize >= minFontSize) {
|
|
237
219
|
span.style.fontSize = "".concat(--fontSize, "px");
|
|
238
220
|
}
|
|
239
|
-
|
|
240
221
|
document.body.removeChild(span);
|
|
241
222
|
return "".concat(fontSize, "px");
|
|
242
223
|
},
|
|
@@ -251,7 +232,6 @@ var error = {
|
|
|
251
232
|
let errorObj = {};
|
|
252
233
|
utils.each(error.validators, function (indece, currentValidator) {
|
|
253
234
|
const errorCode = currentValidator.errorCode;
|
|
254
|
-
|
|
255
235
|
if (!skipObj[errorCode] && !currentValidator.condition) {
|
|
256
236
|
errorObj = currentValidator;
|
|
257
237
|
errorObj.error = true;
|
|
@@ -305,9 +285,7 @@ var error = {
|
|
|
305
285
|
const error$2 = Object.freeze({
|
|
306
286
|
default: error
|
|
307
287
|
});
|
|
308
|
-
|
|
309
288
|
const noop = function noop() {};
|
|
310
|
-
|
|
311
289
|
const defaultOptions = {
|
|
312
290
|
sampleInterval: 10,
|
|
313
291
|
numWorkers: 2,
|
|
@@ -342,32 +320,26 @@ const defaultOptions = {
|
|
|
342
320
|
const defaultOptions$2 = Object.freeze({
|
|
343
321
|
default: defaultOptions
|
|
344
322
|
});
|
|
345
|
-
|
|
346
323
|
function isSupported() {
|
|
347
324
|
return error.isValid();
|
|
348
325
|
}
|
|
349
|
-
|
|
350
326
|
function isWebCamGIFSupported() {
|
|
351
327
|
return error.isValid();
|
|
352
328
|
}
|
|
353
|
-
|
|
354
329
|
function isSupported$1() {
|
|
355
330
|
const options = {
|
|
356
331
|
getUserMedia: true
|
|
357
332
|
};
|
|
358
333
|
return error.isValid(options);
|
|
359
334
|
}
|
|
360
|
-
|
|
361
335
|
function isExistingVideoGIFSupported(codecs) {
|
|
362
336
|
let hasValidCodec = false;
|
|
363
|
-
|
|
364
337
|
if (utils.isArray(codecs) && codecs.length) {
|
|
365
338
|
utils.each(codecs, function (indece, currentCodec) {
|
|
366
339
|
if (utils.isSupported.videoCodecs[currentCodec]) {
|
|
367
340
|
hasValidCodec = true;
|
|
368
341
|
}
|
|
369
342
|
});
|
|
370
|
-
|
|
371
343
|
if (!hasValidCodec) {
|
|
372
344
|
return false;
|
|
373
345
|
}
|
|
@@ -376,12 +348,10 @@ function isExistingVideoGIFSupported(codecs) {
|
|
|
376
348
|
return false;
|
|
377
349
|
}
|
|
378
350
|
}
|
|
379
|
-
|
|
380
351
|
return error.isValid({
|
|
381
352
|
getUserMedia: true
|
|
382
353
|
});
|
|
383
354
|
}
|
|
384
|
-
|
|
385
355
|
function NeuQuant() {
|
|
386
356
|
const netsize = 256;
|
|
387
357
|
const prime1 = 499;
|
|
@@ -419,7 +389,6 @@ function NeuQuant() {
|
|
|
419
389
|
const bias = [];
|
|
420
390
|
const freq = [];
|
|
421
391
|
const radpower = [];
|
|
422
|
-
|
|
423
392
|
function NeuQuantConstructor(thepic, len, sample) {
|
|
424
393
|
let i;
|
|
425
394
|
let p;
|
|
@@ -427,7 +396,6 @@ function NeuQuant() {
|
|
|
427
396
|
lengthcount = len;
|
|
428
397
|
samplefac = sample;
|
|
429
398
|
network = new Array(netsize);
|
|
430
|
-
|
|
431
399
|
for (i = 0; i < netsize; i++) {
|
|
432
400
|
network[i] = new Array(4);
|
|
433
401
|
p = network[i];
|
|
@@ -436,27 +404,21 @@ function NeuQuant() {
|
|
|
436
404
|
bias[i] = 0;
|
|
437
405
|
}
|
|
438
406
|
}
|
|
439
|
-
|
|
440
407
|
function colorMap() {
|
|
441
408
|
const map = [];
|
|
442
409
|
const index = new Array(netsize);
|
|
443
|
-
|
|
444
410
|
for (let i = 0; i < netsize; i++) {
|
|
445
411
|
index[network[i][3]] = i;
|
|
446
412
|
}
|
|
447
|
-
|
|
448
413
|
let k = 0;
|
|
449
|
-
|
|
450
414
|
for (let l = 0; l < netsize; l++) {
|
|
451
415
|
const j = index[l];
|
|
452
416
|
map[k++] = network[j][0];
|
|
453
417
|
map[k++] = network[j][1];
|
|
454
418
|
map[k++] = network[j][2];
|
|
455
419
|
}
|
|
456
|
-
|
|
457
420
|
return map;
|
|
458
421
|
}
|
|
459
|
-
|
|
460
422
|
function inxbuild() {
|
|
461
423
|
let i;
|
|
462
424
|
let j;
|
|
@@ -468,15 +430,12 @@ function NeuQuant() {
|
|
|
468
430
|
let startpos;
|
|
469
431
|
previouscol = 0;
|
|
470
432
|
startpos = 0;
|
|
471
|
-
|
|
472
433
|
for (i = 0; i < netsize; i++) {
|
|
473
434
|
p = network[i];
|
|
474
435
|
smallpos = i;
|
|
475
436
|
smallval = p[1];
|
|
476
|
-
|
|
477
437
|
for (j = i + 1; j < netsize; j++) {
|
|
478
438
|
q = network[j];
|
|
479
|
-
|
|
480
439
|
if (q[1] < smallval) {
|
|
481
440
|
smallpos = j;
|
|
482
441
|
smallval = q[1];
|
|
@@ -484,7 +443,6 @@ function NeuQuant() {
|
|
|
484
443
|
}
|
|
485
444
|
|
|
486
445
|
q = network[smallpos];
|
|
487
|
-
|
|
488
446
|
if (i != smallpos) {
|
|
489
447
|
j = q[0];
|
|
490
448
|
q[0] = p[0];
|
|
@@ -499,26 +457,20 @@ function NeuQuant() {
|
|
|
499
457
|
q[3] = p[3];
|
|
500
458
|
p[3] = j;
|
|
501
459
|
}
|
|
502
|
-
|
|
503
460
|
if (smallval != previouscol) {
|
|
504
461
|
netindex[previouscol] = startpos + i >> 1;
|
|
505
|
-
|
|
506
462
|
for (j = previouscol + 1; j < smallval; j++) {
|
|
507
463
|
netindex[j] = i;
|
|
508
464
|
}
|
|
509
|
-
|
|
510
465
|
previouscol = smallval;
|
|
511
466
|
startpos = i;
|
|
512
467
|
}
|
|
513
468
|
}
|
|
514
|
-
|
|
515
469
|
netindex[previouscol] = startpos + maxnetpos >> 1;
|
|
516
|
-
|
|
517
470
|
for (j = previouscol + 1; j < 256; j++) {
|
|
518
471
|
netindex[j] = maxnetpos;
|
|
519
472
|
}
|
|
520
473
|
}
|
|
521
|
-
|
|
522
474
|
function learn() {
|
|
523
475
|
let i;
|
|
524
476
|
let j;
|
|
@@ -534,11 +486,9 @@ function NeuQuant() {
|
|
|
534
486
|
let p;
|
|
535
487
|
let pix;
|
|
536
488
|
let lim;
|
|
537
|
-
|
|
538
489
|
if (lengthcount < minpicturebytes) {
|
|
539
490
|
samplefac = 1;
|
|
540
491
|
}
|
|
541
|
-
|
|
542
492
|
alphadec = 30 + (samplefac - 1) / 3;
|
|
543
493
|
p = thepicture;
|
|
544
494
|
pix = 0;
|
|
@@ -548,15 +498,12 @@ function NeuQuant() {
|
|
|
548
498
|
alpha = initalpha;
|
|
549
499
|
radius = initradius;
|
|
550
500
|
rad = radius >> radiusbiasshift;
|
|
551
|
-
|
|
552
501
|
if (rad <= 1) {
|
|
553
502
|
rad = 0;
|
|
554
503
|
}
|
|
555
|
-
|
|
556
504
|
for (i = 0; i < rad; i++) {
|
|
557
505
|
radpower[i] = alpha * ((rad * rad - i * i) * radbias / (rad * rad));
|
|
558
506
|
}
|
|
559
|
-
|
|
560
507
|
if (lengthcount < minpicturebytes) {
|
|
561
508
|
step = 3;
|
|
562
509
|
} else if (lengthcount % prime1 !== 0) {
|
|
@@ -568,48 +515,37 @@ function NeuQuant() {
|
|
|
568
515
|
} else {
|
|
569
516
|
step = 3 * prime4;
|
|
570
517
|
}
|
|
571
|
-
|
|
572
518
|
i = 0;
|
|
573
|
-
|
|
574
519
|
while (i < samplepixels) {
|
|
575
520
|
b = (p[pix + 0] & 0xff) << netbiasshift;
|
|
576
521
|
g = (p[pix + 1] & 0xff) << netbiasshift;
|
|
577
522
|
r = (p[pix + 2] & 0xff) << netbiasshift;
|
|
578
523
|
j = contest(b, g, r);
|
|
579
524
|
altersingle(alpha, j, b, g, r);
|
|
580
|
-
|
|
581
525
|
if (rad !== 0) {
|
|
582
526
|
alterneigh(rad, j, b, g, r);
|
|
583
527
|
}
|
|
584
|
-
|
|
585
528
|
pix += step;
|
|
586
|
-
|
|
587
529
|
if (pix >= lim) {
|
|
588
530
|
pix -= lengthcount;
|
|
589
531
|
}
|
|
590
|
-
|
|
591
532
|
i++;
|
|
592
|
-
|
|
593
533
|
if (delta === 0) {
|
|
594
534
|
delta = 1;
|
|
595
535
|
}
|
|
596
|
-
|
|
597
536
|
if (i % delta === 0) {
|
|
598
537
|
alpha -= alpha / alphadec;
|
|
599
538
|
radius -= radius / radiusdec;
|
|
600
539
|
rad = radius >> radiusbiasshift;
|
|
601
|
-
|
|
602
540
|
if (rad <= 1) {
|
|
603
541
|
rad = 0;
|
|
604
542
|
}
|
|
605
|
-
|
|
606
543
|
for (j = 0; j < rad; j++) {
|
|
607
544
|
radpower[j] = alpha * ((rad * rad - j * j) * radbias / (rad * rad));
|
|
608
545
|
}
|
|
609
546
|
}
|
|
610
547
|
}
|
|
611
548
|
}
|
|
612
|
-
|
|
613
549
|
function map(b, g, r) {
|
|
614
550
|
let i;
|
|
615
551
|
let j;
|
|
@@ -622,38 +558,28 @@ function NeuQuant() {
|
|
|
622
558
|
best = -1;
|
|
623
559
|
i = netindex[g];
|
|
624
560
|
j = i - 1;
|
|
625
|
-
|
|
626
561
|
while (i < netsize || j >= 0) {
|
|
627
562
|
if (i < netsize) {
|
|
628
563
|
p = network[i];
|
|
629
564
|
dist = p[1] - g;
|
|
630
|
-
|
|
631
565
|
if (dist >= bestd) {
|
|
632
566
|
i = netsize;
|
|
633
567
|
} else {
|
|
634
568
|
i++;
|
|
635
|
-
|
|
636
569
|
if (dist < 0) {
|
|
637
570
|
dist = -dist;
|
|
638
571
|
}
|
|
639
|
-
|
|
640
572
|
a = p[0] - b;
|
|
641
|
-
|
|
642
573
|
if (a < 0) {
|
|
643
574
|
a = -a;
|
|
644
575
|
}
|
|
645
|
-
|
|
646
576
|
dist += a;
|
|
647
|
-
|
|
648
577
|
if (dist < bestd) {
|
|
649
578
|
a = p[2] - r;
|
|
650
|
-
|
|
651
579
|
if (a < 0) {
|
|
652
580
|
a = -a;
|
|
653
581
|
}
|
|
654
|
-
|
|
655
582
|
dist += a;
|
|
656
|
-
|
|
657
583
|
if (dist < bestd) {
|
|
658
584
|
bestd = dist;
|
|
659
585
|
best = p[3];
|
|
@@ -661,37 +587,27 @@ function NeuQuant() {
|
|
|
661
587
|
}
|
|
662
588
|
}
|
|
663
589
|
}
|
|
664
|
-
|
|
665
590
|
if (j >= 0) {
|
|
666
591
|
p = network[j];
|
|
667
592
|
dist = g - p[1];
|
|
668
|
-
|
|
669
593
|
if (dist >= bestd) {
|
|
670
594
|
j = -1;
|
|
671
595
|
} else {
|
|
672
596
|
j--;
|
|
673
|
-
|
|
674
597
|
if (dist < 0) {
|
|
675
598
|
dist = -dist;
|
|
676
599
|
}
|
|
677
|
-
|
|
678
600
|
a = p[0] - b;
|
|
679
|
-
|
|
680
601
|
if (a < 0) {
|
|
681
602
|
a = -a;
|
|
682
603
|
}
|
|
683
|
-
|
|
684
604
|
dist += a;
|
|
685
|
-
|
|
686
605
|
if (dist < bestd) {
|
|
687
606
|
a = p[2] - r;
|
|
688
|
-
|
|
689
607
|
if (a < 0) {
|
|
690
608
|
a = -a;
|
|
691
609
|
}
|
|
692
|
-
|
|
693
610
|
dist += a;
|
|
694
|
-
|
|
695
611
|
if (dist < bestd) {
|
|
696
612
|
bestd = dist;
|
|
697
613
|
best = p[3];
|
|
@@ -700,21 +616,17 @@ function NeuQuant() {
|
|
|
700
616
|
}
|
|
701
617
|
}
|
|
702
618
|
}
|
|
703
|
-
|
|
704
619
|
return best;
|
|
705
620
|
}
|
|
706
|
-
|
|
707
621
|
function process() {
|
|
708
622
|
learn();
|
|
709
623
|
unbiasnet();
|
|
710
624
|
inxbuild();
|
|
711
625
|
return colorMap();
|
|
712
626
|
}
|
|
713
|
-
|
|
714
627
|
function unbiasnet() {
|
|
715
628
|
let i;
|
|
716
629
|
let j;
|
|
717
|
-
|
|
718
630
|
for (i = 0; i < netsize; i++) {
|
|
719
631
|
network[i][0] >>= netbiasshift;
|
|
720
632
|
network[i][1] >>= netbiasshift;
|
|
@@ -722,7 +634,6 @@ function NeuQuant() {
|
|
|
722
634
|
network[i][3] = i;
|
|
723
635
|
}
|
|
724
636
|
}
|
|
725
|
-
|
|
726
637
|
function alterneigh(rad, i, b, g, r) {
|
|
727
638
|
let j;
|
|
728
639
|
let k;
|
|
@@ -732,37 +643,28 @@ function NeuQuant() {
|
|
|
732
643
|
let m;
|
|
733
644
|
let p;
|
|
734
645
|
lo = i - rad;
|
|
735
|
-
|
|
736
646
|
if (lo < -1) {
|
|
737
647
|
lo = -1;
|
|
738
648
|
}
|
|
739
|
-
|
|
740
649
|
hi = i + rad;
|
|
741
|
-
|
|
742
650
|
if (hi > netsize) {
|
|
743
651
|
hi = netsize;
|
|
744
652
|
}
|
|
745
|
-
|
|
746
653
|
j = i + 1;
|
|
747
654
|
k = i - 1;
|
|
748
655
|
m = 1;
|
|
749
|
-
|
|
750
656
|
while (j < hi || k > lo) {
|
|
751
657
|
a = radpower[m++];
|
|
752
|
-
|
|
753
658
|
if (j < hi) {
|
|
754
659
|
p = network[j++];
|
|
755
|
-
|
|
756
660
|
try {
|
|
757
661
|
p[0] -= a * (p[0] - b) / alpharadbias | 0;
|
|
758
662
|
p[1] -= a * (p[1] - g) / alpharadbias | 0;
|
|
759
663
|
p[2] -= a * (p[2] - r) / alpharadbias | 0;
|
|
760
664
|
} catch (e) {}
|
|
761
665
|
}
|
|
762
|
-
|
|
763
666
|
if (k > lo) {
|
|
764
667
|
p = network[k--];
|
|
765
|
-
|
|
766
668
|
try {
|
|
767
669
|
p[0] -= a * (p[0] - b) / alpharadbias | 0;
|
|
768
670
|
p[1] -= a * (p[1] - g) / alpharadbias | 0;
|
|
@@ -771,7 +673,6 @@ function NeuQuant() {
|
|
|
771
673
|
}
|
|
772
674
|
}
|
|
773
675
|
}
|
|
774
|
-
|
|
775
676
|
function altersingle(alpha, i, b, g, r) {
|
|
776
677
|
const n = network[i];
|
|
777
678
|
const alphaMult = alpha / initalpha;
|
|
@@ -779,7 +680,6 @@ function NeuQuant() {
|
|
|
779
680
|
n[1] -= alphaMult * (n[1] - g) | 0;
|
|
780
681
|
n[2] -= alphaMult * (n[2] - r) | 0;
|
|
781
682
|
}
|
|
782
|
-
|
|
783
683
|
function contest(b, g, r) {
|
|
784
684
|
let i;
|
|
785
685
|
let dist;
|
|
@@ -795,80 +695,62 @@ function NeuQuant() {
|
|
|
795
695
|
bestbiasd = bestd;
|
|
796
696
|
bestpos = -1;
|
|
797
697
|
bestbiaspos = bestpos;
|
|
798
|
-
|
|
799
698
|
for (i = 0; i < netsize; i++) {
|
|
800
699
|
n = network[i];
|
|
801
700
|
dist = n[0] - b;
|
|
802
|
-
|
|
803
701
|
if (dist < 0) {
|
|
804
702
|
dist = -dist;
|
|
805
703
|
}
|
|
806
|
-
|
|
807
704
|
a = n[1] - g;
|
|
808
|
-
|
|
809
705
|
if (a < 0) {
|
|
810
706
|
a = -a;
|
|
811
707
|
}
|
|
812
|
-
|
|
813
708
|
dist += a;
|
|
814
709
|
a = n[2] - r;
|
|
815
|
-
|
|
816
710
|
if (a < 0) {
|
|
817
711
|
a = -a;
|
|
818
712
|
}
|
|
819
|
-
|
|
820
713
|
dist += a;
|
|
821
|
-
|
|
822
714
|
if (dist < bestd) {
|
|
823
715
|
bestd = dist;
|
|
824
716
|
bestpos = i;
|
|
825
717
|
}
|
|
826
|
-
|
|
827
718
|
biasdist = dist - (bias[i] >> intbiasshift - netbiasshift);
|
|
828
|
-
|
|
829
719
|
if (biasdist < bestbiasd) {
|
|
830
720
|
bestbiasd = biasdist;
|
|
831
721
|
bestbiaspos = i;
|
|
832
722
|
}
|
|
833
|
-
|
|
834
723
|
betafreq = freq[i] >> betashift;
|
|
835
724
|
freq[i] -= betafreq;
|
|
836
725
|
bias[i] += betafreq << gammashift;
|
|
837
726
|
}
|
|
838
|
-
|
|
839
727
|
freq[bestpos] += beta;
|
|
840
728
|
bias[bestpos] -= betagamma;
|
|
841
729
|
return bestbiaspos;
|
|
842
730
|
}
|
|
843
|
-
|
|
844
731
|
NeuQuantConstructor.apply(this, arguments);
|
|
845
732
|
const exports = {};
|
|
846
733
|
exports.map = map;
|
|
847
734
|
exports.process = process;
|
|
848
735
|
return exports;
|
|
849
736
|
}
|
|
850
|
-
|
|
851
737
|
function workerCode() {
|
|
852
738
|
const self = this;
|
|
853
|
-
|
|
854
739
|
try {
|
|
855
740
|
globalThis.onmessage = function (ev) {
|
|
856
741
|
const data = ev.data || {};
|
|
857
742
|
let response;
|
|
858
|
-
|
|
859
743
|
if (data.gifshot) {
|
|
860
744
|
response = workerMethods.run(data);
|
|
861
745
|
postMessage(response);
|
|
862
746
|
}
|
|
863
747
|
};
|
|
864
748
|
} catch (e) {}
|
|
865
|
-
|
|
866
749
|
var workerMethods = {
|
|
867
750
|
dataToRGB: function dataToRGB(data, width, height) {
|
|
868
751
|
const length = width * height * 4;
|
|
869
752
|
let i = 0;
|
|
870
753
|
const rgb = [];
|
|
871
|
-
|
|
872
754
|
while (i < length) {
|
|
873
755
|
rgb.push(data[i++]);
|
|
874
756
|
rgb.push(data[i++]);
|
|
@@ -881,14 +763,12 @@ function workerCode() {
|
|
|
881
763
|
componentizedPaletteToArray: function componentizedPaletteToArray(paletteRGB) {
|
|
882
764
|
paletteRGB = paletteRGB || [];
|
|
883
765
|
const paletteArray = [];
|
|
884
|
-
|
|
885
766
|
for (let i = 0; i < paletteRGB.length; i += 3) {
|
|
886
767
|
const r = paletteRGB[i];
|
|
887
768
|
const g = paletteRGB[i + 1];
|
|
888
769
|
const b = paletteRGB[i + 2];
|
|
889
770
|
paletteArray.push(r << 16 | g << 8 | b);
|
|
890
771
|
}
|
|
891
|
-
|
|
892
772
|
return paletteArray;
|
|
893
773
|
},
|
|
894
774
|
processFrameWithQuantizer: function processFrameWithQuantizer(imageData, width, height, sampleInterval) {
|
|
@@ -899,14 +779,12 @@ function workerCode() {
|
|
|
899
779
|
const numberPixels = width * height;
|
|
900
780
|
const indexedPixels = new Uint8Array(numberPixels);
|
|
901
781
|
let k = 0;
|
|
902
|
-
|
|
903
782
|
for (let i = 0; i < numberPixels; i++) {
|
|
904
783
|
const r = rgbComponents[k++];
|
|
905
784
|
const g = rgbComponents[k++];
|
|
906
785
|
const b = rgbComponents[k++];
|
|
907
786
|
indexedPixels[i] = nq.map(r, g, b);
|
|
908
787
|
}
|
|
909
|
-
|
|
910
788
|
return {
|
|
911
789
|
pixels: indexedPixels,
|
|
912
790
|
palette: paletteArray
|
|
@@ -925,20 +803,17 @@ function workerCode() {
|
|
|
925
803
|
};
|
|
926
804
|
return workerMethods;
|
|
927
805
|
}
|
|
928
|
-
|
|
929
806
|
function gifWriter(buf, width, height, gopts) {
|
|
930
807
|
let p = 0;
|
|
931
808
|
gopts = gopts === undefined ? {} : gopts;
|
|
932
809
|
const loop_count = gopts.loop === undefined ? null : gopts.loop;
|
|
933
810
|
const global_palette = gopts.palette === undefined ? null : gopts.palette;
|
|
934
811
|
if (width <= 0 || height <= 0 || width > 65535 || height > 65535) throw 'Width/Height invalid.';
|
|
935
|
-
|
|
936
812
|
function check_palette_and_num_colors(palette) {
|
|
937
813
|
const num_colors = palette.length;
|
|
938
814
|
if (num_colors < 2 || num_colors > 256 || num_colors & num_colors - 1) throw 'Invalid code/color length, must be power of 2 and 2 .. 256.';
|
|
939
815
|
return num_colors;
|
|
940
816
|
}
|
|
941
|
-
|
|
942
817
|
buf[p++] = 0x47;
|
|
943
818
|
buf[p++] = 0x49;
|
|
944
819
|
buf[p++] = 0x46;
|
|
@@ -951,10 +826,10 @@ function gifWriter(buf, width, height, gopts) {
|
|
|
951
826
|
buf[p++] = width >> 8 & 0xff;
|
|
952
827
|
buf[p++] = height & 0xff;
|
|
953
828
|
buf[p++] = height >> 8 & 0xff;
|
|
954
|
-
buf[p++] = (global_palette !== null ? 0x80 : 0) |
|
|
829
|
+
buf[p++] = (global_palette !== null ? 0x80 : 0) |
|
|
830
|
+
gp_num_colors_pow2;
|
|
955
831
|
buf[p++] = background;
|
|
956
832
|
buf[p++] = 0;
|
|
957
|
-
|
|
958
833
|
if (loop_count !== null) {
|
|
959
834
|
if (loop_count < 0 || loop_count > 65535) throw 'Loop count invalid.';
|
|
960
835
|
buf[p++] = 0x21;
|
|
@@ -979,46 +854,39 @@ function gifWriter(buf, width, height, gopts) {
|
|
|
979
854
|
}
|
|
980
855
|
|
|
981
856
|
let ended = false;
|
|
982
|
-
|
|
983
857
|
this.addFrame = function (x, y, w, h, indexed_pixels, opts) {
|
|
984
858
|
if (ended === true) {
|
|
985
859
|
--p;
|
|
986
860
|
ended = false;
|
|
987
861
|
}
|
|
988
|
-
|
|
989
862
|
opts = opts === undefined ? {} : opts;
|
|
990
863
|
if (x < 0 || y < 0 || x > 65535 || y > 65535) throw 'x/y invalid.';
|
|
991
864
|
if (w <= 0 || h <= 0 || w > 65535 || h > 65535) throw 'Width/Height invalid.';
|
|
992
865
|
if (indexed_pixels.length < w * h) throw 'Not enough pixels for the frame size.';
|
|
993
866
|
let using_local_palette = true;
|
|
994
867
|
let palette = opts.palette;
|
|
995
|
-
|
|
996
868
|
if (palette === undefined || palette === null) {
|
|
997
869
|
using_local_palette = false;
|
|
998
870
|
palette = global_palette;
|
|
999
871
|
}
|
|
1000
|
-
|
|
1001
872
|
if (palette === undefined || palette === null) throw 'Must supply either a local or global palette.';
|
|
1002
873
|
let num_colors = check_palette_and_num_colors(palette);
|
|
1003
874
|
let min_code_size = 0;
|
|
1004
|
-
|
|
1005
875
|
while (num_colors >>= 1) {
|
|
1006
876
|
++min_code_size;
|
|
1007
877
|
}
|
|
1008
|
-
|
|
1009
878
|
num_colors = 1 << min_code_size;
|
|
1010
879
|
const delay = opts.delay === undefined ? 0 : opts.delay;
|
|
1011
880
|
const disposal = opts.disposal === undefined ? 0 : opts.disposal;
|
|
1012
|
-
if (disposal < 0 || disposal > 3)
|
|
881
|
+
if (disposal < 0 || disposal > 3)
|
|
882
|
+
throw 'Disposal out of range.';
|
|
1013
883
|
let use_transparency = false;
|
|
1014
884
|
let transparent_index = 0;
|
|
1015
|
-
|
|
1016
885
|
if (opts.transparent !== undefined && opts.transparent !== null) {
|
|
1017
886
|
use_transparency = true;
|
|
1018
887
|
transparent_index = opts.transparent;
|
|
1019
888
|
if (transparent_index < 0 || transparent_index >= num_colors) throw 'Transparent color index.';
|
|
1020
889
|
}
|
|
1021
|
-
|
|
1022
890
|
if (disposal !== 0 || use_transparency || delay !== 0) {
|
|
1023
891
|
buf[p++] = 0x21;
|
|
1024
892
|
buf[p++] = 0xf9;
|
|
@@ -1029,7 +897,6 @@ function gifWriter(buf, width, height, gopts) {
|
|
|
1029
897
|
buf[p++] = transparent_index;
|
|
1030
898
|
buf[p++] = 0;
|
|
1031
899
|
}
|
|
1032
|
-
|
|
1033
900
|
buf[p++] = 0x2c;
|
|
1034
901
|
buf[p++] = x & 0xff;
|
|
1035
902
|
buf[p++] = x >> 8 & 0xff;
|
|
@@ -1040,7 +907,6 @@ function gifWriter(buf, width, height, gopts) {
|
|
|
1040
907
|
buf[p++] = h & 0xff;
|
|
1041
908
|
buf[p++] = h >> 8 & 0xff;
|
|
1042
909
|
buf[p++] = using_local_palette === true ? 0x80 | min_code_size - 1 : 0;
|
|
1043
|
-
|
|
1044
910
|
if (using_local_palette === true) {
|
|
1045
911
|
for (let i = 0, il = palette.length; i < il; ++i) {
|
|
1046
912
|
const rgb = palette[i];
|
|
@@ -1049,19 +915,15 @@ function gifWriter(buf, width, height, gopts) {
|
|
|
1049
915
|
buf[p++] = rgb & 0xff;
|
|
1050
916
|
}
|
|
1051
917
|
}
|
|
1052
|
-
|
|
1053
918
|
p = GifWriterOutputLZWCodeStream(buf, p, min_code_size < 2 ? 2 : min_code_size, indexed_pixels);
|
|
1054
919
|
};
|
|
1055
|
-
|
|
1056
920
|
this.end = function () {
|
|
1057
921
|
if (ended === false) {
|
|
1058
922
|
buf[p++] = 0x3b;
|
|
1059
923
|
ended = true;
|
|
1060
924
|
}
|
|
1061
|
-
|
|
1062
925
|
return p;
|
|
1063
926
|
};
|
|
1064
|
-
|
|
1065
927
|
function GifWriterOutputLZWCodeStream(buf, p, min_code_size, index_stream) {
|
|
1066
928
|
buf[p++] = min_code_size;
|
|
1067
929
|
let cur_subblock = p++;
|
|
@@ -1072,50 +934,41 @@ function gifWriter(buf, width, height, gopts) {
|
|
|
1072
934
|
let cur_code_size = min_code_size + 1;
|
|
1073
935
|
let cur_shift = 0;
|
|
1074
936
|
let cur = 0;
|
|
1075
|
-
|
|
1076
937
|
function emit_bytes_to_buffer(bit_block_size) {
|
|
1077
938
|
while (cur_shift >= bit_block_size) {
|
|
1078
939
|
buf[p++] = cur & 0xff;
|
|
1079
940
|
cur >>= 8;
|
|
1080
941
|
cur_shift -= 8;
|
|
1081
|
-
|
|
1082
942
|
if (p === cur_subblock + 256) {
|
|
1083
943
|
buf[cur_subblock] = 255;
|
|
1084
944
|
cur_subblock = p++;
|
|
1085
945
|
}
|
|
1086
946
|
}
|
|
1087
947
|
}
|
|
1088
|
-
|
|
1089
948
|
function emit_code(c) {
|
|
1090
949
|
cur |= c << cur_shift;
|
|
1091
950
|
cur_shift += cur_code_size;
|
|
1092
951
|
emit_bytes_to_buffer(8);
|
|
1093
952
|
}
|
|
1094
|
-
|
|
1095
953
|
let ib_code = index_stream[0] & code_mask;
|
|
1096
954
|
let code_table = {};
|
|
1097
955
|
emit_code(clear_code);
|
|
1098
|
-
|
|
1099
956
|
for (let i = 1, il = index_stream.length; i < il; ++i) {
|
|
1100
957
|
const k = index_stream[i] & code_mask;
|
|
1101
958
|
const cur_key = ib_code << 8 | k;
|
|
1102
959
|
const cur_code = code_table[cur_key];
|
|
1103
|
-
|
|
1104
960
|
if (cur_code === undefined) {
|
|
1105
961
|
cur |= ib_code << cur_shift;
|
|
1106
962
|
cur_shift += cur_code_size;
|
|
1107
|
-
|
|
1108
963
|
while (cur_shift >= 8) {
|
|
1109
964
|
buf[p++] = cur & 0xff;
|
|
1110
965
|
cur >>= 8;
|
|
1111
966
|
cur_shift -= 8;
|
|
1112
|
-
|
|
1113
967
|
if (p === cur_subblock + 256) {
|
|
1114
968
|
buf[cur_subblock] = 255;
|
|
1115
969
|
cur_subblock = p++;
|
|
1116
970
|
}
|
|
1117
971
|
}
|
|
1118
|
-
|
|
1119
972
|
if (next_code === 4096) {
|
|
1120
973
|
emit_code(clear_code);
|
|
1121
974
|
next_code = eoi_code + 1;
|
|
@@ -1135,20 +988,16 @@ function gifWriter(buf, width, height, gopts) {
|
|
|
1135
988
|
emit_code(ib_code);
|
|
1136
989
|
emit_code(eoi_code);
|
|
1137
990
|
emit_bytes_to_buffer(1);
|
|
1138
|
-
|
|
1139
991
|
if (cur_subblock + 1 === p) {
|
|
1140
992
|
buf[cur_subblock] = 0;
|
|
1141
993
|
} else {
|
|
1142
994
|
buf[cur_subblock] = p - cur_subblock - 1;
|
|
1143
995
|
buf[p++] = 0;
|
|
1144
996
|
}
|
|
1145
|
-
|
|
1146
997
|
return p;
|
|
1147
998
|
}
|
|
1148
999
|
}
|
|
1149
|
-
|
|
1150
1000
|
const noop$2 = function noop() {};
|
|
1151
|
-
|
|
1152
1001
|
const AnimatedGIF = function AnimatedGIF(options) {
|
|
1153
1002
|
this.canvas = null;
|
|
1154
1003
|
this.ctx = null;
|
|
@@ -1163,7 +1012,6 @@ const AnimatedGIF = function AnimatedGIF(options) {
|
|
|
1163
1012
|
this.options = options;
|
|
1164
1013
|
this.initializeWebWorkers(options);
|
|
1165
1014
|
};
|
|
1166
|
-
|
|
1167
1015
|
AnimatedGIF.prototype = {
|
|
1168
1016
|
workerMethods: workerCode(),
|
|
1169
1017
|
initializeWebWorkers: function initializeWebWorkers(options) {
|
|
@@ -1176,10 +1024,8 @@ AnimatedGIF.prototype = {
|
|
|
1176
1024
|
let x = -1;
|
|
1177
1025
|
let workerError = '';
|
|
1178
1026
|
numWorkers = options.numWorkers;
|
|
1179
|
-
|
|
1180
1027
|
while (++x < numWorkers) {
|
|
1181
1028
|
webWorkerObj = utils.createWebWorker(processFrameWorkerCode);
|
|
1182
|
-
|
|
1183
1029
|
if (utils.isObject(webWorkerObj)) {
|
|
1184
1030
|
objectUrl = webWorkerObj.objectUrl;
|
|
1185
1031
|
webWorker = webWorkerObj.worker;
|
|
@@ -1193,7 +1039,6 @@ AnimatedGIF.prototype = {
|
|
|
1193
1039
|
utils.webWorkerError = Boolean(webWorkerObj);
|
|
1194
1040
|
}
|
|
1195
1041
|
}
|
|
1196
|
-
|
|
1197
1042
|
this.workerError = workerError;
|
|
1198
1043
|
this.canvas = document.createElement('canvas');
|
|
1199
1044
|
this.canvas.width = options.gifWidth;
|
|
@@ -1209,22 +1054,18 @@ AnimatedGIF.prototype = {
|
|
|
1209
1054
|
},
|
|
1210
1055
|
byteMap: function () {
|
|
1211
1056
|
const byteMap = [];
|
|
1212
|
-
|
|
1213
1057
|
for (let i = 0; i < 256; i++) {
|
|
1214
1058
|
byteMap[i] = String.fromCharCode(i);
|
|
1215
1059
|
}
|
|
1216
|
-
|
|
1217
1060
|
return byteMap;
|
|
1218
1061
|
}(),
|
|
1219
1062
|
bufferToString: function bufferToString(buffer) {
|
|
1220
1063
|
const numberValues = buffer.length;
|
|
1221
1064
|
let str = '';
|
|
1222
1065
|
let x = -1;
|
|
1223
|
-
|
|
1224
1066
|
while (++x < numberValues) {
|
|
1225
1067
|
str += this.byteMap[buffer[x]];
|
|
1226
1068
|
}
|
|
1227
|
-
|
|
1228
1069
|
return str;
|
|
1229
1070
|
},
|
|
1230
1071
|
onFrameFinished: function onFrameFinished(progressCallback) {
|
|
@@ -1236,13 +1077,10 @@ AnimatedGIF.prototype = {
|
|
|
1236
1077
|
return !frame.beingProcessed && frame.done;
|
|
1237
1078
|
});
|
|
1238
1079
|
self.numRenderedFrames++;
|
|
1239
|
-
|
|
1240
1080
|
if (hasExistingImages) {
|
|
1241
1081
|
progressCallback(self.numRenderedFrames / frames.length);
|
|
1242
1082
|
}
|
|
1243
|
-
|
|
1244
1083
|
self.onRenderProgressCallback(self.numRenderedFrames * 0.75 / frames.length);
|
|
1245
|
-
|
|
1246
1084
|
if (allDone) {
|
|
1247
1085
|
if (!self.generatingGIF) {
|
|
1248
1086
|
self.generateGIF(frames, self.onRenderCompleteCallback);
|
|
@@ -1262,7 +1100,6 @@ AnimatedGIF.prototype = {
|
|
|
1262
1100
|
const frames = this.frames;
|
|
1263
1101
|
let frame = void 0;
|
|
1264
1102
|
let worker = void 0;
|
|
1265
|
-
|
|
1266
1103
|
const done = function done() {
|
|
1267
1104
|
const ev = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1268
1105
|
const data = ev.data;
|
|
@@ -1274,19 +1111,15 @@ AnimatedGIF.prototype = {
|
|
|
1274
1111
|
AnimatedGifContext.freeWorker(worker);
|
|
1275
1112
|
AnimatedGifContext.onFrameFinished(progressCallback);
|
|
1276
1113
|
};
|
|
1277
|
-
|
|
1278
1114
|
frame = frames[position];
|
|
1279
|
-
|
|
1280
1115
|
if (frame.beingProcessed || frame.done) {
|
|
1281
1116
|
this.onFrameFinished();
|
|
1282
1117
|
return;
|
|
1283
1118
|
}
|
|
1284
|
-
|
|
1285
1119
|
frame.sampleInterval = sampleInterval;
|
|
1286
1120
|
frame.beingProcessed = true;
|
|
1287
1121
|
frame.gifshot = true;
|
|
1288
1122
|
worker = this.getWorker();
|
|
1289
|
-
|
|
1290
1123
|
if (worker) {
|
|
1291
1124
|
worker.onmessage = done;
|
|
1292
1125
|
worker.postMessage(frame);
|
|
@@ -1298,23 +1131,19 @@ AnimatedGIF.prototype = {
|
|
|
1298
1131
|
},
|
|
1299
1132
|
startRendering: function startRendering(completeCallback) {
|
|
1300
1133
|
this.onRenderCompleteCallback = completeCallback;
|
|
1301
|
-
|
|
1302
1134
|
for (let i = 0; i < this.options.numWorkers && i < this.frames.length; i++) {
|
|
1303
1135
|
this.processFrame(i);
|
|
1304
1136
|
}
|
|
1305
1137
|
},
|
|
1306
1138
|
processNextFrame: function processNextFrame() {
|
|
1307
1139
|
let position = -1;
|
|
1308
|
-
|
|
1309
1140
|
for (let i = 0; i < this.frames.length; i++) {
|
|
1310
1141
|
const frame = this.frames[i];
|
|
1311
|
-
|
|
1312
1142
|
if (!frame.done && !frame.beingProcessed) {
|
|
1313
1143
|
position = i;
|
|
1314
1144
|
break;
|
|
1315
1145
|
}
|
|
1316
1146
|
}
|
|
1317
|
-
|
|
1318
1147
|
if (position >= 0) {
|
|
1319
1148
|
this.processFrame(position);
|
|
1320
1149
|
}
|
|
@@ -1340,7 +1169,6 @@ AnimatedGIF.prototype = {
|
|
|
1340
1169
|
utils.each(frames, function (iterator, frame) {
|
|
1341
1170
|
const framePalette = frame.palette;
|
|
1342
1171
|
onRenderProgressCallback(0.75 + 0.25 * frame.position * 1.0 / frames.length);
|
|
1343
|
-
|
|
1344
1172
|
for (let i = 0; i < frameDuration; i++) {
|
|
1345
1173
|
gifWriter$$1.addFrame(0, 0, width, height, frame.pixels, {
|
|
1346
1174
|
palette: framePalette,
|
|
@@ -1352,7 +1180,6 @@ AnimatedGIF.prototype = {
|
|
|
1352
1180
|
onRenderProgressCallback(1.0);
|
|
1353
1181
|
this.frames = [];
|
|
1354
1182
|
this.generatingGIF = false;
|
|
1355
|
-
|
|
1356
1183
|
if (utils.isFunction(callback)) {
|
|
1357
1184
|
bufferToString = this.bufferToString(buffer);
|
|
1358
1185
|
gif = "data:image/gif;base64,".concat(utils.btoa(bufferToString));
|
|
@@ -1384,11 +1211,9 @@ AnimatedGIF.prototype = {
|
|
|
1384
1211
|
const textYCoordinate = gifshotOptions.textYCoordinate ? gifshotOptions.textYCoordinate : textBaseline === 'top' ? 1 : textBaseline === 'center' ? height / 2 : height;
|
|
1385
1212
|
const font = "".concat(fontWeight, " ").concat(fontSize, " ").concat(fontFamily);
|
|
1386
1213
|
let imageData = void 0;
|
|
1387
|
-
|
|
1388
1214
|
try {
|
|
1389
1215
|
ctx.filter = filter;
|
|
1390
1216
|
ctx.drawImage(element, 0, 0, width, height);
|
|
1391
|
-
|
|
1392
1217
|
if (text) {
|
|
1393
1218
|
ctx.font = font;
|
|
1394
1219
|
ctx.fillStyle = fontColor;
|
|
@@ -1396,7 +1221,6 @@ AnimatedGIF.prototype = {
|
|
|
1396
1221
|
ctx.textBaseline = textBaseline;
|
|
1397
1222
|
ctx.fillText(text, textXCoordinate, textYCoordinate);
|
|
1398
1223
|
}
|
|
1399
|
-
|
|
1400
1224
|
imageData = ctx.getImageData(0, 0, width, height);
|
|
1401
1225
|
self.addFrameImageData(imageData);
|
|
1402
1226
|
} catch (e) {
|
|
@@ -1426,21 +1250,18 @@ AnimatedGIF.prototype = {
|
|
|
1426
1250
|
},
|
|
1427
1251
|
getBase64GIF: function getBase64GIF(completeCallback) {
|
|
1428
1252
|
const self = this;
|
|
1429
|
-
|
|
1430
1253
|
const onRenderComplete = function onRenderComplete(gif) {
|
|
1431
1254
|
self.destroyWorkers();
|
|
1432
1255
|
utils.requestTimeout(function () {
|
|
1433
1256
|
completeCallback(gif);
|
|
1434
1257
|
}, 0);
|
|
1435
1258
|
};
|
|
1436
|
-
|
|
1437
1259
|
self.startRendering(onRenderComplete);
|
|
1438
1260
|
},
|
|
1439
1261
|
destroyWorkers: function destroyWorkers() {
|
|
1440
1262
|
if (this.workerError) {
|
|
1441
1263
|
return;
|
|
1442
1264
|
}
|
|
1443
|
-
|
|
1444
1265
|
const workers = this.workers;
|
|
1445
1266
|
utils.each(workers, function (iterator, workerObj) {
|
|
1446
1267
|
const worker = workerObj.worker;
|
|
@@ -1450,7 +1271,6 @@ AnimatedGIF.prototype = {
|
|
|
1450
1271
|
});
|
|
1451
1272
|
}
|
|
1452
1273
|
};
|
|
1453
|
-
|
|
1454
1274
|
function getBase64GIF(animatedGifInstance, callback) {
|
|
1455
1275
|
animatedGifInstance.getBase64GIF(function (image) {
|
|
1456
1276
|
callback({
|
|
@@ -1461,7 +1281,6 @@ function getBase64GIF(animatedGifInstance, callback) {
|
|
|
1461
1281
|
});
|
|
1462
1282
|
});
|
|
1463
1283
|
}
|
|
1464
|
-
|
|
1465
1284
|
function existingImages() {
|
|
1466
1285
|
const obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1467
1286
|
const self = this;
|
|
@@ -1478,49 +1297,39 @@ function existingImages() {
|
|
|
1478
1297
|
let loadedImagesLength = 0;
|
|
1479
1298
|
let tempImage = void 0;
|
|
1480
1299
|
let ag = void 0;
|
|
1481
|
-
|
|
1482
1300
|
if (errorObj.error) {
|
|
1483
1301
|
return callback(errorObj);
|
|
1484
1302
|
}
|
|
1485
|
-
|
|
1486
1303
|
ag = new AnimatedGIF(options);
|
|
1487
1304
|
utils.each(images, function (index, image) {
|
|
1488
1305
|
const currentImage = image;
|
|
1489
|
-
|
|
1490
1306
|
if (utils.isElement(currentImage)) {
|
|
1491
1307
|
if (options.crossOrigin) {
|
|
1492
1308
|
currentImage.crossOrigin = options.crossOrigin;
|
|
1493
1309
|
}
|
|
1494
|
-
|
|
1495
1310
|
loadedImages[index] = currentImage;
|
|
1496
1311
|
loadedImagesLength += 1;
|
|
1497
|
-
|
|
1498
1312
|
if (loadedImagesLength === imagesLength) {
|
|
1499
1313
|
addLoadedImagesToGif();
|
|
1500
1314
|
}
|
|
1501
1315
|
} else if (utils.isString(currentImage)) {
|
|
1502
1316
|
tempImage = new Image();
|
|
1503
|
-
|
|
1504
1317
|
if (options.crossOrigin) {
|
|
1505
1318
|
tempImage.crossOrigin = options.crossOrigin;
|
|
1506
1319
|
}
|
|
1507
|
-
|
|
1508
1320
|
(function (tempImage) {
|
|
1509
1321
|
if (image.text) {
|
|
1510
1322
|
tempImage.text = image.text;
|
|
1511
1323
|
}
|
|
1512
|
-
|
|
1513
1324
|
tempImage.onerror = function (e) {
|
|
1514
1325
|
let obj = void 0;
|
|
1515
1326
|
--imagesLength;
|
|
1516
|
-
|
|
1517
1327
|
if (imagesLength === 0) {
|
|
1518
1328
|
obj = {};
|
|
1519
1329
|
obj.error = 'None of the requested images was capable of being retrieved';
|
|
1520
1330
|
return callback(obj);
|
|
1521
1331
|
}
|
|
1522
1332
|
};
|
|
1523
|
-
|
|
1524
1333
|
tempImage.onload = function (e) {
|
|
1525
1334
|
if (image.text) {
|
|
1526
1335
|
loadedImages[index] = {
|
|
@@ -1530,19 +1339,14 @@ function existingImages() {
|
|
|
1530
1339
|
} else {
|
|
1531
1340
|
loadedImages[index] = tempImage;
|
|
1532
1341
|
}
|
|
1533
|
-
|
|
1534
1342
|
loadedImagesLength += 1;
|
|
1535
|
-
|
|
1536
1343
|
if (loadedImagesLength === imagesLength) {
|
|
1537
1344
|
addLoadedImagesToGif();
|
|
1538
1345
|
}
|
|
1539
|
-
|
|
1540
1346
|
utils.removeElement(tempImage);
|
|
1541
1347
|
};
|
|
1542
|
-
|
|
1543
1348
|
tempImage.src = currentImage;
|
|
1544
1349
|
})(tempImage);
|
|
1545
|
-
|
|
1546
1350
|
utils.setCSSAttr(tempImage, {
|
|
1547
1351
|
position: 'fixed',
|
|
1548
1352
|
opacity: '0'
|
|
@@ -1550,7 +1354,6 @@ function existingImages() {
|
|
|
1550
1354
|
document.body.appendChild(tempImage);
|
|
1551
1355
|
}
|
|
1552
1356
|
});
|
|
1553
|
-
|
|
1554
1357
|
function addLoadedImagesToGif() {
|
|
1555
1358
|
utils.each(loadedImages, function (index, loadedImage) {
|
|
1556
1359
|
if (loadedImage) {
|
|
@@ -1564,9 +1367,7 @@ function existingImages() {
|
|
|
1564
1367
|
getBase64GIF(ag, callback);
|
|
1565
1368
|
}
|
|
1566
1369
|
}
|
|
1567
|
-
|
|
1568
1370
|
const noop$3 = function noop() {};
|
|
1569
|
-
|
|
1570
1371
|
const screenShot = {
|
|
1571
1372
|
getGIF: function getGIF() {
|
|
1572
1373
|
const options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -1611,35 +1412,28 @@ const screenShot = {
|
|
|
1611
1412
|
let sourceWidth = crop ? videoWidth - crop.scaledWidth : 0;
|
|
1612
1413
|
let sourceY = crop ? Math.floor(crop.scaledHeight / 2) : 0;
|
|
1613
1414
|
let sourceHeight = crop ? videoHeight - crop.scaledHeight : 0;
|
|
1614
|
-
|
|
1615
1415
|
const captureFrames = function captureSingleFrame() {
|
|
1616
1416
|
const framesLeft = pendingFrames - 1;
|
|
1617
|
-
|
|
1618
1417
|
if (savedRenderingContexts.length) {
|
|
1619
1418
|
context.putImageData(savedRenderingContexts[numFrames - pendingFrames], 0, 0);
|
|
1620
1419
|
finishCapture();
|
|
1621
1420
|
} else {
|
|
1622
1421
|
drawVideo();
|
|
1623
1422
|
}
|
|
1624
|
-
|
|
1625
1423
|
function drawVideo() {
|
|
1626
1424
|
try {
|
|
1627
1425
|
if (sourceWidth > videoWidth) {
|
|
1628
1426
|
sourceWidth = videoWidth;
|
|
1629
1427
|
}
|
|
1630
|
-
|
|
1631
1428
|
if (sourceHeight > videoHeight) {
|
|
1632
1429
|
sourceHeight = videoHeight;
|
|
1633
1430
|
}
|
|
1634
|
-
|
|
1635
1431
|
if (sourceX < 0) {
|
|
1636
1432
|
sourceX = 0;
|
|
1637
1433
|
}
|
|
1638
|
-
|
|
1639
1434
|
if (sourceY < 0) {
|
|
1640
1435
|
sourceY = 0;
|
|
1641
1436
|
}
|
|
1642
|
-
|
|
1643
1437
|
context.filter = filter;
|
|
1644
1438
|
context.drawImage(videoElement, sourceX, sourceY, sourceWidth, sourceHeight, 0, 0, gifWidth, gifHeight);
|
|
1645
1439
|
finishCapture();
|
|
@@ -1651,14 +1445,11 @@ const screenShot = {
|
|
|
1651
1445
|
}
|
|
1652
1446
|
}
|
|
1653
1447
|
}
|
|
1654
|
-
|
|
1655
1448
|
function finishCapture() {
|
|
1656
1449
|
let imageData = void 0;
|
|
1657
|
-
|
|
1658
1450
|
if (saveRenderingContexts) {
|
|
1659
1451
|
renderingContextsToSave.push(context.getImageData(0, 0, gifWidth, gifHeight));
|
|
1660
1452
|
}
|
|
1661
|
-
|
|
1662
1453
|
if (text) {
|
|
1663
1454
|
context.font = font;
|
|
1664
1455
|
context.fillStyle = fontColor;
|
|
@@ -1666,16 +1457,13 @@ const screenShot = {
|
|
|
1666
1457
|
context.textBaseline = textBaseline;
|
|
1667
1458
|
context.fillText(text, textXCoordinate, textYCoordinate);
|
|
1668
1459
|
}
|
|
1669
|
-
|
|
1670
1460
|
imageData = context.getImageData(0, 0, gifWidth, gifHeight);
|
|
1671
1461
|
ag.addFrameImageData(imageData);
|
|
1672
1462
|
pendingFrames = framesLeft;
|
|
1673
1463
|
progressCallback((numFrames - pendingFrames) / numFrames);
|
|
1674
|
-
|
|
1675
1464
|
if (framesLeft > 0) {
|
|
1676
1465
|
utils.requestTimeout(captureSingleFrame, waitBetweenFrames);
|
|
1677
1466
|
}
|
|
1678
|
-
|
|
1679
1467
|
if (!pendingFrames) {
|
|
1680
1468
|
ag.getBase64GIF(function (image) {
|
|
1681
1469
|
callback({
|
|
@@ -1693,19 +1481,16 @@ const screenShot = {
|
|
|
1693
1481
|
}
|
|
1694
1482
|
}
|
|
1695
1483
|
};
|
|
1696
|
-
|
|
1697
1484
|
numFrames = numFrames !== undefined ? numFrames : 10;
|
|
1698
1485
|
interval = interval !== undefined ? interval : 0.1;
|
|
1699
1486
|
canvas.width = gifWidth;
|
|
1700
1487
|
canvas.height = gifHeight;
|
|
1701
1488
|
context = canvas.getContext('2d');
|
|
1702
|
-
|
|
1703
1489
|
(function capture() {
|
|
1704
1490
|
if (!savedRenderingContexts.length && videoElement.currentTime === 0) {
|
|
1705
1491
|
utils.requestTimeout(capture, 100);
|
|
1706
1492
|
return;
|
|
1707
1493
|
}
|
|
1708
|
-
|
|
1709
1494
|
captureFrames();
|
|
1710
1495
|
})();
|
|
1711
1496
|
},
|
|
@@ -1721,7 +1506,6 @@ const screenShot = {
|
|
|
1721
1506
|
scaledWidth: 0,
|
|
1722
1507
|
scaledHeight: 0
|
|
1723
1508
|
};
|
|
1724
|
-
|
|
1725
1509
|
if (width > height) {
|
|
1726
1510
|
result.width = Math.round(width * (gifHeight / height)) - gifWidth;
|
|
1727
1511
|
result.scaledWidth = Math.round(result.width * (height / gifHeight));
|
|
@@ -1729,7 +1513,6 @@ const screenShot = {
|
|
|
1729
1513
|
result.height = Math.round(height * (gifWidth / width)) - gifHeight;
|
|
1730
1514
|
result.scaledHeight = Math.round(result.height * (width / gifWidth));
|
|
1731
1515
|
}
|
|
1732
|
-
|
|
1733
1516
|
return result;
|
|
1734
1517
|
}
|
|
1735
1518
|
};
|
|
@@ -1744,11 +1527,9 @@ var videoStream = {
|
|
|
1744
1527
|
const cameraStream = obj.cameraStream;
|
|
1745
1528
|
const completedCallback = obj.completedCallback;
|
|
1746
1529
|
const videoElement = obj.videoElement;
|
|
1747
|
-
|
|
1748
1530
|
if (!videoElement) {
|
|
1749
1531
|
return;
|
|
1750
1532
|
}
|
|
1751
|
-
|
|
1752
1533
|
if (videoElement.videoWidth > 0 && videoElement.videoHeight > 0) {
|
|
1753
1534
|
videoElement.removeEventListener('loadeddata', videoStream.findVideoSize);
|
|
1754
1535
|
completedCallback({
|
|
@@ -1788,11 +1569,9 @@ var videoStream = {
|
|
|
1788
1569
|
const completedCallback = obj.completedCallback;
|
|
1789
1570
|
const streamedCallback = obj.streamedCallback;
|
|
1790
1571
|
const videoElement = obj.videoElement;
|
|
1791
|
-
|
|
1792
1572
|
if (utils.isFunction(streamedCallback)) {
|
|
1793
1573
|
streamedCallback();
|
|
1794
1574
|
}
|
|
1795
|
-
|
|
1796
1575
|
if (existingVideo) {
|
|
1797
1576
|
if (utils.isString(existingVideo)) {
|
|
1798
1577
|
videoElement.src = existingVideo;
|
|
@@ -1801,7 +1580,6 @@ var videoStream = {
|
|
|
1801
1580
|
try {
|
|
1802
1581
|
videoElement.src = utils.URL.createObjectURL(existingVideo);
|
|
1803
1582
|
} catch (e) {}
|
|
1804
|
-
|
|
1805
1583
|
videoElement.innerHTML = "<source src=\"".concat(existingVideo, "\" type=\"").concat(existingVideo.type, "\" />");
|
|
1806
1584
|
}
|
|
1807
1585
|
} else if (videoElement.mozSrcObject) {
|
|
@@ -1814,11 +1592,9 @@ var videoStream = {
|
|
|
1814
1592
|
videoElement.srcObject = cameraStream;
|
|
1815
1593
|
}
|
|
1816
1594
|
}
|
|
1817
|
-
|
|
1818
1595
|
videoElement.play();
|
|
1819
1596
|
utils.requestTimeout(function checkLoadedData() {
|
|
1820
1597
|
checkLoadedData.count = checkLoadedData.count || 0;
|
|
1821
|
-
|
|
1822
1598
|
if (videoStream.loadedData === true) {
|
|
1823
1599
|
videoStream.findVideoSize({
|
|
1824
1600
|
videoElement,
|
|
@@ -1828,7 +1604,6 @@ var videoStream = {
|
|
|
1828
1604
|
videoStream.loadedData = false;
|
|
1829
1605
|
} else {
|
|
1830
1606
|
checkLoadedData.count += 1;
|
|
1831
|
-
|
|
1832
1607
|
if (checkLoadedData.count > 10) {
|
|
1833
1608
|
videoStream.findVideoSize({
|
|
1834
1609
|
videoElement,
|
|
@@ -1852,22 +1627,18 @@ var videoStream = {
|
|
|
1852
1627
|
const webcamVideoElement = obj.webcamVideoElement;
|
|
1853
1628
|
const videoElement = utils.isElement(existingVideo) ? existingVideo : webcamVideoElement ? webcamVideoElement : document.createElement('video');
|
|
1854
1629
|
const cameraStream = void 0;
|
|
1855
|
-
|
|
1856
1630
|
if (crossOrigin) {
|
|
1857
1631
|
videoElement.crossOrigin = options.crossOrigin;
|
|
1858
1632
|
}
|
|
1859
|
-
|
|
1860
1633
|
videoElement.autoplay = true;
|
|
1861
1634
|
videoElement.loop = true;
|
|
1862
1635
|
videoElement.muted = true;
|
|
1863
1636
|
videoElement.addEventListener('loadeddata', function (event) {
|
|
1864
1637
|
videoStream.loadedData = true;
|
|
1865
|
-
|
|
1866
1638
|
if (options.offset) {
|
|
1867
1639
|
videoElement.currentTime = options.offset;
|
|
1868
1640
|
}
|
|
1869
1641
|
});
|
|
1870
|
-
|
|
1871
1642
|
if (existingVideo) {
|
|
1872
1643
|
videoStream.stream({
|
|
1873
1644
|
videoElement,
|
|
@@ -1900,13 +1671,11 @@ var videoStream = {
|
|
|
1900
1671
|
const originalCallback = options.callback;
|
|
1901
1672
|
const webcamVideoElement = options.webcamVideoElement;
|
|
1902
1673
|
let noGetUserMediaSupportTimeout = void 0;
|
|
1903
|
-
|
|
1904
1674
|
if (timeoutLength > 0) {
|
|
1905
1675
|
noGetUserMediaSupportTimeout = utils.requestTimeout(function () {
|
|
1906
1676
|
videoStream.onStreamingTimeout(originalCallback);
|
|
1907
1677
|
}, 10000);
|
|
1908
1678
|
}
|
|
1909
|
-
|
|
1910
1679
|
videoStream.startStreaming({
|
|
1911
1680
|
error: function error() {
|
|
1912
1681
|
originalCallback({
|
|
@@ -1949,32 +1718,26 @@ var videoStream = {
|
|
|
1949
1718
|
const cameraStreamTracks = cameraStream.getTracks ? cameraStream.getTracks() || [] : [];
|
|
1950
1719
|
const hasCameraStreamTracks = Boolean(cameraStreamTracks.length);
|
|
1951
1720
|
const firstCameraStreamTrack = cameraStreamTracks[0];
|
|
1952
|
-
|
|
1953
1721
|
if (!keepCameraOn && hasCameraStreamTracks) {
|
|
1954
1722
|
if (utils.isFunction(firstCameraStreamTrack.stop)) {
|
|
1955
1723
|
firstCameraStreamTrack.stop();
|
|
1956
1724
|
}
|
|
1957
1725
|
}
|
|
1958
|
-
|
|
1959
1726
|
if (utils.isElement(videoElement) && !webcamVideoElement) {
|
|
1960
1727
|
videoElement.pause();
|
|
1961
|
-
|
|
1962
1728
|
if (utils.isFunction(utils.URL.revokeObjectURL) && !utils.webWorkerError) {
|
|
1963
1729
|
if (videoElement.src) {
|
|
1964
1730
|
utils.URL.revokeObjectURL(videoElement.src);
|
|
1965
1731
|
}
|
|
1966
1732
|
}
|
|
1967
|
-
|
|
1968
1733
|
utils.removeElement(videoElement);
|
|
1969
1734
|
}
|
|
1970
1735
|
}
|
|
1971
1736
|
};
|
|
1972
|
-
|
|
1973
1737
|
function stopVideoStreaming(options) {
|
|
1974
1738
|
options = utils.isObject(options) ? options : {};
|
|
1975
1739
|
videoStream.stopVideoStreaming(options);
|
|
1976
1740
|
}
|
|
1977
|
-
|
|
1978
1741
|
function createAndGetGIF(obj, callback) {
|
|
1979
1742
|
const options = obj.options || {};
|
|
1980
1743
|
const images = options.images;
|
|
@@ -1998,14 +1761,11 @@ function createAndGetGIF(obj, callback) {
|
|
|
1998
1761
|
options.videoWidth = videoWidth;
|
|
1999
1762
|
options.videoHeight = videoHeight;
|
|
2000
1763
|
options.cameraStream = cameraStream;
|
|
2001
|
-
|
|
2002
1764
|
if (!utils.isElement(videoElement)) {
|
|
2003
1765
|
return;
|
|
2004
1766
|
}
|
|
2005
|
-
|
|
2006
1767
|
videoElement.width = gifWidth + cropDimensions.width;
|
|
2007
1768
|
videoElement.height = gifHeight + cropDimensions.height;
|
|
2008
|
-
|
|
2009
1769
|
if (!options.webcamVideoElement) {
|
|
2010
1770
|
utils.setCSSAttr(videoElement, {
|
|
2011
1771
|
position: 'fixed',
|
|
@@ -2013,17 +1773,14 @@ function createAndGetGIF(obj, callback) {
|
|
|
2013
1773
|
});
|
|
2014
1774
|
document.body.appendChild(videoElement);
|
|
2015
1775
|
}
|
|
2016
|
-
|
|
2017
1776
|
videoElement.play();
|
|
2018
1777
|
screenShot.getGIF(options, function (obj) {
|
|
2019
1778
|
if ((!images || !images.length) && (!video || !video.length)) {
|
|
2020
1779
|
stopVideoStreaming(obj);
|
|
2021
1780
|
}
|
|
2022
|
-
|
|
2023
1781
|
completeCallback(obj);
|
|
2024
1782
|
});
|
|
2025
1783
|
}
|
|
2026
|
-
|
|
2027
1784
|
function existingVideo() {
|
|
2028
1785
|
const obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2029
1786
|
const callback = obj.callback;
|
|
@@ -2039,15 +1796,12 @@ function existingVideo() {
|
|
|
2039
1796
|
let videoSrc = void 0;
|
|
2040
1797
|
const tempImage = void 0;
|
|
2041
1798
|
const ag = void 0;
|
|
2042
|
-
|
|
2043
1799
|
if (errorObj.error) {
|
|
2044
1800
|
return callback(errorObj);
|
|
2045
1801
|
}
|
|
2046
|
-
|
|
2047
1802
|
if (utils.isElement(existingVideo) && existingVideo.src) {
|
|
2048
1803
|
videoSrc = existingVideo.src;
|
|
2049
1804
|
videoType = utils.getExtension(videoSrc);
|
|
2050
|
-
|
|
2051
1805
|
if (!utils.isSupported.videoCodecs[videoType]) {
|
|
2052
1806
|
return callback(error.messages.videoCodecs);
|
|
2053
1807
|
}
|
|
@@ -2058,14 +1812,12 @@ function existingVideo() {
|
|
|
2058
1812
|
} else {
|
|
2059
1813
|
videoType = videoSrc.substr(videoSrc.lastIndexOf('.') + 1, videoSrc.length);
|
|
2060
1814
|
}
|
|
2061
|
-
|
|
2062
1815
|
if (utils.isSupported.videoCodecs[videoType]) {
|
|
2063
1816
|
existingVideo = videoSrc;
|
|
2064
1817
|
return false;
|
|
2065
1818
|
}
|
|
2066
1819
|
});
|
|
2067
1820
|
}
|
|
2068
|
-
|
|
2069
1821
|
videoStream.startStreaming({
|
|
2070
1822
|
completed: function completed(obj) {
|
|
2071
1823
|
obj.options = options || {};
|
|
@@ -2076,25 +1828,21 @@ function existingVideo() {
|
|
|
2076
1828
|
options
|
|
2077
1829
|
});
|
|
2078
1830
|
}
|
|
2079
|
-
|
|
2080
1831
|
function existingWebcam() {
|
|
2081
1832
|
const obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2082
1833
|
const callback = obj.callback;
|
|
2083
1834
|
const lastCameraStream = obj.lastCameraStream;
|
|
2084
1835
|
const options = obj.options;
|
|
2085
1836
|
const webcamVideoElement = obj.webcamVideoElement;
|
|
2086
|
-
|
|
2087
1837
|
if (!isWebCamGIFSupported()) {
|
|
2088
1838
|
return callback(error.validate());
|
|
2089
1839
|
}
|
|
2090
|
-
|
|
2091
1840
|
if (options.savedRenderingContexts.length) {
|
|
2092
1841
|
screenShot.getGIF(options, function (obj) {
|
|
2093
1842
|
callback(obj);
|
|
2094
1843
|
});
|
|
2095
1844
|
return;
|
|
2096
1845
|
}
|
|
2097
|
-
|
|
2098
1846
|
videoStream.startVideoStreaming(function () {
|
|
2099
1847
|
const obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2100
1848
|
obj.options = options || {};
|
|
@@ -2106,15 +1854,12 @@ function existingWebcam() {
|
|
|
2106
1854
|
crossOrigin: options.crossOrigin
|
|
2107
1855
|
});
|
|
2108
1856
|
}
|
|
2109
|
-
|
|
2110
1857
|
function createGIF(userOptions, callback) {
|
|
2111
1858
|
callback = utils.isFunction(userOptions) ? userOptions : callback;
|
|
2112
1859
|
userOptions = utils.isObject(userOptions) ? userOptions : {};
|
|
2113
|
-
|
|
2114
1860
|
if (!utils.isFunction(callback)) {
|
|
2115
1861
|
return;
|
|
2116
1862
|
}
|
|
2117
|
-
|
|
2118
1863
|
let options = utils.normalizeOptions(defaultOptions, userOptions) || {};
|
|
2119
1864
|
const lastCameraStream = userOptions.cameraStream;
|
|
2120
1865
|
const images = options.images;
|
|
@@ -2125,7 +1870,6 @@ function createGIF(userOptions, callback) {
|
|
|
2125
1870
|
gifWidth: Math.floor(options.gifWidth),
|
|
2126
1871
|
gifHeight: Math.floor(options.gifHeight)
|
|
2127
1872
|
});
|
|
2128
|
-
|
|
2129
1873
|
if (imagesLength) {
|
|
2130
1874
|
existingImages({
|
|
2131
1875
|
images,
|
|
@@ -2148,15 +1892,12 @@ function createGIF(userOptions, callback) {
|
|
|
2148
1892
|
});
|
|
2149
1893
|
}
|
|
2150
1894
|
}
|
|
2151
|
-
|
|
2152
1895
|
function takeSnapShot(userOptions, callback) {
|
|
2153
1896
|
callback = utils.isFunction(userOptions) ? userOptions : callback;
|
|
2154
1897
|
userOptions = utils.isObject(userOptions) ? userOptions : {};
|
|
2155
|
-
|
|
2156
1898
|
if (!utils.isFunction(callback)) {
|
|
2157
1899
|
return;
|
|
2158
1900
|
}
|
|
2159
|
-
|
|
2160
1901
|
const mergedOptions = utils.normalizeOptions(defaultOptions, userOptions);
|
|
2161
1902
|
const options = utils.normalizeOptions(mergedOptions, {
|
|
2162
1903
|
interval: 0.1,
|
|
@@ -2166,7 +1907,6 @@ function takeSnapShot(userOptions, callback) {
|
|
|
2166
1907
|
});
|
|
2167
1908
|
createGIF(options, callback);
|
|
2168
1909
|
}
|
|
2169
|
-
|
|
2170
1910
|
const API = {
|
|
2171
1911
|
utils: utils$2,
|
|
2172
1912
|
error: error$2,
|