Skip to content

Commit 5f971c7

Browse files
Merge branch 'main' into js/fix-2866-v4
2 parents 583d89e + ba61e04 commit 5f971c7

File tree

245 files changed

+8349
-3233
lines changed

Some content is hidden

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

245 files changed

+8349
-3233
lines changed

.editorconfig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:war
104104
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
105105
dotnet_style_parentheses_in_other_operators = always_for_clarity:suggestion
106106
# Expression-level preferences
107-
dotnet_style_object_initializer = true:warning
108-
dotnet_style_collection_initializer = true:warning
107+
dotnet_style_object_initializer = true:error
108+
dotnet_style_collection_initializer = true:error
109109
dotnet_style_explicit_tuple_names = true:warning
110110
dotnet_style_prefer_inferred_tuple_names = true:warning
111111
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
@@ -135,9 +135,9 @@ csharp_style_prefer_null_check_over_type_check = true:warning
135135
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#c-style-rules
136136
[*.{cs,csx,cake}]
137137
# 'var' preferences
138-
csharp_style_var_for_built_in_types = false:warning
139-
csharp_style_var_when_type_is_apparent = false:warning
140-
csharp_style_var_elsewhere = false:warning
138+
csharp_style_var_for_built_in_types = false:error
139+
csharp_style_var_when_type_is_apparent = false:error
140+
csharp_style_var_elsewhere = false:error
141141
# Expression-bodied members
142142
csharp_style_expression_bodied_methods = true:warning
143143
csharp_style_expression_bodied_constructors = true:warning
@@ -160,7 +160,7 @@ csharp_style_pattern_local_over_anonymous_function = true:warning
160160
csharp_style_deconstructed_variable_declaration = true:warning
161161
csharp_style_prefer_index_operator = true:warning
162162
csharp_style_prefer_range_operator = true:warning
163-
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
163+
csharp_style_implicit_object_creation_when_type_is_apparent = true:error
164164
# "Null" checking preferences
165165
csharp_style_throw_expression = true:warning
166166
csharp_style_conditional_delegate_call = true:warning

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,10 @@
136136
*.ico filter=lfs diff=lfs merge=lfs -text
137137
*.cur filter=lfs diff=lfs merge=lfs -text
138138
*.ani filter=lfs diff=lfs merge=lfs -text
139+
*.heic filter=lfs diff=lfs merge=lfs -text
140+
*.hif filter=lfs diff=lfs merge=lfs -text
141+
*.avif filter=lfs diff=lfs merge=lfs -text
142+
###############################################################################
143+
# Handle ICC files by git lfs
144+
###############################################################################
145+
*.icc filter=lfs diff=lfs merge=lfs -text

src/ImageSharp/ColorProfiles/CieLab.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public CieLab(float l, float a, float b)
3535
/// <param name="vector">The vector representing the l, a, b components.</param>
3636
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3737
public CieLab(Vector3 vector)
38-
: this()
3938
{
4039
this.L = vector.X;
4140
this.A = vector.Y;
@@ -82,6 +81,49 @@ public CieLab(Vector3 vector)
8281
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8382
public static bool operator !=(CieLab left, CieLab right) => !left.Equals(right);
8483

84+
/// <inheritdoc/>
85+
public Vector4 ToScaledVector4()
86+
{
87+
Vector3 v3 = default;
88+
v3 += this.AsVector3Unsafe();
89+
v3 += new Vector3(0, 128F, 128F);
90+
v3 /= new Vector3(100F, 255F, 255F);
91+
return new Vector4(v3, 1F);
92+
}
93+
94+
/// <inheritdoc/>
95+
public static CieLab FromScaledVector4(Vector4 source)
96+
{
97+
Vector3 v3 = source.AsVector3();
98+
v3 *= new Vector3(100F, 255, 255);
99+
v3 -= new Vector3(0, 128F, 128F);
100+
return new CieLab(v3);
101+
}
102+
103+
/// <inheritdoc/>
104+
public static void ToScaledVector4(ReadOnlySpan<CieLab> source, Span<Vector4> destination)
105+
{
106+
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
107+
108+
// TODO: Optimize via SIMD
109+
for (int i = 0; i < source.Length; i++)
110+
{
111+
destination[i] = source[i].ToScaledVector4();
112+
}
113+
}
114+
115+
/// <inheritdoc/>
116+
public static void FromScaledVector4(ReadOnlySpan<Vector4> source, Span<CieLab> destination)
117+
{
118+
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
119+
120+
// TODO: Optimize via SIMD
121+
for (int i = 0; i < source.Length; i++)
122+
{
123+
destination[i] = FromScaledVector4(source[i]);
124+
}
125+
}
126+
85127
/// <inheritdoc/>
86128
[MethodImpl(MethodImplOptions.AggressiveInlining)]
87129
public static CieLab FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source)
@@ -136,7 +178,7 @@ public CieXyz ToProfileConnectingSpace(ColorConversionOptions options)
136178
float yr = l > CieConstants.Kappa * CieConstants.Epsilon ? Numerics.Pow3((l + 16F) / 116F) : l / CieConstants.Kappa;
137179
float zr = fz3 > CieConstants.Epsilon ? fz3 : ((116F * fz) - 16F) / CieConstants.Kappa;
138180

