Skip to content

Commit 65f0d02

Browse files
authored
Merge pull request SixLabors#910 from SixLabors/af/refactor-drawing
Pixel-agnostic Drawing processors and extensions
2 parents 51d12c5 + 45643d5 commit 65f0d02

File tree

77 files changed

+2998
-3099
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2998
-3099
lines changed

src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939

4040
<ItemGroup>
4141
<AdditionalFiles Include="..\..\standards\stylecop.json" />
42+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
4243
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta0008" />
4344
<PackageReference Include="SixLabors.Shapes" Version="1.0.0-beta0008" />
44-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-rc.114" PrivateAssets="All" />
4545
</ItemGroup>
4646

4747
<PropertyGroup>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<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">
2+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=processing_005Cextensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/ImageSharp.Drawing/Processing/BrushApplicator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal BrushApplicator(ImageFrame<TPixel> target, GraphicsOptions options)
4444
/// <summary>
4545
/// Gets the blend percentage
4646
/// </summary>
47-
protected GraphicsOptions Options { get; private set; }
47+
protected GraphicsOptions Options { get; }
4848

4949
/// <summary>
5050
/// Gets the color for a single pixel.

src/ImageSharp.Drawing/Processing/Brushes.cs

Lines changed: 44 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Processing
88
/// <summary>
99
/// A collection of methods for creating generic brushes.
1010
/// </summary>
11-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
11+
/// <returns>A New <see cref="PatternBrush"/></returns>
1212
public static class Brushes
1313
{
1414
/// <summary>
@@ -94,163 +94,131 @@ public static class Brushes
9494
/// Create as brush that will paint a solid color
9595
/// </summary>
9696
/// <param name="color">The color.</param>
97-
/// <typeparam name="TPixel">The pixel format.</typeparam>
98-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
99-
public static SolidBrush<TPixel> Solid<TPixel>(TPixel color)
100-
where TPixel : struct, IPixel<TPixel>
101-
=> new SolidBrush<TPixel>(color);
97+
/// <returns>A New <see cref="PatternBrush"/></returns>
98+
public static SolidBrush Solid(Color color) => new SolidBrush(color);
10299

103100
/// <summary>
104101
/// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
105102
/// </summary>
106103
/// <param name="foreColor">Color of the foreground.</param>
107-
/// <typeparam name="TPixel">The pixel format.</typeparam>
108-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
109-
public static PatternBrush<TPixel> Percent10<TPixel>(TPixel foreColor)
110-
where TPixel : struct, IPixel<TPixel>
111-
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, Percent10Pattern);
104+
/// <returns>A New <see cref="PatternBrush"/></returns>
105+
public static PatternBrush Percent10(Color foreColor) =>
106+
new PatternBrush(foreColor, Color.Transparent, Percent10Pattern);
112107

113108
/// <summary>
114109
/// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
115110
/// </summary>
116111
/// <param name="foreColor">Color of the foreground.</param>
117112
/// <param name="backColor">Color of the background.</param>
118-
/// <typeparam name="TPixel">The pixel format.</typeparam>
119-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
120-
public static PatternBrush<TPixel> Percent10<TPixel>(TPixel foreColor, TPixel backColor)
121-
where TPixel : struct, IPixel<TPixel>
122-
=> new PatternBrush<TPixel>(foreColor, backColor, Percent10Pattern);
113+
/// <returns>A New <see cref="PatternBrush"/></returns>
114+
public static PatternBrush Percent10(Color foreColor, Color backColor) =>
115+
new PatternBrush(foreColor, backColor, Percent10Pattern);
123116

124117
/// <summary>
125118
/// Create as brush that will paint a Percent20 Hatch Pattern with the specified foreground color and a
126119
/// transparent background.
127120
/// </summary>
128121
/// <param name="foreColor">Color of the foreground.</param>
129-
/// <typeparam name="TPixel">The pixel format.</typeparam>
130-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
131-
public static PatternBrush<TPixel> Percent20<TPixel>(TPixel foreColor)
132-
where TPixel : struct, IPixel<TPixel>
133-
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, Percent20Pattern);
122+
/// <returns>A New <see cref="PatternBrush"/></returns>
123+
public static PatternBrush Percent20(Color foreColor) =>
124+
new PatternBrush(foreColor, Color.Transparent, Percent20Pattern);
134125

135126
/// <summary>
136127
/// Create as brush that will paint a Percent20 Hatch Pattern with the specified colors
137128
/// </summary>
138129
/// <param name="foreColor">Color of the foreground.</param>
139130
/// <param name="backColor">Color of the background.</param>
140-
/// <typeparam name="TPixel">The pixel format.</typeparam>
141-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
142-
public static PatternBrush<TPixel> Percent20<TPixel>(TPixel foreColor, TPixel backColor)
143-
where TPixel : struct, IPixel<TPixel>
144-
=> new PatternBrush<TPixel>(foreColor, backColor, Percent20Pattern);
131+
/// <returns>A New <see cref="PatternBrush"/></returns>
132+
public static PatternBrush Percent20(Color foreColor, Color backColor) =>
133+
new PatternBrush(foreColor, backColor, Percent20Pattern);
145134

