Browse Source

Merge branch 'master' into js/better-identify

pull/549/head
James Jackson-South 9 years ago
parent
commit
2c0fb6df05
  1. 2
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs
  2. 48
      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();
} }
} }
} }

48
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
@ -166,7 +166,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;
@ -213,7 +213,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
{ {
foreach (OrigComponent component in this.Components) foreach (OrigComponent component in this.Components)
{ {
component.Dispose(); component?.Dispose();
} }
} }
@ -361,12 +361,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
break; break;
case OrigJpegConstants.Markers.SOS: case OrigJpegConstants.Markers.SOS:
if (metadataOnly) if (!metadataOnly)
{ {
return; this.ProcessStartOfScanMarker(remaining);
} }
this.ProcessStartOfScanMarker(remaining);
if (this.InputProcessor.ReachedEOF) if (this.InputProcessor.ReachedEOF)
{ {
// If unexpected EOF reached. We can stop processing bytes as we now have the image data. // 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. /// 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>
/// <param name="metadataOnly">Whether to parse metadata only</param> /// <param name="metadataOnly">Whether to decode metadata only.</param>
private void ProcessStartOfFrameMarker(int remaining, bool metadataOnly) private void ProcessStartOfFrameMarker(int remaining, bool metadataOnly)
{ {
if (this.ComponentCount != 0) if (this.ComponentCount != 0)
@ -675,27 +674,30 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
throw new ImageFormatException("SOF has wrong length"); throw new ImageFormatException("SOF has wrong length");
} }
this.Components = new OrigComponent[this.ComponentCount]; if (!metadataOnly)
for (int i = 0; i < this.ComponentCount; i++)
{ {
byte componentIdentifier = this.Temp[6 + (3 * i)]; this.Components = new OrigComponent[this.ComponentCount];
var component = new OrigComponent(componentIdentifier, i);
component.InitializeCoreData(this); for (int i = 0; i < this.ComponentCount; i++)
this.Components[i] = component; {
} 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 h0 = this.Components[0].HorizontalSamplingFactor;
int v0 = this.Components[0].VerticalSamplingFactor; 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) this.ColorSpace = this.DeduceJpegColorSpace();
{
component.InitializeDerivedData(this.configuration.MemoryManager, this);
}
this.ColorSpace = this.DeduceJpegColorSpace(); foreach (OrigComponent component in this.Components)
{
component.InitializeDerivedData(this.configuration.MemoryManager, this);
}
}
} }
/// <summary> /// <summary>

Loading…
Cancel
Save