From fbec9db3f6c7bb79afde233d27658bea2bea90a7 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Fri, 6 Sep 2024 19:31:25 +0100 Subject: [PATCH] Nicer interlaced GIF handling --- project/code/Images/GifDecoder.cs | 41 +++++++++---------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/project/code/Images/GifDecoder.cs b/project/code/Images/GifDecoder.cs index e389a55..d462625 100644 --- a/project/code/Images/GifDecoder.cs +++ b/project/code/Images/GifDecoder.cs @@ -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; } }