Skip to content

Enforce Explicit Types and Target Type new #2951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions src/ImageSharp/Advanced/ParallelExecutionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public ParallelExecutionSettings MultiplyMinimumPixelsPerTask(int multiplier)
{
Guard.MustBeGreaterThan(multiplier, 0, nameof(multiplier));

return new ParallelExecutionSettings(
return new(
this.MaxDegreeOfParallelism,
this.MinimumPixelsProcessedPerTask * multiplier,
this.MemoryAllocator);
Expand All @@ -92,6 +92,6 @@ public ParallelExecutionSettings MultiplyMinimumPixelsPerTask(int multiplier)
/// <returns>The <see cref="ParallelExecutionSettings"/>.</returns>
public static ParallelExecutionSettings FromConfiguration(Configuration configuration)
{
return new ParallelExecutionSettings(configuration.MaxDegreeOfParallelism, configuration.MemoryAllocator);
return new(configuration.MaxDegreeOfParallelism, configuration.MemoryAllocator);
}
}
4 changes: 2 additions & 2 deletions src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void Invoke(int i)
}

int yMax = Math.Min(yMin + this.stepY, this.maxY);
var rows = new RowInterval(yMin, yMax);
RowInterval rows = new RowInterval(yMin, yMax);

// Skip the safety copy when invoking a potentially impure method on a readonly field
Unsafe.AsRef(in this.operation).Invoke(in rows);
Expand Down Expand Up @@ -185,7 +185,7 @@ public void Invoke(int i)
}

int yMax = Math.Min(yMin + this.stepY, this.maxY);
var rows = new RowInterval(yMin, yMax);
RowInterval rows = new RowInterval(yMin, yMax);

using IMemoryOwner<TBuffer> buffer = this.allocator.Allocate<TBuffer>(this.bufferLength);

Expand Down
28 changes: 14 additions & 14 deletions src/ImageSharp/Advanced/ParallelRowIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static partial class ParallelRowIterator
public static void IterateRows<T>(Configuration configuration, Rectangle rectangle, in T operation)
where T : struct, IRowOperation
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRows(rectangle, in parallelSettings, in operation);
}

Expand Down Expand Up @@ -65,8 +65,8 @@ public static void IterateRows<T>(
}

int verticalStep = DivideCeil(rectangle.Height, numOfSteps);
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
var wrappingOperation = new RowOperationWrapper<T>(top, bottom, verticalStep, in operation);
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = numOfSteps };
RowOperationWrapper<T> wrappingOperation = new(top, bottom, verticalStep, in operation);

Parallel.For(
0,
Expand All @@ -88,7 +88,7 @@ public static void IterateRows<T, TBuffer>(Configuration configuration, Rectangl
where T : struct, IRowOperation<TBuffer>
where TBuffer : unmanaged
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRows<T, TBuffer>(rectangle, in parallelSettings, in operation);
}

Expand Down Expand Up @@ -135,8 +135,8 @@ public static void IterateRows<T, TBuffer>(
}

int verticalStep = DivideCeil(height, numOfSteps);
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
var wrappingOperation = new RowOperationWrapper<T, TBuffer>(top, bottom, verticalStep, bufferLength, allocator, in operation);
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = numOfSteps };
RowOperationWrapper<T, TBuffer> wrappingOperation = new(top, bottom, verticalStep, bufferLength, allocator, in operation);

