Browse Source

Merging into master

af/merge-core
James Jackson-South 9 years ago
parent
commit
7e048ed506
  1. 2
      ImageSharp.sln
  2. 4
      README.md
  3. 13
      src/ImageSharp/Colors/PackedPixel/IPackedPixel.cs
  4. 2
      src/ImageSharp/Colors/PackedPixel/IPackedVector.cs
  5. 10
      src/ImageSharp/Common/Extensions/ArrayExtensions.cs
  6. 18
      src/ImageSharp/Common/Helpers/ImageMaths.cs
  7. 28
      src/ImageSharp/Drawing/Brushes/Brushes.cs
  8. 40
      src/ImageSharp/Drawing/Brushes/Brushes{TColor}.cs
  9. 10
      src/ImageSharp/Drawing/Brushes/IBrush.cs
  10. 4
      src/ImageSharp/Drawing/Brushes/ImageBrush.cs
  11. 22
      src/ImageSharp/Drawing/Brushes/ImageBrush{TColor}.cs
  12. 4
      src/ImageSharp/Drawing/Brushes/PatternBrush.cs
  13. 18
      src/ImageSharp/Drawing/Brushes/PatternBrush{TColor}.cs
  14. 6
      src/ImageSharp/Drawing/Brushes/Processors/IBrushApplicator.cs
  15. 2
      src/ImageSharp/Drawing/Brushes/SolidBrush.cs
  16. 14
      src/ImageSharp/Drawing/Brushes/SolidBrush{TColor}.cs
  17. 228
      src/ImageSharp/Drawing/Draw.cs
  18. 18
      src/ImageSharp/Drawing/DrawImage.cs
  19. 53
      src/ImageSharp/Drawing/DrawRectangle.cs
  20. 80
      src/ImageSharp/Drawing/Fill.cs
  21. 82
      src/ImageSharp/Drawing/FillRectangle.cs
  22. 92
      src/ImageSharp/Drawing/Fill_Rectangle.cs
  23. 13
      src/ImageSharp/Drawing/Pens/IPen.cs
  24. 272
      src/ImageSharp/Drawing/Pens/Pen.cs
  25. 141
      src/ImageSharp/Drawing/Pens/Pens.cs
  26. 112
      src/ImageSharp/Drawing/Pens/Pens{TColor}.cs
  27. 267
      src/ImageSharp/Drawing/Pens/Pen{TColor}.cs
  28. 6
      src/ImageSharp/Drawing/Pens/Processors/ColoredPointInfo.cs
  29. 10
      src/ImageSharp/Drawing/Pens/Processors/IPenApplicator.cs
  30. 18
      src/ImageSharp/Drawing/Processors/DrawImageProcessor.cs
  31. 28
      src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs
  32. 27
      src/ImageSharp/Drawing/Processors/FillProcessor.cs
  33. 42
      src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs
  34. 28
      src/ImageSharp/Filters/Binarization/BinaryThreshold.cs
  35. 20
      src/ImageSharp/Filters/ColorMatrix/BlackWhite.cs
  36. 36
      src/ImageSharp/Filters/ColorMatrix/ColorBlindness.cs
  37. 24
      src/ImageSharp/Filters/ColorMatrix/Grayscale.cs
  38. 20
      src/ImageSharp/Filters/ColorMatrix/Hue.cs
  39. 20
      src/ImageSharp/Filters/ColorMatrix/Kodachrome.cs
  40. 20
      src/ImageSharp/Filters/ColorMatrix/Lomograph.cs
  41. 20
      src/ImageSharp/Filters/ColorMatrix/Polaroid.cs
  42. 20
      src/ImageSharp/Filters/ColorMatrix/Saturation.cs
  43. 16
      src/ImageSharp/Filters/ColorMatrix/Sepia.cs
  44. 20
      src/ImageSharp/Filters/Convolution/BoxBlur.cs
  45. 80
      src/ImageSharp/Filters/Convolution/DetectEdges.cs
  46. 20
      src/ImageSharp/Filters/Convolution/GaussianBlur.cs
  47. 20
      src/ImageSharp/Filters/Convolution/GaussianSharpen.cs
  48. 16
      src/ImageSharp/Filters/Effects/Alpha.cs
  49. 12
      src/ImageSharp/Filters/Effects/BackgroundColor.cs
  50. 28
      src/ImageSharp/Filters/Effects/Brightness.cs
  51. 20
      src/ImageSharp/Filters/Effects/Contrast.cs
  52. 16
      src/ImageSharp/Filters/Effects/Invert.cs
  53. 20
      src/ImageSharp/Filters/Effects/OilPainting.cs
  54. 20
      src/ImageSharp/Filters/Effects/Pixelate.cs
  55. 44
      src/ImageSharp/Filters/Overlays/Glow.cs
  56. 44
      src/ImageSharp/Filters/Overlays/Vignette.cs
  57. 18
      src/ImageSharp/Filters/Processors/Binarization/BinaryThresholdProcessor.cs
  58. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs
  59. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs
  60. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs
  61. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs
  62. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs
  63. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs
  64. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs
  65. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs
  66. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs
  67. 10
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs
  68. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt601Processor.cs
  69. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs
  70. 10
      src/ImageSharp/Filters/Processors/ColorMatrix/HueProcessor.cs
  71. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs
  72. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/KodachromeProcessor.cs
  73. 10
      src/ImageSharp/Filters/Processors/ColorMatrix/LomographProcessor.cs
  74. 12
      src/ImageSharp/Filters/Processors/ColorMatrix/PolaroidProcessor.cs
  75. 10
      src/ImageSharp/Filters/Processors/ColorMatrix/SaturationProcessor.cs
  76. 6
      src/ImageSharp/Filters/Processors/ColorMatrix/SepiaProcessor.cs
  77. 12
      src/ImageSharp/Filters/Processors/Convolution/BoxBlurProcessor.cs
  78. 14
      src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs
  79. 16
      src/ImageSharp/Filters/Processors/Convolution/Convolution2PassProcessor.cs
  80. 14
      src/ImageSharp/Filters/Processors/Convolution/ConvolutionProcessor.cs
  81. 14
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs
  82. 24
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs
  83. 14
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs
  84. 6
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs
  85. 6
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs
  86. 6
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs
  87. 6
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs
  88. 6
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs
  89. 6
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs
  90. 6
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs
  91. 6
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs
  92. 6
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs
  93. 6
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs
  94. 6
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs
  95. 16
      src/ImageSharp/Filters/Processors/Convolution/GaussianBlurProcessor.cs
  96. 16
      src/ImageSharp/Filters/Processors/Convolution/GaussianSharpenProcessor.cs
  97. 14
      src/ImageSharp/Filters/Processors/Effects/AlphaProcessor.cs
  98. 12
      src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs
  99. 14
      src/ImageSharp/Filters/Processors/Effects/BrightnessProcessor.cs
  100. 14
      src/ImageSharp/Filters/Processors/Effects/ContrastProcessor.cs

2
ImageSharp.sln

@ -15,7 +15,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
build\appveyor-semver.ps1 = build\appveyor-semver.ps1
appveyor.yml = appveyor.yml
CodeCoverage.runsettings = CodeCoverage.runsettings
contributing.md = contributing.md
build\dotnet-latest.ps1 = build\dotnet-latest.ps1
features.md = features.md
global.json = global.json
build\package.json = build\package.json
README.md = README.md

4
README.md

@ -197,13 +197,13 @@ Setting individual pixel values is perfomed as follows:
```csharp
Image image = new Image(400, 400);
using (PixelAccessor pixels = image.Lock())
using (var pixels = image.Lock())
{
pixels[200, 200] = Color.White;
}
```
For advanced usage the `Image<TColor, TPacked>` and `PixelAccessor<TColor, TPacked>` classes are available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame.
For advanced usage the `Image<TColor>` and `PixelAccessor<TColor>` classes are available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame.
All in all this should allow image processing to be much more accessible to developers which has always been my goal from the start.

13
src/ImageSharp/Colors/PackedPixel/IPackedPixel.cs

@ -8,11 +8,18 @@ namespace ImageSharp
using System;
/// <summary>
/// An interface that represents a packed pixel type.
/// An interface that represents a generic packed pixel type.
/// </summary>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public interface IPackedPixel<TPacked> : IPackedVector<TPacked>, IPackedBytes
public interface IPackedPixel<TPacked> : IPackedPixel, IPackedVector<TPacked>
where TPacked : struct, IEquatable<TPacked>
{
}
}
/// <summary>
/// An interface that represents a packed pixel type.
/// </summary>
public interface IPackedPixel : IPackedVector, IPackedBytes
{
}
}

2
src/ImageSharp/Colors/PackedPixel/IPackedVector.cs

@ -40,4 +40,4 @@ namespace ImageSharp
/// <returns>The <see cref="Vector4"/>.</returns>
Vector4 ToVector4();
}
}
}

10
src/ImageSharp/Common/Extensions/ArrayExtensions.cs

@ -16,16 +16,14 @@ namespace ImageSharp
/// Locks the pixel buffer providing access to the pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="pixels">The pixel buffer.</param>
/// <param name="width">Gets the width of the image represented by the pixel buffer.</param>
/// <param name="height">The height of the image represented by the pixel buffer.</param>
/// <returns>The <see cref="PixelAccessor{TColor,TPacked}"/></returns>
public static PixelAccessor<TColor, TPacked> Lock<TColor, TPacked>(this TColor[] pixels, int width, int height)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="PixelAccessor{TColor}"/></returns>
public static PixelAccessor<TColor> Lock<TColor>(this TColor[] pixels, int width, int height)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return new PixelAccessor<TColor, TPacked>(width, height, pixels);
return new PixelAccessor<TColor>(width, height, pixels);
}
}
}

18
src/ImageSharp/Common/Helpers/ImageMaths.cs

