Browse Source

Break out after SOS marker

af/merge-core
James Jackson-South 8 years ago
parent
commit
5e184bcffa
  1. 15
      src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs
  2. 6
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs
  3. 22
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

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

@ -191,7 +191,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
where TPixel : struct, IPixel<TPixel>
{
this.ParseStream(stream);
return this.PostProcessIntoImage<TPixel>();
}
@ -202,7 +201,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
public IImageInfo Identify(Stream stream)
{
this.ParseStream(stream, true);
return new ImageInfo(new PixelTypeInfo(this.BitsPerPixel), this.ImageWidth, this.ImageHeight, this.MetaData);
}
@ -361,11 +359,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
break;
case OrigJpegConstants.Markers.SOS:
if (metadataOnly)
{
this.InputProcessor.Skip(remaining);
}
else
if (!metadataOnly)
{
this.ProcessStartOfScanMarker(remaining);
if (this.InputProcessor.ReachedEOF)
@ -374,8 +368,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
processBytes = false;
}
}
else
{
// It's highly unlikely that APPn related data will be found after the SOS marker
// We should have gathered everything we need by now.
processBytes = false;
}
break;
case OrigJpegConstants.Markers.DRI:
if (metadataOnly)
{

6
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs

@ -412,19 +412,19 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool TryReadBit(DoubleBufferedStreamReader stream, out int bits)
private bool TryReadBit(DoubleBufferedStreamReader stream, out int bit)
{
if (this.bitsCount == 0)
{
if (!this.TryFillBits(stream))
{
bits = 0;
bit = 0;
return false;
}
}
this.bitsCount--;
bits = (this.bitsData >> this.bitsCount) & 1;
bit = (this.bitsData >> this.bitsCount) & 1;
return true;
}

22
src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

@ -185,6 +185,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
where TPixel : struct, IPixel<TPixel>
{
this.ParseStream(stream);
this.AssignResolution();
return this.PostProcessIntoImage<TPixel>();
}
@ -195,6 +196,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
public IImageInfo Identify(Stream stream)
{
this.ParseStream(stream, true);
this.AssignResolution();
return new ImageInfo(new PixelTypeInfo(this.BitsPerPixel), this.ImageWidth, this.ImageHeight, this.MetaData);
}
@ -244,17 +246,18 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
break;
case PdfJsJpegConstants.Markers.SOS:
if (metadataOnly)
if (!metadataOnly)
{
this.InputStream.Skip(remaining);
this.ProcessStartOfScanMarker();
break;
}
else
{
this.ProcessStartOfScanMarker();
// It's highly unlikely that APPn related data will be found after the SOS marker
// We should have gathered everything we need by now.
return;
}
break;
case PdfJsJpegConstants.Markers.DHT:
if (metadataOnly)
{
@ -331,11 +334,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
// Read on.
fileMarker = FindNextFileMarker(this.markerBuffer, this.InputStream);
}
this.ImageWidth = this.Frame.SamplesPerLine;
this.ImageHeight = this.Frame.Scanlines;
this.ComponentCount = this.Frame.ComponentCount;
this.AssignResolution();
}
/// <inheritdoc/>
@ -389,6 +387,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
/// </summary>
private void AssignResolution()
{
this.ImageWidth = this.Frame.SamplesPerLine;
this.ImageHeight = this.Frame.Scanlines;
if (this.jFif.XDensity > 0 && this.jFif.YDensity > 0)
{
this.MetaData.HorizontalResolution = this.jFif.XDensity;
@ -633,6 +634,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
int maxV = 0;
int index = 6;
this.ComponentCount = this.Frame.ComponentCount;
if (!metadataOnly)
{
// No need to pool this. They max out at 4

Loading…
Cancel
Save