Browse Source

fix for unnecessary memory allocation, if only the metadata of the image will be read

pull/547/head
popow 9 years ago
parent
commit
bab1728eea
  1. 2
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs
  2. 20
      src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs

2
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs

@ -246,7 +246,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
public void Dispose() public void Dispose()
{ {
this.SpectralBlocks.Dispose(); this.SpectralBlocks?.Dispose();
} }
} }
} }

20
src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
/// <summary> /// <summary>
/// Encapsulates stream reading and processing data and operations for <see cref="OrigJpegDecoderCore"/>. /// Encapsulates stream reading and processing data and operations for <see cref="OrigJpegDecoderCore"/>.
/// 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
/// </summary> /// </summary>
public InputProcessor InputProcessor; public InputProcessor InputProcessor;
#pragma warning restore SA401 #pragma warning restore SA401
@ -168,7 +168,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
public int MCUCountY => this.ImageSizeInMCU.Height; public int MCUCountY => this.ImageSizeInMCU.Height;
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public int TotalMCUCount => this.MCUCountX * this.MCUCountY; public int TotalMCUCount => this.MCUCountX * this.MCUCountY;
@ -331,7 +331,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
case OrigJpegConstants.Markers.SOF1: case OrigJpegConstants.Markers.SOF1:
case OrigJpegConstants.Markers.SOF2: case OrigJpegConstants.Markers.SOF2:
this.IsProgressive = marker == OrigJpegConstants.Markers.SOF2; this.IsProgressive = marker == OrigJpegConstants.Markers.SOF2;
this.ProcessStartOfFrameMarker(remaining); this.ProcessStartOfFrameMarker(remaining, metadataOnly);
if (metadataOnly && this.isJFif) if (metadataOnly && this.isJFif)
{ {
return; return;
@ -634,7 +634,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
/// Processes the Start of Frame marker. Specified in section B.2.2. /// Processes the Start of Frame marker. Specified in section B.2.2.
/// </summary> /// </summary>
/// <param name="remaining">The remaining bytes in the segment block.</param> /// <param name="remaining">The remaining bytes in the segment block.</param>
private void ProcessStartOfFrameMarker(int remaining) /// <param name="metadataOnly">Whether to decode metadata only.</param>
private void ProcessStartOfFrameMarker(int remaining, bool metadataOnly)
{ {
if (this.ComponentCount != 0) if (this.ComponentCount != 0)
{ {
@ -689,12 +690,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
this.ImageSizeInMCU = this.ImageSizeInPixels.DivideRoundUp(8 * h0, 8 * v0); this.ImageSizeInMCU = this.ImageSizeInPixels.DivideRoundUp(8 * h0, 8 * v0);
foreach (OrigComponent component in this.Components) this.ColorSpace = this.DeduceJpegColorSpace();
if (!metadataOnly)
{ {
component.InitializeDerivedData(this.configuration.MemoryManager, this); foreach (OrigComponent component in this.Components)
{
component.InitializeDerivedData(this.configuration.MemoryManager, this);
}
} }
this.ColorSpace = this.DeduceJpegColorSpace();
} }
/// <summary> /// <summary>

Loading…
Cancel
Save