146135
/// <summary>
147136
/// Create as brush that will paint a Horizontal Hatch Pattern with the specified foreground color and a
148137
/// transparent background.
149138
/// </summary>
150139
/// <param name="foreColor">Color of the foreground.</param>
151-
/// <typeparam name="TPixel">The pixel format.</typeparam>
152-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
153-
public static PatternBrush<TPixel> Horizontal<TPixel>(TPixel foreColor)
154-
where TPixel : struct, IPixel<TPixel>
155-
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, HorizontalPattern);
140+
/// <returns>A New <see cref="PatternBrush"/></returns>
141+
public static PatternBrush Horizontal(Color foreColor) =>
142+
new PatternBrush(foreColor, Color.Transparent, HorizontalPattern);
156143

157144
/// <summary>
158145
/// Create as brush that will paint a Horizontal Hatch Pattern with the specified colors
159146
/// </summary>
160147
/// <param name="foreColor">Color of the foreground.</param>
161148
/// <param name="backColor">Color of the background.</param>
162-
/// <typeparam name="TPixel">The pixel format.</typeparam>
163-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
164-
public static PatternBrush<TPixel> Horizontal<TPixel>(TPixel foreColor, TPixel backColor)
165-
where TPixel : struct, IPixel<TPixel>
166-
=> new PatternBrush<TPixel>(foreColor, backColor, HorizontalPattern);
149+
/// <returns>A New <see cref="PatternBrush"/></returns>
150+
public static PatternBrush Horizontal(Color foreColor, Color backColor) =>
151+
new PatternBrush(foreColor, backColor, HorizontalPattern);
167152

168153
/// <summary>
169154
/// Create as brush that will paint a Min Hatch Pattern with the specified foreground color and a
170155
/// transparent background.
171156
/// </summary>
172157
/// <param name="foreColor">Color of the foreground.</param>
173-
/// <typeparam name="TPixel">The pixel format.</typeparam>
174-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
175-
public static PatternBrush<TPixel> Min<TPixel>(TPixel foreColor)
176-
where TPixel : struct, IPixel<TPixel>
177-
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, MinPattern);
158+
/// <returns>A New <see cref="PatternBrush"/></returns>
159+
public static PatternBrush Min(Color foreColor) => new PatternBrush(foreColor, Color.Transparent, MinPattern);
178160

179161
/// <summary>
180162
/// Create as brush that will paint a Min Hatch Pattern with the specified colors
181163
/// </summary>
182164
/// <param name="foreColor">Color of the foreground.</param>
183165
/// <param name="backColor">Color of the background.</param>
184-
/// <typeparam name="TPixel">The pixel format.</typeparam>
185-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
186-
public static PatternBrush<TPixel> Min<TPixel>(TPixel foreColor, TPixel backColor)
187-
where TPixel : struct, IPixel<TPixel>
188-
=> new PatternBrush<TPixel>(foreColor, backColor, MinPattern);
166+
/// <returns>A New <see cref="PatternBrush"/></returns>
167+
public static PatternBrush Min(Color foreColor, Color backColor) =>
168+
new PatternBrush(foreColor, backColor, MinPattern);
189169

190170
/// <summary>
191171
/// Create as brush that will paint a Vertical Hatch Pattern with the specified foreground color and a
192172
/// transparent background.
193173
/// </summary>
194174
/// <param name="foreColor">Color of the foreground.</param>
195-
/// <typeparam name="TPixel">The pixel format.</typeparam>
196-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
197-
public static PatternBrush<TPixel> Vertical<TPixel>(TPixel foreColor)
198-
where TPixel : struct, IPixel<TPixel>
199-
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, VerticalPattern);
175+
/// <returns>A New <see cref="PatternBrush"/></returns>
176+
public static PatternBrush Vertical(Color foreColor) =>
177+
new PatternBrush(foreColor, Color.Transparent, VerticalPattern);
200178

201179
/// <summary>
202180
/// Create as brush that will paint a Vertical Hatch Pattern with the specified colors
203181
/// </summary>
204182
/// <param name="foreColor">Color of the foreground.</param>
205183
/// <param name="backColor">Color of the background.</param>
206-
/// <typeparam name="TPixel">The pixel format.</typeparam>
207-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
208-
public static PatternBrush<TPixel> Vertical<TPixel>(TPixel foreColor, TPixel backColor)
209-
where TPixel : struct, IPixel<TPixel>
210-
=> new PatternBrush<TPixel>(foreColor, backColor, VerticalPattern);
184+
/// <returns>A New <see cref="PatternBrush"/></returns>
185+
public static PatternBrush Vertical(Color foreColor, Color backColor) =>
186+
new PatternBrush(foreColor, backColor, VerticalPattern);
211187

