(bytes, offset)
| 2731 | * @returns {Uint8Array} |
| 2732 | */ |
| 2733 | export function extractGIF(bytes, offset) { |
| 2734 | const stream = new Stream(bytes.slice(offset)); |
| 2735 | |
| 2736 | // Move to application extension block. |
| 2737 | stream.continueUntil([0x21, 0xff]); |
| 2738 | |
| 2739 | // Move to Graphic Control Extension for frame #1. |
| 2740 | stream.continueUntil([0x21, 0xf9]); |
| 2741 | stream.moveForwardsBy(2); |
| 2742 | |
| 2743 | while (stream.hasMore()) { |
| 2744 | // Move to Image descriptor. |
| 2745 | stream.moveForwardsBy(stream.readInt(1) + 1); |
| 2746 | |
| 2747 | // Move past Image descriptor to the image data. |
| 2748 | stream.moveForwardsBy(11); |
| 2749 | |
| 2750 | // Loop until next Graphic Control Extension. |
| 2751 | while (!Array.from(stream.getBytes(2)).equals([0x21, 0xf9])) { |
| 2752 | stream.moveBackwardsBy(2); |
| 2753 | stream.moveForwardsBy(stream.readInt(1)); |
| 2754 | if (!stream.readInt(1)) |
| 2755 | break; |
| 2756 | stream.moveBackwardsBy(1); |
| 2757 | } |
| 2758 | |
| 2759 | // When the end of the file is [0x00, 0x3b], end. |
| 2760 | if (stream.readInt(1) === 0x3b) |
| 2761 | break; |
| 2762 | |
| 2763 | stream.moveForwardsBy(1); |
| 2764 | } |
| 2765 | return stream.carve(); |
| 2766 | } |
| 2767 | |
| 2768 | |
| 2769 | /** |
nothing calls this directly
no test coverage detected