diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
index 1a1260a58e..c19495da72 100644
--- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
+++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
@@ -7,7 +7,6 @@ using System.Buffers.Binary;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
-using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
@@ -73,7 +72,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
this.configuration = image.GetConfiguration();
ImageMetadata metadata = image.Metadata;
TgaMetadata tgaMetadata = metadata.GetTgaMetadata();
- this.bitsPerPixel = this.bitsPerPixel ?? tgaMetadata.BitsPerPixel;
+ this.bitsPerPixel ??= tgaMetadata.BitsPerPixel;
TgaImageType imageType = this.compression is TgaCompression.RunLength ? TgaImageType.RleTrueColor : TgaImageType.TrueColor;
if (this.bitsPerPixel == TgaBitsPerPixel.Pixel8)
@@ -160,6 +159,8 @@ namespace SixLabors.ImageSharp.Formats.Tga
case TgaBitsPerPixel.Pixel32:
this.Write32Bit(stream, pixels);
break;
+ default:
+ break;
}
}
@@ -213,6 +214,8 @@ namespace SixLabors.ImageSharp.Formats.Tga
stream.WriteByte(color.R);
stream.WriteByte(color.A);
break;
+ default:
+ break;
}
encodedPixels += equalPixelCount + 1;
@@ -225,35 +228,29 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// The pixel type.
/// The pixels of the image.
/// X coordinate to start searching for the same pixels.
- /// Y coordinate to start searching for the same pixels.
+ /// Y coordinate to searching for the same pixels in only one scan line.
/// The number of equal pixels.
- private byte FindEqualPixels(Buffer2D pixels, int xStart, int yStart)
+ private byte FindEqualPixels(Buffer2D pixels, int xStart, int yPos)
where TPixel : unmanaged, IPixel
{
byte equalPixelCount = 0;
- bool firstRow = true;
- TPixel startPixel = pixels[xStart, yStart];
- for (int y = yStart; y < pixels.Height; y++)
+ TPixel startPixel = pixels[xStart, yPos];
+ for (int x = xStart + 1; x < pixels.Width; x++)
{
- for (int x = firstRow ? xStart + 1 : 0; x < pixels.Width; x++)
+ TPixel nextPixel = pixels[x, yPos];
+ if (startPixel.Equals(nextPixel))
+ {
+ equalPixelCount++;
+ }
+ else
{
- TPixel nextPixel = pixels[x, y];
- if (startPixel.Equals(nextPixel))
- {
- equalPixelCount++;
- }
- else
- {
- return equalPixelCount;
- }
-
- if (equalPixelCount >= 127)
- {
- return equalPixelCount;
- }
+ return equalPixelCount;
}
- firstRow = false;
+ if (equalPixelCount >= 127)
+ {
+ return equalPixelCount;
+ }
}
return equalPixelCount;