Browse Source

Implemented disposable pattern for spectral converter

pull/1694/head
Dmitry Pentin 5 years ago
parent
commit
1348ecfeaa
  1. 16
      src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs
  2. 2
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

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

@ -13,15 +13,15 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
internal abstract class SpectralConverter
internal abstract class SpectralConverter : IDisposable
{
public abstract void InjectFrameData(JpegFrame frame, IRawJpegData jpegData);
public abstract void ConvertStride();
public abstract void Dispose();
}
// TODO: componentProcessors must be disposed!!!
// TODO: rgbaBuffer must be disposed!!!
internal class SpectralConverter<TPixel> : SpectralConverter
where TPixel : unmanaged, IPixel<TPixel>
{
@ -129,5 +129,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
this.PixelRowCounter += this.PixelRowsPerStep;
}
public override void Dispose()
{
foreach (JpegComponentPostProcessor cpp in this.componentProcessors)
{
cpp.Dispose();
}
this.rgbaBuffer.Dispose();
}
}
}

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

@ -215,7 +215,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
{
var spectralConverter = new SpectralConverter<TPixel>(this.Configuration, cancellationToken);
using var spectralConverter = new SpectralConverter<TPixel>(this.Configuration, cancellationToken);
this.scanDecoder = new HuffmanScanDecoder(stream, spectralConverter, cancellationToken);

Loading…
Cancel
Save