From dc4bc6e03f91f87bc2464ac5154f258a2ab7175a Mon Sep 17 00:00:00 2001 From: Dmitry Pentin Date: Fri, 9 Jul 2021 18:58:07 +0300 Subject: [PATCH] Fixed converter frame injection --- .../Decoder/SpectralConverter{TPixel}.cs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs index 8bab9f18a3..6e6ba7ab8f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs @@ -33,6 +33,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder private Buffer2D pixelBuffer; + public int BlockRowsPerStep; private int PixelRowsPerStep; @@ -40,42 +41,39 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder private int PixelRowCounter; - public JpegFrame Frame - { - set => this.InjectFrame(value); - } public SpectralConverter(Configuration configuration) { this.configuration = configuration; } - private void InjectFrame(JpegFrame frame) + public void InjectFrameData(JpegFrame frame, IRawJpegData jpegData) { MemoryAllocator allocator = this.configuration.MemoryAllocator; + // iteration data + IJpegComponent c0 = frame.Components[0]; + + const int blockPixelHeight = 8; + this.BlockRowsPerStep = c0.SamplingFactors.Height; + this.PixelRowsPerStep = this.BlockRowsPerStep * blockPixelHeight; + // pixel buffer for resulting image this.pixelBuffer = allocator.Allocate2D(frame.PixelWidth, frame.PixelHeight, AllocationOptions.Clean); // component processors from spectral to Rgba32 + var postProcessorBufferSize = new Size(c0.SizeInBlocks.Width * 8, this.PixelRowsPerStep); this.componentProcessors = new JpegComponentPostProcessor[frame.Components.Length]; for (int i = 0; i < this.componentProcessors.Length; i++) { - this.componentProcessors[i] = new JpegComponentPostProcessor(allocator, this, frame.Components[i]); + this.componentProcessors[i] = new JpegComponentPostProcessor(allocator, jpegData, postProcessorBufferSize, frame.Components[i]); } // single 'stride' rgba32 buffer for conversion between spectral and TPixel this.rgbaBuffer = allocator.Allocate(frame.PixelWidth); // color converter from Rgba32 to TPixel - this.colorConverter = JpegColorConverter.GetConverter(rawJpeg.ColorSpace, frame.Precision); - - // iteration data - IJpegComponent c0 = frame.Components[0]; - - const int blockPixelHeight = 8; - this.BlockRowsPerStep = c0.SamplingFactors.Height; - this.PixelRowsPerStep = this.BlockRowsPerStep * blockPixelHeight; + this.colorConverter = JpegColorConverter.GetConverter(jpegData.ColorSpace, frame.Precision); } public override void ConvertStride()