Browse Source

refactor the rest of the FilterProcessor code

af/merge-core
Anton Firszov 7 years ago
parent
commit
86cc38ad94
  1. 12
      src/ImageSharp/Processing/BrightnessExtensions.cs
  2. 31
      src/ImageSharp/Processing/ColorBlindnessExtensions.cs
  3. 14
      src/ImageSharp/Processing/ContrastExtensions.cs
  4. 62
      src/ImageSharp/Processing/GrayscaleExtensions.cs
  5. 14
      src/ImageSharp/Processing/HueExtensions.cs
  6. 14
      src/ImageSharp/Processing/InvertExtensions.cs
  7. 14
      src/ImageSharp/Processing/KodachromeExtensions.cs
  8. 14
      src/ImageSharp/Processing/LomographExtensions.cs
  9. 13
      src/ImageSharp/Processing/PolaroidExtensions.cs
  10. 2
      src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor.cs
  11. 2
      src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor.cs
  12. 2
      src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor.cs
  13. 6
      src/ImageSharp/Processing/Processors/Filters/AchromatomalyProcessor.cs
  14. 6
      src/ImageSharp/Processing/Processors/Filters/AchromatopsiaProcessor.cs
  15. 6
      src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs
  16. 6
      src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs
  17. 6
      src/ImageSharp/Processing/Processors/Filters/DeuteranomalyProcessor.cs
  18. 6
      src/ImageSharp/Processing/Processors/Filters/DeuteranopiaProcessor.cs
  19. 2
      src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs
  20. 8
      src/ImageSharp/Processing/Processors/Filters/FilterProcessorImplementation.cs
  21. 6
      src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs
  22. 17
      src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs
  23. 5
      src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs
  24. 6
      src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs
  25. 6
      src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs
  26. 19
      src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs
  27. 26
      src/ImageSharp/Processing/Processors/Filters/LomographProcessorImplementation.cs
  28. 22
      src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs
  29. 6
      src/ImageSharp/Processing/Processors/Filters/ProtanomalyProcessor.cs
  30. 5
      src/ImageSharp/Processing/Processors/Filters/ProtanopiaProcessor.cs
  31. 6
      src/ImageSharp/Processing/Processors/Filters/SaturateProcessor.cs
  32. 6
      src/ImageSharp/Processing/Processors/Filters/SepiaProcessor.cs
  33. 6
      src/ImageSharp/Processing/Processors/Filters/TritanomalyProcessor.cs
  34. 6
      src/ImageSharp/Processing/Processors/Filters/TritanopiaProcessor.cs
  35. 31
      src/ImageSharp/Processing/Processors/IImageProcessor.cs
  36. 14
      src/ImageSharp/Processing/SaturateExtensions.cs
  37. 22
      src/ImageSharp/Processing/SepiaExtensions.cs

12
src/ImageSharp/Processing/BrightnessExtensions.cs

@ -19,13 +19,11 @@ namespace SixLabors.ImageSharp.Processing
/// A value of 0 will create an image that is completely black. A value of 1 leaves the input unchanged.
/// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing brighter results.
/// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Brightness<TPixel>(this IImageProcessingContext<TPixel> source, float amount)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new BrightnessProcessor<TPixel>(amount));
public static IImageProcessingContext Brightness(this IImageProcessingContext source, float amount)
=> source.ApplyProcessor(new BrightnessProcessor(amount));
/// <summary>
/// Alters the brightness component of the image.
@ -34,15 +32,13 @@ namespace SixLabors.ImageSharp.Processing
/// A value of 0 will create an image that is completely black. A value of 1 leaves the input unchanged.
/// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing brighter results.
/// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Brightness<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new BrightnessProcessor<TPixel>(amount), rectangle);
public static IImageProcessingContext Brightness(this IImageProcessingContext source, float amount, Rectangle rectangle)
=> source.ApplyProcessor(new BrightnessProcessor(amount), rectangle);
}
}

31
src/ImageSharp/Processing/ColorBlindnessExtensions.cs

