Browse Source

Moved various properties from the encoder/decoder to the image format.

af/merge-core
Dirk Lemstra 10 years ago
parent
commit
7914848786
  1. 18
      src/ImageSharp/Formats/Bmp/BmpDecoder.cs
  2. 23
      src/ImageSharp/Formats/Bmp/BmpEncoder.cs
  3. 11
      src/ImageSharp/Formats/Bmp/BmpFormat.cs
  4. 16
      src/ImageSharp/Formats/Gif/GifDecoder.cs
  5. 15
      src/ImageSharp/Formats/Gif/GifEncoder.cs
  6. 11
      src/ImageSharp/Formats/Gif/GifFormat.cs
  7. 10
      src/ImageSharp/Formats/IImageDecoder.cs
  8. 25
      src/ImageSharp/Formats/IImageEncoder.cs
  9. 20
      src/ImageSharp/Formats/IImageFormat.cs
  10. 27
      src/ImageSharp/Formats/Jpg/JpegDecoder.cs
  11. 21
      src/ImageSharp/Formats/Jpg/JpegEncoder.cs
  12. 11
      src/ImageSharp/Formats/Jpg/JpegFormat.cs
  13. 17
      src/ImageSharp/Formats/Png/PngDecoder.cs
  14. 16
      src/ImageSharp/Formats/Png/PngEncoder.cs
  15. 11
      src/ImageSharp/Formats/Png/PngFormat.cs
  16. 2
      src/ImageSharp/Image/Image.cs

18
src/ImageSharp/Formats/Bmp/BmpDecoder.cs

