Skip to content

Commit 3719c4d

Browse files
Merge branch 'main' into bp/tiff-jpeg-cmyk
2 parents a65d290 + c19a82e commit 3719c4d

File tree

724 files changed

+18718
-8242
lines changed

Some content is hidden

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

724 files changed

+18718
-8242
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

.github/workflows/build-and-test.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,31 @@ jobs:
1919
isARM:
2020
- ${{ contains(github.event.pull_request.labels.*.name, 'arch:arm32') || contains(github.event.pull_request.labels.*.name, 'arch:arm64') }}
2121
options:
22+
- os: ubuntu-latest
23+
framework: net9.0
24+
sdk: 9.0.x
25+
sdk-preview: true
26+
runtime: -x64
27+
codecov: false
28+
- os: macos-13 # macos-latest runs on arm64 runners where libgdiplus is unavailable
29+
framework: net9.0
30+
sdk: 9.0.x
31+
sdk-preview: true
32+
runtime: -x64
33+
codecov: false
34+
- os: windows-latest
35+
framework: net9.0
36+
sdk: 9.0.x
37+
sdk-preview: true
38+
runtime: -x64
39+
codecov: false
40+
- os: buildjet-4vcpu-ubuntu-2204-arm
41+
framework: net9.0
42+
sdk: 9.0.x
43+
sdk-preview: true
44+
runtime: -x64
45+
codecov: false
46+
2247
- os: ubuntu-latest
2348
framework: net8.0
2449
sdk: 8.0.x
@@ -48,8 +73,10 @@ jobs:
4873

4974
steps:
5075
- name: Install libgdi+, which is required for tests running on ubuntu
51-
if: ${{ matrix.options.os == 'buildjet-4vcpu-ubuntu-2204-arm' }}
52-
run: sudo apt-get -y install libgdiplus libgif-dev libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev
76+
if: ${{ contains(matrix.options.os, 'ubuntu') }}
77+
run: |
78+
sudo apt-get update
79+
sudo apt-get -y install libgdiplus libgif-dev libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev
5380
5481
- name: Git Config
5582
shell: bash
@@ -100,7 +127,7 @@ jobs:
100127
uses: actions/setup-dotnet@v4
101128
with:
102129
dotnet-version: |
103-
8.0.x
130+
9.0.x
104131
105132
- name: DotNet Build
106133
if: ${{ matrix.options.sdk-preview != true }}

.github/workflows/code-coverage.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ jobs:
1717
runs-on: ${{matrix.options.os}}
1818

1919
steps:
20+
21+
- name: Install libgdi+, which is required for tests running on ubuntu
22+
if: ${{ contains(matrix.options.os, 'ubuntu') }}
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get -y install libgdiplus libgif-dev libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev
26+
2027
- name: Git Config
2128
shell: bash
2229
run: |

Directory.Build.props

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
<!-- Import the shared global .props file -->
2222
<Import Project="$(MSBuildThisFileDirectory)shared-infrastructure\msbuild\props\SixLabors.Global.props" />
2323

24-
<PropertyGroup Condition="$(SIXLABORS_TESTING_PREVIEW) == true">
25-
<!-- Workaround various issues bound to implicit language features. -->
26-
<LangVersion>preview</LangVersion>
24+
<PropertyGroup>
25+
<LangVersion>12.0</LangVersion>
2726
</PropertyGroup>
2827

2928
<!--

src/ImageSharp.ruleset

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RuleSet Name="ImageSharp" ToolsVersion="17.0">
33
<Include Path="..\shared-infrastructure\sixlabors.ruleset" Action="Default" />
4+
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.NetAnalyzers" RuleNamespace="Microsoft.CodeAnalysis.CSharp.NetAnalyzers">
5+
<Rule Id="CA2022" Action="Info" />
6+
</Rules>
47
</RuleSet>

src/ImageSharp/Advanced/AotCompilerTools.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ private static void Seed<TPixel>()
138138
AotCompileResamplers<TPixel>();
139139
AotCompileQuantizers<TPixel>();
140140
AotCompilePixelSamplingStrategys<TPixel>();
141+
AotCompilePixelMaps<TPixel>();
141142
AotCompileDithers<TPixel>();
142143
AotCompileMemoryManagers<TPixel>();
143144

144-
Unsafe.SizeOf<TPixel>();
145+
_ = Unsafe.SizeOf<TPixel>();
145146

146147
// TODO: Do the discovery work to figure out what works and what doesn't.
147148
}
@@ -276,11 +277,11 @@ private static void AotCompileImageDecoders<TPixel>()
276277
private static void AotCompileSpectralConverter<TPixel>()
277278
where TPixel : unmanaged, IPixel<TPixel>
278279
{
279-
default(SpectralConverter<TPixel>).GetPixelBuffer(default);
280-
default(GrayJpegSpectralConverter<TPixel>).GetPixelBuffer(default);
281-
default(RgbJpegSpectralConverter<TPixel>).GetPixelBuffer(default);
282-
default(TiffJpegSpectralConverter<TPixel>).GetPixelBuffer(default);
283-
default(TiffOldJpegSpectralConverter<TPixel>).GetPixelBuffer(default);
280+
default(SpectralConverter<TPixel>).GetPixelBuffer(default, default);
281+
default(GrayJpegSpectralConverter<TPixel>).GetPixelBuffer(default, default);
282+
default(RgbJpegSpectralConverter<TPixel>).GetPixelBuffer(default, default);
283+
default(TiffJpegSpectralConverter<TPixel>).GetPixelBuffer(default, default);
284+
default(TiffOldJpegSpectralConverter<TPixel>).GetPixelBuffer(default, default);
284285
}
285286

286287
/// <summary>
@@ -514,6 +515,20 @@ private static void AotCompilePixelSamplingStrategys<TPixel>()
514515
default(ExtensivePixelSamplingStrategy).EnumeratePixelRegions(default(ImageFrame<TPixel>));
515516
}
516517

518+
/// <summary>
519+
/// This method pre-seeds the all <see cref="IColorIndexCache{T}" /> in the AoT compiler.
520+
/// </summary>
521+
/// <typeparam name="TPixel">The pixel format.</typeparam>
522+
[Preserve]
523+
private static void AotCompilePixelMaps<TPixel>()
524+
where TPixel : unmanaged, IPixel<TPixel>
525+
{
526+
default(EuclideanPixelMap<TPixel, HybridCache>).GetClosestColor(default, out _);
527+
default(EuclideanPixelMap<TPixel, AccurateCache>).GetClosestColor(default, out _);
528+
default(EuclideanPixelMap<TPixel, CoarseCache>).GetClosestColor(default, out _);
529+
default(EuclideanPixelMap<TPixel, NullCache>).GetClosestColor(default, out _);
530+
}
531+
517532
/// <summary>
518533
/// This method pre-seeds the all <see cref="IDither" /> in the AoT compiler.
519534
/// </summary>

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
{

0 commit comments

Comments
 (0)