@ -157,16 +157,14 @@ namespace ImageSharp
/// than the given one.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="bitmap">The <see cref="Image"/> to search within.</param>
/// <param name="componentValue">The color component value to remove.</param>
/// <param name="channel">The <see cref="RgbaComponent"/> channel to test against.</param>
/// <returns>
/// The <see cref="Rectangle"/>.
/// </returns>
public static Rectangle GetFilteredBoundingRectangle<TColor, TPacked>(ImageBase<TColor, TPacked> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Rectangle GetFilteredBoundingRectangle<TColor>(ImageBase<TColor> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
const float Epsilon = .00001f;
int width = bitmap.Width;
@ -174,7 +172,7 @@ namespace ImageSharp
Point topLeft = default(Point);
Point bottomRight = default(Point);
Func<PixelAccessor<TColor, TPacked>, int, int, float, bool> delegateFunc;
Func<PixelAccessor<TColor>, int, int, float, bool> delegateFunc;
// Determine which channel to check against
switch (channel)
@ -196,7 +194,7 @@ namespace ImageSharp
break;
}
Func<PixelAccessor<TColor, TPacked>, int> getMinY = pixels =>
Func<PixelAccessor<TColor>, int> getMinY = pixels =>
{
for (int y = 0; y < height; y++)
{
@ -212,7 +210,7 @@ namespace ImageSharp
return 0;
};
Func<PixelAccessor<TColor, TPacked>, int> getMaxY = pixels =>
Func<PixelAccessor<TColor>, int> getMaxY = pixels =>
{
for (int y = height - 1; y > -1; y--)
{
@ -228,7 +226,7 @@ namespace ImageSharp
return height;
};
Func<PixelAccessor<TColor, TPacked>, int> getMinX = pixels =>
Func<PixelAccessor<TColor>, int> getMinX = pixels =>
{
for (int x = 0; x < width; x++)
{
@ -244,7 +242,7 @@ namespace ImageSharp
return 0;
};
Func<PixelAccessor<TColor, TPacked>, int> getMaxX = pixels =>
Func<PixelAccessor<TColor>, int> getMaxX = pixels =>
{
for (int x = width - 1; x > -1; x--)
{
@ -260,7 +258,7 @@ namespace ImageSharp
return height;
};
using (PixelAccessor<TColor, TPacked> bitmapPixels = bitmap.Lock())
using (PixelAccessor<TColor> bitmapPixels = bitmap.Lock())
{
topLeft.Y = getMinY(bitmapPixels);
topLeft.X = getMinX(bitmapPixels);

28
src/ImageSharp/Drawing/Brushes/Brushes.cs

@ -25,7 +25,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent10(Color foreColor)
=> new PatternBrush(Brushes<Color, uint>.Percent10(foreColor, Color.Transparent));
=> new PatternBrush(Brushes<Color>.Percent10(foreColor, Color.Transparent));
/// <summary>
/// Create as brush that will paint a Percent10 Hatch Pattern with
@ -35,7 +35,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent10(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color, uint>.Percent10(foreColor, backColor));
=> new PatternBrush(Brushes<Color>.Percent10(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Percent20 Hatch Pattern with
@ -44,7 +44,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent20(Color foreColor)
=> new PatternBrush(Brushes<Color, uint>.Percent20(foreColor, Color.Transparent));
=> new PatternBrush(Brushes<Color>.Percent20(foreColor, Color.Transparent));
/// <summary>
/// Create as brush that will paint a Percent20 Hatch Pattern with
@ -54,7 +54,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent20(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color, uint>.Percent20(foreColor, backColor));
=> new PatternBrush(Brushes<Color>.Percent20(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Horizontal Hatch Pattern with
@ -63,7 +63,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Horizontal(Color foreColor)
=> new PatternBrush(Brushes<Color, uint>.Horizontal(foreColor, Color.Transparent));
=> new PatternBrush(Brushes<Color>.Horizontal(foreColor, Color.Transparent));
/// <summary>
/// Create as brush that will paint a Horizontal Hatch Pattern with
@ -73,7 +73,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Horizontal(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color, uint>.Horizontal(foreColor, backColor));
=> new PatternBrush(Brushes<Color>.Horizontal(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Min Hatch Pattern with
@ -82,7 +82,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Min(Color foreColor)
=> new PatternBrush(Brushes<Color, uint>.Min(foreColor, Color.Transparent));
=> new PatternBrush(Brushes<Color>.Min(foreColor, Color.Transparent));
/// <summary>
/// Create as brush that will paint a Min Hatch Pattern with
@ -92,7 +92,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Min(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color, uint>.Min(foreColor, backColor));
=> new PatternBrush(Brushes<Color>.Min(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Vertical Hatch Pattern with
@ -101,7 +101,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Vertical(Color foreColor)
=> new PatternBrush(Brushes<Color, uint>.Vertical(foreColor, Color.Transparent));
=> new PatternBrush(Brushes<Color>.Vertical(foreColor, Color.Transparent));
/// <summary>
/// Create as brush that will paint a Vertical Hatch Pattern with
@ -111,7 +111,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Vertical(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color, uint>.Vertical(foreColor, backColor));
=> new PatternBrush(Brushes<Color>.Vertical(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with
@ -120,7 +120,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush ForwardDiagonal(Color foreColor)
=> new PatternBrush(Brushes<Color, uint>.ForwardDiagonal(foreColor, Color.Transparent));
=> new PatternBrush(Brushes<Color>.ForwardDiagonal(foreColor, Color.Transparent));
/// <summary>
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with
@ -130,7 +130,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color, uint>.ForwardDiagonal(foreColor, backColor));
=> new PatternBrush(Brushes<Color>.ForwardDiagonal(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with
@ -139,7 +139,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush BackwardDiagonal(Color foreColor)
=> new PatternBrush(Brushes<Color, uint>.BackwardDiagonal(foreColor, Color.Transparent));
=> new PatternBrush(Brushes<Color>.BackwardDiagonal(foreColor, Color.Transparent));
/// <summary>
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with
@ -149,6 +149,6 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color, uint>.BackwardDiagonal(foreColor, backColor));
=> new PatternBrush(Brushes<Color>.BackwardDiagonal(foreColor, backColor));
}
}

40
src/ImageSharp/Drawing/Brushes/Brushes{TColor,TPacked}.cs → src/ImageSharp/Drawing/Brushes/Brushes{TColor}.cs

@ -1,4 +1,4 @@
// <copyright file="Brushes{TColor,TPacked}.cs" company="James Jackson-South">
// <copyright file="Brushes{TColor}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -11,11 +11,9 @@ namespace ImageSharp.Drawing.Brushes
/// A collection of methods for creating generic brushes.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <returns>A Brush</returns>
public class Brushes<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class Brushes<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Percent10 Hatch Pattern
@ -99,8 +97,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary>
/// <param name="color">The color.</param>
/// <returns>A Brush</returns>
public static SolidBrush<TColor, TPacked> Solid(TColor color)
=> new SolidBrush<TColor, TPacked>(color);
public static SolidBrush<TColor> Solid(TColor color)
=> new SolidBrush<TColor>(color);
/// <summary>
/// Create as brush that will paint a Percent10 Hatch Pattern within the specified colors
@ -108,8 +106,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor, TPacked> Percent10(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor, TPacked>(foreColor, backColor, Percent10Pattern);
public static PatternBrush<TColor> Percent10(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, Percent10Pattern);
/// <summary>
/// Create as brush that will paint a Percent20 Hatch Pattern within the specified colors
@ -117,8 +115,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor, TPacked> Percent20(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor, TPacked>(foreColor, backColor, Percent20Pattern);
public static PatternBrush<TColor> Percent20(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, Percent20Pattern);
/// <summary>
/// Create as brush that will paint a Horizontal Hatch Pattern within the specified colors
@ -126,8 +124,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor, TPacked> Horizontal(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor, TPacked>(foreColor, backColor, HorizontalPattern);
public static PatternBrush<TColor> Horizontal(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, HorizontalPattern);
/// <summary>
/// Create as brush that will paint a Min Hatch Pattern within the specified colors
@ -135,8 +133,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor, TPacked> Min(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor, TPacked>(foreColor, backColor, MinPattern);
public static PatternBrush<TColor> Min(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, MinPattern);
/// <summary>
/// Create as brush that will paint a Vertical Hatch Pattern within the specified colors
@ -144,8 +142,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor, TPacked> Vertical(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor, TPacked>(foreColor, backColor, VerticalPattern);
public static PatternBrush<TColor> Vertical(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, VerticalPattern);
/// <summary>
/// Create as brush that will paint a Forward Diagonal Hatch Pattern within the specified colors
@ -153,8 +151,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor, TPacked> ForwardDiagonal(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor, TPacked>(foreColor, backColor, ForwardDiagonalPattern);
public static PatternBrush<TColor> ForwardDiagonal(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, ForwardDiagonalPattern);
/// <summary>
/// Create as brush that will paint a Backward Diagonal Hatch Pattern within the specified colors
@ -162,7 +160,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor, TPacked> BackwardDiagonal(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor, TPacked>(foreColor, backColor, BackwardDiagonalPattern);
public static PatternBrush<TColor> BackwardDiagonal(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, BackwardDiagonalPattern);
}
}

10
src/ImageSharp/Drawing/Brushes/IBrush.cs

@ -13,14 +13,12 @@ namespace ImageSharp.Drawing
/// Brush represents a logical configuration of a brush which can be used to source pixel colors
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <remarks>
/// A brush is a simple class that will return an <see cref="IBrushApplicator{TColor, TPacked}" /> that will perform the
/// A brush is a simple class that will return an <see cref="IBrushApplicator{TColor}" /> that will perform the
/// logic for converting a pixel location to a <typeparamref name="TColor"/>.
/// </remarks>
public interface IBrush<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public interface IBrush<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Creates the applicator for this brush.
@ -31,6 +29,6 @@ namespace ImageSharp.Drawing
/// The <paramref name="region" /> when being applied to things like shapes would usually be the
/// bounding box of the shape not necessarily the bounds of the whole image
/// </remarks>
IBrushApplicator<TColor, TPacked> CreateApplicator(RectangleF region);
IBrushApplicator<TColor> CreateApplicator(RectangleF region);
}
}

4
src/ImageSharp/Drawing/Brushes/ImageBrush.cs

@ -8,13 +8,13 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// Provides an implementation of a solid brush for painting with repeating images. The brush uses <see cref="Color"/> for painting.
/// </summary>
public class ImageBrush : ImageBrush<Color, uint>
public class ImageBrush : ImageBrush<Color>
{
/// <summary>
/// Initializes a new instance of the <see cref="ImageBrush" /> class.
/// </summary>
/// <param name="image">The image to paint.</param>
public ImageBrush(IImageBase<Color, uint> image)
public ImageBrush(IImageBase<Color> image)
: base(image)
{
}

22
src/ImageSharp/Drawing/Brushes/ImageBrush{TColor,TPacked}.cs → src/ImageSharp/Drawing/Brushes/ImageBrush{TColor}.cs

@ -1,4 +1,4 @@
// <copyright file="ImageBrush{TColor,TPacked}.cs" company="James Jackson-South">
// <copyright file="ImageBrush{TColor}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -14,27 +14,25 @@ namespace ImageSharp.Drawing.Brushes
/// Provides an implementation of an image brush for painting images within areas.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class ImageBrush<TColor, TPacked> : IBrush<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class ImageBrush<TColor> : IBrush<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The image to paint.
/// </summary>
private readonly IImageBase<TColor, TPacked> image;
private readonly IImageBase<TColor> image;
/// <summary>
/// Initializes a new instance of the <see cref="ImageBrush{TColor,TPacked}"/> class.
/// Initializes a new instance of the <see cref="ImageBrush{TColor}"/> class.
/// </summary>
/// <param name="image">The image.</param>
public ImageBrush(IImageBase<TColor, TPacked> image)
public ImageBrush(IImageBase<TColor> image)
{
this.image = image;
}
/// <inheritdoc />
public IBrushApplicator<TColor, TPacked> CreateApplicator(RectangleF region)
public IBrushApplicator<TColor> CreateApplicator(RectangleF region)
{
return new ImageBrushApplicator(this.image, region);
}
@ -42,12 +40,12 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// The image brush applicator.
/// </summary>
private class ImageBrushApplicator : IBrushApplicator<TColor, TPacked>
private class ImageBrushApplicator : IBrushApplicator<TColor>
{
/// <summary>
/// The source pixel accessor.
/// </summary>
private readonly PixelAccessor<TColor, TPacked> source;
private readonly PixelAccessor<TColor> source;
/// <summary>
/// The y-length.
@ -73,7 +71,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="region">
/// The region.
/// </param>
public ImageBrushApplicator(IImageBase<TColor, TPacked> image, RectangleF region)
public ImageBrushApplicator(IImageBase<TColor> image, RectangleF region)
{
this.source = image.Lock();
this.xLength = image.Width;

4
src/ImageSharp/Drawing/Brushes/PatternBrush.cs

@ -8,7 +8,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// Provides an implementation of a pattern brush for painting patterns. The brush use <see cref="Color"/> for painting.
/// </summary>
public class PatternBrush : PatternBrush<Color, uint>
public class PatternBrush : PatternBrush<Color>
{
/// <summary>
/// Initializes a new instance of the <see cref="PatternBrush"/> class.
@ -25,7 +25,7 @@ namespace ImageSharp.Drawing.Brushes
/// Initializes a new instance of the <see cref="PatternBrush"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
internal PatternBrush(PatternBrush<Color, uint> brush)
internal PatternBrush(PatternBrush<Color> brush)
: base(brush)
{
}

18
src/ImageSharp/Drawing/Brushes/PatternBrush{TColor,TPacked}.cs → src/ImageSharp/Drawing/Brushes/PatternBrush{TColor}.cs

@ -1,4 +1,4 @@
// <copyright file="PatternBrush{TColor,TPacked}.cs" company="James Jackson-South">
// <copyright file="PatternBrush{TColor}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -41,10 +41,8 @@ namespace ImageSharp.Drawing.Brushes
/// 00
/// </remarks>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class PatternBrush<TColor, TPacked> : IBrush<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class PatternBrush<TColor> : IBrush<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The pattern.
@ -57,7 +55,7 @@ namespace ImageSharp.Drawing.Brushes
private readonly int stride;
/// <summary>
/// Initializes a new instance of the <see cref="PatternBrush{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="PatternBrush{TColor}"/> class.
/// </summary>
/// <param name="foreColor">Color of the fore.</param>
/// <param name="backColor">Color of the back.</param>
@ -87,17 +85,17 @@ namespace ImageSharp.Drawing.Brushes
}
/// <summary>
/// Initializes a new instance of the <see cref="PatternBrush{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="PatternBrush{TColor}"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
internal PatternBrush(PatternBrush<TColor, TPacked> brush)
internal PatternBrush(PatternBrush<TColor> brush)
{
this.pattern = brush.pattern;
this.stride = brush.stride;
}
/// <inheritdoc />
public IBrushApplicator<TColor, TPacked> CreateApplicator(RectangleF region)
public IBrushApplicator<TColor> CreateApplicator(RectangleF region)
{
return new PatternBrushApplicator(this.pattern, this.stride);
}
@ -105,7 +103,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// The pattern brush applicator.
/// </summary>
private class PatternBrushApplicator : IBrushApplicator<TColor, TPacked>
private class PatternBrushApplicator : IBrushApplicator<TColor>
{
/// <summary>
/// The patter x-length.

6
src/ImageSharp/Drawing/Brushes/Processors/IBrushApplicator.cs

@ -12,11 +12,9 @@ namespace ImageSharp.Drawing.Processors
/// primitive that converts a point in to a color for discovering the fill color based on an implementation
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <seealso cref="System.IDisposable" />
public interface IBrushApplicator<TColor, TPacked> : IDisposable // disposable will be required if/when there is an ImageBrush
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public interface IBrushApplicator<TColor> : IDisposable // disposable will be required if/when there is an ImageBrush
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Gets the color for a single pixel.

2
src/ImageSharp/Drawing/Brushes/SolidBrush.cs

@ -8,7 +8,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// Provides an implementation of a solid brush for painting solid color areas. The brush uses <see cref="Color"/> for painting.
/// </summary>
public class SolidBrush : SolidBrush<Color, uint>
public class SolidBrush : SolidBrush<Color>
{
/// <summary>
/// Initializes a new instance of the <see cref="SolidBrush" /> class.

14
src/ImageSharp/Drawing/Brushes/SolidBrush{TColor,TPacked}.cs → src/ImageSharp/Drawing/Brushes/SolidBrush{TColor}.cs

@ -1,4 +1,4 @@
// <copyright file="SolidBrush{TColor,TPacked}.cs" company="James Jackson-South">
// <copyright file="SolidBrush{TColor}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -14,10 +14,8 @@ namespace ImageSharp.Drawing.Brushes
/// Provides an implementation of a solid brush for painting solid color areas.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class SolidBrush<TColor, TPacked> : IBrush<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class SolidBrush<TColor> : IBrush<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The color to paint.
@ -25,7 +23,7 @@ namespace ImageSharp.Drawing.Brushes
private readonly TColor color;
/// <summary>
/// Initializes a new instance of the <see cref="SolidBrush{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="SolidBrush{TColor}"/> class.
/// </summary>
/// <param name="color">The color.</param>
public SolidBrush(TColor color)
@ -42,7 +40,7 @@ namespace ImageSharp.Drawing.Brushes
public TColor Color => this.color;
/// <inheritdoc />
public IBrushApplicator<TColor, TPacked> CreateApplicator(RectangleF region)
public IBrushApplicator<TColor> CreateApplicator(RectangleF region)
{
return new SolidBrushApplicator(this.color);
}
@ -50,7 +48,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// The solid brush applicator.
/// </summary>
private class SolidBrushApplicator : IBrushApplicator<TColor, TPacked>
private class SolidBrushApplicator : IBrushApplicator<TColor>
{
/// <summary>
/// The solid color.

228
src/ImageSharp/Drawing/Draw.cs

@ -15,7 +15,7 @@ namespace ImageSharp
using Drawing.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -23,7 +23,6 @@ namespace ImageSharp
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param>
@ -31,25 +30,22 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(new DrawPathProcessor<TColor, TPacked>(pen, shape, options));
return source.Process(new DrawPathProcessor<TColor>(pen, shape, options));
}
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, IShape shape)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(pen, shape, GraphicsOptions.Default);
}
@ -58,7 +54,6 @@ namespace ImageSharp
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
@ -67,35 +62,31 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new Pen<TColor, TPacked>(brush, thickness), shape, options);
return source.DrawPolygon(new Pen<TColor>(brush, thickness), shape, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, IShape shape)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new Pen<TColor, TPacked>(brush, thickness), shape);
return source.DrawPolygon(new Pen<TColor>(brush, thickness), shape);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
@ -104,35 +95,31 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor, TPacked>(color), thickness, shape, options);
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, shape, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, IShape shape)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor, TPacked>(color), thickness, shape);
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, shape);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
@ -141,52 +128,46 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new Pen<TColor, TPacked>(brush, thickness), new Polygon(new LinearLineSegment(points)), options);
return source.DrawPolygon(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new Pen<TColor, TPacked>(brush, thickness), new Polygon(new LinearLineSegment(points)));
return source.DrawPolygon(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points)));
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor, TPacked>(color), thickness, points);
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
@ -195,18 +176,16 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor, TPacked>(color), thickness, points, options);
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points, options);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
@ -214,9 +193,8 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points)), options);
}
@ -225,14 +203,12 @@ namespace ImageSharp
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, Vector2[] points)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points)));
}
@ -241,7 +217,6 @@ namespace ImageSharp
/// Draws the path with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="path">The path.</param>
@ -249,34 +224,30 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPath<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(new DrawPathProcessor<TColor, TPacked>(pen, path, options));
return source.Process(new DrawPathProcessor<TColor>(pen, path, options));
}
/// <summary>
/// Draws the path with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPath<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, IPath path)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(new DrawPathProcessor<TColor, TPacked>(pen, path, GraphicsOptions.Default));
return source.Process(new DrawPathProcessor<TColor>(pen, path, GraphicsOptions.Default));
}
/// <summary>
/// Draws the path with the bursh at the privdied thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
@ -285,35 +256,31 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPath<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor, TPacked>(brush, thickness), path, options);
return source.DrawPath(new Pen<TColor>(brush, thickness), path, options);
}
/// <summary>
/// Draws the path with the bursh at the privdied thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPath<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, IPath path)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor, TPacked>(brush, thickness), path);
return source.DrawPath(new Pen<TColor>(brush, thickness), path);
}
/// <summary>
/// Draws the path with the bursh at the privdied thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
@ -322,35 +289,31 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPath<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new SolidBrush<TColor, TPacked>(color), thickness, path, options);
return source.DrawPath(new SolidBrush<TColor>(color), thickness, path, options);
}
/// <summary>
/// Draws the path with the bursh at the privdied thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPath<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, IPath path)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new SolidBrush<TColor, TPacked>(color), thickness, path);
return source.DrawPath(new SolidBrush<TColor>(color), thickness, path);
}
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
@ -359,52 +322,46 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawLines<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor, TPacked>(brush, thickness), new Path(new LinearLineSegment(points)), options);
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawLines<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor, TPacked>(brush, thickness), new Path(new LinearLineSegment(points)));
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points)));
}
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawLines<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawLines(new SolidBrush<TColor, TPacked>(color), thickness, points);
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points);
}
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
@ -413,18 +370,16 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawLines<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawLines(new SolidBrush<TColor, TPacked>(color), thickness, points, options);
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points, options);
}
/// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
@ -432,9 +387,8 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawLines<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(pen, new Path(new LinearLineSegment(points)), options);
}
@ -443,14 +397,12 @@ namespace ImageSharp
/// Draws the provided Points as an open Linear path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawLines<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, Vector2[] points)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(pen, new Path(new LinearLineSegment(points)));
}
@ -459,7 +411,6 @@ namespace ImageSharp
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
@ -468,52 +419,46 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawBeziers<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor, TPacked>(brush, thickness), new Path(new BezierLineSegment(points)), options);
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawBeziers<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor, TPacked>(brush, thickness), new Path(new BezierLineSegment(points)));
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points)));
}
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawBeziers<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawBeziers(new SolidBrush<TColor, TPacked>(color), thickness, points);
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points);
}
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
@ -522,18 +467,16 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawBeziers<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawBeziers(new SolidBrush<TColor, TPacked>(color), thickness, points, options);
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points, options);
}
/// <summary>
/// Draws the provided Points as an open Bezier path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
@ -541,9 +484,8 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawBeziers<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(pen, new Path(new BezierLineSegment(points)), options);
}
@ -552,14 +494,12 @@ namespace ImageSharp
/// Draws the provided Points as an open Bezier path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawBeziers<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, Vector2[] points)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(pen, new Path(new BezierLineSegment(points)));
}