@ -16,49 +16,44 @@ namespace SixLabors.ImageSharp.Processing
/// <summary>
/// Applies the given colorblindness simulator to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> ColorBlindness<TPixel>(this IImageProcessingContext<TPixel> source, ColorBlindnessMode colorBlindness)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(GetProcessor<TPixel>(colorBlindness));
public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindnessMode colorBlindness)
=> source.ApplyProcessor(GetProcessor(colorBlindness));
/// <summary>
/// Applies the given colorblindness simulator to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="colorBlindnessMode">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>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> ColorBlindness<TPixel>(this IImageProcessingContext<TPixel> source, ColorBlindnessMode colorBlindnessMode, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(GetProcessor<TPixel>(colorBlindnessMode), rectangle);
public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindnessMode colorBlindnessMode, Rectangle rectangle)
=> source.ApplyProcessor(GetProcessor(colorBlindnessMode), rectangle);
private static IImageProcessor<TPixel> GetProcessor<TPixel>(ColorBlindnessMode colorBlindness)
where TPixel : struct, IPixel<TPixel>
private static IImageProcessor GetProcessor(ColorBlindnessMode colorBlindness)
{
switch (colorBlindness)
{
case ColorBlindnessMode.Achromatomaly:
return new AchromatomalyProcessor<TPixel>();
return new AchromatomalyProcessor();
case ColorBlindnessMode.Achromatopsia:
return new AchromatopsiaProcessor<TPixel>();
return new AchromatopsiaProcessor();
case ColorBlindnessMode.Deuteranomaly:
return new DeuteranomalyProcessor<TPixel>();
return new DeuteranomalyProcessor();
case ColorBlindnessMode.Deuteranopia:
return new DeuteranopiaProcessor<TPixel>();
return new DeuteranopiaProcessor();
case ColorBlindnessMode.Protanomaly:
return new ProtanomalyProcessor<TPixel>();
return new ProtanomalyProcessor();
case ColorBlindnessMode.Protanopia:
return new ProtanopiaProcessor<TPixel>();
return new ProtanopiaProcessor();
case ColorBlindnessMode.Tritanomaly:
return new TritanomalyProcessor<TPixel>();
return new TritanomalyProcessor();
default:
return new TritanopiaProcessor<TPixel>();
return new TritanopiaProcessor();
}
}
}

14
src/ImageSharp/Processing/ContrastExtensions.cs

@ -8,7 +8,7 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Adds extensions that allow the alteration of the contrast component to the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the alteration of the contrast component to the <see cref="Image"/> type.
/// </summary>
public static class ContrastExtensions
{
@ -19,13 +19,11 @@ namespace SixLabors.ImageSharp.Processing
/// A value of 0 will create an image that is completely gray. A value of 1 leaves the input unchanged.
/// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing results with more contrast.
/// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Contrast<TPixel>(this IImageProcessingContext<TPixel> source, float amount)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new ContrastProcessor<TPixel>(amount));
public static IImageProcessingContext Contrast(this IImageProcessingContext source, float amount)
=> source.ApplyProcessor(new ContrastProcessor(amount));
/// <summary>
/// Alters the contrast component of the image.
@ -34,15 +32,13 @@ namespace SixLabors.ImageSharp.Processing
/// A value of 0 will create an image that is completely gray. A value of 1 leaves the input unchanged.
/// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing results with more contrast.
/// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Contrast<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new ContrastProcessor<TPixel>(amount), rectangle);
public static IImageProcessingContext Contrast(this IImageProcessingContext source, float amount, Rectangle rectangle)
=> source.ApplyProcessor(new ContrastProcessor(amount), rectangle);
}
}

62
src/ImageSharp/Processing/GrayscaleExtensions.cs

