From 8db7cd5955e88356b4013aa01cd030e21a7ca7bb Mon Sep 17 00:00:00 2001 From: popow Date: Fri, 27 Apr 2018 20:00:02 +0200 Subject: [PATCH] added parameter metadataOnly to InitializeDerivedData: If true, memory allocation will not be done --- .../Jpeg/GolangPort/Components/Decoder/OrigComponent.cs | 8 ++++++-- .../Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs | 7 ++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs index e2b72db05..8445625bd 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs @@ -57,7 +57,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder /// /// The to use for buffer allocations. /// The instance - public void InitializeDerivedData(MemoryManager memoryManager, OrigJpegDecoderCore decoder) + /// Whether to decode metadata only. If this is true, memory allocation for SpectralBlocks will not be necessary + public void InitializeDerivedData(MemoryManager memoryManager, OrigJpegDecoderCore decoder, bool metadataOnly) { // For 4-component images (either CMYK or YCbCrK), we only support two // hv vectors: [0x11 0x11 0x11 0x11] and [0x22 0x11 0x11 0x22]. @@ -80,7 +81,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors); } - this.SpectralBlocks = memoryManager.Allocate2D(this.SizeInBlocks.Width, this.SizeInBlocks.Height, true); + if (!metadataOnly) + { + this.SpectralBlocks = memoryManager.Allocate2D(this.SizeInBlocks.Width, this.SizeInBlocks.Height, true); + } } /// diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs index 920210872..66b4601da 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs @@ -692,12 +692,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort this.ColorSpace = this.DeduceJpegColorSpace(); - if (!metadataOnly) + foreach (OrigComponent component in this.Components) { - foreach (OrigComponent component in this.Components) - { - component.InitializeDerivedData(this.configuration.MemoryManager, this); - } + component.InitializeDerivedData(this.configuration.MemoryManager, this, metadataOnly); } }