18
src/ImageSharp/Drawing/DrawImage.cs

@ -18,14 +18,12 @@ namespace ImageSharp
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Blend<TColor, TPacked>(this Image<TColor, TPacked> source, Image<TColor, TPacked> image, int percent = 50)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Blend<TColor>(this Image<TColor> source, Image<TColor> image, int percent = 50)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return DrawImage(source, image, percent, default(Size), default(Point));
}
@ -36,14 +34,12 @@ namespace ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
/// <param name="size">The size to draw the blended image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> DrawImage<TColor, TPacked>(this Image<TColor, TPacked> source, Image<TColor, TPacked> image, int percent, Size size, Point location)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DrawImage<TColor>(this Image<TColor> source, Image<TColor> image, int percent, Size size, Point location)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
if (size == default(Size))
{
@ -55,7 +51,7 @@ namespace ImageSharp
location = Point.Empty;
}
return source.Process(source.Bounds, new DrawImageProcessor<TColor, TPacked>(image, size, location, percent));
return source.Process(source.Bounds, new DrawImageProcessor<TColor>(image, size, location, percent));
}
}
}

53
src/ImageSharp/Drawing/Draw_Rectangle.cs → src/ImageSharp/Drawing/DrawRectangle.cs

@ -1,4 +1,4 @@
// <copyright file="Draw_Rectangle.cs" company="James Jackson-South">
// <copyright file="DrawRectangle.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -6,17 +6,16 @@
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Paths;
using Drawing.Pens;
using Drawing.Processors;
using Drawing.Shapes;
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -24,7 +23,6 @@ namespace ImageSharp
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param>
@ -32,25 +30,22 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, RectangleF shape, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, RectangleF shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(new DrawPathProcessor<TColor, TPacked>(pen, (IPath)new RectangularPolygon(shape), options));
return source.Process(new DrawPathProcessor<TColor>(pen, (IPath)new RectangularPolygon(shape), options));
}
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IPen<TColor, TPacked> pen, RectangleF shape)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, RectangleF shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(pen, shape, GraphicsOptions.Default);
}
@ -59,7 +54,6 @@ namespace ImageSharp
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
@ -68,35 +62,31 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, RectangleF shape, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, RectangleF shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new Pen<TColor, TPacked>(brush, thickness), shape, options);
return source.DrawPolygon(new Pen<TColor>(brush, thickness), shape, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, float thickness, RectangleF shape)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, RectangleF shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new Pen<TColor, TPacked>(brush, thickness), shape);
return source.DrawPolygon(new Pen<TColor>(brush, thickness), shape);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
@ -105,28 +95,25 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, RectangleF shape, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, RectangleF shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor, TPacked>(color), thickness, shape, options);
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, shape, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> DrawPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float thickness, RectangleF shape)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, RectangleF shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor, TPacked>(color), thickness, shape);
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, shape);
}
}
}

80
src/ImageSharp/Drawing/Fill.cs

@ -14,7 +14,7 @@ namespace ImageSharp
using Drawing.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -22,70 +22,61 @@ namespace ImageSharp
/// Flood fills the image with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> Fill<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(new FillProcessor<TColor, TPacked>(brush));
return source.Process(new FillProcessor<TColor>(brush));
}
/// <summary>
/// Flood fills the image with the specified color.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> Fill<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor, TPacked>(color));
return source.Fill(new SolidBrush<TColor>(color));
}
/// <summary>
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> Fill<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(new FillShapeProcessor<TColor, TPacked>(brush, shape, options));
return source.Process(new FillShapeProcessor<TColor>(brush, shape, options));
}
/// <summary>
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> Fill<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, IShape shape)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(new FillShapeProcessor<TColor, TPacked>(brush, shape, GraphicsOptions.Default));
return source.Process(new FillShapeProcessor<TColor>(brush, shape, GraphicsOptions.Default));
}
/// <summary>
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
@ -93,34 +84,30 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> Fill<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor, TPacked>(color), shape, options);
return source.Fill(new SolidBrush<TColor>(color), shape, options);
}
/// <summary>
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> Fill<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, IShape shape)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor, TPacked>(color), shape);
return source.Fill(new SolidBrush<TColor>(color), shape);
}
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="points">The points.</param>
@ -128,9 +115,8 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> FillPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
// using Polygon directly instead of LinearPolygon as its will have less indirection
return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options);
@ -140,14 +126,12 @@ namespace ImageSharp
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> FillPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, Vector2[] points)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
// using Polygon directly instead of LinearPolygon as its will have less indirection
return source.Fill(brush, new Polygon(new LinearLineSegment(points)));
@ -157,7 +141,6 @@ namespace ImageSharp
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="points">The points.</param>
@ -165,29 +148,26 @@ namespace ImageSharp
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> FillPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
// using Polygon directly instead of LinearPolygon as its will have less indirection
return source.Fill(new SolidBrush<TColor, TPacked>(color), new Polygon(new LinearLineSegment(points)), options);
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points)), options);
}
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> FillPolygon<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, Vector2[] points)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
// using Polygon directly instead of LinearPolygon as its will have less indirection
return source.Fill(new SolidBrush<TColor, TPacked>(color), new Polygon(new LinearLineSegment(points)));
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points)));
}
}
}

82
src/ImageSharp/Drawing/FillRectangle.cs

@ -0,0 +1,82 @@
// <copyright file="FillRectangle.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;
using Drawing.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, RectangleF shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(new FillShapeProcessor<TColor>(brush, new RectangularPolygon(shape), options));
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, RectangleF shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(new FillShapeProcessor<TColor>(brush, new RectangularPolygon(shape), GraphicsOptions.Default));
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, RectangleF shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), shape, options);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, RectangleF shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), shape);
}
}
}

92
src/ImageSharp/Drawing/Fill_Rectangle.cs

@ -1,92 +0,0 @@
// <copyright file="Fill_Rectangle.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Paths;
using Drawing.Processors;
using Drawing.Shapes;
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> Fill<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, RectangleF shape, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
{
return source.Process(new FillShapeProcessor<TColor, TPacked>(brush, new RectangularPolygon(shape), options));
}
/// <summary>
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> Fill<TColor, TPacked>(this Image<TColor, TPacked> source, IBrush<TColor, TPacked> brush, RectangleF shape)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
{
return source.Process(new FillShapeProcessor<TColor, TPacked>(brush, new RectangularPolygon(shape), GraphicsOptions.Default));
}
/// <summary>
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor, TPacked> Fill<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, RectangleF shape, GraphicsOptions options)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
{
return source.Fill(new SolidBrush<TColor, TPacked>(color), shape, options);
}
/// <summary>
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor, TPacked> Fill<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, RectangleF shape)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
{
return source.Fill(new SolidBrush<TColor, TPacked>(color), shape);
}
}
}

13
src/ImageSharp/Drawing/Pens/IPen.cs

@ -9,13 +9,11 @@ namespace ImageSharp.Drawing.Pens
using Processors;
/// <summary>
/// interface preresenting a Pen
/// Interface representing a Pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
public interface IPen<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public interface IPen<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Creates the applicator for applying this pen to an Image
@ -23,9 +21,8 @@ namespace ImageSharp.Drawing.Pens
/// <param name="region">The region the pen will be applied to.</param>
/// <returns>Returns a the applicator for the pen.</returns>
/// <remarks>
/// The <paramref name="region" /> when being applied to things like shapes would ussually be the
/// bounding box of the shape not necorserrally the shape of the whole image
/// The <paramref name="region" /> when being applied to things like shapes would usually be the bounding box of the shape not necessarily the shape of the whole image.
/// </remarks>
IPenApplicator<TColor, TPacked> CreateApplicator(RectangleF region);
IPenApplicator<TColor> CreateApplicator(RectangleF region);
}
}

272
src/ImageSharp/Drawing/Pens/Pen.cs

@ -5,18 +5,10 @@
namespace ImageSharp.Drawing.Pens
{
using System;
using System.Numerics;
using Brushes;
using Drawing.Processors;
using Paths;
using Processors;
/// <summary>
/// Represenets a <see cref="Pen{TColor, TPacked}"/> in the <see cref="Color"/> color space.
/// Represents a <see cref="Pen{TColor}"/> in the <see cref="Color"/> color space.
/// </summary>
public partial class Pen : Pen<Color, uint>
public class Pen : Pen<Color>
{
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
@ -33,7 +25,7 @@ namespace ImageSharp.Drawing.Pens
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
public Pen(IBrush<Color, uint> brush, float width)
public Pen(IBrush<Color> brush, float width)
: base(brush, width)
{
}
@ -44,7 +36,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <param name="pattern">The pattern.</param>
public Pen(IBrush<Color, uint> brush, float width, float[] pattern)
public Pen(IBrush<Color> brush, float width, float[] pattern)
: base(brush, width, pattern)
{
}
@ -53,263 +45,9 @@ namespace ImageSharp.Drawing.Pens
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
/// <param name="pen">The pen.</param>
internal Pen(Pen<Color, uint> pen)
internal Pen(Pen<Color> pen)
: base(pen)
{
}
}
/// <summary>
/// Provides a pen that can apply a pattern to a line with a set brush and thickness
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <remarks>
/// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be
/// converted into a pattern that is 3.5 times longer that the width with 3 sections
/// section 1 will be width long (making a square) and will be filled by the brush
/// section 2 will be width * 2 long and will be empty
/// section 3 will be width/2 long and will be filled
/// the the pattern will imidiatly repeat without gap.
/// </remarks>
public class Pen<TColor, TPacked> : IPen<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
{
private static readonly float[] EmptyPattern = new float[0];
private readonly float[] pattern;
/// <summary>
/// Initializes a new instance of the <see cref="Pen{TColor, TPacked}"/> class.
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <param name="pattern">The pattern.</param>
public Pen(TColor color, float width, float[] pattern)
: this(new SolidBrush<TColor, TPacked>(color), width, pattern)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Pen{TColor, TPacked}"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <param name="pattern">The pattern.</param>
public Pen(IBrush<TColor, TPacked> brush, float width, float[] pattern)
{
this.Brush = brush;
this.Width = width;
this.pattern = pattern;
}
/// <summary>
/// Initializes a new instance of the <see cref="Pen{TColor, TPacked}"/> class.
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
public Pen(TColor color, float width)
: this(new SolidBrush<TColor, TPacked>(color), width)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Pen{TColor, TPacked}"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
public Pen(IBrush<TColor, TPacked> brush, float width)
: this(brush, width, EmptyPattern)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Pen{TColor, TPacked}"/> class.
/// </summary>
/// <param name="pen">The pen.</param>
internal Pen(Pen<TColor, TPacked> pen)
: this(pen.Brush, pen.Width, pen.pattern)
{
}
/// <summary>
/// Gets the brush.
/// </summary>
/// <value>
/// The brush.
/// </value>
public IBrush<TColor, TPacked> Brush { get; }
/// <summary>
/// Gets the width.
/// </summary>
/// <value>
/// The width.
/// </value>
public float Width { get; }
/// <summary>
/// Creates the applicator for applying this pen to an Image
/// </summary>
/// <param name="region">The region the pen will be applied to.</param>
/// <returns>
/// Returns a the applicator for the pen.
/// </returns>
/// <remarks>
/// The <paramref name="region" /> when being applied to things like shapes would ussually be the
/// bounding box of the shape not necorserrally the shape of the whole image
/// </remarks>
public IPenApplicator<TColor, TPacked> CreateApplicator(RectangleF region)
{
if (this.pattern == null || this.pattern.Length < 2)
{
// if there is only one item in the pattern then 100% of it will
// be solid so use the quicker applicator
return new SolidPenApplicator(this.Brush, region, this.Width);
}
return new PatternPenApplicator(this.Brush, region, this.Width, this.pattern);
}
private class SolidPenApplicator : IPenApplicator<TColor, TPacked>
{
private readonly IBrushApplicator<TColor, TPacked> brush;
private readonly float halfWidth;
public SolidPenApplicator(IBrush<TColor, TPacked> brush, RectangleF region, float width)
{
this.brush = brush.CreateApplicator(region);
this.halfWidth = width / 2;
this.RequiredRegion = RectangleF.Outset(region, width);
}
public RectangleF RequiredRegion
{
get;
}
public void Dispose()
{
this.brush.Dispose();
}
public ColoredPointInfo<TColor, TPacked> GetColor(PointInfo info)
{
var result = default(ColoredPointInfo<TColor, TPacked>);
result.Color = this.brush.GetColor(info.SearchPoint);
if (info.DistanceFromPath < this.halfWidth)
{
// inside strip
result.DistanceFromElement = 0;
}
else
{
result.DistanceFromElement = info.DistanceFromPath - this.halfWidth;
}
return result;
}
}
private class PatternPenApplicator : IPenApplicator<TColor, TPacked>
{
private readonly IBrushApplicator<TColor, TPacked> brush;
private readonly float halfWidth;
private readonly float[] pattern;
private readonly float totalLength;
public PatternPenApplicator(IBrush<TColor, TPacked> brush, RectangleF region, float width, float[] pattern)
{
this.brush = brush.CreateApplicator(region);
this.halfWidth = width / 2;
this.totalLength = 0;
this.pattern = new float[pattern.Length + 1];
this.pattern[0] = 0;
for (var i = 0; i < pattern.Length; i++)
{
this.totalLength += pattern[i] * width;
this.pattern[i + 1] = this.totalLength;
}
this.RequiredRegion = RectangleF.Outset(region, width);
}
public RectangleF RequiredRegion
{
get;
}
public void Dispose()
{
this.brush.Dispose();
}
public ColoredPointInfo<TColor, TPacked> GetColor(PointInfo info)
{
var infoResult = default(ColoredPointInfo<TColor, TPacked>);
infoResult.DistanceFromElement = float.MaxValue; // is really outside the element
var length = info.DistanceAlongPath % this.totalLength;
// we can treat the DistanceAlongPath and DistanceFromPath as x,y coords for the pattern
// we need to calcualte the distance from the outside edge of the pattern
// and set them on the ColoredPointInfo<TColor, TPacked> along with the color.
infoResult.Color = this.brush.GetColor(info.SearchPoint);
float distanceWAway = 0;
if (info.DistanceFromPath < this.halfWidth)
{
// inside strip
distanceWAway = 0;
}
else
{
distanceWAway = info.DistanceFromPath - this.halfWidth;
}
for (var i = 0; i < this.pattern.Length - 1; i++)
{
var start = this.pattern[i];
var end = this.pattern[i + 1];
if (length >= start && length < end)
{
// in section
if (i % 2 == 0)
{
// solid part return the maxDistance
infoResult.DistanceFromElement = distanceWAway;
return infoResult;
}
else
{
// this is a none solid part
var distanceFromStart = length - start;
var distanceFromEnd = end - length;
var closestEdge = Math.Min(distanceFromStart, distanceFromEnd);
var distanceAcross = closestEdge;
if (distanceWAway > 0)
{
infoResult.DistanceFromElement = new Vector2(distanceAcross, distanceWAway).Length();
}
else
{
infoResult.DistanceFromElement = closestEdge;
}
return infoResult;
}
}
}
return infoResult;
}
}
}
}

