Browse Source

Fix Tests

Merge IImageFilteringProcessor with IImageProcessor to simplify
encapsulation and allow easy setting of parallel options
pull/68/head
James Jackson-South 10 years ago
parent
commit
171a38a0fa
  1. 2
      src/ImageSharp/Drawing/Processors/DrawImageProcessor.cs
  2. 4
      src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs
  3. 2
      src/ImageSharp/Drawing/Processors/FillProcessor.cs
  4. 4
      src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs
  5. 2
      src/ImageSharp/Filters/ColorMatrix/ColorBlindness.cs
  6. 4
      src/ImageSharp/Filters/ColorMatrix/Grayscale.cs
  7. 4
      src/ImageSharp/Filters/Processors/Binarization/BinaryThresholdProcessor.cs
  8. 2
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs
  9. 2
      src/ImageSharp/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs
  10. 2
      src/ImageSharp/Filters/Processors/Convolution/BoxBlurProcessor.cs
  11. 2
      src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs
  12. 2
      src/ImageSharp/Filters/Processors/Convolution/Convolution2PassProcessor.cs
  13. 2
      src/ImageSharp/Filters/Processors/Convolution/ConvolutionProcessor.cs
  14. 2
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs
  15. 2
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs
  16. 2
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs
  17. 2
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs
  18. 2
      src/ImageSharp/Filters/Processors/Convolution/GaussianBlurProcessor.cs
  19. 2
      src/ImageSharp/Filters/Processors/Convolution/GaussianSharpenProcessor.cs
  20. 4
      src/ImageSharp/Filters/Processors/Effects/AlphaProcessor.cs
  21. 2
      src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs
  22. 4
      src/ImageSharp/Filters/Processors/Effects/BrightnessProcessor.cs
  23. 4
      src/ImageSharp/Filters/Processors/Effects/ContrastProcessor.cs
  24. 4
      src/ImageSharp/Filters/Processors/Effects/InvertProcessor.cs
  25. 4
      src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs
  26. 4
      src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs
  27. 36
      src/ImageSharp/Filters/Processors/IImageFilteringProcessor.cs
  28. 66
      src/ImageSharp/Filters/Processors/ImageFilteringProcessor.cs
  29. 4
      src/ImageSharp/Filters/Processors/Overlays/GlowProcessor.cs
  30. 4
      src/ImageSharp/Filters/Processors/Overlays/VignetteProcessor.cs
  31. 2
      src/ImageSharp/Filters/Processors/Transforms/CropProcessor.cs
  32. 2
      src/ImageSharp/Filters/Processors/Transforms/EntropyCropProcessor.cs
  33. 2
      src/ImageSharp/Filters/Processors/Transforms/FlipProcessor.cs
  34. 2
      src/ImageSharp/Filters/Processors/Transforms/Matrix3x2Processor.cs
  35. 2
      src/ImageSharp/Filters/Processors/Transforms/ResamplingWeightedProcessor.cs
  36. 20
      src/ImageSharp/Image/IImageProcessor.cs
  37. 9
      src/ImageSharp/Image/ImageProcessingExtensions.cs
  38. 56
      src/ImageSharp/ImageProcessor.cs

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

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Combines two images together by blending the pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class DrawImageProcessor<TColor> : ImageFilteringProcessor<TColor>
public class DrawImageProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs

@ -20,8 +20,8 @@ namespace ImageSharp.Drawing.Processors
/// Draws a path using the processor pipeline
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <seealso cref="ImageSharp.Processors.ImageFilteringProcessor{TColor}" />
public class DrawPathProcessor<TColor> : ImageFilteringProcessor<TColor>
/// <seealso cref="ImageSharp.Processors.ImageProcessor{TColor}" />
public class DrawPathProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
private const float AntialiasFactor = 1f;

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

@ -16,7 +16,7 @@ namespace ImageSharp.Drawing.Processors
/// Using the bursh as a source of pixels colors blends the brush color with source.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class FillProcessor<TColor> : ImageFilteringProcessor<TColor>
public class FillProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs

@ -17,8 +17,8 @@ namespace ImageSharp.Drawing.Processors
/// Usinf a brsuh and a shape fills shape with contents of brush the
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <seealso cref="ImageSharp.Processors.ImageFilteringProcessor{TColor}" />
public class FillShapeProcessor<TColor> : ImageFilteringProcessor<TColor>
/// <seealso cref="ImageSharp.Processors.ImageProcessor{TColor}" />
public class FillShapeProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
private const float AntialiasFactor = 1f;

2
src/ImageSharp/Filters/ColorMatrix/ColorBlindness.cs

@ -40,7 +40,7 @@ namespace ImageSharp
public static Image<TColor> ColorBlindness<TColor>(this Image<TColor> source, ColorBlindness colorBlindness, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
IImageFilteringProcessor<TColor> processor;
IImageProcessor<TColor> processor;
switch (colorBlindness)
{

4
src/ImageSharp/Filters/ColorMatrix/Grayscale.cs

@ -40,8 +40,8 @@ namespace ImageSharp
public static Image<TColor> Grayscale<TColor>(this Image<TColor> source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
IImageFilteringProcessor<TColor> processor = mode == GrayscaleMode.Bt709
? (IImageFilteringProcessor<TColor>)new GrayscaleBt709Processor<TColor>()
IImageProcessor<TColor> processor = mode == GrayscaleMode.Bt709
? (IImageProcessor<TColor>)new GrayscaleBt709Processor<TColor>()
: new GrayscaleBt601Processor<TColor>();
return source.Process(rectangle, processor);

4
src/ImageSharp/Filters/Processors/Binarization/BinaryThresholdProcessor.cs

@ -9,11 +9,11 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to perform binary threshold filtering against an
/// An <see cref="IImageProcessor{TColor}"/> to perform binary threshold filtering against an
/// <see cref="Image"/>. The image will be converted to grayscale before thresholding occurs.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class BinaryThresholdProcessor<TColor> : ImageFilteringProcessor<TColor>
public class BinaryThresholdProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// The color matrix filter. Inherit from this class to perform operation involving color matrices.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class ColorMatrixFilter<TColor> : ImageFilteringProcessor<TColor>, IColorMatrixFilter<TColor>
public abstract class ColorMatrixFilter<TColor> : ImageProcessor<TColor>, IColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>

2
src/ImageSharp/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// alter the image pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public interface IColorMatrixFilter<TColor> : IImageFilteringProcessor<TColor>
public interface IColorMatrixFilter<TColor> : IImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/BoxBlurProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Applies a Box blur sampler to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class BoxBlurProcessor<TColor> : ImageFilteringProcessor<TColor>
public class BoxBlurProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that uses two one-dimensional matrices to perform convolution against an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class Convolution2DProcessor<TColor> : ImageFilteringProcessor<TColor>
public class Convolution2DProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/Convolution2PassProcessor.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that uses two one-dimensional matrices to perform two-pass convolution against an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class Convolution2PassProcessor<TColor> : ImageFilteringProcessor<TColor>
public class Convolution2PassProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/ConvolutionProcessor.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that uses a 2 dimensional matrix to perform convolution against an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class ConvolutionProcessor<TColor> : ImageFilteringProcessor<TColor>
public class ConvolutionProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that detects edges within an image using two one-dimensional matrices.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class EdgeDetector2DProcessor<TColor> : ImageFilteringProcessor<TColor>, IEdgeDetectorProcessor<TColor>
public abstract class EdgeDetector2DProcessor<TColor> : ImageProcessor<TColor>, IEdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that detects edges within an image using a eight two dimensional matrices.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class EdgeDetectorCompassProcessor<TColor> : ImageFilteringProcessor<TColor>, IEdgeDetectorProcessor<TColor>
public abstract class EdgeDetectorCompassProcessor<TColor> : ImageProcessor<TColor>, IEdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that detects edges within an image using a single two dimensional matrix.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class EdgeDetectorProcessor<TColor> : ImageFilteringProcessor<TColor>, IEdgeDetectorProcessor<TColor>
public abstract class EdgeDetectorProcessor<TColor> : ImageProcessor<TColor>, IEdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>

2
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Provides properties and methods allowing the detection of edges within an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public interface IEdgeDetectorProcessor<TColor> : IImageFilteringProcessor<TColor>, IEdgeDetectorProcessor
public interface IEdgeDetectorProcessor<TColor> : IImageProcessor<TColor>, IEdgeDetectorProcessor
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
}

2
src/ImageSharp/Filters/Processors/Convolution/GaussianBlurProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Applies a Gaussian blur sampler to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class GaussianBlurProcessor<TColor> : ImageFilteringProcessor<TColor>
public class GaussianBlurProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/GaussianSharpenProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Applies a Gaussian sharpening sampler to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class GaussianSharpenProcessor<TColor> : ImageFilteringProcessor<TColor>
public class GaussianSharpenProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Effects/AlphaProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to change the alpha component of an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to change the alpha component of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class AlphaProcessor<TColor> : ImageFilteringProcessor<TColor>
public class AlphaProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Sets the background color of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class BackgroundColorProcessor<TColor> : ImageFilteringProcessor<TColor>
public class BackgroundColorProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Effects/BrightnessProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to change the brightness of an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to change the brightness of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class BrightnessProcessor<TColor> : ImageFilteringProcessor<TColor>
public class BrightnessProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Effects/ContrastProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to change the contrast of an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to change the contrast of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class ContrastProcessor<TColor> : ImageFilteringProcessor<TColor>
public class ContrastProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Effects/InvertProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to invert the colors of an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to invert the colors of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class InvertProcessor<TColor> : ImageFilteringProcessor<TColor>
public class InvertProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>

4
src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs

@ -10,11 +10,11 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to apply an oil painting effect to an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to apply an oil painting effect to an <see cref="Image{TColor}"/>.
/// </summary>
/// <remarks>Adapted from <see href="https://softwarebydefault.com/2013/06/29/oil-painting-cartoon-filter/"/> by Dewald Esterhuizen.</remarks>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class OilPaintingProcessor<TColor> : ImageFilteringProcessor<TColor>
public class OilPaintingProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to pixelate the colors of an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to pixelate the colors of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class PixelateProcessor<TColor> : ImageFilteringProcessor<TColor>
public class PixelateProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

36
src/ImageSharp/Filters/Processors/IImageFilteringProcessor.cs

@ -1,36 +0,0 @@
// <copyright file="IImageFilteringProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Processors
{
using System;
/// <summary>
/// Encapsulates methods to alter the pixels of an image. The processor operates on the original source pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public interface IImageFilteringProcessor<TColor> : IImageProcessor
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor}"/>.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
/// <remarks>
/// The method keeps the source image unchanged and returns the
/// the result of image processing filter as new image.
/// </remarks>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="source"/> is null.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="sourceRectangle"/> doesnt fit the dimension of the image.
/// </exception>
void Apply(ImageBase<TColor> source, Rectangle sourceRectangle);
}
}

