Browse Source

Fix namespaces

Former-commit-id: 5e9d8e0d98e6bed499d71b0cab005c2c253ec917
Former-commit-id: 87cc61833ac266b0795f93a8c3a46ba84796e726
Former-commit-id: 2d3e58fe24556ae5701d00236b10125f878b4b63
pull/1/head
James Jackson-South 10 years ago
parent
commit
53199d0592
  1. 75
      src/ImageProcessorCore/Filters/Alpha.cs
  2. 79
      src/ImageProcessorCore/Filters/BackgroundColor.cs
  3. 50
      src/ImageProcessorCore/Filters/BlackWhite.cs
  4. 92
      src/ImageProcessorCore/Filters/Blend.cs
  5. 52
      src/ImageProcessorCore/Filters/BoxBlur.cs
  6. 75
      src/ImageProcessorCore/Filters/Brightness.cs
  7. 88
      src/ImageProcessorCore/Filters/ColorBlindness.cs
  8. 76
      src/ImageProcessorCore/Filters/Contrast.cs
  9. 63
      src/ImageProcessorCore/Filters/DetectEdges.cs
  10. 55
      src/ImageProcessorCore/Filters/Greyscale.cs
  11. 52
      src/ImageProcessorCore/Filters/GuassianBlur.cs
  12. 52
      src/ImageProcessorCore/Filters/GuassianSharpen.cs
  13. 52
      src/ImageProcessorCore/Filters/Hue.cs
  14. 784
      src/ImageProcessorCore/Filters/ImageFilterExtensions.cs
  15. 66
      src/ImageProcessorCore/Filters/Invert.cs
  16. 50
      src/ImageProcessorCore/Filters/Kodachrome.cs
  17. 50
      src/ImageProcessorCore/Filters/Lomograph.cs
  18. 2
      src/ImageProcessorCore/Filters/Options/ColorBlindness.cs
  19. 105
      src/ImageProcessorCore/Filters/Pixelate.cs
  20. 50
      src/ImageProcessorCore/Filters/Polaroid.cs
  21. 69
      src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs
  22. 78
      src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs
  23. 12
      src/ImageProcessorCore/Filters/Processors/Binarization/ThresholdProcessor.cs
  24. 86
      src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs
  25. 69
      src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs
  26. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs
  27. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs
  28. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs
  29. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs
  30. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs
  31. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs
  32. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs
  33. 0
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/README.md
  34. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs
  35. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs
  36. 2
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs
  37. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/GreyscaleBt601Processor.cs
  38. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/GreyscaleBt709Processor.cs
  39. 2
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/GreyscaleMode.cs
  40. 13
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/HueProcessor.cs
  41. 5
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs
  42. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/KodachromeProcessor.cs
  43. 8
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/LomographProcessor.cs
  44. 10
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/PolaroidProcessor.cs
  45. 10
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/SaturationProcessor.cs
  46. 6
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/SepiaProcessor.cs
  47. 70
      src/ImageProcessorCore/Filters/Processors/ContrastProcessor.cs
  48. 10
      src/ImageProcessorCore/Filters/Processors/Convolution/BoxBlurProcessor.cs
  49. 2
      src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2DFilter.cs
  50. 2
      src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2PassFilter.cs
  51. 2
      src/ImageProcessorCore/Filters/Processors/Convolution/ConvolutionFilter.cs
  52. 4
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DFilter.cs
  53. 4
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs
  54. 2
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorFilter.cs
  55. 6
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs
  56. 6
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs
  57. 6
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs
  58. 6
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs
  59. 6
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs
  60. 6
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs
  61. 6
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs
  62. 6
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs
  63. 6
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs
  64. 18
      src/ImageProcessorCore/Filters/Processors/Convolution/GuassianBlurProcessor.cs
  65. 18
      src/ImageProcessorCore/Filters/Processors/Convolution/GuassianSharpenProcessor.cs
  66. 6
      src/ImageProcessorCore/Filters/Processors/GlowProcessor.cs
  67. 48
      src/ImageProcessorCore/Filters/Processors/InvertProcessor.cs
  68. 97
      src/ImageProcessorCore/Filters/Processors/PixelateProcessor.cs
  69. 6
      src/ImageProcessorCore/Filters/Processors/VignetteProcessor.cs
  70. 52
      src/ImageProcessorCore/Filters/Saturation.cs
  71. 50
      src/ImageProcessorCore/Filters/Sepia.cs
  72. 4
      src/ImageProcessorCore/IImageProcessor.cs
  73. 1
      src/ImageProcessorCore/ImageExtensions.cs
  74. 2
      src/ImageProcessorCore/ParallelImageProcessor.cs
  75. 2
      src/ImageProcessorCore/PixelAccessor.cs
  76. 2
      src/ImageProcessorCore/Samplers/Crop.cs
  77. 2
      src/ImageProcessorCore/Samplers/EntropyCrop.cs
  78. 2
      src/ImageProcessorCore/Samplers/Pad.cs
  79. 2
      src/ImageProcessorCore/Samplers/Processors/CropProcessor.cs
  80. 8
      src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs
  81. 2
      src/ImageProcessorCore/Samplers/Processors/IImageSampler.cs
  82. 2
      src/ImageProcessorCore/Samplers/Processors/ImageSampler.cs
  83. 2
      src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs
  84. 3
      src/ImageProcessorCore/Samplers/Processors/RotateFlipProcessor.cs
  85. 2
      src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs
  86. 2
      src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs
  87. 2
      src/ImageProcessorCore/Samplers/Resize.cs
  88. 2
      src/ImageProcessorCore/Samplers/Rotate.cs
  89. 2
      src/ImageProcessorCore/Samplers/RotateFlip.cs
  90. 2
      src/ImageProcessorCore/Samplers/Skew.cs
  91. 84
      tests/ImageProcessorCore.Tests/Processors/Filters/FilterTests.cs
  92. 3
      tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs

75
src/ImageProcessorCore/Filters/Alpha.cs

@ -1,68 +1,51 @@
// <copyright file="Alpha.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore
{
using System;
using System.Numerics;
using System.Threading.Tasks;
using Processors;
/// <summary>
/// An <see cref="IImageProcessor"/> to change the Alpha of an <see cref="Image"/>.
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public class Alpha : ParallelImageProcessor
public static partial class ImageExtensions
{
/// <summary>
/// Initializes a new instance of the <see cref="Alpha"/> class.
/// Alters the alpha component of the image.
/// </summary>
/// <param name="percent">The percentage to adjust the opacity of the image. Must be between 0 and 100.</param>
/// <exception cref="ArgumentException">
/// <paramref name="percent"/> is less than 0 or is greater than 100.
/// </exception>
public Alpha(int percent)
/// <param name="source">The image this method extends.</param>
/// <param name="percent">The new opacity of the image. Must be between 0 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Alpha(this Image source, int percent, ProgressEventHandler progressHandler = null)
{
Guard.MustBeBetweenOrEqualTo(percent, 0, 100, nameof(percent));
this.Value = percent;
return Alpha(source, percent, source.Bounds, progressHandler);
}
/// <summary>
/// Gets the alpha value.
/// Alters the alpha component of the image.
/// </summary>
public int Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
/// <param name="source">The image this method extends.</param>
/// <param name="percent">The new opacity of the image. Must be between 0 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Alpha(this Image source, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
float alpha = this.Value / 100f;
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Vector4 alphaVector = new Vector4(1, 1, 1, alpha);
AlphaProcessor processor = new AlphaProcessor(percent);
processor.OnProgress += progressHandler;
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
try
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Vector4 color = Color.ToNonPremultiplied(sourcePixels[x, y]).ToVector4();
color *= alphaVector;
targetPixels[x, y] = Color.FromNonPremultiplied(new Color(color));
}
this.OnRowProcessed();
}
});
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}

79
src/ImageProcessorCore/Filters/BackgroundColor.cs

@ -1,77 +1,36 @@
// <copyright file="BackgroundColor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore
{
using System;
using System.Threading.Tasks;
using Processors;
/// <summary>
/// Sets the background color of the image.
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public class BackgroundColor : ParallelImageProcessor
public static partial class ImageExtensions
{
/// <summary>
/// The epsilon for comparing floating point numbers.
/// Combines the given image together with the current one by blending their pixels.
/// </summary>
private const float Epsilon = 0.001f;
/// <summary>
/// Initializes a new instance of the <see cref="BackgroundColor"/> class.
/// </summary>
/// <param name="color">The <see cref="Color"/> to set the background color to.</param>
public BackgroundColor(Color color)
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color to set as the background.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BackgroundColor(this Image source, Color color, ProgressEventHandler progressHandler = null)
{
this.Value = Color.FromNonPremultiplied(color);
}
BackgroundColorProcessor processor = new BackgroundColorProcessor(color);
processor.OnProgress += progressHandler;
/// <summary>
/// Gets the background color value.
/// </summary>
public Color Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Color backgroundColor = this.Value;
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
try
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Color color = sourcePixels[x, y];
float a = color.A;
if (a < 1 && a > 0)
{
color = Color.Lerp(color, backgroundColor, .5f);
}
if (Math.Abs(a) < Epsilon)
{
color = backgroundColor;
}
targetPixels[x, y] = color;
}
this.OnRowProcessed();
}
});
return source.Process(source.Bounds, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}

50
src/ImageProcessorCore/Filters/BlackWhite.cs

