Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6741c28
temporarily disable target frameworks
antonfirsov May 11, 2019
7e8357c
validating tests for: DrawPath, FillComplexPolygon
antonfirsov May 11, 2019
cf8005d
validation in DrawImageTest
antonfirsov May 11, 2019
5ab0ad2
RecolorImageTests
antonfirsov May 11, 2019
52fbbda
FillPolygonTests
antonfirsov May 12, 2019
680156a
DrawPolygonTests, DrawLinesTests
antonfirsov May 12, 2019
473fd02
DrawBeziersTests, DrawComplexPolygonTests
antonfirsov May 12, 2019
fd6b229
Merge branch 'af/general-color-type' into af/refactor-drawing
antonfirsov May 12, 2019
a910005
fix merge issues
antonfirsov May 12, 2019
21f221e
DrawImageTests: add tolerance to make all test configurations happy
antonfirsov May 12, 2019
2bff823
started the refactor
antonfirsov May 12, 2019
73f9116
Pen, Brush & Processors refactored
antonfirsov May 12, 2019
b902e6c
ImageSharp.Drawing compiles
antonfirsov May 12, 2019
8271ef1
everything builds
antonfirsov May 12, 2019
f0b70b6
tests are passing
antonfirsov May 12, 2019
0eff9bc
Merge branch 'af/general-color-type' into af/refactor-drawing
antonfirsov May 12, 2019
f7df30f
move drawing extensions to a (non-namespace-provider) subfolder
antonfirsov May 12, 2019
c07bd2f
rename files
antonfirsov May 12, 2019
efaa3c0
ImageBrush can apply a source image of a different pixel type than th…
antonfirsov May 12, 2019
0bd86dd
non-generic DrawImageProcessor
antonfirsov May 12, 2019
3b7a741
DrawImageOfDifferentPixelType test cases
antonfirsov May 13, 2019
b7dadca
clean-up drawing processors
antonfirsov May 13, 2019
d2ea005
fix remaining stylecop issues
antonfirsov May 13, 2019
c2e955c
Rgba32.Definitions: use Color instead of NamedColors<T>
antonfirsov May 13, 2019
51e23eb
Remove NamedColors<T> usages
antonfirsov May 13, 2019
17f2311
drop unnecessary generic IImageProcessorContext<TPixel> usages
antonfirsov May 16, 2019
7e57fce
drop almost all usages of FileTestBase
antonfirsov May 16, 2019
3af895b
fix tests
antonfirsov May 16, 2019
a36aa55
re-enable target frameworks
antonfirsov May 16, 2019
0395300
Merge remote-tracking branch 'origin/master' into af/refactor-drawing
antonfirsov May 16, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@

<ItemGroup>
<AdditionalFiles Include="..\..\standards\stylecop.json" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta0008" />
<PackageReference Include="SixLabors.Shapes" Version="1.0.0-beta0008" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-rc.114" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/ImageSharp.Drawing/ImageSharp.Drawing.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=processing_005Cextensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion src/ImageSharp.Drawing/Processing/BrushApplicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal BrushApplicator(ImageFrame<TPixel> target, GraphicsOptions options)
/// <summary>
/// Gets the blend percentage
/// </summary>
protected GraphicsOptions Options { get; private set; }
protected GraphicsOptions Options { get; }

