Browse Source

Make JFIF marker optional

pull/2566/head
James Jackson-South 2 years ago
parent
commit
48cecd3c18
  1. 3
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs
  2. 8
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs
  3. 5
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  4. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

3
src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs

@ -73,8 +73,7 @@ internal readonly struct JFifMarker : IEquatable<JFifMarker>
{
// Some images incorrectly use JFXX as the App0 marker (Issue 2478)
if (ProfileResolver.IsProfile(bytes, ProfileResolver.JFifMarker)
|| ProfileResolver.IsProfile(bytes, ProfileResolver.JFxxMarker)
|| ProfileResolver.IsProfile(bytes, ProfileResolver.OSQidMaker))
|| ProfileResolver.IsProfile(bytes, ProfileResolver.JFxxMarker))
{
byte majorVersion = bytes[5];
byte minorVersion = bytes[6];

8
src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs

@ -24,14 +24,6 @@ internal static class ProfileResolver
(byte)'J', (byte)'F', (byte)'X', (byte)'X', (byte)'\0'
};
/// <summary>
/// Gets the \n[ID or 10 91 73 68 32 specific markers.
/// </summary>
public static ReadOnlySpan<byte> OSQidMaker => new[]
{
(byte)'\n', (byte)'[', (byte)'I', (byte)'D', (byte)' '
};
/// <summary>
/// Gets the ICC specific markers.
/// </summary>

5
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -753,10 +753,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals
Span<byte> temp = stackalloc byte[2 * 16 * 4];
stream.Read(temp, 0, JFifMarker.Length);
if (!JFifMarker.TryParse(temp, out this.jFif))
{
JpegThrowHelper.ThrowNotSupportedException("Unknown App0 Marker - Expected JFIF.");
}
_ = JFifMarker.TryParse(temp, out this.jFif);
remaining -= JFifMarker.Length;

2
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -330,7 +330,7 @@ public partial class JpegDecoderTests
[Theory]
[WithFile(TestImages.Jpeg.Issues.Issue2564, PixelTypes.Rgba32)]
public void Issue2564_DecodeWorks<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(JpegDecoder.Instance);
image.DebugSave(provider);

Loading…
Cancel
Save