diff --git a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs index dd3b6a821..c8e23532f 100644 --- a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Tga /// /// A scratch buffer to reduce allocations. /// - private readonly byte[] buffer = new byte[4]; + private readonly byte[] scratchBuffer = new byte[4]; /// /// The metadata. @@ -430,19 +430,19 @@ namespace SixLabors.ImageSharp.Formats.Tga { for (int x = 0; x < width; x++) { - this.currentStream.Read(this.buffer, 0, 2); + this.currentStream.Read(this.scratchBuffer, 0, 2); if (!this.hasAlpha) { - this.buffer[1] |= 1 << 7; + this.scratchBuffer[1] |= 1 << 7; } if (this.fileHeader.ImageType == TgaImageType.BlackAndWhite) { - color.FromLa16(Unsafe.As(ref this.buffer[0])); + color.FromLa16(Unsafe.As(ref this.scratchBuffer[0])); } else { - color.FromBgra5551(Unsafe.As(ref this.buffer[0])); + color.FromBgra5551(Unsafe.As(ref this.scratchBuffer[0])); } int newX = InvertX(x, width, origin); @@ -497,8 +497,8 @@ namespace SixLabors.ImageSharp.Formats.Tga Span pixelSpan = pixels.GetRowSpan(newY); for (int x = 0; x < width; x++) { - this.currentStream.Read(this.buffer, 0, 3); - color.FromBgr24(Unsafe.As(ref this.buffer[0])); + this.currentStream.Read(this.scratchBuffer, 0, 3); + color.FromBgr24(Unsafe.As(ref this.scratchBuffer[0])); int newX = InvertX(x, width, origin); pixelSpan[newX] = color; } @@ -531,9 +531,9 @@ namespace SixLabors.ImageSharp.Formats.Tga where TPixel : unmanaged, IPixel { TPixel color = default; + bool isXInverted = origin == TgaImageOrigin.BottomRight || origin == TgaImageOrigin.TopRight; if (this.tgaMetadata.AlphaChannelBits == 8) { - bool isXInverted = origin == TgaImageOrigin.BottomRight || origin == TgaImageOrigin.TopRight; if (isXInverted) { for (int y = 0; y < height; y++) @@ -542,8 +542,8 @@ namespace SixLabors.ImageSharp.Formats.Tga Span pixelSpan = pixels.GetRowSpan(newY); for (int x = 0; x < width; x++) { - this.currentStream.Read(this.buffer, 0, 4); - color.FromBgra32(Unsafe.As(ref this.buffer[0])); + this.currentStream.Read(this.scratchBuffer, 0, 4); + color.FromBgra32(Unsafe.As(ref this.scratchBuffer[0])); int newX = InvertX(x, width, origin); pixelSpan[newX] = color; } diff --git a/tests/Directory.Build.targets b/tests/Directory.Build.targets index 3c3b3b5ec..df153c08b 100644 --- a/tests/Directory.Build.targets +++ b/tests/Directory.Build.targets @@ -29,7 +29,7 @@ - + diff --git a/tests/ImageSharp.Tests/Formats/Tga/TgaTestUtils.cs b/tests/ImageSharp.Tests/Formats/Tga/TgaTestUtils.cs index cb3986b1f..c69cf2f20 100644 --- a/tests/ImageSharp.Tests/Formats/Tga/TgaTestUtils.cs +++ b/tests/ImageSharp.Tests/Formats/Tga/TgaTestUtils.cs @@ -44,6 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tga { using (var magickImage = new MagickImage(fileInfo)) { + magickImage.AutoOrient(); var result = new Image(configuration, magickImage.Width, magickImage.Height); Span resultPixels = result.GetPixelSpan();