From e1e60aa0c3b065a37c9ed1cb7c1f84f0e45dd330 Mon Sep 17 00:00:00 2001 From: Dmitry Brant Date: Sun, 22 Oct 2023 15:22:19 -0400 Subject: [PATCH] A bit of cleanup. --- ImageFormats/TgaReader.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ImageFormats/TgaReader.cs b/ImageFormats/TgaReader.cs index ab8abc8..472390c 100644 --- a/ImageFormats/TgaReader.cs +++ b/ImageFormats/TgaReader.cs @@ -43,10 +43,8 @@ public static class TgaReader /// Bitmap that contains the image that was read. public static Image Load(string fileName) { - using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - return Load(f); - } + using var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); + return Load(f); } /// @@ -57,10 +55,9 @@ public static Image Load(string fileName) /// public static Image Load(Stream stream) { - BinaryReader reader = new BinaryReader(stream); + BinaryReader reader = new(stream); UInt32[] palette = null; - byte[] scanline = null; byte idFieldLength = (byte)stream.ReadByte(); byte colorMap = (byte)stream.ReadByte(); @@ -159,6 +156,8 @@ public static Image Load(Stream stream) } } + byte[] scanline; + if (imageType == 1 || imageType == 2 || imageType == 3) { scanline = new byte[imgWidth * (bitsPerPixel / 8)];