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; } }