Browse Source

Binarization, Convolution, DIthering, Effects & Filters

pull/486/head
James Jackson-South 8 years ago
parent
commit
b7df3c1090
  1. 2
      ImageSharp.ruleset
  2. 2
      src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
  3. 2
      src/ImageSharp.Drawing/Processors/FillProcessor.cs
  4. 2
      src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
  5. 2
      src/ImageSharp/Dithering/ErrorDiffusion/Diffusers.cs
  6. 2
      src/ImageSharp/Dithering/Ordered/Ditherers.cs
  7. 6
      src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs
  8. 2
      src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs
  9. 2
      src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegColorSpace.cs
  10. 6
      src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs
  11. 4
      src/ImageSharp/Formats/Png/PngDecoder.cs
  12. 2
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  13. 2
      src/ImageSharp/IImageProcessor.cs
  14. 5
      src/ImageSharp/ImageSharp.csproj
  15. 10
      src/ImageSharp/Numerics/ValueSize.cs
  16. 28
      src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs
  17. 28
      src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs
  18. 28
      src/ImageSharp/Processing/Binarization/BinaryThresholdExtensions.cs
  19. 4
      src/ImageSharp/Processing/Binarization/Processors/BinaryErrorDiffusionProcessor.cs
  20. 4
      src/ImageSharp/Processing/Binarization/Processors/BinaryOrderedDitherProcessor.cs
  21. 4
      src/ImageSharp/Processing/Binarization/Processors/BinaryThresholdProcessor.cs
  22. 75
      src/ImageSharp/Processing/ColorMatrix/Lomograph.cs
  23. 75
      src/ImageSharp/Processing/ColorMatrix/Polaroid.cs
  24. 13
      src/ImageSharp/Processing/Convolution/BoxBlurExtensions.cs
  25. 72
      src/ImageSharp/Processing/Convolution/DetectEdgesExtensions.cs
  26. 14
      src/ImageSharp/Processing/Convolution/EdgeDetectionOperators.cs
  27. 12
      src/ImageSharp/Processing/Convolution/GaussianBlurExtensions.cs
  28. 12
      src/ImageSharp/Processing/Convolution/GaussianSharpenExtensions.cs
  29. 8
      src/ImageSharp/Processing/Convolution/Processors/BoxBlurProcessor.cs
  30. 4
      src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs
  31. 4
      src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs
  32. 4
      src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs
  33. 15
      src/ImageSharp/Processing/Convolution/Processors/EdgeDetector2DProcessor.cs
  34. 22
      src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorCompassProcessor.cs
  35. 17
      src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorProcessor.cs
  36. 24
      src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs
  37. 26
      src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs
  38. 7
      src/ImageSharp/Processing/Convolution/Processors/IEdgeDetectorProcessor.cs
  39. 35
      src/ImageSharp/Processing/Convolution/Processors/KayyaliKernels.cs
  40. 24
      src/ImageSharp/Processing/Convolution/Processors/KayyaliProcessor.cs
  41. 49
      src/ImageSharp/Processing/Convolution/Processors/KirschProcessor.cs
  42. 101
      src/ImageSharp/Processing/Convolution/Processors/KirshKernels.cs
  43. 25
      src/ImageSharp/Processing/Convolution/Processors/Laplacian3x3Processor.cs
  44. 25
      src/ImageSharp/Processing/Convolution/Processors/Laplacian5x5Processor.cs
  45. 40
      src/ImageSharp/Processing/Convolution/Processors/LaplacianKernelFactory.cs
  46. 36
      src/ImageSharp/Processing/Convolution/Processors/LaplacianKernels.cs
  47. 25
      src/ImageSharp/Processing/Convolution/Processors/LaplacianOfGaussianProcessor.cs
  48. 35
      src/ImageSharp/Processing/Convolution/Processors/PrewittKernels.cs
  49. 25
      src/ImageSharp/Processing/Convolution/Processors/PrewittProcessor.cs
  50. 33
      src/ImageSharp/Processing/Convolution/Processors/RobertsCrossKernels.cs
  51. 25
      src/ImageSharp/Processing/Convolution/Processors/RobertsCrossProcessor.cs
  52. 101
      src/ImageSharp/Processing/Convolution/Processors/RobinsonKernels.cs
  53. 50
      src/ImageSharp/Processing/Convolution/Processors/RobinsonProcessor.cs
  54. 35
      src/ImageSharp/Processing/Convolution/Processors/ScharrKernels.cs
  55. 25
      src/ImageSharp/Processing/Convolution/Processors/ScharrProcessor.cs
  56. 35
      src/ImageSharp/Processing/Convolution/Processors/SobelKernels.cs
  57. 26
      src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.cs
  58. 10
      src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs
  59. 10
      src/ImageSharp/Processing/Dithering/DitherExtensions.cs
  60. 4
      src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs
  61. 4
      src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs
  62. 4
      src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs
  63. 2
      src/ImageSharp/Processing/Dithering/Processors/PixelPair.cs
  64. 21
      src/ImageSharp/Processing/Effects/OilPaintExtensions.cs
  65. 15
      src/ImageSharp/Processing/Effects/PixelateExtensions.cs
  66. 6
      src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs
  67. 6
      src/ImageSharp/Processing/Effects/Processors/PixelateProcessor.cs
  68. 18
      src/ImageSharp/Processing/Filters/BlackWhiteExtensions.cs
  69. 13
      src/ImageSharp/Processing/Filters/BrightnessExtensions.cs
  70. 2
      src/ImageSharp/Processing/Filters/ColorBlindness.cs
  71. 24
      src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs
  72. 12
      src/ImageSharp/Processing/Filters/ContrastExtensions.cs
  73. 18
      src/ImageSharp/Processing/Filters/FilterExtensions.cs
  74. 33
      src/ImageSharp/Processing/Filters/GrayscaleExtensions.cs
  75. 6
      src/ImageSharp/Processing/Filters/GrayscaleMode.cs
  76. 20
      src/ImageSharp/Processing/Filters/HueExtensions.cs
  77. 15
      src/ImageSharp/Processing/Filters/InvertExtensions.cs
  78. 20
      src/ImageSharp/Processing/Filters/KodachromeExtensions.cs
  79. 38
      src/ImageSharp/Processing/Filters/LomographExtensions.cs
  80. 8
      src/ImageSharp/Processing/Filters/MatrixFilters.cs
  81. 13
      src/ImageSharp/Processing/Filters/OpacityExtensions.cs
  82. 38
      src/ImageSharp/Processing/Filters/PolaroidExtensions.cs
  83. 2
      src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs
  84. 2
      src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs
  85. 2
      src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs
  86. 4
      src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs
  87. 4
      src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs
  88. 2
      src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs
  89. 2
      src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs
  90. 4
      src/ImageSharp/Processing/Filters/Processors/FilterProcessor.cs
  91. 4
      src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs
  92. 2
      src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs
  93. 2
      src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs
  94. 2
      src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs
  95. 2
      src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs
  96. 33
      src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs
  97. 2
      src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs
  98. 35
      src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs
  99. 2
      src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs
  100. 3
      src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs

2
ImageSharp.ruleset

@ -7,5 +7,7 @@
temp remove the header requirement as stylecop is currently failing to read the stylecop.json file from 'dotnet build' temp remove the header requirement as stylecop is currently failing to read the stylecop.json file from 'dotnet build'
<Rule Id="SA1636" Action="None" />--> <Rule Id="SA1636" Action="None" />-->
<Rule Id="SA1633" Action="None" /> <Rule Id="SA1633" Action="None" />
<!--1.1.0-beta6 incorrectly throws a wobbler here for multiline matrices-->
<Rule Id="SA1500" Action="None" />
</Rules> </Rules>
</RuleSet> </RuleSet>

2
src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs

@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
public Point Location { get; } public Point Location { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
Image<TPixel> targetImage = this.Image; Image<TPixel> targetImage = this.Image;
PixelBlender<TPixel> blender = this.Blender; PixelBlender<TPixel> blender = this.Blender;

2
src/ImageSharp.Drawing/Processors/FillProcessor.cs

@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
int startX = sourceRectangle.X; int startX = sourceRectangle.X;
int endX = sourceRectangle.Right; int endX = sourceRectangle.Right;

2
src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs

@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
public GraphicsOptions Options { get; } public GraphicsOptions Options { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
Region region = this.Region; Region region = this.Region;
Rectangle rect = region.Bounds; Rectangle rect = region.Bounds;

2
src/ImageSharp/Dithering/ErrorDiffusion/KnownDiffusers.cs → src/ImageSharp/Dithering/ErrorDiffusion/Diffusers.cs

@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Dithering
/// <summary> /// <summary>
/// Contains reusable static instances of known error diffusion algorithms /// Contains reusable static instances of known error diffusion algorithms
/// </summary> /// </summary>
public static class KnownDiffusers public static class Diffusers
{ {
/// <summary> /// <summary>
/// Gets the error diffuser that implements the Atkinson algorithm. /// Gets the error diffuser that implements the Atkinson algorithm.

2
src/ImageSharp/Dithering/Ordered/KnownDitherers.cs → src/ImageSharp/Dithering/Ordered/Ditherers.cs

@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Dithering
/// <summary> /// <summary>
/// Contains reusable static instances of known ordered dither matrices /// Contains reusable static instances of known ordered dither matrices
/// </summary> /// </summary>
public class KnownDitherers public class Ditherers
{ {
/// <summary> /// <summary>
/// Gets the order ditherer using the 2x2 Bayer dithering matrix /// Gets the order ditherer using the 2x2 Bayer dithering matrix

6
src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs

@ -8,10 +8,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
{ {
internal abstract partial class JpegColorConverter internal abstract partial class JpegColorConverter
{ {
internal class FromGrayScale : ColorConverters.JpegColorConverter internal class FromGrayscale : ColorConverters.JpegColorConverter
{ {
public FromGrayScale() public FromGrayscale()
: base(JpegColorSpace.GrayScale) : base(JpegColorSpace.Grayscale)
{ {
} }

2
src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs

@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
/// </summary> /// </summary>
private static readonly JpegColorConverter[] Converters = private static readonly JpegColorConverter[] Converters =
{ {
GetYCbCrConverter(), new FromYccK(), new FromCmyk(), new FromGrayScale(), new FromRgb() GetYCbCrConverter(), new FromYccK(), new FromCmyk(), new FromGrayscale(), new FromRgb()
}; };
/// <summary> /// <summary>

2
src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegColorSpace.cs

@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
{ {
Undefined = 0, Undefined = 0,
GrayScale, Grayscale,
Ycck, Ycck,

6
src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs

@ -640,7 +640,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
switch (remaining) switch (remaining)
{ {
case 6 + (3 * 1): // Grayscale image. case 6 + (3 * 1): // grayscale image.
this.ComponentCount = 1; this.ComponentCount = 1;
break; break;
case 6 + (3 * 3): // YCbCr or RGB image. case 6 + (3 * 3): // YCbCr or RGB image.
@ -767,7 +767,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
switch (this.ComponentCount) switch (this.ComponentCount)
{ {
case 1: case 1:
return JpegColorSpace.GrayScale; return JpegColorSpace.Grayscale;
case 3: case 3:
if (!this.isAdobe || this.adobe.ColorTransform == OrigJpegConstants.Adobe.ColorTransformYCbCr) if (!this.isAdobe || this.adobe.ColorTransform == OrigJpegConstants.Adobe.ColorTransformYCbCr)
{ {
@ -790,7 +790,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
} }
throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}." throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}."
+ "JpegDecoder only supports YCbCr, RGB, YccK, CMYK and Grayscale color spaces."); + "JpegDecoder only supports YCbCr, RGB, YccK, CMYK and grayscale color spaces.");
} }
private Image<TPixel> PostProcessIntoImage<TPixel>() private Image<TPixel> PostProcessIntoImage<TPixel>()

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

@ -20,8 +20,8 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <list type="bullet"> /// <list type="bullet">
/// <item>RGBA (True color) with alpha (8 bit).</item> /// <item>RGBA (True color) with alpha (8 bit).</item>
/// <item>RGB (True color) without alpha (8 bit).</item> /// <item>RGB (True color) without alpha (8 bit).</item>
/// <item>Grayscale with alpha (8 bit).</item> /// <item>grayscale with alpha (8 bit).</item>
/// <item>Grayscale without alpha (8 bit).</item> /// <item>grayscale without alpha (8 bit).</item>
/// <item>Palette Index with alpha (8 bit).</item> /// <item>Palette Index with alpha (8 bit).</item>
/// <item>Palette Index without alpha (8 bit).</item> /// <item>Palette Index without alpha (8 bit).</item>
/// </list> /// </list>

2
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.Formats.Png
private Rgb24 rgb24Trans; private Rgb24 rgb24Trans;
/// <summary> /// <summary>
/// Represents any color in a Grayscale encoded png that should be transparent /// Represents any color in a grayscale encoded png that should be transparent
/// </summary> /// </summary>
private byte intensityTrans; private byte intensityTrans;

2
src/ImageSharp/IImageProcessor.cs

@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp
/// <paramref name="source"/> is null. /// <paramref name="source"/> is null.
/// </exception> /// </exception>
/// <exception cref="System.ArgumentException"> /// <exception cref="System.ArgumentException">
/// <paramref name="sourceRectangle"/> doesnt fit the dimension of the image. /// <paramref name="sourceRectangle"/> doesn't fit the dimension of the image.
/// </exception> /// </exception>
void Apply(Image<TPixel> source, Rectangle sourceRectangle); void Apply(Image<TPixel> source, Rectangle sourceRectangle);
} }

5
src/ImageSharp/ImageSharp.csproj

@ -37,7 +37,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="SixLabors.Core" Version="1.0.0-ci0005" /> <PackageReference Include="SixLabors.Core" Version="1.0.0-ci0005" />
<AdditionalFiles Include="..\..\stylecop.json" /> <AdditionalFiles Include="..\..\stylecop.json" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004"> <PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta006">
<PrivateAssets>All</PrivateAssets> <PrivateAssets>All</PrivateAssets>
</PackageReference> </PackageReference>
<PackageReference Include="System.Buffers" Version="4.4.0" /> <PackageReference Include="System.Buffers" Version="4.4.0" />
@ -126,7 +126,4 @@
<DependentUpon>PorterDuffFunctions.Generated.tt</DependentUpon> <DependentUpon>PorterDuffFunctions.Generated.tt</DependentUpon>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Formats\Jpeg\GolangPort\Utils\" />
</ItemGroup>
</Project> </Project>

10
src/ImageSharp/Numerics/ValueSize.cs

@ -61,9 +61,9 @@ namespace SixLabors.ImageSharp
/// <summary> /// <summary>
/// Implicitly converts a float into an absolute value /// Implicitly converts a float into an absolute value
/// </summary> /// </summary>
/// <param name="d">the vlaue to use as the absolute figure.</param> /// <param name="f">the value to use as the absolute figure.</param>
public static implicit operator ValueSize(float d) public static implicit operator ValueSize(float f)
=> Absolute(d); => Absolute(f);
/// <summary> /// <summary>
/// Create a new ValueSize with as a PercentageOfWidth type with value set to percentage. /// Create a new ValueSize with as a PercentageOfWidth type with value set to percentage.
@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp
/// Calculates the specified size. /// Calculates the specified size.
/// </summary> /// </summary>
/// <param name="size">The size.</param> /// <param name="size">The size.</param>
/// <returns>The calucalted value</returns> /// <returns>The calculated value</returns>
public float Calculate(Size size) public float Calculate(Size size)
{ {
switch (this.Type) switch (this.Type)
@ -123,7 +123,7 @@ namespace SixLabors.ImageSharp
/// <inheritdoc/> /// <inheritdoc/>
public bool Equals(ValueSize other) public bool Equals(ValueSize other)
{ {
return this.Type == other.Type && this.Value == other.Value; return this.Type == other.Type && this.Value.Equals(other.Value);
} }
} }
} }

28
src/ImageSharp/Processing/Binarization/BinaryDiffuse.cs → src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs

@ -3,15 +3,15 @@
using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Binarization.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Binarization
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds binary diffusion extensions to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class BinaryDiffuseExtensions
{ {
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using error diffusion. /// Dithers the image reducing it to two colors using error diffusion.
@ -23,10 +23,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold) public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold));
source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold));
return source;
}
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using error diffusion. /// Dithers the image reducing it to two colors using error diffusion.
@ -41,10 +38,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold), rectangle);
source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold), rectangle);
return source;
}
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using error diffusion. /// Dithers the image reducing it to two colors using error diffusion.
@ -58,10 +52,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, TPixel upperColor, TPixel lowerColor) public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, TPixel upperColor, TPixel lowerColor)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold, upperColor, lowerColor));
source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold, upperColor, lowerColor));
return source;
}
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using error diffusion. /// Dithers the image reducing it to two colors using error diffusion.
@ -78,9 +69,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, TPixel upperColor, TPixel lowerColor, Rectangle rectangle) public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, TPixel upperColor, TPixel lowerColor, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold, upperColor, lowerColor), rectangle);
source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold, upperColor, lowerColor), rectangle);
return source;
}
} }
} }

28
src/ImageSharp/Processing/Binarization/BinaryDither.cs → src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs

@ -3,15 +3,15 @@
using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Binarization.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Binarization
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds binary dithering extensions to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class BinaryDitherExtensions
{ {
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using ordered dithering. /// Dithers the image reducing it to two colors using ordered dithering.
@ -22,10 +22,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither) public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither));
source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither));
return source;
}
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using ordered dithering. /// Dithers the image reducing it to two colors using ordered dithering.
@ -38,10 +35,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, TPixel upperColor, TPixel lowerColor) public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, TPixel upperColor, TPixel lowerColor)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither, upperColor, lowerColor));
source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither, upperColor, lowerColor));
return source;
}
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using ordered dithering. /// Dithers the image reducing it to two colors using ordered dithering.
@ -55,10 +49,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, Rectangle rectangle) public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither), rectangle);
source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither), rectangle);
return source;
}
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using ordered dithering. /// Dithers the image reducing it to two colors using ordered dithering.
@ -74,9 +65,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, TPixel upperColor, TPixel lowerColor, Rectangle rectangle) public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, TPixel upperColor, TPixel lowerColor, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither, upperColor, lowerColor), rectangle);
source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither, upperColor, lowerColor), rectangle);
return source;
}
} }
} }

28
src/ImageSharp/Processing/Binarization/BinaryThreshold.cs → src/ImageSharp/Processing/Binarization/BinaryThresholdExtensions.cs

@ -2,15 +2,15 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Binarization.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Binarization
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds binary thresholding extensions to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class BinaryThresholdExtensions
{ {
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold. /// Applies binarization to the image splitting the pixels at the given threshold.
@ -21,10 +21,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryThreshold<TPixel>(this IImageProcessingContext<TPixel> source, float threshold) public static IImageProcessingContext<TPixel> BinaryThreshold<TPixel>(this IImageProcessingContext<TPixel> source, float threshold)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryThresholdProcessor<TPixel>(threshold));
source.ApplyProcessor(new BinaryThresholdProcessor<TPixel>(threshold));
return source;
}
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold. /// Applies binarization to the image splitting the pixels at the given threshold.
@ -38,10 +35,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryThreshold<TPixel>(this IImageProcessingContext<TPixel> source, float threshold, Rectangle rectangle) public static IImageProcessingContext<TPixel> BinaryThreshold<TPixel>(this IImageProcessingContext<TPixel> source, float threshold, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryThresholdProcessor<TPixel>(threshold), rectangle);
source.ApplyProcessor(new BinaryThresholdProcessor<TPixel>(threshold), rectangle);
return source;
}
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold. /// Applies binarization to the image splitting the pixels at the given threshold.
@ -54,10 +48,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryThreshold<TPixel>(this IImageProcessingContext<TPixel> source, float threshold, TPixel upperColor, TPixel lowerColor) public static IImageProcessingContext<TPixel> BinaryThreshold<TPixel>(this IImageProcessingContext<TPixel> source, float threshold, TPixel upperColor, TPixel lowerColor)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryThresholdProcessor<TPixel>(threshold, upperColor, lowerColor));
source.ApplyProcessor(new BinaryThresholdProcessor<TPixel>(threshold, upperColor, lowerColor));
return source;
}
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold. /// Applies binarization to the image splitting the pixels at the given threshold.
@ -73,9 +64,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryThreshold<TPixel>(this IImageProcessingContext<TPixel> source, float threshold, TPixel upperColor, TPixel lowerColor, Rectangle rectangle) public static IImageProcessingContext<TPixel> BinaryThreshold<TPixel>(this IImageProcessingContext<TPixel> source, float threshold, TPixel upperColor, TPixel lowerColor, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BinaryThresholdProcessor<TPixel>(threshold, upperColor, lowerColor), rectangle);
source.ApplyProcessor(new BinaryThresholdProcessor<TPixel>(threshold, upperColor, lowerColor), rectangle);
return source;
}
} }
} }

4
src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs → src/ImageSharp/Processing/Binarization/Processors/BinaryErrorDiffusionProcessor.cs

@ -8,7 +8,7 @@ using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Binarization.Processors
{ {
/// <summary> /// <summary>
/// Performs binary threshold filtering against an image using error diffusion. /// Performs binary threshold filtering against an image using error diffusion.
@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public TPixel LowerColor { get; } public TPixel LowerColor { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
float threshold = this.Threshold * 255F; float threshold = this.Threshold * 255F;
var rgba = default(Rgba32); var rgba = default(Rgba32);

4
src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs → src/ImageSharp/Processing/Binarization/Processors/BinaryOrderedDitherProcessor.cs

@ -8,7 +8,7 @@ using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Binarization.Processors
{ {
/// <summary> /// <summary>
/// Performs binary threshold filtering against an image using ordered dithering. /// Performs binary threshold filtering against an image using ordered dithering.
@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public TPixel LowerColor { get; } public TPixel LowerColor { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
var rgba = default(Rgba32); var rgba = default(Rgba32);
bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8); bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8);

4
src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs → src/ImageSharp/Processing/Binarization/Processors/BinaryThresholdProcessor.cs

@ -8,7 +8,7 @@ using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Binarization.Processors
{ {
/// <summary> /// <summary>
/// Performs simple binary threshold filtering against an image. /// Performs simple binary threshold filtering against an image.
@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public TPixel LowerColor { get; set; } public TPixel LowerColor { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
float threshold = this.Threshold * 255F; float threshold = this.Threshold * 255F;
TPixel upper = this.UpperColor; TPixel upper = this.UpperColor;

75
src/ImageSharp/Processing/ColorMatrix/Lomograph.cs

@ -1,75 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
{
return Lomograph(source, GraphicsOptions.Default);
}
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
return Lomograph(source, rectangle, GraphicsOptions.Default);
}
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The options effecting pixel blending.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new LomographProcessor<TPixel>(source.MemoryManager, options));
return source;
}
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="options">The options effecting pixel blending.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new LomographProcessor<TPixel>(source.MemoryManager, options), rectangle);
return source;
}
}
}

75
src/ImageSharp/Processing/ColorMatrix/Polaroid.cs

@ -1,75 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
{
return Polaroid(source, GraphicsOptions.Default);
}
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
return Polaroid(source, rectangle, GraphicsOptions.Default);
}
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The options effecting pixel blending.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new PolaroidProcessor<TPixel>(source.MemoryManager, options));
return source;
}
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="options">The options effecting pixel blending.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new PolaroidProcessor<TPixel>(source.MemoryManager, options), rectangle);
return source;
}
}
}

13
src/ImageSharp/Processing/Convolution/BoxBlur.cs → src/ImageSharp/Processing/Convolution/BoxBlurExtensions.cs