@ -9,56 +9,48 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Adds extensions that allow the application of grayscale toning to the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the application of grayscale toning to the <see cref="Image"/> type.
/// </summary>
public static class GrayscaleExtensions
{
/// <summary>
/// Applies <see cref="GrayscaleMode.Bt709"/> grayscale toning to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext Grayscale(this IImageProcessingContext source)
=> Grayscale(source, GrayscaleMode.Bt709);
/// <summary>
/// Applies <see cref="GrayscaleMode.Bt709"/> grayscale toning to the image using the given amount.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, float amount)
where TPixel : struct, IPixel<TPixel>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext Grayscale(this IImageProcessingContext source, float amount)
=> Grayscale(source, GrayscaleMode.Bt709, amount);
/// <summary>
/// Applies grayscale toning to the image with the given <see cref="GrayscaleMode"/>.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, GrayscaleMode mode)
where TPixel : struct, IPixel<TPixel>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode)
=> Grayscale(source, mode, 1F);
/// <summary>
/// Applies grayscale toning to the image with the given <see cref="GrayscaleMode"/> using the given amount.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</param>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, GrayscaleMode mode, float amount)
where TPixel : struct, IPixel<TPixel>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode, float amount)
{
IImageProcessor<TPixel> processor = mode == GrayscaleMode.Bt709
? (IImageProcessor<TPixel>)new GrayscaleBt709Processor<TPixel>(amount)
: new GrayscaleBt601Processor<TPixel>(1F);
IImageProcessor processor = mode == GrayscaleMode.Bt709
? (IImageProcessor)new GrayscaleBt709Processor(amount)
: new GrayscaleBt601Processor(1F);
source.ApplyProcessor(processor);
return source;
@ -67,61 +59,53 @@ namespace SixLabors.ImageSharp.Processing
/// <summary>
/// Applies <see cref="GrayscaleMode.Bt709"/> grayscale toning to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext Grayscale(this IImageProcessingContext source, Rectangle rectangle)
=> Grayscale(source, 1F, rectangle);
/// <summary>
/// Applies <see cref="GrayscaleMode.Bt709"/> grayscale toning to the image using the given amount.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext Grayscale(this IImageProcessingContext source, float amount, Rectangle rectangle)
=> Grayscale(source, GrayscaleMode.Bt709, amount, rectangle);
/// <summary>
/// Applies grayscale toning to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, GrayscaleMode mode, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode, Rectangle rectangle)
=> Grayscale(source, mode, 1F, rectangle);
/// <summary>
/// Applies grayscale toning to the image using the given amount.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</param>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Grayscale<TPixel>(this IImageProcessingContext<TPixel> source, GrayscaleMode mode, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode, float amount, Rectangle rectangle)
{
IImageProcessor<TPixel> processor = mode == GrayscaleMode.Bt709
? (IImageProcessor<TPixel>)new GrayscaleBt709Processor<TPixel>(amount)
: new GrayscaleBt601Processor<TPixel>(amount);
IImageProcessor processor = mode == GrayscaleMode.Bt709
? (IImageProcessor)new GrayscaleBt709Processor(amount)
: new GrayscaleBt601Processor(amount);
source.ApplyProcessor(processor, rectangle);
return source;

14
src/ImageSharp/Processing/HueExtensions.cs

@ -8,33 +8,29 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Adds extensions that allow the alteration of the hue component to the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the alteration of the hue component to the <see cref="Image"/> type.
/// </summary>
public static class HueExtensions
{
/// <summary>
/// Alters the hue component of the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="degrees">The rotation angle in degrees to adjust the hue.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Hue<TPixel>(this IImageProcessingContext<TPixel> source, float degrees)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new HueProcessor<TPixel>(degrees));
public static IImageProcessingContext Hue(this IImageProcessingContext source, float degrees)
=> source.ApplyProcessor(new HueProcessor(degrees));
/// <summary>
/// Alters the hue component of the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="degrees">The rotation angle in degrees to adjust the hue.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Hue<TPixel>(this IImageProcessingContext<TPixel> source, float degrees, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new HueProcessor<TPixel>(degrees), rectangle);
public static IImageProcessingContext Hue(this IImageProcessingContext source, float degrees, Rectangle rectangle)
=> source.ApplyProcessor(new HueProcessor(degrees), rectangle);
}
}

14
src/ImageSharp/Processing/InvertExtensions.cs

@ -8,31 +8,27 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Adds extensions that allow the inversion of colors to the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the inversion of colors to the <see cref="Image"/> type.
/// </summary>
public static class InvertExtensions
{
/// <summary>
/// Inverts the colors of the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Invert<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new InvertProcessor<TPixel>(1F));
public static IImageProcessingContext Invert(this IImageProcessingContext source)
=> source.ApplyProcessor(new InvertProcessor(1F));
/// <summary>
/// Inverts the colors of the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Invert<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new InvertProcessor<TPixel>(1F), rectangle);
public static IImageProcessingContext Invert(this IImageProcessingContext source, Rectangle rectangle)
=> source.ApplyProcessor(new InvertProcessor(1F), rectangle);
}
}

