From bd80c72a8212a42063a9e37b4972725dade75143 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 9 Nov 2019 11:27:09 +0100 Subject: [PATCH] Add width and height as parameter for makeopaque, change currentPosition to pixelDataStart --- src/ImageSharp/Formats/Tga/TgaDecoderCore.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs index c5a4df3f96..aa830057e8 100644 --- a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs @@ -366,7 +366,7 @@ namespace SixLabors.ImageSharp.Formats.Tga { Span bgraRowSpan = bgraRow.GetSpan(); long currentPosition = this.currentStream.Position; - for (int y = 0; y < this.fileHeader.Height; y++) + for (int y = 0; y < height; y++) { this.currentStream.Read(row); int newY = Invert(y, height, inverted); @@ -379,7 +379,7 @@ namespace SixLabors.ImageSharp.Formats.Tga } // We need to set each alpha component value to fully opaque. - this.MakeOpaque(pixels, currentPosition, row, bgraRowSpan); + this.MakeOpaque(pixels, width, height, currentPosition, row, bgraRowSpan); } } @@ -551,15 +551,17 @@ namespace SixLabors.ImageSharp.Formats.Tga /// /// The pixel type. /// The destination pixel buffer. - /// The start position of pixel data. + /// The width of the image. + /// The height of the image. + /// The start position of pixel data. /// A byte array to store the read pixel data. /// Bgra pixel row span. - private void MakeOpaque(Buffer2D pixels, long currentPosition, IManagedByteBuffer row, Span bgraRowSpan) + private void MakeOpaque(Buffer2D pixels, int width, int height, long pixelDataStart, IManagedByteBuffer row, Span bgraRowSpan) where TPixel : struct, IPixel { // Reset our stream for a second pass. - this.currentStream.Position = currentPosition; - for (int y = 0; y < this.fileHeader.Height; y++) + this.currentStream.Position = pixelDataStart; + for (int y = 0; y < width; y++) { this.currentStream.Read(row); PixelOperations.Instance.FromBgra5551Bytes( @@ -567,9 +569,9 @@ namespace SixLabors.ImageSharp.Formats.Tga row.GetSpan(), bgraRowSpan, this.fileHeader.Width); - Span pixelSpan = pixels.GetRowSpan(this.fileHeader.Height - y - 1); + Span pixelSpan = pixels.GetRowSpan(height - y - 1); - for (int x = 0; x < this.fileHeader.Width; x++) + for (int x = 0; x < width; x++) { Bgra5551 bgra = bgraRowSpan[x]; bgra.PackedValue = (ushort)(bgra.PackedValue | (1 << 15));