@ -31,24 +31,6 @@ namespace ImageSharp.Formats
/// <value>The size of the header.</value>
public int HeaderSize => 2;
/// <summary>
/// Returns a value indicating whether the <see cref="IImageDecoder"/> supports the specified
/// file header.
/// </summary>
/// <param name="extension">The <see cref="string"/> containing the file extension.</param>
/// <returns>
/// True if the decoder supports the file extension; otherwise, false.
/// </returns>
public bool IsSupportedFileExtension(string extension)
{
Guard.NotNullOrEmpty(extension, "extension");
extension = extension.StartsWith(".") ? extension.Substring(1) : extension;
return extension.Equals("BMP", StringComparison.OrdinalIgnoreCase)
|| extension.Equals("DIP", StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// Returns a value indicating whether the <see cref="IImageDecoder"/> supports the specified
/// file header.

23
src/ImageSharp/Formats/Bmp/BmpEncoder.cs

@ -14,34 +14,11 @@ namespace ImageSharp.Formats
/// <remarks>The encoder can currently only write 24-bit rgb images to streams.</remarks>
public class BmpEncoder : IImageEncoder
{
/// <summary>
/// Gets or sets the quality of output for images.
/// </summary>
/// <remarks>Bitmap is a lossless format so this is not used in this encoder.</remarks>
public int Quality { get; set; }
/// <inheritdoc/>
public string MimeType => "image/bmp";
/// <inheritdoc/>
public string Extension => "bmp";
/// <summary>
/// Gets or sets the number of bits per pixel.
/// </summary>
public BmpBitsPerPixel BitsPerPixel { get; set; } = BmpBitsPerPixel.Pixel24;
/// <inheritdoc/>
public bool IsSupportedFileExtension(string extension)
{
Guard.NotNullOrEmpty(extension, nameof(extension));
extension = extension.StartsWith(".") ? extension.Substring(1) : extension;
return extension.Equals(this.Extension, StringComparison.OrdinalIgnoreCase)
|| extension.Equals("dip", StringComparison.OrdinalIgnoreCase);
}
/// <inheritdoc/>
public void Encode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream)
where TColor : struct, IPackedPixel<TPacked>

11
src/ImageSharp/Formats/Bmp/BmpFormat.cs

@ -5,11 +5,22 @@
namespace ImageSharp.Formats
{
using System.Collections.Generic;
/// <summary>
/// Encapsulates the means to encode and decode bitmap images.
/// </summary>
public class BmpFormat : IImageFormat
{
/// <inheritdoc/>
public string MimeType => "image/bmp";
/// <inheritdoc/>
public string Extension => "bmp";
/// <inheritdoc/>
public IEnumerable<string> SupportedExtensions => new string[] { "bmp", "dip" };
/// <inheritdoc/>
public IImageDecoder Decoder => new BmpDecoder();

16
src/ImageSharp/Formats/Gif/GifDecoder.cs

@ -19,22 +19,6 @@ namespace ImageSharp.Formats
/// <value>The size of the header.</value>
public int HeaderSize => 6;
/// <summary>
/// Returns a value indicating whether the <see cref="IImageDecoder"/> supports the specified
/// file header.
/// </summary>
/// <param name="extension">The <see cref="string"/> containing the file extension.</param>
/// <returns>
/// True if the decoder supports the file extension; otherwise, false.
/// </returns>
public bool IsSupportedFileExtension(string extension)
{
Guard.NotNullOrEmpty(extension, nameof(extension));
extension = extension.StartsWith(".") ? extension.Substring(1) : extension;
return extension.Equals("GIF", StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// Returns a value indicating whether the <see cref="IImageDecoder"/> supports the specified
/// file header.

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

@ -31,21 +31,6 @@ namespace ImageSharp.Formats
/// </summary>
public IQuantizer Quantizer { get; set; }
/// <inheritdoc/>
public string Extension => "gif";
/// <inheritdoc/>
public string MimeType => "image/gif";
/// <inheritdoc/>
public bool IsSupportedFileExtension(string extension)
{
Guard.NotNullOrEmpty(extension, nameof(extension));
extension = extension.StartsWith(".") ? extension.Substring(1) : extension;
return extension.Equals(this.Extension, StringComparison.OrdinalIgnoreCase);
}
/// <inheritdoc/>
public void Encode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream)
where TColor : struct, IPackedPixel<TPacked>

11
src/ImageSharp/Formats/Gif/GifFormat.cs

@ -5,11 +5,22 @@
namespace ImageSharp.Formats
{
using System.Collections.Generic;
/// <summary>
/// Encapsulates the means to encode and decode gif images.
/// </summary>
public class GifFormat : IImageFormat
{
/// <inheritdoc/>
public string Extension => "gif";
/// <inheritdoc/>
public string MimeType => "image/gif";
/// <inheritdoc/>
public IEnumerable<string> SupportedExtensions => new string[] { "gif" };
/// <inheritdoc/>
public IImageDecoder Decoder => new GifDecoder();

10
src/ImageSharp/Formats/IImageDecoder.cs

@ -19,16 +19,6 @@ namespace ImageSharp.Formats
/// <value>The size of the header.</value>
int HeaderSize { get; }
/// <summary>
/// Returns a value indicating whether the <see cref="IImageDecoder"/> supports the specified
/// file header.
/// </summary>
/// <param name="extension">The <see cref="string"/> containing the file extension.</param>
/// <returns>
/// True if the decoder supports the file extension; otherwise, false.
/// </returns>
bool IsSupportedFileExtension(string extension);
/// <summary>
/// Returns a value indicating whether the <see cref="IImageDecoder"/> supports the specified
/// file header.

25
src/ImageSharp/Formats/IImageEncoder.cs

@ -13,31 +13,6 @@ namespace ImageSharp.Formats
/// </summary>
public interface IImageEncoder
{
/// <summary>
/// Gets or sets the quality of output for images.
/// </summary>
int Quality { get; set; }
/// <summary>
/// Gets the standard identifier used on the Internet to indicate the type of data that a file contains.
/// </summary>
string MimeType { get; }
/// <summary>
/// Gets the default file extension for this encoder.
/// </summary>
string Extension { get; }
/// <summary>
/// Returns a value indicating whether the <see cref="IImageEncoder"/> supports the specified
/// file header.
/// </summary>
/// <param name="extension">The <see cref="string"/> containing the file extension.</param>
/// <returns>
/// <c>True</c> if the decoder supports the file extension; otherwise, <c>false</c>.
/// </returns>
bool IsSupportedFileExtension(string extension);
/// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{TColor, TPacked}"/>.
/// </summary>

20
src/ImageSharp/Formats/IImageFormat.cs

@ -5,11 +5,31 @@
namespace ImageSharp.Formats
{
using System.Collections.Generic;
/// <summary>
/// Encapsulates a supported image format, providing means to encode and decode an image.
/// </summary>
public interface IImageFormat
{
/// <summary>
/// Gets the standard identifier used on the Internet to indicate the type of data that a file contains.
/// </summary>
string MimeType { get; }
/// <summary>
/// Gets the default file extension for this format.
/// </summary>
string Extension { get; }
/// <summary>
/// Gets the supported file extensions for this format.
/// </summary>
/// <returns>
/// The supported file extension.
/// </returns>
IEnumerable<string> SupportedExtensions { get; }
/// <summary>
/// Gets the image encoder for encoding an image from a stream.
/// </summary>

27
src/ImageSharp/Formats/Jpg/JpegDecoder.cs

@ -19,33 +19,6 @@ namespace ImageSharp.Formats
/// <value>The size of the header.</value>
public int HeaderSize => 11;
/// <summary>
/// Indicates if the image decoder supports the specified
/// file extension.
/// </summary>
/// <param name="extension">The file extension.</param>
/// <returns>
/// <c>true</c>, if the decoder supports the specified
/// extensions; otherwise <c>false</c>.
/// </returns>
/// <exception cref="System.ArgumentNullException"><paramref name="extension"/>
/// is null (Nothing in Visual Basic).</exception>
/// <exception cref="System.ArgumentException"><paramref name="extension"/> is a string
/// of length zero or contains only blanks.</exception>
public bool IsSupportedFileExtension(string extension)
{
Guard.NotNullOrEmpty(extension, "extension");
if (extension.StartsWith("."))
{
extension = extension.Substring(1);
}
return extension.Equals("JPG", StringComparison.OrdinalIgnoreCase) ||
extension.Equals("JPEG", StringComparison.OrdinalIgnoreCase) ||
extension.Equals("JFIF", StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// Indicates if the image decoder supports the specified
/// file header.

21
src/ImageSharp/Formats/Jpg/JpegEncoder.cs

@ -60,27 +60,6 @@ namespace ImageSharp.Formats
}
}
/// <inheritdoc/>
public string MimeType => "image/jpeg";
/// <inheritdoc/>
public string Extension => "jpg";
/// <inheritdoc/>
public bool IsSupportedFileExtension(string extension)
{
Guard.NotNullOrEmpty(extension, "extension");
if (extension.StartsWith("."))
{
extension = extension.Substring(1);
}
return extension.Equals(this.Extension, StringComparison.OrdinalIgnoreCase) ||
extension.Equals("jpeg", StringComparison.OrdinalIgnoreCase) ||
extension.Equals("jfif", StringComparison.OrdinalIgnoreCase);
}
/// <inheritdoc/>
public void Encode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream)
where TColor : struct, IPackedPixel<TPacked>

11
src/ImageSharp/Formats/Jpg/JpegFormat.cs

@ -5,11 +5,22 @@
namespace ImageSharp.Formats
{
using System.Collections.Generic;
/// <summary>
/// Encapsulates the means to encode and decode jpeg images.
/// </summary>
public class JpegFormat : IImageFormat
{
/// <inheritdoc/>
public string MimeType => "image/jpeg";
/// <inheritdoc/>
public string Extension => "jpg";
/// <inheritdoc/>
public IEnumerable<string> SupportedExtensions => new string[] { "jpg", "jpeg", "jfif" };
/// <inheritdoc/>
public IImageDecoder Decoder => new JpegDecoder();

17
src/ImageSharp/Formats/Png/PngDecoder.cs

@ -36,23 +36,6 @@ namespace ImageSharp.Formats
/// <value>The size of the header.</value>
public int HeaderSize => 8;
/// <summary>
/// Returns a value indicating whether the <see cref="IImageDecoder"/> supports the specified
/// file header.
/// </summary>
/// <param name="extension">The <see cref="string"/> containing the file extension.</param>
/// <returns>
/// True if the decoder supports the file extension; otherwise, false.
/// </returns>
public bool IsSupportedFileExtension(string extension)
{
Guard.NotNullOrEmpty(extension, "extension");
extension = extension.StartsWith(".") ? extension.Substring(1) : extension;
return extension.Equals("PNG", StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// Returns a value indicating whether the <see cref="IImageDecoder"/> supports the specified
/// file header.

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

@ -25,12 +25,6 @@ namespace ImageSharp.Formats
/// </summary>
public PngColorType PngColorType { get; set; } = PngColorType.RgbWithAlpha;
/// <inheritdoc/>
public string MimeType => "image/png";
/// <inheritdoc/>
public string Extension => "png";
/// <summary>
/// Gets or sets the compression level 1-9.
/// <remarks>Defaults to 6.</remarks>
@ -61,16 +55,6 @@ namespace ImageSharp.Formats
/// </summary>
public bool WriteGamma { get; set; }
/// <inheritdoc/>
public bool IsSupportedFileExtension(string extension)
{
Guard.NotNullOrEmpty(extension, nameof(extension));
extension = extension.StartsWith(".") ? extension.Substring(1) : extension;
return extension.Equals(this.Extension, StringComparison.OrdinalIgnoreCase);
}
/// <inheritdoc/>
public void Encode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream)
where TColor : struct, IPackedPixel<TPacked>

11
src/ImageSharp/Formats/Png/PngFormat.cs

@ -5,11 +5,22 @@
namespace ImageSharp.Formats
{
using System.Collections.Generic;
/// <summary>
/// Encapsulates the means to encode and decode png images.
/// </summary>
public class PngFormat : IImageFormat
{
/// <inheritdoc/>
public string MimeType => "image/png";
/// <inheritdoc/>
public string Extension => "png";
/// <inheritdoc/>
public IEnumerable<string> SupportedExtensions => new string[] { "png" };
/// <inheritdoc/>
public IImageDecoder Decoder => new PngDecoder();

2
src/ImageSharp/Image/Image.cs

@ -255,7 +255,7 @@ namespace ImageSharp
{
this.Save(stream);
stream.Flush();
return $"data:{this.CurrentImageFormat.Encoder.MimeType};base64,{Convert.ToBase64String(stream.ToArray())}";
return $"data:{this.CurrentImageFormat.MimeType};base64,{Convert.ToBase64String(stream.ToArray())}";
}
}

Loading…
Cancel
Save