From 560886b3d0775dfb312d1815fc21a4c90089d6f3 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Tue, 12 Sep 2023 10:19:42 +0200 Subject: [PATCH 01/16] Update to net8 --- .github/workflows/build-and-test.yml | 31 ++++---------- .github/workflows/code-coverage.yml | 2 +- README.md | 4 +- src/ImageSharp/Common/Helpers/Numerics.cs | 19 --------- .../CodeAnalysis/UnscopedRefAttribute.cs | 42 ------------------- .../Formats/Webp/Lossy/LossyUtils.cs | 13 +----- src/ImageSharp/ImageSharp.csproj | 4 +- .../ImageSharp.Benchmarks.csproj | 6 +-- .../ImageSharp.Tests.ProfilingSandbox.csproj | 4 +- .../ImageSharp.Tests/ImageSharp.Tests.csproj | 4 +- 10 files changed, 21 insertions(+), 108 deletions(-) delete mode 100644 src/ImageSharp/Diagnostics/CodeAnalysis/UnscopedRefAttribute.cs diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index b375574018..6f9dc1d42b 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -19,44 +19,29 @@ 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 + framework: net8.0 + sdk: 8.0.x sdk-preview: true runtime: -x64 codecov: false - os: macos-latest - framework: net7.0 - sdk: 7.0.x + framework: net8.0 + sdk: 8.0.x sdk-preview: true runtime: -x64 codecov: false - os: windows-latest - framework: net7.0 - sdk: 7.0.x + framework: net8.0 + sdk: 8.0.x sdk-preview: true runtime: -x64 codecov: false - os: buildjet-4vcpu-ubuntu-2204-arm - framework: net7.0 - sdk: 7.0.x + framework: net8.0 + sdk: 8.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 - runtime: -x64 - codecov: false exclude: - isARM: false options: diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index e551afbd6d..bbaea3a61b 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -10,7 +10,7 @@ jobs: matrix: options: - os: ubuntu-latest - framework: net6.0 + framework: net8.0 runtime: -x64 codecov: true diff --git a/README.md b/README.md index fa51d57cdf..cf58b6b14b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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**: diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index aba3c0abdc..293997c4de 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -908,25 +908,6 @@ internal static class Numerics return Sse2.ConvertToInt32(vsum); } - /// - /// Reduces elements of the vector into one sum. - /// - /// The accumulator to reduce. - /// The sum of all elements. - [MethodImpl(InliningOptions.ShortMethod)] - public static int ReduceSumArm(Vector128 accumulator) - { - if (AdvSimd.Arm64.IsSupported) - { - Vector64 sum = AdvSimd.Arm64.AddAcross(accumulator); - return (int)AdvSimd.Extract(sum, 0); - } - - Vector128 sum2 = AdvSimd.AddPairwiseWidening(accumulator); - Vector64 sum3 = AdvSimd.Add(sum2.GetLower().AsUInt32(), sum2.GetUpper().AsUInt32()); - return (int)AdvSimd.Extract(sum3, 0); - } - /// /// Reduces even elements of the vector into one sum. /// diff --git a/src/ImageSharp/Diagnostics/CodeAnalysis/UnscopedRefAttribute.cs b/src/ImageSharp/Diagnostics/CodeAnalysis/UnscopedRefAttribute.cs deleted file mode 100644 index dc2c7bd196..0000000000 --- a/src/ImageSharp/Diagnostics/CodeAnalysis/UnscopedRefAttribute.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Six Labors Split License. -#if NET6_0 -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -namespace System.Diagnostics.CodeAnalysis -{ - /// - /// Used to indicate a byref escapes and is not scoped. - /// - /// - /// - /// There are several cases where the C# compiler treats a as implicitly - /// - where the compiler does not allow the to escape the method. - /// - /// - /// For example: - /// - /// for instance methods. - /// parameters that refer to types. - /// parameters. - /// - /// - /// - /// This attribute is used in those instances where the should be allowed to escape. - /// - /// - /// Applying this attribute, in any form, has impact on consumers of the applicable API. It is necessary for - /// API authors to understand the lifetime implications of applying this attribute and how it may impact their users. - /// - /// - [global::System.AttributeUsage( - global::System.AttributeTargets.Method | - global::System.AttributeTargets.Property | - global::System.AttributeTargets.Parameter, - AllowMultiple = false, - Inherited = false)] - internal sealed class UnscopedRefAttribute : global::System.Attribute - { - } -} -#endif diff --git a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs index de3f1586af..aae4181ce0 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs @@ -230,11 +230,7 @@ internal static class LossyUtils } } -#if NET7_0_OR_GREATER return (int)Vector128.Sum(sum); -#else - return Numerics.ReduceSumArm(sum); -#endif } [MethodImpl(InliningOptions.ShortMethod)] @@ -252,11 +248,7 @@ internal static class LossyUtils } } -#if NET7_0_OR_GREATER return (int)Vector128.Sum(sum); -#else - return Numerics.ReduceSumArm(sum); -#endif } [MethodImpl(InliningOptions.ShortMethod)] @@ -275,11 +267,8 @@ internal static class LossyUtils Vector128 sum2 = AdvSimd.AddPairwiseWidening(prod2); Vector128 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 diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index b08c27c41b..12da6cf532 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -29,13 +29,13 @@ - net7.0;net6.0 + net8.0 true - net6.0 + net8.0 true diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index 0ba2f4b949..22a2777a6a 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -11,7 +11,7 @@ false Debug;Release - + @@ -23,12 +23,12 @@ - net7.0;net6.0 + net8.0 - net6.0 + net8.0 diff --git a/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj b/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj index 492ce36b81..dfa01b8be1 100644 --- a/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj +++ b/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj @@ -19,12 +19,12 @@ - net7.0;net6.0 + net8.0 - net6.0 + net8.0 diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index dc081e0bea..491c4da872 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -12,12 +12,12 @@ - net7.0;net6.0 + net8.0 - net6.0 + net8.0 From 807b5d9555eb776615ef6c2049fa6e26c2cc7c11 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sat, 18 Nov 2023 10:56:56 +0100 Subject: [PATCH 02/16] Update build sdk to net8 --- .github/workflows/build-and-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 6f9dc1d42b..d4c3888d42 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -96,14 +96,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 }} From 836744f47b300787fdbe97711b2a41b390f3e307 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sat, 18 Nov 2023 11:00:13 +0100 Subject: [PATCH 03/16] use win-x64 as rid --- .github/workflows/code-coverage.yml | 2 +- .../ImageSharp.Tests.ProfilingSandbox.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index bbaea3a61b..7624e86b67 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -58,7 +58,7 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.0.x + 8.0.x - name: DotNet Build shell: pwsh diff --git a/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj b/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj index dfa01b8be1..76891b4bbb 100644 --- a/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj +++ b/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj @@ -7,7 +7,7 @@ Exe false SixLabors.ImageSharp.Tests.ProfilingSandbox - win7-x64 + win-x64 SixLabors.ImageSharp.Tests.ProfilingSandbox.Program false From 0b49cb01271d08919120fb6a53957611ddff56ba Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sat, 18 Nov 2023 13:43:25 +0100 Subject: [PATCH 04/16] Use C# 12.0 --- src/ImageSharp/ImageSharp.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 12da6cf532..a1c7e6175f 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -17,6 +17,7 @@ + 12.0 enable Nullable From 69951a59c5ab7d120ac59e78ca91e9c6beb3839d Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sat, 18 Nov 2023 13:55:00 +0100 Subject: [PATCH 05/16] remove sdk-preview --- .github/workflows/build-and-test.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index d4c3888d42..7c7791347d 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -21,25 +21,21 @@ jobs: - os: ubuntu-latest framework: net8.0 sdk: 8.0.x - sdk-preview: true runtime: -x64 codecov: false - os: macos-latest framework: net8.0 sdk: 8.0.x - sdk-preview: true runtime: -x64 codecov: false - os: windows-latest framework: net8.0 sdk: 8.0.x - sdk-preview: true runtime: -x64 codecov: false - os: buildjet-4vcpu-ubuntu-2204-arm framework: net8.0 sdk: 8.0.x - sdk-preview: true runtime: -x64 codecov: false exclude: From 4564831d10dd27ffc123be025e3ee89bffb3c0ab Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sat, 18 Nov 2023 14:13:31 +0100 Subject: [PATCH 06/16] Fix build errors --- .editorconfig | 2 ++ .../Advanced/ParallelRowIterator.Wrappers.cs | 4 ++-- src/ImageSharp/Advanced/ParallelRowIterator.cs | 10 +++++----- src/ImageSharp/Common/Helpers/DebugGuard.cs | 2 ++ src/ImageSharp/Configuration.cs | 5 +---- src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs | 5 +---- .../Allocators/Internals/SharedArrayPoolBuffer{T}.cs | 2 ++ .../PixelFormats/PixelImplementations/Abgr32.cs | 2 +- .../PixelFormats/PixelImplementations/Argb32.cs | 2 +- .../PixelFormats/PixelImplementations/Bgra32.cs | 2 +- .../PixelFormats/PixelImplementations/La16.cs | 2 +- .../PixelFormats/PixelImplementations/La32.cs | 2 +- .../PixelFormats/PixelImplementations/Rgba32.cs | 2 +- .../PixelFormats/PixelImplementations/Rgba64.cs | 4 ++-- .../Processing/Processors/Dithering/ErrorDither.cs | 2 +- .../PixelRowDelegateProcessor{TPixel,TDelegate}.cs | 2 +- .../Processors/Filters/FilterProcessor{TPixel}.cs | 2 +- .../Processors/Quantization/OctreeQuantizer{TPixel}.cs | 2 +- .../Quantization/PaletteQuantizer{TPixel}.cs | 2 +- .../Processors/Quantization/QuantizerUtilities.cs | 2 +- .../Processors/Quantization/WuQuantizer{TPixel}.cs | 2 +- .../ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj | 1 + 22 files changed, 31 insertions(+), 30 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2e3045fb17..ebda51e371 100644 --- a/.editorconfig +++ b/.editorconfig @@ -422,6 +422,8 @@ dotnet_naming_rule.parameters_rule.symbols = parameters_group dotnet_naming_rule.parameters_rule.style = camel_case_style dotnet_naming_rule.parameters_rule.severity = warning + +dotnet_diagnostics.CA1857.severity = none ########################################## # License ########################################## diff --git a/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs b/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs index 9629b0097e..a959faa3b6 100644 --- a/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs +++ b/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs @@ -51,7 +51,7 @@ public static partial class ParallelRowIterator 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); } } } @@ -102,7 +102,7 @@ public static partial class ParallelRowIterator for (int y = yMin; y < yMax; y++) { - Unsafe.AsRef(this.action).Invoke(y, span); + Unsafe.AsRef(in this.action).Invoke(y, span); } } } diff --git a/src/ImageSharp/Advanced/ParallelRowIterator.cs b/src/ImageSharp/Advanced/ParallelRowIterator.cs index 657654a84b..1284a3a898 100644 --- a/src/ImageSharp/Advanced/ParallelRowIterator.cs +++ b/src/ImageSharp/Advanced/ParallelRowIterator.cs @@ -58,7 +58,7 @@ public static partial class ParallelRowIterator { for (int y = top; y < bottom; y++) { - Unsafe.AsRef(operation).Invoke(y); + Unsafe.AsRef(in operation).Invoke(y); } return; @@ -118,7 +118,7 @@ public static partial class ParallelRowIterator 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) @@ -128,7 +128,7 @@ public static partial class ParallelRowIterator for (int y = top; y < bottom; y++) { - Unsafe.AsRef(operation).Invoke(y, span); + Unsafe.AsRef(in operation).Invoke(y, span); } return; @@ -245,7 +245,7 @@ public static partial class ParallelRowIterator 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) @@ -253,7 +253,7 @@ public static partial class ParallelRowIterator var rows = new RowInterval(top, bottom); using IMemoryOwner buffer = allocator.Allocate(bufferLength); - Unsafe.AsRef(operation).Invoke(in rows, buffer.Memory.Span); + Unsafe.AsRef(in operation).Invoke(in rows, buffer.Memory.Span); return; } diff --git a/src/ImageSharp/Common/Helpers/DebugGuard.cs b/src/ImageSharp/Common/Helpers/DebugGuard.cs index be2daa139e..990b21c99e 100644 --- a/src/ImageSharp/Common/Helpers/DebugGuard.cs +++ b/src/ImageSharp/Common/Helpers/DebugGuard.cs @@ -33,10 +33,12 @@ internal static partial class DebugGuard [Conditional("DEBUG")] public static void NotDisposed(bool isDisposed, string objectName) { +#pragma warning disable CA1513 if (isDisposed) { throw new ObjectDisposedException(objectName); } +#pragma warning restore CA1513 } /// diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index 39fcef9c40..1ca5d0a46b 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -87,10 +87,7 @@ public sealed class Configuration get => this.streamProcessingBufferSize; set { - if (value <= 0) - { - throw new ArgumentOutOfRangeException(nameof(this.StreamProcessingBufferSize)); - } + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(value); this.streamProcessingBufferSize = value; } diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index 95f7fde32c..7fc2a1f45e 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -176,10 +176,7 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// is . private void WriteDefineHuffmanTables(JpegHuffmanTableConfig[] tableConfigs, HuffmanScanEncoder scanEncoder, Span buffer) { - if (tableConfigs is null) - { - throw new ArgumentNullException(nameof(tableConfigs)); - } + ArgumentNullException.ThrowIfNull(tableConfigs); int markerlen = 2; diff --git a/src/ImageSharp/Memory/Allocators/Internals/SharedArrayPoolBuffer{T}.cs b/src/ImageSharp/Memory/Allocators/Internals/SharedArrayPoolBuffer{T}.cs index f9434ee941..c0a0c5d272 100644 --- a/src/ImageSharp/Memory/Allocators/Internals/SharedArrayPoolBuffer{T}.cs +++ b/src/ImageSharp/Memory/Allocators/Internals/SharedArrayPoolBuffer{T}.cs @@ -59,10 +59,12 @@ internal class SharedArrayPoolBuffer : ManagedBufferBase, IRefCounted [MemberNotNull(nameof(Array))] private void CheckDisposed() { +#pragma warning disable CA1513 if (this.Array == null) { throw new ObjectDisposedException("SharedArrayPoolBuffer"); } +#pragma warning restore CA1513 } private sealed class LifetimeGuard : RefCountedMemoryLifetimeGuard diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs index 4891abba8c..8bd24c7a01 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs @@ -129,7 +129,7 @@ public partial struct Abgr32 : IPixel, IPackedVector public uint Abgr { [MethodImpl(InliningOptions.ShortMethod)] - readonly get => Unsafe.As(ref Unsafe.AsRef(this)); + readonly get => Unsafe.As(ref Unsafe.AsRef(in this)); [MethodImpl(InliningOptions.ShortMethod)] set => Unsafe.As(ref this) = value; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs index 0c99adb52d..fa8af98a0b 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs @@ -129,7 +129,7 @@ public partial struct Argb32 : IPixel, IPackedVector public uint Argb { [MethodImpl(InliningOptions.ShortMethod)] - readonly get => Unsafe.As(ref Unsafe.AsRef(this)); + readonly get => Unsafe.As(ref Unsafe.AsRef(in this)); [MethodImpl(InliningOptions.ShortMethod)] set => Unsafe.As(ref this) = value; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs index 6b859cda64..d7222f2ef8 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs @@ -85,7 +85,7 @@ public partial struct Bgra32 : IPixel, IPackedVector public uint Bgra { [MethodImpl(InliningOptions.ShortMethod)] - readonly get => Unsafe.As(ref Unsafe.AsRef(this)); + readonly get => Unsafe.As(ref Unsafe.AsRef(in this)); [MethodImpl(InliningOptions.ShortMethod)] set => Unsafe.As(ref this) = value; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs index 7597677a26..58aeb61890 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs @@ -45,7 +45,7 @@ public partial struct La16 : IPixel, IPackedVector /// public ushort PackedValue { - readonly get => Unsafe.As(ref Unsafe.AsRef(this)); + readonly get => Unsafe.As(ref Unsafe.AsRef(in this)); set => Unsafe.As(ref this) = value; } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs index cb8fad228d..db7f433293 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs @@ -45,7 +45,7 @@ public partial struct La32 : IPixel, IPackedVector public uint PackedValue { [MethodImpl(InliningOptions.ShortMethod)] - readonly get => Unsafe.As(ref Unsafe.AsRef(this)); + readonly get => Unsafe.As(ref Unsafe.AsRef(in this)); [MethodImpl(InliningOptions.ShortMethod)] set => Unsafe.As(ref this) = value; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs index a652c2b339..75fe8f3f4e 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs @@ -124,7 +124,7 @@ public partial struct Rgba32 : IPixel, IPackedVector public uint Rgba { [MethodImpl(InliningOptions.ShortMethod)] - readonly get => Unsafe.As(ref Unsafe.AsRef(this)); + readonly get => Unsafe.As(ref Unsafe.AsRef(in this)); [MethodImpl(InliningOptions.ShortMethod)] set => Unsafe.As(ref this) = value; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs index 81c9591480..75235c9007 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs @@ -152,7 +152,7 @@ public partial struct Rgba64 : IPixel, IPackedVector public Rgb48 Rgb { [MethodImpl(InliningOptions.ShortMethod)] - readonly get => Unsafe.As(ref Unsafe.AsRef(this)); + readonly get => Unsafe.As(ref Unsafe.AsRef(in this)); [MethodImpl(InliningOptions.ShortMethod)] set => Unsafe.As(ref this) = value; @@ -162,7 +162,7 @@ public partial struct Rgba64 : IPixel, IPackedVector public ulong PackedValue { [MethodImpl(InliningOptions.ShortMethod)] - readonly get => Unsafe.As(ref Unsafe.AsRef(this)); + readonly get => Unsafe.As(ref Unsafe.AsRef(in this)); [MethodImpl(InliningOptions.ShortMethod)] set => Unsafe.As(ref this) = value; diff --git a/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs b/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs index 754aac90ea..287a8d197c 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs @@ -143,7 +143,7 @@ public readonly partial struct ErrorDither : IDither, IEquatable, I for (int x = bounds.Left; x < bounds.Right; x++) { ref TPixel sourcePixel = ref Unsafe.Add(ref sourceRowRef, (uint)x); - TPixel transformed = Unsafe.AsRef(processor).GetPaletteColor(sourcePixel); + TPixel transformed = Unsafe.AsRef(in processor).GetPaletteColor(sourcePixel); this.Dither(source, bounds, sourcePixel, transformed, x, y, scale); sourcePixel = transformed; } diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel,TDelegate}.cs b/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel,TDelegate}.cs index f59b95050e..36bb327cf2 100644 --- a/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel,TDelegate}.cs +++ b/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel,TDelegate}.cs @@ -96,7 +96,7 @@ internal sealed class PixelRowDelegateProcessor : ImageProces PixelOperations.Instance.ToVector4(this.configuration, rowSpan, span, this.modifiers); // Run the user defined pixel shader to the current row of pixels - Unsafe.AsRef(this.rowProcessor).Invoke(span, new Point(this.startX, y)); + Unsafe.AsRef(in this.rowProcessor).Invoke(span, new Point(this.startX, y)); PixelOperations.Instance.FromVector4Destructive(this.configuration, span, rowSpan, this.modifiers); } diff --git a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs index 5ad245e3ce..5109139647 100644 --- a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs @@ -78,7 +78,7 @@ internal class FilterProcessor : ImageProcessor Span rowSpan = this.source.DangerousGetRowSpan(y).Slice(this.startX, span.Length); PixelOperations.Instance.ToVector4(this.configuration, rowSpan, span, PixelConversionModifiers.Scale); - ColorNumerics.Transform(span, ref Unsafe.AsRef(this.matrix)); + ColorNumerics.Transform(span, ref Unsafe.AsRef(in this.matrix)); PixelOperations.Instance.FromVector4Destructive(this.configuration, span, rowSpan, PixelConversionModifiers.Scale); } diff --git a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs index 1136fbc9da..e81ad59d44 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs @@ -128,7 +128,7 @@ public struct OctreeQuantizer : IQuantizer /// [MethodImpl(InliningOptions.ShortMethod)] public readonly IndexedImageFrame QuantizeFrame(ImageFrame source, Rectangle bounds) - => QuantizerUtilities.QuantizeFrame(ref Unsafe.AsRef(this), source, bounds); + => QuantizerUtilities.QuantizeFrame(ref Unsafe.AsRef(in this), source, bounds); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs index 3df80ea9b7..092975d28a 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs @@ -56,7 +56,7 @@ internal readonly struct PaletteQuantizer : IQuantizer /// [MethodImpl(InliningOptions.ShortMethod)] public readonly IndexedImageFrame QuantizeFrame(ImageFrame source, Rectangle bounds) - => QuantizerUtilities.QuantizeFrame(ref Unsafe.AsRef(this), source, bounds); + => QuantizerUtilities.QuantizeFrame(ref Unsafe.AsRef(in this), source, bounds); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs index 53203f94a0..55154d6e2f 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs @@ -161,7 +161,7 @@ public static class QuantizerUtilities for (int x = bounds.Left; x < bounds.Right; x++) { - destinationRow[x - offsetX] = Unsafe.AsRef(quantizer).GetQuantizedColor(sourceRow[x], out TPixel _); + destinationRow[x - offsetX] = Unsafe.AsRef(in quantizer).GetQuantizedColor(sourceRow[x], out TPixel _); } } diff --git a/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs index 524153804c..46c3f03d69 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs @@ -167,7 +167,7 @@ internal struct WuQuantizer : IQuantizer /// [MethodImpl(InliningOptions.ShortMethod)] public readonly IndexedImageFrame QuantizeFrame(ImageFrame source, Rectangle bounds) - => QuantizerUtilities.QuantizeFrame(ref Unsafe.AsRef(this), source, bounds); + => QuantizerUtilities.QuantizeFrame(ref Unsafe.AsRef(in this), source, bounds); /// public readonly byte GetQuantizedColor(TPixel color, out TPixel match) diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index 22a2777a6a..5686003116 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -10,6 +10,7 @@ false Debug;Release + 12.0 From 85c0b618b5432a1c31d41558f59913bc6966d760 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sat, 18 Nov 2023 14:17:10 +0100 Subject: [PATCH 07/16] Disable CS1859 --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index ebda51e371..2007532919 100644 --- a/.editorconfig +++ b/.editorconfig @@ -424,6 +424,7 @@ dotnet_naming_rule.parameters_rule.severity = warning dotnet_diagnostics.CA1857.severity = none +dotnet_diagnostics.CA1859.severity = none ########################################## # License ########################################## From 1be9491023c05000952d8f20c55fa57d3a4fe986 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sat, 18 Nov 2023 14:23:16 +0100 Subject: [PATCH 08/16] Disable the rules in the ruleset --- .editorconfig | 3 --- src/ImageSharp.ruleset | 6 +++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2007532919..2e3045fb17 100644 --- a/.editorconfig +++ b/.editorconfig @@ -422,9 +422,6 @@ dotnet_naming_rule.parameters_rule.symbols = parameters_group dotnet_naming_rule.parameters_rule.style = camel_case_style dotnet_naming_rule.parameters_rule.severity = warning - -dotnet_diagnostics.CA1857.severity = none -dotnet_diagnostics.CA1859.severity = none ########################################## # License ########################################## diff --git a/src/ImageSharp.ruleset b/src/ImageSharp.ruleset index e88c43f838..11f5041589 100644 --- a/src/ImageSharp.ruleset +++ b/src/ImageSharp.ruleset @@ -1,7 +1,11 @@  + + + + - \ No newline at end of file + From d1c3c31258e8ce734b53e6d926af5c06005df640 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sat, 18 Nov 2023 14:29:43 +0100 Subject: [PATCH 09/16] Nextfixes --- src/ImageSharp/Formats/ImageFormatManager.cs | 5 +---- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Formats/ImageFormatManager.cs b/src/ImageSharp/Formats/ImageFormatManager.cs index 0ee4bc79b9..b6b5f87797 100644 --- a/src/ImageSharp/Formats/ImageFormatManager.cs +++ b/src/ImageSharp/Formats/ImageFormatManager.cs @@ -83,10 +83,7 @@ public class ImageFormatManager lock (HashLock) { - if (!this.imageFormats.Contains(format)) - { - this.imageFormats.Add(format); - } + this.imageFormats.Add(format); } } diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index d8305a3f57..4e8067016e 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -1938,8 +1938,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals // 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 keywordBytes) From 8b2e164c83a7fc910a6f84c686f8dc12e1350291 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Mon, 20 Nov 2023 08:17:54 +0100 Subject: [PATCH 10/16] Fix CA1857 --- src/ImageSharp.ruleset | 1 - src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs | 5 +++-- src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp.ruleset b/src/ImageSharp.ruleset index 11f5041589..8327dd7565 100644 --- a/src/ImageSharp.ruleset +++ b/src/ImageSharp.ruleset @@ -2,7 +2,6 @@ - diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 7caaa5868d..373069e9bc 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -58,7 +59,7 @@ internal static partial class SimdUtils public static void Shuffle4Reduce( ref ReadOnlySpan source, ref Span dest, - byte control) + [ConstantExpected] byte control) { if (Avx.IsSupported || Sse.IsSupported) { @@ -217,7 +218,7 @@ internal static partial class SimdUtils private static void Shuffle4( ReadOnlySpan source, Span dest, - byte control) + [ConstantExpected] byte control) { if (Avx.IsSupported) { diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs b/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs index c1437c05e6..83cd3d246c 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -20,7 +21,7 @@ internal static partial class SimdUtils public static void Shuffle4( ReadOnlySpan source, Span dest, - byte control) + [ConstantExpected] byte control) { VerifyShuffle4SpanInput(source, dest); From d79e08c6dae35d9fae18a7e5e63ee266e98bcc3a Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Fri, 1 Dec 2023 14:31:18 +0100 Subject: [PATCH 11/16] Update to latest SharedInfrastructure commit --- shared-infrastructure | 2 +- src/ImageSharp/ImageSharp.csproj | 1 - tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/shared-infrastructure b/shared-infrastructure index 353b9afe32..4e892950d7 160000 --- a/shared-infrastructure +++ b/shared-infrastructure @@ -1 +1 @@ -Subproject commit 353b9afe32a8000410312d17263407cd7bb82d19 +Subproject commit 4e892950d7f17e5cb64160675d6902545cc3b5c5 diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index a1c7e6175f..12da6cf532 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -17,7 +17,6 @@ - 12.0 enable Nullable diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index 5686003116..22a2777a6a 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -10,7 +10,6 @@ false Debug;Release - 12.0 From 651763daa705a377006eb073f45fc212a33ed950 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Fri, 1 Dec 2023 14:47:42 +0100 Subject: [PATCH 12/16] Fix SA1516 --- src/ImageSharp/Formats/AnimatedImageFrameMetadata.cs | 1 + src/ImageSharp/Formats/AnimatedImageMetadata.cs | 1 + src/ImageSharp/Formats/Qoi/QoiDecoder.cs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/ImageSharp/Formats/AnimatedImageFrameMetadata.cs b/src/ImageSharp/Formats/AnimatedImageFrameMetadata.cs index 5f4015180b..75595e1f7d 100644 --- a/src/ImageSharp/Formats/AnimatedImageFrameMetadata.cs +++ b/src/ImageSharp/Formats/AnimatedImageFrameMetadata.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. namespace SixLabors.ImageSharp.Formats; + internal class AnimatedImageFrameMetadata { /// diff --git a/src/ImageSharp/Formats/AnimatedImageMetadata.cs b/src/ImageSharp/Formats/AnimatedImageMetadata.cs index d89ec41f07..ac3ca29f4f 100644 --- a/src/ImageSharp/Formats/AnimatedImageMetadata.cs +++ b/src/ImageSharp/Formats/AnimatedImageMetadata.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. namespace SixLabors.ImageSharp.Formats; + internal class AnimatedImageMetadata { /// diff --git a/src/ImageSharp/Formats/Qoi/QoiDecoder.cs b/src/ImageSharp/Formats/Qoi/QoiDecoder.cs index a54095dfc6..5c1bf6ad23 100644 --- a/src/ImageSharp/Formats/Qoi/QoiDecoder.cs +++ b/src/ImageSharp/Formats/Qoi/QoiDecoder.cs @@ -4,6 +4,7 @@ using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Qoi; + internal class QoiDecoder : ImageDecoder { private QoiDecoder() From 98ffa0fb44040cd0e2ae4d8f922d4ee622fe7879 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Fri, 1 Dec 2023 16:26:00 +0100 Subject: [PATCH 13/16] Update Microsoft.DotNet.RemoteExecutor --- tests/Directory.Build.targets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Directory.Build.targets b/tests/Directory.Build.targets index 3a29442872..85796e0d63 100644 --- a/tests/Directory.Build.targets +++ b/tests/Directory.Build.targets @@ -22,8 +22,8 @@ - - + + From 290906a752f98cdd678516f04d09467c24ce2608 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Fri, 1 Dec 2023 16:29:53 +0100 Subject: [PATCH 14/16] Fix CA1513 --- .../Allocators/Internals/SharedArrayPoolBuffer{T}.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/ImageSharp/Memory/Allocators/Internals/SharedArrayPoolBuffer{T}.cs b/src/ImageSharp/Memory/Allocators/Internals/SharedArrayPoolBuffer{T}.cs index c0a0c5d272..02bdf0f48d 100644 --- a/src/ImageSharp/Memory/Allocators/Internals/SharedArrayPoolBuffer{T}.cs +++ b/src/ImageSharp/Memory/Allocators/Internals/SharedArrayPoolBuffer{T}.cs @@ -57,15 +57,7 @@ internal class SharedArrayPoolBuffer : ManagedBufferBase, IRefCounted [Conditional("DEBUG")] [MemberNotNull(nameof(Array))] - private void CheckDisposed() - { -#pragma warning disable CA1513 - if (this.Array == null) - { - throw new ObjectDisposedException("SharedArrayPoolBuffer"); - } -#pragma warning restore CA1513 - } + private void CheckDisposed() => ObjectDisposedException.ThrowIf(this.Array == null, this.Array); private sealed class LifetimeGuard : RefCountedMemoryLifetimeGuard { From 9ac4cd91a417fa28bbb6357e1e82f63a40cab1d9 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 4 Dec 2023 12:33:35 +1000 Subject: [PATCH 15/16] Enable CA1859 --- .gitattributes | 3 +++ shared-infrastructure | 2 +- src/ImageSharp.ruleset | 3 --- src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs | 4 ++-- src/ImageSharp/Formats/Tiff/Ifd/DirectoryReader.cs | 2 +- src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitattributes b/.gitattributes index 3647a7063d..b5f742ab47 100644 --- a/.gitattributes +++ b/.gitattributes @@ -133,3 +133,6 @@ *.pnm filter=lfs diff=lfs merge=lfs -text *.wbmp filter=lfs diff=lfs merge=lfs -text *.exr filter=lfs diff=lfs merge=lfs -text +*.ico filter=lfs diff=lfs merge=lfs -text +*.cur filter=lfs diff=lfs merge=lfs -text +*.ani filter=lfs diff=lfs merge=lfs -text diff --git a/shared-infrastructure b/shared-infrastructure index 4e892950d7..1c526a97ee 160000 --- a/shared-infrastructure +++ b/shared-infrastructure @@ -1 +1 @@ -Subproject commit 4e892950d7f17e5cb64160675d6902545cc3b5c5 +Subproject commit 1c526a97eea8bcbc7c79de095676f7fb975a9fb1 diff --git a/src/ImageSharp.ruleset b/src/ImageSharp.ruleset index 8327dd7565..d7a147df03 100644 --- a/src/ImageSharp.ruleset +++ b/src/ImageSharp.ruleset @@ -1,9 +1,6 @@  - - - diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs index c3cd95c028..f251df3bf2 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs @@ -133,7 +133,7 @@ internal sealed class JpegFrame : IDisposable for (int i = 0; i < this.ComponentCount; i++) { - IJpegComponent component = this.Components[i]; + JpegComponent component = this.Components[i]; component.Init(maxSubFactorH, maxSubFactorV); } } @@ -143,7 +143,7 @@ internal sealed class JpegFrame : IDisposable bool fullScan = this.Progressive || !this.Interleaved; for (int i = 0; i < this.ComponentCount; i++) { - IJpegComponent component = this.Components[i]; + JpegComponent component = this.Components[i]; component.AllocateSpectral(fullScan); } } diff --git a/src/ImageSharp/Formats/Tiff/Ifd/DirectoryReader.cs b/src/ImageSharp/Formats/Tiff/Ifd/DirectoryReader.cs index 086eef0585..114fc12b23 100644 --- a/src/ImageSharp/Formats/Tiff/Ifd/DirectoryReader.cs +++ b/src/ImageSharp/Formats/Tiff/Ifd/DirectoryReader.cs @@ -71,7 +71,7 @@ internal class DirectoryReader throw TiffThrowHelper.ThrowInvalidHeader(); } - private IList ReadIfds(bool isBigTiff) + private List ReadIfds(bool isBigTiff) { List readers = new(); while (this.nextIfdOffset != 0 && this.nextIfdOffset < (ulong)this.stream.Length) diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs index 953ef74afb..a4fcd9275b 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs @@ -472,7 +472,7 @@ internal abstract class BaseExifReader } } - private void Add(IList values, IExifValue exif, object? value) + private void Add(IList values, ExifValue exif, object? value) { if (!exif.TrySetValue(value)) { From b4f9bf963bc67a52257d7ac04a9d802073f69ac0 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 4 Dec 2023 14:58:01 +1000 Subject: [PATCH 16/16] Update package dependencies and min ver number --- src/ImageSharp/ImageSharp.csproj | 4 ++-- tests/Directory.Build.targets | 20 +++++++++---------- .../ImageSharp.Benchmarks.csproj | 4 ++-- .../LoadResizeSaveStressRunner.cs | 6 ++---- .../ImageSharp.Tests.ProfilingSandbox.csproj | 2 +- .../ImageSharp.Tests/ImageSharp.Tests.csproj | 6 +++++- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 12da6cf532..4c08fc017b 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -22,8 +22,8 @@ - - 3.1 + + 4.0 diff --git a/tests/Directory.Build.targets b/tests/Directory.Build.targets index 85796e0d63..d6b35d003f 100644 --- a/tests/Directory.Build.targets +++ b/tests/Directory.Build.targets @@ -18,20 +18,18 @@ - - - - + + - - - - - - + + + + + + - + diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index 22a2777a6a..4408159ef4 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -41,8 +41,8 @@ - - + + diff --git a/tests/ImageSharp.Benchmarks/LoadResizeSave/LoadResizeSaveStressRunner.cs b/tests/ImageSharp.Benchmarks/LoadResizeSave/LoadResizeSaveStressRunner.cs index dd9b55e58d..a06784f1b1 100644 --- a/tests/ImageSharp.Benchmarks/LoadResizeSave/LoadResizeSaveStressRunner.cs +++ b/tests/ImageSharp.Benchmarks/LoadResizeSave/LoadResizeSaveStressRunner.cs @@ -269,9 +269,7 @@ public class LoadResizeSaveStressRunner Width = this.ThumbnailSize, Height = this.ThumbnailSize, ResizeMode = CropScaleMode.Max, - SaveFormat = FileFormat.Jpeg, - JpegQuality = Quality, - JpegSubsampleMode = ChromaSubsampleMode.Subsample420 + EncoderOptions = new JpegEncoderOptions(Quality, ChromaSubsampleMode.Subsample420, true) }; // TODO: Is there a way to capture input dimensions for IncreaseTotalMegapixels? @@ -343,6 +341,6 @@ public class LoadResizeSaveStressRunner using var thumb = NetVipsImage.Thumbnail(input, this.ThumbnailSize, this.ThumbnailSize); // Save the results - thumb.Jpegsave(this.OutputPath(input), q: Quality, strip: true); + thumb.Jpegsave(this.OutputPath(input), q: Quality, keep: NetVips.Enums.ForeignKeep.None); } } diff --git a/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj b/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj index 76891b4bbb..b93d011910 100644 --- a/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj +++ b/tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj @@ -43,7 +43,7 @@ - + diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 491c4da872..e0c65475af 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -35,7 +35,11 @@ - + +