|
|
|
@ -212,18 +212,18 @@ namespace SixLabors.ImageSharp.Formats.Jpeg |
|
|
|
public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
this.ParseStream(stream); |
|
|
|
this.ParseStream(stream, cancellationToken: cancellationToken); |
|
|
|
this.InitExifProfile(); |
|
|
|
this.InitIccProfile(); |
|
|
|
this.InitIptcProfile(); |
|
|
|
this.InitDerivedMetadataProperties(); |
|
|
|
return this.PostProcessIntoImage<TPixel>(); |
|
|
|
return this.PostProcessIntoImage<TPixel>(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
this.ParseStream(stream, true); |
|
|
|
this.ParseStream(stream, true, cancellationToken); |
|
|
|
this.InitExifProfile(); |
|
|
|
this.InitIccProfile(); |
|
|
|
this.InitIptcProfile(); |
|
|
|
@ -237,7 +237,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg |
|
|
|
/// </summary>
|
|
|
|
/// <param name="stream">The input stream</param>
|
|
|
|
/// <param name="metadataOnly">Whether to decode metadata only.</param>
|
|
|
|
public void ParseStream(BufferedReadStream stream, bool metadataOnly = false) |
|
|
|
/// <param name="cancellationToken">The token to monitor cancellation.</param>
|
|
|
|
public void ParseStream(BufferedReadStream stream, bool metadataOnly = false, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
this.Metadata = new ImageMetadata(); |
|
|
|
|
|
|
|
@ -283,7 +284,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg |
|
|
|
case JpegConstants.Markers.SOS: |
|
|
|
if (!metadataOnly) |
|
|
|
{ |
|
|
|
this.ProcessStartOfScanMarker(stream); |
|
|
|
this.ProcessStartOfScanMarker(stream, cancellationToken); |
|
|
|
break; |
|
|
|
} |
|
|
|
else |
|
|
|
@ -990,8 +991,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg |
|
|
|
/// <summary>
|
|
|
|
/// Processes the SOS (Start of scan marker).
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="stream">The input stream.</param>
|
|
|
|
private void ProcessStartOfScanMarker(BufferedReadStream stream) |
|
|
|
private void ProcessStartOfScanMarker(BufferedReadStream stream, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
if (this.Frame is null) |
|
|
|
{ |
|
|
|
@ -1042,7 +1042,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg |
|
|
|
spectralStart, |
|
|
|
spectralEnd, |
|
|
|
successiveApproximation >> 4, |
|
|
|
successiveApproximation & 15); |
|
|
|
successiveApproximation & 15, |
|
|
|
cancellationToken); |
|
|
|
|
|
|
|
sd.ParseEntropyCodedData(); |
|
|
|
} |
|
|
|
@ -1075,7 +1076,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg |
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|
|
|
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|
|
|
private Image<TPixel> PostProcessIntoImage<TPixel>() |
|
|
|
private Image<TPixel> PostProcessIntoImage<TPixel>(CancellationToken cancellationToken) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
if (this.ImageWidth == 0 || this.ImageHeight == 0) |
|
|
|
@ -1091,7 +1092,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg |
|
|
|
|
|
|
|
using (var postProcessor = new JpegImagePostProcessor(this.Configuration, this)) |
|
|
|
{ |
|
|
|
postProcessor.PostProcess(image.Frames.RootFrame); |
|
|
|
postProcessor.PostProcess(image.Frames.RootFrame, cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
return image; |
|
|
|
|