From 6b2f18952c0a802cc69065ec095157588dcc97bc Mon Sep 17 00:00:00 2001 From: Dmitry Pentin Date: Fri, 9 Jul 2021 18:52:33 +0300 Subject: [PATCH] Decoupled image processor from component processor --- .../Decoder/JpegComponentPostProcessor.cs | 19 ++++++++----------- .../Decoder/JpegImagePostProcessor.cs | 11 ++--------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs index 0a0a2cd9e..83406e0d6 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs @@ -27,23 +27,20 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// /// Initializes a new instance of the class. /// - public JpegComponentPostProcessor(MemoryAllocator memoryAllocator, JpegImagePostProcessor imagePostProcessor, IJpegComponent component) + public JpegComponentPostProcessor(MemoryAllocator memoryAllocator, IRawJpegData rawJpeg, Size postProcessorBufferSize, IJpegComponent component) { this.Component = component; - this.ImagePostProcessor = imagePostProcessor; + this.RawJpeg = rawJpeg; this.blockAreaSize = this.Component.SubSamplingDivisors * 8; this.ColorBuffer = memoryAllocator.Allocate2DOveraligned( - imagePostProcessor.PostProcessorBufferSize.Width, - imagePostProcessor.PostProcessorBufferSize.Height, + postProcessorBufferSize.Width, + postProcessorBufferSize.Height, this.blockAreaSize.Height); - this.BlockRowsPerStep = imagePostProcessor.BlockRowsPerStep / this.Component.SubSamplingDivisors.Height; + this.BlockRowsPerStep = postProcessorBufferSize.Height / 8 / this.Component.SubSamplingDivisors.Height; } - /// - /// Gets the - /// - public JpegImagePostProcessor ImagePostProcessor { get; } + public IRawJpegData RawJpeg { get; } /// /// Gets the @@ -76,8 +73,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// public void CopyBlocksToColorBuffer() { - var blockPp = new JpegBlockPostProcessor(this.ImagePostProcessor.RawJpeg, this.Component); - float maximumValue = MathF.Pow(2, this.ImagePostProcessor.RawJpeg.Precision) - 1; + var blockPp = new JpegBlockPostProcessor(this.RawJpeg, this.Component); + float maximumValue = MathF.Pow(2, this.RawJpeg.Precision) - 1; int destAreaStride = this.ColorBuffer.Width; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs index 5f3389e17..18b2bc6e8 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs @@ -62,14 +62,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder this.NumberOfPostProcessorSteps = c0.SizeInBlocks.Height / this.BlockRowsPerStep; - this.PostProcessorBufferSize = new Size(c0.SizeInBlocks.Width * 8, this.PixelRowsPerStep); - + var postProcessorBufferSize = new Size(c0.SizeInBlocks.Width * 8, this.PixelRowsPerStep); MemoryAllocator memoryAllocator = configuration.MemoryAllocator; - this.ComponentProcessors = new JpegComponentPostProcessor[rawJpeg.Components.Length]; for (int i = 0; i < rawJpeg.Components.Length; i++) { - this.ComponentProcessors[i] = new JpegComponentPostProcessor(memoryAllocator, this, rawJpeg.Components[i]); + this.ComponentProcessors[i] = new JpegComponentPostProcessor(memoryAllocator, this.RawJpeg, postProcessorBufferSize, rawJpeg.Components[i]); } this.rgbaBuffer = memoryAllocator.Allocate(rawJpeg.ImageSizeInPixels.Width); @@ -91,11 +89,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// public int NumberOfPostProcessorSteps { get; } - /// - /// Gets the size of the temporary buffers we need to allocate into . - /// - public Size PostProcessorBufferSize { get; } - /// /// Gets the value of the counter that grows by each step by . ///