Skip to content

Commit 1d27038

Browse files
Add luminance color profile type and cleanup
1 parent afbd247 commit 1d27038

20 files changed

Lines changed: 400 additions & 26 deletions

src/ImageSharp/ColorProfiles/CieLab.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Numerics;
55
using System.Runtime.CompilerServices;
66
using System.Runtime.InteropServices;
7-
using System.Runtime.Intrinsics;
87

98
namespace SixLabors.ImageSharp.ColorProfiles;
109

@@ -36,7 +35,6 @@ public CieLab(float l, float a, float b)
3635
/// <param name="vector">The vector representing the l, a, b components.</param>
3736
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3837
public CieLab(Vector3 vector)
39-
: this()
4038
{
4139
this.L = vector.X;
4240
this.A = vector.Y;

src/ImageSharp/ColorProfiles/CieLch.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Numerics;
55
using System.Runtime.CompilerServices;
66
using System.Runtime.InteropServices;
7-
using System.Runtime.Intrinsics;
87

98
namespace SixLabors.ImageSharp.ColorProfiles;
109

@@ -43,6 +42,17 @@ public CieLch(Vector3 vector)
4342
this.H = vector.Z;
4443
}
4544

45+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
46+
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
47+
private CieLch(Vector3 vector, bool _)
48+
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
49+
{
50+
vector = Vector3.Clamp(vector, Min, Max);
51+
this.L = vector.X;
52+
this.C = vector.Y;
53+
this.H = vector.Z;
54+
}
55+
4656
/// <summary>
4757
/// Gets the lightness dimension.
4858
/// <remarks>A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).</remarks>
@@ -99,7 +109,7 @@ public static CieLch FromScaledVector4(Vector4 source)
99109
Vector3 v3 = source.AsVector3();
100110
v3 *= new Vector3(100, 400, 360);
101111
v3 -= new Vector3(0, 200, 0);
102-
return new CieLch(v3);
112+
return new CieLch(v3, true);
103113
}
104114

105115
/// <inheritdoc/>

src/ImageSharp/ColorProfiles/CieLchuv.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Numerics;
55
using System.Runtime.CompilerServices;
66
using System.Runtime.InteropServices;
7-
using System.Runtime.Intrinsics;
87

98
namespace SixLabors.ImageSharp.ColorProfiles;
109

@@ -36,14 +35,23 @@ public CieLchuv(float l, float c, float h)
3635
/// <param name="vector">The vector representing the l, c, h components.</param>
3736
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3837
public CieLchuv(Vector3 vector)
39-
: this()
4038
{
4139
vector = Vector3.Clamp(vector, Min, Max);
4240
this.L = vector.X;
4341
this.C = vector.Y;
4442
this.H = vector.Z;
4543
}
4644

45+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
46+
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
47+
private CieLchuv(Vector3 vector, bool _)
48+
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
49+
{
50+
this.L = vector.X;
51+
this.C = vector.Y;
52+
this.H = vector.Z;
53+
}
54+
4755
/// <summary>
4856
/// Gets the lightness dimension.
4957
/// <remarks>A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).</remarks>
@@ -98,7 +106,7 @@ public static CieLchuv FromScaledVector4(Vector4 source)
98106
Vector3 v3 = source.AsVector3();
99107
v3 *= new Vector3(100, 400, 360);
100108
v3 -= new Vector3(0, 200, 0);
101-
return new CieLchuv(v3);
109+
return new CieLchuv(v3, true);
102110
}
103111

104112
/// <inheritdoc/>