141
src/ImageSharp/Drawing/Pens/Pens.cs

@ -5,12 +5,10 @@
namespace ImageSharp.Drawing.Pens
{
using System;
/// <summary>
/// Common Pen styles
/// </summary>
public partial class Pens
public class Pens
{
/// <summary>
/// Create a solid pen with out any drawing patterns
@ -18,113 +16,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen Solid(Color color, float width)
=> new Pen(color, width);
/// <summary>
/// Create a solid pen with out any drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen Solid(IBrush<Color, uint> brush, float width)
=> new Pen(brush, width);
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen Dash(Color color, float width)
=> new Pen(Pens<Color, uint>.Dash(color, width));
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen Dash(IBrush<Color, uint> brush, float width)
=> new Pen(Pens<Color, uint>.Dash(brush, width));
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen Dot(Color color, float width)
=> new Pen(Pens<Color, uint>.Dot(color, width));
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen Dot(IBrush<Color, uint> brush, float width)
=> new Pen(Pens<Color, uint>.Dot(brush, width));
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen DashDot(Color color, float width)
=> new Pen(Pens<Color, uint>.DashDot(color, width));
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen DashDot(IBrush<Color, uint> brush, float width)
=> new Pen(Pens<Color, uint>.DashDot(brush, width));
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen DashDotDot(Color color, float width)
=> new Pen(Pens<Color, uint>.DashDotDot(color, width));
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen DashDotDot(IBrush<Color, uint> brush, float width)
=> new Pen(Pens<Color, uint>.DashDotDot(brush, width));
}
/// <summary>
/// Common Pen styles
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
public partial class Pens<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
{
private static readonly float[] DashDotPattern = new[] { 3f, 1f, 1f, 1f };
private static readonly float[] DashDotDotPattern = new[] { 3f, 1f, 1f, 1f, 1f, 1f };
private static readonly float[] DottedPattern = new[] { 1f, 1f };
private static readonly float[] DashedPattern = new[] { 3f, 1f };
/// <summary>
/// Create a solid pen with out any drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor, TPacked> Solid(TColor color, float width)
=> new Pen<TColor, TPacked>(color, width);
public static Pen Solid(Color color, float width) => new Pen(color, width);
/// <summary>
/// Create a solid pen with out any drawing patterns
@ -132,8 +24,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor, TPacked> Solid(IBrush<TColor, TPacked> brush, float width)
=> new Pen<TColor, TPacked>(brush, width);
public static Pen Solid(IBrush<Color> brush, float width) => new Pen(brush, width);
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
@ -141,8 +32,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor, TPacked> Dash(TColor color, float width)
=> new Pen<TColor, TPacked>(color, width, DashedPattern);
public static Pen Dash(Color color, float width) => new Pen(Pens<Color>.Dash(color, width));
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
@ -150,8 +40,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor, TPacked> Dash(IBrush<TColor, TPacked> brush, float width)
=> new Pen<TColor, TPacked>(brush, width, DashedPattern);
public static Pen Dash(IBrush<Color> brush, float width) => new Pen(Pens<Color>.Dash(brush, width));
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
@ -159,8 +48,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor, TPacked> Dot(TColor color, float width)
=> new Pen<TColor, TPacked>(color, width, DottedPattern);
public static Pen Dot(Color color, float width) => new Pen(Pens<Color>.Dot(color, width));
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
@ -168,8 +56,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor, TPacked> Dot(IBrush<TColor, TPacked> brush, float width)
=> new Pen<TColor, TPacked>(brush, width, DottedPattern);
public static Pen Dot(IBrush<Color> brush, float width) => new Pen(Pens<Color>.Dot(brush, width));
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
@ -177,8 +64,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor, TPacked> DashDot(TColor color, float width)
=> new Pen<TColor, TPacked>(color, width, DashDotPattern);
public static Pen DashDot(Color color, float width) => new Pen(Pens<Color>.DashDot(color, width));
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
@ -186,8 +72,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor, TPacked> DashDot(IBrush<TColor, TPacked> brush, float width)
=> new Pen<TColor, TPacked>(brush, width, DashDotPattern);
public static Pen DashDot(IBrush<Color> brush, float width) => new Pen(Pens<Color>.DashDot(brush, width));
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
@ -195,8 +80,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor, TPacked> DashDotDot(TColor color, float width)
=> new Pen<TColor, TPacked>(color, width, DashDotDotPattern);
public static Pen DashDotDot(Color color, float width) => new Pen(Pens<Color>.DashDotDot(color, width));
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
@ -204,7 +88,6 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor, TPacked> DashDotDot(IBrush<TColor, TPacked> brush, float width)
=> new Pen<TColor, TPacked>(brush, width, DashDotDotPattern);
public static Pen DashDotDot(IBrush<Color> brush, float width) => new Pen(Pens<Color>.DashDotDot(brush, width));
}
}
}

112
src/ImageSharp/Drawing/Pens/Pens{TColor}.cs

@ -0,0 +1,112 @@
// <copyright file="Pens{TColor}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Pens
{
using System;
/// <summary>
/// Common Pen styles
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
public class Pens<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
private static readonly float[] DashDotPattern = new[] { 3f, 1f, 1f, 1f };
private static readonly float[] DashDotDotPattern = new[] { 3f, 1f, 1f, 1f, 1f, 1f };
private static readonly float[] DottedPattern = new[] { 1f, 1f };
private static readonly float[] DashedPattern = new[] { 3f, 1f };
/// <summary>
/// Create a solid pen with out any drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Solid(TColor color, float width)
=> new Pen<TColor>(color, width);
/// <summary>
/// Create a solid pen with out any drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Solid(IBrush<TColor> brush, float width)
=> new Pen<TColor>(brush, width);
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Dash(TColor color, float width)
=> new Pen<TColor>(color, width, DashedPattern);
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Dash(IBrush<TColor> brush, float width)
=> new Pen<TColor>(brush, width, DashedPattern);
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Dot(TColor color, float width)
=> new Pen<TColor>(color, width, DottedPattern);
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Dot(IBrush<TColor> brush, float width)
=> new Pen<TColor>(brush, width, DottedPattern);
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> DashDot(TColor color, float width)
=> new Pen<TColor>(color, width, DashDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> DashDot(IBrush<TColor> brush, float width)
=> new Pen<TColor>(brush, width, DashDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> DashDotDot(TColor color, float width)
=> new Pen<TColor>(color, width, DashDotDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> DashDotDot(IBrush<TColor> brush, float width)
=> new Pen<TColor>(brush, width, DashDotDotPattern);
}
}

267
src/ImageSharp/Drawing/Pens/Pen{TColor}.cs

@ -0,0 +1,267 @@
// <copyright file="Pen{TColor}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Pens
{
using System;
using System.Numerics;
using ImageSharp.Drawing.Brushes;
using ImageSharp.Drawing.Paths;
using ImageSharp.Drawing.Pens.Processors;
using ImageSharp.Drawing.Processors;
/// <summary>
/// Provides a pen that can apply a pattern to a line with a set brush and thickness
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <remarks>
/// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be
/// converted into a pattern that is 3.5 times longer that the width with 3 sections
/// section 1 will be width long (making a square) and will be filled by the brush
/// section 2 will be width * 2 long and will be empty
/// section 3 will be width/2 long and will be filled
/// the the pattern will imidiatly repeat without gap.
/// </remarks>
public class Pen<TColor> : IPen<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
private static readonly float[] EmptyPattern = new float[0];
private readonly float[] pattern;
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TColor}"/> class.
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <param name="pattern">The pattern.</param>
public Pen(TColor color, float width, float[] pattern)
: this(new SolidBrush<TColor>(color), width, pattern)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TColor}"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <param name="pattern">The pattern.</param>
public Pen(IBrush<TColor> brush, float width, float[] pattern)
{
this.Brush = brush;
this.Width = width;
this.pattern = pattern;
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TColor}"/> class.
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
public Pen(TColor color, float width)
: this(new SolidBrush<TColor>(color), width)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TColor}"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
public Pen(IBrush<TColor> brush, float width)
: this(brush, width, EmptyPattern)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TColor}"/> class.
/// </summary>
/// <param name="pen">The pen.</param>
internal Pen(Pen<TColor> pen)
: this(pen.Brush, pen.Width, pen.pattern)
{
}
/// <summary>
/// Gets the brush.
/// </summary>
/// <value>
/// The brush.
/// </value>
public IBrush<TColor> Brush { get; }
/// <summary>
/// Gets the width.
/// </summary>
/// <value>
/// The width.
/// </value>
public float Width { get; }
/// <summary>
/// Creates the applicator for applying this pen to an Image
/// </summary>
/// <param name="region">The region the pen will be applied to.</param>
/// <returns>
/// Returns a the applicator for the pen.
/// </returns>
/// <remarks>
/// The <paramref name="region" /> when being applied to things like shapes would ussually be the
/// bounding box of the shape not necorserrally the shape of the whole image
/// </remarks>
public IPenApplicator<TColor> CreateApplicator(RectangleF region)
{
if (this.pattern == null || this.pattern.Length < 2)
{
// if there is only one item in the pattern then 100% of it will
// be solid so use the quicker applicator
return new SolidPenApplicator(this.Brush, region, this.Width);
}
return new PatternPenApplicator(this.Brush, region, this.Width, this.pattern);
}
private class SolidPenApplicator : IPenApplicator<TColor>
{
private readonly IBrushApplicator<TColor> brush;
private readonly float halfWidth;
public SolidPenApplicator(IBrush<TColor> brush, RectangleF region, float width)
{
this.brush = brush.CreateApplicator(region);
this.halfWidth = width / 2;
this.RequiredRegion = RectangleF.Outset(region, width);
}
public RectangleF RequiredRegion
{
get;
}
public void Dispose()
{
this.brush.Dispose();
}
public ColoredPointInfo<TColor> GetColor(PointInfo info)
{
var result = default(ColoredPointInfo<TColor>);
result.Color = this.brush.GetColor(info.SearchPoint);
if (info.DistanceFromPath < this.halfWidth)
{
// inside strip
result.DistanceFromElement = 0;
}
else
{
result.DistanceFromElement = info.DistanceFromPath - this.halfWidth;
}
return result;
}
}
private class PatternPenApplicator : IPenApplicator<TColor>
{
private readonly IBrushApplicator<TColor> brush;
private readonly float halfWidth;
private readonly float[] pattern;
private readonly float totalLength;
public PatternPenApplicator(IBrush<TColor> brush, RectangleF region, float width, float[] pattern)
{
this.brush = brush.CreateApplicator(region);
this.halfWidth = width / 2;
this.totalLength = 0;
this.pattern = new float[pattern.Length + 1];
this.pattern[0] = 0;
for (var i = 0; i < pattern.Length; i++)
{
this.totalLength += pattern[i] * width;
this.pattern[i + 1] = this.totalLength;
}
this.RequiredRegion = RectangleF.Outset(region, width);
}
public RectangleF RequiredRegion
{
get;
}
public void Dispose()
{
this.brush.Dispose();
}
public ColoredPointInfo<TColor> GetColor(PointInfo info)
{
var infoResult = default(ColoredPointInfo<TColor>);
infoResult.DistanceFromElement = float.MaxValue; // is really outside the element
var length = info.DistanceAlongPath % this.totalLength;
// we can treat the DistanceAlongPath and DistanceFromPath as x,y coords for the pattern
// we need to calcualte the distance from the outside edge of the pattern
// and set them on the ColoredPointInfo<TColor> along with the color.
infoResult.Color = this.brush.GetColor(info.SearchPoint);
float distanceWAway = 0;
if (info.DistanceFromPath < this.halfWidth)
{
// inside strip
distanceWAway = 0;
}
else
{
distanceWAway = info.DistanceFromPath - this.halfWidth;
}
for (var i = 0; i < this.pattern.Length - 1; i++)
{
var start = this.pattern[i];
var end = this.pattern[i + 1];
if (length >= start && length < end)
{
// in section
if (i % 2 == 0)
{
// solid part return the maxDistance
infoResult.DistanceFromElement = distanceWAway;
return infoResult;
}
else
{
// this is a none solid part
var distanceFromStart = length - start;
var distanceFromEnd = end - length;
var closestEdge = Math.Min(distanceFromStart, distanceFromEnd);
var distanceAcross = closestEdge;
if (distanceWAway > 0)
{
infoResult.DistanceFromElement = new Vector2(distanceAcross, distanceWAway).Length();
}
else
{
infoResult.DistanceFromElement = closestEdge;
}
return infoResult;
}
}
}
return infoResult;
}
}
}
}

6
src/ImageSharp/Drawing/Pens/Processors/ColoredPointInfo.cs

@ -11,10 +11,8 @@ namespace ImageSharp.Drawing.Pens.Processors
/// Returns details about how far away from the inside of a shape and the color the pixel could be.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
public struct ColoredPointInfo<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public struct ColoredPointInfo<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The color

10
src/ImageSharp/Drawing/Pens/Processors/IPenApplicator.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Drawing.Pens.Processors
/// primitive that converts a <see cref="PointInfo"/> into a color and a distance away from the drawable part of the path.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
public interface IPenApplicator<TColor, TPacked> : IDisposable
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public interface IPenApplicator<TColor> : IDisposable
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Gets the required region.
@ -26,10 +24,10 @@ namespace ImageSharp.Drawing.Pens.Processors
RectangleF RequiredRegion { get; }
/// <summary>
/// Gets a <see cref="ColoredPointInfo{TColor, TPacked}" /> from a point represented by a <see cref="PointInfo" />.
/// Gets a <see cref="ColoredPointInfo{TColor}" /> from a point represented by a <see cref="PointInfo" />.
/// </summary>
/// <param name="info">The information to extract color details about.</param>
/// <returns>Returns the color details and distance from a solid bit of the line.</returns>
ColoredPointInfo<TColor, TPacked> GetColor(PointInfo info);
ColoredPointInfo<TColor> GetColor(PointInfo info);
}
}

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

