Skip to content

Commit dc5affa

Browse files
committed
update jpeg encoder core
1 parent 490c0d3 commit dc5affa

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
108108

109109
// Write scans with actual pixel data
110110
using SpectralConverter<TPixel> spectralConverter = new(frame, image, this.QuantizationTables);
111-
if (this.encoder.Progressive)
112-
{
113-
this.WriteProgressiveScans(frame, frameConfig, spectralConverter, scanEncoder, buffer, cancellationToken);
114-
}
115-
else
116-
{
117-
this.WriteHuffmanScans(frame, frameConfig, spectralConverter, scanEncoder, buffer, cancellationToken);
118-
}
111+
this.WriteHuffmanScans(frame, frameConfig, spectralConverter, scanEncoder, buffer, cancellationToken);
119112

120113
// Write the End Of Image marker.
121114
this.WriteEndOfImageMarker(buffer);
@@ -690,7 +683,14 @@ private void WriteHuffmanScans<TPixel>(
690683
CancellationToken cancellationToken)
691684
where TPixel : unmanaged, IPixel<TPixel>
692685
{
693-
if (frame.Components.Length == 1)
686+
if (this.encoder.Progressive)
687+
{
688+
frame.AllocateComponents(fullScan: true);
689+
spectralConverter.ConvertFull();
690+
691+
this.WriteProgressiveScans<TPixel>(frame, frameConfig, encoder, buffer, cancellationToken);
692+
}
693+
else if (frame.Components.Length == 1)
694694
{
695695
frame.AllocateComponents(fullScan: false);
696696

@@ -724,22 +724,17 @@ private void WriteHuffmanScans<TPixel>(
724724
/// <typeparam name="TPixel">The type of pixel format.</typeparam>
725725
/// <param name="frame">The current frame.</param>
726726
/// <param name="frameConfig">The frame configuration.</param>
727-
/// <param name="spectralConverter">The spectral converter.</param>
728727
/// <param name="encoder">The scan encoder.</param>
729728
/// <param name="buffer">Temporary buffer.</param>
730729
/// <param name="cancellationToken">The cancellation token.</param>
731730
private void WriteProgressiveScans<TPixel>(
732731
JpegFrame frame,
733732
JpegFrameConfig frameConfig,
734-
SpectralConverter<TPixel> spectralConverter,
735733
HuffmanScanEncoder encoder,
736734
Span<byte> buffer,
737735
CancellationToken cancellationToken)
738736
where TPixel : unmanaged, IPixel<TPixel>
739737
{
740-
frame.AllocateComponents(fullScan: true);
741-
spectralConverter.ConvertFull();
742-
743738
Span<JpegComponentConfig> components = frameConfig.Components;
744739

745740
// Phase 1: DC scan

0 commit comments

Comments
 (0)