@ -1,17 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Convolution.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Convolution
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds box blurring extensions to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class BoxBlurExtensions
{ {
/// <summary> /// <summary>
/// Applies a box blur to the image. /// Applies a box blur to the image.
@ -21,7 +20,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BoxBlur<TPixel>(this IImageProcessingContext<TPixel> source) public static IImageProcessingContext<TPixel> BoxBlur<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new BoxBlurProcessor<TPixel>(7)); => source.ApplyProcessor(new BoxBlurProcessor<TPixel>());
/// <summary> /// <summary>
/// Applies a box blur to the image. /// Applies a box blur to the image.
@ -48,4 +47,4 @@ namespace SixLabors.ImageSharp
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new BoxBlurProcessor<TPixel>(radius), rectangle); => source.ApplyProcessor(new BoxBlurProcessor<TPixel>(radius), rectangle);
} }
} }

72
src/ImageSharp/Processing/Convolution/DetectEdges.cs → src/ImageSharp/Processing/Convolution/DetectEdgesExtensions.cs

@ -1,35 +1,31 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Convolution.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Convolution
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds edge detection extensions to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class DetectEdgesExtensions
{ {
/// <summary> /// <summary>
/// Detects any edges within the image. Uses the <see cref="SobelProcessor{TPixel}"/> filter /// Detects any edges within the image. Uses the <see cref="SobelProcessor{TPixel}"/> filter
/// operating in Grayscale mode. /// operating in grayscale mode.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DetectEdges<TPixel>(this IImageProcessingContext<TPixel> source) public static IImageProcessingContext<TPixel> DetectEdges<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => DetectEdges(source, new SobelProcessor<TPixel>(true));
return DetectEdges(source, new SobelProcessor<TPixel> { Grayscale = true });
}
/// <summary> /// <summary>
/// Detects any edges within the image. Uses the <see cref="SobelProcessor{TPixel}"/> filter /// Detects any edges within the image. Uses the <see cref="SobelProcessor{TPixel}"/> filter
/// operating in Grayscale mode. /// operating in grayscale mode.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
@ -39,9 +35,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DetectEdges<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle) public static IImageProcessingContext<TPixel> DetectEdges<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => DetectEdges(source, rectangle, new SobelProcessor<TPixel>(true));
return DetectEdges(source, rectangle, new SobelProcessor<TPixel> { Grayscale = true });
}
/// <summary> /// <summary>
/// Detects any edges within the image. /// Detects any edges within the image.
@ -50,7 +44,7 @@ namespace SixLabors.ImageSharp
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="filter">The filter for detecting edges.</param> /// <param name="filter">The filter for detecting edges.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DetectEdges<TPixel>(this IImageProcessingContext<TPixel> source, EdgeDetection filter) public static IImageProcessingContext<TPixel> DetectEdges<TPixel>(this IImageProcessingContext<TPixel> source, EdgeDetectionOperators filter)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> DetectEdges(source, GetProcessor<TPixel>(filter, true)); => DetectEdges(source, GetProcessor<TPixel>(filter, true));
@ -60,9 +54,9 @@ namespace SixLabors.ImageSharp
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="filter">The filter for detecting edges.</param> /// <param name="filter">The filter for detecting edges.</param>
/// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param> /// <param name="grayscale">Whether to convert the image to grayscale first. Defaults to true.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DetectEdges<TPixel>(this IImageProcessingContext<TPixel> source, EdgeDetection filter, bool grayscale) public static IImageProcessingContext<TPixel> DetectEdges<TPixel>(this IImageProcessingContext<TPixel> source, EdgeDetectionOperators filter, bool grayscale)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> DetectEdges(source, GetProcessor<TPixel>(filter, grayscale)); => DetectEdges(source, GetProcessor<TPixel>(filter, grayscale));
@ -75,9 +69,9 @@ namespace SixLabors.ImageSharp
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param> /// <param name="grayscale">Whether to convert the image to grayscale first. Defaults to true.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DetectEdges<TPixel>(this IImageProcessingContext<TPixel> source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) public static IImageProcessingContext<TPixel> DetectEdges<TPixel>(this IImageProcessingContext<TPixel> source, EdgeDetectionOperators filter, Rectangle rectangle, bool grayscale = true)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> DetectEdges(source, rectangle, GetProcessor<TPixel>(filter, grayscale)); => DetectEdges(source, rectangle, GetProcessor<TPixel>(filter, grayscale));
@ -111,51 +105,51 @@ namespace SixLabors.ImageSharp
return source; return source;
} }
private static IEdgeDetectorProcessor<TPixel> GetProcessor<TPixel>(EdgeDetection filter, bool grayscale) private static IEdgeDetectorProcessor<TPixel> GetProcessor<TPixel>(EdgeDetectionOperators filter, bool grayscale)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
IEdgeDetectorProcessor<TPixel> processor; IEdgeDetectorProcessor<TPixel> processor;
switch (filter) switch (filter)
{ {
case EdgeDetection.Kayyali: case EdgeDetectionOperators.Kayyali:
processor = new KayyaliProcessor<TPixel> { Grayscale = grayscale }; processor = new KayyaliProcessor<TPixel>(grayscale);
break; break;
case EdgeDetection.Kirsch: case EdgeDetectionOperators.Kirsch:
processor = new KirschProcessor<TPixel> { Grayscale = grayscale }; processor = new KirschProcessor<TPixel>(grayscale);
break; break;
case EdgeDetection.Lapacian3X3: case EdgeDetectionOperators.Laplacian3x3:
processor = new Laplacian3X3Processor<TPixel> { Grayscale = grayscale }; processor = new Laplacian3x3Processor<TPixel>(grayscale);
break; break;
case EdgeDetection.Lapacian5X5: case EdgeDetectionOperators.Laplacian5x5:
processor = new Laplacian5X5Processor<TPixel> { Grayscale = grayscale }; processor = new Laplacian5x5Processor<TPixel>(grayscale);
break; break;
case EdgeDetection.LaplacianOfGaussian: case EdgeDetectionOperators.LaplacianOfGaussian:
processor = new LaplacianOfGaussianProcessor<TPixel> { Grayscale = grayscale }; processor = new LaplacianOfGaussianProcessor<TPixel>(grayscale);
break; break;
case EdgeDetection.Prewitt: case EdgeDetectionOperators.Prewitt:
processor = new PrewittProcessor<TPixel> { Grayscale = grayscale }; processor = new PrewittProcessor<TPixel>(grayscale);
break; break;
case EdgeDetection.RobertsCross: case EdgeDetectionOperators.RobertsCross:
processor = new RobertsCrossProcessor<TPixel> { Grayscale = grayscale }; processor = new RobertsCrossProcessor<TPixel>(grayscale);
break; break;
case EdgeDetection.Robinson: case EdgeDetectionOperators.Robinson:
processor = new RobinsonProcessor<TPixel> { Grayscale = grayscale }; processor = new RobinsonProcessor<TPixel>(grayscale);
break; break;
case EdgeDetection.Scharr: case EdgeDetectionOperators.Scharr:
processor = new ScharrProcessor<TPixel> { Grayscale = grayscale }; processor = new ScharrProcessor<TPixel>(grayscale);
break; break;
default: default:
processor = new SobelProcessor<TPixel> { Grayscale = grayscale }; processor = new SobelProcessor<TPixel>(grayscale);
break; break;
} }

14
src/ImageSharp/Processing/Convolution/Options/EdgeDetection.cs → src/ImageSharp/Processing/Convolution/EdgeDetectionOperators.cs

@ -1,12 +1,12 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Convolution
{ {
/// <summary> /// <summary>
/// Enumerates the various types of defined edge detection filters. /// Enumerates the various types of defined edge detection filters.
/// </summary> /// </summary>
public enum EdgeDetection public enum EdgeDetectionOperators
{ {
/// <summary> /// <summary>
/// The Kayyali operator filter. /// The Kayyali operator filter.
@ -19,14 +19,14 @@ namespace SixLabors.ImageSharp.Processing
Kirsch, Kirsch,
/// <summary> /// <summary>
/// The Lapacian3X3 operator filter. /// The Laplacian3X3 operator filter.
/// </summary> /// </summary>
Lapacian3X3, Laplacian3x3,
/// <summary> /// <summary>
/// The Lapacian5X5 operator filter. /// The Laplacian5X5 operator filter.
/// </summary> /// </summary>
Lapacian5X5, Laplacian5x5,
/// <summary> /// <summary>
/// The LaplacianOfGaussian operator filter. /// The LaplacianOfGaussian operator filter.
@ -58,4 +58,4 @@ namespace SixLabors.ImageSharp.Processing
/// </summary> /// </summary>
Sobel Sobel
} }
} }

12
src/ImageSharp/Processing/Convolution/GaussianBlur.cs → src/ImageSharp/Processing/Convolution/GaussianBlurExtensions.cs

@ -1,18 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Convolution.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Convolution
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds Gaussian blurring extensions to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class GaussianBlurExtensions
{ {
/// <summary> /// <summary>
/// Applies a Gaussian blur to the image. /// Applies a Gaussian blur to the image.
@ -22,7 +20,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> GaussianBlur<TPixel>(this IImageProcessingContext<TPixel> source) public static IImageProcessingContext<TPixel> GaussianBlur<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new GaussianBlurProcessor<TPixel>(3f)); => source.ApplyProcessor(new GaussianBlurProcessor<TPixel>());
/// <summary> /// <summary>
/// Applies a Gaussian blur to the image. /// Applies a Gaussian blur to the image.

12
src/ImageSharp/Processing/Convolution/GaussianSharpen.cs → src/ImageSharp/Processing/Convolution/GaussianSharpenExtensions.cs

@ -1,18 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Convolution.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Convolution
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds Gaussian sharpening extensions to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class GaussianSharpenExtensions
{ {
/// <summary> /// <summary>
/// Applies a Gaussian sharpening filter to the image. /// Applies a Gaussian sharpening filter to the image.
@ -22,7 +20,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> GaussianSharpen<TPixel>(this IImageProcessingContext<TPixel> source) public static IImageProcessingContext<TPixel> GaussianSharpen<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new GaussianSharpenProcessor<TPixel>(3f)); => source.ApplyProcessor(new GaussianSharpenProcessor<TPixel>());
/// <summary> /// <summary>
/// Applies a Gaussian sharpening filter to the image. /// Applies a Gaussian sharpening filter to the image.

8
src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs → src/ImageSharp/Processing/Convolution/Processors/BoxBlurProcessor.cs

@ -1,15 +1,15 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{ {
/// <summary> /// <summary>
/// Applies a Box blur sampler to the image. /// Applies box blur processing to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class BoxBlurProcessor<TPixel> : ImageProcessor<TPixel> internal class BoxBlurProcessor<TPixel> : ImageProcessor<TPixel>
@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray<float> KernelY { get; } public Fast2DArray<float> KernelY { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
new Convolution2PassProcessor<TPixel>(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration); new Convolution2PassProcessor<TPixel>(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration);
} }

4
src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs → src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs

@ -12,7 +12,7 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Processors
{ {
/// <summary> /// <summary>
/// Defines a sampler that uses two one-dimensional matrices to perform convolution against an image. /// Defines a processor that uses two one-dimensional matrices to perform convolution against an image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class Convolution2DProcessor<TPixel> : ImageProcessor<TPixel> internal class Convolution2DProcessor<TPixel> : ImageProcessor<TPixel>
@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray<float> KernelY { get; } public Fast2DArray<float> KernelY { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
int kernelYHeight = this.KernelY.Height; int kernelYHeight = this.KernelY.Height;
int kernelYWidth = this.KernelY.Width; int kernelYWidth = this.KernelY.Width;

4
src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs → src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs

@ -13,7 +13,7 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Processors
{ {
/// <summary> /// <summary>
/// Defines a sampler that uses two one-dimensional matrices to perform two-pass convolution against an image. /// Defines a processor that uses two one-dimensional matrices to perform two-pass convolution against an image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class Convolution2PassProcessor<TPixel> : ImageProcessor<TPixel> internal class Convolution2PassProcessor<TPixel> : ImageProcessor<TPixel>
@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray<float> KernelY { get; } public Fast2DArray<float> KernelY { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
ParallelOptions parallelOptions = configuration.ParallelOptions; ParallelOptions parallelOptions = configuration.ParallelOptions;

4
src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs → src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs

@ -13,7 +13,7 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Processors
{ {
/// <summary> /// <summary>
/// Defines a sampler that uses a 2 dimensional matrix to perform convolution against an image. /// Defines a processor that uses a 2 dimensional matrix to perform convolution against an image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class ConvolutionProcessor<TPixel> : ImageProcessor<TPixel> internal class ConvolutionProcessor<TPixel> : ImageProcessor<TPixel>
@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray<float> KernelXY { get; } public Fast2DArray<float> KernelXY { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
int kernelLength = this.KernelXY.Height; int kernelLength = this.KernelXY.Height;
int radius = kernelLength >> 1; int radius = kernelLength >> 1;

15
src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs → src/ImageSharp/Processing/Convolution/Processors/EdgeDetector2DProcessor.cs

@ -1,15 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{ {
/// <summary> /// <summary>
/// Defines a sampler that detects edges within an image using two one-dimensional matrices. /// Defines a processor that detects edges within an image using two one-dimensional matrices.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal abstract class EdgeDetector2DProcessor<TPixel> : ImageProcessor<TPixel>, IEdgeDetectorProcessor<TPixel> internal abstract class EdgeDetector2DProcessor<TPixel> : ImageProcessor<TPixel>, IEdgeDetectorProcessor<TPixel>
@ -20,10 +21,12 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// </summary> /// </summary>
/// <param name="kernelX">The horizontal gradient operator.</param> /// <param name="kernelX">The horizontal gradient operator.</param>
/// <param name="kernelY">The vertical gradient operator.</param> /// <param name="kernelY">The vertical gradient operator.</param>
protected EdgeDetector2DProcessor(Fast2DArray<float> kernelX, Fast2DArray<float> kernelY) /// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
protected EdgeDetector2DProcessor(Fast2DArray<float> kernelX, Fast2DArray<float> kernelY, bool grayscale)
{ {
this.KernelX = kernelX; this.KernelX = kernelX;
this.KernelY = kernelY; this.KernelY = kernelY;
this.Grayscale = grayscale;
} }
/// <summary> /// <summary>
@ -40,13 +43,13 @@ namespace SixLabors.ImageSharp.Processing.Processors
public bool Grayscale { get; set; } public bool Grayscale { get; set; }
/// <inheritdoc /> /// <inheritdoc />
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
new Convolution2DProcessor<TPixel>(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration); new Convolution2DProcessor<TPixel>(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration);
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void BeforeApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void BeforeFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
if (this.Grayscale) if (this.Grayscale)
{ {

22
src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs → src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorCompassProcessor.cs

@ -4,20 +4,30 @@
using System; using System;
using System.Numerics; using System.Numerics;
using System.Threading.Tasks; using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{ {
/// <summary> /// <summary>
/// Defines a sampler that detects edges within an image using a eight two dimensional matrices. /// Defines a processor that detects edges within an image using a eight two dimensional matrices.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal abstract class EdgeDetectorCompassProcessor<TPixel> : ImageProcessor<TPixel>, IEdgeDetectorProcessor<TPixel> internal abstract class EdgeDetectorCompassProcessor<TPixel> : ImageProcessor<TPixel>, IEdgeDetectorProcessor<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary>
/// Initializes a new instance of the <see cref="EdgeDetectorCompassProcessor{TPixel}"/> class.
/// </summary>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
protected EdgeDetectorCompassProcessor(bool grayscale)
{
this.Grayscale = grayscale;
}
/// <summary> /// <summary>
/// Gets the North gradient operator /// Gets the North gradient operator
/// </summary> /// </summary>
@ -59,10 +69,10 @@ namespace SixLabors.ImageSharp.Processing.Processors
public abstract Fast2DArray<float> NorthEast { get; } public abstract Fast2DArray<float> NorthEast { get; }
/// <inheritdoc/> /// <inheritdoc/>
public bool Grayscale { get; set; } public bool Grayscale { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void BeforeApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void BeforeFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
if (this.Grayscale) if (this.Grayscale)
{ {
@ -71,7 +81,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
Fast2DArray<float>[] kernels = { this.North, this.NorthWest, this.West, this.SouthWest, this.South, this.SouthEast, this.East, this.NorthEast }; Fast2DArray<float>[] kernels = { this.North, this.NorthWest, this.West, this.SouthWest, this.South, this.SouthEast, this.East, this.NorthEast };

17
src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs → src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorProcessor.cs

@ -1,15 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{ {
/// <summary> /// <summary>
/// Defines a sampler that detects edges within an image using a single two dimensional matrix. /// Defines a processor that detects edges within an image using a single two dimensional matrix.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal abstract class EdgeDetectorProcessor<TPixel> : ImageProcessor<TPixel>, IEdgeDetectorProcessor<TPixel> internal abstract class EdgeDetectorProcessor<TPixel> : ImageProcessor<TPixel>, IEdgeDetectorProcessor<TPixel>
@ -19,13 +20,15 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Initializes a new instance of the <see cref="EdgeDetectorProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="EdgeDetectorProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="kernelXY">The 2d gradient operator.</param> /// <param name="kernelXY">The 2d gradient operator.</param>
protected EdgeDetectorProcessor(Fast2DArray<float> kernelXY) /// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
protected EdgeDetectorProcessor(Fast2DArray<float> kernelXY, bool grayscale)
{ {
this.KernelXY = kernelXY; this.KernelXY = kernelXY;
this.Grayscale = grayscale;
} }
/// <inheritdoc/> /// <inheritdoc/>
public bool Grayscale { get; set; } public bool Grayscale { get; }
/// <summary> /// <summary>
/// Gets the 2d gradient operator. /// Gets the 2d gradient operator.
@ -33,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray<float> KernelXY { get; } public Fast2DArray<float> KernelXY { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void BeforeApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void BeforeFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
if (this.Grayscale) if (this.Grayscale)
{ {
@ -42,7 +45,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
new ConvolutionProcessor<TPixel>(this.KernelXY).Apply(source, sourceRectangle, configuration); new ConvolutionProcessor<TPixel>(this.KernelXY).Apply(source, sourceRectangle, configuration);
} }

24
src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs → src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs

@ -4,12 +4,13 @@
using System; using System;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{ {
/// <summary> /// <summary>
/// Applies a Gaussian blur sampler to the image. /// Applies Gaussian blur processing to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class GaussianBlurProcessor<TPixel> : ImageProcessor<TPixel> internal class GaussianBlurProcessor<TPixel> : ImageProcessor<TPixel>
@ -20,11 +21,6 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// </summary> /// </summary>
private readonly int kernelSize; private readonly int kernelSize;
/// <summary>
/// The spread of the blur.
/// </summary>
private readonly float sigma;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GaussianBlurProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="GaussianBlurProcessor{TPixel}"/> class.
/// </summary> /// </summary>
@ -32,7 +28,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public GaussianBlurProcessor(float sigma = 3f) public GaussianBlurProcessor(float sigma = 3f)
{ {
this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1; this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1;
this.sigma = sigma; this.Sigma = sigma;
this.KernelX = this.CreateGaussianKernel(true); this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false); this.KernelY = this.CreateGaussianKernel(false);
} }
@ -46,7 +42,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public GaussianBlurProcessor(int radius) public GaussianBlurProcessor(int radius)
{ {
this.kernelSize = (radius * 2) + 1; this.kernelSize = (radius * 2) + 1;
this.sigma = radius; this.Sigma = radius;
this.KernelX = this.CreateGaussianKernel(true); this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false); this.KernelY = this.CreateGaussianKernel(false);
} }
@ -64,15 +60,15 @@ namespace SixLabors.ImageSharp.Processing.Processors
public GaussianBlurProcessor(float sigma, int radius) public GaussianBlurProcessor(float sigma, int radius)
{ {
this.kernelSize = (radius * 2) + 1; this.kernelSize = (radius * 2) + 1;
this.sigma = sigma; this.Sigma = sigma;
this.KernelX = this.CreateGaussianKernel(true); this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false); this.KernelY = this.CreateGaussianKernel(false);
} }
/// <summary> /// <summary>
/// Gets the sigma /// Gets the sigma value representing the weight of the blur
/// </summary> /// </summary>
public float Sigma => this.sigma; public float Sigma { get; }
/// <summary> /// <summary>
/// Gets the horizontal gradient operator. /// Gets the horizontal gradient operator.
@ -85,7 +81,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray<float> KernelY { get; } public Fast2DArray<float> KernelY { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
new Convolution2PassProcessor<TPixel>(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration); new Convolution2PassProcessor<TPixel>(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration);
} }
@ -98,7 +94,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
private Fast2DArray<float> CreateGaussianKernel(bool horizontal) private Fast2DArray<float> CreateGaussianKernel(bool horizontal)
{ {
int size = this.kernelSize; int size = this.kernelSize;
float weight = this.sigma; float weight = this.Sigma;
Fast2DArray<float> kernel = horizontal Fast2DArray<float> kernel = horizontal
? new Fast2DArray<float>(size, 1) ? new Fast2DArray<float>(size, 1)
: new Fast2DArray<float>(1, size); : new Fast2DArray<float>(1, size);

26
src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs → src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs

@ -4,12 +4,13 @@
using System; using System;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{ {
/// <summary> /// <summary>
/// Applies a Gaussian sharpening sampler to the image. /// Applies Gaussian sharpening processing to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class GaussianSharpenProcessor<TPixel> : ImageProcessor<TPixel> internal class GaussianSharpenProcessor<TPixel> : ImageProcessor<TPixel>
@ -20,11 +21,6 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// </summary> /// </summary>
private readonly int kernelSize; private readonly int kernelSize;
/// <summary>
/// The spread of the blur.
/// </summary>
private readonly float sigma;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GaussianSharpenProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="GaussianSharpenProcessor{TPixel}"/> class.
/// </summary> /// </summary>
@ -34,7 +30,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public GaussianSharpenProcessor(float sigma = 3f) public GaussianSharpenProcessor(float sigma = 3f)
{ {
this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1; this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1;
this.sigma = sigma; this.Sigma = sigma;
this.KernelX = this.CreateGaussianKernel(true); this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false); this.KernelY = this.CreateGaussianKernel(false);
} }
@ -48,7 +44,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public GaussianSharpenProcessor(int radius) public GaussianSharpenProcessor(int radius)
{ {
this.kernelSize = (radius * 2) + 1; this.kernelSize = (radius * 2) + 1;
this.sigma = radius; this.Sigma = radius;
this.KernelX = this.CreateGaussianKernel(true); this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false); this.KernelY = this.CreateGaussianKernel(false);
} }
@ -66,15 +62,15 @@ namespace SixLabors.ImageSharp.Processing.Processors
public GaussianSharpenProcessor(float sigma, int radius) public GaussianSharpenProcessor(float sigma, int radius)
{ {
this.kernelSize = (radius * 2) + 1; this.kernelSize = (radius * 2) + 1;
this.sigma = sigma; this.Sigma = sigma;
this.KernelX = this.CreateGaussianKernel(true); this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false); this.KernelY = this.CreateGaussianKernel(false);
} }
/// <summary> /// <summary>
/// Gets the sigma /// Gets the sigma value representing the weight of the blur
/// </summary> /// </summary>
public float Sigma => this.sigma; public float Sigma { get; }
/// <summary> /// <summary>
/// Gets the horizontal gradient operator. /// Gets the horizontal gradient operator.
@ -87,7 +83,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray<float> KernelY { get; } public Fast2DArray<float> KernelY { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
new Convolution2PassProcessor<TPixel>(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration); new Convolution2PassProcessor<TPixel>(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration);
} }
@ -100,7 +96,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
private Fast2DArray<float> CreateGaussianKernel(bool horizontal) private Fast2DArray<float> CreateGaussianKernel(bool horizontal)
{ {
int size = this.kernelSize; int size = this.kernelSize;
float weight = this.sigma; float weight = this.Sigma;
Fast2DArray<float> kernel = horizontal Fast2DArray<float> kernel = horizontal
? new Fast2DArray<float>(size, 1) ? new Fast2DArray<float>(size, 1)
: new Fast2DArray<float>(1, size); : new Fast2DArray<float>(1, size);
@ -159,7 +155,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
} }
} }
// Normalise kernel so that the sum of all weights equals 1 // Normalize kernel so that the sum of all weights equals 1
if (horizontal) if (horizontal)
{ {
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)

7
src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs → src/ImageSharp/Processing/Convolution/Processors/IEdgeDetectorProcessor.cs

@ -1,10 +1,9 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{ {
/// <summary> /// <summary>
/// Provides properties and methods allowing the detection of edges within an image. /// Provides properties and methods allowing the detection of edges within an image.
@ -21,8 +20,8 @@ namespace SixLabors.ImageSharp.Processing
public interface IEdgeDetectorProcessor public interface IEdgeDetectorProcessor
{ {
/// <summary> /// <summary>
/// Gets or sets a value indicating whether to convert the image to grayscale before performing edge detection. /// Gets a value indicating whether to convert the image to grayscale before performing edge detection.
/// </summary> /// </summary>
bool Grayscale { get; set; } bool Grayscale { get; }
} }
} }

35
src/ImageSharp/Processing/Convolution/Processors/KayyaliKernels.cs

@ -0,0 +1,35 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Contains the kernels used for Kayyali edge detection
/// </summary>
internal static class KayyaliKernels
{
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>
public static Fast2DArray<float> KayyaliX =>
new float[,]
{
{ 6, 0, -6 },
{ 0, 0, 0 },
{ -6, 0, 6 }
};
/// <summary>
/// Gets the vertical gradient operator.
/// </summary>
public static Fast2DArray<float> KayyaliY =>
new float[,]
{
{ -6, 0, 6 },
{ 0, 0, 0 },
{ 6, 0, -6 }
};
}
}

24
src/ImageSharp/Processing/Convolution/Processors/KayyaliProcessor.cs

@ -0,0 +1,24 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Applies edge detection processing to the image using the Kayyali operator filter. <see href="http://edgedetection.webs.com/"/>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class KayyaliProcessor<TPixel> : EdgeDetector2DProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="KayyaliProcessor{TPixel}"/> class.
/// </summary>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
public KayyaliProcessor(bool grayscale)
: base(KayyaliKernels.KayyaliX, KayyaliKernels.KayyaliY, grayscale)
{
}
}
}

49
src/ImageSharp/Processing/Convolution/Processors/KirschProcessor.cs

@ -0,0 +1,49 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Applies edge detection processing to the image using the Kirsch operator filter. <see href="http://en.wikipedia.org/wiki/Kirsch_operator"/>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class KirschProcessor<TPixel> : EdgeDetectorCompassProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="KirschProcessor{TPixel}"/> 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 Fast2DArray<float> North => KirshKernels.KirschNorth;
/// <inheritdoc/>
public override Fast2DArray<float> NorthWest => KirshKernels.KirschNorthWest;
/// <inheritdoc/>
public override Fast2DArray<float> West => KirshKernels.KirschWest;
/// <inheritdoc/>
public override Fast2DArray<float> SouthWest => KirshKernels.KirschSouthWest;
/// <inheritdoc/>
public override Fast2DArray<float> South => KirshKernels.KirschSouth;
/// <inheritdoc/>
public override Fast2DArray<float> SouthEast => KirshKernels.KirschSouthEast;
/// <inheritdoc/>
public override Fast2DArray<float> East => KirshKernels.KirschEast;
/// <inheritdoc/>
public override Fast2DArray<float> NorthEast => KirshKernels.KirschNorthEast;
}
}

101
src/ImageSharp/Processing/Convolution/Processors/KirshKernels.cs

@ -0,0 +1,101 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Contains the eight matrices used for Kirsh edge detection
/// </summary>
internal static class KirshKernels
{
/// <summary>
/// Gets the North gradient operator
/// </summary>
public static Fast2DArray<float> KirschNorth =>
new float[,]
{
{ 5, 5, 5 },
{ -3, 0, -3 },
{ -3, -3, -3 }
};
/// <summary>
/// Gets the NorthWest gradient operator
/// </summary>
public static Fast2DArray<float> KirschNorthWest =>
new float[,]
{
{ 5, 5, -3 },
{ 5, 0, -3 },
{ -3, -3, -3 }
};
/// <summary>
/// Gets the West gradient operator
/// </summary>
public static Fast2DArray<float> KirschWest =>
new float[,]
{
{ 5, -3, -3 },
{ 5, 0, -3 },
{ 5, -3, -3 }
};
/// <summary>
/// Gets the SouthWest gradient operator
/// </summary>
public static Fast2DArray<float> KirschSouthWest =>
new float[,]
{
{ -3, -3, -3 },
{ 5, 0, -3 },
{ 5, 5, -3 }
};
/// <summary>
/// Gets the South gradient operator
/// </summary>
public static Fast2DArray<float> KirschSouth =>
new float[,]
{
{ -3, -3, -3 },
{ -3, 0, -3 },
{ 5, 5, 5 }
};
/// <summary>
/// Gets the SouthEast gradient operator
/// </summary>
public static Fast2DArray<float> KirschSouthEast =>
new float[,]
{
{ -3, -3, -3 },
{ -3, 0, 5 },
{ -3, 5, 5 }
};
/// <summary>
/// Gets the East gradient operator
/// </summary>
public static Fast2DArray<float> KirschEast =>
new float[,]
{
{ -3, -3, 5 },
{ -3, 0, 5 },
{ -3, -3, 5 }
};
/// <summary>
/// Gets the NorthEast gradient operator
/// </summary>
public static Fast2DArray<float> KirschNorthEast =>
new float[,]
{
{ -3, 5, 5 },
{ -3, 0, 5 },
{ -3, -3, -3 }
};
}
}

25
src/ImageSharp/Processing/Convolution/Processors/Laplacian3x3Processor.cs

@ -0,0 +1,25 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <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>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class Laplacian3x3Processor<TPixel> : EdgeDetectorProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="Laplacian3x3Processor{TPixel}"/> class.
/// </summary>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
public Laplacian3x3Processor(bool grayscale)
: base(LaplacianKernels.Laplacian3x3, grayscale)
{
}
}
}

25
src/ImageSharp/Processing/Convolution/Processors/Laplacian5x5Processor.cs

@ -0,0 +1,25 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Applies edge detection processing to the image using the Laplacian 5x5 operator filter.
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class Laplacian5x5Processor<TPixel> : EdgeDetectorProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="Laplacian5x5Processor{TPixel}"/> class.
/// </summary>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
public Laplacian5x5Processor(bool grayscale)
: base(LaplacianKernels.Laplacian5x5, grayscale)
{
}
}
}

40
src/ImageSharp/Processing/Convolution/Processors/LaplacianKernelFactory.cs

@ -0,0 +1,40 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// A factory for creating Laplacian kernel matrices.
/// </summary>
internal static class LaplacianKernelFactory
{
/// <summary>
/// Creates a Laplacian matrix, 2nd derivative, of an arbitrary length.
/// <see href="https://stackoverflow.com/questions/19422029/how-to-calculate-a-laplacian-mask-or-any-size"/>
/// </summary>
/// <param name="length">The length of the matrix sides</param>
/// <returns>The <see cref="Fast2DArray{T}"/></returns>
public static Fast2DArray<float> CreateKernel(uint length)
{
Guard.MustBeGreaterThanOrEqualTo(length, 3u, nameof(length));
Guard.IsFalse(length % 2 == 0, nameof(length), "The kernel length must be an odd number.");
var kernel = new Fast2DArray<float>((int)length);
for (int y = 0; y < kernel.Height; y++)
{
for (int x = 0; x < kernel.Width; x++)
{
kernel[x, y] = -1;
}
}
int mid = (int)(length / 2);
kernel[mid, mid] = (length * length) - 1;
return kernel;
}
}
}

36
src/ImageSharp/Processing/Convolution/Processors/LaplacianKernels.cs

@ -0,0 +1,36 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Contains Laplacian kernels of different sizes
/// </summary>
internal static class LaplacianKernels
{
/// <summary>
/// Gets the 3x3 Laplacian kernel
/// </summary>
public static Fast2DArray<float> Laplacian3x3 => LaplacianKernelFactory.CreateKernel(3);
/// <summary>
/// Gets the 5x5 Laplacian kernel
/// </summary>
public static Fast2DArray<float> Laplacian5x5 => LaplacianKernelFactory.CreateKernel(5);
/// <summary>
/// Gets the Laplacian of Gaussian kernel.
/// </summary>
public static Fast2DArray<float> LaplacianOfGaussianXY =>
new float[,]
{
{ 0, 0, -1, 0, 0 },
{ 0, -1, -2, -1, 0 },
{ -1, -2, 16, -2, -1 },
{ 0, -1, -2, -1, 0 },
{ 0, 0, -1, 0, 0 }
};
}
}

25
src/ImageSharp/Processing/Convolution/Processors/LaplacianOfGaussianProcessor.cs

@ -0,0 +1,25 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Applies edge detection processing to the image using the Laplacian of Gaussian operator filter.
/// <see href="http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html"/>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class LaplacianOfGaussianProcessor<TPixel> : EdgeDetectorProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="LaplacianOfGaussianProcessor{TPixel}"/> class.
/// </summary>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
public LaplacianOfGaussianProcessor(bool grayscale)
: base(LaplacianKernels.LaplacianOfGaussianXY, grayscale)
{
}
}
}

35
src/ImageSharp/Processing/Convolution/Processors/PrewittKernels.cs

@ -0,0 +1,35 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Contains the kernels used for Prewitt edge detection
/// </summary>
internal static class PrewittKernels
{
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>
public static Fast2DArray<float> PrewittX =>
new float[,]
{
{ -1, 0, 1 },
{ -1, 0, 1 },
{ -1, 0, 1 }
};
/// <summary>
/// Gets the vertical gradient operator.
/// </summary>
public static Fast2DArray<float> PrewittY =>
new float[,]
{
{ 1, 1, 1 },
{ 0, 0, 0 },
{ -1, -1, -1 }
};
}
}

25
src/ImageSharp/Processing/Convolution/Processors/PrewittProcessor.cs

@ -0,0 +1,25 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Applies edge detection processing to the image using the Prewitt operator filter.
/// <see href="http://en.wikipedia.org/wiki/Prewitt_operator"/>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class PrewittProcessor<TPixel> : EdgeDetector2DProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="PrewittProcessor{TPixel}"/> class.
/// </summary>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
public PrewittProcessor(bool grayscale)
: base(PrewittKernels.PrewittX, PrewittKernels.PrewittY, grayscale)
{
}
}
}

33
src/ImageSharp/Processing/Convolution/Processors/RobertsCrossKernels.cs

@ -0,0 +1,33 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Contains the kernels used for RobertsCross edge detection
/// </summary>
internal static class RobertsCrossKernels
{
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>
public static Fast2DArray<float> RobertsCrossX =>
new float[,]
{
{ 1, 0 },
{ 0, -1 }
};
/// <summary>
/// Gets the vertical gradient operator.
/// </summary>
public static Fast2DArray<float> RobertsCrossY =>
new float[,]
{
{ 0, 1 },
{ -1, 0 }
};
}
}

25
src/ImageSharp/Processing/Convolution/Processors/RobertsCrossProcessor.cs

@ -0,0 +1,25 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Applies edge detection processing to the image using the Roberts Cross operator filter.
/// <see href="http://en.wikipedia.org/wiki/Roberts_cross"/>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class RobertsCrossProcessor<TPixel> : EdgeDetector2DProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="RobertsCrossProcessor{TPixel}"/> class.
/// </summary>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
public RobertsCrossProcessor(bool grayscale)
: base(RobertsCrossKernels.RobertsCrossX, RobertsCrossKernels.RobertsCrossY, grayscale)
{
}
}
}

101
src/ImageSharp/Processing/Convolution/Processors/RobinsonKernels.cs

@ -0,0 +1,101 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Contains the kernels used for Robinson edge detection
/// </summary>
internal static class RobinsonKernels
{
/// <summary>
/// Gets the North gradient operator
/// </summary>
public static Fast2DArray<float> RobinsonNorth =>
new float[,]
{
{ 1, 2, 1 },
{ 0, 0, 0 },
{ -1, -2, -1 }
};
/// <summary>
/// Gets the NorthWest gradient operator
/// </summary>
public static Fast2DArray<float> RobinsonNorthWest =>
new float[,]
{
{ 2, 1, 0 },
{ 1, 0, -1 },
{ 0, -1, -2 }
};
/// <summary>
/// Gets the West gradient operator
/// </summary>
public static Fast2DArray<float> RobinsonWest =>
new float[,]
{
{ 1, 0, -1 },
{ 2, 0, -2 },
{ 1, 0, -1 }
};
/// <summary>
/// Gets the SouthWest gradient operator
/// </summary>
public static Fast2DArray<float> RobinsonSouthWest =>
new float[,]
{
{ 0, -1, -2 },
{ 1, 0, -1 },
{ 2, 1, 0 }
};
/// <summary>
/// Gets the South gradient operator
/// </summary>
public static Fast2DArray<float> RobinsonSouth =>
new float[,]
{
{ -1, -2, -1 },
{ 0, 0, 0 },
{ 1, 2, 1 }
};
/// <summary>
/// Gets the SouthEast gradient operator
/// </summary>
public static Fast2DArray<float> RobinsonSouthEast =>
new float[,]
{
{ -2, -1, 0 },
{ -1, 0, 1 },
{ 0, 1, 2 }
};
/// <summary>
/// Gets the East gradient operator
/// </summary>
public static Fast2DArray<float> RobinsonEast =>
new float[,]
{
{ -1, 0, 1 },
{ -2, 0, 2 },
{ -1, 0, 1 }
};
/// <summary>
/// Gets the NorthEast gradient operator
/// </summary>
public static Fast2DArray<float> RobinsonNorthEast =>
new float[,]
{
{ 0, 1, 2 },
{ -1, 0, 1 },
{ -2, -1, 0 }
};
}
}