@ -13,19 +13,17 @@ namespace ImageSharp.Processors
/// Combines two images together by blending the pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class DrawImageProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class DrawImageProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TColor,TPacked}"/> class.
/// Initializes a new instance of the <see cref="DrawImageProcessor{TColor}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="size">The size to draw the blended image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="alpha">The opacity of the image to blend. Between 0 and 100.</param>
public DrawImageProcessor(Image<TColor, TPacked> image, Size size, Point location, int alpha = 100)
public DrawImageProcessor(Image<TColor> image, Size size, Point location, int alpha = 100)
{
Guard.MustBeBetweenOrEqualTo(alpha, 0, 100, nameof(alpha));
this.Image = image;
@ -37,7 +35,7 @@ namespace ImageSharp.Processors
/// <summary>
/// Gets the image to blend.
/// </summary>
public Image<TColor, TPacked> Image { get; private set; }
public Image<TColor> Image { get; private set; }
/// <summary>
/// Gets the alpha percentage value.
@ -55,7 +53,7 @@ namespace ImageSharp.Processors
public Point Location { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
if (this.Image.Bounds.Size != this.Size)
{
@ -71,8 +69,8 @@ namespace ImageSharp.Processors
float alpha = this.Alpha / 100F;
using (PixelAccessor<TColor, TPacked> toBlendPixels = this.Image.Lock())
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (PixelAccessor<TColor> toBlendPixels = this.Image.Lock())
using (PixelAccessor<TColor> sourcePixels = source.Lock())
{
Parallel.For(
minY,

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

@ -21,50 +21,48 @@ namespace ImageSharp.Drawing.Processors
/// Draws a path using the processor pipeline
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <seealso cref="ImageSharp.Processors.ImageFilteringProcessor{TColor, TPacked}" />
public class DrawPathProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <seealso cref="ImageSharp.Processors.ImageFilteringProcessor{TColor}" />
public class DrawPathProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
private const float AntialiasFactor = 1f;
private const int PaddingFactor = 1; // needs to been the same or greater than AntialiasFactor
private const float Epsilon = 0.001f;
private readonly IPen<TColor, TPacked> pen;
private readonly IPen<TColor> pen;
private readonly IPath[] paths;
private readonly RectangleF region;
private readonly GraphicsOptions options;
/// <summary>
/// Initializes a new instance of the <see cref="DrawPathProcessor{TColor, TPacked}" /> class.
/// Initializes a new instance of the <see cref="DrawPathProcessor{TColor}" /> class.
/// </summary>
/// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
public DrawPathProcessor(IPen<TColor, TPacked> pen, IShape shape, GraphicsOptions options)
public DrawPathProcessor(IPen<TColor> pen, IShape shape, GraphicsOptions options)
: this(pen, shape.ToArray(), options)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawPathProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="DrawPathProcessor{TColor}"/> class.
/// </summary>
/// <param name="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
public DrawPathProcessor(IPen<TColor, TPacked> pen, IPath path, GraphicsOptions options)
public DrawPathProcessor(IPen<TColor> pen, IPath path, GraphicsOptions options)
: this(pen, new[] { path }, options)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawPathProcessor{TColor, TPacked}" /> class.
/// Initializes a new instance of the <see cref="DrawPathProcessor{TColor}" /> class.
/// </summary>
/// <param name="pen">The pen.</param>
/// <param name="paths">The paths.</param>
/// <param name="options">The options.</param>
public DrawPathProcessor(IPen<TColor, TPacked> pen, IPath[] paths, GraphicsOptions options)
public DrawPathProcessor(IPen<TColor> pen, IPath[] paths, GraphicsOptions options)
{
this.paths = paths;
this.pen = pen;
@ -86,9 +84,9 @@ namespace ImageSharp.Drawing.Processors
}
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
using (IPenApplicator<TColor, TPacked> applicator = this.pen.CreateApplicator(this.region))
using (IPenApplicator<TColor> applicator = this.pen.CreateApplicator(this.region))
{
var rect = RectangleF.Ceiling(applicator.RequiredRegion);
@ -119,7 +117,7 @@ namespace ImageSharp.Drawing.Processors
polyStartY = 0;
}
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (PixelAccessor<TColor> sourcePixels = source.Lock())
{
Parallel.For(
minY,

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

@ -16,26 +16,25 @@ 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>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class FillProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class FillProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
private const float Epsilon = 0.001f;
private readonly IBrush<TColor, TPacked> brush;
/// <summary>
/// The brush.
/// </summary>
private readonly IBrush<TColor> brush;
/// <summary>
/// Initializes a new instance of the <see cref="FillProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="FillProcessor{TColor}"/> class.
/// </summary>
/// <param name="brush">The brush to source pixel colors from.</param>
public FillProcessor(IBrush<TColor, TPacked> brush)
public FillProcessor(IBrush<TColor> brush)
{
this.brush = brush;
}
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
@ -60,10 +59,10 @@ namespace ImageSharp.Drawing.Processors
}
// we could possibly do some optermising by having knowledge about the individual brushes operate
// for example If brush is SolidBrush<TColor, TPacked> then we could just get the color upfront
// and skip using the IBrushApplicator<TColor, TPacked>?.
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (IBrushApplicator<TColor, TPacked> applicator = this.brush.CreateApplicator(sourceRectangle))
// for example If brush is SolidBrush<TColor> then we could just get the color upfront
// and skip using the IBrushApplicator<TColor>?.
using (PixelAccessor<TColor> sourcePixels = source.Lock())
using (IBrushApplicator<TColor> applicator = this.brush.CreateApplicator(sourceRectangle))
{
Parallel.For(
minY,

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

@ -17,27 +17,25 @@ 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>
/// <typeparam name="TPacked">The type of the packed.</typeparam>
/// <seealso cref="ImageSharp.Processors.ImageFilteringProcessor{TColor, TPacked}" />
public class FillShapeProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <seealso cref="ImageSharp.Processors.ImageFilteringProcessor{TColor}" />
public class FillShapeProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
private const float Epsilon = 0.001f;
private const float AntialiasFactor = 1f;
private const int DrawPadding = 1;
private readonly IBrush<TColor, TPacked> fillColor;
private readonly IBrush<TColor> fillColor;
private readonly IShape poly;
private readonly GraphicsOptions options;
/// <summary>
/// Initializes a new instance of the <see cref="FillShapeProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="FillShapeProcessor{TColor}"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The graphics options.</param>
public FillShapeProcessor(IBrush<TColor, TPacked> brush, IShape shape, GraphicsOptions options)
public FillShapeProcessor(IBrush<TColor> brush, IShape shape, GraphicsOptions options)
{
this.poly = shape;
this.fillColor = brush;
@ -45,9 +43,9 @@ namespace ImageSharp.Drawing.Processors
}
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
var rect = RectangleF.Ceiling(this.poly.Bounds); // rounds the points out away from the center
Rectangle rect = RectangleF.Ceiling(this.poly.Bounds); // rounds the points out away from the center
int polyStartY = rect.Y - DrawPadding;
int polyEndY = rect.Bottom + DrawPadding;
@ -76,8 +74,8 @@ namespace ImageSharp.Drawing.Processors
polyStartY = 0;
}
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (IBrushApplicator<TColor, TPacked> applicator = this.fillColor.CreateApplicator(rect))
using (PixelAccessor<TColor> sourcePixels = source.Lock())
using (IBrushApplicator<TColor> applicator = this.fillColor.CreateApplicator(rect))
{
Parallel.For(
minY,
@ -94,17 +92,15 @@ namespace ImageSharp.Drawing.Processors
int offsetX = x - startX;
currentPoint.X = offsetX;
currentPoint.Y = offsetY;
var dist = this.poly.Distance(currentPoint);
var opacity = this.Opacity(dist);
float dist = this.poly.Distance(currentPoint);
float opacity = this.Opacity(dist);
if (opacity > Epsilon)
{
int offsetColorX = x - minX;
Vector4 backgroundVector = sourcePixels[offsetX, offsetY].ToVector4();
Vector4 sourceVector = applicator.GetColor(currentPoint).ToVector4();
var finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
finalColor.W = backgroundVector.W;
TColor packed = default(TColor);
@ -116,13 +112,23 @@ namespace ImageSharp.Drawing.Processors
}
}
/// <summary>
/// Returns the correct alpha value for the given distance.
/// </summary>
/// <param name="distance">
/// The distance.
/// </param>
/// <returns>
/// The <see cref="float"/>.
/// </returns>
private float Opacity(float distance)
{
if (distance <= 0)
{
return 1;
}
else if (this.options.Antialias && distance < AntialiasFactor)
if (this.options.Antialias && distance < AntialiasFactor)
{
return 1 - (distance / AntialiasFactor);
}

28
src/ImageSharp/Filters/Binarization/BinaryThreshold.cs

@ -10,41 +10,37 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies binerization to the image splitting the pixels at the given threshold.
/// Applies binarization to the image splitting the pixels at the given threshold.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="threshold">The threshold to apply binerization of the image. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> BinaryThreshold<TColor, TPacked>(this Image<TColor, TPacked> source, float threshold)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> BinaryThreshold<TColor>(this Image<TColor> source, float threshold)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return BinaryThreshold(source, threshold, source.Bounds);
}
/// <summary>
/// Applies binerization to the image splitting the pixels at the given threshold.
/// Applies binarization to the image splitting the pixels at the given threshold.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="threshold">The threshold to apply binerization of the image. Must be between 0 and 1.</param>
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> BinaryThreshold<TColor, TPacked>(this Image<TColor, TPacked> source, float threshold, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> BinaryThreshold<TColor>(this Image<TColor> source, float threshold, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new BinaryThresholdProcessor<TColor, TPacked>(threshold));
return source.Process(rectangle, new BinaryThresholdProcessor<TColor>(threshold));
}
}
}

20
src/ImageSharp/Filters/ColorMatrix/BlackWhite.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,12 +18,10 @@ namespace ImageSharp
/// Applies black and white toning to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> BlackWhite<TColor, TPacked>(this Image<TColor, TPacked> source)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> BlackWhite<TColor>(this Image<TColor> source)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return BlackWhite(source, source.Bounds);
}
@ -32,17 +30,15 @@ namespace ImageSharp
/// Applies black and white toning to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> BlackWhite<TColor, TPacked>(this Image<TColor, TPacked> source, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> BlackWhite<TColor>(this Image<TColor> source, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new BlackWhiteProcessor<TColor, TPacked>());
return source.Process(rectangle, new BlackWhiteProcessor<TColor>());
}
}
}

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

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,13 +18,11 @@ namespace ImageSharp
/// Applies the given colorblindness simulator to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> ColorBlindness<TColor, TPacked>(this Image<TColor, TPacked> source, ColorBlindness colorBlindness)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> ColorBlindness<TColor>(this Image<TColor> source, ColorBlindness colorBlindness)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return ColorBlindness(source, colorBlindness, source.Bounds);
}
@ -33,51 +31,49 @@ namespace ImageSharp
/// Applies the given colorblindness simulator to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> ColorBlindness<TColor, TPacked>(this Image<TColor, TPacked> source, ColorBlindness colorBlindness, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> ColorBlindness<TColor>(this Image<TColor> source, ColorBlindness colorBlindness, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
IImageFilteringProcessor<TColor, TPacked> processor;
IImageFilteringProcessor<TColor> processor;
switch (colorBlindness)
{
case ImageSharp.ColorBlindness.Achromatomaly:
processor = new AchromatomalyProcessor<TColor, TPacked>();
processor = new AchromatomalyProcessor<TColor>();
break;
case ImageSharp.ColorBlindness.Achromatopsia:
processor = new AchromatopsiaProcessor<TColor, TPacked>();
processor = new AchromatopsiaProcessor<TColor>();
break;
case ImageSharp.ColorBlindness.Deuteranomaly:
processor = new DeuteranomalyProcessor<TColor, TPacked>();
processor = new DeuteranomalyProcessor<TColor>();
break;
case ImageSharp.ColorBlindness.Deuteranopia:
processor = new DeuteranopiaProcessor<TColor, TPacked>();
processor = new DeuteranopiaProcessor<TColor>();
break;
case ImageSharp.ColorBlindness.Protanomaly:
processor = new ProtanomalyProcessor<TColor, TPacked>();
processor = new ProtanomalyProcessor<TColor>();
break;
case ImageSharp.ColorBlindness.Protanopia:
processor = new ProtanopiaProcessor<TColor, TPacked>();
processor = new ProtanopiaProcessor<TColor>();
break;
case ImageSharp.ColorBlindness.Tritanomaly:
processor = new TritanomalyProcessor<TColor, TPacked>();
processor = new TritanomalyProcessor<TColor>();
break;
default:
processor = new TritanopiaProcessor<TColor, TPacked>();
processor = new TritanopiaProcessor<TColor>();
break;
}

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

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,13 +18,11 @@ namespace ImageSharp
/// Applies Grayscale toning to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Grayscale<TColor, TPacked>(this Image<TColor, TPacked> source, GrayscaleMode mode = GrayscaleMode.Bt709)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Grayscale<TColor>(this Image<TColor> source, GrayscaleMode mode = GrayscaleMode.Bt709)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Grayscale(source, source.Bounds, mode);
}
@ -33,20 +31,18 @@ namespace ImageSharp
/// Applies Grayscale toning to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="mode">The formula to apply to perform the operation.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Grayscale<TColor, TPacked>(this Image<TColor, TPacked> source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Grayscale<TColor>(this Image<TColor> source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
IImageFilteringProcessor<TColor, TPacked> processor = mode == GrayscaleMode.Bt709
? (IImageFilteringProcessor<TColor, TPacked>)new GrayscaleBt709Processor<TColor, TPacked>()
: new GrayscaleBt601Processor<TColor, TPacked>();
IImageFilteringProcessor<TColor> processor = mode == GrayscaleMode.Bt709
? (IImageFilteringProcessor<TColor>)new GrayscaleBt709Processor<TColor>()
: new GrayscaleBt601Processor<TColor>();
return source.Process(rectangle, processor);
}

20
src/ImageSharp/Filters/ColorMatrix/Hue.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,13 +18,11 @@ namespace ImageSharp
/// Alters the hue component of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="degrees">The angle in degrees to adjust the image.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Hue<TColor, TPacked>(this Image<TColor, TPacked> source, float degrees)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Hue<TColor>(this Image<TColor> source, float degrees)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Hue(source, degrees, source.Bounds);
}
@ -33,18 +31,16 @@ namespace ImageSharp
/// Alters the hue component of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="degrees">The angle in degrees to adjust the image.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Hue<TColor, TPacked>(this Image<TColor, TPacked> source, float degrees, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Hue<TColor>(this Image<TColor> source, float degrees, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new HueProcessor<TColor, TPacked>(degrees));
return source.Process(rectangle, new HueProcessor<TColor>(degrees));
}
}
}

