Skip over GIF extension blocks and set transparency to index 0

This commit is contained in:
Jarrod Doyle 2024-09-06 19:47:06 +01:00
parent fbec9db3f6
commit f6e35f5b7a
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 10 additions and 17 deletions

View File

@ -263,9 +263,7 @@ public class GifDecoder
bytes[bytesOffset] = _colors[colorIndex * 3];
bytes[bytesOffset + 1] = _colors[colorIndex * 3 + 1];
bytes[bytesOffset + 2] = _colors[colorIndex * 3 + 2];
// Fuck you LGS hardcoding the transparent index suck my balls
// bytes[bytesOffset++] = (byte)((colorIndex == _transparentIndex) ? 0 : 255);
bytes[bytesOffset + 3] = (byte)((colorIndex == 0) ? 0 : 255);
bytes[bytesOffset + 3] = (byte)((colorIndex == _transparentIndex) ? 0 : 255);
}
if (!_interlaced)
@ -323,7 +321,6 @@ public class GifDecoder
_header = new Header(reader);
_globalColors = ReadColorTable(reader, _header.HasGlobalColorTable ? _header.GlobalColorTableSize : 0);
var images = new List<ImageData>();
var transparentIndex = -1;
while (true)
{
var id = reader.ReadByte();
@ -331,22 +328,18 @@ public class GifDecoder
switch (id)
{
case 0x2C: // Image
// Godot.GD.Print("Adding new image!!");
images.Add(new ImageData(reader, _globalColors, transparentIndex));
transparentIndex = -1;
images.Add(new ImageData(reader, _globalColors, 0));
break;
case 0x21: // Extension
var extId = reader.ReadByte();
if (extId == 0xF9)
// We don't need to actually handle any extensions. The only one that's
// potentially relevant is GraphicsControl, but Dark uses a hardcoded
// transparency palette index and doesn't use multi-frame GIFs with timing.
reader.ReadByte();
var blockSize = reader.ReadByte();
while (blockSize != 0)
{
var graphicsControl = new GraphicsControl(reader);
transparentIndex = graphicsControl.TransparencyIndex;
// Godot.GD.Print($"We set the transparent index: {transparentIndex} for {path}");
}
else
{
// We don't support Comment (0xFE), Text (0x01), or Application (0xFF) extensions
throw new InvalidDataException($"Unknown or unsupported extension identifier in GIF file: {extId}");
reader.ReadBytes(blockSize);
blockSize = reader.ReadByte();
}
break;
case 0x3B: