📷 A modern, cross-platform, 2D Graphics library for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

50 lines
1.7 KiB

// <copyright file="ScharrProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Processing.Processors
{
using System;
using System.Diagnostics.CodeAnalysis;
/// <summary>
/// The Scharr operator filter.
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator#Alternative_operators"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")]
public class ScharrProcessor<TColor> : EdgeDetector2DProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The horizontal gradient operator.
/// </summary>
private static readonly Fast2DArray<float> ScharrX =
new Fast2DArray<float>(new float[,]
{
{ -3, 0, 3 },
{ -10, 0, 10 },
{ -3, 0, 3 }
});
/// <summary>
/// The vertical gradient operator.
/// </summary>
private static readonly Fast2DArray<float> ScharrY =
new Fast2DArray<float>(new float[,]
{
{ 3, 10, 3 },
{ 0, 0, 0 },
{ -3, -10, -3 }
});
/// <summary>
/// Initializes a new instance of the <see cref="ScharrProcessor{TColor}"/> class.
/// </summary>
public ScharrProcessor()
: base(ScharrX, ScharrY)
{
}
}
}