14
src/ImageSharp/Processing/KodachromeExtensions.cs

@ -8,31 +8,27 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Adds extensions that allow the recreation of an old Kodachrome camera effect to the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the recreation of an old Kodachrome camera effect to the <see cref="Image"/> type.
/// </summary>
public static class KodachromeExtensions
{
/// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Kodachrome<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new KodachromeProcessor<TPixel>());
public static IImageProcessingContext Kodachrome(this IImageProcessingContext source)
=> source.ApplyProcessor(new KodachromeProcessor());
/// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Kodachrome<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new KodachromeProcessor<TPixel>(), rectangle);
public static IImageProcessingContext Kodachrome(this IImageProcessingContext source, Rectangle rectangle)
=> source.ApplyProcessor(new KodachromeProcessor(), rectangle);
}
}

14
src/ImageSharp/Processing/LomographExtensions.cs

@ -8,31 +8,27 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Adds extensions that allow the recreation of an old Lomograph camera effect to the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the recreation of an old Lomograph camera effect to the <see cref="Image"/> type.
/// </summary>
public static class LomographExtensions
{
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new LomographProcessor<TPixel>());
public static IImageProcessingContext Lomograph(this IImageProcessingContext source)
=> source.ApplyProcessor(new LomographProcessor());
/// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new LomographProcessor<TPixel>(), rectangle);
public static IImageProcessingContext Lomograph(this IImageProcessingContext source, Rectangle rectangle)
=> source.ApplyProcessor(new LomographProcessor(), rectangle);
}
}

13
src/ImageSharp/Processing/PolaroidExtensions.cs

@ -8,19 +8,17 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Adds extensions that allow the recreation of an old Polaroid camera effect to the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the recreation of an old Polaroid camera effect to the <see cref="Image"/> type.
/// </summary>
public static class PolaroidExtensions
{
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new PolaroidProcessor<TPixel>());
public static IImageProcessingContext Polaroid(this IImageProcessingContext source)
=> source.ApplyProcessor(new PolaroidProcessor());
/// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect.
@ -31,8 +29,7 @@ namespace SixLabors.ImageSharp.Processing
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new PolaroidProcessor<TPixel>(), rectangle);
public static IImageProcessingContext Polaroid(this IImageProcessingContext source, Rectangle rectangle)
=> source.ApplyProcessor(new PolaroidProcessor(), rectangle);
}
}

2
src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor.cs

@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
if (this.Grayscale)
{
new GrayscaleBt709Processor<TPixel>(1F).Apply(source, sourceRectangle, configuration);
new GrayscaleBt709Processor(1F).ApplyToFrame(source, sourceRectangle, configuration);
}
}
}

2
src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor.cs

@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
if (this.Grayscale)
{
new GrayscaleBt709Processor<TPixel>(1F).Apply(source, sourceRectangle, configuration);
new GrayscaleBt709Processor(1F).ApplyToFrame(source, sourceRectangle, configuration);
}
}

2
src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor.cs

@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{
if (this.Grayscale)
{
new GrayscaleBt709Processor<TPixel>(1F).Apply(source, sourceRectangle, configuration);
new GrayscaleBt709Processor(1F).ApplyToFrame(source, sourceRectangle, configuration);
}
}

6
src/ImageSharp/Processing/Processors/Filters/AchromatomalyProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class AchromatomalyProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class AchromatomalyProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="AchromatomalyProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="AchromatomalyProcessor"/> class.
/// </summary>
public AchromatomalyProcessor()
: base(KnownFilterMatrices.AchromatomalyFilter)

6
src/ImageSharp/Processing/Processors/Filters/AchromatopsiaProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class AchromatopsiaProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class AchromatopsiaProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="AchromatopsiaProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="AchromatopsiaProcessor"/> class.
/// </summary>
public AchromatopsiaProcessor()
: base(KnownFilterMatrices.AchromatopsiaFilter)

