Browse Source

Wired up converter & scan decoder

pull/1694/head
Dmitry Pentin 5 years ago
parent
commit
1dbb16a7fd
  1. 21
      src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
  2. 4
      src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs
  3. 5
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

21
src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs

@ -26,15 +26,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
private JpegFrame frame; private JpegFrame frame;
private JpegComponent[] components; private JpegComponent[] components;
public JpegFrame Frame
{
set
{
frame = value;
components = value.Components;
}
}
// The restart interval. // The restart interval.
private int restartInterval; private int restartInterval;
// How many mcu's are left to do. // How many mcu's are left to do.
@ -72,6 +63,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
private HuffmanScanBuffer scanBuffer; private HuffmanScanBuffer scanBuffer;
private SpectralConverter spectralConverter;
private CancellationToken cancellationToken; private CancellationToken cancellationToken;
/// <summary> /// <summary>
@ -90,10 +83,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// <param name="cancellationToken">The token to monitor cancellation.</param> /// <param name="cancellationToken">The token to monitor cancellation.</param>
public HuffmanScanDecoder( public HuffmanScanDecoder(
BufferedReadStream stream, BufferedReadStream stream,
SpectralConverter converter,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
this.dctZigZag = ZigZag.CreateUnzigTable(); this.dctZigZag = ZigZag.CreateUnzigTable();
this.stream = stream; this.stream = stream;
this.spectralConverter = converter;
this.cancellationToken = cancellationToken; this.cancellationToken = cancellationToken;
} }
@ -121,6 +116,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
} }
} }
public void InjectFrameData(JpegFrame frame, IRawJpegData jpegData)
{
this.frame = frame;
this.components = frame.Components;
this.spectralConverter.InjectFrameData(frame, jpegData);
}
private void ParseBaselineData() private void ParseBaselineData()
{ {
if (this.componentsLength == 1) if (this.componentsLength == 1)

4
src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs

@ -15,6 +15,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{ {
internal abstract class SpectralConverter internal abstract class SpectralConverter
{ {
public abstract void InjectFrameData(JpegFrame frame, IRawJpegData jpegData);
public abstract void ConvertStride(); public abstract void ConvertStride();
} }
@ -72,7 +74,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
this.cancellationToken = ct; this.cancellationToken = ct;
} }
public void InjectFrameData(JpegFrame frame, IRawJpegData jpegData) public override void InjectFrameData(JpegFrame frame, IRawJpegData jpegData)
{ {
MemoryAllocator allocator = this.configuration.MemoryAllocator; MemoryAllocator allocator = this.configuration.MemoryAllocator;

5
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -215,13 +215,16 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken) public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
this.scanDecoder = new HuffmanScanDecoder(stream, cancellationToken); SpectralConverter<TPixel> spectralConverter = new SpectralConverter<TPixel>(this.Configuration, cancellationToken);
this.scanDecoder = new HuffmanScanDecoder(stream, spectralConverter, cancellationToken);
this.ParseStream(stream, cancellationToken: cancellationToken); this.ParseStream(stream, cancellationToken: cancellationToken);
this.InitExifProfile(); this.InitExifProfile();
this.InitIccProfile(); this.InitIccProfile();
this.InitIptcProfile(); this.InitIptcProfile();
this.InitDerivedMetadataProperties(); this.InitDerivedMetadataProperties();
return this.PostProcessIntoImage<TPixel>(cancellationToken); return this.PostProcessIntoImage<TPixel>(cancellationToken);
} }

Loading…
Cancel
Save