From 59a84498d50a17f3c9fa3349027435608c334528 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 17 Aug 2021 11:18:18 +0200 Subject: [PATCH 1/5] Throw NotSupportedException for arithmetic coding and lossless jpeg's --- src/ImageSharp/Formats/Jpeg/JpegConstants.cs | 45 +++++++++++++++++++ .../Formats/Jpeg/JpegDecoderCore.cs | 18 ++++++++ .../Formats/Jpeg/JpegThrowHelper.cs | 7 +++ .../Formats/Jpg/JpegDecoderTests.cs | 15 ++++++- tests/ImageSharp.Tests/TestImages.cs | 3 ++ .../Input/Jpg/baseline/arithmetic_coding.jpg | 3 ++ .../Jpg/baseline/arithmetic_progressive.jpg | 3 ++ tests/Images/Input/Jpg/baseline/lossless.jpg | 3 ++ 8 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/Images/Input/Jpg/baseline/arithmetic_coding.jpg create mode 100644 tests/Images/Input/Jpg/baseline/arithmetic_progressive.jpg create mode 100644 tests/Images/Input/Jpg/baseline/lossless.jpg diff --git a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs index 8cc6ee81af..98c4025991 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs @@ -133,6 +133,11 @@ internal static class Markers /// public const byte APP15 = 0xEF; + /// + /// Define arithmetic coding conditioning marker. + /// + public const byte DAC = 0xCC; + /// /// The text comment marker /// @@ -173,6 +178,46 @@ internal static class Markers /// public const byte SOF2 = 0xC2; + /// + /// Start of Frame marker, non differential lossless, Huffman coding. + /// + public const byte SOF3 = 0xC3; + + /// + /// 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 e94b07faae..3810dd19c6 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -247,6 +247,20 @@ internal void ParseStream(BufferedReadStream stream, HuffmanScanDecoder scanDeco this.ProcessStartOfFrameMarker(stream, remaining, fileMarker, metadataOnly); 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) { @@ -326,6 +340,10 @@ internal void ParseStream(BufferedReadStream stream, HuffmanScanDecoder scanDeco 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 1b5362275d..b6c7e76268 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/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index e8d307f909..6b1ce19e49 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -74,7 +74,7 @@ public void ParseStream_BasicPropertiesAreCorrect() 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 @@ public async Task Identify_IsCancellable() 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 1e12bb66ab..85c007c89f 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -200,6 +200,9 @@ public static class Bad 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/baseline/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 0000000000..3f57b7d7a7 --- /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/arithmetic_progressive.jpg b/tests/Images/Input/Jpg/baseline/arithmetic_progressive.jpg new file mode 100644 index 0000000000..06b3b684eb --- /dev/null +++ b/tests/Images/Input/Jpg/baseline/arithmetic_progressive.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3af237c172248d39c7b82c879de3d162e4dafaf36dc298add210740843edd33f +size 3129 diff --git a/tests/Images/Input/Jpg/baseline/lossless.jpg b/tests/Images/Input/Jpg/baseline/lossless.jpg new file mode 100644 index 0000000000..37091b73c2 --- /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 From 1ab518518113a0cad46592e2f7b3103f550eb947 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 17 Aug 2021 12:38:08 +0200 Subject: [PATCH 2/5] Add NotSupportedException to the Image.Load overload documentation --- src/ImageSharp/Image.FromBytes.cs | 28 +++++++++++++++++++++++----- src/ImageSharp/Image.FromFile.cs | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs index a33a345a0f..789a936879 100644 --- a/src/ImageSharp/Image.FromBytes.cs +++ b/src/ImageSharp/Image.FromBytes.cs @@ -102,6 +102,7 @@ public static Image Load(byte[] data) /// 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 @@ public static Image Load(byte[] data) /// 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 @@ public static Image Load(byte[] data, out IImageFormat format) /// 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 @@ public static Image Load(Configuration configuration, byte[] dat /// 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 @@ public static Image Load(Configuration configuration, byte[] dat /// 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 @@ public static Image Load(byte[] data, IImageDecoder decoder) /// 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 @@ public static Image Load(Configuration configuration, byte[] dat /// /// 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 @@ public static IImageFormat DetectFormat(Configuration configuration, ReadOnlySpa /// 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 @@ public static Image Load(ReadOnlySpan data) /// 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 @@ public static Image Load(ReadOnlySpan data, out IImageForm /// 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 @@ public static Image Load(ReadOnlySpan data, IImageDecoder /// 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 @@ public static unsafe Image Load(Configuration configuration, Rea /// 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 @@ public static unsafe Image Load( /// 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 @@ public static unsafe Image Load( /// 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 @@ public static Image Load(byte[] data, out IImageFormat format) /// 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 @@ public static Image Load(byte[] data, IImageDecoder decoder) /// 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 @@ public static Image Load(Configuration configuration, byte[] data) /// 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 @@ public static Image Load(Configuration configuration, byte[] data, IImageDecoder /// 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 @@ public static Image Load(Configuration configuration, byte[] data, out IImageFor /// 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 @@ public static Image Load(ReadOnlySpan data) /// 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 @@ public static Image Load(ReadOnlySpan data, IImageDecoder decoder) /// 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 @@ public static Image Load(Configuration configuration, ReadOnlySpan data) /// 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 @@ public static unsafe Image Load( /// 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 bf239c3e9f..3a4b459c54 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -182,6 +182,7 @@ public static Image Load(string path, out IImageFormat format) /// 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 @@ public static Image Load(Configuration configuration, string path) /// 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 @@ public static async Task LoadAsync( /// 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 @@ public static Image Load(Configuration configuration, string path, IImageDecoder /// 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 @@ public static Task LoadAsync(string path, CancellationToken cancellationT /// 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 @@ public static Task LoadAsync(string path, IImageDecoder decoder) /// 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 @@ public static Task> LoadAsync(string path, IImageDecoder d /// 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 @@ public static Task LoadAsync( /// 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 @@ public static Task> LoadAsync( /// 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 @@ public static Task> LoadAsync(string path) /// 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 @@ public static async Task> LoadAsync( /// 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 @@ public static Image Load(string path, IImageDecoder decoder) /// 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 @@ public static Image Load(string path) /// 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 @@ public static Image Load(string path, out IImageFormat format) /// 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 @@ public static Image Load(Configuration configuration, string pat /// 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 @@ public static Image Load(Configuration configuration, string pat /// 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 @@ public static Image Load(Configuration configuration, string path, out IImageFor /// 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 @@ public static Image Load(string path, IImageDecoder decoder) /// 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 . From 27cbafecd69d1ffc57f74e933b23b83c9db6f349 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 17 Aug 2021 12:59:40 +0200 Subject: [PATCH 3/5] Add SOF5 and SOF6 to the unsupported jpeg markers --- src/ImageSharp/Formats/Jpeg/JpegConstants.cs | 10 ++++++++++ src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs index 98c4025991..89c4de5500 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs @@ -183,6 +183,16 @@ internal static class Markers /// 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. /// diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 3810dd19c6..96520c535c 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -247,6 +247,14 @@ internal void ParseStream(BufferedReadStream stream, HuffmanScanDecoder scanDeco 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."); From 10b05571fa36267681274c9e88de84dbd7074844 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 17 Aug 2021 13:02:43 +0200 Subject: [PATCH 4/5] Move arithmetic_progressive.jpg to progressive folder --- tests/ImageSharp.Tests/TestImages.cs | 2 +- .../Jpg/{baseline => progressive}/arithmetic_progressive.jpg | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/Images/Input/Jpg/{baseline => progressive}/arithmetic_progressive.jpg (100%) diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 85c007c89f..8252b52587 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -201,7 +201,7 @@ public static class Bad 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/baseline/arithmetic_progressive.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_progressive.jpg b/tests/Images/Input/Jpg/progressive/arithmetic_progressive.jpg similarity index 100% rename from tests/Images/Input/Jpg/baseline/arithmetic_progressive.jpg rename to tests/Images/Input/Jpg/progressive/arithmetic_progressive.jpg From 1000dfbd8ddf0572545f0375bae091ce055796a5 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 17 Aug 2021 18:12:55 +0200 Subject: [PATCH 5/5] Add NotSupportedException to the Image.Load FromStream overload documentation --- src/ImageSharp/Image.FromStream.cs | 51 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs index b57fa9a6ca..3dde8e77bc 100644 --- a/src/ImageSharp/Image.FromStream.cs +++ b/src/ImageSharp/Image.FromStream.cs @@ -9,7 +9,6 @@ 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 @@ public static IImageInfo Identify(Configuration configuration, Stream stream, ou /// 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 @@ public static Image Load(Stream stream, out IImageFormat format) /// /// 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 @@ public static Image Load(Stream stream, out IImageFormat format) /// /// 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 @@ public static Image Load(Stream stream, out IImageFormat format) /// /// 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 @@ public static Image Load(Stream stream, out IImageFormat format) /// 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 @@ public static Image Load(Stream stream, IImageDecoder decoder) /// 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 @@ public static Task LoadAsync(Stream stream, IImageDecoder decoder) /// 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 @@ public static Image Load(Configuration configuration, Stream stream, IImageDecod /// 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 @@ public static Task LoadAsync( /// 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 @@ public static Task LoadAsync( /// 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 @@ public static async Task LoadAsync(Configuration configuration, Stream st /// /// 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 @@ public static Image Load(Stream stream) /// /// 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 @@ public static Task> LoadAsync(Stream stream) /// 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 @@ public static Image Load(Stream stream, out IImageFormat format) /// /// 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 @@ public static Image Load(Stream stream, out IImageFormat format) /// 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 @@ public static Image Load(Stream stream, IImageDecoder decoder) /// 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 @@ public static Task> LoadAsync(Stream stream, IImageDecoder /// 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 @@ public static Image Load(Configuration configuration, Stream str /// 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 @@ public static Task> LoadAsync( /// 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 @@ public static Image Load(Configuration configuration, Stream str /// 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 @@ public static Image Load(Configuration configuration, Stream str /// 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 @@ public static Image Load(Configuration configuration, Stream str /// 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 @@ await WithSeekableStreamAsync( /// 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 @@ public static async Task> LoadAsync( /// 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 @@ private static async Task WithSeekableStreamAsync( } // 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)