20
src/ImageSharp/Filters/ColorMatrix/Kodachrome.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,12 +18,10 @@ namespace ImageSharp
/// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Kodachrome<TColor, TPacked>(this Image<TColor, TPacked> source)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Kodachrome<TColor>(this Image<TColor> source)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Kodachrome(source, source.Bounds);
}
@ -32,17 +30,15 @@ namespace ImageSharp
/// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Kodachrome<TColor, TPacked>(this Image<TColor, TPacked> source, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Kodachrome<TColor>(this Image<TColor> source, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new KodachromeProcessor<TColor, TPacked>());
return source.Process(rectangle, new KodachromeProcessor<TColor>());
}
}
}

20
src/ImageSharp/Filters/ColorMatrix/Lomograph.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,12 +18,10 @@ namespace ImageSharp
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Lomograph<TColor, TPacked>(this Image<TColor, TPacked> source)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Lomograph<TColor>(this Image<TColor> source)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Lomograph(source, source.Bounds);
}
@ -32,17 +30,15 @@ namespace ImageSharp
/// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Lomograph<TColor, TPacked>(this Image<TColor, TPacked> source, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Lomograph<TColor>(this Image<TColor> source, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new LomographProcessor<TColor, TPacked>());
return source.Process(rectangle, new LomographProcessor<TColor>());
}
}
}

20
src/ImageSharp/Filters/ColorMatrix/Polaroid.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,12 +18,10 @@ namespace ImageSharp
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Polaroid<TColor, TPacked>(this Image<TColor, TPacked> source)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Polaroid<TColor>(this Image<TColor> source)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Polaroid(source, source.Bounds);
}
@ -32,17 +30,15 @@ namespace ImageSharp
/// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Polaroid<TColor, TPacked>(this Image<TColor, TPacked> source, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Polaroid<TColor>(this Image<TColor> source, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new PolaroidProcessor<TColor, TPacked>());
return source.Process(rectangle, new PolaroidProcessor<TColor>());
}
}
}

20
src/ImageSharp/Filters/ColorMatrix/Saturation.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,13 +18,11 @@ namespace ImageSharp
/// Alters the saturation component of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Saturation<TColor, TPacked>(this Image<TColor, TPacked> source, int amount)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Saturation<TColor>(this Image<TColor> source, int amount)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Saturation(source, amount, source.Bounds);
}
@ -33,18 +31,16 @@ namespace ImageSharp
/// Alters the saturation component of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Saturation<TColor, TPacked>(this Image<TColor, TPacked> source, int amount, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Saturation<TColor>(this Image<TColor> source, int amount, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new SaturationProcessor<TColor, TPacked>(amount));
return source.Process(rectangle, new SaturationProcessor<TColor>(amount));
}
}
}

16
src/ImageSharp/Filters/ColorMatrix/Sepia.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,12 +18,10 @@ namespace ImageSharp
/// Applies sepia toning to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image<TColor, TPacked> Sepia<TColor, TPacked>(this Image<TColor, TPacked> source)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> Sepia<TColor>(this Image<TColor> source)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Sepia(source, source.Bounds);
}
@ -32,17 +30,15 @@ namespace ImageSharp
/// Applies sepia toning to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image<TColor, TPacked> Sepia<TColor, TPacked>(this Image<TColor, TPacked> source, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> Sepia<TColor>(this Image<TColor> source, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new SepiaProcessor<TColor, TPacked>());
return source.Process(rectangle, new SepiaProcessor<TColor>());
}
}
}

20
src/ImageSharp/Filters/Convolution/BoxBlur.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,13 +18,11 @@ namespace ImageSharp
/// Applies a box blur to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> BoxBlur<TColor, TPacked>(this Image<TColor, TPacked> source, int radius = 7)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> BoxBlur<TColor>(this Image<TColor> source, int radius = 7)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return BoxBlur(source, radius, source.Bounds);
}
@ -33,18 +31,16 @@ namespace ImageSharp
/// Applies a box blur to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> BoxBlur<TColor, TPacked>(this Image<TColor, TPacked> source, int radius, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> BoxBlur<TColor>(this Image<TColor> source, int radius, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new BoxBlurProcessor<TColor, TPacked>(radius));
return source.Process(rectangle, new BoxBlurProcessor<TColor>(radius));
}
}
}

80
src/ImageSharp/Filters/Convolution/DetectEdges.cs

@ -10,55 +10,49 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Detects any edges within the image. Uses the <see cref="SobelProcessor{TColor, TPacked}"/> filter
/// Detects any edges within the image. Uses the <see cref="SobelProcessor{TColor}"/> filter
/// operating in Grayscale mode.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> DetectEdges<TColor, TPacked>(this Image<TColor, TPacked> source)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return DetectEdges(source, source.Bounds, new SobelProcessor<TColor, TPacked> { Grayscale = true });
return DetectEdges(source, source.Bounds, new SobelProcessor<TColor> { Grayscale = true });
}
/// <summary>
/// Detects any edges within the image. Uses the <see cref="SobelProcessor{TColor,TPacked}"/> filter
/// Detects any edges within the image. Uses the <see cref="SobelProcessor{TColor}"/> filter
/// operating in Grayscale mode.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> DetectEdges<TColor, TPacked>(this Image<TColor, TPacked> source, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return DetectEdges(source, rectangle, new SobelProcessor<TColor, TPacked> { Grayscale = true });
return DetectEdges(source, rectangle, new SobelProcessor<TColor> { Grayscale = true });
}
/// <summary>
/// Detects any edges within the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="filter">The filter for detecting edges.</param>
/// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> DetectEdges<TColor, TPacked>(this Image<TColor, TPacked> source, EdgeDetection filter, bool grayscale = true)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source, EdgeDetection filter, bool grayscale = true)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return DetectEdges(source, filter, source.Bounds, grayscale);
}
@ -67,60 +61,58 @@ namespace ImageSharp
/// Detects any edges within the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="filter">The filter for detecting edges.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> DetectEdges<TColor, TPacked>(this Image<TColor, TPacked> source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
IEdgeDetectorProcessor<TColor, TPacked> processor;
IEdgeDetectorProcessor<TColor> processor;
switch (filter)
{
case EdgeDetection.Kayyali:
processor = new KayyaliProcessor<TColor, TPacked> { Grayscale = grayscale };
processor = new KayyaliProcessor<TColor> { Grayscale = grayscale };
break;
case EdgeDetection.Kirsch:
processor = new KirschProcessor<TColor, TPacked> { Grayscale = grayscale };
processor = new KirschProcessor<TColor> { Grayscale = grayscale };
break;
case EdgeDetection.Lapacian3X3:
processor = new Laplacian3X3Processor<TColor, TPacked> { Grayscale = grayscale };
processor = new Laplacian3X3Processor<TColor> { Grayscale = grayscale };
break;
case EdgeDetection.Lapacian5X5:
processor = new Laplacian5X5Processor<TColor, TPacked> { Grayscale = grayscale };
processor = new Laplacian5X5Processor<TColor> { Grayscale = grayscale };
break;
case EdgeDetection.LaplacianOfGaussian:
processor = new LaplacianOfGaussianProcessor<TColor, TPacked> { Grayscale = grayscale };
processor = new LaplacianOfGaussianProcessor<TColor> { Grayscale = grayscale };
break;
case EdgeDetection.Prewitt:
processor = new PrewittProcessor<TColor, TPacked> { Grayscale = grayscale };
processor = new PrewittProcessor<TColor> { Grayscale = grayscale };
break;
case EdgeDetection.RobertsCross:
processor = new RobertsCrossProcessor<TColor, TPacked> { Grayscale = grayscale };
processor = new RobertsCrossProcessor<TColor> { Grayscale = grayscale };
break;
case EdgeDetection.Robinson:
processor = new RobinsonProcessor<TColor, TPacked> { Grayscale = grayscale };
processor = new RobinsonProcessor<TColor> { Grayscale = grayscale };
break;
case EdgeDetection.Scharr:
processor = new ScharrProcessor<TColor, TPacked> { Grayscale = grayscale };
processor = new ScharrProcessor<TColor> { Grayscale = grayscale };
break;
default:
processor = new SobelProcessor<TColor, TPacked> { Grayscale = grayscale };
processor = new SobelProcessor<TColor> { Grayscale = grayscale };
break;
}
@ -131,13 +123,11 @@ namespace ImageSharp
/// Detects any edges within the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="filter">The filter for detecting edges.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> DetectEdges<TColor, TPacked>(this Image<TColor, TPacked> source, IEdgeDetectorProcessor<TColor, TPacked> filter)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source, IEdgeDetectorProcessor<TColor> filter)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return DetectEdges(source, source.Bounds, filter);
}
@ -146,16 +136,14 @@ namespace ImageSharp
/// Detects any edges within the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="filter">The filter for detecting edges.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> DetectEdges<TColor, TPacked>(this Image<TColor, TPacked> source, Rectangle rectangle, IEdgeDetectorProcessor<TColor, TPacked> filter)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source, Rectangle rectangle, IEdgeDetectorProcessor<TColor> filter)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, filter);
}

20
src/ImageSharp/Filters/Convolution/GaussianBlur.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,13 +18,11 @@ namespace ImageSharp
/// Applies a Gaussian blur to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> GaussianBlur<TColor, TPacked>(this Image<TColor, TPacked> source, float sigma = 3f)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> GaussianBlur<TColor>(this Image<TColor> source, float sigma = 3f)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return GaussianBlur(source, sigma, source.Bounds);
}
@ -33,18 +31,16 @@ namespace ImageSharp
/// Applies a Gaussian blur to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> GaussianBlur<TColor, TPacked>(this Image<TColor, TPacked> source, float sigma, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> GaussianBlur<TColor>(this Image<TColor> source, float sigma, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new GaussianBlurProcessor<TColor, TPacked>(sigma));
return source.Process(rectangle, new GaussianBlurProcessor<TColor>(sigma));
}
}
}

20
src/ImageSharp/Filters/Convolution/GaussianSharpen.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,13 +18,11 @@ namespace ImageSharp
/// Applies a Gaussian sharpening filter to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> GaussianSharpen<TColor, TPacked>(this Image<TColor, TPacked> source, float sigma = 3f)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> GaussianSharpen<TColor>(this Image<TColor> source, float sigma = 3f)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return GaussianSharpen(source, sigma, source.Bounds);
}
@ -33,18 +31,16 @@ namespace ImageSharp
/// Applies a Gaussian sharpening filter to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> GaussianSharpen<TColor, TPacked>(this Image<TColor, TPacked> source, float sigma, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> GaussianSharpen<TColor>(this Image<TColor> source, float sigma, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new GaussianSharpenProcessor<TColor, TPacked>(sigma));
return source.Process(rectangle, new GaussianSharpenProcessor<TColor>(sigma));
}
}
}

16
src/ImageSharp/Filters/Effects/Alpha.cs

@ -18,13 +18,11 @@ namespace ImageSharp
/// Alters the alpha component of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="percent">The new opacity of the image. Must be between 0 and 100.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Alpha<TColor, TPacked>(this Image<TColor, TPacked> source, int percent)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Alpha<TColor>(this Image<TColor> source, int percent)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Alpha(source, percent, source.Bounds);
}
@ -33,18 +31,16 @@ namespace ImageSharp
/// Alters the alpha component of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="percent">The new opacity of the image. Must be between 0 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image<TColor, TPacked> Alpha<TColor, TPacked>(this Image<TColor, TPacked> source, int percent, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> Alpha<TColor>(this Image<TColor> source, int percent, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new AlphaProcessor<TColor, TPacked>(percent));
return source.Process(rectangle, new AlphaProcessor<TColor>(percent));
}
}
}

12
src/ImageSharp/Filters/Effects/BackgroundColor.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,15 +18,13 @@ namespace ImageSharp
/// Replaces the background color of image with the given one.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color to set as the background.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> BackgroundColor<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> BackgroundColor<TColor>(this Image<TColor> source, TColor color)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(source.Bounds, new BackgroundColorProcessor<TColor, TPacked>(color));
return source.Process(source.Bounds, new BackgroundColorProcessor<TColor>(color));
}
}
}

28
src/ImageSharp/Filters/Effects/Brightness.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,14 +18,12 @@ namespace ImageSharp
/// Alters the brightness component of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new brightness of the image. Must be between -100 and 100.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Brightness<TColor, TPacked>(this Image<TColor, TPacked> source, int amount)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
{
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Brightness<TColor>(this Image<TColor> source, int amount)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Brightness(source, amount, source.Bounds);
}
@ -33,18 +31,16 @@ namespace ImageSharp
/// Alters the brightness component of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new brightness of the image. Must be between -100 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Brightness<TColor, TPacked>(this Image<TColor, TPacked> source, int amount, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
{
return source.Process(rectangle, new BrightnessProcessor<TColor, TPacked>(amount));
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Brightness<TColor>(this Image<TColor> source, int amount, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new BrightnessProcessor<TColor>(amount));
}
}
}

20
src/ImageSharp/Filters/Effects/Contrast.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,13 +18,11 @@ namespace ImageSharp
/// Alters the contrast component of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new contrast of the image. Must be between -100 and 100.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Contrast<TColor, TPacked>(this Image<TColor, TPacked> source, int amount)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Contrast<TColor>(this Image<TColor> source, int amount)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Contrast(source, amount, source.Bounds);
}
@ -33,18 +31,16 @@ namespace ImageSharp
/// Alters the contrast component of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new contrast of the image. Must be between -100 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Contrast<TColor, TPacked>(this Image<TColor, TPacked> source, int amount, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Contrast<TColor>(this Image<TColor> source, int amount, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new ContrastProcessor<TColor, TPacked>(amount));
return source.Process(rectangle, new ContrastProcessor<TColor>(amount));
}
}
}

16
src/ImageSharp/Filters/Effects/Invert.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,12 +18,10 @@ namespace ImageSharp
/// Inverts the colors of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image<TColor, TPacked> Invert<TColor, TPacked>(this Image<TColor, TPacked> source)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> Invert<TColor>(this Image<TColor> source)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Invert(source, source.Bounds);
}
@ -32,17 +30,15 @@ namespace ImageSharp
/// Inverts the colors of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image<TColor, TPacked> Invert<TColor, TPacked>(this Image<TColor, TPacked> source, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public static Image<TColor> Invert<TColor>(this Image<TColor> source, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Process(rectangle, new InvertProcessor<TColor, TPacked>());
return source.Process(rectangle, new InvertProcessor<TColor>());
}
}
}

20
src/ImageSharp/Filters/Effects/OilPainting.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,14 +18,12 @@ namespace ImageSharp
/// Alters the colors of the image recreating an oil painting effect.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="levels">The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image.</param>
/// <param name="brushSize">The number of neighboring pixels used in calculating each individual pixel value.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> OilPaint<TColor, TPacked>(this Image<TColor, TPacked> source, int levels = 10, int brushSize = 15)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> OilPaint<TColor>(this Image<TColor> source, int levels = 10, int brushSize = 15)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return OilPaint(source, levels, brushSize, source.Bounds);
}
@ -34,17 +32,15 @@ namespace ImageSharp
/// Alters the colors of the image recreating an oil painting effect.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="levels">The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image.</param>
/// <param name="brushSize">The number of neighboring pixels used in calculating each individual pixel value.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> OilPaint<TColor, TPacked>(this Image<TColor, TPacked> source, int levels, int brushSize, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> OilPaint<TColor>(this Image<TColor> source, int levels, int brushSize, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
Guard.MustBeGreaterThan(levels, 0, nameof(levels));
@ -53,7 +49,7 @@ namespace ImageSharp
throw new ArgumentOutOfRangeException(nameof(brushSize));
}
return source.Process(rectangle, new OilPaintingProcessor<TColor, TPacked>(levels, brushSize));
return source.Process(rectangle, new OilPaintingProcessor<TColor>(levels, brushSize));
}
}
}