212188
/// <summary>
213189
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified foreground color and a
214190
/// transparent background.
215191
/// </summary>
216192
/// <param name="foreColor">Color of the foreground.</param>
217-
/// <typeparam name="TPixel">The pixel format.</typeparam>
218-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
219-
public static PatternBrush<TPixel> ForwardDiagonal<TPixel>(TPixel foreColor)
220-
where TPixel : struct, IPixel<TPixel>
221-
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, ForwardDiagonalPattern);
193+
/// <returns>A New <see cref="PatternBrush"/></returns>
194+
public static PatternBrush ForwardDiagonal(Color foreColor) =>
195+
new PatternBrush(foreColor, Color.Transparent, ForwardDiagonalPattern);
222196

223197
/// <summary>
224198
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified colors
225199
/// </summary>
226200
/// <param name="foreColor">Color of the foreground.</param>
227201
/// <param name="backColor">Color of the background.</param>
228-
/// <typeparam name="TPixel">The pixel format.</typeparam>
229-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
230-
public static PatternBrush<TPixel> ForwardDiagonal<TPixel>(TPixel foreColor, TPixel backColor)
231-
where TPixel : struct, IPixel<TPixel>
232-
=> new PatternBrush<TPixel>(foreColor, backColor, ForwardDiagonalPattern);
202+
/// <returns>A New <see cref="PatternBrush"/></returns>
203+
public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor) =>
204+
new PatternBrush(foreColor, backColor, ForwardDiagonalPattern);
233205

234206
/// <summary>
235207
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified foreground color and a
236208
/// transparent background.
237209
/// </summary>
238210
/// <param name="foreColor">Color of the foreground.</param>
239-
/// <typeparam name="TPixel">The pixel format.</typeparam>
240-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
241-
public static PatternBrush<TPixel> BackwardDiagonal<TPixel>(TPixel foreColor)
242-
where TPixel : struct, IPixel<TPixel>
243-
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, BackwardDiagonalPattern);
211+
/// <returns>A New <see cref="PatternBrush"/></returns>
212+
public static PatternBrush BackwardDiagonal(Color foreColor) =>
213+
new PatternBrush(foreColor, Color.Transparent, BackwardDiagonalPattern);
244214

245215
/// <summary>
246216
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified colors
247217
/// </summary>
248218
/// <param name="foreColor">Color of the foreground.</param>
249219
/// <param name="backColor">Color of the background.</param>
250-
/// <typeparam name="TPixel">The pixel format.</typeparam>
251-
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
252-
public static PatternBrush<TPixel> BackwardDiagonal<TPixel>(TPixel foreColor, TPixel backColor)
253-
where TPixel : struct, IPixel<TPixel>
254-
=> new PatternBrush<TPixel>(foreColor, backColor, BackwardDiagonalPattern);
220+
/// <returns>A New <see cref="PatternBrush"/></returns>
221+
public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor) =>
222+
new PatternBrush(foreColor, backColor, BackwardDiagonalPattern);
255223
}
256224
}

src/ImageSharp.Drawing/Processing/ColorStop{TPixel}.cs renamed to src/ImageSharp.Drawing/Processing/ColorStop.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ namespace SixLabors.ImageSharp.Processing
1010
/// <summary>
1111
/// A struct that defines a single color stop.
1212
/// </summary>
13-
/// <typeparam name="TPixel">The pixel format.</typeparam>
1413
[DebuggerDisplay("ColorStop({Ratio} -> {Color}")]
15-
public struct ColorStop<TPixel>
16-
where TPixel : struct, IPixel<TPixel>
14+
public readonly struct ColorStop
1715
{
1816
/// <summary>
19-
/// Initializes a new instance of the <see cref="ColorStop{TPixel}" /> struct.
17+
/// Initializes a new instance of the <see cref="ColorStop" /> struct.
2018
/// </summary>
2119
/// <param name="ratio">Where should it be? 0 is at the start, 1 at the end of the Gradient.</param>
2220
/// <param name="color">What color should be used at that point?</param>
23-
public ColorStop(float ratio, TPixel color)
21+
public ColorStop(float ratio, in Color color)
2422
{
2523
this.Ratio = ratio;
2624
this.Color = color;
@@ -34,6 +32,6 @@ public ColorStop(float ratio, TPixel color)
3432
/// <summary>
3533
/// Gets the color to be used.
3634
/// </summary>
37-
public TPixel Color { get; }
35+
public Color Color { get; }
3836
}
3937
}

0 commit comments

Comments
 (0)