|
|
|
@ -31,17 +31,17 @@ namespace ImageSharp |
|
|
|
private readonly object syncRoot = new object(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The list of supported <see cref="IImageEncoder"/> keyed to mimestypes.
|
|
|
|
/// The list of supported <see cref="IImageEncoder"/> keyed to mime types.
|
|
|
|
/// </summary>
|
|
|
|
private readonly ConcurrentDictionary<string, IImageEncoder> mimeTypeEncoders = new ConcurrentDictionary<string, IImageEncoder>(StringComparer.OrdinalIgnoreCase); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The list of supported <see cref="IImageEncoder"/> keyed to fiel extensions.
|
|
|
|
/// The list of supported mime types keyed to file extensions.
|
|
|
|
/// </summary>
|
|
|
|
private readonly ConcurrentDictionary<string, string> extensionsMap = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The list of supported <see cref="IImageEncoder"/> keyed to mimestypes.
|
|
|
|
/// The list of supported <see cref="IImageEncoder"/> keyed to mime types.
|
|
|
|
/// </summary>
|
|
|
|
private readonly ConcurrentDictionary<string, IImageDecoder> mimeTypeDecoders = new ConcurrentDictionary<string, IImageDecoder>(StringComparer.OrdinalIgnoreCase); |
|
|
|
|
|
|
|
@ -83,27 +83,27 @@ namespace ImageSharp |
|
|
|
public ParallelOptions ParallelOptions { get; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the maximum header size of all formats.
|
|
|
|
/// Gets the maximum header size of all the formats.
|
|
|
|
/// </summary>
|
|
|
|
internal int MaxHeaderSize { get; private set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the currently registerd <see cref="IMimeTypeDetector"/>s.
|
|
|
|
/// Gets the currently registered <see cref="IMimeTypeDetector"/>s.
|
|
|
|
/// </summary>
|
|
|
|
internal IEnumerable<IMimeTypeDetector> MimeTypeDetectors => this.mimeTypeDetectors; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the typeof of all the current image decoders
|
|
|
|
/// Gets the currently registered <see cref="IImageDecoder"/>s.
|
|
|
|
/// </summary>
|
|
|
|
internal IEnumerable<KeyValuePair<string, IImageDecoder>> ImageDecoders => this.mimeTypeDecoders; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the typeof of all the current image decoders
|
|
|
|
/// Gets the currently registered <see cref="IImageEncoder"/>s.
|
|
|
|
/// </summary>
|
|
|
|
internal IEnumerable<KeyValuePair<string, IImageEncoder>> ImageEncoders => this.mimeTypeEncoders; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the typeof of all the current image decoders
|
|
|
|
/// Gets the currently registered file extensions.
|
|
|
|
/// </summary>
|
|
|
|
internal IEnumerable<KeyValuePair<string, string>> ImageExtensionToMimeTypeMapping => this.extensionsMap; |
|
|
|
|
|
|
|
@ -133,11 +133,11 @@ namespace ImageSharp |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public void SetFileExtensionToMimeTypeMapping(string extension, string mimetype) |
|
|
|
public void SetFileExtensionToMimeTypeMapping(string extension, string mimeType) |
|
|
|
{ |
|
|
|
Guard.NotNullOrEmpty(extension, nameof(extension)); |
|
|
|
Guard.NotNullOrEmpty(mimetype, nameof(mimetype)); |
|
|
|
this.extensionsMap.AddOrUpdate(extension?.Trim(), mimetype, (s, e) => mimetype); |
|
|
|
Guard.NotNullOrEmpty(mimeType, nameof(mimeType)); |
|
|
|
this.extensionsMap.AddOrUpdate(extension?.Trim(), mimeType, (s, e) => mimeType); |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
@ -149,7 +149,7 @@ namespace ImageSharp |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Removes all the registerd detectors
|
|
|
|
/// Removes all the registered mime type detectors.
|
|
|
|
/// </summary>
|
|
|
|
public void ClearMimeTypeDetectors() |
|
|
|
{ |
|
|
|
@ -165,9 +165,13 @@ namespace ImageSharp |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates the default instance, with Png, Jpeg, Gif and Bmp preregisterd (if they have been referenced)
|
|
|
|
/// Creates the default instance with the following <see cref="IImageFormatProvider"/>s preregistered:
|
|
|
|
/// <para><see cref="PngImageFormatProvider"/></para>
|
|
|
|
/// <para><see cref="JpegImageFormatProvider"/></para>
|
|
|
|
/// <para><see cref="GifImageFormatProvider"/></para>
|
|
|
|
/// <para><see cref="BmpImageFormatProvider"/></para>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The default configuration of <see cref="Configuration"/> </returns>
|
|
|
|
/// <returns>The default configuration of <see cref="Configuration"/></returns>
|
|
|
|
internal static Configuration CreateDefaultInstance() |
|
|
|
{ |
|
|
|
return new Configuration( |
|
|
|
@ -178,73 +182,73 @@ namespace ImageSharp |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// For the specified mimetype find the decoder.
|
|
|
|
/// For the specified mime type find the decoder.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="mimeType">the mimetype to discover</param>
|
|
|
|
/// <returns>the IImageDecoder if found othersize null </returns>
|
|
|
|
/// <param name="mimeType">The mime type to discover</param>
|
|
|
|
/// <returns>The <see cref="IImageDecoder"/> if found otherwise null</returns>
|
|
|
|
internal IImageDecoder FindMimeTypeDecoder(string mimeType) |
|
|
|
{ |
|
|
|
Guard.NotNullOrEmpty(mimeType, nameof(mimeType)); |
|
|
|
if (this.mimeTypeDecoders.TryGetValue(mimeType, out IImageDecoder dec)) |
|
|
|
if (this.mimeTypeDecoders.TryGetValue(mimeType, out IImageDecoder decoder)) |
|
|
|
{ |
|
|
|
return dec; |
|
|
|
return decoder; |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// For the specified mimetype find the encoder.
|
|
|
|
/// For the specified mime type find the encoder.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="mimeType">the mimetype to discover</param>
|
|
|
|
/// <returns>the IImageEncoder if found othersize null </returns>
|
|
|
|
/// <param name="mimeType">The mime type to discover</param>
|
|
|
|
/// <returns>The <see cref="IImageEncoder"/> if found otherwise null</returns>
|
|
|
|
internal IImageEncoder FindMimeTypeEncoder(string mimeType) |
|
|
|
{ |
|
|
|
Guard.NotNullOrEmpty(mimeType, nameof(mimeType)); |
|
|
|
if (this.mimeTypeEncoders.TryGetValue(mimeType, out IImageEncoder dec)) |
|
|
|
if (this.mimeTypeEncoders.TryGetValue(mimeType, out IImageEncoder encoder)) |
|
|
|
{ |
|
|
|
return dec; |
|
|
|
return encoder; |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// For the specified mimetype find the encoder.
|
|
|
|
/// For the specified mime type find the encoder.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="extensions">the extensions to discover</param>
|
|
|
|
/// <returns>the IImageEncoder if found othersize null </returns>
|
|
|
|
/// <param name="extensions">The extensions to discover</param>
|
|
|
|
/// <returns>The <see cref="IImageEncoder"/> if found otherwise null</returns>
|
|
|
|
internal IImageEncoder FindFileExtensionsEncoder(string extensions) |
|
|
|
{ |
|
|
|
extensions = extensions?.TrimStart('.'); |
|
|
|
Guard.NotNullOrEmpty(extensions, nameof(extensions)); |
|
|
|
if (this.extensionsMap.TryGetValue(extensions, out string mime)) |
|
|
|
if (this.extensionsMap.TryGetValue(extensions, out string mimeType)) |
|
|
|
{ |
|
|
|
return this.FindMimeTypeEncoder(mime); |
|
|
|
return this.FindMimeTypeEncoder(mimeType); |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// For the specified mimetype find the encoder.
|
|
|
|
/// For the specified extension find the mime type.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="extensions">the extensions to discover</param>
|
|
|
|
/// <returns>the IImageEncoder if found othersize null </returns>
|
|
|
|
/// <returns>The mime type if found otherwise null</returns>
|
|
|
|
internal string FindFileExtensionsMimeType(string extensions) |
|
|
|
{ |
|
|
|
extensions = extensions?.TrimStart('.'); |
|
|
|
Guard.NotNullOrEmpty(extensions, nameof(extensions)); |
|
|
|
if (this.extensionsMap.TryGetValue(extensions, out string mime)) |
|
|
|
if (this.extensionsMap.TryGetValue(extensions, out string mimeType)) |
|
|
|
{ |
|
|
|
return mime; |
|
|
|
return mimeType; |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets max header size.
|
|
|
|
/// Sets the max header size.
|
|
|
|
/// </summary>
|
|
|
|
private void SetMaxHeaderSize() |
|
|
|
{ |
|
|
|
|