6
src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Applies a brightness filter matrix using the given amount.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class BrightnessProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class BrightnessProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="BrightnessProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="BrightnessProcessor"/> class.
/// </summary>
/// <remarks>
/// A value of <value>0</value> will create an image that is completely black. A value of <value>1</value> leaves the input unchanged.

6
src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Applies a contrast filter matrix using the given amount.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class ContrastProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class ContrastProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="ContrastProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="ContrastProcessor"/> class.
/// </summary>
/// <remarks>
/// A value of <value>0</value> will create an image that is completely gray. A value of <value>1</value> leaves the input unchanged.

6
src/ImageSharp/Processing/Processors/Filters/DeuteranomalyProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class DeuteranomalyProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class DeuteranomalyProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="DeuteranomalyProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="DeuteranomalyProcessor"/> class.
/// </summary>
public DeuteranomalyProcessor()
: base(KnownFilterMatrices.DeuteranomalyFilter)

6
src/ImageSharp/Processing/Processors/Filters/DeuteranopiaProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class DeuteranopiaProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class DeuteranopiaProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="DeuteranopiaProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="DeuteranopiaProcessor"/> class.
/// </summary>
public DeuteranopiaProcessor()
: base(KnownFilterMatrices.DeuteranopiaFilter)

2
src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// </summary>
public ColorMatrix Matrix { get; }
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>()
public virtual IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
return new FilterProcessorImplementation<TPixel>(this);

8
src/ImageSharp/Processing/Processors/Filters/FilterProcessorImplementation.cs

@ -18,11 +18,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
internal class FilterProcessorImplementation<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private readonly FilterProcessor paramterSource;
private readonly FilterProcessor definition;
public FilterProcessorImplementation(FilterProcessor paramterSource)
public FilterProcessorImplementation(FilterProcessor definition)
{
this.paramterSource = paramterSource;
this.definition = definition;
}
/// <inheritdoc/>
@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
var interest = Rectangle.Intersect(sourceRectangle, source.Bounds());
int startX = interest.X;
ColorMatrix matrix = this.paramterSource.Matrix;
ColorMatrix matrix = this.definition.Matrix;
ParallelHelper.IterateRowsWithTempBuffer<Vector4>(
interest,

6
src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Applies a grayscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.601
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class GrayscaleBt601Processor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class GrayscaleBt601Processor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="GrayscaleBt601Processor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="GrayscaleBt601Processor"/> class.
/// </summary>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
public GrayscaleBt601Processor(float amount)

17
src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs

@ -2,18 +2,17 @@
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
/// <summary>
/// Applies a grayscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.709
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class GrayscaleBt709Processor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class GrayscaleBt709Processor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="GrayscaleBt709Processor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="GrayscaleBt709Processor"/> class.
/// </summary>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
public GrayscaleBt709Processor(float amount)
@ -23,8 +22,16 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
}
/// <summary>
/// Gets the proportion of the conversion
/// Gets the proportion of the conversion.
/// </summary>
public float Amount { get; }
// TODO: Move this to an appropriate extension method if possible.
internal void ApplyToFrame<TPixel>(ImageFrame<TPixel> frame, Rectangle sourceRectangle, Configuration configuration)
where TPixel : struct, IPixel<TPixel>
{
var processorImpl = new FilterProcessorImplementation<TPixel>(new GrayscaleBt709Processor(1F));
processorImpl.Apply(frame, sourceRectangle, configuration);
}
}
}

5
src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs

@ -8,11 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Applies a hue filter matrix using the given angle of rotation in degrees
/// </summary>
internal class HueProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class HueProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="HueProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="HueProcessor"/> class.
/// </summary>
/// <param name="degrees">The angle of rotation in degrees</param>
public HueProcessor(float degrees)

6
src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Applies a filter matrix that inverts the colors of an image
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class InvertProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class InvertProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="InvertProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="InvertProcessor"/> class.
/// </summary>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
public InvertProcessor(float amount)

