From dd571d936962cddc08c1a620fbcb42531fc61999 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 13 Dec 2019 23:01:32 +1100 Subject: [PATCH] Revert non-generic decode to use RGba32 and add comments --- src/ImageSharp/Formats/IImageDecoder.cs | 7 ++--- src/ImageSharp/Formats/Jpeg/JpegDecoder.cs | 9 +----- .../Formats/Jpeg/JpegDecoderCore.cs | 16 ---------- src/ImageSharp/Image.FromBytes.cs | 30 +++++++++---------- src/ImageSharp/Image.FromFile.cs | 22 +++++++------- src/ImageSharp/Image.FromStream.cs | 6 ++-- 6 files changed, 33 insertions(+), 57 deletions(-) diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs index 8dafdac79..b69ed8453 100644 --- a/src/ImageSharp/Formats/IImageDecoder.cs +++ b/src/ImageSharp/Formats/IImageDecoder.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.IO; @@ -17,17 +17,16 @@ namespace SixLabors.ImageSharp.Formats /// The pixel format. /// The configuration for the image. /// The containing image data. - /// The decoded image of a given pixel type. + /// The . Image Decode(Configuration configuration, Stream stream) where TPixel : struct, IPixel; /// /// Decodes the image from the specified stream to an . - /// The decoder is free to choose the pixel type. /// /// The configuration for the image. /// The containing image data. - /// The decoded image of a pixel type chosen by the decoder. + /// The in pixel format. Image Decode(Configuration configuration, Stream stream); } } diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs index 63276babd..4e1c0c1be 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs @@ -30,14 +30,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg /// public Image Decode(Configuration configuration, Stream stream) - { - Guard.NotNull(stream, nameof(stream)); - - using (var decoder = new JpegDecoderCore(configuration, this)) - { - return decoder.Decode(stream); - } - } + => this.Decode(configuration, stream); /// public IImageInfo Identify(Configuration configuration, Stream stream) diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 193983cd0..60709ed00 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -204,22 +204,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg return new JpegFileMarker(marker[1], stream.Position - 2, true); } - /// - /// Decodes the image from the specified and sets the data to image. - /// - /// The stream, where the image should be. - /// The decoded image. - public Image Decode(Stream stream) - { - this.ParseStream(stream); - this.InitExifProfile(); - this.InitIccProfile(); - this.InitDerivedMetadataProperties(); - return this.ColorSpace == JpegColorSpace.Grayscale - ? (Image)this.PostProcessIntoImage() - : this.PostProcessIntoImage(); - } - /// /// Decodes the image from the specified and sets the data to image. /// diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs index 465139b2e..294a86b35 100644 --- a/src/ImageSharp/Image.FromBytes.cs +++ b/src/ImageSharp/Image.FromBytes.cs @@ -270,7 +270,7 @@ namespace SixLabors.ImageSharp /// /// The byte array containing image data. /// The detected format. - /// A new . + /// The in pixel format. public static Image Load(byte[] data, out IImageFormat format) => Load(Configuration.Default, data, out format); @@ -279,24 +279,24 @@ namespace SixLabors.ImageSharp /// /// The byte array containing encoded image data. /// The decoder. - /// A new . + /// The in pixel format. public static Image Load(byte[] data, IImageDecoder decoder) => Load(Configuration.Default, data, decoder); /// - /// Load a new instance of from the given encoded byte array. + /// Load a new instance of from the given encoded byte array. /// /// The config for the decoder. /// The byte array containing encoded image data. - /// A new . + /// The in pixel format. public static Image Load(Configuration config, byte[] data) => Load(config, data, out _); /// - /// Load a new instance of from the given encoded byte array. + /// Load a new instance of from the given encoded byte array. /// /// The config for the decoder. /// The byte array containing image data. /// The decoder. - /// A new . + /// The in pixel format. public static Image Load(Configuration config, byte[] data, IImageDecoder decoder) { using (var stream = new MemoryStream(data)) @@ -306,12 +306,12 @@ namespace SixLabors.ImageSharp } /// - /// Load a new instance of from the given encoded byte array. + /// Load a new instance of from the given encoded byte array. /// /// The config for the decoder. /// The byte array containing image data. /// The mime type of the decoded image. - /// A new . + /// The in pixel format. public static Image Load(Configuration config, byte[] data, out IImageFormat format) { using (var stream = new MemoryStream(data)) @@ -321,10 +321,10 @@ namespace SixLabors.ImageSharp } /// - /// Load a new instance of from the given encoded byte span. + /// Load a new instance of from the given encoded byte span. /// /// The byte span containing image data. - /// A new . + /// The in pixel format. public static Image Load(ReadOnlySpan data) => Load(Configuration.Default, data); /// @@ -332,7 +332,7 @@ namespace SixLabors.ImageSharp /// /// The byte span containing image data. /// The decoder. - /// A new . + /// The in pixel format. public static Image Load(ReadOnlySpan data, IImageDecoder decoder) => Load(Configuration.Default, data, decoder); @@ -341,7 +341,7 @@ namespace SixLabors.ImageSharp /// /// The byte span containing image data. /// The detected format. - /// A new . + /// The in pixel format. public static Image Load(ReadOnlySpan data, out IImageFormat format) => Load(Configuration.Default, data, out format); @@ -350,7 +350,7 @@ namespace SixLabors.ImageSharp /// /// The configuration options. /// The byte span containing image data. - /// A new . + /// The in pixel format. public static Image Load(Configuration config, ReadOnlySpan data) => Load(config, data, out _); /// @@ -359,7 +359,7 @@ namespace SixLabors.ImageSharp /// The Configuration. /// The byte span containing image data. /// The decoder. - /// A new . + /// The in pixel format. public static unsafe Image Load( Configuration config, ReadOnlySpan data, @@ -380,7 +380,7 @@ namespace SixLabors.ImageSharp /// The configuration options. /// The byte span containing image data. /// The of the decoded image.> - /// A new . + /// The in pixel format. public static unsafe Image Load( Configuration config, ReadOnlySpan data, diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index 08ed381c5..4423d800a 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -39,17 +39,17 @@ namespace SixLabors.ImageSharp } /// - /// Create a new instance of the class from the given file. + /// Create a new instance of the class from the given file. /// /// The file path to the image. /// /// Thrown if the stream is not readable nor seekable. /// - /// A new . + /// The in pixel format. public static Image Load(string path) => Load(Configuration.Default, path); /// - /// Create a new instance of the class from the given file. + /// Create a new instance of the class from the given file. /// /// The file path to the image. /// The mime type of the decoded image. @@ -60,18 +60,18 @@ namespace SixLabors.ImageSharp public static Image Load(string path, out IImageFormat format) => Load(Configuration.Default, path, out format); /// - /// Create a new instance of the class from the given file. + /// Create a new instance of the class from the given file. /// /// The config for the decoder. /// The file path to the image. /// /// Thrown if the stream is not readable nor seekable. /// - /// A new . + /// The in pixel format. public static Image Load(Configuration config, string path) => Load(config, path, out _); /// - /// Create a new instance of the class from the given file. + /// Create a new instance of the class from the given file. /// /// The Configuration. /// The file path to the image. @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp /// /// Thrown if the stream is not readable nor seekable. /// - /// A new . + /// The in pixel format. public static Image Load(Configuration config, string path, IImageDecoder decoder) { using (Stream stream = config.FileSystem.OpenRead(path)) @@ -89,14 +89,14 @@ namespace SixLabors.ImageSharp } /// - /// Create a new instance of the class from the given file. + /// Create a new instance of the class from the given file. /// /// The file path to the image. /// The decoder. /// /// Thrown if the stream is not readable nor seekable. /// - /// A new . + /// The in pixel format. public static Image Load(string path, IImageDecoder decoder) => Load(Configuration.Default, path, decoder); /// @@ -224,4 +224,4 @@ namespace SixLabors.ImageSharp } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs index 60db45f21..c88072546 100644 --- a/src/ImageSharp/Image.FromStream.cs +++ b/src/ImageSharp/Image.FromStream.cs @@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp /// The format type of the decoded image. /// Thrown if the stream is not readable. /// Image cannot be loaded. - /// A new .> + /// The in pixel format. public static Image Load(Stream stream, out IImageFormat format) => Load(Configuration.Default, stream, out format); /// @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp /// The stream containing image information. /// Thrown if the stream is not readable. /// Image cannot be loaded. - /// A new .> + /// The in pixel format. public static Image Load(Stream stream) => Load(Configuration.Default, stream); /// @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp /// The decoder. /// Thrown if the stream is not readable. /// Image cannot be loaded. - /// A new .> + /// The in pixel format. public static Image Load(Stream stream, IImageDecoder decoder) => Load(Configuration.Default, stream, decoder); ///