Skip to content
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

Update to net8 #2583

Merged
merged 20 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 10 additions & 29 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,23 @@ jobs:
- ${{ contains(github.event.pull_request.labels.*.name, 'arch:arm32') || contains(github.event.pull_request.labels.*.name, 'arch:arm64') }}
options:
- os: ubuntu-latest
framework: net7.0
sdk: 7.0.x
sdk-preview: true
framework: net8.0
sdk: 8.0.x
runtime: -x64
codecov: false
- os: macos-latest
framework: net7.0
sdk: 7.0.x
sdk-preview: true
framework: net8.0
sdk: 8.0.x
runtime: -x64
codecov: false
- os: windows-latest
framework: net7.0
sdk: 7.0.x
sdk-preview: true
framework: net8.0
sdk: 8.0.x
runtime: -x64
codecov: false
- os: buildjet-4vcpu-ubuntu-2204-arm
framework: net7.0
sdk: 7.0.x
sdk-preview: true
runtime: -x64
codecov: false
- os: ubuntu-latest
framework: net6.0
sdk: 6.0.x
runtime: -x64
codecov: false
- os: macos-latest
framework: net6.0
sdk: 6.0.x
runtime: -x64
codecov: false
- os: windows-latest
framework: net6.0
sdk: 6.0.x
framework: net8.0
sdk: 8.0.x
runtime: -x64
codecov: false
exclude:
Expand Down Expand Up @@ -111,14 +92,14 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
8.0.x

