diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index bb6934479..1d195f597 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -279,20 +279,20 @@ namespace SixLabors.ImageSharp.Formats.Bmp break; default: - // If the second byte > 2, signals 'absolute mode' + // If the second byte > 2, we are in 'absolute mode' // Take this number of bytes from the stream as uncompressed data int length = cmd[1]; - int copyLength = length; + + byte[] run = new byte[length]; + + this.stream.Read(run, 0, length); + + run.AsSpan().CopyTo(buffer); // Absolute mode data is aligned to two-byte word-boundary - length += length & 1; + int padding = length & 0; - byte[] run = new byte[length]; - this.stream.Read(run, 0, run.Length); - for (int i = 0; i < copyLength; i++) - { - buffer[count++] = run[i]; - } + this.stream.Skip(padding); break; } @@ -467,7 +467,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp /// private void ReadInfoHeader() { - byte[] buffer = new byte[BmpInfoHeader.MaxHeaderSize]; // TODO: stackalloc + byte[] buffer = new byte[BmpInfoHeader.MaxHeaderSize]; // read header size this.stream.Read(buffer, 0, BmpInfoHeader.HeaderSizeSize); @@ -512,7 +512,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp /// private void ReadFileHeader() { - byte[] buffer = new byte[BmpFileHeader.Size]; // TODO: stackalloc + byte[] buffer = new byte[BmpFileHeader.Size]; this.stream.Read(buffer, 0, BmpFileHeader.Size);