139-
CieXyz whitePoint = options.WhitePoint;
181+
CieXyz whitePoint = options.SourceWhitePoint;
140182
Vector3 wxyz = new(whitePoint.X, whitePoint.Y, whitePoint.Z);
141183
Vector3 xyzr = new(xr, yr, zr);
142184

src/ImageSharp/ColorProfiles/CieLch.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public CieLch(Vector3 vector)
4242
this.H = vector.Z;
4343
}
4444

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+
4556
/// <summary>
4657
/// Gets the lightness dimension.
4758
/// <remarks>A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).</remarks>
@@ -50,7 +61,7 @@ public CieLch(Vector3 vector)
5061

5162
/// <summary>
5263
/// Gets the a chroma component.
53-
/// <remarks>A value ranging from 0 to 200.</remarks>
64+
/// <remarks>A value ranging from -200 to 200.</remarks>
5465
/// </summary>
5566
public float C { get; }
5667

@@ -82,6 +93,49 @@ public CieLch(Vector3 vector)
8293
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8394
public static bool operator !=(CieLch left, CieLch right) => !left.Equals(right);
8495

96+
/// <inheritdoc/>
97+
public Vector4 ToScaledVector4()
98+
{
99+
Vector3 v3 = default;
100+
v3 += this.AsVector3Unsafe();
101+
v3 += new Vector3(0, 200, 0);
102+
v3 /= new Vector3(100, 400, 360);
103+
return new Vector4(v3, 1F);
104+
}
105+
106+
/// <inheritdoc/>
107+
public static CieLch FromScaledVector4(Vector4 source)
108+
{
109+
Vector3 v3 = source.AsVector3();
110+
v3 *= new Vector3(100, 400, 360);
111+
v3 -= new Vector3(0, 200, 0);
112+
return new CieLch(v3, true);
113+
}
114+
115+
/// <inheritdoc/>
116+
public static void ToScaledVector4(ReadOnlySpan<CieLch> source, Span<Vector4> destination)
117+
{
118+
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
119+
120+
// TODO: Optimize via SIMD
121+
for (int i = 0; i < source.Length; i++)
122+
{
123+
destination[i] = source[i].ToScaledVector4();
124+
}
125+
}
126+
127+
/// <inheritdoc/>
128+
public static void FromScaledVector4(ReadOnlySpan<Vector4> source, Span<CieLch> destination)
129+
{
130+
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
131+
132+
// TODO: Optimize via SIMD
133+
for (int i = 0; i < source.Length; i++)
134+
{
135+
destination[i] = FromScaledVector4(source[i]);
136+
}
137+
}
138+
85139
/// <inheritdoc/>
86140
public static CieLch FromProfileConnectingSpace(ColorConversionOptions options, in CieLab source)
87141
{

src/ImageSharp/ColorProfiles/CieLchuv.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,23 @@ public CieLchuv(float l, float c, float h)
3535
/// <param name="vector">The vector representing the l, c, h components.</param>
3636
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3737
public CieLchuv(Vector3 vector)
38-
: this()
3938
{
4039
vector = Vector3.Clamp(vector, Min, Max);
4140
this.L = vector.X;
4241
this.C = vector.Y;
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 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+
4655
/// <summary>
4756
/// Gets the lightness dimension.
4857
/// <remarks>A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).</remarks>
@@ -51,7 +60,7 @@ public CieLchuv(Vector3 vector)
5160

5261
/// <summary>
5362
/// Gets the a chroma component.
54-
/// <remarks>A value ranging from 0 to 200.</remarks>
63+
/// <remarks>A value ranging from -200 to 200.</remarks>
5564
/// </summary>
5665
public float C { get; }
5766

@@ -81,6 +90,49 @@ public CieLchuv(Vector3 vector)
8190
/// </returns>
8291
public static bool operator !=(CieLchuv left, CieLchuv right) => !left.Equals(right);
8392

93+
/// <inheritdoc/>
94+
public Vector4 ToScaledVector4()
95+
{
96+
Vector3 v3 = default;
97+
v3 += this.AsVector3Unsafe();
98+
v3 += new Vector3(0, 200, 0);
99+
v3 /= new Vector3(100, 400, 360);
100+
return new Vector4(v3, 1F);
101+
}
102+
103+
/// <inheritdoc/>
104+
public static CieLchuv FromScaledVector4(Vector4 source)
105+
{
106+
Vector3 v3 = source.AsVector3();
107+
v3 *= new Vector3(100, 400, 360);
108+
v3 -= new Vector3(0, 200, 0);
109+
return new CieLchuv(v3, true);
110+
}
111+
112+
/// <inheritdoc/>
113+
public static void ToScaledVector4(ReadOnlySpan<CieLchuv> source, Span<Vector4> destination)
114+
{
115+
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
116+
117+
// TODO: Optimize via SIMD
118+
for (int i = 0; i < source.Length; i++)
119+
{
120+
destination[i] = source[i].ToScaledVector4();
121+
}
122+
}
123+
124+
/// <inheritdoc/>
125+
public static void FromScaledVector4(ReadOnlySpan<Vector4> source, Span<CieLchuv> destination)
126+
{
127+
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
128+
129+
// TODO: Optimize via SIMD
130+
for (int i = 0; i < source.Length; i++)
131+
{
132+
destination[i] = FromScaledVector4(source[i]);
133+
}
134+
}
135+
84136
/// <inheritdoc/>
85137
public static CieLchuv FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source)
86138
{

src/ImageSharp/ColorProfiles/CieLuv.cs

Lines changed: 13 additions & 2 deletions
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;
@@ -84,6 +83,18 @@ public CieLuv(Vector3 vector)
8483
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8584
public static bool operator !=(CieLuv left, CieLuv right) => !left.Equals(right);
8685

86+
/// <inheritdoc/>
87+
public Vector4 ToScaledVector4() => throw new NotImplementedException();
88+
89+
/// <inheritdoc/>
90+
public static CieLuv FromScaledVector4(Vector4 source) => throw new NotImplementedException();
91+
92+
/// <inheritdoc/>
93+
public static void ToScaledVector4(ReadOnlySpan<CieLuv> source, Span<Vector4> destination) => throw new NotImplementedException();
94+
95+
/// <inheritdoc/>
96+
public static void FromScaledVector4(ReadOnlySpan<Vector4> source, Span<CieLuv> destination) => throw new NotImplementedException();
97+
8798
/// <inheritdoc/>
8899
public static CieLuv FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source)
89100
{
@@ -143,7 +154,7 @@ public CieXyz ToProfileConnectingSpace(ColorConversionOptions options)
143154
// Use doubles here for accuracy.
144155
// Conversion algorithm described here:
145156
// http://www.brucelindbloom.com/index.html?Eqn_Luv_to_XYZ.html
146-
CieXyz whitePoint = options.WhitePoint;
157+
CieXyz whitePoint = options.SourceWhitePoint;
147158

148159
double l = this.L, u = this.U, v = this.V;
149160

src/ImageSharp/ColorProfiles/CieXyy.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public CieXyy(float x, float y, float yl)
3535
/// <param name="vector">The vector representing the x, y, Y components.</param>
3636
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3737
public CieXyy(Vector3 vector)
38-
: this()
3938
{
4039
// Not clamping as documentation about this space only indicates "usual" ranges
4140
this.X = vector.X;
@@ -83,6 +82,38 @@ public CieXyy(Vector3 vector)
8382
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8483
public static bool operator !=(CieXyy left, CieXyy right) => !left.Equals(right);
8584

85+
/// <inheritdoc/>
86+
public Vector4 ToScaledVector4()
87+
=> new(this.AsVector3Unsafe(), 1F);
88+
89+
/// <inheritdoc/>
90+
public static CieXyy FromScaledVector4(Vector4 source)
91+
=> new(source.AsVector3());
92+
93+
/// <inheritdoc/>
94+
public static void ToScaledVector4(ReadOnlySpan<CieXyy> source, Span<Vector4> destination)
95+
{
96+
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
97+
98+
// TODO: Optimize via SIMD
99+
for (int i = 0; i < source.Length; i++)
100+
{
101+
destination[i] = source[i].ToScaledVector4();
102+
}
103+
}
104+
105+
/// <inheritdoc/>
106+
public static void FromScaledVector4(ReadOnlySpan<Vector4> source, Span<CieXyy> destination)
107+
{
108+
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
109+
110+
// TODO: Optimize via SIMD
111+
for (int i = 0; i < source.Length; i++)
112+
{
113+
destination[i] = FromScaledVector4(source[i]);
114+
}
115+
}
116+
86117
/// <inheritdoc/>
87118
public static CieXyy FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source)
88119
{

0 commit comments

Comments
 (0)