- name: DotNet Setup Preview
if: ${{ matrix.options.sdk-preview == true }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
7.0.x
8.0.x

- name: DotNet Build
if: ${{ matrix.options.sdk-preview != true }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
matrix:
options:
- os: ubuntu-latest
framework: net6.0
framework: net8.0
runtime: -x64
codecov: true

Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
8.0.x

- name: DotNet Build
shell: pwsh
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Designed to simplify image processing, ImageSharp brings you an incredibly power

ImageSharp is designed from the ground up to be flexible and extensible. The library provides API endpoints for common image processing operations and the building blocks to allow for the development of additional operations.

Built against [.NET 6](https://docs.microsoft.com/en-us/dotnet/standard/net-standard), ImageSharp can be used in device, cloud, and embedded/IoT scenarios.
Built against [.NET 8](https://docs.microsoft.com/en-us/dotnet/standard/net-standard), ImageSharp can be used in device, cloud, and embedded/IoT scenarios.


## License
Expand Down Expand Up @@ -64,7 +64,7 @@ If you prefer, you can compile ImageSharp yourself (please do and help!)

- Using [Visual Studio 2022](https://visualstudio.microsoft.com/vs/)
- Make sure you have the latest version installed
- Make sure you have [the .NET 7 SDK](https://www.microsoft.com/net/core#windows) installed
- Make sure you have [the .NET 8 SDK](https://www.microsoft.com/net/core#windows) installed

Alternatively, you can work from command line and/or with a lightweight editor on **both Linux/Unix and Windows**:

Expand Down
6 changes: 5 additions & 1 deletion src/ImageSharp.ruleset
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="ImageSharp" ToolsVersion="17.0">
<Include Path="..\shared-infrastructure\sixlabors.ruleset" Action="Default" />
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.NetAnalyzers" RuleNamespace="Microsoft.CodeAnalysis.CSharp.NetAnalyzers">
<Rule Id="CA1857" Action="None" />
stefannikolei marked this conversation as resolved.
Show resolved Hide resolved
<Rule Id="CA1859" Action="None" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://learn.microsoft.com/de-de/dotnet/fundamentals/code-analysis/quality-rules/ca1859

I disabled this to get a build without errors. I can remove it and fix all places

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should open up a discussion or issue to track it so it's not forgotten.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had a hack at this. Only 3 changes required in private methods.

</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1011" Action="None" />
</Rules>
</RuleSet>
</RuleSet>
4 changes: 2 additions & 2 deletions src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Invoke(int i)
for (int y = yMin; y < yMax; y++)
{
// Skip the safety copy when invoking a potentially impure method on a readonly field
Unsafe.AsRef(this.action).Invoke(y);
Unsafe.AsRef(in this.action).Invoke(y);
}
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public void Invoke(int i)

for (int y = yMin; y < yMax; y++)
{
Unsafe.AsRef(this.action).Invoke(y, span);
Unsafe.AsRef(in this.action).Invoke(y, span);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/ImageSharp/Advanced/ParallelRowIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void IterateRows<T>(
{
for (int y = top; y < bottom; y++)
{
Unsafe.AsRef(operation).Invoke(y);
Unsafe.AsRef(in operation).Invoke(y);
}

return;
Expand Down Expand Up @@ -118,7 +118,7 @@ public static void IterateRows<T, TBuffer>(
int maxSteps = DivideCeil(width * (long)height, parallelSettings.MinimumPixelsProcessedPerTask);
int numOfSteps = Math.Min(parallelSettings.MaxDegreeOfParallelism, maxSteps);
MemoryAllocator allocator = parallelSettings.MemoryAllocator;
int bufferLength = Unsafe.AsRef(operation).GetRequiredBufferLength(rectangle);
int bufferLength = Unsafe.AsRef(in operation).GetRequiredBufferLength(rectangle);

// Avoid TPL overhead in this trivial case:
if (numOfSteps == 1)
Expand All @@ -128,7 +128,7 @@ public static void IterateRows<T, TBuffer>(

for (int y = top; y < bottom; y++)
{
Unsafe.AsRef(operation).Invoke(y, span);
Unsafe.AsRef(in operation).Invoke(y, span);
}

return;
Expand Down Expand Up @@ -245,15 +245,15 @@ public static void IterateRowIntervals<T, TBuffer>(
int maxSteps = DivideCeil(width * (long)height, parallelSettings.MinimumPixelsProcessedPerTask);
int numOfSteps = Math.Min(parallelSettings.MaxDegreeOfParallelism, maxSteps);
MemoryAllocator allocator = parallelSettings.MemoryAllocator;
int bufferLength = Unsafe.AsRef(operation).GetRequiredBufferLength(rectangle);
int bufferLength = Unsafe.AsRef(in operation).GetRequiredBufferLength(rectangle);

// Avoid TPL overhead in this trivial case:
if (numOfSteps == 1)
{
var rows = new RowInterval(top, bottom);
using IMemoryOwner<TBuffer> buffer = allocator.Allocate<TBuffer>(bufferLength);

Unsafe.AsRef(operation).Invoke(in rows, buffer.Memory.Span);
Unsafe.AsRef(in operation).Invoke(in rows, buffer.Memory.Span);

return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/ImageSharp/Common/Helpers/DebugGuard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public static void IsTrue(bool target, string message)
[Conditional("DEBUG")]
public static void NotDisposed(bool isDisposed, string objectName)
{
#pragma warning disable CA1513
if (isDisposed)
{
throw new ObjectDisposedException(objectName);
}
#pragma warning restore CA1513
}

/// <summary>
Expand Down
19 changes: 0 additions & 19 deletions src/ImageSharp/Common/Helpers/Numerics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -908,25 +908,6 @@ public static int ReduceSum(Vector256<int> accumulator)
return Sse2.ConvertToInt32(vsum);
}

/// <summary>
/// Reduces elements of the vector into one sum.
/// </summary>
/// <param name="accumulator">The accumulator to reduce.</param>
/// <returns>The sum of all elements.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static int ReduceSumArm(Vector128<uint> accumulator)
stefannikolei marked this conversation as resolved.
Show resolved Hide resolved
{
if (AdvSimd.Arm64.IsSupported)
{
Vector64<uint> sum = AdvSimd.Arm64.AddAcross(accumulator);
return (int)AdvSimd.Extract(sum, 0);
}

Vector128<ulong> sum2 = AdvSimd.AddPairwiseWidening(accumulator);
Vector64<uint> sum3 = AdvSimd.Add(sum2.GetLower().AsUInt32(), sum2.GetUpper().AsUInt32());
return (int)AdvSimd.Extract(sum3, 0);
}

/// <summary>
/// Reduces even elements of the vector into one sum.
/// </summary>
Expand Down
5 changes: 1 addition & 4 deletions src/ImageSharp/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ public int StreamProcessingBufferSize
get => this.streamProcessingBufferSize;
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(this.StreamProcessingBufferSize));
}
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(value);

this.streamProcessingBufferSize = value;
}
Expand Down
42 changes: 0 additions & 42 deletions src/ImageSharp/Diagnostics/CodeAnalysis/UnscopedRefAttribute.cs

This file was deleted.

5 changes: 1 addition & 4 deletions src/ImageSharp/Formats/ImageFormatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ public void AddImageFormat(IImageFormat format)

lock (HashLock)
{
if (!this.imageFormats.Contains(format))
{
this.imageFormats.Add(format);
}
this.imageFormats.Add(format);
stefannikolei marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ private void WriteJfifApplicationHeader(ImageMetadata meta, Span<byte> buffer)
/// <exception cref="ArgumentNullException"><paramref name="tableConfigs"/> is <see langword="null"/>.</exception>
private void WriteDefineHuffmanTables(JpegHuffmanTableConfig[] tableConfigs, HuffmanScanEncoder scanEncoder, Span<byte> buffer)
{
if (tableConfigs is null)
{
throw new ArgumentNullException(nameof(tableConfigs));
}
ArgumentNullException.ThrowIfNull(tableConfigs);

int markerlen = 2;

Expand Down
3 changes: 1 addition & 2 deletions src/ImageSharp/Formats/Png/PngDecoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1938,8 +1938,7 @@ private static bool TryReadTextKeyword(ReadOnlySpan<byte> keywordBytes, out stri
// Keywords should not be empty or have leading or trailing whitespace.
name = PngConstants.Encoding.GetString(keywordBytes);
return !string.IsNullOrWhiteSpace(name)
&& !name.StartsWith(" ", StringComparison.Ordinal)
&& !name.EndsWith(" ", StringComparison.Ordinal);
&& !name.StartsWith(' ') && !name.EndsWith(' ');
}

private static bool IsXmpTextData(ReadOnlySpan<byte> keywordBytes)
Expand Down
13 changes: 1 addition & 12 deletions src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,7 @@ private static unsafe int Vp8_Sse16x16_Neon(Span<byte> a, Span<byte> b)
}
}

#if NET7_0_OR_GREATER
return (int)Vector128.Sum(sum);
#else
return Numerics.ReduceSumArm(sum);
#endif
}

[MethodImpl(InliningOptions.ShortMethod)]
Expand All @@ -252,11 +248,7 @@ private static unsafe int Vp8_Sse16x8_Neon(Span<byte> a, Span<byte> b)
}
}

#if NET7_0_OR_GREATER
return (int)Vector128.Sum(sum);
#else
return Numerics.ReduceSumArm(sum);
#endif
}

[MethodImpl(InliningOptions.ShortMethod)]
Expand All @@ -275,11 +267,8 @@ private static int Vp8_Sse4x4_Neon(Span<byte> a, Span<byte> b)
Vector128<uint> sum2 = AdvSimd.AddPairwiseWidening(prod2);

Vector128<uint> sum = AdvSimd.Add(sum1, sum2);
#if NET7_0_OR_GREATER

return (int)Vector128.Sum(sum);
#else
return Numerics.ReduceSumArm(sum);
#endif
}

// Load all 4x4 pixels into a single Vector128<uint>
Expand Down
5 changes: 3 additions & 2 deletions src/ImageSharp/ImageSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<!-- This enables the nullable analysis and treats all nullable warnings as error-->
<PropertyGroup>
<LangVersion>12.0</LangVersion>
stefannikolei marked this conversation as resolved.
Show resolved Hide resolved
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
</PropertyGroup>
Expand All @@ -29,13 +30,13 @@
<Choose>
<When Condition="$(SIXLABORS_TESTING_PREVIEW) == true">
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
</Otherwise>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ public void AddRef()
[MemberNotNull(nameof(Array))]
private void CheckDisposed()
{
#pragma warning disable CA1513
stefannikolei marked this conversation as resolved.
Show resolved Hide resolved
if (this.Array == null)
{
throw new ObjectDisposedException("SharedArrayPoolBuffer");
}
#pragma warning restore CA1513
}

private sealed class LifetimeGuard : RefCountedMemoryLifetimeGuard
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public Abgr32(uint packed)
public uint Abgr
{
[MethodImpl(InliningOptions.ShortMethod)]
readonly get => Unsafe.As<Abgr32, uint>(ref Unsafe.AsRef(this));
readonly get => Unsafe.As<Abgr32, uint>(ref Unsafe.AsRef(in this));

[MethodImpl(InliningOptions.ShortMethod)]
set => Unsafe.As<Abgr32, uint>(ref this) = value;
Expand Down
Loading
Loading