mirror of https://github.com/SixLabors/ImageSharp
2 changed files with 370 additions and 372 deletions
@ -1,221 +1,221 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
// Copyright (c) Six Labors and contributors.
|
||||
// Licensed under the Apache License, Version 2.0.
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
using System; |
using System; |
||||
using System.Collections.Concurrent; |
using System.Collections.Concurrent; |
||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using System.Linq; |
using System.Linq; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using SixLabors.ImageSharp.Formats; |
using SixLabors.ImageSharp.Formats; |
||||
using SixLabors.ImageSharp.Formats.Bmp; |
using SixLabors.ImageSharp.Formats.Bmp; |
||||
using SixLabors.ImageSharp.Formats.Gif; |
using SixLabors.ImageSharp.Formats.Gif; |
||||
using SixLabors.ImageSharp.Formats.Jpeg; |
using SixLabors.ImageSharp.Formats.Jpeg; |
||||
using SixLabors.ImageSharp.Formats.Png; |
using SixLabors.ImageSharp.Formats.Png; |
||||
using SixLabors.ImageSharp.IO; |
using SixLabors.ImageSharp.IO; |
||||
using SixLabors.ImageSharp.Memory; |
using SixLabors.ImageSharp.Memory; |
||||
|
|
||||
namespace SixLabors.ImageSharp |
namespace SixLabors.ImageSharp |
||||
{ |
{ |
||||
/// <summary>
|
/// <summary>
|
||||
/// Provides initialization code which allows extending the library.
|
/// Provides initialization code which allows extending the library.
|
||||
/// </summary>
|
/// </summary>
|
||||
public sealed class Configuration |
public sealed class Configuration |
||||
{ |
{ |
||||
/// <summary>
|
/// <summary>
|
||||
/// A lazily initialized configuration default instance.
|
/// A lazily initialized configuration default instance.
|
||||
/// </summary>
|
/// </summary>
|
||||
private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(CreateDefaultInstance); |
private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(CreateDefaultInstance); |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Configuration" /> class.
|
/// Initializes a new instance of the <see cref="Configuration" /> class.
|
||||
/// </summary>
|
/// </summary>
|
||||
public Configuration() |
public Configuration() |
||||
{ |
{ |
||||
} |
} |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Configuration" /> class.
|
/// Initializes a new instance of the <see cref="Configuration" /> class.
|
||||
/// </summary>
|
/// </summary>
|
||||
/// <param name="configurationModules">A collection of configuration modules to register</param>
|
/// <param name="configurationModules">A collection of configuration modules to register</param>
|
||||
public Configuration(params IConfigurationModule[] configurationModules) |
public Configuration(params IConfigurationModule[] configurationModules) |
||||
{ |
{ |
||||
if (configurationModules != null) |
if (configurationModules != null) |
||||
{ |
{ |
||||
foreach (IConfigurationModule p in configurationModules) |
foreach (IConfigurationModule p in configurationModules) |
||||
{ |
{ |
||||
p.Configure(this); |
p.Configure(this); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Gets the default <see cref="Configuration"/> instance.
|
/// Gets the default <see cref="Configuration"/> instance.
|
||||
/// </summary>
|
/// </summary>
|
||||
public static Configuration Default { get; } = Lazy.Value; |
public static Configuration Default { get; } = Lazy.Value; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Gets the global parallel options for processing tasks in parallel.
|
/// Gets the global parallel options for processing tasks in parallel.
|
||||
/// </summary>
|
/// </summary>
|
||||
public ParallelOptions ParallelOptions { get; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }; |
public ParallelOptions ParallelOptions { get; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Gets the currently registered <see cref="IImageFormat"/>s.
|
/// Gets the currently registered <see cref="IImageFormat"/>s.
|
||||
/// </summary>
|
/// </summary>
|
||||
public IEnumerable<IImageFormat> ImageFormats => this.FormatsManager.ImageFormats; |
public IEnumerable<IImageFormat> ImageFormats => this.FormatsManager.ImageFormats; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Gets or sets the <see cref="ImageFormatsManager"/> that is currently in use.
|
/// Gets or sets the <see cref="ImageFormatsManager"/> that is currently in use.
|
||||
/// </summary>
|
/// </summary>
|
||||
public ImageFormatsManager FormatsManager { get; set; } = new ImageFormatsManager(); |
public ImageFormatsManager FormatsManager { get; set; } = new ImageFormatsManager(); |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Gets or sets the <see cref="MemoryManager"/> that is currently in use.
|
/// Gets or sets the <see cref="MemoryManager"/> that is currently in use.
|
||||
/// </summary>
|
/// </summary>
|
||||
public MemoryManager MemoryManager { get; set; } = ArrayPoolMemoryManager.CreateDefault(); |
public MemoryManager MemoryManager { get; set; } = ArrayPoolMemoryManager.CreateDefault(); |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Gets the maximum header size of all the formats.
|
/// Gets the maximum header size of all the formats.
|
||||
/// </summary>
|
/// </summary>
|
||||
internal int MaxHeaderSize => this.FormatsManager.MaxHeaderSize; |
internal int MaxHeaderSize => this.FormatsManager.MaxHeaderSize; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Gets the currently registered <see cref="IImageFormatDetector"/>s.
|
/// Gets the currently registered <see cref="IImageFormatDetector"/>s.
|
||||
/// </summary>
|
/// </summary>
|
||||
internal IEnumerable<IImageFormatDetector> FormatDetectors => this.FormatsManager.FormatDetectors; |
internal IEnumerable<IImageFormatDetector> FormatDetectors => this.FormatsManager.FormatDetectors; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Gets the currently registered <see cref="IImageDecoder"/>s.
|
/// Gets the currently registered <see cref="IImageDecoder"/>s.
|
||||
/// </summary>
|
/// </summary>
|
||||
internal IEnumerable<KeyValuePair<IImageFormat, IImageDecoder>> ImageDecoders => this.FormatsManager.ImageDecoders; |
internal IEnumerable<KeyValuePair<IImageFormat, IImageDecoder>> ImageDecoders => this.FormatsManager.ImageDecoders; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Gets the currently registered <see cref="IImageEncoder"/>s.
|
/// Gets the currently registered <see cref="IImageEncoder"/>s.
|
||||
/// </summary>
|
/// </summary>
|
||||
internal IEnumerable<KeyValuePair<IImageFormat, IImageEncoder>> ImageEncoders => this.FormatsManager.ImageEncoders; |
internal IEnumerable<KeyValuePair<IImageFormat, IImageEncoder>> ImageEncoders => this.FormatsManager.ImageEncoders; |
||||
|
|
||||
#if !NETSTANDARD1_1
|
#if !NETSTANDARD1_1
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Gets or sets the filesystem helper for accessing the local file system.
|
/// Gets or sets the filesystem helper for accessing the local file system.
|
||||
/// </summary>
|
/// </summary>
|
||||
internal IFileSystem FileSystem { get; set; } = new LocalFileSystem(); |
internal IFileSystem FileSystem { get; set; } = new LocalFileSystem(); |
||||
#endif
|
#endif
|
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Gets or sets the image operations provider factory.
|
/// Gets or sets the image operations provider factory.
|
||||
/// </summary>
|
/// </summary>
|
||||
internal IImageProcessingContextFactory ImageOperationsProvider { get; set; } = new DefaultImageOperationsProviderFactory(); |
internal IImageProcessingContextFactory ImageOperationsProvider { get; set; } = new DefaultImageOperationsProviderFactory(); |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Registers a new format provider.
|
/// Registers a new format provider.
|
||||
/// </summary>
|
/// </summary>
|
||||
/// <param name="configuration">The configuration provider to call configure on.</param>
|
/// <param name="configuration">The configuration provider to call configure on.</param>
|
||||
public void Configure(IConfigurationModule configuration) |
public void Configure(IConfigurationModule configuration) |
||||
{ |
{ |
||||
Guard.NotNull(configuration, nameof(configuration)); |
Guard.NotNull(configuration, nameof(configuration)); |
||||
configuration.Configure(this); |
configuration.Configure(this); |
||||
} |
} |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Registers a new format provider.
|
/// Registers a new format provider.
|
||||
/// </summary>
|
/// </summary>
|
||||
/// <param name="format">The format to register as a known format.</param>
|
/// <param name="format">The format to register as a known format.</param>
|
||||
public void AddImageFormat(IImageFormat format) |
public void AddImageFormat(IImageFormat format) |
||||
|
{ |
||||
|
this.FormatsManager.AddImageFormat(format); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// For the specified file extensions type find the e <see cref="IImageFormat"/>.
|
||||
|
/// </summary>
|
||||
|
/// <param name="extension">The extension to discover</param>
|
||||
|
/// <returns>The <see cref="IImageFormat"/> if found otherwise null</returns>
|
||||
|
public IImageFormat FindFormatByFileExtension(string extension) |
||||
|
{ |
||||
|
return this.FormatsManager.FindFormatByFileExtension(extension); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// For the specified mime type find the <see cref="IImageFormat"/>.
|
||||
|
/// </summary>
|
||||
|
/// <param name="mimeType">The mime-type to discover</param>
|
||||
|
/// <returns>The <see cref="IImageFormat"/> if found; otherwise null</returns>
|
||||
|
public IImageFormat FindFormatByMimeType(string mimeType) |
||||
|
{ |
||||
|
return this.FormatsManager.FindFormatByMimeType(mimeType); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Sets a specific image encoder as the encoder for a specific image format.
|
||||
|
/// </summary>
|
||||
|
/// <param name="imageFormat">The image format to register the encoder for.</param>
|
||||
|
/// <param name="encoder">The encoder to use,</param>
|
||||
|
public void SetEncoder(IImageFormat imageFormat, IImageEncoder encoder) |
||||
|
{ |
||||
|
this.FormatsManager.SetEncoder(imageFormat, encoder); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Sets a specific image decoder as the decoder for a specific image format.
|
||||
|
/// </summary>
|
||||
|
/// <param name="imageFormat">The image format to register the encoder for.</param>
|
||||
|
/// <param name="decoder">The decoder to use,</param>
|
||||
|
public void SetDecoder(IImageFormat imageFormat, IImageDecoder decoder) |
||||
|
{ |
||||
|
this.FormatsManager.SetDecoder(imageFormat, decoder); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Removes all the registered image format detectors.
|
||||
|
/// </summary>
|
||||
|
public void ClearImageFormatDetectors() |
||||
|
{ |
||||
|
this.FormatsManager.ClearImageFormatDetectors(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Adds a new detector for detecting mime types.
|
||||
|
/// </summary>
|
||||
|
/// <param name="detector">The detector to add</param>
|
||||
|
public void AddImageFormatDetector(IImageFormatDetector detector) |
||||
|
{ |
||||
|
this.FormatsManager.AddImageFormatDetector(detector); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// For the specified mime type find the decoder.
|
||||
|
/// </summary>
|
||||
|
/// <param name="format">The format to discover</param>
|
||||
|
/// <returns>The <see cref="IImageDecoder"/> if found otherwise null</returns>
|
||||
|
public IImageDecoder FindDecoder(IImageFormat format) |
||||
|
{ |
||||
|
return this.FormatsManager.FindDecoder(format); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// For the specified mime type find the encoder.
|
||||
|
/// </summary>
|
||||
|
/// <param name="format">The format to discover</param>
|
||||
|
/// <returns>The <see cref="IImageEncoder"/> if found otherwise null</returns>
|
||||
|
public IImageEncoder FindEncoder(IImageFormat format) |
||||
|
{ |
||||
|
return this.FormatsManager.FindEncoder(format); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Creates the default instance with the following <see cref="IConfigurationModule"/>s preregistered:
|
||||
|
/// <para><see cref="PngConfigurationModule"/></para>
|
||||
|
/// <para><see cref="JpegConfigurationModule"/></para>
|
||||
|
/// <para><see cref="GifConfigurationModule"/></para>
|
||||
|
/// <para><see cref="BmpConfigurationModule"/></para>
|
||||
|
/// </summary>
|
||||
|
/// <returns>The default configuration of <see cref="Configuration"/></returns>
|
||||
|
internal static Configuration CreateDefaultInstance() |
||||
{ |
{ |
||||
this.FormatsManager.AddImageFormat(format); |
return new Configuration( |
||||
} |
new PngConfigurationModule(), |
||||
|
new JpegConfigurationModule(), |
||||
/// <summary>
|
new GifConfigurationModule(), |
||||
/// For the specified file extensions type find the e <see cref="IImageFormat"/>.
|
new BmpConfigurationModule()); |
||||
/// </summary>
|
|
||||
/// <param name="extension">The extension to discover</param>
|
|
||||
/// <returns>The <see cref="IImageFormat"/> if found otherwise null</returns>
|
|
||||
public IImageFormat FindFormatByFileExtension(string extension) |
|
||||
{ |
|
||||
return this.FormatsManager.FindFormatByFileExtension(extension); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// For the specified mime type find the <see cref="IImageFormat"/>.
|
|
||||
/// </summary>
|
|
||||
/// <param name="mimeType">The mime-type to discover</param>
|
|
||||
/// <returns>The <see cref="IImageFormat"/> if found; otherwise null</returns>
|
|
||||
public IImageFormat FindFormatByMimeType(string mimeType) |
|
||||
{ |
|
||||
return this.FormatsManager.FindFormatByMimeType(mimeType); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Sets a specific image encoder as the encoder for a specific image format.
|
|
||||
/// </summary>
|
|
||||
/// <param name="imageFormat">The image format to register the encoder for.</param>
|
|
||||
/// <param name="encoder">The encoder to use,</param>
|
|
||||
public void SetEncoder(IImageFormat imageFormat, IImageEncoder encoder) |
|
||||
{ |
|
||||
this.FormatsManager.SetEncoder(imageFormat, encoder); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Sets a specific image decoder as the decoder for a specific image format.
|
|
||||
/// </summary>
|
|
||||
/// <param name="imageFormat">The image format to register the encoder for.</param>
|
|
||||
/// <param name="decoder">The decoder to use,</param>
|
|
||||
public void SetDecoder(IImageFormat imageFormat, IImageDecoder decoder) |
|
||||
{ |
|
||||
this.FormatsManager.SetDecoder(imageFormat, decoder); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Removes all the registered image format detectors.
|
|
||||
/// </summary>
|
|
||||
public void ClearImageFormatDetectors() |
|
||||
{ |
|
||||
this.FormatsManager.ClearImageFormatDetectors(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Adds a new detector for detecting mime types.
|
|
||||
/// </summary>
|
|
||||
/// <param name="detector">The detector to add</param>
|
|
||||
public void AddImageFormatDetector(IImageFormatDetector detector) |
|
||||
{ |
|
||||
this.FormatsManager.AddImageFormatDetector(detector); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// For the specified mime type find the decoder.
|
|
||||
/// </summary>
|
|
||||
/// <param name="format">The format to discover</param>
|
|
||||
/// <returns>The <see cref="IImageDecoder"/> if found otherwise null</returns>
|
|
||||
public IImageDecoder FindDecoder(IImageFormat format) |
|
||||
{ |
|
||||
return this.FormatsManager.FindDecoder(format); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// For the specified mime type find the encoder.
|
|
||||
/// </summary>
|
|
||||
/// <param name="format">The format to discover</param>
|
|
||||
/// <returns>The <see cref="IImageEncoder"/> if found otherwise null</returns>
|
|
||||
public IImageEncoder FindEncoder(IImageFormat format) |
|
||||
{ |
|
||||
return this.FormatsManager.FindEncoder(format); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Creates the default instance with the following <see cref="IConfigurationModule"/>s preregistered:
|
|
||||
/// <para><see cref="PngConfigurationModule"/></para>
|
|
||||
/// <para><see cref="JpegConfigurationModule"/></para>
|
|
||||
/// <para><see cref="GifConfigurationModule"/></para>
|
|
||||
/// <para><see cref="BmpConfigurationModule"/></para>
|
|
||||
/// </summary>
|
|
||||
/// <returns>The default configuration of <see cref="Configuration"/></returns>
|
|
||||
internal static Configuration CreateDefaultInstance() |
|
||||
{ |
|
||||
return new Configuration( |
|
||||
new PngConfigurationModule(), |
|
||||
new JpegConfigurationModule(), |
|
||||
new GifConfigurationModule(), |
|
||||
new BmpConfigurationModule()); |
|
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue