Replies: 5 comments 26 replies
-
|
In combination with #2090 it would be closer to 65 'removed' APIs |
Beta Was this translation helpful? Give feedback.
-
|
Maybe we should use struct/record class to ensure passed options are immutable from outside? IMO |
Beta Was this translation helpful? Give feedback.
-
|
Shouldn't we just implement the old methods on top of Edit: + class DecoderOptions {
+ // common options
+ }
+
+ class GifDecoderOptions : DecoderOptions {
+ public FrameDecodingMode DecodingMode { get; set; }
+ }
- interface IGifDecoderOptions { FrameDecodingMode DecodingMode { get; set; } }
+ interface IImageDecoder {
+ Image Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
+ }
class GifDecoder :
- IGifDecoderOptions,
IImageDecoder
{
- Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken);
+ Image Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken);
} |
Beta Was this translation helpful? Give feedback.
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
Completed in v3 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The proposal is to add a new
DecoderOptionstype that can be passed along to compatible decoders.The idea is that decoder options will provider generic high level options that can be utilised by all decoders and can have a reasonable fallback to support decoders that do not have native support for the target feature.
First 2 options should be fairly obvious they provide a way for explicitly defining the decoder and explicitly defining the
Configurationwithout having overload explosion on the loading apis.The
TargetSizesize property allow for supporting decoders to use that to decode into the target size with us providing a check and applying a final mutate if the decoder returns an image on the wrong size (upscaled size provided or just not supported etc).. decoders will be able to use this more of a hint than a target requirement but Image.Load will force the size before returning to the user.SkipMetadata: allow for supporting decoders to totally skip metadata blocks but if the decoder does not support metadata skipping then we will null out all relevant parts of the metadata object before returning the image to the user.MaxFrames: hints to the decoder that it can stop decoding frames after this point... additonal returns frames will auto be removed in anycase.namespace SixLabors.ImageSharp { public sealed partial class Image { public static Image<TPixel> Load<TPixel>(byte[] data) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, byte[] data) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(byte[] data, IImageDecoder decoder) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, byte[] data, IImageDecoder decoder) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> Load<TPixel>(byte[] data, DecoderOptions options) where TPixel : managed, IPixel<TPixel> public static Image<TPixel> Load<TPixel>(byte[] data, out IImageFormat format) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, byte[] data, out IImageFormat format) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> Load<TPixel>(byte[] data, DecoderOptions options, out IImageFormat format) where TPixel : managed, IPixel<TPixel> public static Image<TPixel> Load<TPixel>(ReadOnlySpan<byte> data) where TPixel : managed, IPixel<TPixel> public static Image<TPixel> Load<TPixel>(ReadOnlySpan<byte> data, out IImageFormat format) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, ReadOnlySpan<byte> data, out IImageFormat format) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> Load<TPixel>(ReadOnlySpan<byte> data, DecoderOptions options, out IImageFormat format) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(ReadOnlySpan<byte> data, IImageDecoder decoder) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, ReadOnlySpan<byte> data) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, ReadOnlySpan<byte> data, IImageDecoder decoder) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> Load<TPixel>(ReadOnlySpan<byte> data, DecoderOptions options) where TPixel : managed, IPixel<TPixel> public static Image Load(byte[] data) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(byte[] data, IImageDecoder decoder) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, byte[] data) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, byte[] data, IImageDecoder decoder) + public static Image Load(byte[] data, DecoderOptions options) public static Image Load(byte[] data, out IImageFormat format) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, byte[] data, out IImageFormat format) + public static Image Load(byte[] data, DecoderOptions options, out IImageFormat format) public static Image Load(ReadOnlySpan<byte> data) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(ReadOnlySpan<byte> data, IImageDecoder decoder) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, ReadOnlySpan<byte> data) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, ReadOnlySpan<byte> data, IImageDecoder decoder) + public static Image Load(ReadOnlySpan<byte> data, DecoderOptions options) public static Image Load(ReadOnlySpan<byte> data, out IImageFormat format) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, ReadOnlySpan<byte> data, out IImageFormat format) + public static Image Load(ReadOnlySpan<byte> data, DecoderOptions options, out IImageFormat format) public static Image Load(string path) public static Image Load(string path, out IImageFormat format) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, string path, out IImageFormat format) + public static Image Load(string path, DecoderOptions options, out IImageFormat format) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, string path) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, string path, IImageDecoder decoder) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(string path, IImageDecoder decoder) + public static Image Load(string path, DecoderOptions options) public static Image<TPixel> Load<TPixel>(string path) where TPixel : managed, IPixel<TPixel> public static Image<TPixel> Load<TPixel>(string path, out IImageFormat format) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, string path, out IImageFormat format) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> Load<TPixel>(string path, DecoderOptions optionsh, out IImageFormat format) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, string path) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(string path, IImageDecoder decoder) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, string path, IImageDecoder decoder) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> Load<TPixel>(string path, DecoderOptions options) where TPixel : managed, IPixel<TPixel> public static Image Load(Stream stream, out IImageFormat format) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, Stream stream, out IImageFormat format) + public static Image Load(Stream stream, DecoderOptions options out IImageFormat format) public static Image Load(Stream stream) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Stream stream, IImageDecoder decoder) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, Stream stream, IImageDecoder decoder) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image Load(Configuration configuration, Stream stream) + public static Image Load(Stream stream, DecoderOptions options) public static Image<TPixel> Load<TPixel>(Stream stream) where TPixel : managed, IPixel<TPixel> public static Image<TPixel> Load<TPixel>(Stream stream, out IImageFormat format) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Stream stream, IImageDecoder decoder) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, Stream stream, IImageDecoder decoder) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, Stream stream) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> Load<TPixel>(Stream stream, DecoderOptions options) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> Load<TPixel>(Configuration configuration, Stream stream, out IImageFormat format) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> Load<TPixel>(Stream stream, DecoderOptions options, out IImageFormat format) where TPixel : managed, IPixel<TPixel> public static Task<Image> LoadAsync(string path, CancellationToken cancellationToken = default) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image> LoadAsync(Configuration configuration, string path, CancellationToken cancellationToken = default) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image> LoadAsync(string path, IImageDecoder decoder, CancellationToken cancellationToken = default) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image> LoadAsync(Configuration configuration, string path, IImageDecoder decoder, CancellationToken cancellationToken = default) + public static Task<Image> LoadAsync(string path, DecoderOptions options, CancellationToken cancellationToken = default) public static Task<Image> LoadAsync(Stream stream, CancellationToken cancellationToken = default) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image> LoadAsync(Stream stream, IImageDecoder decoder, CancellationToken cancellationToken = default) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image> LoadAsync(Configuration configuration, Stream stream, IImageDecoder decoder, CancellationToken cancellationToken = default) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image> LoadAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken = default) + public static Task<Image> LoadAsync(Stream stream, DecoderOptions options, CancellationToken cancellationToken = default) public static Task<Image<TPixel>> LoadAsync<TPixel>(string path, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image<TPixel>> LoadAsync<TPixel>(string path, IImageDecoder decoder, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image<TPixel>> LoadAsync<TPixel>(Configuration configuration, string path, IImageDecoder decoder, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image<TPixel>> LoadAsync<TPixel>(Configuration configuration, string path, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> + public static Task<Image<TPixel>> LoadAsync<TPixel>(string path, DecoderOptions options, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> public static Task<Image<TPixel>> LoadAsync<TPixel>(Stream stream, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image<TPixel>> LoadAsync<TPixel>(Stream stream, IImageDecoder decoder, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image<TPixel>> LoadAsync<TPixel>(Configuration configuration, Stream stream, IImageDecoder decoder, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<Image<TPixel>> LoadAsync<TPixel>(Configuration configuration, Stream stream, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> + public static Task<Image<TPixel>> LoadAsync<TPixel>(Stream stream, DecoderOptions options, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> public static Image<TPixel> LoadPixelData<TPixel>(TPixel[] data, int width, int height) where TPixel : managed, IPixel<TPixel> public static Image<TPixel> LoadPixelData<TPixel>(ReadOnlySpan<TPixel> data, int width, int height) where TPixel : managed, IPixel<TPixel> public static Image<TPixel> LoadPixelData<TPixel>(byte[] data, int width, int height) where TPixel : managed, IPixel<TPixel> public static Image<TPixel> LoadPixelData<TPixel>(ReadOnlySpan<byte> data, int width, int height) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> LoadPixelData<TPixel>(Configuration configuration, byte[] data, int width, int height) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> LoadPixelData<TPixel>(Configuration configuration, ReadOnlySpan<byte> data, int width, int height) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> LoadPixelData<TPixel>(Configuration configuration, TPixel[] data, int width, int height) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Image<TPixel> LoadPixelData<TPixel>(Configuration configuration, ReadOnlySpan<TPixel> data, int width, int height) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> LoadPixelData<TPixel>(byte[] data, int width, int height, DecoderOptions options) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> LoadPixelData<TPixel>(ReadOnlySpan<byte> data, int width, int height, DecoderOptions options) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> LoadPixelData<TPixel>(TPixel[] data, int width, int height, DecoderOptions options) where TPixel : managed, IPixel<TPixel> + public static Image<TPixel> LoadPixelData<TPixel>(ReadOnlySpan<TPixel> data, int width, int height, DecoderOptions options) where TPixel : managed, IPixel<TPixel> public static Task<(Image, IImageFormat)> LoadWithFormatAsync(Stream stream, CancellationToken cancellationToken = default) public static Task<(Image<TPixel>, IImageFormat)> LoadWithFormatAsync<TPixel>(Stream stream, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<(Image, IImageFormat)> LoadWithFormatAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken = default) + public static Task<(Image, IImageFormat)> LoadWithFormatAsync( Stream stream, DecoderOptions options, CancellationToken cancellationToken = default) + [Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)] public static Task<(Image<TPixel>, IImageFormat)> LoadWithFormatAsync<TPixel>(Configuration configuration, Stream stream, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> + public static Task<(Image<TPixel>, IImageFormat)> LoadWithFormatAsync<TPixel>( Stream stream, DecoderOptions options, CancellationToken cancellationToken = default) where TPixel : managed, IPixel<TPixel> } }This will drastically reduce our api surface area (this removed 50 apis and add 26 new ones), and provides a class that can be used to add addition loading functionality without adding new API surface just a new field to
DecoderOptionsIt might be worth trying to get this added for / before #2076 so it doesn't add lots of new Size APIs.
We can retain backwards compat by not actually deleting these APIs yet and instead appling
[Obsolete("Format accessible from Metadata.OriginalImageFormat"),EditorBrowsable(EditorBrowsableState.Never)]and moving them to a new file for obsolete apis. WE can then remove them in a major or 2.Beta Was this translation helpful? Give feedback.
All reactions