Parallel.For(
0,
Expand All @@ -156,7 +156,7 @@ public static void IterateRows<T, TBuffer>(
public static void IterateRowIntervals<T>(Configuration configuration, Rectangle rectangle, in T operation)
where T : struct, IRowIntervalOperation
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRowIntervals(rectangle, in parallelSettings, in operation);
}

Expand Down Expand Up @@ -186,14 +186,14 @@ public static void IterateRowIntervals<T>(
// Avoid TPL overhead in this trivial case:
if (numOfSteps == 1)
{
var rows = new RowInterval(top, bottom);
RowInterval rows = new(top, bottom);
Unsafe.AsRef(in operation).Invoke(in rows);
return;
}

int verticalStep = DivideCeil(rectangle.Height, numOfSteps);
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
var wrappingOperation = new RowIntervalOperationWrapper<T>(top, bottom, verticalStep, in operation);
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = numOfSteps };
RowIntervalOperationWrapper<T> wrappingOperation = new(top, bottom, verticalStep, in operation);

Parallel.For(
0,
Expand All @@ -215,7 +215,7 @@ public static void IterateRowIntervals<T, TBuffer>(Configuration configuration,
where T : struct, IRowIntervalOperation<TBuffer>
where TBuffer : unmanaged
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRowIntervals<T, TBuffer>(rectangle, in parallelSettings, in operation);
}

Expand Down Expand Up @@ -250,7 +250,7 @@ public static void IterateRowIntervals<T, TBuffer>(
// Avoid TPL overhead in this trivial case:
if (numOfSteps == 1)
{
var rows = new RowInterval(top, bottom);
RowInterval rows = new(top, bottom);
using IMemoryOwner<TBuffer> buffer = allocator.Allocate<TBuffer>(bufferLength);

Unsafe.AsRef(in operation).Invoke(in rows, buffer.Memory.Span);
Expand All @@ -259,8 +259,8 @@ public static void IterateRowIntervals<T, TBuffer>(
}

int verticalStep = DivideCeil(height, numOfSteps);
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
var wrappingOperation = new RowIntervalOperationWrapper<T, TBuffer>(top, bottom, verticalStep, bufferLength, allocator, in operation);
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = numOfSteps };
RowIntervalOperationWrapper<T, TBuffer> wrappingOperation = new(top, bottom, verticalStep, bufferLength, allocator, in operation);

Parallel.For(
0,
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Color/Color.WebSafePalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp;
/// </content>
public partial struct Color
{
private static readonly Lazy<Color[]> WebSafePaletteLazy = new Lazy<Color[]>(CreateWebSafePalette, true);
private static readonly Lazy<Color[]> WebSafePaletteLazy = new(CreateWebSafePalette, true);

/// <summary>
/// Gets a collection of named, web safe colors as defined in the CSS Color Module Level 4.
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/ColorProfiles/CieLab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Vector4 ToScaledVector4()
v3 += this.AsVector3Unsafe();
v3 += new Vector3(0, 128F, 128F);
v3 /= new Vector3(100F, 255F, 255F);
return new Vector4(v3, 1F);
return new(v3, 1F);
}

/// <inheritdoc/>
Expand All @@ -97,7 +97,7 @@ public static CieLab FromScaledVector4(Vector4 source)
Vector3 v3 = source.AsVector3();
v3 *= new Vector3(100F, 255, 255);
v3 -= new Vector3(0, 128F, 128F);
return new CieLab(v3);
return new(v3);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -145,7 +145,7 @@ public static CieLab FromProfileConnectingSpace(ColorConversionOptions options,
float a = 500F * (fx - fy);
float b = 200F * (fy - fz);

return new CieLab(l, a, b);
return new(l, a, b);
}

/// <inheritdoc/>
Expand Down
10 changes: 5 additions & 5 deletions src/ImageSharp/ColorProfiles/CieLch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.ColorProfiles;
/// <param name="h">The hue in degrees.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CieLch(float l, float c, float h)
: this(new Vector3(l, c, h))
: this(new(l, c, h))
{
}

Expand Down Expand Up @@ -100,7 +100,7 @@ public Vector4 ToScaledVector4()
v3 += this.AsVector3Unsafe();
v3 += new Vector3(0, 200, 0);
v3 /= new Vector3(100, 400, 360);
return new Vector4(v3, 1F);
return new(v3, 1F);
}

/// <inheritdoc/>
Expand All @@ -109,7 +109,7 @@ public static CieLch FromScaledVector4(Vector4 source)
Vector3 v3 = source.AsVector3();
v3 *= new Vector3(100, 400, 360);
v3 -= new Vector3(0, 200, 0);
return new CieLch(v3, true);
return new(v3, true);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -155,7 +155,7 @@ public static CieLch FromProfileConnectingSpace(ColorConversionOptions options,
hDegrees += 360;
}

return new CieLch(l, c, hDegrees);
return new(l, c, hDegrees);
}

/// <inheritdoc/>
Expand All @@ -181,7 +181,7 @@ public CieLab ToProfileConnectingSpace(ColorConversionOptions options)
float a = c * MathF.Cos(hRadians);
float b = c * MathF.Sin(hRadians);

return new CieLab(l, a, b);
return new(l, a, b);
}

/// <inheritdoc/>
Expand Down
8 changes: 4 additions & 4 deletions src/ImageSharp/ColorProfiles/CieLchuv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.ColorProfiles;
/// <param name="h">The hue in degrees.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CieLchuv(float l, float c, float h)
: this(new Vector3(l, c, h))
: this(new(l, c, h))
{
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public Vector4 ToScaledVector4()
v3 += this.AsVector3Unsafe();
v3 += new Vector3(0, 200, 0);
v3 /= new Vector3(100, 400, 360);
return new Vector4(v3, 1F);
return new(v3, 1F);
}

/// <inheritdoc/>
Expand All @@ -106,7 +106,7 @@ public static CieLchuv FromScaledVector4(Vector4 source)
Vector3 v3 = source.AsVector3();
v3 *= new Vector3(100, 400, 360);
v3 -= new Vector3(0, 200, 0);
return new CieLchuv(v3, true);
return new(v3, true);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -154,7 +154,7 @@ public static CieLchuv FromProfileConnectingSpace(ColorConversionOptions options
hDegrees += 360;
}

return new CieLchuv(l, c, hDegrees);
return new(l, c, hDegrees);
}