66
src/ImageSharp/Filters/Processors/ImageFilteringProcessor.cs

@ -1,66 +0,0 @@
// <copyright file="ImageFilteringProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Processors
{
using System;
/// <summary>
/// Encapsulates methods to alter the pixels of an image. The processor operates on the original source pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class ImageFilteringProcessor<TColor> : ImageProcessor<TColor>, IImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public void Apply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
try
{
this.BeforeApply(source, sourceRectangle);
this.OnApply(source, sourceRectangle);
this.AfterApply(source, sourceRectangle);
}
catch (Exception ex)
{
throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex);
}
}
/// <summary>
/// This method is called before the process is applied to prepare the processor.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected virtual void BeforeApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
}
/// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor}"/> at the specified location
/// and with the specified size.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected abstract void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle);
/// <summary>
/// This method is called after the process is applied to prepare the processor.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected virtual void AfterApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
}
}
}

4
src/ImageSharp/Filters/Processors/Overlays/GlowProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> that applies a radial glow effect an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> that applies a radial glow effect an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class GlowProcessor<TColor> : ImageFilteringProcessor<TColor>
public class GlowProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Overlays/VignetteProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> that applies a radial vignette effect to an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> that applies a radial vignette effect to an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class VignetteProcessor<TColor> : ImageFilteringProcessor<TColor>
public class VignetteProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Transforms/CropProcessor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processors
/// Provides methods to allow the cropping of an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class CropProcessor<TColor> : ImageFilteringProcessor<TColor>
public class CropProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Transforms/EntropyCropProcessor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processors
/// entropy.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class EntropyCropProcessor<TColor> : ImageFilteringProcessor<TColor>
public class EntropyCropProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Transforms/FlipProcessor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processors
/// Provides methods that allow the flipping of an image around its center point.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class FlipProcessor<TColor> : ImageFilteringProcessor<TColor>
public class FlipProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Transforms/Matrix3x2Processor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processors
/// Provides methods to transform an image using a <see cref="Matrix3x2"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class Matrix3x2Processor<TColor> : ImageFilteringProcessor<TColor>
public abstract class Matrix3x2Processor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Transforms/ResamplingWeightedProcessor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processors
/// Adapted from <see href="http://www.realtimerendering.com/resources/GraphicsGems/gemsiii/filter_rcg.c"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class ResamplingWeightedProcessor<TColor> : ImageFilteringProcessor<TColor>
public abstract class ResamplingWeightedProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

