mirror of https://github.com/SixLabors/ImageSharp
37 changed files with 647 additions and 558 deletions
@ -0,0 +1,27 @@ |
|||
// <copyright file="ConfigurationModule.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the bmp format.
|
|||
/// </summary>
|
|||
public class BmpConfigurationModule : IConfigurationModule |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public void Configure(Configuration config) |
|||
{ |
|||
config.SetEncoder(ImageFormats.Bitmap, new BmpEncoder()); |
|||
config.SetDecoder(ImageFormats.Bitmap, new BmpDecoder()); |
|||
config.AddImageFormatDetector(new BmpImageFormatDetector()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
// <copyright file="GifFormat.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
|
|||
/// </summary>
|
|||
internal sealed class BmpFormat : IImageFormat |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public string Name => "BMP"; |
|||
|
|||
/// <inheritdoc/>
|
|||
public string DefaultMimeType => "image/bmp"; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IEnumerable<string> MimeTypes => BmpConstants.MimeTypes; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IEnumerable<string> FileExtensions => BmpConstants.FileExtensions; |
|||
} |
|||
} |
|||
@ -1,45 +0,0 @@ |
|||
// <copyright file="PngImageFormatProvider.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the bmp format.
|
|||
/// </summary>
|
|||
public class BmpImageFormatProvider : IImageFormatProvider |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public void Configure(IImageFormatHost host) |
|||
{ |
|||
var encoder = new BmpEncoder(); |
|||
foreach (string mimeType in BmpConstants.MimeTypes) |
|||
{ |
|||
host.SetMimeTypeEncoder(mimeType, encoder); |
|||
} |
|||
|
|||
foreach (string ext in BmpConstants.FileExtensions) |
|||
{ |
|||
foreach (string mimeType in BmpConstants.MimeTypes) |
|||
{ |
|||
host.SetFileExtensionToMimeTypeMapping(ext, mimeType); |
|||
} |
|||
} |
|||
|
|||
var decoder = new BmpDecoder(); |
|||
foreach (string mimeType in BmpConstants.MimeTypes) |
|||
{ |
|||
host.SetMimeTypeDecoder(mimeType, decoder); |
|||
} |
|||
|
|||
host.AddMimeTypeDetector(new BmpMimeTypeDetector()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
// <copyright file="PngImageFormatProvider.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the gif format.
|
|||
/// </summary>
|
|||
public class GifConfigurationModule : IConfigurationModule |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public void Configure(Configuration config) |
|||
{ |
|||
config.SetEncoder(ImageFormats.Gif, new GifEncoder()); |
|||
config.SetDecoder(ImageFormats.Gif, new GifDecoder()); |
|||
|
|||
config.AddImageFormatDetector(new GifImageFormatDetector()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
// <copyright file="GifFormat.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
|
|||
/// </summary>
|
|||
internal sealed class GifFormat : IImageFormat |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public string Name => "GIF"; |
|||
|
|||
/// <inheritdoc/>
|
|||
public string DefaultMimeType => "image/gif"; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IEnumerable<string> MimeTypes => GifConstants.MimeTypes; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IEnumerable<string> FileExtensions => GifConstants.FileExtensions; |
|||
} |
|||
} |
|||
@ -1,45 +0,0 @@ |
|||
// <copyright file="PngImageFormatProvider.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the gif format.
|
|||
/// </summary>
|
|||
public class GifImageFormatProvider : IImageFormatProvider |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public void Configure(IImageFormatHost host) |
|||
{ |
|||
var encoder = new GifEncoder(); |
|||
foreach (string mimeType in GifConstants.MimeTypes) |
|||
{ |
|||
host.SetMimeTypeEncoder(mimeType, encoder); |
|||
} |
|||
|
|||
foreach (string ext in GifConstants.FileExtensions) |
|||
{ |
|||
foreach (string mimeType in GifConstants.MimeTypes) |
|||
{ |
|||
host.SetFileExtensionToMimeTypeMapping(ext, mimeType); |
|||
} |
|||
} |
|||
|
|||
var decoder = new GifDecoder(); |
|||
foreach (string mimeType in GifConstants.MimeTypes) |
|||
{ |
|||
host.SetMimeTypeDecoder(mimeType, decoder); |
|||
} |
|||
|
|||
host.AddMimeTypeDetector(new GifMimeTypeDetector()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
// <copyright file="IImageFormat.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
|
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Describes an image format.
|
|||
/// </summary>
|
|||
public interface IImageFormat |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the name that describes this image format.
|
|||
/// </summary>
|
|||
string Name { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the default mimetype that the image foramt uses
|
|||
/// </summary>
|
|||
string DefaultMimeType { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets all the mimetypes that have been used by this image foramt.
|
|||
/// </summary>
|
|||
IEnumerable<string> MimeTypes { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the file extensions this image format commonly uses.
|
|||
/// </summary>
|
|||
IEnumerable<string> FileExtensions { get; } |
|||
} |
|||
} |
|||
@ -1,56 +0,0 @@ |
|||
// <copyright file="IImageFormatProvider.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
/// <summary>
|
|||
/// 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, 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 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 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 mime type.
|
|||
/// </summary>
|
|||
/// <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 mime type.
|
|||
/// </summary>
|
|||
/// <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 mime types.
|
|||
/// </summary>
|
|||
/// <param name="detector">The detector to add</param>
|
|||
void AddMimeTypeDetector(IMimeTypeDetector detector); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
// <copyright file="PngImageFormatProvider.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
|
|||
/// </summary>
|
|||
public class JpegConfigurationModule : IConfigurationModule |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public void Configure(Configuration config) |
|||
{ |
|||
config.SetEncoder(ImageFormats.Jpeg, new JpegEncoder()); |
|||
config.SetDecoder(ImageFormats.Jpeg, new JpegDecoder()); |
|||
|
|||
config.AddImageFormatDetector(new JpegImageFormatDetector()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
// <copyright file="JpegFormat.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
|
|||
/// </summary>
|
|||
internal sealed class JpegFormat : IImageFormat |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public string Name => "JPEG"; |
|||
|
|||
/// <inheritdoc/>
|
|||
public string DefaultMimeType => "image/jpeg"; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IEnumerable<string> MimeTypes => JpegConstants.MimeTypes; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IEnumerable<string> FileExtensions => JpegConstants.FileExtensions; |
|||
} |
|||
} |
|||
@ -1,45 +0,0 @@ |
|||
// <copyright file="PngImageFormatProvider.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
|
|||
/// </summary>
|
|||
public class JpegImageFormatProvider : IImageFormatProvider |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public void Configure(IImageFormatHost host) |
|||
{ |
|||
var pngEncoder = new JpegEncoder(); |
|||
foreach (string mimeType in JpegConstants.MimeTypes) |
|||
{ |
|||
host.SetMimeTypeEncoder(mimeType, pngEncoder); |
|||
} |
|||
|
|||
foreach (string ext in JpegConstants.FileExtensions) |
|||
{ |
|||
foreach (string mimeType in JpegConstants.MimeTypes) |
|||
{ |
|||
host.SetFileExtensionToMimeTypeMapping(ext, mimeType); |
|||
} |
|||
} |
|||
|
|||
var pngDecoder = new JpegDecoder(); |
|||
foreach (string mimeType in JpegConstants.MimeTypes) |
|||
{ |
|||
host.SetMimeTypeDecoder(mimeType, pngDecoder); |
|||
} |
|||
|
|||
host.AddMimeTypeDetector(new JpegMimeTypeDetector()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// <copyright file="PngConfigurationModule.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the png format.
|
|||
/// </summary>
|
|||
public class PngConfigurationModule : IConfigurationModule |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public void Configure(Configuration host) |
|||
{ |
|||
host.SetEncoder(ImageFormats.Png, new PngEncoder()); |
|||
host.SetDecoder(ImageFormats.Png, new PngDecoder()); |
|||
host.AddImageFormatDetector(new PngImageFormatDetector()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
// <copyright file="PngFormat.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
|
|||
/// </summary>
|
|||
internal sealed class PngFormat : IImageFormat |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public string Name => "PNG"; |
|||
|
|||
/// <inheritdoc/>
|
|||
public string DefaultMimeType => "image/png"; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IEnumerable<string> MimeTypes => PngConstants.MimeTypes; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IEnumerable<string> FileExtensions => PngConstants.FileExtensions; |
|||
} |
|||
} |
|||
@ -1,45 +0,0 @@ |
|||
// <copyright file="PngImageFormatProvider.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Formats |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the png format.
|
|||
/// </summary>
|
|||
public class PngImageFormatProvider : IImageFormatProvider |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public void Configure(IImageFormatHost host) |
|||
{ |
|||
var pngEncoder = new PngEncoder(); |
|||
foreach (string mimeType in PngConstants.MimeTypes) |
|||
{ |
|||
host.SetMimeTypeEncoder(mimeType, pngEncoder); |
|||
} |
|||
|
|||
foreach (string ext in PngConstants.FileExtensions) |
|||
{ |
|||
foreach (string mimeType in PngConstants.MimeTypes) |
|||
{ |
|||
host.SetFileExtensionToMimeTypeMapping(ext, mimeType); |
|||
} |
|||
} |
|||
|
|||
var pngDecoder = new PngDecoder(); |
|||
foreach (string mimeType in PngConstants.MimeTypes) |
|||
{ |
|||
host.SetMimeTypeDecoder(mimeType, pngDecoder); |
|||
} |
|||
|
|||
host.AddMimeTypeDetector(new PngMimeTypeDetector()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
// <copyright file="IConfigurationModule.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
/// <summary>
|
|||
/// Represents an interface that can register image encoders, decoders and image format detectors.
|
|||
/// </summary>
|
|||
public interface IConfigurationModule |
|||
{ |
|||
/// <summary>
|
|||
/// Called when loaded into a configuration object so the module can register items into the configuration.
|
|||
/// </summary>
|
|||
/// <param name="configuration">The configuration that will retain the encoders, decodes and mime type detectors.</param>
|
|||
void Configure(Configuration configuration); |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
// <copyright file="IImageFormat.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using ImageSharp.Formats; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// The static collection of all the default image formats
|
|||
/// </summary>
|
|||
public static class ImageFormats |
|||
{ |
|||
/// <summary>
|
|||
/// The format details for the jpegs.
|
|||
/// </summary>
|
|||
public static readonly IImageFormat Jpeg = new JpegFormat(); |
|||
|
|||
/// <summary>
|
|||
/// The format details for the pngs.
|
|||
/// </summary>
|
|||
public static readonly IImageFormat Png = new PngFormat(); |
|||
|
|||
/// <summary>
|
|||
/// The format details for the gifs.
|
|||
/// </summary>
|
|||
public static readonly IImageFormat Gif = new GifFormat(); |
|||
|
|||
/// <summary>
|
|||
/// The format details for the bitmaps.
|
|||
/// </summary>
|
|||
public static readonly IImageFormat Bitmap = new BmpFormat(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue