Browse Source

Various comment fixes and some variable renames.

pull/254/head
Dirk Lemstra 9 years ago
parent
commit
6d4e4f2f23
  1. 72
      src/ImageSharp/Configuration.cs
  2. 4
      src/ImageSharp/Formats/Bmp/BmpConstants.cs
  3. 2
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
  4. 2
      src/ImageSharp/Formats/Bmp/BmpImageFormatProvider.cs
  5. 4
      src/ImageSharp/Formats/Gif/GifConstants.cs
  6. 2
      src/ImageSharp/Formats/Gif/GifEncoder.cs
  7. 4
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  8. 2
      src/ImageSharp/Formats/Gif/GifImageFormatProvider.cs
  9. 24
      src/ImageSharp/Formats/IImageFormatProvider.cs
  10. 4
      src/ImageSharp/Formats/Jpeg/JpegConstants.cs
  11. 2
      src/ImageSharp/Formats/Jpeg/JpegImageFormatProvider.cs
  12. 6
      src/ImageSharp/Formats/Png/PngConstants.cs
  13. 20
      src/ImageSharp/Formats/Png/PngEncoder.cs
  14. 2
      src/ImageSharp/Formats/Png/PngImageFormatProvider.cs
  15. 2
      src/ImageSharp/Image/Image.Decode.cs
  16. 36
      src/ImageSharp/Image/Image.FromBytes.cs
  17. 28
      src/ImageSharp/Image/Image.FromFile.cs
  18. 16
      src/ImageSharp/Image/Image.FromStream.cs
  19. 4
      src/ImageSharp/Image/Image{TPixel}.cs

72
src/ImageSharp/Configuration.cs

@ -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()
{

4
src/ImageSharp/Formats/Bmp/BmpConstants.cs

@ -13,12 +13,12 @@ namespace ImageSharp.Formats
internal static class BmpConstants
{
/// <summary>
/// The list of mimetypes that equate to a bmp
/// The list of mimetypes that equate to a bmp.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/bmp", "image/x-windows-bmp" };
/// <summary>
/// The list of file extensions that equate to a bmp
/// The list of file extensions that equate to a bmp.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "bm", "bmp", "dip" };
}

2
src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

@ -30,7 +30,7 @@ namespace ImageSharp.Formats
}
/// <summary>
/// Gets or sets the BitsPerPixel
/// Gets or sets the number of bits per pixel.
/// </summary>
public BmpBitsPerPixel BitsPerPixel { get; internal set; } = BmpBitsPerPixel.Pixel24;

2
src/ImageSharp/Formats/Bmp/BmpImageFormatProvider.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Formats
using ImageSharp.PixelFormats;
/// <summary>
/// Detects gif file headers
/// Registers the image encoders, decoders and mime type detectors for the bmp format.
/// </summary>
public class BmpImageFormatProvider : IImageFormatProvider
{

4
src/ImageSharp/Formats/Gif/GifConstants.cs

@ -94,12 +94,12 @@ namespace ImageSharp.Formats
public static readonly Encoding DefaultEncoding = Encoding.GetEncoding("ASCII");
/// <summary>
/// The list of mimetypes that equate to a bmp
/// The list of mimetypes that equate to a gif.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/gif" };
/// <summary>
/// The list of file extensions that equate to a bmp
/// The list of file extensions that equate to a gif.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "gif" };
}

2
src/ImageSharp/Formats/Gif/GifEncoder.cs

@ -33,7 +33,7 @@ namespace ImageSharp.Formats
public Encoding TextEncoding { get; set; } = GifConstants.DefaultEncoding;
/// <summary>
/// Gets or sets the size of the color palette to use. For gifs the value ranges from 1 to 256. Leave as zero for default size.
/// Gets or sets the size of the color palette to use. For gifs the value ranges from 1 to 256. Leave as zero for default size.
/// </summary>
public int PaletteSize { get; set; } = 0;

4
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -60,7 +60,7 @@ namespace ImageSharp.Formats
public byte Threshold { get; internal set; }
/// <summary>
/// Gets or sets the quality of output for images.
/// Gets or sets the size of the color palette to use.
/// </summary>
public int PaletteSize { get; internal set; }
@ -91,7 +91,7 @@ namespace ImageSharp.Formats
// Do not use IDisposable pattern here as we want to preserve the stream.
var writer = new EndianBinaryWriter(Endianness.LittleEndian, stream);
// Ensure that quality can be set but has a fallback.
// Ensure that pallete size can be set but has a fallback.
int paletteSize = this.PaletteSize;
paletteSize = paletteSize > 0 ? paletteSize.Clamp(1, 256) : 256;

