diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index 19e5e88ca6..bc85194096 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -108,14 +108,7 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals // Write scans with actual pixel data using SpectralConverter spectralConverter = new(frame, image, this.QuantizationTables); - if (this.encoder.Progressive) - { - this.WriteProgressiveScans(frame, frameConfig, spectralConverter, scanEncoder, buffer, cancellationToken); - } - else - { - this.WriteHuffmanScans(frame, frameConfig, spectralConverter, scanEncoder, buffer, cancellationToken); - } + this.WriteHuffmanScans(frame, frameConfig, spectralConverter, scanEncoder, buffer, cancellationToken); // Write the End Of Image marker. this.WriteEndOfImageMarker(buffer); @@ -690,7 +683,14 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { - if (frame.Components.Length == 1) + if (this.encoder.Progressive) + { + frame.AllocateComponents(fullScan: true); + spectralConverter.ConvertFull(); + + this.WriteProgressiveScans(frame, frameConfig, encoder, buffer, cancellationToken); + } + else if (frame.Components.Length == 1) { frame.AllocateComponents(fullScan: false); @@ -724,22 +724,17 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// The type of pixel format. /// The current frame. /// The frame configuration. - /// The spectral converter. /// The scan encoder. /// Temporary buffer. /// The cancellation token. private void WriteProgressiveScans( JpegFrame frame, JpegFrameConfig frameConfig, - SpectralConverter spectralConverter, HuffmanScanEncoder encoder, Span buffer, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { - frame.AllocateComponents(fullScan: true); - spectralConverter.ConvertFull(); - Span components = frameConfig.Components; // Phase 1: DC scan