50
src/ImageSharp/Processing/Convolution/Processors/RobinsonProcessor.cs

@ -0,0 +1,50 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Applies edge detection processing to the image using the Robinson operator filter.
/// <see href="http://www.tutorialspoint.com/dip/Robinson_Compass_Mask.htm"/>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class RobinsonProcessor<TPixel> : EdgeDetectorCompassProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="RobinsonProcessor{TPixel}"/> 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 Fast2DArray<float> North => RobinsonKernels.RobinsonNorth;
/// <inheritdoc/>
public override Fast2DArray<float> NorthWest => RobinsonKernels.RobinsonNorthWest;
/// <inheritdoc/>
public override Fast2DArray<float> West => RobinsonKernels.RobinsonWest;
/// <inheritdoc/>
public override Fast2DArray<float> SouthWest => RobinsonKernels.RobinsonSouthWest;
/// <inheritdoc/>
public override Fast2DArray<float> South => RobinsonKernels.RobinsonSouth;
/// <inheritdoc/>
public override Fast2DArray<float> SouthEast => RobinsonKernels.RobinsonSouthEast;
/// <inheritdoc/>
public override Fast2DArray<float> East => RobinsonKernels.RobinsonEast;
/// <inheritdoc/>
public override Fast2DArray<float> NorthEast => RobinsonKernels.RobinsonNorthEast;
}
}

