From d178c8c6725cb68bda2d2acdd820e3ea37ff23fe Mon Sep 17 00:00:00 2001 From: Dmitry Pentin Date: Fri, 9 Jul 2021 19:02:44 +0300 Subject: [PATCH] Added getter which converts pixels to PixelBuffer property --- .../Decoder/SpectralConverter{TPixel}.cs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs index 6e6ba7ab8..1befbbf82 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs @@ -6,6 +6,7 @@ using System.Buffers; using System.Collections.Generic; using System.Numerics; using System.Text; +using System.Threading; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -24,6 +25,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { private Configuration configuration; + private CancellationToken cancellationToken; + + private JpegComponentPostProcessor[] componentProcessors; private JpegColorConverter colorConverter; @@ -41,10 +45,31 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder private int PixelRowCounter; + private bool converted; + + public Buffer2D PixelBuffer + { + get + { + if (!this.converted) + { + while (this.PixelRowCounter < this.pixelBuffer.Height) + { + this.cancellationToken.ThrowIfCancellationRequested(); + this.ConvertStride(); + } + + this.converted = true; + } + + return this.pixelBuffer; + } + } - public SpectralConverter(Configuration configuration) + public SpectralConverter(Configuration configuration, CancellationToken ct) { this.configuration = configuration; + this.cancellationToken = ct; } public void InjectFrameData(JpegFrame frame, IRawJpegData jpegData)