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. /// 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. /// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing brighter results.
/// </remarks> /// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param> /// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Brightness<TPixel>(this IImageProcessingContext<TPixel> source, float amount) public static IImageProcessingContext Brightness(this IImageProcessingContext source, float amount)
where TPixel : struct, IPixel<TPixel> => source.ApplyProcessor(new BrightnessProcessor(amount));
=> source.ApplyProcessor(new BrightnessProcessor<TPixel>(amount));
/// <summary> /// <summary>
/// Alters the brightness component of the image. /// 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. /// 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. /// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing brighter results.
/// </remarks> /// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param> /// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Brightness<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle) public static IImageProcessingContext Brightness(this IImageProcessingContext source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> => source.ApplyProcessor(new BrightnessProcessor(amount), rectangle);
=> source.ApplyProcessor(new BrightnessProcessor<TPixel>(amount), rectangle);
} }
} }

31
src/ImageSharp/Processing/ColorBlindnessExtensions.cs

@ -16,49 +16,44 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Applies the given colorblindness simulator to the image. /// Applies the given colorblindness simulator to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param> /// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> ColorBlindness<TPixel>(this IImageProcessingContext<TPixel> source, ColorBlindnessMode colorBlindness) public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindnessMode colorBlindness)
where TPixel : struct, IPixel<TPixel> => source.ApplyProcessor(GetProcessor(colorBlindness));
=> source.ApplyProcessor(GetProcessor<TPixel>(colorBlindness));
/// <summary> /// <summary>
/// Applies the given colorblindness simulator to the image. /// Applies the given colorblindness simulator to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="colorBlindnessMode">The type of color blindness simulator to apply.</param> /// <param name="colorBlindnessMode">The type of color blindness simulator to apply.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> ColorBlindness<TPixel>(this IImageProcessingContext<TPixel> source, ColorBlindnessMode colorBlindnessMode, Rectangle rectangle) public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindnessMode colorBlindnessMode, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> => source.ApplyProcessor(GetProcessor(colorBlindnessMode), rectangle);
=> source.ApplyProcessor(GetProcessor<TPixel>(colorBlindnessMode), rectangle);
private static IImageProcessor<TPixel> GetProcessor<TPixel>(ColorBlindnessMode colorBlindness) private static IImageProcessor GetProcessor(ColorBlindnessMode colorBlindness)
where TPixel : struct, IPixel<TPixel>
{ {
switch (colorBlindness) switch (colorBlindness)
{ {
case ColorBlindnessMode.Achromatomaly: case ColorBlindnessMode.Achromatomaly:
return new AchromatomalyProcessor<TPixel>(); return new AchromatomalyProcessor();
case ColorBlindnessMode.Achromatopsia: case ColorBlindnessMode.Achromatopsia:
return new AchromatopsiaProcessor<TPixel>(); return new AchromatopsiaProcessor();
case ColorBlindnessMode.Deuteranomaly: case ColorBlindnessMode.Deuteranomaly:
return new DeuteranomalyProcessor<TPixel>(); return new DeuteranomalyProcessor();
case ColorBlindnessMode.Deuteranopia: case ColorBlindnessMode.Deuteranopia:
return new DeuteranopiaProcessor<TPixel>(); return new DeuteranopiaProcessor();
case ColorBlindnessMode.Protanomaly: case ColorBlindnessMode.Protanomaly:
return new ProtanomalyProcessor<TPixel>(); return new ProtanomalyProcessor();
case ColorBlindnessMode.Protanopia: case ColorBlindnessMode.Protanopia:
return new ProtanopiaProcessor<TPixel>(); return new ProtanopiaProcessor();
case ColorBlindnessMode.Tritanomaly: case ColorBlindnessMode.Tritanomaly:
return new TritanomalyProcessor<TPixel>(); return new TritanomalyProcessor();
default: 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 namespace SixLabors.ImageSharp.Processing
{ {
/// <summary> /// <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> /// </summary>
public static class ContrastExtensions 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. /// 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. /// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing results with more contrast.
/// </remarks> /// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param> /// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Contrast<TPixel>(this IImageProcessingContext<TPixel> source, float amount) public static IImageProcessingContext Contrast(this IImageProcessingContext source, float amount)
where TPixel : struct, IPixel<TPixel> => source.ApplyProcessor(new ContrastProcessor(amount));
=> source.ApplyProcessor(new ContrastProcessor<TPixel>(amount));
/// <summary> /// <summary>
/// Alters the contrast component of the image. /// 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. /// 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. /// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing results with more contrast.
/// </remarks> /// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param> /// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Contrast<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle) public static IImageProcessingContext Contrast(this IImageProcessingContext source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> => source.ApplyProcessor(new ContrastProcessor(amount), rectangle);
=> source.ApplyProcessor(new ContrastProcessor<TPixel>(amount), rectangle);
} }
} }

62
src/ImageSharp/Processing/GrayscaleExtensions.cs

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

14
src/ImageSharp/Processing/HueExtensions.cs

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

14
src/ImageSharp/Processing/InvertExtensions.cs

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

14
src/ImageSharp/Processing/KodachromeExtensions.cs

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

14
src/ImageSharp/Processing/LomographExtensions.cs

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

13
src/ImageSharp/Processing/PolaroidExtensions.cs

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

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

@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{ {
if (this.Grayscale) 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) 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) 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> /// <summary>
/// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness. /// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> internal class AchromatomalyProcessor : FilterProcessor
internal class AchromatomalyProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="AchromatomalyProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="AchromatomalyProcessor"/> class.
/// </summary> /// </summary>
public AchromatomalyProcessor() public AchromatomalyProcessor()
: base(KnownFilterMatrices.AchromatomalyFilter) : base(KnownFilterMatrices.AchromatomalyFilter)

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

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

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

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary> /// <summary>
/// Applies a brightness filter matrix using the given amount. /// Applies a brightness filter matrix using the given amount.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> internal class BrightnessProcessor : FilterProcessor
internal class BrightnessProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BrightnessProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="BrightnessProcessor"/> class.
/// </summary> /// </summary>
/// <remarks> /// <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. /// 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> /// <summary>
/// Applies a contrast filter matrix using the given amount. /// Applies a contrast filter matrix using the given amount.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> internal class ContrastProcessor : FilterProcessor
internal class ContrastProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ContrastProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="ContrastProcessor"/> class.
/// </summary> /// </summary>
/// <remarks> /// <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. /// 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> /// <summary>
/// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness. /// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> internal class DeuteranomalyProcessor : FilterProcessor
internal class DeuteranomalyProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DeuteranomalyProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="DeuteranomalyProcessor"/> class.
/// </summary> /// </summary>
public DeuteranomalyProcessor() public DeuteranomalyProcessor()
: base(KnownFilterMatrices.DeuteranomalyFilter) : base(KnownFilterMatrices.DeuteranomalyFilter)

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

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

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

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// </summary> /// </summary>
public ColorMatrix Matrix { get; } public ColorMatrix Matrix { get; }
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>() public virtual IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>()
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
return new FilterProcessorImplementation<TPixel>(this); 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> internal class FilterProcessorImplementation<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<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/> /// <inheritdoc/>
@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
var interest = Rectangle.Intersect(sourceRectangle, source.Bounds()); var interest = Rectangle.Intersect(sourceRectangle, source.Bounds());
int startX = interest.X; int startX = interest.X;
ColorMatrix matrix = this.paramterSource.Matrix; ColorMatrix matrix = this.definition.Matrix;
ParallelHelper.IterateRowsWithTempBuffer<Vector4>( ParallelHelper.IterateRowsWithTempBuffer<Vector4>(
interest, interest,

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

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

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

@ -2,18 +2,17 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors.Filters namespace SixLabors.ImageSharp.Processing.Processors.Filters
{ {
/// <summary> /// <summary>
/// Applies a grayscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.709 /// Applies a grayscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.709
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> internal class GrayscaleBt709Processor : FilterProcessor
internal class GrayscaleBt709Processor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GrayscaleBt709Processor{TPixel}"/> class. /// Initializes a new instance of the <see cref="GrayscaleBt709Processor"/> class.
/// </summary> /// </summary>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param> /// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
public GrayscaleBt709Processor(float amount) public GrayscaleBt709Processor(float amount)
@ -23,8 +22,16 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
} }
/// <summary> /// <summary>
/// Gets the proportion of the conversion /// Gets the proportion of the conversion.
/// </summary> /// </summary>
public float Amount { get; } 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> /// <summary>
/// Applies a hue filter matrix using the given angle of rotation in degrees /// Applies a hue filter matrix using the given angle of rotation in degrees
/// </summary> /// </summary>
internal class HueProcessor<TPixel> : FilterProcessor<TPixel> internal class HueProcessor : FilterProcessor
where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HueProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="HueProcessor"/> class.
/// </summary> /// </summary>
/// <param name="degrees">The angle of rotation in degrees</param> /// <param name="degrees">The angle of rotation in degrees</param>
public HueProcessor(float degrees) public HueProcessor(float degrees)

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

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

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

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

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

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

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> /// <summary>
/// Converts the colors of the image recreating an old Polaroid effect. /// Converts the colors of the image recreating an old Polaroid effect.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> public class PolaroidProcessor : FilterProcessor
internal class PolaroidProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
private static readonly TPixel VeryDarkOrange = ColorBuilder<TPixel>.FromRGB(102, 34, 0);
private static readonly TPixel LightOrange = ColorBuilder<TPixel>.FromRGBA(255, 153, 102, 128);
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PolaroidProcessor{TPixel}" /> class. /// Initializes a new instance of the <see cref="PolaroidProcessor{TPixel}" /> class.
/// </summary> /// </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/> /// <inheritdoc/>
protected override void AfterFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) protected override void AfterFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{ {
new VignetteProcessor<TPixel>(VeryDarkOrange).Apply(source, sourceRectangle, configuration); new VignetteProcessor<TPixel>(VeryDarkOrange).Apply(source, sourceRectangle, configuration);
new GlowProcessor<TPixel>(LightOrange, source.Width / 4F).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> /// <summary>
/// Converts the colors of the image recreating Protanomaly (Red-Weak) color blindness. /// Converts the colors of the image recreating Protanomaly (Red-Weak) color blindness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> internal class ProtanomalyProcessor : FilterProcessor
internal class ProtanomalyProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ProtanomalyProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="ProtanomalyProcessor"/> class.
/// </summary> /// </summary>
public ProtanomalyProcessor() public ProtanomalyProcessor()
: base(KnownFilterMatrices.ProtanomalyFilter) : 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. /// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class ProtanopiaProcessor<TPixel> : FilterProcessor<TPixel> internal class ProtanopiaProcessor : FilterProcessor
where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ProtanopiaProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="ProtanopiaProcessor"/> class.
/// </summary> /// </summary>
public ProtanopiaProcessor() public ProtanopiaProcessor()
: base(KnownFilterMatrices.ProtanopiaFilter) : base(KnownFilterMatrices.ProtanopiaFilter)

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

@ -8,12 +8,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary> /// <summary>
/// Applies a saturation filter matrix using the given amount. /// Applies a saturation filter matrix using the given amount.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> internal class SaturateProcessor : FilterProcessor
internal class SaturateProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SaturateProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="SaturateProcessor"/> class.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// A value of <value>0</value> is completely un-saturated. A value of <value>1</value> leaves the input unchanged. /// 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> /// <summary>
/// Applies a sepia filter matrix using the given amount. /// Applies a sepia filter matrix using the given amount.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> internal class SepiaProcessor : FilterProcessor
internal class SepiaProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SepiaProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="SepiaProcessor"/> class.
/// </summary> /// </summary>
/// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param> /// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param>
public SepiaProcessor(float amount) public SepiaProcessor(float amount)

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

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

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

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

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

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>() IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>()
where TPixel : struct, IPixel<TPixel>; where TPixel : struct, IPixel<TPixel>;
} }
/// <summary> /// <summary>
/// Encapsulates methods to alter the pixels of an image. /// Encapsulates methods to alter the pixels of an image.
/// </summary> /// </summary>
@ -34,4 +34,33 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// </exception> /// </exception>
void Apply(Image<TPixel> source, Rectangle sourceRectangle); 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 namespace SixLabors.ImageSharp.Processing
{ {
/// <summary> /// <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> /// </summary>
public static class SaturateExtensions 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. /// 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 /// Other values are linear multipliers on the effect. Values of amount over 1 are allowed, providing super-saturated results
/// </remarks> /// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param> /// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Saturate<TPixel>(this IImageProcessingContext<TPixel> source, float amount) public static IImageProcessingContext Saturate(this IImageProcessingContext source, float amount)
where TPixel : struct, IPixel<TPixel> => source.ApplyProcessor(new SaturateProcessor(amount));
=> source.ApplyProcessor(new SaturateProcessor<TPixel>(amount));
/// <summary> /// <summary>
/// Alters the saturation component of the image. /// 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. /// 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 /// Other values are linear multipliers on the effect. Values of amount over 1 are allowed, providing super-saturated results
/// </remarks> /// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param> /// <param name="amount">The proportion of the conversion. Must be greater than or equal to 0.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Saturate<TPixel>(this IImageProcessingContext<TPixel> source, float amount, Rectangle rectangle) public static IImageProcessingContext Saturate(this IImageProcessingContext source, float amount, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel> => source.ApplyProcessor(new SaturateProcessor(amount), rectangle);
=> source.ApplyProcessor(new SaturateProcessor<TPixel>(amount), rectangle);
} }
} }

22
src/ImageSharp/Processing/SepiaExtensions.cs

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