diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs index e2f21bd1c3..e2b72db057 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs @@ -246,7 +246,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder public void Dispose() { - this.SpectralBlocks.Dispose(); + this.SpectralBlocks?.Dispose(); } } } diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs index fd83f95680..6b4da1ba1c 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort /// /// Encapsulates stream reading and processing data and operations for . - /// It's a value type for imporved data locality, and reduced number of CALLVIRT-s + /// It's a value type for improved data locality, and reduced number of CALLVIRT-s /// public InputProcessor InputProcessor; #pragma warning restore SA401 @@ -166,7 +166,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort public int MCUCountY => this.ImageSizeInMCU.Height; /// - /// Gets the the total number of MCU-s (Minimum Coded Units) in the image. + /// Gets the total number of MCU-s (Minimum Coded Units) in the image. /// public int TotalMCUCount => this.MCUCountX * this.MCUCountY; @@ -213,7 +213,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort { foreach (OrigComponent component in this.Components) { - component.Dispose(); + component?.Dispose(); } } @@ -361,12 +361,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort break; case OrigJpegConstants.Markers.SOS: - if (metadataOnly) + if (!metadataOnly) { - return; + this.ProcessStartOfScanMarker(remaining); } - this.ProcessStartOfScanMarker(remaining); if (this.InputProcessor.ReachedEOF) { // If unexpected EOF reached. We can stop processing bytes as we now have the image data. @@ -634,7 +633,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort /// Processes the Start of Frame marker. Specified in section B.2.2. /// /// The remaining bytes in the segment block. - /// Whether to parse metadata only + /// Whether to decode metadata only. private void ProcessStartOfFrameMarker(int remaining, bool metadataOnly) { if (this.ComponentCount != 0) @@ -675,27 +674,30 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort throw new ImageFormatException("SOF has wrong length"); } - this.Components = new OrigComponent[this.ComponentCount]; - - for (int i = 0; i < this.ComponentCount; i++) + if (!metadataOnly) { - byte componentIdentifier = this.Temp[6 + (3 * i)]; - var component = new OrigComponent(componentIdentifier, i); - component.InitializeCoreData(this); - this.Components[i] = component; - } + this.Components = new OrigComponent[this.ComponentCount]; + + for (int i = 0; i < this.ComponentCount; i++) + { + byte componentIdentifier = this.Temp[6 + (3 * i)]; + var component = new OrigComponent(componentIdentifier, i); + component.InitializeCoreData(this); + this.Components[i] = component; + } - int h0 = this.Components[0].HorizontalSamplingFactor; - int v0 = this.Components[0].VerticalSamplingFactor; + int h0 = this.Components[0].HorizontalSamplingFactor; + int v0 = this.Components[0].VerticalSamplingFactor; - this.ImageSizeInMCU = this.ImageSizeInPixels.DivideRoundUp(8 * h0, 8 * v0); + this.ImageSizeInMCU = this.ImageSizeInPixels.DivideRoundUp(8 * h0, 8 * v0); - foreach (OrigComponent component in this.Components) - { - component.InitializeDerivedData(this.configuration.MemoryManager, this); - } + this.ColorSpace = this.DeduceJpegColorSpace(); - this.ColorSpace = this.DeduceJpegColorSpace(); + foreach (OrigComponent component in this.Components) + { + component.InitializeDerivedData(this.configuration.MemoryManager, this); + } + } } ///