From b88b1815d698ddc12548fb04840fb4afa8125f1f Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 16 Oct 2022 17:18:47 +1000 Subject: [PATCH] Migrate TgaEncoder --- .../Formats/Tga/ITgaEncoderOptions.cs | 20 ------------------- src/ImageSharp/Formats/Tga/TgaEncoder.cs | 13 +++++------- src/ImageSharp/Formats/Tga/TgaEncoderCore.cs | 12 ++++++----- 3 files changed, 12 insertions(+), 33 deletions(-) delete mode 100644 src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs diff --git a/src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs b/src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs deleted file mode 100644 index a42feb7f35..0000000000 --- a/src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Six Labors Split License. - -namespace SixLabors.ImageSharp.Formats.Tga; - -/// -/// Configuration options for use during tga encoding. -/// -internal interface ITgaEncoderOptions -{ - /// - /// Gets the number of bits per pixel. - /// - TgaBitsPerPixel? BitsPerPixel { get; } - - /// - /// Gets a value indicating whether run length compression should be used. - /// - TgaCompression Compression { get; } -} diff --git a/src/ImageSharp/Formats/Tga/TgaEncoder.cs b/src/ImageSharp/Formats/Tga/TgaEncoder.cs index f437e80a3f..d57f3cb33d 100644 --- a/src/ImageSharp/Formats/Tga/TgaEncoder.cs +++ b/src/ImageSharp/Formats/Tga/TgaEncoder.cs @@ -2,14 +2,13 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Tga; /// /// Image encoder for writing an image to a stream as a targa truevision image. /// -public sealed class TgaEncoder : IImageEncoder, ITgaEncoderOptions +public sealed class TgaEncoder : ImageEncoder { /// /// Gets or sets the number of bits per pixel. @@ -22,18 +21,16 @@ public sealed class TgaEncoder : IImageEncoder, ITgaEncoderOptions public TgaCompression Compression { get; set; } = TgaCompression.RunLength; /// - public void Encode(Image image, Stream stream) - where TPixel : unmanaged, IPixel + public override void Encode(Image image, Stream stream) { - var encoder = new TgaEncoderCore(this, image.GetMemoryAllocator()); + TgaEncoderCore encoder = new(this, image.GetMemoryAllocator()); encoder.Encode(image, stream); } /// - public Task EncodeAsync(Image image, Stream stream, CancellationToken cancellationToken) - where TPixel : unmanaged, IPixel + public override Task EncodeAsync(Image image, Stream stream, CancellationToken cancellationToken) { - var encoder = new TgaEncoderCore(this, image.GetMemoryAllocator()); + TgaEncoderCore encoder = new(this, image.GetMemoryAllocator()); return encoder.EncodeAsync(image, stream, cancellationToken); } } diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs index 016806db03..0a3eb74aed 100644 --- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs @@ -45,13 +45,13 @@ internal sealed class TgaEncoderCore : IImageEncoderInternals /// /// Initializes a new instance of the class. /// - /// The encoder options. + /// The encoder with options. /// The memory manager. - public TgaEncoderCore(ITgaEncoderOptions options, MemoryAllocator memoryAllocator) + public TgaEncoderCore(TgaEncoder encoder, MemoryAllocator memoryAllocator) { this.memoryAllocator = memoryAllocator; - this.bitsPerPixel = options.BitsPerPixel; - this.compression = options.Compression; + this.bitsPerPixel = encoder.BitsPerPixel; + this.compression = encoder.Compression; } /// @@ -105,7 +105,9 @@ internal sealed class TgaEncoderCore : IImageEncoderInternals cMapLength: 0, cMapDepth: 0, xOffset: 0, - yOffset: this.compression is TgaCompression.RunLength ? (short)image.Height : (short)0, // When run length encoding is used, the origin should be top left instead of the default bottom left. + + // When run length encoding is used, the origin should be top left instead of the default bottom left. + yOffset: this.compression is TgaCompression.RunLength ? (short)image.Height : (short)0, width: (short)image.Width, height: (short)image.Height, pixelDepth: (byte)this.bitsPerPixel.Value,