6
src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Applies a filter matrix recreating an old Kodachrome camera effect matrix to the image
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class KodachromeProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class KodachromeProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="KodachromeProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="KodachromeProcessor"/> class.
/// </summary>
public KodachromeProcessor()
: base(KnownFilterMatrices.KodachromeFilter)

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

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

26
src/ImageSharp/Processing/Processors/Filters/LomographProcessorImplementation.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Overlays;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
internal class LomographProcessorImplementation<TPixel> : FilterProcessorImplementation<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static readonly TPixel VeryDarkGreen = ColorBuilder<TPixel>.FromRGBA(0, 10, 0, 255);
/// <inheritdoc/>
protected override void AfterFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
new VignetteProcessor<TPixel>(VeryDarkGreen).Apply(source, sourceRectangle, configuration);
}
public LomographProcessorImplementation(FilterProcessor definition)
: base(definition)
{
}
}
}

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

@ -10,13 +10,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Converts the colors of the image recreating an old Polaroid effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class PolaroidProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
public class PolaroidProcessor : FilterProcessor
{
private static readonly TPixel VeryDarkOrange = ColorBuilder<TPixel>.FromRGB(102, 34, 0);
private static readonly TPixel LightOrange = ColorBuilder<TPixel>.FromRGBA(255, 153, 102, 128);
/// <summary>
/// Initializes a new instance of the <see cref="PolaroidProcessor{TPixel}" /> class.
/// </summary>
@ -25,11 +20,26 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
{
}
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>() =>
new PolaroidProcessorImplementation<TPixel>(this);
}
internal class PolaroidProcessorImplementation<TPixel> : FilterProcessorImplementation<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static readonly TPixel VeryDarkOrange = ColorBuilder<TPixel>.FromRGB(102, 34, 0);
private static readonly TPixel LightOrange = ColorBuilder<TPixel>.FromRGBA(255, 153, 102, 128);
/// <inheritdoc/>
protected override void AfterFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
new VignetteProcessor<TPixel>(VeryDarkOrange).Apply(source, sourceRectangle, configuration);
new GlowProcessor<TPixel>(LightOrange, source.Width / 4F).Apply(source, sourceRectangle, configuration);
}
public PolaroidProcessorImplementation(FilterProcessor definition)
: base(definition)
{
}
}
}

6
src/ImageSharp/Processing/Processors/Filters/ProtanomalyProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Converts the colors of the image recreating Protanomaly (Red-Weak) color blindness.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class ProtanomalyProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class ProtanomalyProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="ProtanomalyProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="ProtanomalyProcessor"/> class.
/// </summary>
public ProtanomalyProcessor()
: base(KnownFilterMatrices.ProtanomalyFilter)

5
src/ImageSharp/Processing/Processors/Filters/ProtanopiaProcessor.cs

@ -9,11 +9,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class ProtanopiaProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class ProtanopiaProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="ProtanopiaProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="ProtanopiaProcessor"/> class.
/// </summary>
public ProtanopiaProcessor()
: base(KnownFilterMatrices.ProtanopiaFilter)

6
src/ImageSharp/Processing/Processors/Filters/SaturateProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Applies a saturation filter matrix using the given amount.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class SaturateProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class SaturateProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="SaturateProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="SaturateProcessor"/> class.
/// </summary>
/// <remarks>
/// A value of <value>0</value> is completely un-saturated. A value of <value>1</value> leaves the input unchanged.

6
src/ImageSharp/Processing/Processors/Filters/SepiaProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Applies a sepia filter matrix using the given amount.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class SepiaProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class SepiaProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="SepiaProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="SepiaProcessor"/> class.
/// </summary>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
public SepiaProcessor(float amount)

6
src/ImageSharp/Processing/Processors/Filters/TritanomalyProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Converts the colors of the image recreating Tritanomaly (Blue-Weak) color blindness.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class TritanomalyProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class TritanomalyProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="TritanomalyProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="TritanomalyProcessor"/> class.
/// </summary>
public TritanomalyProcessor()
: base(KnownFilterMatrices.TritanomalyFilter)