20
src/ImageSharp/Filters/Effects/Pixelate.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,13 +18,11 @@ namespace ImageSharp
/// Pixelates an image with the given pixel size.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Pixelate<TColor, TPacked>(this Image<TColor, TPacked> source, int size = 4)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Pixelate<TColor>(this Image<TColor> source, int size = 4)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Pixelate(source, size, source.Bounds);
}
@ -33,23 +31,21 @@ namespace ImageSharp
/// Pixelates an image with the given pixel size.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Pixelate<TColor, TPacked>(this Image<TColor, TPacked> source, int size, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Pixelate<TColor>(this Image<TColor> source, int size, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
if (size <= 0 || size > source.Height || size > source.Width)
{
throw new ArgumentOutOfRangeException(nameof(size));
}
return source.Process(rectangle, new PixelateProcessor<TColor, TPacked>(size));
return source.Process(rectangle, new PixelateProcessor<TColor>(size));
}
}
}

44
src/ImageSharp/Filters/Overlays/Glow.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,12 +18,10 @@ namespace ImageSharp
/// Applies a radial glow effect to an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Glow<TColor, TPacked>(this Image<TColor, TPacked> source)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Glow<TColor>(this Image<TColor> source)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Glow(source, default(TColor), source.Bounds.Width * .5F, source.Bounds);
}
@ -32,13 +30,11 @@ namespace ImageSharp
/// Applies a radial glow effect to an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color to set as the glow.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Glow<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Glow<TColor>(this Image<TColor> source, TColor color)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Glow(source, color, source.Bounds.Width * .5F, source.Bounds);
}
@ -47,13 +43,11 @@ namespace ImageSharp
/// Applies a radial glow effect to an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="radius">The the radius.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Glow<TColor, TPacked>(this Image<TColor, TPacked> source, float radius)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Glow<TColor>(this Image<TColor> source, float radius)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Glow(source, default(TColor), radius, source.Bounds);
}
@ -62,15 +56,13 @@ namespace ImageSharp
/// Applies a radial glow effect to an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Glow<TColor, TPacked>(this Image<TColor, TPacked> source, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Glow<TColor>(this Image<TColor> source, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Glow(source, default(TColor), 0, rectangle);
}
@ -79,19 +71,17 @@ namespace ImageSharp
/// Applies a radial glow effect to an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color to set as the glow.</param>
/// <param name="radius">The the radius.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Glow<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float radius, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Glow<TColor>(this Image<TColor> source, TColor color, float radius, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
GlowProcessor<TColor, TPacked> processor = new GlowProcessor<TColor, TPacked> { Radius = radius, };
GlowProcessor<TColor> processor = new GlowProcessor<TColor> { Radius = radius, };
if (!color.Equals(default(TColor)))
{

44
src/ImageSharp/Filters/Overlays/Vignette.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -18,12 +18,10 @@ namespace ImageSharp
/// Applies a radial vignette effect to an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Vignette<TColor, TPacked>(this Image<TColor, TPacked> source)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Vignette<TColor>(this Image<TColor> source)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Vignette(source, default(TColor), source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds);
}
@ -32,13 +30,11 @@ namespace ImageSharp
/// Applies a radial vignette effect to an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color to set as the vignette.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Vignette<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Vignette<TColor>(this Image<TColor> source, TColor color)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Vignette(source, color, source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds);
}
@ -47,14 +43,12 @@ namespace ImageSharp
/// Applies a radial vignette effect to an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="radiusX">The the x-radius.</param>
/// <param name="radiusY">The the y-radius.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Vignette<TColor, TPacked>(this Image<TColor, TPacked> source, float radiusX, float radiusY)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Vignette<TColor>(this Image<TColor> source, float radiusX, float radiusY)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Vignette(source, default(TColor), radiusX, radiusY, source.Bounds);
}
@ -63,15 +57,13 @@ namespace ImageSharp
/// Applies a radial vignette effect to an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Vignette<TColor, TPacked>(this Image<TColor, TPacked> source, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Vignette<TColor>(this Image<TColor> source, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Vignette(source, default(TColor), 0, 0, rectangle);
}
@ -80,7 +72,6 @@ namespace ImageSharp
/// Applies a radial vignette effect to an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color to set as the vignette.</param>
/// <param name="radiusX">The the x-radius.</param>
@ -88,12 +79,11 @@ namespace ImageSharp
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
public static Image<TColor, TPacked> Vignette<TColor, TPacked>(this Image<TColor, TPacked> source, TColor color, float radiusX, float radiusY, Rectangle rectangle)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Vignette<TColor>(this Image<TColor> source, TColor color, float radiusX, float radiusY, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
VignetteProcessor<TColor, TPacked> processor = new VignetteProcessor<TColor, TPacked> { RadiusX = radiusX, RadiusY = radiusY };
VignetteProcessor<TColor> processor = new VignetteProcessor<TColor> { RadiusX = radiusX, RadiusY = radiusY };
if (!color.Equals(default(TColor)))
{

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

@ -9,17 +9,15 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor,TPacked}"/> to perform binary threshold filtering against an
/// An <see cref="IImageFilteringProcessor{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>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class BinaryThresholdProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class BinaryThresholdProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Initializes a new instance of the <see cref="BinaryThresholdProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="BinaryThresholdProcessor{TColor}"/> class.
/// </summary>
/// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param>
/// <exception cref="System.ArgumentException">
@ -56,13 +54,13 @@ namespace ImageSharp.Processors
public TColor LowerColor { get; set; }
/// <inheritdoc/>
protected override void BeforeApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void BeforeApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
new GrayscaleBt709Processor<TColor, TPacked>().Apply(source, sourceRectangle);
new GrayscaleBt709Processor<TColor>().Apply(source, sourceRectangle);
}
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
float threshold = this.Value;
TColor upper = this.UpperColor;
@ -90,7 +88,7 @@ namespace ImageSharp.Processors
startY = 0;
}
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (PixelAccessor<TColor> sourcePixels = source.Lock())
{
Parallel.For(
minY,

6
src/ImageSharp/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image to their black and white equivalent.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class BlackWhiteProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class BlackWhiteProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class AchromatomalyProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class AchromatomalyProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class AchromatopsiaProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class AchromatopsiaProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class DeuteranomalyProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class DeuteranomalyProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class DeuteranopiaProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class DeuteranopiaProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image recreating Protanopia (Red-Weak) color blindness.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class ProtanomalyProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class ProtanomalyProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class ProtanopiaProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class ProtanopiaProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image recreating Tritanomaly (Blue-Weak) color blindness.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class TritanomalyProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class TritanomalyProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image recreating Tritanopia (Blue-Blind) color blindness.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class TritanopiaProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class TritanopiaProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

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

@ -13,10 +13,8 @@ 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>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public abstract class ColorMatrixFilter<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>, IColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public abstract class ColorMatrixFilter<TColor> : ImageFilteringProcessor<TColor>, IColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public abstract Matrix4x4 Matrix { get; }
@ -25,7 +23,7 @@ namespace ImageSharp.Processors
public override bool Compand { get; set; } = true;
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
int startY = sourceRectangle.Y;
int endY = sourceRectangle.Bottom;
@ -52,7 +50,7 @@ namespace ImageSharp.Processors
Matrix4x4 matrix = this.Matrix;
bool compand = this.Compand;
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (PixelAccessor<TColor> sourcePixels = source.Lock())
{
Parallel.For(
minY,

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

@ -13,10 +13,8 @@ namespace ImageSharp.Processors
/// ITU-R Recommendation BT.601 <see href="https://en.wikipedia.org/wiki/Luma_%28video%29#Rec._601_luma_versus_Rec._709_luma_coefficients"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class GrayscaleBt601Processor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class GrayscaleBt601Processor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

6
src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs

@ -13,10 +13,8 @@ namespace ImageSharp.Processors
/// ITU-R Recommendation BT.709 <see href="https://en.wikipedia.org/wiki/Rec._709#Luma_coefficients"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class GrayscaleBt709Processor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class GrayscaleBt709Processor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

10
src/ImageSharp/Filters/Processors/ColorMatrix/HueProcessor.cs

@ -9,16 +9,14 @@ namespace ImageSharp.Processors
using System.Numerics;
/// <summary>
/// An <see cref="ImageProcessor{TColor, TPacked}"/> to change the hue of an <see cref="Image{TColor, TPacked}"/>.
/// An <see cref="ImageProcessor{TColor}"/> to change the hue of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class HueProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class HueProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Initializes a new instance of the <see cref="HueProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="HueProcessor{TColor}"/> class.
/// </summary>
/// <param name="angle">The new brightness of the image. Must be between -100 and 100.</param>
public HueProcessor(float angle)

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

@ -13,10 +13,8 @@ namespace ImageSharp.Processors
/// alter the image pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public interface IColorMatrixFilter<TColor, TPacked> : IImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public interface IColorMatrixFilter<TColor> : IImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Gets the <see cref="Matrix4x4"/> used to alter the image.

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

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class KodachromeProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class KodachromeProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()

10
src/ImageSharp/Filters/Processors/ColorMatrix/LomographProcessor.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image recreating an old Lomograph effect.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class LomographProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class LomographProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
@ -30,11 +28,11 @@ namespace ImageSharp.Processors
};
/// <inheritdoc/>
protected override void AfterApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void AfterApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
TColor packed = default(TColor);
packed.PackFromVector4(new Color(0, 10, 0).ToVector4()); // Very dark (mostly black) lime green.
new VignetteProcessor<TColor, TPacked> { VignetteColor = packed }.Apply(source, sourceRectangle);
new VignetteProcessor<TColor> { VignetteColor = packed }.Apply(source, sourceRectangle);
}
}
}

12
src/ImageSharp/Filters/Processors/ColorMatrix/PolaroidProcessor.cs

@ -12,10 +12,8 @@ namespace ImageSharp.Processors
/// Converts the colors of the image recreating an old Polaroid effect.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class PolaroidProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class PolaroidProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
@ -36,15 +34,15 @@ namespace ImageSharp.Processors
};
/// <inheritdoc/>
protected override void AfterApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void AfterApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
TColor packedV = default(TColor);
packedV.PackFromVector4(new Color(102, 34, 0).ToVector4()); // Very dark orange [Brown tone]
new VignetteProcessor<TColor, TPacked> { VignetteColor = packedV }.Apply(source, sourceRectangle);
new VignetteProcessor<TColor> { VignetteColor = packedV }.Apply(source, sourceRectangle);
TColor packedG = default(TColor);
packedG.PackFromVector4(new Color(255, 153, 102, 178).ToVector4()); // Light orange
new GlowProcessor<TColor, TPacked> { GlowColor = packedG, Radius = source.Width / 4F }.Apply(source, sourceRectangle);
new GlowProcessor<TColor> { GlowColor = packedG, Radius = source.Width / 4F }.Apply(source, sourceRectangle);
}
}
}

10
src/ImageSharp/Filters/Processors/ColorMatrix/SaturationProcessor.cs

@ -9,16 +9,14 @@ namespace ImageSharp.Processors
using System.Numerics;
/// <summary>
/// An <see cref="ImageProcessor{TColor, TPacked}"/> to change the saturation of an <see cref="Image{TColor, TPacked}"/>.
/// An <see cref="ImageProcessor{TColor}"/> to change the saturation of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class SaturationProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class SaturationProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Initializes a new instance of the <see cref="SaturationProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="SaturationProcessor{TColor}"/> class.
/// </summary>
/// <param name="saturation">The new saturation of the image. Must be between -100 and 100.</param>
/// <exception cref="System.ArgumentException">

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

@ -13,10 +13,8 @@ namespace ImageSharp.Processors
/// The formula used matches the svg specification. <see href="http://www.w3.org/TR/filter-effects/#sepiaEquivalent"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class SepiaProcessor<TColor, TPacked> : ColorMatrixFilter<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class SepiaProcessor<TColor> : ColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4

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

