Skip over GIF extension blocks and set transparency to index 0
This commit is contained in:
parent
fbec9db3f6
commit
f6e35f5b7a
|
@ -263,9 +263,7 @@ public class GifDecoder
|
||||||
bytes[bytesOffset] = _colors[colorIndex * 3];
|
bytes[bytesOffset] = _colors[colorIndex * 3];
|
||||||
bytes[bytesOffset + 1] = _colors[colorIndex * 3 + 1];
|
bytes[bytesOffset + 1] = _colors[colorIndex * 3 + 1];
|
||||||
bytes[bytesOffset + 2] = _colors[colorIndex * 3 + 2];
|
bytes[bytesOffset + 2] = _colors[colorIndex * 3 + 2];
|
||||||
// Fuck you LGS hardcoding the transparent index suck my balls
|
bytes[bytesOffset + 3] = (byte)((colorIndex == _transparentIndex) ? 0 : 255);
|
||||||
// bytes[bytesOffset++] = (byte)((colorIndex == _transparentIndex) ? 0 : 255);
|
|
||||||
bytes[bytesOffset + 3] = (byte)((colorIndex == 0) ? 0 : 255);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_interlaced)
|
if (!_interlaced)
|
||||||
|
@ -323,7 +321,6 @@ public class GifDecoder
|
||||||
_header = new Header(reader);
|
_header = new Header(reader);
|
||||||
_globalColors = ReadColorTable(reader, _header.HasGlobalColorTable ? _header.GlobalColorTableSize : 0);
|
_globalColors = ReadColorTable(reader, _header.HasGlobalColorTable ? _header.GlobalColorTableSize : 0);
|
||||||
var images = new List<ImageData>();
|
var images = new List<ImageData>();
|
||||||
var transparentIndex = -1;
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var id = reader.ReadByte();
|
var id = reader.ReadByte();
|
||||||
|
@ -331,22 +328,18 @@ public class GifDecoder
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case 0x2C: // Image
|
case 0x2C: // Image
|
||||||
// Godot.GD.Print("Adding new image!!");
|
images.Add(new ImageData(reader, _globalColors, 0));
|
||||||
images.Add(new ImageData(reader, _globalColors, transparentIndex));
|
|
||||||
transparentIndex = -1;
|
|
||||||
break;
|
break;
|
||||||
case 0x21: // Extension
|
case 0x21: // Extension
|
||||||
var extId = reader.ReadByte();
|
// We don't need to actually handle any extensions. The only one that's
|
||||||
if (extId == 0xF9)
|
// 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);
|
reader.ReadBytes(blockSize);
|
||||||
transparentIndex = graphicsControl.TransparencyIndex;
|
blockSize = reader.ReadByte();
|
||||||
// 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}");
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x3B:
|
case 0x3B:
|
||||||
|
|
Loading…
Reference in New Issue