35
src/ImageSharp/Processing/Convolution/Processors/ScharrKernels.cs

@ -0,0 +1,35 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Contains the kernels used for Scharr edge detection
/// </summary>
internal static class ScharrKernels
{
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>
public static Fast2DArray<float> ScharrX =>
new float[,]
{
{ -3, 0, 3 },
{ -10, 0, 10 },
{ -3, 0, 3 }
};
/// <summary>
/// Gets the vertical gradient operator.
/// </summary>
public static Fast2DArray<float> ScharrY =>
new float[,]
{
{ 3, 10, 3 },
{ 0, 0, 0 },
{ -3, -10, -3 }
};
}
}

25
src/ImageSharp/Processing/Convolution/Processors/ScharrProcessor.cs

@ -0,0 +1,25 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Applies edge detection processing to the image using the Scharr operator filter.
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator#Alternative_operators"/>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class ScharrProcessor<TPixel> : EdgeDetector2DProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="ScharrProcessor{TPixel}"/> class.
/// </summary>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
public ScharrProcessor(bool grayscale)
: base(ScharrKernels.ScharrX, ScharrKernels.ScharrY, grayscale)
{
}
}
}

35
src/ImageSharp/Processing/Convolution/Processors/SobelKernels.cs

@ -0,0 +1,35 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// Contains the kernels used for Sobel edge detection
/// </summary>
internal static class SobelKernels
{
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>
public static Fast2DArray<float> SobelX =>
new float[,]
{
{ -1, 0, 1 },
{ -2, 0, 2 },
{ -1, 0, 1 }
};
/// <summary>
/// Gets the vertical gradient operator.
/// </summary>
public static Fast2DArray<float> SobelY =>
new float[,]
{
{ -1, -2, -1 },
{ 0, 0, 0 },
{ 1, 2, 1 }
};
}
}

26
src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
/// <summary>
/// The Sobel operator filter.
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator"/>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class SobelProcessor<TPixel> : EdgeDetector2DProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="SobelProcessor{TPixel}"/> class.
/// </summary>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
public SobelProcessor(bool grayscale)
: base(SobelKernels.SobelX, SobelKernels.SobelY, grayscale)
{
}
}
}

10
src/ImageSharp/Processing/Dithering/Diffuse.cs → src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs

@ -3,15 +3,15 @@
using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Dithering.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Dithering
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds diffusion extensions to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class DiffuseExtensions
{ {
/// <summary> /// <summary>
/// Dithers the image reducing it to a web-safe palette using error diffusion. /// Dithers the image reducing it to a web-safe palette using error diffusion.
@ -81,4 +81,4 @@ namespace SixLabors.ImageSharp
return source; return source;
} }
} }
} }

10
src/ImageSharp/Processing/Dithering/Dither.cs → src/ImageSharp/Processing/Dithering/DitherExtensions.cs

@ -3,15 +3,15 @@
using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Dithering.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Dithering
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds dithering extensions to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class DitherExtensions
{ {
/// <summary> /// <summary>
/// Dithers the image reducing it to a web-safe palette using ordered dithering. /// Dithers the image reducing it to a web-safe palette using ordered dithering.
@ -77,4 +77,4 @@ namespace SixLabors.ImageSharp
return source; return source;
} }
} }
} }

4
src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs → src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs

@ -8,7 +8,7 @@ using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Dithering.Processors
{ {
/// <summary> /// <summary>
/// An <see cref="IImageProcessor{TPixel}"/> that dithers an image using error diffusion. /// An <see cref="IImageProcessor{TPixel}"/> that dithers an image using error diffusion.
@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public float Threshold { get; } public float Threshold { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
float threshold = this.Threshold * 255F; float threshold = this.Threshold * 255F;
var rgba = default(Rgba32); var rgba = default(Rgba32);

4
src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs → src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs

@ -8,7 +8,7 @@ using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Dithering.Processors
{ {
/// <summary> /// <summary>
/// An <see cref="IImageProcessor{TPixel}"/> that dithers an image using error diffusion. /// An <see cref="IImageProcessor{TPixel}"/> that dithers an image using error diffusion.
@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public IOrderedDither Dither { get; } public IOrderedDither Dither { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
var rgba = default(Rgba32); var rgba = default(Rgba32);
bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8); bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8);

4
src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs → src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs

@ -6,7 +6,7 @@ using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Dithering.Processors
{ {
/// <summary> /// <summary>
/// The base class for dither and diffusion processors that consume a palette. /// The base class for dither and diffusion processors that consume a palette.
@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Initializes a new instance of the <see cref="PaletteDitherProcessorBase{TPixel}"/> class. /// Initializes a new instance of the <see cref="PaletteDitherProcessorBase{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="palette">The palette to select substitute colors from.</param> /// <param name="palette">The palette to select substitute colors from.</param>
public PaletteDitherProcessorBase(TPixel[] palette) protected PaletteDitherProcessorBase(TPixel[] palette)
{ {
Guard.NotNull(palette, nameof(palette)); Guard.NotNull(palette, nameof(palette));
this.Palette = palette; this.Palette = palette;

2
src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs → src/ImageSharp/Processing/Dithering/Processors/PixelPair.cs

@ -4,7 +4,7 @@
using System; using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Dithering.Processors
{ {
/// <summary> /// <summary>
/// Represents a composite pair of pixels. Used for caching color distance lookups. /// Represents a composite pair of pixels. Used for caching color distance lookups.

21
src/ImageSharp/Processing/Effects/OilPainting.cs → src/ImageSharp/Processing/Effects/OilPaintExtensions.cs

@ -1,17 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Effects.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Effects
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds oil painting effect extensions to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class OilPaintExtensions
{ {
/// <summary> /// <summary>
/// Alters the colors of the image recreating an oil painting effect with levels and brushSize /// Alters the colors of the image recreating an oil painting effect with levels and brushSize
@ -22,9 +21,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> OilPaint<TPixel>(this IImageProcessingContext<TPixel> source) public static IImageProcessingContext<TPixel> OilPaint<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => OilPaint(source, 10, 15);
return OilPaint(source, 10, 15);
}
/// <summary> /// <summary>
/// Alters the colors of the image recreating an oil painting effect with levels and brushSize /// Alters the colors of the image recreating an oil painting effect with levels and brushSize
@ -38,9 +35,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> OilPaint<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle) public static IImageProcessingContext<TPixel> OilPaint<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => OilPaint(source, 10, 15, rectangle);
return OilPaint(source, 10, 15, rectangle);
}
/// <summary> /// <summary>
/// Alters the colors of the image recreating an oil painting effect. /// Alters the colors of the image recreating an oil painting effect.
@ -52,7 +47,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> OilPaint<TPixel>(this IImageProcessingContext<TPixel> source, int levels, int brushSize) public static IImageProcessingContext<TPixel> OilPaint<TPixel>(this IImageProcessingContext<TPixel> source, int levels, int brushSize)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new OilPaintingProcessor<TPixel>(levels, brushSize)); => source.ApplyProcessor(new OilPaintingProcessor<TPixel>(levels, brushSize));
/// <summary> /// <summary>
/// Alters the colors of the image recreating an oil painting effect. /// Alters the colors of the image recreating an oil painting effect.
@ -67,6 +62,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> OilPaint<TPixel>(this IImageProcessingContext<TPixel> source, int levels, int brushSize, Rectangle rectangle) public static IImageProcessingContext<TPixel> OilPaint<TPixel>(this IImageProcessingContext<TPixel> source, int levels, int brushSize, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new OilPaintingProcessor<TPixel>(levels, brushSize), rectangle); => source.ApplyProcessor(new OilPaintingProcessor<TPixel>(levels, brushSize), rectangle);
} }
} }

15
src/ImageSharp/Processing/Effects/Pixelate.cs → src/ImageSharp/Processing/Effects/PixelateExtensions.cs

@ -1,17 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Effects.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Effects
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds pixelation effect extensions to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class PixelateExtensions
{ {
/// <summary> /// <summary>
/// Pixelates an image with the given pixel size. /// Pixelates an image with the given pixel size.
@ -21,7 +20,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Pixelate<TPixel>(this IImageProcessingContext<TPixel> source) public static IImageProcessingContext<TPixel> Pixelate<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new PixelateProcessor<TPixel>(4)); => Pixelate(source, 4);
/// <summary> /// <summary>
/// Pixelates an image with the given pixel size. /// Pixelates an image with the given pixel size.
@ -32,7 +31,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Pixelate<TPixel>(this IImageProcessingContext<TPixel> source, int size) public static IImageProcessingContext<TPixel> Pixelate<TPixel>(this IImageProcessingContext<TPixel> source, int size)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new PixelateProcessor<TPixel>(size)); => source.ApplyProcessor(new PixelateProcessor<TPixel>(size));
/// <summary> /// <summary>
/// Pixelates an image with the given pixel size. /// Pixelates an image with the given pixel size.
@ -46,6 +45,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Pixelate<TPixel>(this IImageProcessingContext<TPixel> source, int size, Rectangle rectangle) public static IImageProcessingContext<TPixel> Pixelate<TPixel>(this IImageProcessingContext<TPixel> source, int size, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new PixelateProcessor<TPixel>(size), rectangle); => source.ApplyProcessor(new PixelateProcessor<TPixel>(size), rectangle);
} }
} }

