// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Processing.Processors { using System; /// /// Defines a sampler that detects edges within an image using two one-dimensional matrices. /// /// The pixel format. public abstract class EdgeDetector2DProcessor : ImageProcessor, IEdgeDetectorProcessor where TColor : struct, IPackedPixel, IEquatable { /// /// Initializes a new instance of the class. /// /// The horizontal gradient operator. /// The vertical gradient operator. protected EdgeDetector2DProcessor(Fast2DArray kernelX, Fast2DArray kernelY) { this.KernelX = kernelX; this.KernelY = kernelY; } /// /// Gets the horizontal gradient operator. /// public Fast2DArray KernelX { get; } /// /// Gets the vertical gradient operator. /// public Fast2DArray KernelY { get; } /// public bool Grayscale { get; set; } /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { new Convolution2DProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); } /// protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { if (this.Grayscale) { new GrayscaleBt709Processor().Apply(source, sourceRectangle); } } } }