/// <inheritdoc/>
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp/ColorProfiles/CieLuv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static CieLuv FromProfileConnectingSpace(ColorConversionOptions options,
v = 0;
}

return new CieLuv((float)l, (float)u, (float)v);
return new((float)l, (float)u, (float)v);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -188,7 +188,7 @@ public CieXyz ToProfileConnectingSpace(ColorConversionOptions options)
z = 0;
}

return new CieXyz((float)x, (float)y, (float)z);
return new((float)x, (float)y, (float)z);
}

/// <inheritdoc/>
Expand Down
8 changes: 4 additions & 4 deletions src/ImageSharp/ColorProfiles/CieXyy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ public static CieXyy FromProfileConnectingSpace(ColorConversionOptions options,

if (float.IsNaN(x) || float.IsNaN(y))
{
return new CieXyy(0, 0, source.Y);
return new(0, 0, source.Y);
}

return new CieXyy(x, y, source.Y);
return new(x, y, source.Y);
}

/// <inheritdoc/>
Expand All @@ -144,14 +144,14 @@ public CieXyz ToProfileConnectingSpace(ColorConversionOptions options)
{
if (MathF.Abs(this.Y) < Constants.Epsilon)
{
return new CieXyz(0, 0, this.Yl);
return new(0, 0, this.Yl);
}

float x = (this.X * this.Yl) / this.Y;
float y = this.Yl;
float z = ((1 - this.X - this.Y) * y) / this.Y;

return new CieXyz(x, y, z);
return new(x, y, z);
}

/// <inheritdoc/>
Expand Down
8 changes: 4 additions & 4 deletions src/ImageSharp/ColorProfiles/CieXyz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal Vector4 ToVector4()
{
Vector3 v3 = default;
v3 += this.AsVector3Unsafe();
return new Vector4(v3, 1F);
return new(v3, 1F);
}

/// <inheritdoc/>
Expand All @@ -97,21 +97,21 @@ public Vector4 ToScaledVector4()
Vector3 v3 = default;
v3 += this.AsVector3Unsafe();
v3 *= 32768F / 65535;
return new Vector4(v3, 1F);
return new(v3, 1F);
}

internal static CieXyz FromVector4(Vector4 source)
{
Vector3 v3 = source.AsVector3();
return new CieXyz(v3);
return new(v3);
}

/// <inheritdoc/>
public static CieXyz FromScaledVector4(Vector4 source)
{
Vector3 v3 = source.AsVector3();
v3 *= 65535 / 32768F;
return new CieXyz(v3);
return new(v3);
}

/// <inheritdoc/>
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/ColorProfiles/Cmyk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.ColorProfiles;
/// <param name="k">The keyline black component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Cmyk(float c, float m, float y, float k)
: this(new Vector4(c, m, y, k))
: this(new(c, m, y, k))
{
}

Expand Down Expand Up @@ -138,12 +138,12 @@ public static Cmyk FromProfileConnectingSpace(ColorConversionOptions options, in

if (k.X >= 1F - Constants.Epsilon)
{
return new Cmyk(0, 0, 0, 1F);
return new(0, 0, 0, 1F);
}

cmy = (cmy - k) / (Vector3.One - k);

return new Cmyk(cmy.X, cmy.Y, cmy.Z, k.X);
return new(cmy.X, cmy.Y, cmy.Z, k.X);
}

/// <inheritdoc/>
Expand Down
Loading
Loading