6
src/ImageSharp/Processing/Processors/Filters/TritanopiaProcessor.cs

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// Converts the colors of the image recreating Tritanopia (Blue-Blind) color blindness.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class TritanopiaProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class TritanopiaProcessor : FilterProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="TritanopiaProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="TritanopiaProcessor"/> class.
/// </summary>
public TritanopiaProcessor()
: base(KnownFilterMatrices.TritanopiaFilter)

31
src/ImageSharp/Processing/Processors/IImageProcessor.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>()
where TPixel : struct, IPixel<TPixel>;
}
/// <summary>
/// Encapsulates methods to alter the pixels of an image.
/// </summary>
@ -34,4 +34,33 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// </exception>
void Apply(Image<TPixel> source, Rectangle sourceRectangle);
}
internal static class ImageProcessorExtensions
{
public static void Apply(this IImageProcessor processor, Image source, Rectangle sourceRectangle)
{
var visitor = new ApplyVisitor(processor, sourceRectangle);
source.AcceptVisitor(visitor);
}
private class ApplyVisitor : IImageVisitor
{
private readonly IImageProcessor processor;
private readonly Rectangle sourceRectangle;
public ApplyVisitor(IImageProcessor processor, Rectangle sourceRectangle)
{
this.processor = processor;
this.sourceRectangle = sourceRectangle;
}
public void Visit<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
var processorImpl = processor.CreatePixelSpecificProcessor<TPixel>();
processorImpl.Apply(image, this.sourceRectangle);
}
}
}
}

14
src/ImageSharp/Processing/SaturateExtensions.cs

@ -8,7 +8,7 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Adds extensions that allow the alteration of the saturation component to the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the alteration of the saturation component to the <see cref="Image"/> type.
/// </summary>
public static class SaturateExtensions
{
@ -19,13 +19,11 @@ namespace SixLabors.ImageSharp.Processing
/// A value of 0 is completely un-saturated. A value of 1 leaves the input unchanged.
/// Other values are linear multipliers on the effect. Values of amount over 1 are allowed, providing super-saturated results
/// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Saturate<TPixel>(this IImageProcessingContext<TPixel> source, float amount)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new SaturateProcessor<TPixel>(amount));
public static IImageProcessingContext Saturate(this IImageProcessingContext source, float amount)
=> source.ApplyProcessor(new SaturateProcessor(amount));
/// <summary>
/// Alters the saturation component of the image.
@ -34,15 +32,13 @@ namespace SixLabors.ImageSharp.Processing
/// A value of 0 is completely un-saturated. A value of 1 leaves the input unchanged.
/// Other values are linear multipliers on the effect. Values of amount over 1 are allowed, providing super-saturated results
/// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Saturate<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new SaturateProcessor<TPixel>(amount), rectangle);
public static IImageProcessingContext Saturate(this IImageProcessingContext source, float amount, Rectangle rectangle)
=> source.ApplyProcessor(new SaturateProcessor(amount), rectangle);
}
}

22
src/ImageSharp/Processing/SepiaExtensions.cs

@ -8,56 +8,48 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Adds extensions that allow the application of sepia toning to the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the application of sepia toning to the <see cref="Image"/> type.
/// </summary>
public static class SepiaExtensions
{
/// <summary>
/// Applies sepia toning to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Sepia<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
public static IImageProcessingContext Sepia(this IImageProcessingContext source)
=> Sepia(source, 1F);
/// <summary>
/// Applies sepia toning to the image using the given amount.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Sepia<TPixel>(this IImageProcessingContext<TPixel> source, float amount)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new SepiaProcessor<TPixel>(amount));
public static IImageProcessingContext Sepia(this IImageProcessingContext source, float amount)
=> source.ApplyProcessor(new SepiaProcessor(amount));
/// <summary>
/// Applies sepia toning to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Sepia<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
public static IImageProcessingContext Sepia(this IImageProcessingContext source, Rectangle rectangle)
=> Sepia(source, 1F, rectangle);
/// <summary>
/// Applies sepia toning to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Sepia<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new SepiaProcessor<TPixel>(amount), rectangle);
public static IImageProcessingContext Sepia(this IImageProcessingContext source, float amount, Rectangle rectangle)
=> source.ApplyProcessor(new SepiaProcessor(amount), rectangle);
}
}
Loading…
Cancel
Save