@ -0,0 +1,50 @@
// <copyright file="BlackWhite.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies black and white toning to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BlackWhite(this Image source, ProgressEventHandler progressHandler = null)
{
return BlackWhite(source, source.Bounds, progressHandler);
}
/// <summary>
/// Applies black and white toning to the image.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BlackWhite(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
BlackWhiteProcessor processor = new BlackWhiteProcessor();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

92
src/ImageProcessorCore/Filters/Blend.cs

@ -1,85 +1,59 @@
// <copyright file="Blend.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore
{
using System.Threading.Tasks;
using Processors;
/// <summary>
/// Combines two images together by blending the pixels.
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public class Blend : ParallelImageProcessor
public static partial class ImageExtensions
{
/// <summary>
/// The image to blend.
/// </summary>
private readonly ImageBase blend;
/// <summary>
/// Initializes a new instance of the <see cref="Blend"/> class.
/// Combines the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="image">
/// The image to blend with the currently processing image.
/// Disposal of this image is the responsibility of the developer.
/// </param>
/// <param name="alpha">The opacity of the image to blend. Between 0 and 100.</param>
public Blend(ImageBase image, int alpha = 100)
/// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Blend(this Image source, ImageBase image, int percent = 50, ProgressEventHandler progressHandler = null)
{
Guard.MustBeBetweenOrEqualTo(alpha, 0, 100, nameof(alpha));
this.blend = image;
this.Value = alpha;
return Blend(source, image, percent, source.Bounds, progressHandler);
}
/// <summary>
/// Gets the alpha percentage value.
/// Combines the given image together with the current one by blending their pixels.
/// </summary>
public int Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
/// <param name="source">The image this method extends.</param>
/// <param name="image">
/// The image to blend with the currently processing image.
/// Disposal of this image is the responsibility of the developer.
/// </param>
/// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Blend(this Image source, ImageBase image, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Rectangle bounds = this.blend.Bounds;
float alpha = this.Value / 100f;
BlendProcessor processor = new BlendProcessor(image, percent);
processor.OnProgress += progressHandler;
using (PixelAccessor toBlendPixels = this.blend.Lock())
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
try
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Color color = sourcePixels[x, y];
if (bounds.Contains(x, y))
{
Color blendedColor = toBlendPixels[x, y];
if (blendedColor.A > 0)
{
// Lerping colors is dependent on the alpha of the blended color
float alphaFactor = alpha > 0 ? alpha : blendedColor.A;
color = Color.Lerp(color, blendedColor, alphaFactor);
}
}
targetPixels[x, y] = color;
}
this.OnRowProcessed();
}
});
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}

52
src/ImageProcessorCore/Filters/BoxBlur.cs

@ -0,0 +1,52 @@
// <copyright file="BoxBlur.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies a box blur to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BoxBlur(this Image source, int radius = 7, ProgressEventHandler progressHandler = null)
{
return BoxBlur(source, radius, source.Bounds, progressHandler);
}
/// <summary>
/// Applies a box blur to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BoxBlur(this Image source, int radius, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
BoxBlurProcessor processor = new BoxBlurProcessor(radius);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

75
src/ImageProcessorCore/Filters/Brightness.cs

@ -1,68 +1,51 @@
// <copyright file="Brightness.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore
{
using System;
using System.Numerics;
using System.Threading.Tasks;
using Processors;
/// <summary>
/// An <see cref="IImageProcessor"/> to change the brightness of an <see cref="Image"/>.
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public class Brightness : ParallelImageProcessor
public static partial class ImageExtensions
{
/// <summary>
/// Initializes a new instance of the <see cref="Brightness"/> class.
/// Alters the brightness component of the image.
/// </summary>
/// <param name="brightness">The new brightness of the image. Must be between -100 and 100.</param>
/// <exception cref="ArgumentException">
/// <paramref name="brightness"/> is less than -100 or is greater than 100.
/// </exception>
public Brightness(int brightness)
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new brightness of the image. Must be between -100 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Brightness(this Image source, int amount, ProgressEventHandler progressHandler = null)
{
Guard.MustBeBetweenOrEqualTo(brightness, -100, 100, nameof(brightness));
this.Value = brightness;
return Brightness(source, amount, source.Bounds, progressHandler);
}
/// <summary>
/// Gets the brightness value.
/// Alters the brightness component of the image.
/// </summary>
public int Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new brightness of the image. Must be between -100 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Brightness(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
float brightness = this.Value / 100f;
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
BrightnessProcessor processor = new BrightnessProcessor(amount);
processor.OnProgress += progressHandler;
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
try
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Color color = Color.Expand(sourcePixels[x, y]);
Vector3 vector3 = color.ToVector3();
vector3 += new Vector3(brightness);
targetPixels[x, y] = Color.Compress(new Color(vector3, color.A));
}
this.OnRowProcessed();
}
});
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}

88
src/ImageProcessorCore/Filters/ColorBlindness.cs

@ -0,0 +1,88 @@
// <copyright file="ColorBlindness.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies the given colorblindness simulator to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, ProgressEventHandler progressHandler = null)
{
return ColorBlindness(source, colorBlindness, source.Bounds, progressHandler);
}
/// <summary>
/// Applies the given colorblindness simulator to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
IImageProcessor processor;
switch (colorBlindness)
{
case ImageProcessorCore.ColorBlindness.Achromatomaly:
processor = new AchromatomalyProcessor();
break;
case ImageProcessorCore.ColorBlindness.Achromatopsia:
processor = new AchromatopsiaProcessor();
break;
case ImageProcessorCore.ColorBlindness.Deuteranomaly:
processor = new DeuteranomalyProcessor();
break;
case ImageProcessorCore.ColorBlindness.Deuteranopia:
processor = new DeuteranopiaProcessor();
break;
case ImageProcessorCore.ColorBlindness.Protanomaly:
processor = new ProtanomalyProcessor();
break;
case ImageProcessorCore.ColorBlindness.Protanopia:
processor = new ProtanopiaProcessor();
break;
case ImageProcessorCore.ColorBlindness.Tritanomaly:
processor = new TritanomalyProcessor();
break;
default:
processor = new TritanopiaProcessor();
break;
}
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

76
src/ImageProcessorCore/Filters/Contrast.cs

@ -1,69 +1,51 @@
// <copyright file="Contrast.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore
{
using System;
using System.Numerics;
using System.Threading.Tasks;
using Processors;
/// <summary>
/// An <see cref="IImageProcessor"/> to change the contrast of an <see cref="Image"/>.
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public class Contrast : ParallelImageProcessor
public static partial class ImageExtensions
{
/// <summary>
/// Initializes a new instance of the <see cref="Contrast"/> class.
/// Alters the contrast component of the image.
/// </summary>
/// <param name="contrast">The new contrast of the image. Must be between -100 and 100.</param>
/// <exception cref="ArgumentException">
/// <paramref name="contrast"/> is less than -100 or is greater than 100.
/// </exception>
public Contrast(int contrast)
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new contrast of the image. Must be between -100 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Contrast(this Image source, int amount, ProgressEventHandler progressHandler = null)
{
Guard.MustBeBetweenOrEqualTo(contrast, -100, 100, nameof(contrast));
this.Value = contrast;
return Contrast(source, amount, source.Bounds, progressHandler);
}
/// <summary>
/// Gets the contrast value.
/// Alters the contrast component of the image.
/// </summary>
public int Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new contrast of the image. Must be between -100 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Contrast(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
float contrast = (100f + this.Value) / 100f;
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Vector4 contrastVector = new Vector4(contrast, contrast, contrast, 1);
Vector4 shiftVector = new Vector4(.5f, .5f, .5f, 1);
ContrastProcessor processor = new ContrastProcessor(amount);
processor.OnProgress += progressHandler;
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
try
{
return source.Process(rectangle, processor);
}
finally
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Vector4 color = Color.Expand(sourcePixels[x, y]).ToVector4();
color -= shiftVector;
color *= contrastVector;
color += shiftVector;
targetPixels[x, y] = Color.Compress(new Color(color));
}
this.OnRowProcessed();
}
});
processor.OnProgress -= progressHandler;
}
}
}

63
src/ImageProcessorCore/Filters/DetectEdges.cs

@ -0,0 +1,63 @@
// <copyright file="DetectEdges.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Detects any edges within the image. Uses the <see cref="SobelProcessor"/> filter
/// operating in greyscale mode.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image DetectEdges(this Image source, ProgressEventHandler progressHandler = null)
{
return DetectEdges(source, source.Bounds, new SobelProcessor { Greyscale = true }, progressHandler);
}
/// <summary>
/// Detects any edges within the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="filter">The filter for detecting edges.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image DetectEdges(this Image source, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null)
{
return DetectEdges(source, source.Bounds, filter, progressHandler);
}
/// <summary>
/// Detects any edges within the image.
/// </summary>
/// <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="filter">The filter for detecting edges.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null)
{
filter.OnProgress += progressHandler;
try
{
return source.Process(rectangle, filter);
}
finally
{
filter.OnProgress -= progressHandler;
}
}
}
}

55
src/ImageProcessorCore/Filters/Greyscale.cs