2
src/ImageSharp/Formats/Gif/GifImageFormatProvider.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Formats
using ImageSharp.PixelFormats;
/// <summary>
/// Detects gif file headers
/// Registers the image encoders, decoders and mime type detectors for the gif format.
/// </summary>
public class GifImageFormatProvider : IImageFormatProvider
{

24
src/ImageSharp/Formats/IImageFormatProvider.cs

@ -10,47 +10,47 @@ namespace ImageSharp.Formats
using System.Text;
/// <summary>
/// Represents an abstract class that can register image encoders, decoders and mime type detectors
/// Represents an interface that can register image encoders, decoders and mime type detectors.
/// </summary>
public interface IImageFormatProvider
{
/// <summary>
/// Called when loaded so the provider and register its encoders, decodes and mime type detectors into an IImageFormatHost.
/// Called when loaded so the provider and register its encoders, decoders and mime type detectors into an IImageFormatHost.
/// </summary>
/// <param name="host">The host that will retain the encoders, decodes and mime type detectors.</param>
void Configure(IImageFormatHost host);
}
/// <summary>
/// Represents an abstract class that can have encoders decoders and mimetype detecotrs loaded into.
/// Represents an interface that can have encoders, decoders and mime type detectors loaded into.
/// </summary>
public interface IImageFormatHost
{
/// <summary>
/// Sets a specific image encoder as the encoder for a specific mimetype
/// Sets a specific image encoder as the encoder for a specific mime type.
/// </summary>
/// <param name="mimeType">the target mimetype</param>
/// <param name="encoder">the encoder to use</param>
void SetMimeTypeEncoder(string mimeType, IImageEncoder encoder); // could/should this be an Action<IImageEncoder>???
/// <summary>
/// Sets a mapping value between a file extension and a mimetype
/// Sets a mapping value between a file extension and a mime type.
/// </summary>
/// <param name="extension">the target mimetype</param>
/// <param name="mimetype">the mimetype this extenion equates to</param>
/// <param name="extension">The target mime type</param>
/// <param name="mimetype">The mime type this extension equates to</param>
void SetFileExtensionToMimeTypeMapping(string extension, string mimetype);
/// <summary>
/// Sets a specific image decoder as the decoder for a specific mimetype
/// Sets a specific image decoder as the decoder for a specific mime type.
/// </summary>
/// <param name="mimeType">the target mimetype</param>
/// <param name="decoder">the decoder to use</param>
/// <param name="mimeType">The target mime type</param>
/// <param name="decoder">The decoder to use</param>
void SetMimeTypeDecoder(string mimeType, IImageDecoder decoder);
/// <summary>
/// Adds a new detector for detecting in mime types
/// Adds a new detector for detecting mime types.
/// </summary>
/// <param name="detector">The detector</param>
/// <param name="detector">The detector to add</param>
void AddMimeTypeDetector(IMimeTypeDetector detector);
}
}

4
src/ImageSharp/Formats/Jpeg/JpegConstants.cs

@ -18,12 +18,12 @@ namespace ImageSharp.Formats
public const ushort MaxLength = 65535;
/// <summary>
/// The list of mimetypes that equate to a jpeg
/// The list of mimetypes that equate to a jpeg.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/jpeg", "image/pjpeg" };
/// <summary>
/// The list of file extensions that equate to a jpeg
/// The list of file extensions that equate to a jpeg.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "jpg", "jpeg", "jfif" };