src/ImageSharp/ColorProfiles/CieLuv.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public CieLuv(float l, float u, float v)
3737
/// <param name="vector">The vector representing the l, u, v components.</param>
3838
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3939
public CieLuv(Vector3 vector)
40-
: this()
4140
{
4241
this.L = vector.X;
4342
this.U = vector.Y;

src/ImageSharp/ColorProfiles/CieXyy.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Numerics;
55
using System.Runtime.CompilerServices;
66
using System.Runtime.InteropServices;
7-
using System.Runtime.Intrinsics;
87

98
namespace SixLabors.ImageSharp.ColorProfiles;
109

@@ -36,7 +35,6 @@ public CieXyy(float x, float y, float yl)
3635
/// <param name="vector">The vector representing the x, y, Y components.</param>
3736
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3837
public CieXyy(Vector3 vector)
39-
: this()
4038
{
4139
// Not clamping as documentation about this space only indicates "usual" ranges
4240
this.X = vector.X;

src/ImageSharp/ColorProfiles/CieXyz.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public CieXyz(float x, float y, float z)
3434
/// </summary>
3535
/// <param name="vector">The vector representing the x, y, z components.</param>
3636
public CieXyz(Vector3 vector)
37-
: this()
3837
{
3938
this.X = vector.X;
4039
this.Y = vector.Y;

src/ImageSharp/ColorProfiles/Cmyk.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,18 @@ public Cmyk(float c, float m, float y, float k)
3636
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3737
public Cmyk(Vector4 vector)
3838
{
39-
vector = Numerics.Clamp(vector, Min, Max);
39+
vector = Vector4.Clamp(vector, Min, Max);
40+
this.C = vector.X;
41+
this.M = vector.Y;
42+
this.Y = vector.Z;
43+
this.K = vector.W;
44+
}
45+
46+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
47+
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
48+
private Cmyk(Vector4 vector, bool _)
49+
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
50+
{
4051
this.C = vector.X;
4152
this.M = vector.Y;
4253
this.Y = vector.Z;
@@ -99,7 +110,7 @@ public Vector4 ToScaledVector4()
99110

100111
/// <inheritdoc/>
101112
public static Cmyk FromScaledVector4(Vector4 source)
102-
=> new(source);
113+
=> new(source, true);
103114

104115
/// <inheritdoc/>
105116
public static void ToScaledVector4(ReadOnlySpan<Cmyk> source, Span<Vector4> destination)

src/ImageSharp/ColorProfiles/ColorConversionOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public class ColorConversionOptions
4545
/// </summary>
4646
public RgbWorkingSpace TargetRgbWorkingSpace { get; init; } = KnownRgbWorkingSpaces.SRgb;
4747

48+
/// <summary>
49+
/// Gets the Y (luma) coefficients to use in conversions from RGB.
50+
/// </summary>
51+
public Vector3 YCoefficients { get; init; } = KnownYCoefficients.BT709;
52+
4853
/// <summary>
4954
/// Gets the source ICC profile.
5055
/// </summary>

src/ImageSharp/ColorProfiles/Hsl.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Numerics;
55
using System.Runtime.CompilerServices;
66
using System.Runtime.InteropServices;
7-
using System.Runtime.Intrinsics;
87

98
namespace SixLabors.ImageSharp.ColorProfiles;
109

@@ -42,6 +41,16 @@ public Hsl(Vector3 vector)
4241
this.L = vector.Z;
4342
}
4443

44+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
45+
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
46+
private Hsl(Vector3 vector, bool _)
47+
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
48+
{
49+
this.H = vector.X;
50+
this.S = vector.Y;
51+
this.L = vector.Z;
52+
}
53+
4554
/// <summary>
4655
/// Gets the hue component.
4756
/// <remarks>A value ranging between 0 and 360.</remarks>
@@ -90,7 +99,7 @@ public Vector4 ToScaledVector4()
9099

91100
/// <inheritdoc/>
92101
public static Hsl FromScaledVector4(Vector4 source)
93-
=> new(source.AsVector3() * 360F);
102+
=> new(source.AsVector3() * 360F, true);
94103

95104
/// <inheritdoc/>
96105
public static void ToScaledVector4(ReadOnlySpan<Hsl> source, Span<Vector4> destination)

src/ImageSharp/ColorProfiles/Hsv.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Numerics;
55
using System.Runtime.CompilerServices;
66
using System.Runtime.InteropServices;
7-
using System.Runtime.Intrinsics;
87

98
namespace SixLabors.ImageSharp.ColorProfiles;
109

@@ -42,6 +41,16 @@ public Hsv(Vector3 vector)
4241
this.V = vector.Z;
4342
}
4443

44+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
45+
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
46+
private Hsv(Vector3 vector, bool _)
47+
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
48+
{
49+
this.H = vector.X;
50+
this.S = vector.Y;
51+
this.V = vector.Z;
52+
}
53+
4554
/// <summary>
4655
/// Gets the hue component.
4756
/// <remarks>A value ranging between 0 and 360.</remarks>
@@ -88,7 +97,7 @@ public Vector4 ToScaledVector4()
8897

8998
/// <inheritdoc/>
9099
public static Hsv FromScaledVector4(Vector4 source)
91-
=> new(source.AsVector3() * 360F);
100+
=> new(source.AsVector3() * 360F, true);
92101

93102
/// <inheritdoc/>
94103
public static void ToScaledVector4(ReadOnlySpan<Hsv> source, Span<Vector4> destination)

0 commit comments

Comments
 (0)