@ -11,10 +11,8 @@ namespace ImageSharp.Processors
/// Applies a Box blur sampler to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class BoxBlurProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class BoxBlurProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The maximum size of the kernel in either direction.
@ -22,7 +20,7 @@ namespace ImageSharp.Processors
private readonly int kernelSize;
/// <summary>
/// Initializes a new instance of the <see cref="BoxBlurProcessor{TColor,TPacked}"/> class.
/// Initializes a new instance of the <see cref="BoxBlurProcessor{TColor}"/> class.
/// </summary>
/// <param name="radius">
/// The 'radius' value representing the size of the area to sample.
@ -45,9 +43,9 @@ namespace ImageSharp.Processors
public float[][] KernelY { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
new Convolution2PassProcessor<TColor, TPacked>(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
new Convolution2PassProcessor<TColor>(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
}
/// <summary>

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

@ -13,13 +13,11 @@ 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>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class Convolution2DProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class Convolution2DProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Initializes a new instance of the <see cref="Convolution2DProcessor{TColor,TPacked}"/> class.
/// Initializes a new instance of the <see cref="Convolution2DProcessor{TColor}"/> class.
/// </summary>
/// <param name="kernelX">The horizontal gradient operator.</param>
/// <param name="kernelY">The vertical gradient operator.</param>
@ -40,7 +38,7 @@ namespace ImageSharp.Processors
public float[][] KernelY { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
int kernelYHeight = this.KernelY.Length;
int kernelYWidth = this.KernelY[0].Length;
@ -57,8 +55,8 @@ namespace ImageSharp.Processors
int maxX = endX - 1;
TColor[] target = new TColor[source.Width * source.Height];
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (PixelAccessor<TColor, TPacked> targetPixels = target.Lock<TColor, TPacked>(source.Width, source.Height))
using (PixelAccessor<TColor> sourcePixels = source.Lock())
using (PixelAccessor<TColor> targetPixels = target.Lock<TColor>(source.Width, source.Height))
{
Parallel.For(
startY,

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

@ -13,13 +13,11 @@ 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>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class Convolution2PassProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class Convolution2PassProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Initializes a new instance of the <see cref="Convolution2PassProcessor{TColor,TPacked}"/> class.
/// Initializes a new instance of the <see cref="Convolution2PassProcessor{TColor}"/> class.
/// </summary>
/// <param name="kernelX">The horizontal gradient operator.</param>
/// <param name="kernelY">The vertical gradient operator.</param>
@ -40,7 +38,7 @@ namespace ImageSharp.Processors
public float[][] KernelY { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
float[][] kernelX = this.KernelX;
float[][] kernelY = this.KernelY;
@ -57,7 +55,7 @@ namespace ImageSharp.Processors
}
/// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor, TPacked}"/> at the specified location
/// 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="width">The image width.</param>
@ -82,8 +80,8 @@ namespace ImageSharp.Processors
int maxY = endY - 1;
int maxX = endX - 1;
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock<TColor, TPacked>(width, height))
using (PixelAccessor<TColor, TPacked> targetPixels = target.Lock<TColor, TPacked>(width, height))
using (PixelAccessor<TColor> sourcePixels = source.Lock<TColor>(width, height))
using (PixelAccessor<TColor> targetPixels = target.Lock<TColor>(width, height))
{
Parallel.For(
startY,

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

@ -13,13 +13,11 @@ 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>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class ConvolutionProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class ConvolutionProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Initializes a new instance of the <see cref="ConvolutionProcessor{TColor,TPacked}"/> class.
/// Initializes a new instance of the <see cref="ConvolutionProcessor{TColor}"/> class.
/// </summary>
/// <param name="kernelXY">The 2d gradient operator.</param>
public ConvolutionProcessor(float[][] kernelXY)
@ -33,7 +31,7 @@ namespace ImageSharp.Processors
public virtual float[][] KernelXY { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
float[][] kernelX = this.KernelXY;
int kernelLength = kernelX.GetLength(0);
@ -47,8 +45,8 @@ namespace ImageSharp.Processors
int maxX = endX - 1;
TColor[] target = new TColor[source.Width * source.Height];
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (PixelAccessor<TColor, TPacked> targetPixels = target.Lock<TColor, TPacked>(source.Width, source.Height))
using (PixelAccessor<TColor> sourcePixels = source.Lock())
using (PixelAccessor<TColor> targetPixels = target.Lock<TColor>(source.Width, source.Height))
{
Parallel.For(
startY,

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

@ -11,10 +11,8 @@ 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>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public abstract class EdgeDetector2DProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>, IEdgeDetectorProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public abstract class EdgeDetector2DProcessor<TColor> : ImageFilteringProcessor<TColor>, IEdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Gets the horizontal gradient operator.
@ -30,17 +28,17 @@ namespace ImageSharp.Processors
public bool Grayscale { get; set; }
/// <inheritdoc />
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
new Convolution2DProcessor<TColor, TPacked>(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
new Convolution2DProcessor<TColor>(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
}
/// <inheritdoc/>
protected override void BeforeApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void BeforeApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
if (this.Grayscale)
{
new GrayscaleBt709Processor<TColor, TPacked>().Apply(source, sourceRectangle);
new GrayscaleBt709Processor<TColor>().Apply(source, sourceRectangle);
}
}
}

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

@ -13,10 +13,8 @@ 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>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public abstract class EdgeDetectorCompassProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>, IEdgeDetectorProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public abstract class EdgeDetectorCompassProcessor<TColor> : ImageFilteringProcessor<TColor>, IEdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Gets the North gradient operator
@ -62,7 +60,7 @@ namespace ImageSharp.Processors
public bool Grayscale { get; set; }
/// <inheritdoc />
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
float[][][] kernels = { this.North, this.NorthWest, this.West, this.SouthWest, this.South, this.SouthEast, this.East, this.NorthEast };
@ -78,9 +76,9 @@ namespace ImageSharp.Processors
int maxY = Math.Min(source.Height, endY);
// First run.
ImageBase<TColor, TPacked> target = new Image<TColor, TPacked>(source.Width, source.Height);
ImageBase<TColor> target = new Image<TColor>(source.Width, source.Height);
target.ClonePixels(source.Width, source.Height, source.Pixels);
new ConvolutionProcessor<TColor, TPacked>(kernels[0]).Apply(target, sourceRectangle);
new ConvolutionProcessor<TColor>(kernels[0]).Apply(target, sourceRectangle);
if (kernels.Length == 1)
{
@ -106,13 +104,13 @@ namespace ImageSharp.Processors
for (int i = 1; i < kernels.Length; i++)
{
// Create a clone for each pass and copy the offset pixels across.
ImageBase<TColor, TPacked> pass = new Image<TColor, TPacked>(source.Width, source.Height);
ImageBase<TColor> pass = new Image<TColor>(source.Width, source.Height);
pass.ClonePixels(source.Width, source.Height, source.Pixels);
new ConvolutionProcessor<TColor, TPacked>(kernels[i]).Apply(pass, sourceRectangle);
new ConvolutionProcessor<TColor>(kernels[i]).Apply(pass, sourceRectangle);
using (PixelAccessor<TColor, TPacked> passPixels = pass.Lock())
using (PixelAccessor<TColor, TPacked> targetPixels = target.Lock())
using (PixelAccessor<TColor> passPixels = pass.Lock())
using (PixelAccessor<TColor> targetPixels = target.Lock())
{
Parallel.For(
minY,
@ -138,11 +136,11 @@ namespace ImageSharp.Processors
}
/// <inheritdoc/>
protected override void BeforeApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void BeforeApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
if (this.Grayscale)
{
new GrayscaleBt709Processor<TColor, TPacked>().Apply(source, sourceRectangle);
new GrayscaleBt709Processor<TColor>().Apply(source, sourceRectangle);
}
}
}

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

@ -11,10 +11,8 @@ 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>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public abstract class EdgeDetectorProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>, IEdgeDetectorProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public abstract class EdgeDetectorProcessor<TColor> : ImageFilteringProcessor<TColor>, IEdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public bool Grayscale { get; set; }
@ -25,17 +23,17 @@ namespace ImageSharp.Processors
public abstract float[][] KernelXY { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
new ConvolutionProcessor<TColor, TPacked>(this.KernelXY).Apply(source, sourceRectangle);
new ConvolutionProcessor<TColor>(this.KernelXY).Apply(source, sourceRectangle);
}
/// <inheritdoc/>
protected override void BeforeApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void BeforeApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
if (this.Grayscale)
{
new GrayscaleBt709Processor<TColor, TPacked>().Apply(source, sourceRectangle);
new GrayscaleBt709Processor<TColor>().Apply(source, sourceRectangle);
}
}
}

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

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

6
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs

@ -13,11 +13,9 @@ namespace ImageSharp.Processors
/// <see href="http://edgedetection.webs.com/"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")]
public class KayyaliProcessor<TColor, TPacked> : EdgeDetector2DProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class KayyaliProcessor<TColor> : EdgeDetector2DProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The horizontal gradient operator.

6
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs

@ -12,11 +12,9 @@ namespace ImageSharp.Processors
/// <see href="http://en.wikipedia.org/wiki/Kirsch_operator"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")]
public class KirschProcessor<TColor, TPacked> : EdgeDetectorCompassProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class KirschProcessor<TColor> : EdgeDetectorCompassProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The North gradient operator

6
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs

@ -13,11 +13,9 @@ namespace ImageSharp.Processors
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")]
public class Laplacian3X3Processor<TColor, TPacked> : EdgeDetectorProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class Laplacian3X3Processor<TColor> : EdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The 2d gradient operator.

6
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs

@ -13,11 +13,9 @@ namespace ImageSharp.Processors
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")]
public class Laplacian5X5Processor<TColor, TPacked> : EdgeDetectorProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class Laplacian5X5Processor<TColor> : EdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The 2d gradient operator.

6
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs

@ -13,11 +13,9 @@ namespace ImageSharp.Processors
/// <see href="http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")]
public class LaplacianOfGaussianProcessor<TColor, TPacked> : EdgeDetectorProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class LaplacianOfGaussianProcessor<TColor> : EdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The 2d gradient operator.

6
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs

@ -13,11 +13,9 @@ namespace ImageSharp.Processors
/// <see href="http://en.wikipedia.org/wiki/Prewitt_operator"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")]
public class PrewittProcessor<TColor, TPacked> : EdgeDetector2DProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class PrewittProcessor<TColor> : EdgeDetector2DProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The horizontal gradient operator.

6
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs

@ -13,11 +13,9 @@ namespace ImageSharp.Processors
/// <see href="http://en.wikipedia.org/wiki/Roberts_cross"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")]
public class RobertsCrossProcessor<TColor, TPacked> : EdgeDetector2DProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class RobertsCrossProcessor<TColor> : EdgeDetector2DProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The horizontal gradient operator.

6
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs

@ -12,11 +12,9 @@ namespace ImageSharp.Processors
/// <see href="http://www.tutorialspoint.com/dip/Robinson_Compass_Mask.htm"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")]
public class RobinsonProcessor<TColor, TPacked> : EdgeDetectorCompassProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class RobinsonProcessor<TColor> : EdgeDetectorCompassProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The North gradient operator

6
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs

@ -13,11 +13,9 @@ namespace ImageSharp.Processors
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator#Alternative_operators"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")]
public class ScharrProcessor<TColor, TPacked> : EdgeDetector2DProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class ScharrProcessor<TColor> : EdgeDetector2DProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The horizontal gradient operator.

6
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs

@ -13,11 +13,9 @@ namespace ImageSharp.Processors
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")]
public class SobelProcessor<TColor, TPacked> : EdgeDetector2DProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class SobelProcessor<TColor> : EdgeDetector2DProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The horizontal gradient operator.

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

@ -11,10 +11,8 @@ namespace ImageSharp.Processors
/// Applies a Gaussian blur sampler to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class GaussianBlurProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class GaussianBlurProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The maximum size of the kernel in either direction.
@ -27,7 +25,7 @@ namespace ImageSharp.Processors
private readonly float sigma;
/// <summary>
/// Initializes a new instance of the <see cref="GaussianBlurProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="GaussianBlurProcessor{TColor}"/> class.
/// </summary>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
public GaussianBlurProcessor(float sigma = 3f)
@ -39,7 +37,7 @@ namespace ImageSharp.Processors
}
/// <summary>
/// Initializes a new instance of the <see cref="GaussianBlurProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="GaussianBlurProcessor{TColor}"/> class.
/// </summary>
/// <param name="radius">
/// The 'radius' value representing the size of the area to sample.
@ -53,7 +51,7 @@ namespace ImageSharp.Processors
}
/// <summary>
/// Initializes a new instance of the <see cref="GaussianBlurProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="GaussianBlurProcessor{TColor}"/> class.
/// </summary>
/// <param name="sigma">
/// The 'sigma' value representing the weight of the blur.
@ -81,9 +79,9 @@ namespace ImageSharp.Processors
public float[][] KernelY { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
new Convolution2PassProcessor<TColor, TPacked>(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
new Convolution2PassProcessor<TColor>(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
}
/// <summary>

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

@ -11,10 +11,8 @@ namespace ImageSharp.Processors
/// Applies a Gaussian sharpening sampler to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class GaussianSharpenProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class GaussianSharpenProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The maximum size of the kernel in either direction.
@ -27,7 +25,7 @@ namespace ImageSharp.Processors
private readonly float sigma;
/// <summary>
/// Initializes a new instance of the <see cref="GaussianSharpenProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="GaussianSharpenProcessor{TColor}"/> class.
/// </summary>
/// <param name="sigma">
/// The 'sigma' value representing the weight of the sharpening.
@ -41,7 +39,7 @@ namespace ImageSharp.Processors
}
/// <summary>
/// Initializes a new instance of the <see cref="GaussianSharpenProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="GaussianSharpenProcessor{TColor}"/> class.
/// </summary>
/// <param name="radius">
/// The 'radius' value representing the size of the area to sample.
@ -55,7 +53,7 @@ namespace ImageSharp.Processors
}
/// <summary>
/// Initializes a new instance of the <see cref="GaussianSharpenProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="GaussianSharpenProcessor{TColor}"/> class.
/// </summary>
/// <param name="sigma">
/// The 'sigma' value representing the weight of the sharpen.
@ -83,9 +81,9 @@ namespace ImageSharp.Processors
public float[][] KernelY { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
new Convolution2PassProcessor<TColor, TPacked>(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
new Convolution2PassProcessor<TColor>(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
}
/// <summary>

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

@ -10,16 +10,14 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor,TPacked}"/> to change the alpha component of an <see cref="Image{TColor, TPacked}"/>.
/// An <see cref="IImageFilteringProcessor{TColor}"/> to change the alpha component of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class AlphaProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class AlphaProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Initializes a new instance of the <see cref="AlphaProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="AlphaProcessor{TColor}"/> class.
/// </summary>
/// <param name="percent">The percentage to adjust the opacity of the image. Must be between 0 and 100.</param>
/// <exception cref="System.ArgumentException">
@ -37,7 +35,7 @@ namespace ImageSharp.Processors
public int Value { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
float alpha = this.Value / 100F;
@ -65,7 +63,7 @@ namespace ImageSharp.Processors
Vector4 alphaVector = new Vector4(1, 1, 1, alpha);
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (PixelAccessor<TColor> sourcePixels = source.Lock())
{
Parallel.For(
minY,

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

@ -13,10 +13,8 @@ namespace ImageSharp.Processors
/// Sets the background color of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class BackgroundColorProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class BackgroundColorProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The epsilon for comparing floating point numbers.
@ -24,7 +22,7 @@ namespace ImageSharp.Processors
private const float Epsilon = 0.001f;
/// <summary>
/// Initializes a new instance of the <see cref="BackgroundColorProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="BackgroundColorProcessor{TColor}"/> class.
/// </summary>
/// <param name="color">The <typeparamref name="TColor"/> to set the background color to.</param>
public BackgroundColorProcessor(TColor color)
@ -38,7 +36,7 @@ namespace ImageSharp.Processors
public TColor Value { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
int startY = sourceRectangle.Y;
int endY = sourceRectangle.Bottom;
@ -64,7 +62,7 @@ namespace ImageSharp.Processors
Vector4 backgroundColor = this.Value.ToVector4();
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (PixelAccessor<TColor> sourcePixels = source.Lock())
{
Parallel.For(
minY,

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

@ -10,16 +10,14 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor,TPacked}"/> to change the brightness of an <see cref="Image{TColor, TPacked}"/>.
/// An <see cref="IImageFilteringProcessor{TColor}"/> to change the brightness of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class BrightnessProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class BrightnessProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Initializes a new instance of the <see cref="BrightnessProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="BrightnessProcessor{TColor}"/> class.
/// </summary>
/// <param name="brightness">The new brightness of the image. Must be between -100 and 100.</param>
/// <exception cref="System.ArgumentException">
@ -37,7 +35,7 @@ namespace ImageSharp.Processors
public int Value { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
float brightness = this.Value / 100F;
@ -63,7 +61,7 @@ namespace ImageSharp.Processors
startY = 0;
}
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (PixelAccessor<TColor> sourcePixels = source.Lock())
{
Parallel.For(
minY,

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

@ -10,16 +10,14 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor,TPacked}"/> to change the contrast of an <see cref="Image{TColor, TPacked}"/>.
/// An <see cref="IImageFilteringProcessor{TColor}"/> to change the contrast of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>long, float.</example></typeparam>
public class ContrastProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct, IEquatable<TPacked>
public class ContrastProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Initializes a new instance of the <see cref="ContrastProcessor{TColor, TPacked}"/> class.
/// Initializes a new instance of the <see cref="ContrastProcessor{TColor}"/> class.
/// </summary>
/// <param name="contrast">The new contrast of the image. Must be between -100 and 100.</param>
/// <exception cref="System.ArgumentException">
@ -37,7 +35,7 @@ namespace ImageSharp.Processors
public int Value { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle)
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
float contrast = (100F + this.Value) / 100F;
@ -65,7 +63,7 @@ namespace ImageSharp.Processors
startY = 0;
}
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (PixelAccessor<TColor> sourcePixels = source.Lock())
{
Parallel.For(
minY,

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

Loading…
Cancel
Save