2
src/ImageSharp/Formats/Jpeg/JpegImageFormatProvider.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Formats
using ImageSharp.PixelFormats;
/// <summary>
/// Detects png file headers
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
/// </summary>
public class JpegImageFormatProvider : IImageFormatProvider
{

6
src/ImageSharp/Formats/Png/PngConstants.cs

@ -13,17 +13,17 @@ namespace ImageSharp.Formats
internal static class PngConstants
{
/// <summary>
/// The default encoding for text metadata
/// The default encoding for text metadata.
/// </summary>
public static readonly Encoding DefaultEncoding = Encoding.GetEncoding("ASCII");
/// <summary>
/// The list of mimetypes that equate to a jpeg
/// The list of mimetypes that equate to a png.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/png" };
/// <summary>
/// The list of file extensions that equate to a jpeg
/// The list of file extensions that equate to a png.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "png" };
}

20
src/ImageSharp/Formats/Png/PngEncoder.cs

@ -70,19 +70,19 @@ namespace ImageSharp.Formats
public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
using (var encode = new PngEncoderCore())
using (var encoder = new PngEncoderCore())
{
encode.IgnoreMetadata = this.IgnoreMetadata;
encoder.IgnoreMetadata = this.IgnoreMetadata;
encode.PaletteSize = this.PaletteSize > 0 ? this.PaletteSize.Clamp(1, int.MaxValue) : int.MaxValue;
encode.PngColorType = this.PngColorType;
encode.CompressionLevel = this.CompressionLevel;
encode.Gamma = this.Gamma;
encode.Quantizer = this.Quantizer;
encode.Threshold = this.Threshold;
encode.WriteGamma = this.WriteGamma;
encoder.PaletteSize = this.PaletteSize > 0 ? this.PaletteSize.Clamp(1, int.MaxValue) : int.MaxValue;
encoder.PngColorType = this.PngColorType;
encoder.CompressionLevel = this.CompressionLevel;
encoder.Gamma = this.Gamma;
encoder.Quantizer = this.Quantizer;
encoder.Threshold = this.Threshold;
encoder.WriteGamma = this.WriteGamma;
encode.Encode(image, stream);
encoder.Encode(image, stream);
}
}
}