/// <summary>
/// Gets the color for a single pixel.
Expand Down
120 changes: 44 additions & 76 deletions src/ImageSharp.Drawing/Processing/Brushes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Processing
/// <summary>
/// A collection of methods for creating generic brushes.
/// </summary>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
/// <returns>A New <see cref="PatternBrush"/></returns>
public static class Brushes
{
/// <summary>
Expand Down Expand Up @@ -94,163 +94,131 @@ public static class Brushes
/// Create as brush that will paint a solid color
/// </summary>
/// <param name="color">The color.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static SolidBrush<TPixel> Solid<TPixel>(TPixel color)
where TPixel : struct, IPixel<TPixel>
=> new SolidBrush<TPixel>(color);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static SolidBrush Solid(Color color) => new SolidBrush(color);

/// <summary>
/// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Percent10<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, Percent10Pattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush Percent10(Color foreColor) =>
new PatternBrush(foreColor, Color.Transparent, Percent10Pattern);

/// <summary>
/// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Percent10<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, Percent10Pattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush Percent10(Color foreColor, Color backColor) =>
new PatternBrush(foreColor, backColor, Percent10Pattern);

/// <summary>
/// Create as brush that will paint a Percent20 Hatch Pattern with the specified foreground color and a
/// transparent background.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Percent20<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, Percent20Pattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush Percent20(Color foreColor) =>
new PatternBrush(foreColor, Color.Transparent, Percent20Pattern);

/// <summary>
/// Create as brush that will paint a Percent20 Hatch Pattern with the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Percent20<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, Percent20Pattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush Percent20(Color foreColor, Color backColor) =>
new PatternBrush(foreColor, backColor, Percent20Pattern);

/// <summary>
/// Create as brush that will paint a Horizontal Hatch Pattern with the specified foreground color and a
/// transparent background.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Horizontal<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, HorizontalPattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush Horizontal(Color foreColor) =>
new PatternBrush(foreColor, Color.Transparent, HorizontalPattern);

/// <summary>
/// Create as brush that will paint a Horizontal Hatch Pattern with the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Horizontal<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, HorizontalPattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush Horizontal(Color foreColor, Color backColor) =>
new PatternBrush(foreColor, backColor, HorizontalPattern);

/// <summary>
/// Create as brush that will paint a Min Hatch Pattern with the specified foreground color and a
/// transparent background.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Min<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, MinPattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush Min(Color foreColor) => new PatternBrush(foreColor, Color.Transparent, MinPattern);

/// <summary>
/// Create as brush that will paint a Min Hatch Pattern with the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Min<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, MinPattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush Min(Color foreColor, Color backColor) =>
new PatternBrush(foreColor, backColor, MinPattern);

/// <summary>
/// Create as brush that will paint a Vertical Hatch Pattern with the specified foreground color and a
/// transparent background.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Vertical<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, VerticalPattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush Vertical(Color foreColor) =>
new PatternBrush(foreColor, Color.Transparent, VerticalPattern);

/// <summary>
/// Create as brush that will paint a Vertical Hatch Pattern with the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Vertical<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, VerticalPattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush Vertical(Color foreColor, Color backColor) =>
new PatternBrush(foreColor, backColor, VerticalPattern);

/// <summary>
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified foreground color and a
/// transparent background.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> ForwardDiagonal<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, ForwardDiagonalPattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush ForwardDiagonal(Color foreColor) =>
new PatternBrush(foreColor, Color.Transparent, ForwardDiagonalPattern);

/// <summary>
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> ForwardDiagonal<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, ForwardDiagonalPattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor) =>
new PatternBrush(foreColor, backColor, ForwardDiagonalPattern);

/// <summary>
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified foreground color and a
/// transparent background.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> BackwardDiagonal<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, BackwardDiagonalPattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush BackwardDiagonal(Color foreColor) =>
new PatternBrush(foreColor, Color.Transparent, BackwardDiagonalPattern);

/// <summary>
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> BackwardDiagonal<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, BackwardDiagonalPattern);
/// <returns>A New <see cref="PatternBrush"/></returns>
public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor) =>
new PatternBrush(foreColor, backColor, BackwardDiagonalPattern);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ namespace SixLabors.ImageSharp.Processing
/// <summary>
/// A struct that defines a single color stop.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
[DebuggerDisplay("ColorStop({Ratio} -> {Color}")]
public struct ColorStop<TPixel>
where TPixel : struct, IPixel<TPixel>
public readonly struct ColorStop
{
/// <summary>
/// Initializes a new instance of the <see cref="ColorStop{TPixel}" /> struct.
/// Initializes a new instance of the <see cref="ColorStop" /> struct.
/// </summary>
/// <param name="ratio">Where should it be? 0 is at the start, 1 at the end of the Gradient.</param>
/// <param name="color">What color should be used at that point?</param>
public ColorStop(float ratio, TPixel color)
public ColorStop(float ratio, in Color color)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love that we can now use readonly structs here.

{
this.Ratio = ratio;
this.Color = color;
Expand All @@ -34,6 +32,6 @@ public ColorStop(float ratio, TPixel color)
/// <summary>
/// Gets the color to be used.
/// </summary>
public TPixel Color { get; }
public Color Color { get; }
}
}
Loading