Nicer interlaced GIF handling

This commit is contained in:
Jarrod Doyle 2024-09-06 19:31:25 +01:00
parent a9a16f88e9
commit fbec9db3f6
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 12 additions and 29 deletions

View File

@ -278,45 +278,28 @@ public class GifDecoder
return bytes;
}
var pass1Count = (int)Math.Ceiling(Height / 8.0f);
var pass2Count = (int)Math.Ceiling((Height - 4) / 8.0f);
var pass3Count = (int)Math.Ceiling((Height - 2) / 4.0f);
var pass4Count = (int)Math.Ceiling((Height - 1) / 2.0f);
var pass = 0;
var inc = 8;
var y = 0;
var indicesOffset = 0;
var bytesPerRow = Width * 4;
for (var i = 0; i < pass1Count; i++)
for (var i = 0; i < Height; i++)
{
bytesIdx = 8 * i * bytesPerRow;
bytesIdx = y * bytesPerRow;
for (var x = 0; x < Width; x++)
{
WritePixelBytes(bytesIdx + x * 4, _pixelIndices[indicesOffset++]);
}
}
for (var i = 0; i < pass2Count; i++)
{
bytesIdx = (4 + 8 * i) * bytesPerRow;
for (var x = 0; x < Width; x++)
y += inc;
if (y >= Height)
{
WritePixelBytes(bytesIdx + x * 4, _pixelIndices[indicesOffset++]);
}
}
for (var i = 0; i < pass3Count; i++)
{
bytesIdx = (2 + 4 * i) * bytesPerRow;
for (var x = 0; x < Width; x++)
{
WritePixelBytes(bytesIdx + x * 4, _pixelIndices[indicesOffset++]);
}
}
for (var i = 0; i < pass4Count; i++)
{
bytesIdx = (1 + 2 * i) * bytesPerRow;
for (var x = 0; x < Width; x++)
{
WritePixelBytes(bytesIdx + x * 4, _pixelIndices[indicesOffset++]);
pass += 1;
y = (int)(8 / Math.Pow(2, pass));
inc = y * 2;
}
}
return bytes;
}
}