2
src/ImageSharp/Formats/Png/PngImageFormatProvider.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Formats
using ImageSharp.PixelFormats;
/// <summary>
/// Detects png file headers
/// Registers the image encoders, decoders and mime type detectors for the png format.
/// </summary>
public class PngImageFormatProvider : IImageFormatProvider
{

2
src/ImageSharp/Image/Image.Decode.cs

@ -22,7 +22,7 @@ namespace ImageSharp
/// </summary>
/// <param name="stream">The image stream to read the header from.</param>
/// <param name="config">The configuration.</param>
/// <returns>The mimetype or null if none found.</returns>
/// <returns>The mime type or null if none found.</returns>
private static string InternalDiscoverMimeType(Stream stream, Configuration config)
{
// This is probably a candidate for making into a public API in the future!

36
src/ImageSharp/Image/Image.FromBytes.cs

@ -16,21 +16,21 @@ namespace ImageSharp
public static partial class Image
{
/// <summary>
/// By reading the header on the provided byte array this calculates the images mimetype.
/// By reading the header on the provided byte array this calculates the images mime type.
/// </summary>
/// <param name="data">The byte array containing image data to read the header from.</param>
/// <returns>The mimetype or null if none found.</returns>
/// <returns>The mime type or null if none found.</returns>
public static string DiscoverMimeType(byte[] data)
{
return DiscoverMimeType(null, data);
}
/// <summary>
/// By reading the header on the provided byte array this calculates the images mimetype.
/// By reading the header on the provided byte array this calculates the images mime type.
/// </summary>
/// <param name="config">The configuration.</param>
/// <param name="data">The byte array containing image data to read the header from.</param>
/// <returns>The mimetype or null if none found.</returns>
/// <returns>The mime type or null if none found.</returns>
public static string DiscoverMimeType(Configuration config, byte[] data)
{
using (Stream stream = new MemoryStream(data))
@ -50,12 +50,12 @@ namespace ImageSharp
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given byte array.
/// </summary>
/// <param name="data">The byte array containing image data.</param>
/// <param name="mimeType">the mime type of the decoded image.</param>
/// <param name="mimeType">The mime type of the decoded image.</param>
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(byte[] data, out string mimeType) => Load<Rgba32>(null, data, out mimeType);
/// <summary>
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given byte array.
/// </summary>
/// <param name="config">The config for the decoder.</param>
/// <param name="data">The byte array containing image data.</param>
@ -63,11 +63,11 @@ namespace ImageSharp
public static Image<Rgba32> Load(Configuration config, byte[] data) => Load<Rgba32>(config, data);
/// <summary>
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given byte array.
/// </summary>
/// <param name="config">The config for the decoder.</param>
/// <param name="data">The byte array containing image data.</param>
/// <param name="mimeType">the mime type of the decoded image.</param>
/// <param name="mimeType">The mime type of the decoded image.</param>
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(Configuration config, byte[] data, out string mimeType) => Load<Rgba32>(config, data, out mimeType);
@ -104,7 +104,7 @@ namespace ImageSharp
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// </summary>
/// <param name="data">The byte array containing image data.</param>
/// <param name="mimeType">the mime type of the decoded image.</param>
/// <param name="mimeType">The mime type of the decoded image.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(byte[] data, out string mimeType)
@ -123,9 +123,9 @@ namespace ImageSharp
public static Image<TPixel> Load<TPixel>(Configuration config, byte[] data)
where TPixel : struct, IPixel<TPixel>
{
using (MemoryStream ms = new MemoryStream(data))
using (var memoryStream = new MemoryStream(data))
{
return Load<TPixel>(config, ms);
return Load<TPixel>(config, memoryStream);
}
}
@ -134,15 +134,15 @@ namespace ImageSharp
/// </summary>
/// <param name="config">The configuration options.</param>
/// <param name="data">The byte array containing image data.</param>
/// <param name="mimeType">the mime type of the decoded image.</param>
/// <param name="mimeType">The mime type of the decoded image.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(Configuration config, byte[] data, out string mimeType)
where TPixel : struct, IPixel<TPixel>
{
using (MemoryStream ms = new MemoryStream(data))
using (var memoryStream = new MemoryStream(data))
{
return Load<TPixel>(config, ms, out mimeType);
return Load<TPixel>(config, memoryStream, out mimeType);
}
}
@ -156,9 +156,9 @@ namespace ImageSharp
public static Image<TPixel> Load<TPixel>(byte[] data, IImageDecoder decoder)
where TPixel : struct, IPixel<TPixel>
{
using (var ms = new MemoryStream(data))
using (var memoryStream = new MemoryStream(data))
{
return Load<TPixel>(ms, decoder);
return Load<TPixel>(memoryStream, decoder);
}
}
@ -173,9 +173,9 @@ namespace ImageSharp
public static Image<TPixel> Load<TPixel>(Configuration config, byte[] data, IImageDecoder decoder)
where TPixel : struct, IPixel<TPixel>
{
using (var ms = new MemoryStream(data))
using (var memoryStream = new MemoryStream(data))
{
return Load<TPixel>(config, ms, decoder);
return Load<TPixel>(config, memoryStream, decoder);
}
}
}

28
src/ImageSharp/Image/Image.FromFile.cs

@ -17,21 +17,21 @@ namespace ImageSharp
public static partial class Image
{
/// <summary>
/// By reading the header on the provided file this calculates the images mimetype.
/// By reading the header on the provided file this calculates the images mime type.
/// </summary>
/// <param name="filePath">The image file to open and to read the header from.</param>
/// <returns>The mimetype or null if none found.</returns>
/// <returns>The mime type or null if none found.</returns>
public static string DiscoverMimeType(string filePath)
{
return DiscoverMimeType(null, filePath);
}
/// <summary>
/// By reading the header on the provided file this calculates the images mimetype.
/// By reading the header on the provided file this calculates the images mime type.
/// </summary>
/// <param name="config">The configuration.</param>
/// <param name="filePath">The image file to open and to read the header from.</param>
/// <returns>The mimetype or null if none found.</returns>
/// <returns>The mime type or null if none found.</returns>
public static string DiscoverMimeType(Configuration config, string filePath)
{
config = config ?? Configuration.Default;
@ -55,7 +55,7 @@ namespace ImageSharp
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// </summary>
/// <param name="path">The file path to the image.</param>
/// <param name="mimeType">the mime type of the decoded image.</param>
/// <param name="mimeType">The mime type of the decoded image.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
@ -78,7 +78,7 @@ namespace ImageSharp
/// </summary>
/// <param name="config">The config for the decoder.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="mimeType">the mime type of the decoded image.</param>
/// <param name="mimeType">The mime type of the decoded image.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
@ -127,7 +127,7 @@ namespace ImageSharp
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
/// </summary>
/// <param name="path">The file path to the image.</param>
/// <param name="mimeType">the mime type of the decoded image.</param>
/// <param name="mimeType">The mime type of the decoded image.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
@ -153,9 +153,9 @@ namespace ImageSharp
where TPixel : struct, IPixel<TPixel>
{
config = config ?? Configuration.Default;
using (Stream s = config.FileSystem.OpenRead(path))
using (Stream stream = config.FileSystem.OpenRead(path))
{
return Load<TPixel>(config, s);
return Load<TPixel>(config, stream);
}
}
@ -164,7 +164,7 @@ namespace ImageSharp
/// </summary>
/// <param name="config">The configuration options.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="mimeType">the mime type of the decoded image.</param>
/// <param name="mimeType">The mime type of the decoded image.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
@ -174,9 +174,9 @@ namespace ImageSharp
where TPixel : struct, IPixel<TPixel>
{
config = config ?? Configuration.Default;
using (Stream s = config.FileSystem.OpenRead(path))
using (Stream stream = config.FileSystem.OpenRead(path))
{
return Load<TPixel>(config, s, out mimeType);
return Load<TPixel>(config, stream, out mimeType);
}
}
@ -211,9 +211,9 @@ namespace ImageSharp
where TPixel : struct, IPixel<TPixel>
{
config = config ?? Configuration.Default;
using (Stream s = config.FileSystem.OpenRead(path))
using (Stream stream = config.FileSystem.OpenRead(path))
{
return Load<TPixel>(config, s, decoder);
return Load<TPixel>(config, stream, decoder);
}
}
}

16
src/ImageSharp/Image/Image.FromStream.cs

@ -20,21 +20,21 @@ namespace ImageSharp
public static partial class Image
{
/// <summary>
/// By reading the header on the provided stream this calculates the images mimetype.
/// By reading the header on the provided stream this calculates the images mime type.
/// </summary>
/// <param name="stream">The image stream to read the header from.</param>
/// <returns>The mimetype or null if none found.</returns>
/// <returns>The mime type or null if none found.</returns>
public static string DiscoverMimeType(Stream stream)
{
return DiscoverMimeType(null, stream);
}
/// <summary>
/// By reading the header on the provided stream this calculates the images mimetype.
/// By reading the header on the provided stream this calculates the images mime type.
/// </summary>
/// <param name="config">The configuration.</param>
/// <param name="stream">The image stream to read the header from.</param>
/// <returns>The mimetype or null if none found.</returns>
/// <returns>The mime type or null if none found.</returns>
public static string DiscoverMimeType(Configuration config, Stream stream)
{
return WithSeekableStream(stream, s => InternalDiscoverMimeType(s, config ?? Configuration.Default));
@ -224,12 +224,12 @@ namespace ImageSharp
}
// We want to be able to load images from things like HttpContext.Request.Body
using (var ms = new MemoryStream())
using (var memoryStream = new MemoryStream())
{
stream.CopyTo(ms);
ms.Position = 0;
stream.CopyTo(memoryStream);
memoryStream.Position = 0;
return action(ms);
return action(memoryStream);
}
}
}

4
src/ImageSharp/Image/Image{TPixel}.cs

@ -214,7 +214,7 @@ namespace ImageSharp
string mime = this.Configuration.FindFileExtensionsMimeType(ext);
if (mime == null)
{
stringBuilder.AppendLine($"Can't find a mime type for the file extention '{ext}'. Registerd File extension maps include:");
stringBuilder.AppendLine($"Can't find a mime type for the file extention '{ext}'. Registered file extension maps include:");
foreach (KeyValuePair<string, string> map in this.Configuration.ImageExtensionToMimeTypeMapping)
{
stringBuilder.AppendLine($" - {map.Key} : {map.Value}");
@ -222,7 +222,7 @@ namespace ImageSharp
}
else
{
stringBuilder.AppendLine($"Can't find encoder for file extention '{ext}' using mime type '{mime}'. Registerd encoders include:");
stringBuilder.AppendLine($"Can't find encoder for file extention '{ext}' using mime type '{mime}'. Registered encoders include:");
foreach (KeyValuePair<string, IImageEncoder> enc in this.Configuration.ImageEncoders)
{
stringBuilder.AppendLine($" - {enc.Key} : {enc.Value.GetType().Name}");

Loading…
Cancel
Save