20
src/ImageSharp/Image/IImageProcessor.cs

@ -5,12 +5,15 @@
namespace ImageSharp.Processors
{
using System;
using System.Threading.Tasks;
/// <summary>
/// Encapsulates methods to alter the pixels of an image.
/// </summary>
public interface IImageProcessor
/// <typeparam name="TColor">The pixel format.</typeparam>
public interface IImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Gets or sets the parallel options for processing tasks in parallel.
@ -22,5 +25,20 @@ namespace ImageSharp.Processors
/// or expand individual pixel colors the value on processing.
/// </summary>
bool Compand { get; set; }
/// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor}"/>.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="source"/> is null.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="sourceRectangle"/> doesnt fit the dimension of the image.
/// </exception>
void Apply(ImageBase<TColor> source, Rectangle sourceRectangle);
}
}

9
src/ImageSharp/Image/ImageProcessingExtensions.cs

@ -21,7 +21,7 @@ namespace ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="processor">The processor to apply to the image.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
internal static Image<TColor> Process<TColor>(this Image<TColor> source, IImageFilteringProcessor<TColor> processor)
internal static Image<TColor> Process<TColor>(this Image<TColor> source, IImageProcessor<TColor> processor)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Process(source, source.Bounds, processor);
@ -38,14 +38,9 @@ namespace ImageSharp
/// </param>
/// <param name="processor">The processors to apply to the image.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
internal static Image<TColor> Process<TColor>(this Image<TColor> source, Rectangle sourceRectangle, IImageFilteringProcessor<TColor> processor)
internal static Image<TColor> Process<TColor>(this Image<TColor> source, Rectangle sourceRectangle, IImageProcessor<TColor> processor)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
if (processor.ParallelOptions == null)
{
processor.ParallelOptions = source.Bootstrapper.ParallelOptions;
}
return PerformAction(source, (sourceImage) => processor.Apply(sourceImage, sourceRectangle));
}

56
src/ImageSharp/ImageProcessor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processors
/// Allows the application of processors to images.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class ImageProcessor<TColor> : IImageProcessor
public abstract class ImageProcessor<TColor> : IImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
@ -20,5 +20,59 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public virtual bool Compand { get; set; } = false;
/// <inheritdoc/>
public void Apply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
if (this.ParallelOptions == null)
{
this.ParallelOptions = source.Bootstrapper.ParallelOptions;
}
try
{
this.BeforeApply(source, sourceRectangle);
this.OnApply(source, sourceRectangle);
this.AfterApply(source, sourceRectangle);
}
catch (Exception ex)
{
throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex);
}
}
/// <summary>
/// This method is called before the process is applied to prepare the processor.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected virtual void BeforeApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
}
/// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor}"/> at the specified location
/// and with the specified size.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected abstract void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle);
/// <summary>
/// This method is called after the process is applied to prepare the processor.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected virtual void AfterApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
}
}
}
Loading…
Cancel
Save