@ -0,0 +1,55 @@
// <copyright file="Greyscale.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies greyscale toning to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Greyscale(this Image source, GreyscaleMode mode = GreyscaleMode.Bt709, ProgressEventHandler progressHandler = null)
{
return Greyscale(source, source.Bounds, mode, progressHandler);
}
/// <summary>
/// Applies greyscale toning to the image.
/// </summary>
/// <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="mode">The formula to apply to perform the operation.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Greyscale(this Image source, Rectangle rectangle, GreyscaleMode mode = GreyscaleMode.Bt709, ProgressEventHandler progressHandler = null)
{
IImageProcessor processor = mode == GreyscaleMode.Bt709
? (IImageProcessor)new GreyscaleBt709Processor()
: new GreyscaleBt601Processor();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

52
src/ImageProcessorCore/Filters/GuassianBlur.cs

@ -0,0 +1,52 @@
// <copyright file="GuassianBlur.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies a Guassian blur to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image GuassianBlur(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null)
{
return GuassianBlur(source, sigma, source.Bounds, progressHandler);
}
/// <summary>
/// Applies a Guassian blur to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image GuassianBlur(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
GuassianBlurProcessor processor = new GuassianBlurProcessor(sigma);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

52
src/ImageProcessorCore/Filters/GuassianSharpen.cs

@ -0,0 +1,52 @@
// <copyright file="GuassianSharpen.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies a Guassian sharpening filter to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image GuassianSharpen(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null)
{
return GuassianSharpen(source, sigma, source.Bounds, progressHandler);
}
/// <summary>
/// Applies a Guassian sharpening filter to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image GuassianSharpen(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
GuassianSharpenProcessor processor = new GuassianSharpenProcessor(sigma);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

52
src/ImageProcessorCore/Filters/Hue.cs

@ -0,0 +1,52 @@
// <copyright file="Hue.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Alters the hue component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="degrees">The angle in degrees to adjust the image.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Hue(this Image source, float degrees, ProgressEventHandler progressHandler = null)
{
return Hue(source, degrees, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the hue component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="degrees">The angle in degrees to adjust the image.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Hue(this Image source, float degrees, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
HueProcessor processor = new HueProcessor(degrees);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

784
src/ImageProcessorCore/Filters/ImageFilterExtensions.cs

@ -1,784 +0,0 @@
// <copyright file="ImageFilterExtensions.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
{
/// <summary>
/// Extensions methods for <see cref="Image"/> to apply filters to the image.
/// </summary>
public static class ImageFilterExtensions
{
/// <summary>
/// Alters the alpha component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="percent">The new opacity of the image. Must be between 0 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Alpha(this Image source, int percent, ProgressEventHandler progressHandler = null)
{
return Alpha(source, percent, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the alpha component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="percent">The new opacity of the image. Must be between 0 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Alpha(this Image source, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Alpha processor = new Alpha(percent);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Combines the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color to set as the background.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BackgroundColor(this Image source, Color color, ProgressEventHandler progressHandler = null)
{
BackgroundColor processor = new BackgroundColor(color);
processor.OnProgress += progressHandler;
try
{
return source.Process(source.Bounds, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Combines the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="image">
/// The image to blend with the currently processing image.
/// Disposal of this image is the responsibility of the developer.
/// </param>
/// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Blend(this Image source, ImageBase image, int percent = 50, ProgressEventHandler progressHandler = null)
{
return Blend(source, image, percent, source.Bounds, progressHandler);
}
/// <summary>
/// Combines the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="image">
/// The image to blend with the currently processing image.
/// Disposal of this image is the responsibility of the developer.
/// </param>
/// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Blend(this Image source, ImageBase image, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Blend processor = new Blend(image, percent);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Applies black and white toning to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BlackWhite(this Image source, ProgressEventHandler progressHandler = null)
{
return BlackWhite(source, source.Bounds, progressHandler);
}
/// <summary>
/// Applies black and white toning to the image.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BlackWhite(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
BlackWhite processor = new BlackWhite();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Applies a box blur to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BoxBlur(this Image source, int radius = 7, ProgressEventHandler progressHandler = null)
{
return BoxBlur(source, radius, source.Bounds, progressHandler);
}
/// <summary>
/// Applies a box blur to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BoxBlur(this Image source, int radius, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
BoxBlur processor = new BoxBlur(radius);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Alters the brightness component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new brightness of the image. Must be between -100 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Brightness(this Image source, int amount, ProgressEventHandler progressHandler = null)
{
return Brightness(source, amount, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the brightness component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new brightness of the image. Must be between -100 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Brightness(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Brightness processor = new Brightness(amount);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Applies the given colorblindness simulator to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, ProgressEventHandler progressHandler = null)
{
return ColorBlindness(source, colorBlindness, source.Bounds, progressHandler);
}
/// <summary>
/// Applies the given colorblindness simulator to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
IImageProcessor processor;
switch (colorBlindness)
{
case Filters.ColorBlindness.Achromatomaly:
processor = new Achromatomaly();
break;
case Filters.ColorBlindness.Achromatopsia:
processor = new Achromatopsia();
break;
case Filters.ColorBlindness.Deuteranomaly:
processor = new Deuteranomaly();
break;
case Filters.ColorBlindness.Deuteranopia:
processor = new Deuteranopia();
break;
case Filters.ColorBlindness.Protanomaly:
processor = new Protanomaly();
break;
case Filters.ColorBlindness.Protanopia:
processor = new Protanopia();
break;
case Filters.ColorBlindness.Tritanomaly:
processor = new Tritanomaly();
break;
default:
processor = new Tritanopia();
break;
}
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Alters the contrast component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new contrast of the image. Must be between -100 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Contrast(this Image source, int amount, ProgressEventHandler progressHandler = null)
{
return Contrast(source, amount, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the contrast component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new contrast of the image. Must be between -100 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Contrast(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Contrast processor = new Contrast(amount);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Detects any edges within the image. Uses the <see cref="Sobel"/> filter
/// operating in greyscale mode.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image DetectEdges(this Image source, ProgressEventHandler progressHandler = null)
{
return DetectEdges(source, source.Bounds, new Sobel { Greyscale = true }, progressHandler);
}
/// <summary>
/// Detects any edges within the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="filter">The filter for detecting edges.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image DetectEdges(this Image source, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null)
{
return DetectEdges(source, source.Bounds, filter, progressHandler);
}
/// <summary>
/// Detects any edges within the image.
/// </summary>
/// <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="filter">The filter for detecting edges.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null)
{
filter.OnProgress += progressHandler;
try
{
return source.Process(rectangle, filter);
}
finally
{
filter.OnProgress -= progressHandler;
}
}
/// <summary>
/// Applies greyscale toning to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Greyscale(this Image source, GreyscaleMode mode = GreyscaleMode.Bt709, ProgressEventHandler progressHandler = null)
{
return Greyscale(source, source.Bounds, mode, progressHandler);
}
/// <summary>
/// Applies greyscale toning to the image.
/// </summary>
/// <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="mode">The formula to apply to perform the operation.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Greyscale(this Image source, Rectangle rectangle, GreyscaleMode mode = GreyscaleMode.Bt709, ProgressEventHandler progressHandler = null)
{
IImageProcessor processor = mode == GreyscaleMode.Bt709
? (IImageProcessor)new GreyscaleBt709()
: new GreyscaleBt601();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Applies a Guassian blur to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image GuassianBlur(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null)
{
return GuassianBlur(source, sigma, source.Bounds, progressHandler);
}
/// <summary>
/// Applies a Guassian blur to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image GuassianBlur(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
GuassianBlur processor = new GuassianBlur(sigma);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Applies a Guassian sharpening filter to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image GuassianSharpen(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null)
{
return GuassianSharpen(source, sigma, source.Bounds, progressHandler);
}
/// <summary>
/// Applies a Guassian sharpening filter to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image GuassianSharpen(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
GuassianSharpen processor = new GuassianSharpen(sigma);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Alters the hue component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="degrees">The angle in degrees to adjust the image.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Hue(this Image source, float degrees, ProgressEventHandler progressHandler = null)
{
return Hue(source, degrees, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the hue component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="degrees">The angle in degrees to adjust the image.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Hue(this Image source, float degrees, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Hue processor = new Hue(degrees);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Inverts the colors of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Invert(this Image source, ProgressEventHandler progressHandler = null)
{
return Invert(source, source.Bounds, progressHandler);
}
/// <summary>
/// Inverts the colors of the image.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Invert(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Invert processor = new Invert();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Kodachrome(this Image source, ProgressEventHandler progressHandler = null)
{
return Kodachrome(source, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Kodachrome(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Kodachrome processor = new Kodachrome();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Lomograph(this Image source, ProgressEventHandler progressHandler = null)
{
return Lomograph(source, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Lomograph(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Lomograph processor = new Lomograph();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Polaroid(this Image source, ProgressEventHandler progressHandler = null)
{
return Polaroid(source, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Polaroid(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Polaroid processor = new Polaroid();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Pixelates and image with the given pixel size.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Pixelate(this Image source, int size = 4, ProgressEventHandler progressHandler = null)
{
return Pixelate(source, size, source.Bounds, progressHandler);
}
/// <summary>
/// Pixelates and image with the given pixel size.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Pixelate(this Image source, int size, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Pixelate processor = new Pixelate(size);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Alters the saturation component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Saturation(this Image source, int amount, ProgressEventHandler progressHandler = null)
{
return Saturation(source, amount, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the saturation component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Saturation(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Saturation processor = new Saturation(amount);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
/// <summary>
/// Applies sepia toning to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Sepia(this Image source, ProgressEventHandler progressHandler = null)
{
return Sepia(source, source.Bounds, progressHandler);
}
/// <summary>
/// Applies sepia toning to the image.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Sepia(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
Sepia processor = new Sepia();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

66
src/ImageProcessorCore/Filters/Invert.cs

@ -1,47 +1,49 @@
// <copyright file="Invert.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore
{
using System.Numerics;
using System.Threading.Tasks;
using Processors;
/// <summary>
/// An <see cref="IImageProcessor"/> to invert the colors of an <see cref="Image"/>.
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public class Invert : ParallelImageProcessor
public static partial class ImageExtensions
{
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
/// <summary>
/// Inverts the colors of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Invert(this Image source, ProgressEventHandler progressHandler = null)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Vector3 inverseVector = Vector3.One;
return Invert(source, source.Bounds, progressHandler);
}
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Color color = sourcePixels[x, y];
Vector3 vector = inverseVector - color.ToVector3();
targetPixels[x, y] = new Color(vector, color.A);
}
/// <summary>
/// Inverts the colors of the image.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Invert(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
InvertProcessor processor = new InvertProcessor();
processor.OnProgress += progressHandler;
this.OnRowProcessed();
}
});
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}

50
src/ImageProcessorCore/Filters/Kodachrome.cs

@ -0,0 +1,50 @@
// <copyright file="Kodachrome.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Kodachrome(this Image source, ProgressEventHandler progressHandler = null)
{
return Kodachrome(source, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Kodachrome(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
KodachromeProcessor processor = new KodachromeProcessor();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

50
src/ImageProcessorCore/Filters/Lomograph.cs

@ -0,0 +1,50 @@
// <copyright file="Lomograph.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Lomograph(this Image source, ProgressEventHandler progressHandler = null)
{
return Lomograph(source, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Lomograph(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
LomographProcessor processor = new LomographProcessor();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

2
src/ImageProcessorCore/Filters/ColorMatrix/ColorBlindness/ColorBlindness.cs → src/ImageProcessorCore/Filters/Options/ColorBlindness.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore
{
/// <summary>
/// Enumerates the various types of color blindness.

105
src/ImageProcessorCore/Filters/Pixelate.cs

@ -1,96 +1,51 @@
// <copyright file="Invert.cs" company="James Jackson-South">
// <copyright file="Pixelate.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Processors;
/// <summary>
/// An <see cref="IImageProcessor"/> to invert the colors of an <see cref="Image"/>.
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public class Pixelate : ParallelImageProcessor
public static partial class ImageExtensions
{
/// <summary>
/// Initializes a new instance of the <see cref="Pixelate"/> class.
/// Pixelates and image with the given pixel size.
/// </summary>
/// <param name="size">The size of the pixels. Must be greater than 0.</param>
/// <exception cref="ArgumentException">
/// <paramref name="size"/> is less than 0 or equal to 0.
/// </exception>
public Pixelate(int size)
/// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Pixelate(this Image source, int size = 4, ProgressEventHandler progressHandler = null)
{
Guard.MustBeGreaterThan(size, 0, nameof(size));
this.Value = size;
return Pixelate(source, size, source.Bounds, progressHandler);
}
/// <inheritdoc/>
public override int Parallelism { get; set; } = 1;
/// <summary>
/// Gets or the pixel size.
/// Pixelates and image with the given pixel size.
/// </summary>
public int Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
/// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Pixelate(this Image source, int size, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
int size = this.Value;
int offset = this.Value / 2;
// Get the range on the y-plane to choose from.
IEnumerable<int> range = EnumerableExtensions.SteppedRange(startY, i => i < endY, size);
PixelateProcessor processor = new PixelateProcessor(size);
processor.OnProgress += progressHandler;
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
try
{
Parallel.ForEach(
range,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x += size)
{
int offsetX = offset;
int offsetY = offset;
// Make sure that the offset is within the boundary of the
// image.
while (y + offsetY >= sourceBottom)
{
offsetY--;
}
while (x + offsetX >= endX)
{
offsetX--;
}
// Get the pixel color in the centre of the soon to be pixelated area.
// ReSharper disable AccessToDisposedClosure
Color pixel = sourcePixels[x + offsetX, y + offsetY];
// For each pixel in the pixelate size, set it to the centre color.
for (int l = y; l < y + size && l < sourceBottom; l++)
{
for (int k = x; k < x + size && k < endX; k++)
{
targetPixels[k, l] = pixel;
}
}
}
this.OnRowProcessed();
}
});
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}

50
src/ImageProcessorCore/Filters/Polaroid.cs

@ -0,0 +1,50 @@
// <copyright file="Polaroid.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Polaroid(this Image source, ProgressEventHandler progressHandler = null)
{
return Polaroid(source, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Polaroid(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
PolaroidProcessor processor = new PolaroidProcessor();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

69
src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs

@ -0,0 +1,69 @@
// <copyright file="AlphaProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
{
using System;
using System.Numerics;
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageProcessor"/> to change the Alpha of an <see cref="Image"/>.
/// </summary>
public class AlphaProcessor : ParallelImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="AlphaProcessor"/> class.
/// </summary>
/// <param name="percent">The percentage to adjust the opacity of the image. Must be between 0 and 100.</param>
/// <exception cref="ArgumentException">
/// <paramref name="percent"/> is less than 0 or is greater than 100.
/// </exception>
public AlphaProcessor(int percent)
{
Guard.MustBeBetweenOrEqualTo(percent, 0, 100, nameof(percent));
this.Value = percent;
}
/// <summary>
/// Gets the alpha value.
/// </summary>
public int Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
float alpha = this.Value / 100f;
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Vector4 alphaVector = new Vector4(1, 1, 1, alpha);
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Vector4 color = Color.ToNonPremultiplied(sourcePixels[x, y]).ToVector4();
color *= alphaVector;
targetPixels[x, y] = Color.FromNonPremultiplied(new Color(color));
}
this.OnRowProcessed();
}
});
}
}
}
}

78
src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs

@ -0,0 +1,78 @@
// <copyright file="BackgroundColorProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
{
using System;
using System.Threading.Tasks;
/// <summary>
/// Sets the background color of the image.
/// </summary>
public class BackgroundColorProcessor : ParallelImageProcessor
{
/// <summary>
/// The epsilon for comparing floating point numbers.
/// </summary>
private const float Epsilon = 0.001f;
/// <summary>
/// Initializes a new instance of the <see cref="BackgroundColorProcessor"/> class.
/// </summary>
/// <param name="color">The <see cref="Color"/> to set the background color to.</param>
public BackgroundColorProcessor(Color color)
{
this.Value = Color.FromNonPremultiplied(color);
}
/// <summary>
/// Gets the background color value.
/// </summary>
public Color Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Color backgroundColor = this.Value;
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Color color = sourcePixels[x, y];
float a = color.A;
if (a < 1 && a > 0)
{
color = Color.Lerp(color, backgroundColor, .5f);
}
if (Math.Abs(a) < Epsilon)
{
color = backgroundColor;
}
targetPixels[x, y] = color;
}
this.OnRowProcessed();
}
});
}
}
}
}

12
src/ImageProcessorCore/Filters/Binarization/Threshold.cs → src/ImageProcessorCore/Filters/Processors/Binarization/ThresholdProcessor.cs

@ -1,9 +1,9 @@
// <copyright file="Threshold.cs" company="James Jackson-South">
// <copyright file="ThresholdProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System;
using System.Threading.Tasks;
@ -13,16 +13,16 @@ namespace ImageProcessorCore.Filters
/// <see cref="Image"/>. The image will be converted to greyscale before thresholding
/// occurs.
/// </summary>
public class Threshold : ParallelImageProcessor
public class ThresholdProcessor : ParallelImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="Threshold"/> class.
/// Initializes a new instance of the <see cref="ThresholdProcessor"/> class.
/// </summary>
/// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param>
/// <exception cref="ArgumentException">
/// <paramref name="threshold"/> is less than 0 or is greater than 1.
/// </exception>
public Threshold(float threshold)
public ThresholdProcessor(float threshold)
{
Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold));
this.Value = threshold;
@ -46,7 +46,7 @@ namespace ImageProcessorCore.Filters
/// <inheritdoc/>
protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle)
{
new GreyscaleBt709().Apply(source, source, sourceRectangle);
new GreyscaleBt709Processor().Apply(source, source, sourceRectangle);
}
/// <inheritdoc/>

86
src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs

@ -0,0 +1,86 @@
// <copyright file="BlendProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
{
using System.Threading.Tasks;
/// <summary>
/// Combines two images together by blending the pixels.
/// </summary>
public class BlendProcessor : ParallelImageProcessor
{
/// <summary>
/// The image to blend.
/// </summary>
private readonly ImageBase blend;
/// <summary>
/// Initializes a new instance of the <see cref="BlendProcessor"/> class.
/// </summary>
/// <param name="image">
/// The image to blend with the currently processing image.
/// Disposal of this image is the responsibility of the developer.
/// </param>
/// <param name="alpha">The opacity of the image to blend. Between 0 and 100.</param>
public BlendProcessor(ImageBase image, int alpha = 100)
{
Guard.MustBeBetweenOrEqualTo(alpha, 0, 100, nameof(alpha));
this.blend = image;
this.Value = alpha;
}
/// <summary>
/// Gets the alpha percentage value.
/// </summary>
public int Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Rectangle bounds = this.blend.Bounds;
float alpha = this.Value / 100f;
using (PixelAccessor toBlendPixels = this.blend.Lock())
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Color color = sourcePixels[x, y];
if (bounds.Contains(x, y))
{
Color blendedColor = toBlendPixels[x, y];
if (blendedColor.A > 0)
{
// Lerping colors is dependent on the alpha of the blended color
float alphaFactor = alpha > 0 ? alpha : blendedColor.A;
color = Color.Lerp(color, blendedColor, alphaFactor);
}
}
targetPixels[x, y] = color;
}
this.OnRowProcessed();
}
});
}
}
}
}

69
src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs

@ -0,0 +1,69 @@
// <copyright file="BrightnessProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
{
using System;
using System.Numerics;
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageProcessor"/> to change the brightness of an <see cref="Image"/>.
/// </summary>
public class BrightnessProcessor : ParallelImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="BrightnessProcessor"/> class.
/// </summary>
/// <param name="brightness">The new brightness of the image. Must be between -100 and 100.</param>
/// <exception cref="ArgumentException">
/// <paramref name="brightness"/> is less than -100 or is greater than 100.
/// </exception>
public BrightnessProcessor(int brightness)
{
Guard.MustBeBetweenOrEqualTo(brightness, -100, 100, nameof(brightness));
this.Value = brightness;
}
/// <summary>
/// Gets the brightness value.
/// </summary>
public int Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
float brightness = this.Value / 100f;
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Color color = Color.Expand(sourcePixels[x, y]);
Vector3 vector3 = color.ToVector3();
vector3 += new Vector3(brightness);
targetPixels[x, y] = Color.Compress(new Color(vector3, color.A));
}
this.OnRowProcessed();
}
});
}
}
}
}

6
src/ImageProcessorCore/Filters/ColorMatrix/BlackWhite.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="BlackWhite.cs" company="James Jackson-South">
// <copyright file="BlackWhiteProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image to their black and white equivalent.
/// </summary>
public class BlackWhite : ColorMatrixFilter
public class BlackWhiteProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageProcessorCore/Filters/ColorMatrix/ColorBlindness/Achromatomaly.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Achromatomaly.cs" company="James Jackson-South">
// <copyright file="AchromatomalyProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness.
/// </summary>
public class Achromatomaly : ColorMatrixFilter
public class AchromatomalyProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageProcessorCore/Filters/ColorMatrix/ColorBlindness/Achromatopsia.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Achromatopsia.cs" company="James Jackson-South">
// <copyright file="AchromatopsiaProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness.
/// </summary>
public class Achromatopsia : ColorMatrixFilter
public class AchromatopsiaProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageProcessorCore/Filters/ColorMatrix/ColorBlindness/Deuteranomaly.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Deuteranomaly.cs" company="James Jackson-South">
// <copyright file="DeuteranomalyProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness.
/// </summary>
public class Deuteranomaly : ColorMatrixFilter
public class DeuteranomalyProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageProcessorCore/Filters/ColorMatrix/ColorBlindness/Deuteranopia.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Deuteranopia.cs" company="James Jackson-South">
// <copyright file="DeuteranopiaProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness.
/// </summary>
public class Deuteranopia : ColorMatrixFilter
public class DeuteranopiaProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageProcessorCore/Filters/ColorMatrix/ColorBlindness/Protanomaly.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Protanomaly.cs" company="James Jackson-South">
// <copyright file="ProtanomalyProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image recreating Protanopia (Red-Weak) color blindness.
/// </summary>
public class Protanomaly : ColorMatrixFilter
public class ProtanomalyProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageProcessorCore/Filters/ColorMatrix/ColorBlindness/Protanopia.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Protanopia.cs" company="James Jackson-South">
// <copyright file="ProtanopiaProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness.
/// </summary>
public class Protanopia : ColorMatrixFilter
public class ProtanopiaProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

0
src/ImageProcessorCore/Filters/ColorMatrix/ColorBlindness/README.md → src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/README.md

6
src/ImageProcessorCore/Filters/ColorMatrix/ColorBlindness/Tritanomaly.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Tritanomaly.cs" company="James Jackson-South">
// <copyright file="TritanomalyProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image recreating Tritanomaly (Blue-Weak) color blindness.
/// </summary>
public class Tritanomaly : ColorMatrixFilter
public class TritanomalyProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageProcessorCore/Filters/ColorMatrix/ColorBlindness/Tritanopia.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Tritanopia.cs" company="James Jackson-South">
// <copyright file="TritanopiaProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image recreating Tritanopia (Blue-Blind) color blindness.
/// </summary>
public class Tritanopia : ColorMatrixFilter
public class TritanopiaProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

2
src/ImageProcessorCore/Filters/ColorMatrix/ColorMatrixFilter.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
using System.Threading.Tasks;

6
src/ImageProcessorCore/Filters/ColorMatrix/GreyscaleBt601.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/GreyscaleBt601Processor.cs

@ -1,9 +1,9 @@
// <copyright file="GreyscaleBt601.cs" company="James Jackson-South">
// <copyright file="GreyscaleBt601Processor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
@ -11,7 +11,7 @@ namespace ImageProcessorCore.Filters
/// Converts the colors of the image to greyscale applying 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"/>.
/// </summary>
public class GreyscaleBt601 : ColorMatrixFilter
public class GreyscaleBt601Processor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageProcessorCore/Filters/ColorMatrix/GreyscaleBt709.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/GreyscaleBt709Processor.cs

@ -1,9 +1,9 @@
// <copyright file="GreyscaleBt709.cs" company="James Jackson-South">
// <copyright file="GreyscaleBt709Processor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
@ -11,7 +11,7 @@ namespace ImageProcessorCore.Filters
/// Converts the colors of the image to greyscale applying the formula as specified by
/// ITU-R Recommendation BT.709 <see href="https://en.wikipedia.org/wiki/Rec._709#Luma_coefficients"/>.
/// </summary>
public class GreyscaleBt709 : ColorMatrixFilter
public class GreyscaleBt709Processor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

2
src/ImageProcessorCore/Filters/ColorMatrix/GreyscaleMode.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/GreyscaleMode.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// Provides enumeration over the various greyscale methods available.

13
src/ImageProcessorCore/Filters/ColorMatrix/Hue.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/HueProcessor.cs

@ -1,9 +1,14 @@
namespace ImageProcessorCore.Filters
// <copyright file="HueProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
{
using System;
using System.Numerics;
public class Hue : ColorMatrixFilter
public class HueProcessor : ColorMatrixFilter
{
/// <summary>
/// The <see cref="Matrix4x4"/> used to alter the image.
@ -11,10 +16,10 @@
private Matrix4x4 matrix;
/// <summary>
/// Initializes a new instance of the <see cref="Hue"/> class.
/// Initializes a new instance of the <see cref="HueProcessor"/> class.
/// </summary>
/// <param name="angle">The new brightness of the image. Must be between -100 and 100.</param>
public Hue(float angle)
public HueProcessor(float angle)
{
// Wrap the angle round at 360.
angle = angle % 360;

5
src/ImageProcessorCore/Filters/ColorMatrix/IColorMatrixFilter.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
@ -19,7 +19,8 @@ namespace ImageProcessorCore.Filters
Matrix4x4 Matrix { get; }
/// <summary>
/// Gets a value indicating whether to compand the value on processing.
/// Gets a value indicating whether to compress
/// or expand individual pixel colors the value on processing.
/// </summary>
bool Compand { get; }
}

6
src/ImageProcessorCore/Filters/ColorMatrix/Kodachrome.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/KodachromeProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Kodachrome.cs" company="James Jackson-South">
// <copyright file="KodachromeProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
public class Kodachrome : ColorMatrixFilter
public class KodachromeProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

8
src/ImageProcessorCore/Filters/ColorMatrix/Lomograph.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/LomographProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Lomograph.cs" company="James Jackson-South">
// <copyright file="LomographProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image recreating an old Lomograph effect.
/// </summary>
public class Lomograph : ColorMatrixFilter
public class LomographProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
@ -26,7 +26,7 @@ namespace ImageProcessorCore.Filters
/// <inheritdoc/>
protected override void AfterApply(ImageBase source, ImageBase target, Rectangle targetRectangle, Rectangle sourceRectangle)
{
new Vignette { Color = new Color(0, 10 / 255f, 0) }.Apply(target, target, targetRectangle);
new VignetteProcessor { Color = new Color(0, 10 / 255f, 0) }.Apply(target, target, targetRectangle);
}
}
}

10
src/ImageProcessorCore/Filters/ColorMatrix/Polaroid.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/PolaroidProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="Polaroid.cs" company="James Jackson-South">
// <copyright file="PolaroidProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
/// <summary>
/// Converts the colors of the image recreating an old Polaroid effect.
/// </summary>
public class Polaroid : ColorMatrixFilter
public class PolaroidProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
@ -32,8 +32,8 @@ namespace ImageProcessorCore.Filters
/// <inheritdoc/>
protected override void AfterApply(ImageBase source, ImageBase target, Rectangle targetRectangle, Rectangle sourceRectangle)
{
new Vignette { Color = new Color(102 / 255f, 34 / 255f, 0) }.Apply(target, target, targetRectangle);
new Glow
new VignetteProcessor { Color = new Color(102 / 255f, 34 / 255f, 0) }.Apply(target, target, targetRectangle);
new GlowProcessor
{
Color = new Color(1, 153 / 255f, 102 / 255f, .7f),
RadiusX = target.Width / 4f,

10
src/ImageProcessorCore/Filters/ColorMatrix/Saturation.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/SaturationProcessor.cs

@ -1,9 +1,9 @@
// <copyright file="Saturation.cs" company="James Jackson-South">
// <copyright file="SaturationProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System;
using System.Numerics;
@ -11,7 +11,7 @@ namespace ImageProcessorCore.Filters
/// <summary>
/// An <see cref="IImageProcessor"/> to change the saturation of an <see cref="Image"/>.
/// </summary>
public class Saturation : ColorMatrixFilter
public class SaturationProcessor : ColorMatrixFilter
{
/// <summary>
/// The saturation to be applied to the image.
@ -24,13 +24,13 @@ namespace ImageProcessorCore.Filters
private Matrix4x4 matrix;
/// <summary>
/// Initializes a new instance of the <see cref="Saturation"/> class.
/// Initializes a new instance of the <see cref="SaturationProcessor"/> class.
/// </summary>
/// <param name="saturation">The new saturation of the image. Must be between -100 and 100.</param>
/// <exception cref="ArgumentException">
/// <paramref name="saturation"/> is less than -100 or is greater than 100.
/// </exception>
public Saturation(int saturation)
public SaturationProcessor(int saturation)
{
Guard.MustBeBetweenOrEqualTo(saturation, -100, 100, nameof(saturation));
this.saturation = saturation;

6
src/ImageProcessorCore/Filters/ColorMatrix/Sepia.cs → src/ImageProcessorCore/Filters/Processors/ColorMatrix/SepiaProcessor.cs

@ -1,9 +1,9 @@
// <copyright file="Sepia.cs" company="James Jackson-South">
// <copyright file="SepiaProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Numerics;
@ -11,7 +11,7 @@ namespace ImageProcessorCore.Filters
/// Converts the colors of the image to their sepia equivalent.
/// The formula used matches the svg specification. <see href="http://www.w3.org/TR/filter-effects/#sepiaEquivalent"/>
/// </summary>
public class Sepia : ColorMatrixFilter
public class SepiaProcessor : ColorMatrixFilter
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

70
src/ImageProcessorCore/Filters/Processors/ContrastProcessor.cs

@ -0,0 +1,70 @@
// <copyright file="ContrastProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
{
using System;
using System.Numerics;
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageProcessor"/> to change the contrast of an <see cref="Image"/>.
/// </summary>
public class ContrastProcessor : ParallelImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="ContrastProcessor"/> class.
/// </summary>
/// <param name="contrast">The new contrast of the image. Must be between -100 and 100.</param>
/// <exception cref="ArgumentException">
/// <paramref name="contrast"/> is less than -100 or is greater than 100.
/// </exception>
public ContrastProcessor(int contrast)
{
Guard.MustBeBetweenOrEqualTo(contrast, -100, 100, nameof(contrast));
this.Value = contrast;
}
/// <summary>
/// Gets the contrast value.
/// </summary>
public int Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
float contrast = (100f + this.Value) / 100f;
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Vector4 contrastVector = new Vector4(contrast, contrast, contrast, 1);
Vector4 shiftVector = new Vector4(.5f, .5f, .5f, 1);
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Vector4 color = Color.Expand(sourcePixels[x, y]).ToVector4();
color -= shiftVector;
color *= contrastVector;
color += shiftVector;
targetPixels[x, y] = Color.Compress(new Color(color));
}
this.OnRowProcessed();
}
});
}
}
}
}

10
src/ImageProcessorCore/Filters/Convolution/BoxBlur.cs → src/ImageProcessorCore/Filters/Processors/Convolution/BoxBlurProcessor.cs

@ -1,14 +1,14 @@
// <copyright file="BoxBlur.cs" company="James Jackson-South">
// <copyright file="BoxBlurProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// Applies a Box blur filter to the image.
/// </summary>
public class BoxBlur : Convolution2PassFilter
public class BoxBlurProcessor : Convolution2PassFilter
{
/// <summary>
/// The maximum size of the kernal in either direction.
@ -26,12 +26,12 @@ namespace ImageProcessorCore.Filters
private float[,] kernelX;
/// <summary>
/// Initializes a new instance of the <see cref="GuassianBlur"/> class.
/// Initializes a new instance of the <see cref="GuassianBlurProcessor"/> class.
/// </summary>
/// <param name="radius">
/// The 'radius' value representing the size of the area to sample.
/// </param>
public BoxBlur(int radius = 7)
public BoxBlurProcessor(int radius = 7)
{
this.kernelSize = (radius * 2) + 1;
}

2
src/ImageProcessorCore/Filters/Convolution/Convolution2DFilter.cs → src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2DFilter.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System;
using System.Threading.Tasks;

2
src/ImageProcessorCore/Filters/Convolution/Convolution2PassFilter.cs → src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2PassFilter.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Threading.Tasks;

2
src/ImageProcessorCore/Filters/Convolution/ConvolutionFilter.cs → src/ImageProcessorCore/Filters/Processors/Convolution/ConvolutionFilter.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System.Threading.Tasks;

4
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/EdgeDetector2DFilter.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DFilter.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// Defines a filter that detects edges within an image using two
@ -19,7 +19,7 @@ namespace ImageProcessorCore.Filters
{
if (this.Greyscale)
{
new GreyscaleBt709().Apply(source, source, sourceRectangle);
new GreyscaleBt709Processor().Apply(source, source, sourceRectangle);
}
}
}

4
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/EdgeDetectorFilter.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// Defines a filter that detects edges within an image using a single
@ -19,7 +19,7 @@ namespace ImageProcessorCore.Filters
{
if (this.Greyscale)
{
new GreyscaleBt709().Apply(source, source, sourceRectangle);
new GreyscaleBt709Processor().Apply(source, source, sourceRectangle);
}
}
}

2
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/IEdgeDetectorFilter.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorFilter.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// Provides properties and methods allowing the detection of edges within an image.

6
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/Kayyali.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs

@ -1,15 +1,15 @@
// <copyright file="Kayyali.cs" company="James Jackson-South">
// <copyright file="KayyaliProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// The Kayyali operator filter.
/// <see href="http://edgedetection.webs.com/"/>
/// </summary>
public class Kayyali : EdgeDetector2DFilter
public class KayyaliProcessor : EdgeDetector2DFilter
{
/// <inheritdoc/>
public override float[,] KernelX => new float[,]

6
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/Kirsch.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs

@ -1,15 +1,15 @@
// <copyright file="Kirsch.cs" company="James Jackson-South">
// <copyright file="KirschProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// The Kirsch operator filter.
/// <see href="http://en.wikipedia.org/wiki/Kirsch_operator"/>
/// </summary>
public class Kirsch : EdgeDetector2DFilter
public class KirschProcessor : EdgeDetector2DFilter
{
/// <inheritdoc/>
public override float[,] KernelX => new float[,]

6
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/Laplacian3X3.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs

@ -1,15 +1,15 @@
// <copyright file="Laplacian3X3.cs" company="James Jackson-South">
// <copyright file="Laplacian3X3Processor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// The Laplacian 3 x 3 operator filter.
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
/// </summary>
public class Laplacian3X3 : EdgeDetectorFilter
public class Laplacian3X3Processor : EdgeDetectorFilter
{
/// <inheritdoc/>
public override float[,] KernelXY => new float[,]

6
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/Laplacian5X5.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs

@ -1,15 +1,15 @@
// <copyright file="Laplacian5X5.cs" company="James Jackson-South">
// <copyright file="Laplacian5X5Processor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// The Laplacian 5 x 5 operator filter.
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
/// </summary>
public class Laplacian5X5 : EdgeDetectorFilter
public class Laplacian5X5Processor : EdgeDetectorFilter
{
/// <inheritdoc/>
public override float[,] KernelXY => new float[,]

6
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/LaplacianOfGaussian.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs

@ -1,15 +1,15 @@
// <copyright file="LaplacianOfGaussian.cs" company="James Jackson-South">
// <copyright file="LaplacianOfGaussianProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// The Laplacian of Gaussian operator filter.
/// <see href="http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html"/>
/// </summary>
public class LaplacianOfGaussian : EdgeDetectorFilter
public class LaplacianOfGaussianProcessor : EdgeDetectorFilter
{
/// <inheritdoc/>
public override float[,] KernelXY => new float[,]

6
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/Prewitt.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs

@ -1,15 +1,15 @@
// <copyright file="Prewitt.cs" company="James Jackson-South">
// <copyright file="PrewittProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// The Prewitt operator filter.
/// <see href="http://en.wikipedia.org/wiki/Prewitt_operator"/>
/// </summary>
public class Prewitt : EdgeDetector2DFilter
public class PrewittProcessor : EdgeDetector2DFilter
{
/// <inheritdoc/>
public override float[,] KernelX => new float[,]

6
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/RobertsCross.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs

@ -1,15 +1,15 @@
// <copyright file="RobertsCross.cs" company="James Jackson-South">
// <copyright file="RobertsCrossProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// The Roberts Cross operator filter.
/// <see href="http://en.wikipedia.org/wiki/Roberts_cross"/>
/// </summary>
public class RobertsCross : EdgeDetector2DFilter
public class RobertsCrossProcessor : EdgeDetector2DFilter
{
/// <inheritdoc/>
public override float[,] KernelX => new float[,]

6
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/Scharr.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs

@ -1,15 +1,15 @@
// <copyright file="Scharr.cs" company="James Jackson-South">
// <copyright file="ScharrProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// The Scharr operator filter.
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator#Alternative_operators"/>
/// </summary>
public class Scharr : EdgeDetector2DFilter
public class ScharrProcessor : EdgeDetector2DFilter
{
/// <inheritdoc/>
public override float[,] KernelX => new float[,]

6
src/ImageProcessorCore/Filters/Convolution/EdgeDetection/Sobel.cs → src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs

@ -1,15 +1,15 @@
// <copyright file="Sobel.cs" company="James Jackson-South">
// <copyright file="SobelProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
/// <summary>
/// The Sobel operator filter.
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator"/>
/// </summary>
public class Sobel : EdgeDetector2DFilter
public class SobelProcessor : EdgeDetector2DFilter
{
/// <inheritdoc/>
public override float[,] KernelX => new float[,]

18
src/ImageProcessorCore/Filters/Convolution/GuassianBlur.cs → src/ImageProcessorCore/Filters/Processors/Convolution/GuassianBlurProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="GuassianBlur.cs" company="James Jackson-South">
// <copyright file="GuassianBlurProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System;
/// <summary>
/// Applies a Gaussian blur filter to the image.
/// </summary>
public class GuassianBlur : Convolution2PassFilter
public class GuassianBlurProcessor : Convolution2PassFilter
{
/// <summary>
/// The maximum size of the kernal in either direction.
@ -33,29 +33,29 @@ namespace ImageProcessorCore.Filters
private float[,] kernelX;
/// <summary>
/// Initializes a new instance of the <see cref="GuassianBlur"/> class.
/// Initializes a new instance of the <see cref="GuassianBlurProcessor"/> class.
/// </summary>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
public GuassianBlur(float sigma = 3f)
public GuassianBlurProcessor(float sigma = 3f)
{
this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1;
this.sigma = sigma;
}
/// <summary>
/// Initializes a new instance of the <see cref="GuassianBlur"/> class.
/// Initializes a new instance of the <see cref="GuassianBlurProcessor"/> class.
/// </summary>
/// <param name="radius">
/// The 'radius' value representing the size of the area to sample.
/// </param>
public GuassianBlur(int radius)
public GuassianBlurProcessor(int radius)
{
this.kernelSize = (radius * 2) + 1;
this.sigma = radius;
}
/// <summary>
/// Initializes a new instance of the <see cref="GuassianBlur"/> class.
/// Initializes a new instance of the <see cref="GuassianBlurProcessor"/> class.
/// </summary>
/// <param name="sigma">
/// The 'sigma' value representing the weight of the blur.
@ -64,7 +64,7 @@ namespace ImageProcessorCore.Filters
/// The 'radius' value representing the size of the area to sample.
/// This should be at least twice the sigma value.
/// </param>
public GuassianBlur(float sigma, int radius)
public GuassianBlurProcessor(float sigma, int radius)
{
this.kernelSize = (radius * 2) + 1;
this.sigma = sigma;

18
src/ImageProcessorCore/Filters/Convolution/GuassianSharpen.cs → src/ImageProcessorCore/Filters/Processors/Convolution/GuassianSharpenProcessor.cs

@ -1,16 +1,16 @@
// <copyright file="GuassianSharpen.cs" company="James Jackson-South">
// <copyright file="GuassianSharpenProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System;
/// <summary>
/// Applies a Gaussian sharpening filter to the image.
/// </summary>
public class GuassianSharpen : Convolution2PassFilter
public class GuassianSharpenProcessor : Convolution2PassFilter
{
/// <summary>
/// The maximum size of the kernal in either direction.
@ -33,31 +33,31 @@ namespace ImageProcessorCore.Filters
private float[,] kernelX;
/// <summary>
/// Initializes a new instance of the <see cref="GuassianSharpen"/> class.
/// Initializes a new instance of the <see cref="GuassianSharpenProcessor"/> class.
/// </summary>
/// <param name="sigma">
/// The 'sigma' value representing the weight of the sharpening.
/// </param>
public GuassianSharpen(float sigma = 3f)
public GuassianSharpenProcessor(float sigma = 3f)
{
this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1;
this.sigma = sigma;
}
/// <summary>
/// Initializes a new instance of the <see cref="GuassianSharpen"/> class.
/// Initializes a new instance of the <see cref="GuassianSharpenProcessor"/> class.
/// </summary>
/// <param name="radius">
/// The 'radius' value representing the size of the area to sample.
/// </param>
public GuassianSharpen(int radius)
public GuassianSharpenProcessor(int radius)
{
this.kernelSize = (radius * 2) + 1;
this.sigma = radius;
}
/// <summary>
/// Initializes a new instance of the <see cref="GuassianSharpen"/> class.
/// Initializes a new instance of the <see cref="GuassianSharpenProcessor"/> class.
/// </summary>
/// <param name="sigma">
/// The 'sigma' value representing the weight of the sharpen.
@ -66,7 +66,7 @@ namespace ImageProcessorCore.Filters
/// The 'radius' value representing the size of the area to sample.
/// This should be at least twice the sigma value.
/// </param>
public GuassianSharpen(float sigma, int radius)
public GuassianSharpenProcessor(float sigma, int radius)
{
this.kernelSize = (radius * 2) + 1;
this.sigma = sigma;

6
src/ImageProcessorCore/Filters/Glow.cs → src/ImageProcessorCore/Filters/Processors/GlowProcessor.cs

@ -1,9 +1,9 @@
// <copyright file="Glow.cs" company="James Jackson-South">
// <copyright file="GlowProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System;
using System.Numerics;
@ -12,7 +12,7 @@ namespace ImageProcessorCore.Filters
/// <summary>
/// Creates a glow effect on the image
/// </summary>
public class Glow : ParallelImageProcessor
public class GlowProcessor : ParallelImageProcessor
{
/// <summary>
/// Gets or sets the glow color to apply.

48
src/ImageProcessorCore/Filters/Processors/InvertProcessor.cs

@ -0,0 +1,48 @@
// <copyright file="InvertProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
{
using System.Numerics;
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageProcessor"/> to invert the colors of an <see cref="Image"/>.
/// </summary>
public class InvertProcessor : ParallelImageProcessor
{
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Vector3 inverseVector = Vector3.One;
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
{
Parallel.For(
startY,
endY,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
Color color = sourcePixels[x, y];
Vector3 vector = inverseVector - color.ToVector3();
targetPixels[x, y] = new Color(vector, color.A);
}
this.OnRowProcessed();
}
});
}
}
}
}

97
src/ImageProcessorCore/Filters/Processors/PixelateProcessor.cs

@ -0,0 +1,97 @@
// <copyright file="PixelateProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageProcessor"/> to invert the colors of an <see cref="Image"/>.
/// </summary>
public class PixelateProcessor : ParallelImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="PixelateProcessor"/> class.
/// </summary>
/// <param name="size">The size of the pixels. Must be greater than 0.</param>
/// <exception cref="ArgumentException">
/// <paramref name="size"/> is less than 0 or equal to 0.
/// </exception>
public PixelateProcessor(int size)
{
Guard.MustBeGreaterThan(size, 0, nameof(size));
this.Value = size;
}
/// <inheritdoc/>
public override int Parallelism { get; set; } = 1;
/// <summary>
/// Gets or the pixel size.
/// </summary>
public int Value { get; }
/// <inheritdoc/>
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
int size = this.Value;
int offset = this.Value / 2;
// Get the range on the y-plane to choose from.
IEnumerable<int> range = EnumerableExtensions.SteppedRange(startY, i => i < endY, size);
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor targetPixels = target.Lock())
{
Parallel.ForEach(
range,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x += size)
{
int offsetX = offset;
int offsetY = offset;
// Make sure that the offset is within the boundary of the
// image.
while (y + offsetY >= sourceBottom)
{
offsetY--;
}
while (x + offsetX >= endX)
{
offsetX--;
}
// Get the pixel color in the centre of the soon to be pixelated area.
// ReSharper disable AccessToDisposedClosure
Color pixel = sourcePixels[x + offsetX, y + offsetY];
// For each pixel in the pixelate size, set it to the centre color.
for (int l = y; l < y + size && l < sourceBottom; l++)
{
for (int k = x; k < x + size && k < endX; k++)
{
targetPixels[k, l] = pixel;
}
}
}
this.OnRowProcessed();
}
});
}
}
}
}

6
src/ImageProcessorCore/Filters/Vignette.cs → src/ImageProcessorCore/Filters/Processors/VignetteProcessor.cs

@ -1,9 +1,9 @@
// <copyright file="Vignette.cs" company="James Jackson-South">
// <copyright file="VignetteProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Filters
namespace ImageProcessorCore.Processors
{
using System;
using System.Numerics;
@ -12,7 +12,7 @@ namespace ImageProcessorCore.Filters
/// <summary>
/// Creates a vignette effect on the image
/// </summary>
public class Vignette : ParallelImageProcessor
public class VignetteProcessor : ParallelImageProcessor
{
/// <summary>
/// Gets or sets the vignette color to apply.

52
src/ImageProcessorCore/Filters/Saturation.cs

@ -0,0 +1,52 @@
// <copyright file="Saturation.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Alters the saturation component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Saturation(this Image source, int amount, ProgressEventHandler progressHandler = null)
{
return Saturation(source, amount, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the saturation component of the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Saturation(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
SaturationProcessor processor = new SaturationProcessor(amount);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

50
src/ImageProcessorCore/Filters/Sepia.cs

@ -0,0 +1,50 @@
// <copyright file="Sepia.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>-------------------------------------------------------------------------------------------------------------------
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies sepia toning to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Sepia(this Image source, ProgressEventHandler progressHandler = null)
{
return Sepia(source, source.Bounds, progressHandler);
}
/// <summary>
/// Applies sepia toning to the image.
/// </summary>
/// <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="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Sepia(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
{
SepiaProcessor processor = new SepiaProcessor();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

4
src/ImageProcessorCore/IImageProcessor.cs

@ -1,9 +1,9 @@
// <copyright file="IImageProcessorCore.cs" company="James Jackson-South">
// <copyright file="IImageProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
namespace ImageProcessorCore.Processors
{
/// <summary>
/// A delegate which is called as progress is made processing an image.

1
src/ImageProcessorCore/ImageExtensions.cs

@ -9,6 +9,7 @@ namespace ImageProcessorCore
using System.IO;
using Formats;
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.

2
src/ImageProcessorCore/ParallelImageProcessor.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
namespace ImageProcessorCore.Processors
{
using System;
using System.Threading;

2
src/ImageProcessorCore/PixelAccessor.cs

@ -53,7 +53,7 @@ namespace ImageProcessorCore
this.Height = image.Height;
// Assign the pointer.
// If buffer is allocated on Large Object Heap, then we are going to pin it instead of making a copy.
// If buffer is allocated on Large Object Heap i.e > 85Kb, then we are going to pin it instead of making a copy.
if (size > (85 * 1024))
{
this.pixelsHandle = GCHandle.Alloc(image.Pixels, GCHandleType.Pinned);

2
src/ImageProcessorCore/Samplers/Crop.cs

@ -5,6 +5,8 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>

2
src/ImageProcessorCore/Samplers/EntropyCrop.cs

@ -5,6 +5,8 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>

2
src/ImageProcessorCore/Samplers/Pad.cs

@ -5,6 +5,8 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>

2
src/ImageProcessorCore/Samplers/Processors/CropProcessor.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
namespace ImageProcessorCore.Processors
{
using System.Threading.Tasks;

8
src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs

@ -3,13 +3,11 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
namespace ImageProcessorCore.Processors
{
using System;
using System.Threading.Tasks;
using Filters;
/// <summary>
/// Provides methods to allow the cropping of an image to preserve areas of highest
/// entropy.
@ -45,10 +43,10 @@ namespace ImageProcessorCore
ImageBase temp = new Image(source.Width, source.Height);
// Detect the edges.
new Sobel().Apply(temp, source, sourceRectangle);
new SobelProcessor().Apply(temp, source, sourceRectangle);
// Apply threshold binarization filter.
new Threshold(.5f).Apply(temp, temp, sourceRectangle);
new ThresholdProcessor(.5f).Apply(temp, temp, sourceRectangle);
// Search for the first white pixels
Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0);

2
src/ImageProcessorCore/Samplers/Processors/IImageSampler.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
namespace ImageProcessorCore.Processors
{
/// <summary>
/// Acts as a marker for generic parameters that require an image sampler.

2
src/ImageProcessorCore/Samplers/Processors/ImageSampler.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
namespace ImageProcessorCore.Processors
{
/// <summary>
/// Applies sampling methods to an image.

2
src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
namespace ImageProcessorCore.Processors
{
using System;
using System.Threading.Tasks;

3
src/ImageProcessorCore/Samplers/Processors/RotateFlip.cs → src/ImageProcessorCore/Samplers/Processors/RotateFlipProcessor.cs

@ -2,7 +2,8 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
namespace ImageProcessorCore.Processors
{
using System;
using System.Threading.Tasks;

2
src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
namespace ImageProcessorCore.Processors
{
using System.Numerics;
using System.Threading.Tasks;

2
src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
namespace ImageProcessorCore.Processors
{
using System.Numerics;
using System.Threading.Tasks;

2
src/ImageProcessorCore/Samplers/Resize.cs

@ -5,6 +5,8 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>

2
src/ImageProcessorCore/Samplers/Rotate.cs

@ -5,6 +5,8 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>

2
src/ImageProcessorCore/Samplers/RotateFlip.cs

@ -5,6 +5,8 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>

2
src/ImageProcessorCore/Samplers/Skew.cs

@ -5,6 +5,8 @@
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>

84
tests/ImageProcessorCore.Tests/Processors/Filters/FilterTests.cs

@ -4,7 +4,7 @@ namespace ImageProcessorCore.Tests
using System.Diagnostics;
using System.IO;
using ImageProcessorCore.Filters;
using Processors;
using Xunit;
@ -12,47 +12,47 @@ namespace ImageProcessorCore.Tests
{
public static readonly TheoryData<string, IImageProcessor> Filters = new TheoryData<string, IImageProcessor>
{
{ "Brightness-50", new Brightness(50) },
{ "Brightness--50", new Brightness(-50) },
{ "Contrast-50", new Contrast(50) },
{ "Contrast--50", new Contrast(-50) },
{ "BackgroundColor", new BackgroundColor(new Color(243 / 255f, 87 / 255f, 161 / 255f,.5f))},
{ "Blend", new Blend(new Image(File.OpenRead("TestImages/Formats/Bmp/Car.bmp")),50)},
{ "Saturation-50", new Saturation(50) },
{ "Saturation--50", new Saturation(-50) },
{ "Alpha--50", new Alpha(50) },
{ "Invert", new Invert() },
{ "Sepia", new Sepia() },
{ "BlackWhite", new BlackWhite() },
{ "Lomograph", new Lomograph() },
{ "Polaroid", new Polaroid() },
{ "Kodachrome", new Kodachrome() },
{ "GreyscaleBt709", new GreyscaleBt709() },
{ "GreyscaleBt601", new GreyscaleBt601() },
{ "Kayyali", new Kayyali() },
{ "Kirsch", new Kirsch() },
{ "Laplacian3X3", new Laplacian3X3() },
{ "Laplacian5X5", new Laplacian5X5() },
{ "LaplacianOfGaussian", new LaplacianOfGaussian() },
{ "Prewitt", new Prewitt() },
{ "RobertsCross", new RobertsCross() },
{ "Scharr", new Scharr() },
{ "Sobel", new Sobel {Greyscale = true} },
{ "Pixelate", new Pixelate(8) },
{ "GuassianBlur", new GuassianBlur(10) },
{ "GuassianSharpen", new GuassianSharpen(10) },
{ "Hue-180", new Hue(180) },
{ "Hue--180", new Hue(-180) },
{ "BoxBlur", new BoxBlur(10) },
{ "Vignette", new Vignette() },
{ "Protanopia", new Protanopia() },
{ "Protanomaly", new Protanomaly() },
{ "Deuteranopia", new Deuteranopia() },
{ "Deuteranomaly", new Deuteranomaly() },
{ "Tritanopia", new Tritanopia() },
{ "Tritanomaly", new Tritanomaly() },
{ "Achromatopsia", new Achromatopsia() },
{ "Achromatomaly", new Achromatomaly() }
{ "Brightness-50", new BrightnessProcessor(50) },
{ "Brightness--50", new BrightnessProcessor(-50) },
{ "Contrast-50", new ContrastProcessor(50) },
{ "Contrast--50", new ContrastProcessor(-50) },
{ "BackgroundColor", new BackgroundColorProcessor(new Color(243 / 255f, 87 / 255f, 161 / 255f,.5f))},
{ "Blend", new BlendProcessor(new Image(File.OpenRead("TestImages/Formats/Bmp/Car.bmp")),50)},
{ "Saturation-50", new SaturationProcessor(50) },
{ "Saturation--50", new SaturationProcessor(-50) },
{ "Alpha--50", new AlphaProcessor(50) },
{ "Invert", new InvertProcessor() },
{ "Sepia", new SepiaProcessor() },
{ "BlackWhite", new BlackWhiteProcessor() },
{ "Lomograph", new LomographProcessor() },
{ "Polaroid", new PolaroidProcessor() },
{ "Kodachrome", new KodachromeProcessor() },
{ "GreyscaleBt709", new GreyscaleBt709Processor() },
{ "GreyscaleBt601", new GreyscaleBt601Processor() },
{ "Kayyali", new KayyaliProcessor() },
{ "Kirsch", new KirschProcessor() },
{ "Laplacian3X3", new Laplacian3X3Processor() },
{ "Laplacian5X5", new Laplacian5X5Processor() },
{ "LaplacianOfGaussian", new LaplacianOfGaussianProcessor() },
{ "Prewitt", new PrewittProcessor() },
{ "RobertsCross", new RobertsCrossProcessor() },
{ "Scharr", new ScharrProcessor() },
{ "Sobel", new SobelProcessor {Greyscale = true} },
{ "Pixelate", new PixelateProcessor(8) },
{ "GuassianBlur", new GuassianBlurProcessor(10) },
{ "GuassianSharpen", new GuassianSharpenProcessor(10) },
{ "Hue-180", new HueProcessor(180) },
{ "Hue--180", new HueProcessor(-180) },
{ "BoxBlur", new BoxBlurProcessor(10) },
{ "Vignette", new VignetteProcessor() },
{ "Protanopia", new ProtanopiaProcessor() },
{ "Protanomaly", new ProtanomalyProcessor() },
{ "Deuteranopia", new DeuteranopiaProcessor() },
{ "Deuteranomaly", new DeuteranomalyProcessor() },
{ "Tritanopia", new TritanopiaProcessor() },
{ "Tritanomaly", new TritanomalyProcessor() },
{ "Achromatopsia", new AchromatopsiaProcessor() },
{ "Achromatomaly", new AchromatomalyProcessor() }
};

3
tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs

@ -3,10 +3,9 @@
using System.Diagnostics;
using System.IO;
using ImageProcessorCore.Processors;
using Processors;
using Xunit;
using Filters;
public class SamplerTests : FileTestBase
{

Loading…
Cancel
Save