6
src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs → src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs

@ -10,10 +10,10 @@ using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Effects.Processors
{ {
/// <summary> /// <summary>
/// An <see cref="IImageProcessor{TPixel}"/> to apply an oil painting effect to an <see cref="Image{TPixel}"/>. /// Applies oil painting effect processing to the image.
/// </summary> /// </summary>
/// <remarks>Adapted from <see href="https://softwarebydefault.com/2013/06/29/oil-painting-cartoon-filter/"/> by Dewald Esterhuizen.</remarks> /// <remarks>Adapted from <see href="https://softwarebydefault.com/2013/06/29/oil-painting-cartoon-filter/"/> by Dewald Esterhuizen.</remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public int BrushSize { get; } public int BrushSize { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
if (this.BrushSize <= 0 || this.BrushSize > source.Height || this.BrushSize > source.Width) if (this.BrushSize <= 0 || this.BrushSize > source.Height || this.BrushSize > source.Width)
{ {

6
src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs → src/ImageSharp/Processing/Effects/Processors/PixelateProcessor.cs

@ -9,10 +9,10 @@ using SixLabors.ImageSharp.Common;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Effects.Processors
{ {
/// <summary> /// <summary>
/// An <see cref="IImageProcessor{TPixel}"/> to pixelate the colors of an <see cref="Image{TPixel}"/>. /// Applies a pixelation effect processing to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class PixelateProcessor<TPixel> : ImageProcessor<TPixel> internal class PixelateProcessor<TPixel> : ImageProcessor<TPixel>
@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public int Size { get; } public int Size { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
if (this.Size <= 0 || this.Size > source.Height || this.Size > source.Width) if (this.Size <= 0 || this.Size > source.Height || this.Size > source.Width)
{ {

18
src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs → src/ImageSharp/Processing/Filters/BlackWhiteExtensions.cs

@ -2,15 +2,15 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of black and white toning to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class BlackWhiteExtensions
{ {
/// <summary> /// <summary>
/// Applies black and white toning to the image. /// Applies black and white toning to the image.
@ -20,10 +20,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BlackWhite<TPixel>(this IImageProcessingContext<TPixel> source) public static IImageProcessingContext<TPixel> BlackWhite<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BlackWhiteProcessor<TPixel>());
source.ApplyProcessor(new BlackWhiteProcessor<TPixel>());
return source;
}
/// <summary> /// <summary>
/// Applies black and white toning to the image. /// Applies black and white toning to the image.
@ -36,9 +33,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BlackWhite<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle) public static IImageProcessingContext<TPixel> BlackWhite<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new BlackWhiteProcessor<TPixel>(), rectangle);
source.ApplyProcessor(new BlackWhiteProcessor<TPixel>(), rectangle);
return source;
}
} }
} }

13
src/ImageSharp/Processing/ColorMatrix/Brightness.cs → src/ImageSharp/Processing/Filters/BrightnessExtensions.cs

@ -1,17 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the alteration of the brightness component to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class BrightnessExtensions
{ {
/// <summary> /// <summary>
/// Alters the brightness component of the image. /// Alters the brightness component of the image.
@ -26,7 +25,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Brightness<TPixel>(this IImageProcessingContext<TPixel> source, float amount) public static IImageProcessingContext<TPixel> Brightness<TPixel>(this IImageProcessingContext<TPixel> source, float amount)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new BrightnessProcessor<TPixel>(amount)); => source.ApplyProcessor(new BrightnessProcessor<TPixel>(amount));
/// <summary> /// <summary>
/// Alters the brightness component of the image. /// Alters the brightness component of the image.
@ -44,6 +43,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Brightness<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle) public static IImageProcessingContext<TPixel> Brightness<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new BrightnessProcessor<TPixel>(amount), rectangle); => source.ApplyProcessor(new BrightnessProcessor<TPixel>(amount), rectangle);
} }
} }

2
src/ImageSharp/Processing/ColorMatrix/Options/ColorBlindness.cs → src/ImageSharp/Processing/Filters/ColorBlindness.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Enumerates the various types of defined color blindness filters. /// Enumerates the various types of defined color blindness filters.

24
src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs → src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs

@ -1,18 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that simulate the effects of various color blindness disorders to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class ColorBlindnessExtensions
{ {
/// <summary> /// <summary>
/// Applies the given colorblindness simulator to the image. /// Applies the given colorblindness simulator to the image.
@ -50,19 +48,19 @@ namespace SixLabors.ImageSharp
{ {
switch (colorBlindness) switch (colorBlindness)
{ {
case ImageSharp.Processing.ColorBlindness.Achromatomaly: case Filters.ColorBlindness.Achromatomaly:
return new AchromatomalyProcessor<TPixel>(); return new AchromatomalyProcessor<TPixel>();
case ImageSharp.Processing.ColorBlindness.Achromatopsia: case Filters.ColorBlindness.Achromatopsia:
return new AchromatopsiaProcessor<TPixel>(); return new AchromatopsiaProcessor<TPixel>();
case ImageSharp.Processing.ColorBlindness.Deuteranomaly: case Filters.ColorBlindness.Deuteranomaly:
return new DeuteranomalyProcessor<TPixel>(); return new DeuteranomalyProcessor<TPixel>();
case ImageSharp.Processing.ColorBlindness.Deuteranopia: case Filters.ColorBlindness.Deuteranopia:
return new DeuteranopiaProcessor<TPixel>(); return new DeuteranopiaProcessor<TPixel>();
case ImageSharp.Processing.ColorBlindness.Protanomaly: case Filters.ColorBlindness.Protanomaly:
return new ProtanomalyProcessor<TPixel>(); return new ProtanomalyProcessor<TPixel>();
case ImageSharp.Processing.ColorBlindness.Protanopia: case Filters.ColorBlindness.Protanopia:
return new ProtanopiaProcessor<TPixel>(); return new ProtanopiaProcessor<TPixel>();
case ImageSharp.Processing.ColorBlindness.Tritanomaly: case Filters.ColorBlindness.Tritanomaly:
return new TritanomalyProcessor<TPixel>(); return new TritanomalyProcessor<TPixel>();
default: default:
return new TritanopiaProcessor<TPixel>(); return new TritanopiaProcessor<TPixel>();

12
src/ImageSharp/Processing/ColorMatrix/Contrast.cs → src/ImageSharp/Processing/Filters/ContrastExtensions.cs

@ -2,15 +2,15 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the alteration of the contrast component to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class ContrastExtensions
{ {
/// <summary> /// <summary>
/// Alters the contrast component of the image. /// Alters the contrast component of the image.
@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Contrast<TPixel>(this IImageProcessingContext<TPixel> source, float amount) public static IImageProcessingContext<TPixel> Contrast<TPixel>(this IImageProcessingContext<TPixel> source, float amount)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new ContrastProcessor<TPixel>(amount)); => source.ApplyProcessor(new ContrastProcessor<TPixel>(amount));
/// <summary> /// <summary>
/// Alters the contrast component of the image. /// Alters the contrast component of the image.
@ -43,6 +43,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Contrast<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle) public static IImageProcessingContext<TPixel> Contrast<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new ContrastProcessor<TPixel>(amount), rectangle); => source.ApplyProcessor(new ContrastProcessor<TPixel>(amount), rectangle);
} }
} }

18
src/ImageSharp/Processing/ColorMatrix/Filter.cs → src/ImageSharp/Processing/Filters/FilterExtensions.cs

@ -3,15 +3,15 @@
using System.Numerics; using System.Numerics;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of composable filters to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class FilterExtensions
{ {
/// <summary> /// <summary>
/// Filters an image but the given color matrix /// Filters an image but the given color matrix
@ -22,10 +22,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Filter<TPixel>(this IImageProcessingContext<TPixel> source, Matrix4x4 matrix) public static IImageProcessingContext<TPixel> Filter<TPixel>(this IImageProcessingContext<TPixel> source, Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new FilterProcessor<TPixel>(matrix));
source.ApplyProcessor(new FilterProcessor<TPixel>(matrix));
return source;
}
/// <summary> /// <summary>
/// Filters an image but the given color matrix /// Filters an image but the given color matrix
@ -39,9 +36,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Filter<TPixel>(this IImageProcessingContext<TPixel> source, Matrix4x4 matrix, Rectangle rectangle) public static IImageProcessingContext<TPixel> Filter<TPixel>(this IImageProcessingContext<TPixel> source, Matrix4x4 matrix, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new FilterProcessor<TPixel>(matrix), rectangle);
source.ApplyProcessor(new FilterProcessor<TPixel>(matrix), rectangle);
return source;
}
} }
} }

33
src/ImageSharp/Processing/ColorMatrix/Grayscale.cs → src/ImageSharp/Processing/Filters/GrayscaleExtensions.cs

@ -2,29 +2,28 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the application of grayscale toning to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class GrayscaleExtensions
{ {
/// <summary> /// <summary>
/// Applies <see cref="GrayscaleMode.Bt709"/> Grayscale toning to the image. /// Applies <see cref="GrayscaleMode.Bt709"/> grayscale toning to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source) public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Grayscale(source, GrayscaleMode.Bt709); => Grayscale(source, GrayscaleMode.Bt709);
/// <summary> /// <summary>
/// Applies <see cref="GrayscaleMode.Bt709"/> Grayscale toning to the image using the given amount. /// Applies <see cref="GrayscaleMode.Bt709"/> grayscale toning to the image using the given amount.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
@ -32,7 +31,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, float amount) public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, float amount)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Grayscale(source, GrayscaleMode.Bt709, amount); => Grayscale(source, GrayscaleMode.Bt709, amount);
/// <summary> /// <summary>
/// Applies grayscale toning to the image with the given <see cref="GrayscaleMode"/>. /// Applies grayscale toning to the image with the given <see cref="GrayscaleMode"/>.
@ -43,7 +42,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, GrayscaleMode mode) public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, GrayscaleMode mode)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Grayscale(source, mode, 1F); => Grayscale(source, mode, 1F);
/// <summary> /// <summary>
/// Applies grayscale toning to the image with the given <see cref="GrayscaleMode"/> using the given amount. /// Applies grayscale toning to the image with the given <see cref="GrayscaleMode"/> using the given amount.
@ -65,7 +64,7 @@ namespace SixLabors.ImageSharp
} }
/// <summary> /// <summary>
/// Applies <see cref="GrayscaleMode.Bt709"/> Grayscale toning to the image. /// Applies <see cref="GrayscaleMode.Bt709"/> grayscale toning to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
@ -75,10 +74,10 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle) public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Grayscale(source, 1F, rectangle); => Grayscale(source, 1F, rectangle);
/// <summary> /// <summary>
/// Applies <see cref="GrayscaleMode.Bt709"/> Grayscale toning to the image using the given amount. /// Applies <see cref="GrayscaleMode.Bt709"/> grayscale toning to the image using the given amount.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
@ -89,10 +88,10 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle) public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Grayscale(source, GrayscaleMode.Bt709, amount, rectangle); => Grayscale(source, GrayscaleMode.Bt709, amount, rectangle);
/// <summary> /// <summary>
/// Applies Grayscale toning to the image. /// Applies grayscale toning to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
@ -103,10 +102,10 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, GrayscaleMode mode, Rectangle rectangle) public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, GrayscaleMode mode, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Grayscale(source, mode, 1F, rectangle); => Grayscale(source, mode, 1F, rectangle);
/// <summary> /// <summary>
/// Applies Grayscale toning to the image using the given amount. /// Applies grayscale toning to the image using the given amount.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>

6
src/ImageSharp/Processing/ColorMatrix/Options/GrayscaleMode.cs → src/ImageSharp/Processing/Filters/GrayscaleMode.cs

@ -1,10 +1,10 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Enumerates the various types of defined Grayscale filters. /// Enumerates the various types of defined grayscale filters.
/// </summary> /// </summary>
public enum GrayscaleMode public enum GrayscaleMode
{ {
@ -18,4 +18,4 @@ namespace SixLabors.ImageSharp.Processing
/// </summary> /// </summary>
Bt601 Bt601
} }
} }

20
src/ImageSharp/Processing/ColorMatrix/Hue.cs → src/ImageSharp/Processing/Filters/HueExtensions.cs

