diff --git a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs index 8cc6ee81a..89c4de550 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs @@ -133,6 +133,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg /// public const byte APP15 = 0xEF; + /// + /// Define arithmetic coding conditioning marker. + /// + public const byte DAC = 0xCC; + /// /// The text comment marker /// @@ -173,6 +178,56 @@ namespace SixLabors.ImageSharp.Formats.Jpeg /// public const byte SOF2 = 0xC2; + /// + /// Start of Frame marker, non differential lossless, Huffman coding. + /// + public const byte SOF3 = 0xC3; + + /// + /// Start of Frame marker, differential, Huffman coding, Differential sequential DCT. + /// + public const byte SOF5 = 0xC5; + + /// + /// Start of Frame marker, differential, Huffman coding, Differential progressive DCT. + /// + public const byte SOF6 = 0xC6; + + /// + /// Start of Frame marker, differential lossless, Huffman coding. + /// + public const byte SOF7 = 0xC7; + + /// + /// Start of Frame marker, non-differential, arithmetic coding, Extended sequential DCT. + /// + public const byte SOF9 = 0xC9; + + /// + /// Start of Frame marker, non-differential, arithmetic coding, Progressive DCT. + /// + public const byte SOF10 = 0xCA; + + /// + /// Start of Frame marker, non-differential, arithmetic coding, Lossless (sequential). + /// + public const byte SOF11 = 0xCB; + + /// + /// Start of Frame marker, differential, arithmetic coding, Differential sequential DCT. + /// + public const byte SOF13 = 0xCD; + + /// + /// Start of Frame marker, differential, arithmetic coding, Differential progressive DCT. + /// + public const byte SOF14 = 0xCE; + + /// + /// Start of Frame marker, differential, arithmetic coding, Differential lossless (sequential). + /// + public const byte SOF15 = 0xCF; + /// /// Define Huffman Table(s) /// diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 83aacb48f..dfef139ab 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -309,6 +309,28 @@ namespace SixLabors.ImageSharp.Formats.Jpeg this.ProcessStartOfFrameMarker(stream, remaining, fileMarker, metadataOnly); break; + case JpegConstants.Markers.SOF5: + JpegThrowHelper.ThrowNotSupportedException("Decoding jpeg files with differential sequential DCT is not supported."); + break; + + case JpegConstants.Markers.SOF6: + JpegThrowHelper.ThrowNotSupportedException("Decoding jpeg files with differential progressive DCT is not supported."); + break; + + case JpegConstants.Markers.SOF3: + case JpegConstants.Markers.SOF7: + JpegThrowHelper.ThrowNotSupportedException("Decoding lossless jpeg files is not supported."); + break; + + case JpegConstants.Markers.SOF9: + case JpegConstants.Markers.SOF10: + case JpegConstants.Markers.SOF11: + case JpegConstants.Markers.SOF13: + case JpegConstants.Markers.SOF14: + case JpegConstants.Markers.SOF15: + JpegThrowHelper.ThrowNotSupportedException("Decoding jpeg files with arithmetic coding is not supported."); + break; + case JpegConstants.Markers.SOS: if (!metadataOnly) { @@ -388,6 +410,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg case JpegConstants.Markers.COM: stream.Skip(remaining); break; + + case JpegConstants.Markers.DAC: + JpegThrowHelper.ThrowNotSupportedException("Decoding jpeg files with arithmetic coding is not supported."); + break; } } diff --git a/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs b/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs index 1b5362275..b6c7e7626 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs @@ -8,6 +8,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg { internal static class JpegThrowHelper { + /// + /// Cold path optimization for throwing 's. + /// + /// The error message for the exception. + [MethodImpl(InliningOptions.ColdPath)] + public static void ThrowNotSupportedException(string errorMessage) => throw new NotSupportedException(errorMessage); + /// /// Cold path optimization for throwing 's. /// diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs index a33a345a0..789a93687 100644 --- a/src/ImageSharp/Image.FromBytes.cs +++ b/src/ImageSharp/Image.FromBytes.cs @@ -102,6 +102,7 @@ namespace SixLabors.ImageSharp /// The pixel format. /// The data is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// A new . public static Image Load(byte[] data) @@ -116,6 +117,7 @@ namespace SixLabors.ImageSharp /// The pixel format. /// The data is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// A new . public static Image Load(byte[] data, out IImageFormat format) @@ -131,6 +133,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// The data is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// A new . public static Image Load(Configuration configuration, byte[] data) @@ -154,6 +157,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// The data is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// A new . public static Image Load(Configuration configuration, byte[] data, out IImageFormat format) @@ -175,6 +179,7 @@ namespace SixLabors.ImageSharp /// The pixel format. /// The data is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// A new . public static Image Load(byte[] data, IImageDecoder decoder) @@ -198,6 +203,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// The data is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// A new . public static Image Load(Configuration configuration, byte[] data, IImageDecoder decoder) @@ -216,10 +222,7 @@ namespace SixLabors.ImageSharp /// /// The byte span containing encoded image data to read the header from. /// The format or null if none found. - public static IImageFormat DetectFormat(ReadOnlySpan data) - { - return DetectFormat(Configuration.Default, data); - } + public static IImageFormat DetectFormat(ReadOnlySpan data) => DetectFormat(Configuration.Default, data); /// /// By reading the header on the provided byte span this calculates the images format. @@ -258,6 +261,7 @@ namespace SixLabors.ImageSharp /// The pixel format. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// A new . public static Image Load(ReadOnlySpan data) where TPixel : unmanaged, IPixel @@ -271,6 +275,7 @@ namespace SixLabors.ImageSharp /// The pixel format. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// A new . public static Image Load(ReadOnlySpan data, out IImageFormat format) where TPixel : unmanaged, IPixel @@ -284,6 +289,7 @@ namespace SixLabors.ImageSharp /// The pixel format. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// A new . public static Image Load(ReadOnlySpan data, IImageDecoder decoder) where TPixel : unmanaged, IPixel @@ -298,6 +304,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// A new . public static unsafe Image Load(Configuration configuration, ReadOnlySpan data) where TPixel : unmanaged, IPixel @@ -321,6 +328,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// A new . public static unsafe Image Load( Configuration configuration, @@ -347,6 +355,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// A new . public static unsafe Image Load( Configuration configuration, @@ -372,6 +381,7 @@ namespace SixLabors.ImageSharp /// The data is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The . public static Image Load(byte[] data, out IImageFormat format) => Load(Configuration.Default, data, out format); @@ -384,6 +394,7 @@ namespace SixLabors.ImageSharp /// The data is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The . public static Image Load(byte[] data, IImageDecoder decoder) => Load(Configuration.Default, data, decoder); @@ -397,6 +408,7 @@ namespace SixLabors.ImageSharp /// The data is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The . public static Image Load(Configuration configuration, byte[] data) => Load(configuration, data, out _); @@ -411,6 +423,7 @@ namespace SixLabors.ImageSharp /// The data is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The . public static Image Load(Configuration configuration, byte[] data, IImageDecoder decoder) { @@ -430,6 +443,7 @@ namespace SixLabors.ImageSharp /// The data is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The . public static Image Load(Configuration configuration, byte[] data, out IImageFormat format) { @@ -445,6 +459,7 @@ namespace SixLabors.ImageSharp /// The byte span containing image data. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The . public static Image Load(ReadOnlySpan data) => Load(Configuration.Default, data); @@ -458,6 +473,7 @@ namespace SixLabors.ImageSharp /// The decoder is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The . public static Image Load(ReadOnlySpan data, IImageDecoder decoder) => Load(Configuration.Default, data, decoder); @@ -470,6 +486,7 @@ namespace SixLabors.ImageSharp /// The decoder is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The . public static Image Load(ReadOnlySpan data, out IImageFormat format) => Load(Configuration.Default, data, out format); @@ -491,7 +508,7 @@ namespace SixLabors.ImageSharp /// The decoder. /// The configuration is null. /// The decoder is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The . @@ -518,6 +535,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The . public static unsafe Image Load( Configuration configuration, diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index bf239c3e9..3a4b459c5 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -182,6 +182,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// The path is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// The . public static Image Load(Configuration configuration, string path) @@ -196,6 +197,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// The path is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// A representing the asynchronous operation. public static async Task LoadAsync( @@ -219,6 +221,7 @@ namespace SixLabors.ImageSharp /// The path is null. /// The decoder is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// The . public static Image Load(Configuration configuration, string path, IImageDecoder decoder) @@ -241,6 +244,7 @@ namespace SixLabors.ImageSharp /// The path is null. /// The decoder is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// A representing the asynchronous operation. public static Task LoadAsync(string path, CancellationToken cancellationToken = default) @@ -255,6 +259,7 @@ namespace SixLabors.ImageSharp /// The path is null. /// The decoder is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// A representing the asynchronous operation. public static Task LoadAsync(string path, IImageDecoder decoder) @@ -269,6 +274,7 @@ namespace SixLabors.ImageSharp /// The path is null. /// The decoder is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// The pixel format. /// A representing the asynchronous operation. @@ -287,6 +293,7 @@ namespace SixLabors.ImageSharp /// The path is null. /// The decoder is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// A representing the asynchronous operation. public static Task LoadAsync( @@ -313,6 +320,7 @@ namespace SixLabors.ImageSharp /// The path is null. /// The decoder is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// The pixel format. /// A representing the asynchronous operation. @@ -338,6 +346,7 @@ namespace SixLabors.ImageSharp /// The path is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The pixel format. /// A representing the asynchronous operation. public static Task> LoadAsync(string path) @@ -353,6 +362,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// The path is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// The pixel format. /// A representing the asynchronous operation. @@ -376,6 +386,7 @@ namespace SixLabors.ImageSharp /// The path is null. /// The decoder is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// The . public static Image Load(string path, IImageDecoder decoder) @@ -388,6 +399,7 @@ namespace SixLabors.ImageSharp /// The path is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The pixel format. /// A new . public static Image Load(string path) @@ -402,6 +414,7 @@ namespace SixLabors.ImageSharp /// The path is null. /// Image format not recognised. /// Image contains invalid content. + /// Image format is not supported. /// The pixel format. /// A new . public static Image Load(string path, out IImageFormat format) @@ -416,6 +429,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// The path is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// The pixel format. /// A new . @@ -440,6 +454,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// The path is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// The pixel format. /// A new . @@ -465,6 +480,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// The path is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// A new . public static Image Load(Configuration configuration, string path, out IImageFormat format) @@ -485,6 +501,7 @@ namespace SixLabors.ImageSharp /// The decoder. /// The path is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// The pixel format. /// A new . @@ -502,6 +519,7 @@ namespace SixLabors.ImageSharp /// The path is null. /// The decoder is null. /// Image format not recognised. + /// Image format is not supported. /// Image contains invalid content. /// The pixel format. /// A new . diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs index b57fa9a6c..3dde8e77b 100644 --- a/src/ImageSharp/Image.FromStream.cs +++ b/src/ImageSharp/Image.FromStream.cs @@ -9,7 +9,6 @@ using System.Threading; using System.Threading.Tasks; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.IO; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp @@ -216,7 +215,7 @@ namespace SixLabors.ImageSharp /// The stream containing image information. /// The format type of the decoded image. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The . @@ -229,7 +228,7 @@ namespace SixLabors.ImageSharp /// /// The stream containing image information. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. @@ -242,7 +241,7 @@ namespace SixLabors.ImageSharp /// /// The stream containing image information. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The . @@ -254,7 +253,7 @@ namespace SixLabors.ImageSharp /// /// The stream containing image information. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. @@ -268,7 +267,7 @@ namespace SixLabors.ImageSharp /// The decoder. /// The stream is null. /// The decoder is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The . @@ -283,7 +282,7 @@ namespace SixLabors.ImageSharp /// The decoder. /// The stream is null. /// The decoder is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. @@ -300,7 +299,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// The stream is null. /// The decoder is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// A new . @@ -321,7 +320,7 @@ namespace SixLabors.ImageSharp /// The configuration is null. /// The stream is null. /// The decoder is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. @@ -346,7 +345,7 @@ namespace SixLabors.ImageSharp /// The stream containing image information. /// The configuration is null. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// A new . @@ -360,7 +359,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// The configuration is null. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. @@ -376,7 +375,7 @@ namespace SixLabors.ImageSharp /// /// The stream containing image information. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -390,7 +389,7 @@ namespace SixLabors.ImageSharp /// /// The stream containing image information. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -405,7 +404,7 @@ namespace SixLabors.ImageSharp /// The stream containing image information. /// The format type of the decoded image. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -419,7 +418,7 @@ namespace SixLabors.ImageSharp /// /// The stream containing image information. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -434,7 +433,7 @@ namespace SixLabors.ImageSharp /// The stream containing image information. /// The decoder. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -450,7 +449,7 @@ namespace SixLabors.ImageSharp /// The decoder. /// The token to monitor for cancellation requests. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -471,7 +470,7 @@ namespace SixLabors.ImageSharp /// The decoder. /// The configuration is null. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -489,7 +488,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// The configuration is null. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -513,7 +512,7 @@ namespace SixLabors.ImageSharp /// The stream containing image information. /// The configuration is null. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -530,7 +529,7 @@ namespace SixLabors.ImageSharp /// The format type of the decoded image. /// The configuration is null. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -566,7 +565,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// The configuration is null. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. @@ -606,7 +605,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// The configuration is null. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -649,7 +648,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// The configuration is null. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// The pixel format. @@ -674,7 +673,7 @@ namespace SixLabors.ImageSharp /// The format type of the decoded image. /// The configuration is null. /// The stream is null. - /// The stream is not readable. + /// The stream is not readable or the image format is not supported. /// Image format not recognised. /// Image contains invalid content. /// A new . @@ -763,7 +762,7 @@ namespace SixLabors.ImageSharp } // To make sure we don't trigger anything with aspnetcore then we just need to make sure we are - // seekable and we make the copy using CopyToAsync if the stream is seekable then we arn't using + // seekable and we make the copy using CopyToAsync if the stream is seekable then we aren't using // one of the aspnetcore wrapped streams that error on sync api calls and we can use it without // having to further wrap if (stream.CanSeek) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 2d265e22c..2a18a2c10 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg byte[] bytes = TestFile.Create(TestImages.Jpeg.Progressive.Progress).Bytes; using var ms = new MemoryStream(bytes); using var bufferedStream = new BufferedReadStream(Configuration.Default, ms); - var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder()); + using var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder()); using Image image = decoder.Decode(bufferedStream, cancellationToken: default); // I don't know why these numbers are different. All I know is that the decoder works @@ -174,6 +174,19 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg await Assert.ThrowsAsync(async () => await Image.IdentifyAsync(config, "someFakeFile", cts.Token)); } + [Theory] + [WithFile(TestImages.Jpeg.Baseline.ArithmeticCoding, PixelTypes.Rgba32)] + [WithFile(TestImages.Jpeg.Baseline.ArithmeticCodingProgressive, PixelTypes.Rgba32)] + [WithFile(TestImages.Jpeg.Baseline.Lossless, PixelTypes.Rgba32)] + public void ThrowsNotSupported_WithUnsupportedJpegs(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + Assert.Throws(() => + { + using Image image = provider.GetImage(JpegDecoder); + }); + } + // https://github.com/SixLabors/ImageSharp/pull/1732 [Theory] [WithFile(TestImages.Jpeg.Issues.WrongColorSpace, PixelTypes.Rgba32)] diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index feff08b94..8763c3cad 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -204,6 +204,9 @@ namespace SixLabors.ImageSharp.Tests public const string App13WithEmptyIptc = "Jpg/baseline/iptc-psAPP13-wIPTCempty.jpg"; public const string HistogramEqImage = "Jpg/baseline/640px-Unequalized_Hawkes_Bay_NZ.jpg"; public const string ForestBridgeDifferentComponentsQuality = "Jpg/baseline/forest_bridge.jpg"; + public const string ArithmeticCoding = "Jpg/baseline/arithmetic_coding.jpg"; + public const string ArithmeticCodingProgressive = "Jpg/progressive/arithmetic_progressive.jpg"; + public const string Lossless = "Jpg/baseline/lossless.jpg"; public static readonly string[] All = { diff --git a/tests/Images/Input/Jpg/baseline/arithmetic_coding.jpg b/tests/Images/Input/Jpg/baseline/arithmetic_coding.jpg new file mode 100644 index 000000000..3f57b7d7a --- /dev/null +++ b/tests/Images/Input/Jpg/baseline/arithmetic_coding.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fec7012d9ae52a12c4617fd7526e506feee812fc67e923a76b2ca88c95f7a538 +size 3111 diff --git a/tests/Images/Input/Jpg/baseline/lossless.jpg b/tests/Images/Input/Jpg/baseline/lossless.jpg new file mode 100644 index 000000000..37091b73c --- /dev/null +++ b/tests/Images/Input/Jpg/baseline/lossless.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8937e245885e1f280e1843ad48a4349ec1a3f71f86c954229cd44160aeeaaac4 +size 209584 diff --git a/tests/Images/Input/Jpg/progressive/arithmetic_progressive.jpg b/tests/Images/Input/Jpg/progressive/arithmetic_progressive.jpg new file mode 100644 index 000000000..06b3b684e --- /dev/null +++ b/tests/Images/Input/Jpg/progressive/arithmetic_progressive.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3af237c172248d39c7b82c879de3d162e4dafaf36dc298add210740843edd33f +size 3129