Skip to content

Commit

Permalink
Make JFIF marker optional
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Nov 29, 2023
1 parent ca1fd46 commit 48cecd3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public static bool TryParse(ReadOnlySpan<byte> bytes, out JFifMarker marker)
{
// 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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 1 addition & 4 deletions src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,7 @@ private void ProcessApplicationHeaderMarker(BufferedReadStream stream, int remai
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;

Expand Down
2 changes: 1 addition & 1 deletion tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public void Issue2478_DecodeWorks<TPixel>(TestImageProvider<TPixel> provider)
[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);
Expand Down

0 comments on commit 48cecd3

Please sign in to comment.