Skip to content

Commit b00b949

Browse files
antonfirsovJimBobSquarePants
authored andcommitted
API cleanup (related to #907) (#911)
* temporarily disable target frameworks * drop DelegateProcessor * drop IImageProcessingContext<TPixel> * drop NamedColors<T> * drop ColorBuilder<T> * drop the *Base postfix for clean class hierarchies * re-enable target frameworks * use MathF in gradient brushes * Move PngFilterMethod to the correct namespace.
1 parent 2b5a575 commit b00b949

60 files changed

Lines changed: 223 additions & 1347 deletions

File tree

Some content is hidden

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

src/ImageSharp.Drawing/Processing/EllipticGradientBrush.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ namespace SixLabors.ImageSharp.Processing
1414
/// a point on the longest extension of the ellipse and
1515
/// the ratio between longest and shortest extension.
1616
/// </summary>
17-
public sealed class EllipticGradientBrush : GradientBrushBase
17+
public sealed class EllipticGradientBrush : GradientBrush
1818
{
1919
private readonly PointF center;
2020

2121
private readonly PointF referenceAxisEnd;
2222

2323
private readonly float axisRatio;
2424

25-
/// <inheritdoc cref="GradientBrushBase" />
25+
/// <inheritdoc cref="GradientBrush" />
2626
/// <param name="center">The center of the elliptical gradient and 0 for the color stops.</param>
2727
/// <param name="referenceAxisEnd">The end point of the reference axis of the ellipse.</param>
2828
/// <param name="axisRatio">
@@ -60,7 +60,7 @@ public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
6060
this.RepetitionMode);
6161

6262
/// <inheritdoc />
63-
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
63+
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicator<TPixel>
6464
where TPixel : struct, IPixel<TPixel>
6565
{
6666
private readonly PointF center;
@@ -149,8 +149,7 @@ private float AngleBetween(PointF junction, PointF a, PointF b)
149149
{
150150
var vA = a - junction;
151151
var vB = b - junction;
152-
return (float)(Math.Atan2(vB.Y, vB.X)
153-
- Math.Atan2(vA.Y, vA.X));
152+
return MathF.Atan2(vB.Y, vB.X) - MathF.Atan2(vA.Y, vA.X);
154153
}
155154

156155
private float DistanceBetween(
@@ -162,7 +161,7 @@ private float DistanceBetween(
162161

163162
float dY = p1.Y - p2.Y;
164163
float dYsquared = dY * dY;
165-
return (float)Math.Sqrt(dXsquared + dYsquared);
164+
return MathF.Sqrt(dXsquared + dYsquared);
166165
}
167166
}
168167
}

src/ImageSharp.Drawing/Processing/GradientBrushBase.cs renamed to src/ImageSharp.Drawing/Processing/GradientBrush.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ namespace SixLabors.ImageSharp.Processing
1313
/// <summary>
1414
/// Base class for Gradient brushes
1515
/// </summary>
16-
public abstract class GradientBrushBase : IBrush
16+
public abstract class GradientBrush : IBrush
1717
{
1818
/// <inheritdoc cref="IBrush"/>
1919
/// <param name="repetitionMode">Defines how the colors are repeated beyond the interval [0..1]</param>
2020
/// <param name="colorStops">The gradient colors.</param>
21-
protected GradientBrushBase(
21+
protected GradientBrush(
2222
GradientRepetitionMode repetitionMode,
2323
params ColorStop[] colorStops)
2424
{
@@ -46,7 +46,7 @@ public abstract BrushApplicator<TPixel> CreateApplicator<TPixel>(
4646
/// <summary>
4747
/// Base class for gradient brush applicators
4848
/// </summary>
49-
internal abstract class GradientBrushApplicatorBase<TPixel> : BrushApplicator<TPixel>
49+
internal abstract class GradientBrushApplicator<TPixel> : BrushApplicator<TPixel>
5050
where TPixel : struct, IPixel<TPixel>
5151
{
5252
private static readonly TPixel Transparent = Color.Transparent.ToPixel<TPixel>();
@@ -56,13 +56,13 @@ internal abstract class GradientBrushApplicatorBase<TPixel> : BrushApplicator<TP
5656
private readonly GradientRepetitionMode repetitionMode;
5757

5858
/// <summary>
59-
/// Initializes a new instance of the <see cref="GradientBrushApplicatorBase{TPixel}"/> class.
59+
/// Initializes a new instance of the <see cref="GradientBrushApplicator{TPixel}"/> class.
6060
/// </summary>
6161
/// <param name="target">The target.</param>
6262
/// <param name="options">The options.</param>
6363
/// <param name="colorStops">An array of color stops sorted by their position.</param>
6464
/// <param name="repetitionMode">Defines if and how the gradient should be repeated.</param>
65-
protected GradientBrushApplicatorBase(
65+
protected GradientBrushApplicator(
6666
ImageFrame<TPixel> target,
6767
GraphicsOptions options,
6868
ColorStop[] colorStops,

src/ImageSharp.Drawing/Processing/LinearGradientBrush.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Processing
1313
/// Supported right now:
1414
/// - a set of colors in relative distances to each other.
1515
/// </summary>
16-
public sealed class LinearGradientBrush : GradientBrushBase
16+
public sealed class LinearGradientBrush : GradientBrush
1717
{
1818
private readonly PointF p1;
1919

@@ -53,7 +53,7 @@ public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
5353
/// <summary>
5454
/// The linear gradient brush applicator.
5555
/// </summary>
56-
private sealed class LinearGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
56+
private sealed class LinearGradientBrushApplicator<TPixel> : GradientBrushApplicator<TPixel>
5757
where TPixel : struct, IPixel<TPixel>
5858
{
5959
private readonly PointF start;
@@ -121,7 +121,7 @@ public LinearGradientBrushApplicator(
121121

122122
// some helpers:
123123
this.alongsSquared = (this.alongX * this.alongX) + (this.alongY * this.alongY);
124-
this.length = (float)Math.Sqrt(this.alongsSquared);
124+
this.length = MathF.Sqrt(this.alongsSquared);
125125
}
126126

127127
protected override float PositionOnGradient(float x, float y)
@@ -145,7 +145,7 @@ protected override float PositionOnGradient(float x, float y)
145145
float y4 = y + (k * this.alongX);
146146

147147
// get distance from (x4,y4) to start
148-
float distance = (float)Math.Sqrt(Math.Pow(x4 - this.start.X, 2) + Math.Pow(y4 - this.start.Y, 2));
148+
float distance = MathF.Sqrt(MathF.Pow(x4 - this.start.X, 2) + MathF.Pow(y4 - this.start.Y, 2));
149149

150150
// get and return ratio
151151
float ratio = distance / this.length;

src/ImageSharp.Drawing/Processing/RadialGradientBrush.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ namespace SixLabors.ImageSharp.Processing
1111
/// <summary>
1212
/// A Circular Gradient Brush, defined by center point and radius.
1313
/// </summary>
14-
public sealed class RadialGradientBrush : GradientBrushBase
14+
public sealed class RadialGradientBrush : GradientBrush
1515
{
1616
private readonly PointF center;
1717

1818
private readonly float radius;
1919

20-
/// <inheritdoc cref="GradientBrushBase" />
20+
/// <inheritdoc cref="GradientBrush" />
2121
/// <param name="center">The center of the circular gradient and 0 for the color stops.</param>
2222
/// <param name="radius">The radius of the circular gradient and 1 for the color stops.</param>
2323
/// <param name="repetitionMode">Defines how the colors in the gradient are repeated.</param>
@@ -47,7 +47,7 @@ public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
4747
this.RepetitionMode);
4848

4949
/// <inheritdoc />
50-
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
50+
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicator<TPixel>
5151
where TPixel : struct, IPixel<TPixel>
5252
{
5353
private readonly PointF center;
@@ -90,7 +90,7 @@ public override void Dispose()
9090
/// <returns>the position on the color gradient.</returns>
9191
protected override float PositionOnGradient(float x, float y)
9292
{
93-
float distance = (float)Math.Sqrt(Math.Pow(this.center.X - x, 2) + Math.Pow(this.center.Y - y, 2));
93+
float distance = MathF.Sqrt(MathF.Pow(this.center.X - x, 2) + MathF.Pow(this.center.Y - y, 2));
9494
return distance / this.radius;
9595
}
9696

src/ImageSharp/Color/Color.cs

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,11 @@ private Color(byte r, byte g, byte b)
104104
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
105105
/// </param>
106106
/// <returns>Returns a <see cref="Color"/> that represents the color defined by the provided RGBA hex string.</returns>
107+
[MethodImpl(InliningOptions.ShortMethod)]
107108
public static Color FromHex(string hex)
108109
{
109-
Guard.NotNullOrWhiteSpace(hex, nameof(hex));
110-
111-
hex = ToRgbaHex(hex);
112-
113-
if (hex is null || !uint.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint packedValue))
114-
{
115-
throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex));
116-
}
110+
Rgba32 rgba = Rgba32.FromHex(hex);
117111

118-
var rgba = new Rgba32(BinaryPrimitives.ReverseEndianness(packedValue));
119112
return new Color(rgba);
120113
}
121114

@@ -189,42 +182,5 @@ internal static void ToPixel<TPixel>(
189182
ReadOnlySpan<Rgba64> rgba64Span = MemoryMarshal.Cast<Color, Rgba64>(source);
190183
PixelOperations<TPixel>.Instance.FromRgba64(Configuration.Default, rgba64Span, destination);
191184
}
192-
193-
/// <summary>
194-
/// Converts the specified hex value to an rrggbbaa hex value.
195-
/// </summary>
196-
/// <param name="hex">The hex value to convert.</param>
197-
/// <returns>
198-
/// A rrggbbaa hex value.
199-
/// </returns>
200-
private static string ToRgbaHex(string hex)
201-
{
202-
if (hex[0] == '#')
203-
{
204-
hex = hex.Substring(1);
205-
}
206-
207-
if (hex.Length == 8)
208-
{
209-
return hex;
210-
}
211-
212-
if (hex.Length == 6)
213-
{
214-
return hex + "FF";
215-
}
216-
217-
if (hex.Length < 3 || hex.Length > 4)
218-
{
219-
return null;
220-
}
221-
222-
char r = hex[0];
223-
char g = hex[1];
224-
char b = hex[2];
225-
char a = hex.Length == 3 ? 'F' : hex[3];
226-
227-
return new string(new[] { r, r, g, g, b, b, a, a });
228-
}
229185
}
230186
}

src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public void Convert(ReadOnlySpan<YCbCr> source, Span<CieXyz> destination)
465465
/// </summary>
466466
/// <param name="workingSpace">The source working space</param>
467467
/// <returns>The <see cref="LinearRgbToCieXyzConverter"/></returns>
468-
private LinearRgbToCieXyzConverter GetLinearRgbToCieXyzConverter(RgbWorkingSpaceBase workingSpace)
468+
private LinearRgbToCieXyzConverter GetLinearRgbToCieXyzConverter(RgbWorkingSpace workingSpace)
469469
{
470470
if (this.linearRgbToCieXyzConverter?.SourceWorkingSpace.Equals(workingSpace) == true)
471471
{

src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public partial class ColorSpaceConverter
1818
private readonly CieXyz targetLuvWhitePoint;
1919
private readonly CieXyz targetLabWhitePoint;
2020
private readonly CieXyz targetHunterLabWhitePoint;
21-
private readonly RgbWorkingSpaceBase targetRgbWorkingSpace;
21+
private readonly RgbWorkingSpace targetRgbWorkingSpace;
2222
private readonly IChromaticAdaptation chromaticAdaptation;
2323
private readonly bool performChromaticAdaptation;
2424
private readonly CieXyzAndLmsConverter cieXyzAndLmsConverter;

src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverterOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ColorSpaceConverterOptions
4040
/// Gets or sets the target working space used *when creating* RGB colors. (RGB colors on the input already contain the working space information)
4141
/// Defaults to: <see cref="Rgb.DefaultWorkingSpace"/>.
4242
/// </summary>
43-
public RgbWorkingSpaceBase TargetRgbWorkingSpace { get; set; } = Rgb.DefaultWorkingSpace;
43+
public RgbWorkingSpace TargetRgbWorkingSpace { get; set; } = Rgb.DefaultWorkingSpace;
4444

4545
/// <summary>
4646
/// Gets or sets the chromatic adaptation method used. When <value>null</value>, no adaptation will be performed.

src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToLinearRgbConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public CieXyzToLinearRgbConverter()
2525
/// Initializes a new instance of the <see cref="CieXyzToLinearRgbConverter"/> class.
2626
/// </summary>
2727
/// <param name="workingSpace">The target working space.</param>
28-
public CieXyzToLinearRgbConverter(RgbWorkingSpaceBase workingSpace)
28+
public CieXyzToLinearRgbConverter(RgbWorkingSpace workingSpace)
2929
{
3030
this.TargetWorkingSpace = workingSpace;
3131

@@ -38,7 +38,7 @@ public CieXyzToLinearRgbConverter(RgbWorkingSpaceBase workingSpace)
3838
/// <summary>
3939
/// Gets the target working space.
4040
/// </summary>
41-
public RgbWorkingSpaceBase TargetWorkingSpace { get; }
41+
public RgbWorkingSpace TargetWorkingSpace { get; }
4242

4343
/// <summary>
4444
/// Performs the conversion from the <see cref="CieXyz"/> input to an instance of <see cref="LinearRgb"/> type.

src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbAndCieXyzConverterBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal abstract class LinearRgbAndCieXyzConverterBase
1515
/// </summary>
1616
/// <param name="workingSpace">The Rgb working space.</param>
1717
/// <returns>The <see cref="Matrix4x4"/> based on the chromaticity and working space.</returns>
18-
public static Matrix4x4 GetRgbToCieXyzMatrix(RgbWorkingSpaceBase workingSpace)
18+
public static Matrix4x4 GetRgbToCieXyzMatrix(RgbWorkingSpace workingSpace)
1919
{
2020
DebugGuard.NotNull(workingSpace, nameof(workingSpace));
2121
RgbPrimariesChromaticityCoordinates chromaticity = workingSpace.ChromaticityCoordinates;

0 commit comments

Comments
 (0)