@lijuhong1981/jsgif 1.0.3 → 1.0.5
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/index.js +49 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -134,7 +134,8 @@ function GifPlayer(options = {}) {
|
|
|
134
134
|
const CANVAS_CTX = CANVAS.getContext('2d');
|
|
135
135
|
const TEMP_CANVAS = document.createElement("canvas");//用来拿 imageData 的工具人
|
|
136
136
|
const TEMP_CANVAS_CTX = TEMP_CANVAS.getContext('2d', { willReadFrequently: true, }); // 工具人的 getContext('2d')
|
|
137
|
-
const
|
|
137
|
+
const ATLAS_CANVAS = document.createElement("canvas");
|
|
138
|
+
const FRAME_LIST = []; // 存放每一帧数据以及对应的延时
|
|
138
139
|
let GIF_INFO = {}; // GIF 的一些信息
|
|
139
140
|
let STREAM = null;
|
|
140
141
|
let LAST_DISPOSA_METHOD = null;
|
|
@@ -429,6 +430,21 @@ function GifPlayer(options = {}) {
|
|
|
429
430
|
}
|
|
430
431
|
};
|
|
431
432
|
|
|
433
|
+
function drawAtlasImage() {
|
|
434
|
+
const length = FRAME_LIST.length;
|
|
435
|
+
if (length > 0) {
|
|
436
|
+
ATLAS_CANVAS.width = CANVAS.width * length;
|
|
437
|
+
ATLAS_CANVAS.height = CANVAS.height;
|
|
438
|
+
const context = ATLAS_CANVAS.getContext('2d');
|
|
439
|
+
let dx = 0;
|
|
440
|
+
for (let i = 0; i < length; i++) {
|
|
441
|
+
const frame = FRAME_LIST[i];
|
|
442
|
+
context.putImageData(frame.imgData, dx, 0);
|
|
443
|
+
dx += CANVAS.width;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
432
448
|
function getNextFrameIndex() {
|
|
433
449
|
if (currentFrameIndex === -1)
|
|
434
450
|
return options.reverse ? FRAME_LIST.length - 1 : 0;
|
|
@@ -445,6 +461,9 @@ function GifPlayer(options = {}) {
|
|
|
445
461
|
function doCurrentFrame() {
|
|
446
462
|
const frame = FRAME_LIST[currentFrameIndex];
|
|
447
463
|
drawFrame(frame);
|
|
464
|
+
if (typeof options.onFrameChanged === 'function') {
|
|
465
|
+
options.onFrameChanged(currentFrameIndex, frame);
|
|
466
|
+
}
|
|
448
467
|
setTimeout(function () {
|
|
449
468
|
if (!isPlaying)
|
|
450
469
|
return;
|
|
@@ -490,6 +509,7 @@ function GifPlayer(options = {}) {
|
|
|
490
509
|
reset();
|
|
491
510
|
parseHeader();
|
|
492
511
|
parseBlock();
|
|
512
|
+
drawAtlasImage();
|
|
493
513
|
stopGif();
|
|
494
514
|
if (options.autoPlay)
|
|
495
515
|
playGif();
|
|
@@ -532,6 +552,21 @@ function GifPlayer(options = {}) {
|
|
|
532
552
|
return CANVAS;
|
|
533
553
|
},
|
|
534
554
|
},
|
|
555
|
+
atlasCanvas: {
|
|
556
|
+
get: function () {
|
|
557
|
+
return ATLAS_CANVAS;
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
frameWidth: {
|
|
561
|
+
get: function () {
|
|
562
|
+
return CANVAS.width;
|
|
563
|
+
}
|
|
564
|
+
},
|
|
565
|
+
frameHeight: {
|
|
566
|
+
get: function () {
|
|
567
|
+
return CANVAS.height;
|
|
568
|
+
}
|
|
569
|
+
},
|
|
535
570
|
framesNumber: {
|
|
536
571
|
get: function () {
|
|
537
572
|
return FRAME_LIST.length;
|
|
@@ -547,6 +582,11 @@ function GifPlayer(options = {}) {
|
|
|
547
582
|
return currentFrameIndex;
|
|
548
583
|
}
|
|
549
584
|
},
|
|
585
|
+
frameList: {
|
|
586
|
+
get: function () {
|
|
587
|
+
return FRAME_LIST;
|
|
588
|
+
}
|
|
589
|
+
},
|
|
550
590
|
reverse: {
|
|
551
591
|
set: function (value) {
|
|
552
592
|
Check.typeOf.bool('reverse', value);
|
|
@@ -565,6 +605,14 @@ function GifPlayer(options = {}) {
|
|
|
565
605
|
return options.timeScale;
|
|
566
606
|
}
|
|
567
607
|
},
|
|
608
|
+
onFrameChanged: {
|
|
609
|
+
set: function (value) {
|
|
610
|
+
options.onFrameChanged = value;
|
|
611
|
+
},
|
|
612
|
+
get: function () {
|
|
613
|
+
return options.onFrameChanged;
|
|
614
|
+
}
|
|
615
|
+
},
|
|
568
616
|
});
|
|
569
617
|
|
|
570
618
|
return player;
|