@ -1,18 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the alteration of the hue component to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class HueExtensions
{ {
/// <summary> /// <summary>
/// Alters the hue component of the image. /// Alters the hue component of the image.
@ -23,10 +21,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Hue<TPixel>(this IImageProcessingContext<TPixel> source, float degrees) public static IImageProcessingContext<TPixel> Hue<TPixel>(this IImageProcessingContext<TPixel> source, float degrees)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new HueProcessor<TPixel>(degrees));
source.ApplyProcessor(new HueProcessor<TPixel>(degrees));
return source;
}
/// <summary> /// <summary>
/// Alters the hue component of the image. /// Alters the hue component of the image.
@ -40,9 +35,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Hue<TPixel>(this IImageProcessingContext<TPixel> source, float degrees, Rectangle rectangle) public static IImageProcessingContext<TPixel> Hue<TPixel>(this IImageProcessingContext<TPixel> source, float degrees, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new HueProcessor<TPixel>(degrees), rectangle);
source.ApplyProcessor(new HueProcessor<TPixel>(degrees), rectangle);
return source;
}
} }
} }

15
src/ImageSharp/Processing/Effects/Invert.cs → src/ImageSharp/Processing/Filters/InvertExtensions.cs

@ -1,17 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the inversion of colors to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class InvertExtensions
{ {
/// <summary> /// <summary>
/// Inverts the colors of the image. /// Inverts the colors of the image.
@ -21,7 +20,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Invert<TPixel>(this IImageProcessingContext<TPixel> source) public static IImageProcessingContext<TPixel> Invert<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new InvertProcessor<TPixel>(1F)); => source.ApplyProcessor(new InvertProcessor<TPixel>(1F));
/// <summary> /// <summary>
/// Inverts the colors of the image. /// Inverts the colors of the image.
@ -34,6 +33,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Invert<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle) public static IImageProcessingContext<TPixel> Invert<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new InvertProcessor<TPixel>(1F), rectangle); => source.ApplyProcessor(new InvertProcessor<TPixel>(1F), rectangle);
} }
} }

20
src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs → src/ImageSharp/Processing/Filters/KodachromeExtensions.cs

@ -1,18 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the recreation of an old Kodachrome camera effect to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class KodachromeExtensions
{ {
/// <summary> /// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect. /// Alters the colors of the image recreating an old Kodachrome camera effect.
@ -22,10 +20,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Kodachrome<TPixel>(this IImageProcessingContext<TPixel> source) public static IImageProcessingContext<TPixel> Kodachrome<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new KodachromeProcessor<TPixel>());
source.ApplyProcessor(new KodachromeProcessor<TPixel>());
return source;
}
/// <summary> /// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect. /// Alters the colors of the image recreating an old Kodachrome camera effect.
@ -38,9 +33,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Kodachrome<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle) public static IImageProcessingContext<TPixel> Kodachrome<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => source.ApplyProcessor(new KodachromeProcessor<TPixel>(), rectangle);
source.ApplyProcessor(new KodachromeProcessor<TPixel>(), rectangle);
return source;
}
} }
} }

38
src/ImageSharp/Processing/Filters/LomographExtensions.cs

@ -0,0 +1,38 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Filters
{
/// <summary>
/// Adds extensions that allow the recreation of an old Lomograph camera effect to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static class LomographExtensions
{
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new LomographProcessor<TPixel>());
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new LomographProcessor<TPixel>(), rectangle);
}
}

8
src/ImageSharp/Processing/ColorMatrix/MatrixFilters.cs → src/ImageSharp/Processing/Filters/MatrixFilters.cs

@ -4,10 +4,10 @@
using System; using System;
using System.Numerics; using System.Numerics;
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Provides extensions methods for the <see cref="Matrix4x4"/> struct /// A collection of known <see cref="Matrix4x4"/> values for composing filters
/// </summary> /// </summary>
public static class MatrixFilters public static class MatrixFilters
{ {
@ -253,7 +253,7 @@ namespace SixLabors.ImageSharp.Processing
} }
/// <summary> /// <summary>
/// Create a greyscale filter matrix using the given amount using the formula as specified by ITU-R Recommendation BT.601. /// Create a grayscale filter matrix using the given amount using the formula as specified by ITU-R Recommendation BT.601.
/// <see href="https://en.wikipedia.org/wiki/Luma_%28video%29#Rec._601_luma_versus_Rec._709_luma_coefficients"/> /// <see href="https://en.wikipedia.org/wiki/Luma_%28video%29#Rec._601_luma_versus_Rec._709_luma_coefficients"/>
/// </summary> /// </summary>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param> /// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
@ -280,7 +280,7 @@ namespace SixLabors.ImageSharp.Processing
} }
/// <summary> /// <summary>
/// Create a greyscale filter matrix using the given amount using the formula as specified by ITU-R Recommendation BT.709. /// Create a grayscale filter matrix using the given amount using the formula as specified by ITU-R Recommendation BT.709.
/// <see href="https://en.wikipedia.org/wiki/Rec._709#Luma_coefficients"/> /// <see href="https://en.wikipedia.org/wiki/Rec._709#Luma_coefficients"/>
/// </summary> /// </summary>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param> /// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>

13
src/ImageSharp/Processing/ColorMatrix/Opacity.cs → src/ImageSharp/Processing/Filters/OpacityExtensions.cs

@ -1,17 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp.Processing.Filters
{ {
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Adds extensions that allow the alteration of the opacity component to the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static class OpacityExtensions
{ {
/// <summary> /// <summary>
/// Multiplies the alpha component of the image. /// Multiplies the alpha component of the image.
@ -22,7 +21,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Opacity<TPixel>(this IImageProcessingContext<TPixel> source, float amount) public static IImageProcessingContext<TPixel> Opacity<TPixel>(this IImageProcessingContext<TPixel> source, float amount)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new OpacityProcessor<TPixel>(amount)); => source.ApplyProcessor(new OpacityProcessor<TPixel>(amount));
/// <summary> /// <summary>
/// Multiplies the alpha component of the image. /// Multiplies the alpha component of the image.
@ -36,6 +35,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Opacity<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle) public static IImageProcessingContext<TPixel> Opacity<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new OpacityProcessor<TPixel>(amount), rectangle); => source.ApplyProcessor(new OpacityProcessor<TPixel>(amount), rectangle);
} }
} }

38
src/ImageSharp/Processing/Filters/PolaroidExtensions.cs

@ -0,0 +1,38 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Filters
{
/// <summary>
/// Adds extensions that allow the recreation of an old Polaroid camera effect to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static class PolaroidExtensions
{
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new PolaroidProcessor<TPixel>());
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new PolaroidProcessor<TPixel>(), rectangle);
}
}

2
src/ImageSharp/Processing/Processors/Filters/ColorBlindness/AchromatomalyProcessor.cs → src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness. /// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness.

2
src/ImageSharp/Processing/Processors/Filters/ColorBlindness/AchromatopsiaProcessor.cs → src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness. /// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness.

2
src/ImageSharp/Processing/Processors/Filters/BlackWhiteProcessor.cs → src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Applies a black and white filter matrix to the image /// Applies a black and white filter matrix to the image

4
src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs → src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Applies a brightness filter matrix using the given amount. /// Applies a brightness filter matrix using the given amount.
@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Initializes a new instance of the <see cref="BrightnessProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="BrightnessProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// A value of 0 will create an image that is completely black. A value of 1 leaves the input unchanged. /// A value of <value>0</value> will create an image that is completely black. A value of <value>1</value> leaves the input unchanged.
/// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing brighter results. /// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing brighter results.
/// </remarks> /// </remarks>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param> /// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>

4
src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs → src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Applies a contrast filter matrix using the given amount. /// Applies a contrast filter matrix using the given amount.
@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Initializes a new instance of the <see cref="ContrastProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="ContrastProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// A value of 0 will create an image that is completely gray. A value of 1 leaves the input unchanged. /// A value of <value>0</value> will create an image that is completely gray. A value of <value>1</value> leaves the input unchanged.
/// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing results with more contrast. /// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing results with more contrast.
/// </remarks> /// </remarks>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param> /// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>

2
src/ImageSharp/Processing/Processors/Filters/ColorBlindness/DeuteranomalyProcessor.cs → src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness. /// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness.

2
src/ImageSharp/Processing/Processors/Filters/ColorBlindness/DeuteranopiaProcessor.cs → src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness. /// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness.

4
src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs → src/ImageSharp/Processing/Filters/Processors/FilterProcessor.cs

@ -9,7 +9,7 @@ using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Provides methods that accept a <see cref="Matrix4x4"/> matrix to apply freeform filters to images. /// Provides methods that accept a <see cref="Matrix4x4"/> matrix to apply freeform filters to images.
@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Matrix4x4 Matrix { get; } public Matrix4x4 Matrix { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
var interest = Rectangle.Intersect(sourceRectangle, source.Bounds()); var interest = Rectangle.Intersect(sourceRectangle, source.Bounds());
int startY = interest.Y; int startY = interest.Y;

4
src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs → src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs

@ -3,10 +3,10 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Applies a greyscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.601 /// Applies a grayscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.601
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class GrayscaleBt601Processor<TPixel> : FilterProcessor<TPixel> internal class GrayscaleBt601Processor<TPixel> : FilterProcessor<TPixel>

2
src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs → src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Applies a grayscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.709 /// Applies a grayscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.709

2
src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs → src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Applies a hue filter matrix using the given angle of rotation in degrees /// Applies a hue filter matrix using the given angle of rotation in degrees

2
src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs → src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Applies a filter matrix that inverts the colors of an image /// Applies a filter matrix that inverts the colors of an image

2
src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs → src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Applies a filter matrix recreating an old Kodachrome camera effect matrix to the image /// Applies a filter matrix recreating an old Kodachrome camera effect matrix to the image

33
src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs

@ -0,0 +1,33 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Overlays;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Filters.Processors
{
/// <summary>
/// Converts the colors of the image recreating an old Lomograph effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class LomographProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static readonly TPixel VeryDarkGreen = ColorBuilder<TPixel>.FromRGBA(0, 10, 0, 255);
/// <summary>
/// Initializes a new instance of the <see cref="LomographProcessor{TPixel}" /> class.
/// </summary>
public LomographProcessor()
: base(MatrixFilters.LomographFilter)
{
}
/// <inheritdoc/>
protected override void AfterFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
new VignetteProcessor<TPixel>(VeryDarkGreen).Apply(source, sourceRectangle, configuration);
}
}
}

2
src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs → src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Applies an opacity filter matrix using the given amount. /// Applies an opacity filter matrix using the given amount.

35
src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs

@ -0,0 +1,35 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Overlays;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Filters.Processors
{
/// <summary>
/// Converts the colors of the image recreating an old Polaroid effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class PolaroidProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static readonly TPixel VeryDarkOrange = ColorBuilder<TPixel>.FromRGB(102, 34, 0);
private static readonly TPixel LightOrange = ColorBuilder<TPixel>.FromRGBA(255, 153, 102, 128);
/// <summary>
/// Initializes a new instance of the <see cref="PolaroidProcessor{TPixel}" /> class.
/// </summary>
public PolaroidProcessor()
: base(MatrixFilters.PolaroidFilter)
{
}
/// <inheritdoc/>
protected override void AfterFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
new VignetteProcessor<TPixel>(VeryDarkOrange).Apply(source, sourceRectangle, configuration);
new GlowProcessor<TPixel>(LightOrange, source.Width / 4F).Apply(source, sourceRectangle, configuration);
}
}
}

2
src/ImageSharp/Processing/Processors/Filters/ColorBlindness/ProtanomalyProcessor.cs → src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Converts the colors of the image recreating Protanomaly (Red-Weak) color blindness. /// Converts the colors of the image recreating Protanomaly (Red-Weak) color blindness.

3
src/ImageSharp/Processing/Processors/Filters/ColorBlindness/ProtanopiaProcessor.cs → src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs

@ -1,10 +1,9 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors namespace SixLabors.ImageSharp.Processing.Filters.Processors
{ {
/// <summary> /// <summary>
/// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness. /// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness.

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save