Comments for GIF.

This commit is contained in:
n1073645 2019-11-07 16:50:10 +00:00
parent f022440b4a
commit 447a6d7524

View File

@ -2449,11 +2449,21 @@ export function extractJPEG(bytes, offset) {
*/ */
export function extractGIF(bytes, offset) { export function extractGIF(bytes, offset) {
const stream = new Stream(bytes.slice(offset)); const stream = new Stream(bytes.slice(offset));
//Move to application extension block.
stream.continueUntil([0x21, 0xff]); stream.continueUntil([0x21, 0xff]);
//Move to Graphic Control Extension for frame #1.
stream.continueUntil([0x21, 0xf9]); stream.continueUntil([0x21, 0xf9]);
while (stream.hasMore()) { while (stream.hasMore()) {
//Move to Image descriptor.
stream.continueUntil(0x2c); stream.continueUntil(0x2c);
//Move past Image descriptor to the image data.
stream.moveForwardsBy(11); stream.moveForwardsBy(11);
//Loop until next Graphic Control Extension.
while (stream.getBytes(2) !== [0x21, 0xf9]) { while (stream.getBytes(2) !== [0x21, 0xf9]) {
stream.moveBackwardsBy(2); stream.moveBackwardsBy(2);
stream.moveForwardsBy(stream.getBytes(1)[0]); stream.moveForwardsBy(stream.getBytes(1)[0]);
@ -2461,6 +2471,7 @@ export function extractGIF(bytes, offset) {
break; break;
stream.moveBackwardsBy(1); stream.moveBackwardsBy(1);
} }
//When the end of the file is [0x00, 0x3b], end.
if (stream.getBytes(1)[0] === 0x3b) if (stream.getBytes(1)[0] === 0x3b)
break; break;
stream.moveBackwardsBy(1); stream.moveBackwardsBy(1);