-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix decoding error with trailing comment extension blocks
The GIF files that can be found on the Internet come in a wide variety of forms. Some strictly adhere to the original specification, others do not and differ in the actual sequence of blocks or their number. For this reason, my decoder has a kind of "virtual" FrameBlock, which can contain all possible blocks in different order that occur in a GIF animation. - Graphic Control Extension - Image Description - Local Color Table - Image Data Block - Plain Text Extension - Application Extension - Comment Extension The TableBasedImage block, which is a chain of ImageDescriptor, (Local Color Table) and ImageData, is used as a feature for terminating a FrameBlock. So far I have only seen GIF files that follow this scheme. However, there was one example where one (or more) comment extensions were added before the end. Here the decoding process failed. This fix also adds "global comments" that are not part of my FrameBlock and are appended to the GifDataStream afterwards.
- Loading branch information
1 parent
1640943
commit cac9182
Showing
5 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
namespace Intervention\Gif; | ||
|
||
use Intervention\Gif\Blocks\ColorTable; | ||
use Intervention\Gif\Blocks\CommentExtension; | ||
use Intervention\Gif\Blocks\FrameBlock; | ||
use Intervention\Gif\Blocks\Header; | ||
use Intervention\Gif\Blocks\LogicalScreenDescriptor; | ||
|
@@ -20,7 +21,8 @@ public function __construct( | |
protected Header $header = new Header(), | ||
protected LogicalScreenDescriptor $logicalScreenDescriptor = new LogicalScreenDescriptor(), | ||
protected ?ColorTable $globalColorTable = null, | ||
protected array $frames = [] | ||
protected array $frames = [], | ||
protected array $comments = [] | ||
) { | ||
} | ||
|
||
|
@@ -122,6 +124,16 @@ public function getFrames(): array | |
return $this->frames; | ||
} | ||
|
||
/** | ||
* Return array of "global" comments | ||
* | ||
* @return array | ||
*/ | ||
public function getComments(): array | ||
{ | ||
return $this->comments; | ||
} | ||
|
||
/** | ||
* Return first frame | ||
* | ||
|
@@ -149,6 +161,19 @@ public function addFrame(FrameBlock $frame): self | |
return $this; | ||
} | ||
|
||
/** | ||
* Add frame | ||
* | ||
* @param FrameBlock $frame | ||
* @return GifDataStream | ||
*/ | ||
public function addComment(CommentExtension $comment): self | ||
Check failure on line 170 in src/GifDataStream.php GitHub Actions / Testing on PHP 8.1
Check failure on line 170 in src/GifDataStream.php GitHub Actions / Testing on PHP 8.2
Check failure on line 170 in src/GifDataStream.php GitHub Actions / Testing on PHP 8.3
|
||
{ | ||
$this->comments[] = $comment; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set the current data | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.