mirror of https://github.com/SixLabors/ImageSharp
127 changed files with 3288 additions and 1811 deletions
@ -1,100 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using SixLabors.ImageSharp.Advanced; |
|||
using SixLabors.ImageSharp.Formats.Gif; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsGif(this Image source, string path) => SaveAsGif(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsGifAsync(this Image source, string path) => SaveAsGifAsync(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsGif(this Image source, string path, GifEncoder encoder) => |
|||
source.Save( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsGifAsync(this Image source, string path, GifEncoder encoder) => |
|||
source.SaveAsync( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsGif(this Image source, Stream stream) => SaveAsGif(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsGifAsync(this Image source, Stream stream) => SaveAsGifAsync(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsGif(this Image source, Stream stream, GifEncoder encoder) => |
|||
source.Save( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsGifAsync(this Image source, Stream stream, GifEncoder encoder) => |
|||
source.SaveAsync( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance)); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.IO; |
|||
using System.Threading; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats |
|||
{ |
|||
/// <summary>
|
|||
/// Abstraction for shared internals for ***DecoderCore implementations to be used with <see cref="ImageEncoderUtilities"/>.
|
|||
/// </summary>
|
|||
internal interface IImageEncoderInternals |
|||
{ |
|||
/// <summary>
|
|||
/// Encodes the image.
|
|||
/// </summary>
|
|||
/// <param name="image">The image.</param>
|
|||
/// <param name="stream">The stream.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <typeparam name="TPixel">The pixel type.</typeparam>
|
|||
void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken cancellationToken) |
|||
where TPixel : unmanaged, IPixel<TPixel>; |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using SixLabors.ImageSharp.Advanced; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats |
|||
{ |
|||
internal static class ImageEncoderUtilities |
|||
{ |
|||
public static async Task EncodeAsync<TPixel>( |
|||
this IImageEncoderInternals encoder, |
|||
Image<TPixel> image, |
|||
Stream stream, |
|||
CancellationToken cancellationToken) |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
{ |
|||
Configuration configuration = image.GetConfiguration(); |
|||
if (stream.CanSeek) |
|||
{ |
|||
await DoEncodeAsync(stream).ConfigureAwait(false); |
|||
} |
|||
else |
|||
{ |
|||
using var ms = new MemoryStream(); |
|||
await DoEncodeAsync(ms); |
|||
ms.Position = 0; |
|||
await ms.CopyToAsync(stream, configuration.StreamProcessingBufferSize, cancellationToken) |
|||
.ConfigureAwait(false); |
|||
} |
|||
|
|||
Task DoEncodeAsync(Stream innerStream) |
|||
{ |
|||
try |
|||
{ |
|||
encoder.Encode(image, innerStream, cancellationToken); |
|||
return Task.CompletedTask; |
|||
} |
|||
catch (OperationCanceledException) |
|||
{ |
|||
return Task.FromCanceled(cancellationToken); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
return Task.FromException(ex); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static void Encode<TPixel>( |
|||
this IImageEncoderInternals encoder, |
|||
Image<TPixel> image, |
|||
Stream stream) |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
=> encoder.Encode(image, stream, default); |
|||
} |
|||
} |
|||
@ -0,0 +1,539 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
// <auto-generated />
|
|||
using System.IO; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using SixLabors.ImageSharp.Advanced; |
|||
|
|||
using SixLabors.ImageSharp.Formats.Bmp; |
|||
using SixLabors.ImageSharp.Formats.Gif; |
|||
using SixLabors.ImageSharp.Formats.Jpeg; |
|||
using SixLabors.ImageSharp.Formats.Png; |
|||
using SixLabors.ImageSharp.Formats.Tga; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Bmp format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsBmp(this Image source, string path) => SaveAsBmp(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Bmp format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsBmpAsync(this Image source, string path) => SaveAsBmpAsync(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Bmp format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsBmpAsync(this Image source, string path, CancellationToken cancellationToken) |
|||
=> SaveAsBmpAsync(source, path, null, cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Bmp format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsBmp(this Image source, string path, BmpEncoder encoder) => |
|||
source.Save( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Bmp format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsBmpAsync(this Image source, string path, BmpEncoder encoder, CancellationToken cancellationToken = default) => |
|||
source.SaveAsync( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance), |
|||
cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Bmp format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsBmp(this Image source, Stream stream) |
|||
=> SaveAsBmp(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Bmp format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsBmpAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) |
|||
=> SaveAsBmpAsync(source, stream, null, cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Bmp format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static void SaveAsBmp(this Image source, Stream stream, BmpEncoder encoder) |
|||
=> source.Save( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Bmp format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsBmpAsync(this Image source, Stream stream, BmpEncoder encoder, CancellationToken cancellationToken = default) => |
|||
source.SaveAsync( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance), |
|||
cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsGif(this Image source, string path) => SaveAsGif(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsGifAsync(this Image source, string path) => SaveAsGifAsync(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsGifAsync(this Image source, string path, CancellationToken cancellationToken) |
|||
=> SaveAsGifAsync(source, path, null, cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsGif(this Image source, string path, GifEncoder encoder) => |
|||
source.Save( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsGifAsync(this Image source, string path, GifEncoder encoder, CancellationToken cancellationToken = default) => |
|||
source.SaveAsync( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance), |
|||
cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsGif(this Image source, Stream stream) |
|||
=> SaveAsGif(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsGifAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) |
|||
=> SaveAsGifAsync(source, stream, null, cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static void SaveAsGif(this Image source, Stream stream, GifEncoder encoder) |
|||
=> source.Save( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Gif format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsGifAsync(this Image source, Stream stream, GifEncoder encoder, CancellationToken cancellationToken = default) => |
|||
source.SaveAsync( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance), |
|||
cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsJpeg(this Image source, string path) => SaveAsJpeg(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsJpegAsync(this Image source, string path) => SaveAsJpegAsync(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsJpegAsync(this Image source, string path, CancellationToken cancellationToken) |
|||
=> SaveAsJpegAsync(source, path, null, cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsJpeg(this Image source, string path, JpegEncoder encoder) => |
|||
source.Save( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsJpegAsync(this Image source, string path, JpegEncoder encoder, CancellationToken cancellationToken = default) => |
|||
source.SaveAsync( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance), |
|||
cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsJpeg(this Image source, Stream stream) |
|||
=> SaveAsJpeg(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsJpegAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) |
|||
=> SaveAsJpegAsync(source, stream, null, cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static void SaveAsJpeg(this Image source, Stream stream, JpegEncoder encoder) |
|||
=> source.Save( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsJpegAsync(this Image source, Stream stream, JpegEncoder encoder, CancellationToken cancellationToken = default) => |
|||
source.SaveAsync( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance), |
|||
cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsPng(this Image source, string path) => SaveAsPng(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsPngAsync(this Image source, string path) => SaveAsPngAsync(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsPngAsync(this Image source, string path, CancellationToken cancellationToken) |
|||
=> SaveAsPngAsync(source, path, null, cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsPng(this Image source, string path, PngEncoder encoder) => |
|||
source.Save( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsPngAsync(this Image source, string path, PngEncoder encoder, CancellationToken cancellationToken = default) => |
|||
source.SaveAsync( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance), |
|||
cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsPng(this Image source, Stream stream) |
|||
=> SaveAsPng(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsPngAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) |
|||
=> SaveAsPngAsync(source, stream, null, cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static void SaveAsPng(this Image source, Stream stream, PngEncoder encoder) |
|||
=> source.Save( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsPngAsync(this Image source, Stream stream, PngEncoder encoder, CancellationToken cancellationToken = default) => |
|||
source.SaveAsync( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance), |
|||
cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsTga(this Image source, string path) => SaveAsTga(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsTgaAsync(this Image source, string path) => SaveAsTgaAsync(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsTgaAsync(this Image source, string path, CancellationToken cancellationToken) |
|||
=> SaveAsTgaAsync(source, path, null, cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsTga(this Image source, string path, TgaEncoder encoder) => |
|||
source.Save( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsTgaAsync(this Image source, string path, TgaEncoder encoder, CancellationToken cancellationToken = default) => |
|||
source.SaveAsync( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance), |
|||
cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsTga(this Image source, Stream stream) |
|||
=> SaveAsTga(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsTgaAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) |
|||
=> SaveAsTgaAsync(source, stream, null, cancellationToken); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static void SaveAsTga(this Image source, Stream stream, TgaEncoder encoder) |
|||
=> source.Save( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the Tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsTgaAsync(this Image source, Stream stream, TgaEncoder encoder, CancellationToken cancellationToken = default) => |
|||
source.SaveAsync( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance), |
|||
cancellationToken); |
|||
|
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder |
|||
{ |
|||
/// <summary>
|
|||
/// Poor man's stackalloc: Contains a value-type <see cref="float"/> buffer sized for 4 <see cref="Block8x8F"/> instances.
|
|||
/// Useful for decoder/encoder operations allocating a block for each Jpeg component.
|
|||
/// </summary>
|
|||
internal unsafe struct BlockQuad |
|||
{ |
|||
/// <summary>
|
|||
/// The value-type <see cref="float"/> buffer sized for 4 <see cref="Block8x8F"/> instances.
|
|||
/// </summary>
|
|||
public fixed float Data[4 * Block8x8F.Size]; |
|||
} |
|||
} |
|||
@ -1,100 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using SixLabors.ImageSharp.Advanced; |
|||
using SixLabors.ImageSharp.Formats.Jpeg; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsJpeg(this Image source, string path) => SaveAsJpeg(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsJpegAsync(this Image source, string path) => SaveAsJpegAsync(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsJpeg(this Image source, string path, JpegEncoder encoder) => |
|||
source.Save( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsJpegAsync(this Image source, string path, JpegEncoder encoder) => |
|||
source.SaveAsync( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsJpeg(this Image source, Stream stream) => SaveAsJpeg(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsJpegAsync(this Image source, Stream stream) => SaveAsJpegAsync(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsJpeg(this Image source, Stream stream, JpegEncoder encoder) => |
|||
source.Save( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the jpeg format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsJpegAsync(this Image source, Stream stream, JpegEncoder encoder) => |
|||
source.SaveAsync( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance)); |
|||
} |
|||
} |
|||
@ -1,100 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using SixLabors.ImageSharp.Advanced; |
|||
using SixLabors.ImageSharp.Formats.Png; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsPng(this Image source, string path) => SaveAsPng(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsPngAsync(this Image source, string path) => SaveAsPngAsync(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsPng(this Image source, string path, PngEncoder encoder) => |
|||
source.Save( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsPngAsync(this Image source, string path, PngEncoder encoder) => |
|||
source.SaveAsync( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsPng(this Image source, Stream stream) => SaveAsPng(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsPngAsync(this Image source, Stream stream) => SaveAsPngAsync(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsPng(this Image source, Stream stream, PngEncoder encoder) => |
|||
source.Save( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the png format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsPngAsync(this Image source, Stream stream, PngEncoder encoder) => |
|||
source.SaveAsync( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance)); |
|||
} |
|||
} |
|||
@ -1,100 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using SixLabors.ImageSharp.Advanced; |
|||
using SixLabors.ImageSharp.Formats.Tga; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsTga(this Image source, string path) => SaveAsTga(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsTgaAsync(this Image source, string path) => SaveAsTgaAsync(source, path, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
public static void SaveAsTga(this Image source, string path, TgaEncoder encoder) => |
|||
source.Save( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="path">The file path to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsTgaAsync(this Image source, string path, TgaEncoder encoder) => |
|||
source.SaveAsync( |
|||
path, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsTga(this Image source, Stream stream) => SaveAsTga(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsTgaAsync(this Image source, Stream stream) => SaveAsTgaAsync(source, stream, null); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
public static void SaveAsTga(this Image source, Stream stream, TgaEncoder encoder) => |
|||
source.Save( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance)); |
|||
|
|||
/// <summary>
|
|||
/// Saves the image to the given stream with the tga format.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="stream">The stream to save the image to.</param>
|
|||
/// <param name="encoder">The encoder to save the image with.</param>
|
|||
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|||
public static Task SaveAsTgaAsync(this Image source, Stream stream, TgaEncoder encoder) => |
|||
source.SaveAsync( |
|||
stream, |
|||
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance)); |
|||
} |
|||
} |
|||
@ -1,61 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing |
|||
{ |
|||
/// <summary>
|
|||
/// Enumerates the various types of defined edge detection filters.
|
|||
/// </summary>
|
|||
public enum EdgeDetectionOperators |
|||
{ |
|||
/// <summary>
|
|||
/// The Kayyali operator filter.
|
|||
/// </summary>
|
|||
Kayyali, |
|||
|
|||
/// <summary>
|
|||
/// The Kirsch operator filter.
|
|||
/// </summary>
|
|||
Kirsch, |
|||
|
|||
/// <summary>
|
|||
/// The Laplacian3X3 operator filter.
|
|||
/// </summary>
|
|||
Laplacian3x3, |
|||
|
|||
/// <summary>
|
|||
/// The Laplacian5X5 operator filter.
|
|||
/// </summary>
|
|||
Laplacian5x5, |
|||
|
|||
/// <summary>
|
|||
/// The LaplacianOfGaussian operator filter.
|
|||
/// </summary>
|
|||
LaplacianOfGaussian, |
|||
|
|||
/// <summary>
|
|||
/// The Prewitt operator filter.
|
|||
/// </summary>
|
|||
Prewitt, |
|||
|
|||
/// <summary>
|
|||
/// The RobertsCross operator filter.
|
|||
/// </summary>
|
|||
RobertsCross, |
|||
|
|||
/// <summary>
|
|||
/// The Robinson operator filter.
|
|||
/// </summary>
|
|||
Robinson, |
|||
|
|||
/// <summary>
|
|||
/// The Scharr operator filter.
|
|||
/// </summary>
|
|||
Scharr, |
|||
|
|||
/// <summary>
|
|||
/// The Sobel operator filter.
|
|||
/// </summary>
|
|||
Sobel |
|||
} |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Processing.Processors.Convolution; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing |
|||
{ |
|||
/// <summary>
|
|||
/// Contains reusable static instances of known edge detection kernels.
|
|||
/// </summary>
|
|||
public static class KnownEdgeDetectorKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the Kayyali edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel Kayyali { get; } = EdgeDetector2DKernel.KayyaliKernel; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Kirsch edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetectorCompassKernel Kirsch { get; } = EdgeDetectorCompassKernel.Kirsch; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Laplacian 3x3 edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel Laplacian3x3 { get; } = EdgeDetectorKernel.Laplacian3x3; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Laplacian 5x5 edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel Laplacian5x5 { get; } = EdgeDetectorKernel.Laplacian5x5; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Laplacian of Gaussian edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel LaplacianOfGaussian { get; } = EdgeDetectorKernel.LaplacianOfGaussian; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Prewitt edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel Prewitt { get; } = EdgeDetector2DKernel.PrewittKernel; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Roberts-Cross edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel RobertsCross { get; } = EdgeDetector2DKernel.RobertsCrossKernel; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Robinson edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetectorCompassKernel Robinson { get; } = EdgeDetectorCompassKernel.Robinson; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Scharr edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel Scharr { get; } = EdgeDetector2DKernel.ScharrKernel; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Sobel edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel Sobel { get; } = EdgeDetector2DKernel.SobelKernel; |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using the two 1D gradient operators.
|
|||
/// </summary>
|
|||
public sealed class EdgeDetector2DProcessor : IImageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EdgeDetector2DProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="kernel">The 2D edge detector kernel.</param>
|
|||
/// <param name="grayscale">
|
|||
/// Whether to convert the image to grayscale before performing edge detection.
|
|||
/// </param>
|
|||
public EdgeDetector2DProcessor(EdgeDetector2DKernel kernel, bool grayscale) |
|||
{ |
|||
this.Kernel = kernel; |
|||
this.Grayscale = grayscale; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the 2D edge detector kernel.
|
|||
/// </summary>
|
|||
public EdgeDetector2DKernel Kernel { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value indicating whether to convert the image to grayscale before performing
|
|||
/// edge detection.
|
|||
/// </summary>
|
|||
public bool Grayscale { get; } |
|||
|
|||
/// <inheritdoc />
|
|||
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
=> new EdgeDetector2DProcessor<TPixel>(configuration, this, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using eight gradient operators.
|
|||
/// </summary>
|
|||
public sealed class EdgeDetectorCompassProcessor : IImageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EdgeDetectorCompassProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="kernel">The edge detector kernel.</param>
|
|||
/// <param name="grayscale">
|
|||
/// Whether to convert the image to grayscale before performing edge detection.
|
|||
/// </param>
|
|||
public EdgeDetectorCompassProcessor(EdgeDetectorCompassKernel kernel, bool grayscale) |
|||
{ |
|||
this.Kernel = kernel; |
|||
this.Grayscale = grayscale; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the edge detector kernel.
|
|||
/// </summary>
|
|||
public EdgeDetectorCompassKernel Kernel { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value indicating whether to convert the image to grayscale before performing
|
|||
/// edge detection.
|
|||
/// </summary>
|
|||
public bool Grayscale { get; } |
|||
|
|||
/// <inheritdoc />
|
|||
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
=> new EdgeDetectorCompassProcessor<TPixel>(configuration, this, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection processing using the Kayyali operator filter.
|
|||
/// See <see href="http://edgedetection.webs.com/"/>.
|
|||
/// </summary>
|
|||
public sealed class KayyaliProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="KayyaliProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public KayyaliProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetector2DProcessor<TPixel>( |
|||
configuration, |
|||
KayyaliKernels.KayyaliX, |
|||
KayyaliKernels.KayyaliY, |
|||
this.Grayscale, |
|||
source, |
|||
sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,55 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
internal abstract class CompassKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the North gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> North { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthWest gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> NorthWest { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the West gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> West { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthWest gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> SouthWest { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the South gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> South { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthEast gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> SouthEast { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the East gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> East { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthEast gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> NorthEast { get; } |
|||
|
|||
public DenseMatrix<float>[] Flatten() => |
|||
new[] |
|||
{ |
|||
this.North, this.NorthWest, this.West, this.SouthWest, |
|||
this.South, this.SouthEast, this.East, this.NorthEast |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,103 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Represents an edge detection convolution kernel consisting of two 1D gradient operators.
|
|||
/// </summary>
|
|||
public readonly struct EdgeDetector2DKernel : IEquatable<EdgeDetector2DKernel> |
|||
{ |
|||
/// <summary>
|
|||
/// An edge detection kernel containing two Kayyali operators.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel KayyaliKernel = new EdgeDetector2DKernel(KayyaliKernels.KayyaliX, KayyaliKernels.KayyaliY); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing two Prewitt operators.
|
|||
/// <see href="https://en.wikipedia.org/wiki/Prewitt_operator"/>.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel PrewittKernel = new EdgeDetector2DKernel(PrewittKernels.PrewittX, PrewittKernels.PrewittY); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing two Roberts-Cross operators.
|
|||
/// <see href="https://en.wikipedia.org/wiki/Roberts_cross"/>.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel RobertsCrossKernel = new EdgeDetector2DKernel(RobertsCrossKernels.RobertsCrossX, RobertsCrossKernels.RobertsCrossY); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing two Scharr operators.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel ScharrKernel = new EdgeDetector2DKernel(ScharrKernels.ScharrX, ScharrKernels.ScharrY); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing two Sobel operators.
|
|||
/// <see href="https://en.wikipedia.org/wiki/Sobel_operator"/>.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel SobelKernel = new EdgeDetector2DKernel(SobelKernels.SobelX, SobelKernels.SobelY); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EdgeDetector2DKernel"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="kernelX">The horizontal gradient operator.</param>
|
|||
/// <param name="kernelY">The vertical gradient operator.</param>
|
|||
public EdgeDetector2DKernel(DenseMatrix<float> kernelX, DenseMatrix<float> kernelY) |
|||
{ |
|||
Guard.IsTrue( |
|||
kernelX.Size.Equals(kernelY.Size), |
|||
$"{nameof(kernelX)} {nameof(kernelY)}", |
|||
"Kernel sizes must be the same."); |
|||
|
|||
this.KernelX = kernelX; |
|||
this.KernelY = kernelY; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the horizontal gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> KernelX { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the vertical gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> KernelY { get; } |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetector2DKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetector2DKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetector2DKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator ==(EdgeDetector2DKernel left, EdgeDetector2DKernel right) |
|||
=> left.Equals(right); |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetector2DKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetector2DKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetector2DKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator !=(EdgeDetector2DKernel left, EdgeDetector2DKernel right) |
|||
=> !(left == right); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
=> obj is EdgeDetector2DKernel kernel && this.Equals(kernel); |
|||
|
|||
/// <inheritdoc/>
|
|||
public bool Equals(EdgeDetector2DKernel other) |
|||
=> this.KernelX.Equals(other.KernelX) |
|||
&& this.KernelY.Equals(other.KernelY); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() => HashCode.Combine(this.KernelX, this.KernelY); |
|||
} |
|||
} |
|||
@ -0,0 +1,163 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Represents an edge detection convolution kernel consisting of eight gradient operators.
|
|||
/// </summary>
|
|||
public readonly struct EdgeDetectorCompassKernel : IEquatable<EdgeDetectorCompassKernel> |
|||
{ |
|||
/// <summary>
|
|||
/// An edge detection kenel comprised of Kirsch gradient operators.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Kirsch_operator"/>.
|
|||
/// </summary>
|
|||
public static EdgeDetectorCompassKernel Kirsch = |
|||
new EdgeDetectorCompassKernel( |
|||
KirschKernels.North, |
|||
KirschKernels.NorthWest, |
|||
KirschKernels.West, |
|||
KirschKernels.SouthWest, |
|||
KirschKernels.South, |
|||
KirschKernels.SouthEast, |
|||
KirschKernels.East, |
|||
KirschKernels.NorthEast); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kenel comprised of Robinson gradient operators.
|
|||
/// <see href="http://www.tutorialspoint.com/dip/Robinson_Compass_Mask.htm"/>
|
|||
/// </summary>
|
|||
public static EdgeDetectorCompassKernel Robinson = |
|||
new EdgeDetectorCompassKernel( |
|||
RobinsonKernels.North, |
|||
RobinsonKernels.NorthWest, |
|||
RobinsonKernels.West, |
|||
RobinsonKernels.SouthWest, |
|||
RobinsonKernels.South, |
|||
RobinsonKernels.SouthEast, |
|||
RobinsonKernels.East, |
|||
RobinsonKernels.NorthEast); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EdgeDetectorCompassKernel"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="north">The north gradient operator.</param>
|
|||
/// <param name="northWest">The north-west gradient operator.</param>
|
|||
/// <param name="west">The west gradient operator.</param>
|
|||
/// <param name="southWest">The south-west gradient operator.</param>
|
|||
/// <param name="south">The south gradient operator.</param>
|
|||
/// <param name="southEast">The south-east gradient operator.</param>
|
|||
/// <param name="east">The east gradient operator.</param>
|
|||
/// <param name="northEast">The north-east gradient operator.</param>
|
|||
public EdgeDetectorCompassKernel( |
|||
DenseMatrix<float> north, |
|||
DenseMatrix<float> northWest, |
|||
DenseMatrix<float> west, |
|||
DenseMatrix<float> southWest, |
|||
DenseMatrix<float> south, |
|||
DenseMatrix<float> southEast, |
|||
DenseMatrix<float> east, |
|||
DenseMatrix<float> northEast) |
|||
{ |
|||
this.North = north; |
|||
this.NorthWest = northWest; |
|||
this.West = west; |
|||
this.SouthWest = southWest; |
|||
this.South = south; |
|||
this.SouthEast = southEast; |
|||
this.East = east; |
|||
this.NorthEast = northEast; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the North gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> North { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthWest gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> NorthWest { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the West gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> West { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthWest gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> SouthWest { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the South gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> South { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthEast gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> SouthEast { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the East gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> East { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthEast gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> NorthEast { get; } |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetectorCompassKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetectorCompassKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetectorCompassKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator ==(EdgeDetectorCompassKernel left, EdgeDetectorCompassKernel right) |
|||
=> left.Equals(right); |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetectorCompassKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetectorCompassKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetectorCompassKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator !=(EdgeDetectorCompassKernel left, EdgeDetectorCompassKernel right) |
|||
=> !(left == right); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) => obj is EdgeDetectorCompassKernel kernel && this.Equals(kernel); |
|||
|
|||
/// <inheritdoc/>
|
|||
public bool Equals(EdgeDetectorCompassKernel other) => this.North.Equals(other.North) && this.NorthWest.Equals(other.NorthWest) && this.West.Equals(other.West) && this.SouthWest.Equals(other.SouthWest) && this.South.Equals(other.South) && this.SouthEast.Equals(other.SouthEast) && this.East.Equals(other.East) && this.NorthEast.Equals(other.NorthEast); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() |
|||
=> HashCode.Combine( |
|||
this.North, |
|||
this.NorthWest, |
|||
this.West, |
|||
this.SouthWest, |
|||
this.South, |
|||
this.SouthEast, |
|||
this.East, |
|||
this.NorthEast); |
|||
|
|||
internal DenseMatrix<float>[] Flatten() => |
|||
new[] |
|||
{ |
|||
this.North, this.NorthWest, this.West, this.SouthWest, |
|||
this.South, this.SouthEast, this.East, this.NorthEast |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,78 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Represents an edge detection convolution kernel consisting of a single 2D gradient operator.
|
|||
/// </summary>
|
|||
public readonly struct EdgeDetectorKernel : IEquatable<EdgeDetectorKernel> |
|||
{ |
|||
/// <summary>
|
|||
/// An edge detection kernel containing a 3x3 Laplacian operator.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel Laplacian3x3 = new EdgeDetectorKernel(LaplacianKernels.Laplacian3x3); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing a 5x5 Laplacian operator.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel Laplacian5x5 = new EdgeDetectorKernel(LaplacianKernels.Laplacian5x5); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing a Laplacian of Gaussian operator.
|
|||
/// <see href="http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html"/>.
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel LaplacianOfGaussian = new EdgeDetectorKernel(LaplacianKernels.LaplacianOfGaussianXY); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EdgeDetectorKernel"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="kernelXY">The 2D gradient operator.</param>
|
|||
public EdgeDetectorKernel(DenseMatrix<float> kernelXY) |
|||
=> this.KernelXY = kernelXY; |
|||
|
|||
/// <summary>
|
|||
/// Gets the 2D gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> KernelXY { get; } |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetectorKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetectorKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetectorKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator ==(EdgeDetectorKernel left, EdgeDetectorKernel right) |
|||
=> left.Equals(right); |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetectorKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetectorKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetectorKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator !=(EdgeDetectorKernel left, EdgeDetectorKernel right) |
|||
=> !(left == right); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
=> obj is EdgeDetectorKernel kernel && this.Equals(kernel); |
|||
|
|||
/// <inheritdoc/>
|
|||
public bool Equals(EdgeDetectorKernel other) |
|||
=> this.KernelXY.Equals(other.KernelXY); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() => this.KernelXY.GetHashCode(); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using the Kirsch operator filter.
|
|||
/// See <see href="http://en.wikipedia.org/wiki/Kirsch_operator"/>.
|
|||
/// </summary>
|
|||
public sealed class KirschProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="KirschProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public KirschProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetectorCompassProcessor<TPixel>(configuration, new KirschKernels(), this.Grayscale, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Laplacian 3x3 operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
|
|||
/// </summary>
|
|||
public sealed class Laplacian3x3Processor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Laplacian3x3Processor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public Laplacian3x3Processor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetectorProcessor<TPixel>(configuration, LaplacianKernels.Laplacian3x3, this.Grayscale, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection processing using the Laplacian 5x5 operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>.
|
|||
/// </summary>
|
|||
public sealed class Laplacian5x5Processor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Laplacian5x5Processor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public Laplacian5x5Processor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetectorProcessor<TPixel>(configuration, LaplacianKernels.Laplacian5x5, this.Grayscale, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Laplacian of Gaussian operator filter.
|
|||
/// See <see href="http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html"/>.
|
|||
/// </summary>
|
|||
public sealed class LaplacianOfGaussianProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="LaplacianOfGaussianProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public LaplacianOfGaussianProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetectorProcessor<TPixel>(configuration, LaplacianKernels.LaplacianOfGaussianXY, this.Grayscale, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using the Prewitt operator filter.
|
|||
/// See <see href="http://en.wikipedia.org/wiki/Prewitt_operator"/>.
|
|||
/// </summary>
|
|||
public sealed class PrewittProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="PrewittProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public PrewittProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetector2DProcessor<TPixel>( |
|||
configuration, |
|||
PrewittKernels.PrewittX, |
|||
PrewittKernels.PrewittY, |
|||
this.Grayscale, |
|||
source, |
|||
sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection processing using the Roberts Cross operator filter.
|
|||
/// See <see href="http://en.wikipedia.org/wiki/Roberts_cross"/>.
|
|||
/// </summary>
|
|||
public sealed class RobertsCrossProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="RobertsCrossProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public RobertsCrossProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetector2DProcessor<TPixel>( |
|||
configuration, |
|||
RobertsCrossKernels.RobertsCrossX, |
|||
RobertsCrossKernels.RobertsCrossY, |
|||
this.Grayscale, |
|||
source, |
|||
sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using the Robinson operator filter.
|
|||
/// See <see href="http://www.tutorialspoint.com/dip/Robinson_Compass_Mask.htm"/>.
|
|||
/// </summary>
|
|||
public sealed class RobinsonProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="RobinsonProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public RobinsonProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetectorCompassProcessor<TPixel>(configuration, new RobinsonKernels(), this.Grayscale, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection processing using the Scharr operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator#Alternative_operators"/>
|
|||
/// </summary>
|
|||
public sealed class ScharrProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ScharrProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public ScharrProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetector2DProcessor<TPixel>( |
|||
configuration, |
|||
ScharrKernels.ScharrX, |
|||
ScharrKernels.ScharrY, |
|||
this.Grayscale, |
|||
source, |
|||
sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using the Sobel operator filter.
|
|||
/// See <see href="http://en.wikipedia.org/wiki/Sobel_operator"/>.
|
|||
/// </summary>
|
|||
public sealed class SobelProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="SobelProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public SobelProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetector2DProcessor<TPixel>( |
|||
configuration, |
|||
SobelKernels.SobelX, |
|||
SobelKernels.SobelY, |
|||
this.Grayscale, |
|||
source, |
|||
sourceRectangle); |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue