From eb549bcda3ac0e7aa471bb0b57bc515dd1341909 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Mon, 17 Aug 2026 08:32:03 +0200 Subject: [PATCH] Use Collection expressions and Target-typed new 1. Collection expressions (`[]` syntax) replacing `new List()`, `new T[] {}`, `.ToArray()`, etc. 2. Target-typed `new()` expressions where appropriate 3. Using spread elements (`[.. collection]`) instead of `.ToArray()` and `.Concat().ToArray()` 4. Adding `#pragma warning disable/restore CS0649` for intentionally unassigned struct fields --- .../Icc/Calculators/GrayTrcCalculator.cs | 2 +- src/ImageSharp/Common/Helpers/SimdUtils.cs | 2 + src/ImageSharp/Formats/Ani/AniDecoderCore.cs | 4 +- src/ImageSharp/Formats/Bmp/BmpFormat.cs | 2 +- .../Compressors/ZipExrCompressor.cs | 2 +- src/ImageSharp/Formats/Exr/ExrMetadata.cs | 4 +- .../Formats/Icon/IconDecoderCore.cs | 4 +- src/ImageSharp/Formats/ImageDecoderCore.cs | 2 +- src/ImageSharp/Formats/ImageFormatManager.cs | 6 +- .../ColorConverters/JpegColorConverterBase.cs | 14 +- .../Formats/Jpeg/JpegDecoderCore.cs | 2 +- .../Jpeg/JpegEncoderCore.FrameConfig.cs | 182 ++++++++---------- .../Formats/Png/Chunks/FrameControl.cs | 2 +- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 12 +- src/ImageSharp/Formats/Qoi/QoiDecoderCore.cs | 2 +- .../Formats/Tiff/TiffDecoderOptionsParser.cs | 2 +- .../Formats/Webp/Lossless/CostManager.cs | 4 +- .../Formats/Webp/Lossless/CrunchConfig.cs | 2 +- .../Formats/Webp/Lossless/Vp8LHistogramSet.cs | 2 +- .../Webp/Lossless/WebpLosslessDecoder.cs | 2 +- .../DataWriter/IccDataWriter.TagDataEntry.cs | 2 +- .../Metadata/Profiles/ICC/IccReader.cs | 4 +- .../Metadata/Profiles/ICC/IccWriter.cs | 2 +- .../IccTextDescriptionTagDataEntry.cs | 2 +- ...iatedAlphaPorterDuffFunctions.Generated.cs | 2 +- ...iatedAlphaPorterDuffFunctions.Generated.tt | 24 +-- .../PixelImplementations/NormalizedByte4P.cs | 2 +- .../PixelImplementations/Rgb96.cs | 6 +- .../PixelImplementations/Rgba128.cs | 6 +- .../AffineTransformProcessor{TPixel}.cs | 2 +- .../Transforms/Resize/ResizeKernel.cs | 4 +- .../Processing/ColorMatchingCaches.cs | 6 +- .../Icc/ColorProfileConverterTests.Icc.cs | 4 +- .../ColorProfiles/RgbWorkingSpaceTests.cs | 2 +- .../Common/EncoderExtensionsTests.cs | 2 +- .../ImageSharp.Tests/Common/SimdUtilsTests.cs | 20 +- .../Common/StreamExtensionsTests.cs | 2 +- .../Common/TensorPrimitivesTests.cs | 24 +-- .../Formats/Ani/AniDecoderTests.cs | 10 +- .../Formats/Exr/ExrDecoderSecurityTests.cs | 18 +- .../Formats/Icon/Ico/IcoDecoderTests.cs | 4 +- .../Formats/Jpg/JpegMetadataTests.cs | 2 +- .../Formats/Jpg/SpectralJpegTests.cs | 2 +- .../Formats/Jpg/Utils/LibJpegTools.cs | 2 +- .../Formats/Jpg/Utils/VerifyJpeg.cs | 2 +- .../Formats/Png/PngEncoderTests.cs | 2 +- .../Formats/Png/PngMetadataTests.cs | 2 +- .../Formats/Tiff/BigTiffMetadataTests.cs | 4 +- .../Formats/WebP/Vp8HistogramTests.cs | 110 ++++++----- .../ImageSharp.Tests/Helpers/NumericsTests.cs | 26 ++- .../Helpers/ParallelRowIteratorTests.cs | 4 +- .../ImageFrameCollectionTests.Generic.cs | 2 +- .../ImageFrameCollectionTests.NonGeneric.cs | 4 +- .../Image/ImageTests.Decode_Cancellation.cs | 2 +- .../Image/ImageTests.WrapMemory.cs | 32 +-- .../Allocators/SharedArrayPoolBufferTests.cs | 4 +- .../UniformUnmanagedMemoryPoolTests.cs | 12 +- .../Memory/Allocators/UnmanagedBufferTests.cs | 2 +- .../Allocators/UnmanagedMemoryHandleTests.cs | 2 +- .../MemoryGroupTests.Allocate.cs | 2 +- .../DiscontiguousBuffers/MemoryGroupTests.cs | 14 +- .../Profiles/Exif/ExifProfileTests.cs | 6 +- .../Metadata/Profiles/Exif/ExifReaderTests.cs | 4 +- .../Profiles/Exif/Values/ExifValuesTests.cs | 6 +- .../IccDataWriterPrimitivesTests.cs | 4 +- .../Profiles/IPTC/IptcProfileTests.cs | 18 +- .../PixelFormats/AssociatedAlphaPixelTests.cs | 4 +- .../PixelFormats/PixelBlenderTests.cs | 12 +- .../PorterDuffFunctionsTestsTPixel.cs | 2 +- .../PixelOperations/PixelOperationsTests.cs | 4 +- .../Convolution/KernelSamplingMapTest.cs | 4 +- .../Processors/Convolution/BokehBlurTest.cs | 20 +- .../Quantization/PaletteQuantizerTests.cs | 8 +- .../Processors/Transforms/CropTest.cs | 2 +- .../Processors/Transforms/FlipTests.cs | 4 +- .../Transforms/ProjectiveTransformTests.cs | 2 +- ...ResizeKernelMapTests.ReferenceKernelMap.cs | 2 +- .../Transforms/ResizeKernelMapTests.cs | 2 +- .../Processors/Transforms/ResizeTests.cs | 2 +- .../Processors/Transforms/RotateTests.cs | 2 +- .../Processors/Transforms/SwizzleTests.cs | 2 +- .../AlphaAssociationQuantizerTests.cs | 4 +- .../IccConversionDataMultiProcessElement.cs | 45 +++-- tests/ImageSharp.Tests/TestFontUtilities.cs | 8 +- tests/ImageSharp.Tests/TestFormat.cs | 7 +- tests/ImageSharp.Tests/TestImages.cs | 2 +- .../TestUtilities/ByteBuffer.cs | 4 +- ...ImageDifferenceIsOverThresholdException.cs | 2 +- .../ImageComparison/ImageSimilarityReport.cs | 2 +- .../TestUtilities/ImagingTestCaseUtility.cs | 23 ++- .../TestUtilities/ScaledRgbaVectorP.cs | 2 +- .../TestUtilities/TestMemoryAllocator.cs | 4 +- .../TestUtilities/TestUtils.cs | 18 +- .../Tests/FeatureTestRunnerTests.cs | 2 +- .../Tests/TestUtilityExtensionsTests.cs | 2 +- 95 files changed, 439 insertions(+), 430 deletions(-) diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/GrayTrcCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/GrayTrcCalculator.cs index 8d823c1e9..1016f829b 100644 --- a/src/ImageSharp/ColorProfiles/Icc/Calculators/GrayTrcCalculator.cs +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/GrayTrcCalculator.cs @@ -12,7 +12,7 @@ internal class GrayTrcCalculator : IVector4Calculator private readonly TrcCalculator calculator; public GrayTrcCalculator(IccTagDataEntry grayTrc, bool toPcs) - => this.calculator = new TrcCalculator(new IccTagDataEntry[] { grayTrc }, !toPcs); + => this.calculator = new TrcCalculator([grayTrc], !toPcs); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 Calculate(Vector4 value) => this.calculator.Calculate(value); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.cs b/src/ImageSharp/Common/Helpers/SimdUtils.cs index 7f98c8375..86e2c1448 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.cs @@ -93,9 +93,11 @@ internal static partial class SimdUtils private struct ByteTuple4 { +#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value public byte V0; public byte V1; public byte V2; public byte V3; +#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value } } diff --git a/src/ImageSharp/Formats/Ani/AniDecoderCore.cs b/src/ImageSharp/Formats/Ani/AniDecoderCore.cs index cdfcf3016..292d357e4 100644 --- a/src/ImageSharp/Formats/Ani/AniDecoderCore.cs +++ b/src/ImageSharp/Formats/Ani/AniDecoderCore.cs @@ -66,7 +66,7 @@ internal sealed class AniDecoderCore : ImageDecoderCore, IDisposable cancellationToken.ThrowIfCancellationRequested(); Image resource = DecodeFrame(format, frameOptions, frameStream, cancellationToken); - this.Dimensions = new(Math.Max(this.Dimensions.Width, resource.Width), Math.Max(this.Dimensions.Height, resource.Height)); + this.Dimensions = new Size(Math.Max(this.Dimensions.Width, resource.Width), Math.Max(this.Dimensions.Height, resource.Height)); return resource; }); @@ -165,7 +165,7 @@ internal sealed class AniDecoderCore : ImageDecoderCore, IDisposable cancellationToken.ThrowIfCancellationRequested(); ImageInfo info = IdentifyFrame(format, frameOptions, frameStream, cancellationToken); - this.Dimensions = new(Math.Max(this.Dimensions.Width, info.Width), Math.Max(this.Dimensions.Height, info.Height)); + this.Dimensions = new Size(Math.Max(this.Dimensions.Width, info.Width), Math.Max(this.Dimensions.Height, info.Height)); return info; }); diff --git a/src/ImageSharp/Formats/Bmp/BmpFormat.cs b/src/ImageSharp/Formats/Bmp/BmpFormat.cs index 50e4090e1..5dec4a674 100644 --- a/src/ImageSharp/Formats/Bmp/BmpFormat.cs +++ b/src/ImageSharp/Formats/Bmp/BmpFormat.cs @@ -30,5 +30,5 @@ public sealed class BmpFormat : IImageFormat public IEnumerable FileExtensions => BmpConstants.FileExtensions; /// - public BmpMetadata CreateDefaultFormatMetadata() => new BmpMetadata(); + public BmpMetadata CreateDefaultFormatMetadata() => new(); } diff --git a/src/ImageSharp/Formats/Exr/Compression/Compressors/ZipExrCompressor.cs b/src/ImageSharp/Formats/Exr/Compression/Compressors/ZipExrCompressor.cs index 01248cc39..d5234bbae 100644 --- a/src/ImageSharp/Formats/Exr/Compression/Compressors/ZipExrCompressor.cs +++ b/src/ImageSharp/Formats/Exr/Compression/Compressors/ZipExrCompressor.cs @@ -32,7 +32,7 @@ internal class ZipExrCompressor : ExrBaseCompressor { this.compressionLevel = compressionLevel; this.buffer = allocator.Allocate((int)bytesPerBlock); - this.memoryStream = new(); + this.memoryStream = new MemoryStream(); } /// diff --git a/src/ImageSharp/Formats/Exr/ExrMetadata.cs b/src/ImageSharp/Formats/Exr/ExrMetadata.cs index de1988674..f619c086d 100644 --- a/src/ImageSharp/Formats/Exr/ExrMetadata.cs +++ b/src/ImageSharp/Formats/Exr/ExrMetadata.cs @@ -102,7 +102,7 @@ public class ExrMetadata : IFormatMetadata ? EncodingType.Lossy : EncodingType.Lossless; - return new() + return new FormatConnectingMetadata { EncodingType = type, PixelTypeInfo = this.GetPixelTypeInfo() @@ -136,7 +136,7 @@ public class ExrMetadata : IFormatMetadata } }; - return new() + return new ExrMetadata { PixelType = bitsPerComponent <= 16 ? ExrPixelType.Half : ExrPixelType.Float, ImageDataType = imageDataType, diff --git a/src/ImageSharp/Formats/Icon/IconDecoderCore.cs b/src/ImageSharp/Formats/Icon/IconDecoderCore.cs index 83a571083..80bc373d2 100644 --- a/src/ImageSharp/Formats/Icon/IconDecoderCore.cs +++ b/src/ImageSharp/Formats/Icon/IconDecoderCore.cs @@ -69,7 +69,7 @@ internal abstract class IconDecoderCore : ImageDecoderCore decodedEntries[decodedCount++] = (entryIndex, decoded, compression); // The embedded header is authoritative because a zero directory dimension can represent 256 pixels or a larger Vista-era PNG. - this.Dimensions = new(Math.Max(this.Dimensions.Width, decoded.Width), Math.Max(this.Dimensions.Height, decoded.Height)); + this.Dimensions = new Size(Math.Max(this.Dimensions.Width, decoded.Width), Math.Max(this.Dimensions.Height, decoded.Height)); }); } @@ -233,7 +233,7 @@ internal abstract class IconDecoderCore : ImageDecoderCore frames[frameCount++] = frameMetadata; // Identification uses the same embedded-header dimensions as decoding, without allocating pixel buffers. - this.Dimensions = new(Math.Max(this.Dimensions.Width, frameInfo.Width), Math.Max(this.Dimensions.Height, frameInfo.Height)); + this.Dimensions = new Size(Math.Max(this.Dimensions.Width, frameInfo.Width), Math.Max(this.Dimensions.Height, frameInfo.Height)); }); } diff --git a/src/ImageSharp/Formats/ImageDecoderCore.cs b/src/ImageSharp/Formats/ImageDecoderCore.cs index 23b517568..3f36b8931 100644 --- a/src/ImageSharp/Formats/ImageDecoderCore.cs +++ b/src/ImageSharp/Formats/ImageDecoderCore.cs @@ -279,7 +279,7 @@ internal abstract class ImageDecoderCore // and Wrap(Memory[]) creates a Consumed MemoryGroup that does not own the buffers (Dispose just // invalidates the view). This means no pixel data is cloned and disposing the temporary image will // not dispose or leak the frame's pixel buffer. - MemoryGroup memorySource = MemoryGroup.Wrap(m.ToArray()); + MemoryGroup memorySource = MemoryGroup.Wrap([.. m]); using Image image = new(frame.Configuration, memorySource, frame.Width, frame.Height, metadata); converter.Convert(image); diff --git a/src/ImageSharp/Formats/ImageFormatManager.cs b/src/ImageSharp/Formats/ImageFormatManager.cs index ecf96855e..733621036 100644 --- a/src/ImageSharp/Formats/ImageFormatManager.cs +++ b/src/ImageSharp/Formats/ImageFormatManager.cs @@ -32,12 +32,12 @@ public class ImageFormatManager /// /// The list of supported s. /// - private readonly HashSet imageFormats = new(); + private readonly HashSet imageFormats = []; /// /// The list of supported s. /// - private ConcurrentBag imageFormatDetectors = new(); + private ConcurrentBag imageFormatDetectors = []; /// /// Initializes a new instance of the class. @@ -161,7 +161,7 @@ public class ImageFormatManager /// /// Removes all the registered image format detectors. /// - public void ClearImageFormatDetectors() => this.imageFormatDetectors = new ConcurrentBag(); + public void ClearImageFormatDetectors() => this.imageFormatDetectors = []; /// /// Adds a new detector for detecting mime types. diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs index 2b1271c82..2c1b825e7 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs @@ -119,49 +119,49 @@ internal abstract partial class JpegColorConverterBase /// /// The precision in bits. private static JpegColorConverter GetYCbCrConverter(int precision) - => new JpegColorConverter(precision); + => new(precision); /// /// Returns the s for the YccK colorspace. /// /// The precision in bits. private static JpegColorConverter GetYccKConverter(int precision) - => new JpegColorConverter(precision); + => new(precision); /// /// Returns the s for the CMYK colorspace. /// /// The precision in bits. private static JpegColorConverter GetCmykConverter(int precision) - => new JpegColorConverter(precision); + => new(precision); /// /// Returns the s for the gray scale colorspace. /// /// The precision in bits. private static JpegColorConverter GetGrayScaleConverter(int precision) - => new JpegColorConverter(precision); + => new(precision); /// /// Returns the s for the RGB colorspace. /// /// The precision in bits. private static JpegColorConverter GetRgbConverter(int precision) - => new JpegColorConverter(precision); + => new(precision); /// /// Returns the for non-inverted TIFF CMYK. /// /// The precision in bits. private static JpegColorConverter GetTiffCmykConverter(int precision) - => new JpegColorConverter(precision); + => new(precision); /// /// Returns the for non-inverted TIFF YccK. /// /// The precision in bits. private static JpegColorConverter GetTiffYccKConverter(int precision) - => new JpegColorConverter(precision); + => new(precision); /// /// A stack-only struct to reference the input buffers using -s. diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index ae26914e8..6445911f8 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -1049,7 +1049,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData if (resourceDataSize > 0 && blockDataSpan.Length >= dataStartIdx + resourceDataSize) { this.hasIptc = true; - this.iptcData = blockDataSpan.Slice(dataStartIdx, resourceDataSize).ToArray(); + this.iptcData = [.. blockDataSpan.Slice(dataStartIdx, resourceDataSize)]; break; } diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.FrameConfig.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.FrameConfig.cs index 98b6dd30a..d86d5cad1 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.FrameConfig.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.FrameConfig.cs @@ -21,175 +21,159 @@ internal sealed unsafe partial class JpegEncoderCore JpegQuantizationTableConfig defaultLuminanceQuantTable = new(0, Quantization.LuminanceTable); JpegQuantizationTableConfig defaultChrominanceQuantTable = new(1, Quantization.ChrominanceTable); - JpegHuffmanTableConfig[] yCbCrHuffmanConfigs = new JpegHuffmanTableConfig[] - { + JpegHuffmanTableConfig[] yCbCrHuffmanConfigs = + [ defaultLuminanceHuffmanDC, defaultLuminanceHuffmanAC, defaultChrominanceHuffmanDC, - defaultChrominanceHuffmanAC, - }; + defaultChrominanceHuffmanAC + ]; - JpegQuantizationTableConfig[] yCbCrQuantTableConfigs = new JpegQuantizationTableConfig[] - { + JpegQuantizationTableConfig[] yCbCrQuantTableConfigs = + [ defaultLuminanceQuantTable, - defaultChrominanceQuantTable, - }; + defaultChrominanceQuantTable + ]; + + return + [ - return new JpegFrameConfig[] - { // YCbCr 4:4:4 - new( + new JpegFrameConfig( JpegColorSpace.YCbCr, JpegColorType.YCbCrRatio444, - new JpegComponentConfig[] - { - new(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), - new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), - }, + [ + new JpegComponentConfig(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), + new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1) + ], yCbCrHuffmanConfigs, yCbCrQuantTableConfigs), // YCbCr 4:2:2 - new( + new JpegFrameConfig( JpegColorSpace.YCbCr, JpegColorType.YCbCrRatio422, - new JpegComponentConfig[] - { - new(id: 1, hsf: 2, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), - new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), - }, + [ + new JpegComponentConfig(id: 1, hsf: 2, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), + new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1) + ], yCbCrHuffmanConfigs, yCbCrQuantTableConfigs), // YCbCr 4:2:0 - new( + new JpegFrameConfig( JpegColorSpace.YCbCr, JpegColorType.YCbCrRatio420, - new JpegComponentConfig[] - { - new(id: 1, hsf: 2, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), - new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), - }, + [ + new JpegComponentConfig(id: 1, hsf: 2, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), + new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1) + ], yCbCrHuffmanConfigs, yCbCrQuantTableConfigs), // YCbCr 4:1:1 - new( + new JpegFrameConfig( JpegColorSpace.YCbCr, JpegColorType.YCbCrRatio411, - new JpegComponentConfig[] - { - new(id: 1, hsf: 4, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), - new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), - }, + [ + new JpegComponentConfig(id: 1, hsf: 4, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), + new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1) + ], yCbCrHuffmanConfigs, yCbCrQuantTableConfigs), // YCbCr 4:1:0 - new( + new JpegFrameConfig( JpegColorSpace.YCbCr, JpegColorType.YCbCrRatio410, - new JpegComponentConfig[] - { - new(id: 1, hsf: 4, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), - new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), - }, + [ + new JpegComponentConfig(id: 1, hsf: 4, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1), + new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1) + ], yCbCrHuffmanConfigs, yCbCrQuantTableConfigs), // Luminance - new( + new JpegFrameConfig( JpegColorSpace.Grayscale, JpegColorType.Luminance, - new JpegComponentConfig[] - { - new(id: 0, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - }, - new JpegHuffmanTableConfig[] - { + [ + new JpegComponentConfig(id: 0, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0) + ], + [ defaultLuminanceHuffmanDC, defaultLuminanceHuffmanAC - }, - new JpegQuantizationTableConfig[] - { + ], + [ defaultLuminanceQuantTable - }), + ]), // Rgb - new( + new JpegFrameConfig( JpegColorSpace.RGB, JpegColorType.Rgb, - new JpegComponentConfig[] - { - new(id: 82, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 71, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 66, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - }, - new JpegHuffmanTableConfig[] - { + [ + new JpegComponentConfig(id: 82, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 71, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 66, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0) + ], + [ defaultLuminanceHuffmanDC, defaultLuminanceHuffmanAC - }, - new JpegQuantizationTableConfig[] - { + ], + [ defaultLuminanceQuantTable - }) + ]) { AdobeColorTransformMarkerFlag = JpegConstants.Adobe.ColorTransformUnknown }, // Cmyk - new( + new JpegFrameConfig( JpegColorSpace.Cmyk, JpegColorType.Cmyk, - new JpegComponentConfig[] - { - new(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - }, - new JpegHuffmanTableConfig[] - { + [ + new JpegComponentConfig(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0) + ], + [ defaultLuminanceHuffmanDC, defaultLuminanceHuffmanAC - }, - new JpegQuantizationTableConfig[] - { + ], + [ defaultLuminanceQuantTable - }) + ]) { AdobeColorTransformMarkerFlag = JpegConstants.Adobe.ColorTransformUnknown, }, // YccK - new( + new JpegFrameConfig( JpegColorSpace.Ycck, JpegColorType.Ycck, - new JpegComponentConfig[] - { - new(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - new(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), - }, - new JpegHuffmanTableConfig[] - { + [ + new JpegComponentConfig(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0), + new JpegComponentConfig(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0) + ], + [ defaultLuminanceHuffmanDC, defaultLuminanceHuffmanAC - }, - new JpegQuantizationTableConfig[] - { + ], + [ defaultLuminanceQuantTable - }) + ]) { AdobeColorTransformMarkerFlag = JpegConstants.Adobe.ColorTransformYcck, - }, - }; + } + ]; } } diff --git a/src/ImageSharp/Formats/Png/Chunks/FrameControl.cs b/src/ImageSharp/Formats/Png/Chunks/FrameControl.cs index 0038b4134..1d6f280ef 100644 --- a/src/ImageSharp/Formats/Png/Chunks/FrameControl.cs +++ b/src/ImageSharp/Formats/Png/Chunks/FrameControl.cs @@ -153,7 +153,7 @@ internal readonly struct FrameControl PngThrowHelper.ThrowInvalidImageContentException("The frame control chunk does not contain enough data!"); } - return new( + return new FrameControl( sequenceNumber: BinaryPrimitives.ReadUInt32BigEndian(data[..4]), width: BinaryPrimitives.ReadUInt32BigEndian(data[4..8]), height: BinaryPrimitives.ReadUInt32BigEndian(data[8..12]), diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 28f9a989b..f99fca680 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -291,10 +291,10 @@ internal sealed class PngDecoderCore : ImageDecoderCore } case PngChunkType.Palette: - this.palette = chunk.Data.GetSpan().ToArray(); + this.palette = [.. chunk.Data.GetSpan()]; break; case PngChunkType.Transparency: - this.paletteAlpha = chunk.Data.GetSpan().ToArray(); + this.paletteAlpha = [.. chunk.Data.GetSpan()]; this.AssignTransparentMarkers(this.paletteAlpha, pngMetadata); break; case PngChunkType.Text: @@ -465,11 +465,11 @@ internal sealed class PngDecoderCore : ImageDecoderCore this.SkipChunkDataAndCrc(chunk); break; case PngChunkType.Palette: - this.palette = chunk.Data.GetSpan().ToArray(); + this.palette = [.. chunk.Data.GetSpan()]; break; case PngChunkType.Transparency: - this.paletteAlpha = chunk.Data.GetSpan().ToArray(); + this.paletteAlpha = [.. chunk.Data.GetSpan()]; this.AssignTransparentMarkers(this.paletteAlpha, pngMetadata); // Spec says tRNS must be after PLTE so safe to exit. @@ -1903,7 +1903,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore if (resourceId == adobeIptcResourceId) { - iptcBytes = payload.ToArray(); + iptcBytes = [.. payload]; return true; } @@ -2119,7 +2119,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore } else if (IsXmpTextData(keywordBytes)) { - metadata.XmpProfile = new XmpProfile(data[dataStartIdx..].ToArray()); + metadata.XmpProfile = new XmpProfile([.. data[dataStartIdx..]]); } else { diff --git a/src/ImageSharp/Formats/Qoi/QoiDecoderCore.cs b/src/ImageSharp/Formats/Qoi/QoiDecoderCore.cs index 85fac7ea2..cd31c9dae 100644 --- a/src/ImageSharp/Formats/Qoi/QoiDecoderCore.cs +++ b/src/ImageSharp/Formats/Qoi/QoiDecoderCore.cs @@ -85,7 +85,7 @@ internal class QoiDecoderCore : ImageDecoderCore // Read magic bytes int read = stream.Read(magicBytes); - if (read != 4 || !magicBytes.SequenceEqual(QoiConstants.Magic.ToArray())) + if (read != 4 || !magicBytes.SequenceEqual([.. QoiConstants.Magic])) { ThrowInvalidImageContentException(); } diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs index 983b08c71..454030599 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs @@ -67,7 +67,7 @@ internal static class TiffDecoderOptionsParser TiffSampleFormat? sampleFormat = null; if (exifProfile.TryGetValue(ExifTag.SampleFormat, out IExifValue formatValue)) { - TiffSampleFormat[] sampleFormats = formatValue.Value.Select(a => (TiffSampleFormat)a).ToArray(); + TiffSampleFormat[] sampleFormats = [.. formatValue.Value.Select(a => (TiffSampleFormat)a)]; sampleFormat = sampleFormats[0]; foreach (TiffSampleFormat format in sampleFormats) { diff --git a/src/ImageSharp/Formats/Webp/Lossless/CostManager.cs b/src/ImageSharp/Formats/Webp/Lossless/CostManager.cs index 4ab9d7b94..f5738c7d3 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/CostManager.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/CostManager.cs @@ -23,8 +23,8 @@ internal sealed class CostManager : IDisposable { int costCacheSize = pixCount > BackwardReferenceEncoder.MaxLength ? BackwardReferenceEncoder.MaxLength : pixCount; - this.CacheIntervals = new List(); - this.CostCache = new List(); + this.CacheIntervals = []; + this.CostCache = []; this.Costs = memoryAllocator.Allocate(pixCount); this.DistArray = distArray; this.Count = 0; diff --git a/src/ImageSharp/Formats/Webp/Lossless/CrunchConfig.cs b/src/ImageSharp/Formats/Webp/Lossless/CrunchConfig.cs index 58394c212..fb9c1fd5c 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/CrunchConfig.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/CrunchConfig.cs @@ -7,5 +7,5 @@ internal class CrunchConfig { public EntropyIx EntropyIdx { get; set; } - public List SubConfigs { get; } = new(); + public List SubConfigs { get; } = []; } diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogramSet.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogramSet.cs index 817641393..008ca9e60 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogramSet.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogramSet.cs @@ -51,7 +51,7 @@ internal sealed class Vp8LHistogramSet : IEnumerable, IDisposable public Vp8LHistogramSet(int capacity) => this.items = new List(capacity); - public Vp8LHistogramSet() => this.items = new List(); + public Vp8LHistogramSet() => this.items = []; public int Count => this.items.Count; diff --git a/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs b/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs index 875149b1b..880d8eeff 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs @@ -438,7 +438,7 @@ internal sealed class WebpLosslessDecoder } // TODO: Avoid allocation. - hTreeGroup.HTrees.Add(huffmanTable[..size].ToArray()); + hTreeGroup.HTrees.Add([.. huffmanTable[..size]]); HuffmanCode huffTableZero = huffmanTable[0]; if (isTrivialLiteral && LiteralMap[j] == 1) diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs index 6019a0bff..2cf637654 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs @@ -478,7 +478,7 @@ internal sealed partial class IccDataWriter this.dataStream.Position += cultureCount * 12; // TODO: Investigate cost of Linq GroupBy - IGrouping[] texts = value.Texts.GroupBy(t => t.Text).ToArray(); + IGrouping[] texts = [.. value.Texts.GroupBy(t => t.Text)]; uint[] offset = new uint[texts.Length]; int[] lengths = new int[texts.Length]; diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs index 084ec388d..5e1c1942a 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs @@ -102,7 +102,7 @@ internal sealed class IccReader entries.Add(entry); } - return entries.ToArray(); + return [.. entries]; } private static IccTagTableEntry[] ReadTagTable(IccDataReader reader) @@ -132,6 +132,6 @@ internal sealed class IccReader } } - return table.ToArray(); + return [.. table]; } } diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs index 6bc0560f0..4a88a76f6 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs @@ -81,6 +81,6 @@ internal sealed class IccWriter } } - return table.ToArray(); + return [.. table]; } } diff --git a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs index 7db26e5c5..5f9496140 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs @@ -102,7 +102,7 @@ internal sealed class IccTextDescriptionTagDataEntry : IccTagDataEntry, IEquatab localString = new IccLocalizedString(string.Empty); } - return new IccMultiLocalizedUnicodeTagDataEntry(new[] { localString }, textEntry.TagSignature); + return new IccMultiLocalizedUnicodeTagDataEntry([localString], textEntry.TagSignature); static CultureInfo GetCulture(uint value) { diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/AssociatedAlphaPorterDuffFunctions.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/AssociatedAlphaPorterDuffFunctions.Generated.cs index 5057a25bd..1ba8b5dde 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/AssociatedAlphaPorterDuffFunctions.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/AssociatedAlphaPorterDuffFunctions.Generated.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. // diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/AssociatedAlphaPorterDuffFunctions.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/AssociatedAlphaPorterDuffFunctions.Generated.tt index 8cc89620b..44f9732fa 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/AssociatedAlphaPorterDuffFunctions.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/AssociatedAlphaPorterDuffFunctions.Generated.tt @@ -60,8 +60,8 @@ internal static partial class AssociatedAlphaPorterDuffFunctions } <#+ private static readonly string[] Composers = - { - "Src", + [ + "Src", "SrcAtop", "SrcOver", "SrcIn", @@ -73,12 +73,12 @@ internal static partial class AssociatedAlphaPorterDuffFunctions "DestOut", "Clear", "Xor", - "Plus", - }; + "Plus" + ]; private static readonly string[] Blenders = - { - "Normal", + [ + "Normal", "Multiply", "Add", "Subtract", @@ -95,15 +95,15 @@ internal static partial class AssociatedAlphaPorterDuffFunctions "Hue", "Saturation", "Color", - "Luminosity", - }; + "Luminosity" + ]; private static readonly string[] VectorTypes = - { - "Vector4", + [ + "Vector4", "Vector256", - "Vector512", - }; + "Vector512" + ]; private static string GetComposition(string blender, string composer, string zero) { diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4P.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4P.cs index 1172aafb9..e70dc548c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4P.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4P.cs @@ -169,7 +169,7 @@ public partial struct NormalizedByte4P : IPixel, IPackedVector // Signed-normalized storage uses the native [-1, 1] range even though association is defined in scaled opacity space. source *= 2F; source -= Vector4.One; - return new() { PackedValue = Pack(source) }; + return new NormalizedByte4P { PackedValue = Pack(source) }; } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs index 4b940a6a5..08cc3afa1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs @@ -183,7 +183,7 @@ public partial struct Rgb96 : IPixel, IEquatable public static Rgb96 FromL16(L16 source) { uint rgb = ColorNumerics.From16BitTo32Bit(source.PackedValue); - return new(rgb, rgb, rgb); + return new Rgb96(rgb, rgb, rgb); } /// @@ -191,7 +191,7 @@ public partial struct Rgb96 : IPixel, IEquatable public static Rgb96 FromLa16(La16 source) { uint rgb = ColorNumerics.From8BitTo32Bit((byte)source.PackedValue); - return new(rgb, rgb, rgb); + return new Rgb96(rgb, rgb, rgb); } /// @@ -199,7 +199,7 @@ public partial struct Rgb96 : IPixel, IEquatable public static Rgb96 FromLa32(La32 source) { uint rgb = ColorNumerics.From16BitTo32Bit(source.L); - return new(rgb, rgb, rgb); + return new Rgb96(rgb, rgb, rgb); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs index 86fab4f61..064b71af2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs @@ -180,21 +180,21 @@ public partial struct Rgba128 : IPixel, IEquatable public static Rgba128 FromL16(L16 source) { uint rgb = ColorNumerics.From16BitTo32Bit(source.PackedValue); - return new(rgb, rgb, rgb, rgb); + return new Rgba128(rgb, rgb, rgb, rgb); } /// public static Rgba128 FromLa16(La16 source) { uint rgb = ColorNumerics.From8BitTo32Bit((byte)source.PackedValue); - return new(rgb, rgb, rgb, rgb); + return new Rgba128(rgb, rgb, rgb, rgb); } /// public static Rgba128 FromLa32(La32 source) { uint rgb = ColorNumerics.From16BitTo32Bit(source.L); - return new(rgb, rgb, rgb, rgb); + return new Rgba128(rgb, rgb, rgb, rgb); } /// diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs index 61cde6e2a..b4848c2d6 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs @@ -35,7 +35,7 @@ internal class AffineTransformProcessor : TransformProcessor, IR { this.destinationSize = definition.DestinationSize; this.transformMatrix = definition.TransformMatrix; - this.transformMatrix4x4 = new(this.transformMatrix); + this.transformMatrix4x4 = new Matrix4x4(this.transformMatrix); this.resampler = definition.Sampler; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs index c0380224c..aa24878c6 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs @@ -73,10 +73,10 @@ internal readonly unsafe struct ResizeKernel { if (Vector256.IsHardwareAccelerated) { - return new(this.bufferPtr, this.Length * 4); + return new Span(this.bufferPtr, this.Length * 4); } - return new(this.bufferPtr, this.Length); + return new Span(this.bufferPtr, this.Length); } } diff --git a/tests/ImageSharp.Benchmarks/Processing/ColorMatchingCaches.cs b/tests/ImageSharp.Benchmarks/Processing/ColorMatchingCaches.cs index dbaf21a8e..6e5c531f5 100644 --- a/tests/ImageSharp.Benchmarks/Processing/ColorMatchingCaches.cs +++ b/tests/ImageSharp.Benchmarks/Processing/ColorMatchingCaches.cs @@ -146,7 +146,7 @@ public class ColorMatchingCaches // RGBA space without clustering into a gradient. That keeps the benchmark from // accidentally favoring any cache because the palette itself is too regular. uint value = unchecked((uint)(i + 1) * 2654435761U); - result[i] = new( + result[i] = new Rgba32( (byte)value, (byte)(value >> 8), (byte)(value >> 16), @@ -166,7 +166,7 @@ public class ColorMatchingCaches for (int i = 0; i < result.Length; i++) { Rgba32 source = palette[(i * 17) % palette.Length]; - result[i] = new( + result[i] = new Rgba32( (byte)(source.R + ((i * 3) & 0x07)), (byte)(source.G + ((i * 5) & 0x07)), (byte)(source.B + ((i * 7) & 0x07)), @@ -200,7 +200,7 @@ public class ColorMatchingCaches int x = i & 511; int y = i >> 9; - result[i] = new( + result[i] = new Rgba32( (byte)((x * 17) + (y * 13)), (byte)((x * 29) + (y * 7)), (byte)((x * 11) + (y * 23)), diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs index cb349af96..cfb4b8e72 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs @@ -189,7 +189,7 @@ public class ColorProfileConverterTests(ITestOutputHelper testOutputHelper) { case IccColorSpaceType.Cmyk: { - Span inputSpan = inputs.Select(x => new Cmyk(new Vector4(x))).ToArray(); + Span inputSpan = [.. inputs.Select(x => new Cmyk(new Vector4(x)))]; switch (targetDataSpace) { @@ -214,7 +214,7 @@ public class ColorProfileConverterTests(ITestOutputHelper testOutputHelper) case IccColorSpaceType.Rgb: { - Span inputSpan = inputs.Select(x => new Rgb(new Vector3(x))).ToArray(); + Span inputSpan = [.. inputs.Select(x => new Rgb(new Vector3(x)))]; switch (targetDataSpace) { diff --git a/tests/ImageSharp.Tests/ColorProfiles/RgbWorkingSpaceTests.cs b/tests/ImageSharp.Tests/ColorProfiles/RgbWorkingSpaceTests.cs index 8a38ea11f..3896418e8 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/RgbWorkingSpaceTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/RgbWorkingSpaceTests.cs @@ -110,7 +110,7 @@ public class RgbWorkingSpaceTests Assert.Equal(linear[i], expanded, TolerantComparer); } - Vector4[] actualCompressed = linear.ToArray(); + Vector4[] actualCompressed = [.. linear]; workingSpace.Compress(actualCompressed); Assert.Equal(expectedCompressed, actualCompressed, TolerantComparer); diff --git a/tests/ImageSharp.Tests/Common/EncoderExtensionsTests.cs b/tests/ImageSharp.Tests/Common/EncoderExtensionsTests.cs index 8421c1fd7..943c643c1 100644 --- a/tests/ImageSharp.Tests/Common/EncoderExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Common/EncoderExtensionsTests.cs @@ -20,7 +20,7 @@ public class EncoderExtensionsTests [Fact] public void GetString_Buffer_ReturnsString() { - ReadOnlySpan buffer = new(new byte[] { 73, 109, 97, 103, 101, 83, 104, 97, 114, 112 }); + ReadOnlySpan buffer = new([73, 109, 97, 103, 101, 83, 104, 97, 114, 112]); string result = Encoding.UTF8.GetString(buffer); diff --git a/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs b/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs index 71335032c..38a0a8d24 100644 --- a/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs +++ b/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs @@ -171,10 +171,10 @@ public partial class SimdUtilsTests int count, Action, Memory> convert) { - byte[] source = Enumerable.Range(0, count).Select(i => (byte)i).ToArray(); + byte[] source = [.. Enumerable.Range(0, count).Select(i => (byte)i)]; float[] result = new float[count]; // A double-precision oracle keeps this expectation independent from either production implementation. - float[] expected = source.Select(b => (float)(b / (double)byte.MaxValue)).ToArray(); + float[] expected = [.. source.Select(b => (float)(b / (double)byte.MaxValue))]; convert(source, result); @@ -222,7 +222,7 @@ public partial class SimdUtilsTests [Fact] public void BulkConvertNormalizedFloatToByteRoundsMidpointsAwayFromZero() { - float[] midpointValues = Enumerable.Range(0, byte.MaxValue).Select(x => (x + 0.5F) / byte.MaxValue).ToArray(); + float[] midpointValues = [.. Enumerable.Range(0, byte.MaxValue).Select(x => (x + 0.5F) / byte.MaxValue)]; float[] source = new float[1024]; byte[] expected = new byte[source.Length]; byte[] actual = new byte[source.Length]; @@ -280,9 +280,9 @@ public partial class SimdUtilsTests return; } - byte[] r = Enumerable.Range(0, 32).Select(x => (byte)x).ToArray(); - byte[] g = Enumerable.Range(100, 32).Select(x => (byte)x).ToArray(); - byte[] b = Enumerable.Range(200, 32).Select(x => (byte)x).ToArray(); + byte[] r = [.. Enumerable.Range(0, 32).Select(x => (byte)x)]; + byte[] g = [.. Enumerable.Range(100, 32).Select(x => (byte)x)]; + byte[] b = [.. Enumerable.Range(200, 32).Select(x => (byte)x)]; const int padding = 4; Rgb24[] d = new Rgb24[32 + padding]; @@ -314,9 +314,9 @@ public partial class SimdUtilsTests return; } - byte[] r = Enumerable.Range(0, 32).Select(x => (byte)x).ToArray(); - byte[] g = Enumerable.Range(100, 32).Select(x => (byte)x).ToArray(); - byte[] b = Enumerable.Range(200, 32).Select(x => (byte)x).ToArray(); + byte[] r = [.. Enumerable.Range(0, 32).Select(x => (byte)x)]; + byte[] g = [.. Enumerable.Range(100, 32).Select(x => (byte)x)]; + byte[] b = [.. Enumerable.Range(200, 32).Select(x => (byte)x)]; Rgba32[] d = new Rgba32[32]; @@ -369,7 +369,7 @@ public partial class SimdUtilsTests { seed = seed > 0 ? seed : count; float[] source = new Random(seed).GenerateRandomFloatArray(count, -0.2f, 1.2f); - byte[] expected = source.Select(NormalizedFloatToByte).ToArray(); + byte[] expected = [.. source.Select(NormalizedFloatToByte)]; byte[] actual = new byte[count]; convert(source, actual); diff --git a/tests/ImageSharp.Tests/Common/StreamExtensionsTests.cs b/tests/ImageSharp.Tests/Common/StreamExtensionsTests.cs index 5ea7afaf8..2cf62c10c 100644 --- a/tests/ImageSharp.Tests/Common/StreamExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Common/StreamExtensionsTests.cs @@ -79,7 +79,7 @@ public class StreamExtensionsTests { public override bool CanSeek => false; - public List Counts = new(); + public List Counts = []; public NonSeekableStream() : base(4) diff --git a/tests/ImageSharp.Tests/Common/TensorPrimitivesTests.cs b/tests/ImageSharp.Tests/Common/TensorPrimitivesTests.cs index b2f4dfe76..3437e800b 100644 --- a/tests/ImageSharp.Tests/Common/TensorPrimitivesTests.cs +++ b/tests/ImageSharp.Tests/Common/TensorPrimitivesTests.cs @@ -251,7 +251,7 @@ public class TensorPrimitivesTests public void NegateSingleMatchesScalarFormula(int length) { float[] values = - { + [ float.NaN, -0F, 0F, @@ -259,7 +259,7 @@ public class TensorPrimitivesTests 1F, float.NegativeInfinity, float.PositiveInfinity - }; + ]; float[] source = new float[length]; float[] expected = new float[length]; @@ -287,7 +287,7 @@ public class TensorPrimitivesTests public void NegateDoubleMatchesScalarFormula(int length) { double[] values = - { + [ double.NaN, -0D, 0D, @@ -295,7 +295,7 @@ public class TensorPrimitivesTests 1D, double.NegativeInfinity, double.PositiveInfinity - }; + ]; double[] source = new double[length]; double[] expected = new double[length]; @@ -349,7 +349,7 @@ public class TensorPrimitivesTests public void ClampSingleMatchesRuntimeFormula(int length) { float[] values = - { + [ float.NaN, -0F, 0F, @@ -357,7 +357,7 @@ public class TensorPrimitivesTests 1F, float.NegativeInfinity, float.PositiveInfinity - }; + ]; float[] source = new float[length]; float[] expected = new float[length]; @@ -381,13 +381,13 @@ public class TensorPrimitivesTests public void ClampSinglePreservesRuntimeSpecialValueSemantics() { float[] values = - { + [ float.NaN, float.NegativeInfinity, -0F, 0F, float.PositiveInfinity - }; + ]; float[] actual = new float[129]; float[] expected = new float[actual.Length]; @@ -409,13 +409,13 @@ public class TensorPrimitivesTests public void ClampDoublePreservesRuntimeSpecialValueSemantics() { double[] values = - { + [ double.NaN, double.NegativeInfinity, -0D, 0D, double.PositiveInfinity - }; + ]; double[] actual = new double[65]; double[] expected = new double[actual.Length]; @@ -465,7 +465,7 @@ public class TensorPrimitivesTests public void MaxSingleMatchesRuntimeFormula(int length) { float[] values = - { + [ float.NaN, float.NegativeInfinity, -1F, @@ -473,7 +473,7 @@ public class TensorPrimitivesTests 0F, 1F, float.PositiveInfinity - }; + ]; float[] actual = new float[length]; float[] expected = new float[length]; diff --git a/tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs index 93de4d2d9..8ad5a0a2d 100644 --- a/tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs @@ -71,7 +71,7 @@ public class AniDecoderTests [Fact] public void AniDecoder_InvalidSequenceReference_FollowsIntegrityHandling() { - byte[] data = TestFile.Create(Help).Bytes.ToArray(); + byte[] data = [.. TestFile.Create(Help).Bytes]; int sequenceOffset = data.AsSpan().IndexOf("seq "u8); Assert.True(sequenceOffset >= 0); @@ -94,7 +94,7 @@ public class AniDecoderTests [Fact] public void AniDecoder_UnsupportedResource_FollowsIntegrityHandling() { - byte[] data = TestFile.Create(Work).Bytes.ToArray(); + byte[] data = [.. TestFile.Create(Work).Bytes]; int resourceOffset = data.AsSpan().IndexOf("icon"u8); Assert.True(resourceOffset >= 0); @@ -119,7 +119,7 @@ public class AniDecoderTests [Fact] public void AniDecoder_InvalidRateChunk_FollowsIntegrityHandling() { - byte[] source = TestFile.Create(Help).Bytes.ToArray(); + byte[] source = [.. TestFile.Create(Help).Bytes]; int rateOffset = source.AsSpan().IndexOf("rate"u8); Assert.True(rateOffset >= 0); @@ -155,7 +155,7 @@ public class AniDecoderTests [InlineData(true)] public void AniDecoder_OversizedControlChunk_FollowsIntegrityHandling(bool sequence) { - byte[] source = TestFile.Create(Help).Bytes.ToArray(); + byte[] source = [.. TestFile.Create(Help).Bytes]; int chunkOffset = (source.Length + 1) & ~1; int payloadSize = AniConstants.MaxAncillaryChunkSize + sizeof(uint); byte[] data = new byte[chunkOffset + AniConstants.ChunkHeaderSize + payloadSize]; @@ -182,7 +182,7 @@ public class AniDecoderTests [Fact] public void AniDecoder_OversizedInformationText_FollowsIntegrityHandling() { - byte[] source = TestFile.Create(Help).Bytes.ToArray(); + byte[] source = [.. TestFile.Create(Help).Bytes]; int listOffset = (source.Length + 1) & ~1; int textSize = AniConstants.MaxAncillaryChunkSize + 1; int paddedTextSize = textSize + (textSize & 1); diff --git a/tests/ImageSharp.Tests/Formats/Exr/ExrDecoderSecurityTests.cs b/tests/ImageSharp.Tests/Formats/Exr/ExrDecoderSecurityTests.cs index 2d59c0235..77aadae38 100644 --- a/tests/ImageSharp.Tests/Formats/Exr/ExrDecoderSecurityTests.cs +++ b/tests/ImageSharp.Tests/Formats/Exr/ExrDecoderSecurityTests.cs @@ -39,7 +39,7 @@ public class ExrDecoderSecurityTests // Width = 1073741823 - (-1073741825) + 1 = 2^31 + 1 → wraps to -2147483647 byte[] data = BuildMinimalExr(xMin: -1073741825, yMin: 0, xMax: 1073741823, yMax: 0); - using var stream = new MemoryStream(data); + using MemoryStream stream = new(data); Assert.Throws( () => ExrDecoder.Instance.Decode(DecoderOptions.Default, stream)); } @@ -74,7 +74,7 @@ public class ExrDecoderSecurityTests xMin: 0, yMin: 0, xMax: 1, yMax: 1, rowOffsetTableAppend: invalidOffsets); - using var stream = new MemoryStream(data); + using MemoryStream stream = new(data); Assert.Throws( () => ExrDecoder.Instance.Decode(DecoderOptions.Default, stream)); } @@ -90,7 +90,7 @@ public class ExrDecoderSecurityTests xMin: 0, yMin: 0, xMax: 1, yMax: 1, rowOffsetTableAppend: headerOffsets); - using var stream = new MemoryStream(data); + using MemoryStream stream = new(data); Assert.Throws( () => ExrDecoder.Instance.Decode(DecoderOptions.Default, stream)); } @@ -105,7 +105,7 @@ public class ExrDecoderSecurityTests // Point the first row offset at the second row offset entry. BinaryPrimitives.WriteUInt64LittleEndian(data.AsSpan(data.Length - 16), (ulong)(data.Length - 8)); - using var stream = new MemoryStream(data); + using MemoryStream stream = new(data); Assert.Throws( () => ExrDecoder.Instance.Decode(DecoderOptions.Default, stream)); } @@ -128,7 +128,7 @@ public class ExrDecoderSecurityTests // int-sized row staging or block buffers. byte[] data = BuildMinimalRgbaExr(xMin: 0, yMin: 0, xMax: 536870911, yMax: 0); - using var stream = new MemoryStream(data); + using MemoryStream stream = new(data); Assert.Throws( () => ExrDecoder.Instance.Decode(DecoderOptions.Default, stream)); } @@ -140,7 +140,7 @@ public class ExrDecoderSecurityTests // still stages four color planes and must reject widths that overflow width × 4. byte[] data = BuildMinimalExr(xMin: 0, yMin: 0, xMax: int.MaxValue / 4, yMax: 0); - using var stream = new MemoryStream(data); + using MemoryStream stream = new(data); Assert.Throws( () => ExrDecoder.Instance.Decode(DecoderOptions.Default, stream)); } @@ -152,7 +152,7 @@ public class ExrDecoderSecurityTests // validated before scanline decoding reads from the table. byte[] data = BuildMinimalExr(xMin: 0, yMin: 0, xMax: 1, yMax: 1); - using var stream = new MemoryStream(data); + using MemoryStream stream = new(data); Assert.Throws( () => ExrDecoder.Instance.Identify(DecoderOptions.Default, stream)); } @@ -223,8 +223,8 @@ public class ExrDecoderSecurityTests byte[] channelData, byte[] rowOffsetTableAppend = null) { - using var ms = new MemoryStream(); - using var bw = new BinaryWriter(ms, System.Text.Encoding.ASCII, leaveOpen: true); + using MemoryStream ms = new(); + using BinaryWriter bw = new(ms, System.Text.Encoding.ASCII, leaveOpen: true); // Magic (0x01312F76 LE) + version 2, scanline (flags = 0x00) bw.Write(new byte[] { 0x76, 0x2F, 0x31, 0x01, 0x02, 0x00, 0x00, 0x00 }); diff --git a/tests/ImageSharp.Tests/Formats/Icon/Ico/IcoDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Icon/Ico/IcoDecoderTests.cs index bdbf67461..46cd99aa3 100644 --- a/tests/ImageSharp.Tests/Formats/Icon/Ico/IcoDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Icon/Ico/IcoDecoderTests.cs @@ -320,7 +320,7 @@ public class IcoDecoderTests [Fact] public void TruncatedEntry_FollowsImageDataIntegrityHandling() { - byte[] data = TestFile.Create(Flutter).Bytes.ToArray(); + byte[] data = [.. TestFile.Create(Flutter).Bytes]; ushort entryCount = BinaryPrimitives.ReadUInt16LittleEndian(data.AsSpan(4)); Assert.True(entryCount > 1); @@ -347,7 +347,7 @@ public class IcoDecoderTests [Fact] public void EntryAtEndOfStream_ThrowsInvalidResourceRange() { - byte[] data = TestFile.Create(Bpp32Size1x1).Bytes.ToArray(); + byte[] data = [.. TestFile.Create(Bpp32Size1x1).Bytes]; Assert.Equal(1, BinaryPrimitives.ReadUInt16LittleEndian(data.AsSpan(4))); // ImageOffset is the final DWORD in the sole directory entry. The stream length is an exclusive boundary, diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegMetadataTests.cs index 37be0f8f5..6ea528818 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegMetadataTests.cs @@ -71,7 +71,7 @@ public class JpegMetadataTests public void Comment_OnlyComment() { string comment = "test comment"; - Collection expectedCollection = new() { comment }; + Collection expectedCollection = [comment]; JpegMetadata meta = new(); meta.Comments.Add(JpegComData.FromString(comment)); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs index 1610df6eb..89ca10c8a 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs @@ -36,7 +36,7 @@ public class SpectralJpegTests TestImages.Jpeg.Progressive.Bad.ExifUndefType ]; - public static readonly string[] AllTestJpegs = BaselineTestJpegs.Concat(ProgressiveTestJpegs).ToArray(); + public static readonly string[] AllTestJpegs = [.. BaselineTestJpegs, .. ProgressiveTestJpegs]; [Theory(Skip = "Debug only, enable manually!")] [WithFileCollection(nameof(AllTestJpegs), PixelTypes.Rgba32)] diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs index 888459112..370736c40 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs @@ -121,7 +121,7 @@ internal static partial class LibJpegTools { rdr.Read(buffer, 0, buffer.Length); - short[] block = MemoryMarshal.Cast(buffer.AsSpan()).ToArray(); + short[] block = [.. MemoryMarshal.Cast(buffer.AsSpan())]; c.MakeBlock(block, y, x); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs index 7a31e35d0..c9d84c3ca 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs @@ -34,7 +34,7 @@ internal static class VerifyJpeg int xBc2, int yBc2) { - IJpegComponent[] c = components.ToArray(); + IJpegComponent[] c = [.. components]; Assert.Equal(3, components.Count()); VerifySize(c[0], xBc0, yBc0); diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index eef8d5ba8..ed238e3fb 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -287,7 +287,7 @@ public partial class PngEncoderTests using MemoryStream ms = new(); image.Save(ms, PngEncoder); - byte[] data = ms.ToArray().Take(8).ToArray(); + byte[] data = [.. ms.ToArray().Take(8)]; byte[] expected = [ 0x89, // Set the high bit. diff --git a/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs index 42048426e..574602704 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs @@ -32,7 +32,7 @@ public class PngMetadataTests ColorType = PngColorType.GrayscaleWithAlpha, InterlaceMethod = PngInterlaceMode.Adam7, Gamma = 2, - TextData = [new("name", "value", "foo", "bar")], + TextData = [new PngTextData("name", "value", "foo", "bar")], RepeatCount = 123, AnimateRootFrame = false }; diff --git a/tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs index 6aebf7b9c..3bcf6c2c8 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs @@ -137,7 +137,7 @@ public class BigTiffMetadataTests }; // arrange - List values = new(); + List values = []; foreach (KeyValuePair tag in testTags) { ExifValue newExifValue = ExifValues.Create((ExifTagValue)(ushort)tag.Key, tag.Value.DataType, tag.Value.Value is Array); @@ -182,7 +182,7 @@ public class BigTiffMetadataTests ////{ new ExifTag((ExifTagValue)0xdd14), (ExifDataType.SignedLong8, new long[] { -1234, 56789L, long.MaxValue }) }, }; - List values = new(); + List values = []; foreach (KeyValuePair tag in testTags) { ExifValue newExifValue = ExifValues.Create((ExifTagValue)(ushort)tag.Key, tag.Value.DataType, tag.Value.Value is Array); diff --git a/tests/ImageSharp.Tests/Formats/WebP/Vp8HistogramTests.cs b/tests/ImageSharp.Tests/Formats/WebP/Vp8HistogramTests.cs index 990c58385..fa240c55b 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/Vp8HistogramTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8HistogramTests.cs @@ -13,55 +13,59 @@ public class Vp8HistogramTests { get { - List result = new(); - result.Add(new object[] - { - new byte[] - { - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, - 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204, - 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, - 204, 204, 204, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204, - 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, - 204, 204, 204, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204, - 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, - 204, 204, 204, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 24, 16, 204, 204, 204, - 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, - 204, 204, 204 - }, - new byte[] - { - 128, 128, 128, 128, 129, 129, 129, 129, 127, 127, 127, 127, 129, 129, 129, 129, 128, 127, 127, - 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 128, 128, 129, 129, - 129, 129, 127, 127, 127, 127, 129, 129, 129, 129, 129, 128, 127, 127, 128, 127, 127, 127, 127, - 127, 127, 127, 127, 127, 127, 127, 128, 128, 128, 128, 129, 129, 129, 129, 127, 127, 127, 127, - 129, 129, 129, 129, 129, 129, 128, 127, 129, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, - 127, 128, 128, 128, 128, 129, 129, 129, 129, 127, 127, 127, 127, 129, 129, 129, 129, 129, 129, - 129, 128, 129, 128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 127, 127, 129, - 129, 129, 129, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, - 204, 204, 204, 204, 204, 204, 204, 204, 129, 129, 128, 128, 129, 129, 129, 129, 204, 204, 204, - 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, - 204, 204, 129, 129, 129, 129, 129, 129, 129, 129, 204, 204, 204, 204, 204, 204, 204, 204, 204, - 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 129, 129, 129, 129, - 129, 129, 129, 129, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, - 204, 204, 204, 204, 204, 204, 204, 204, 204 - } - }); + List result = + [ + [ + new byte[] + { + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, + 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 19, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 204, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204, + 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 19, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 24, 16, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 204 + }, + new byte[] + { + 128, 128, 128, 128, 129, 129, 129, 129, 127, 127, 127, 127, 129, 129, 129, 129, 128, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, + 128, 128, 129, 129, 129, 129, 127, 127, 127, 127, 129, 129, 129, 129, 129, 128, 127, + 127, 128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 128, 128, + 129, 129, 129, 129, 127, 127, 127, 127, 129, 129, 129, 129, 129, 129, 128, 127, 129, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 128, 128, 129, 129, + 129, 129, 127, 127, 127, 127, 129, 129, 129, 129, 129, 129, 129, 128, 129, 128, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 127, 127, 129, 129, 129, 129, + 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 204, 204, 129, 129, 128, 128, 129, 129, 129, 129, 204, 204, + 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 129, 129, 129, 129, 129, 129, 129, 129, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 204, 204, 129, 129, 129, 129, 129, 129, 129, 129, 204, 204, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204 + } + ] + ]; return result; } } @@ -72,7 +76,7 @@ public class Vp8HistogramTests Vp8Histogram histogram = new(); byte[] reference = - { + [ 154, 154, 151, 151, 149, 148, 151, 157, 163, 163, 154, 132, 102, 98, 104, 108, 107, 104, 104, 103, 101, 106, 123, 119, 170, 171, 172, 171, 168, 175, 171, 173, 151, 151, 149, 150, 147, 147, 146, 159, 164, 165, 154, 129, 92, 90, 101, 105, 104, 103, 104, 101, 100, 105, 123, 117, 172, 172, 172, 168, @@ -99,9 +103,9 @@ public class Vp8HistogramTests 95, 102, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 151, 130, 82, 82, 89, 134, 154, 161, 161, 157, 152, 129, 81, 77, 95, 102, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204 - }; + ]; byte[] pred = - { + [ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, @@ -154,7 +158,7 @@ public class Vp8HistogramTests 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129 - }; + ]; int expectedAlpha = 146; // act diff --git a/tests/ImageSharp.Tests/Helpers/NumericsTests.cs b/tests/ImageSharp.Tests/Helpers/NumericsTests.cs index 35109d352..0a498a0b7 100644 --- a/tests/ImageSharp.Tests/Helpers/NumericsTests.cs +++ b/tests/ImageSharp.Tests/Helpers/NumericsTests.cs @@ -178,11 +178,14 @@ public class NumericsTests }; } - Vector4[] expected = source.Select(v => - { - Numerics.Premultiply(ref v); - return v; - }).ToArray(); + Vector4[] expected = + [ + .. source.Select(v => + { + Numerics.Premultiply(ref v); + return v; + }) + ]; Numerics.Premultiply(source); @@ -213,11 +216,14 @@ public class NumericsTests }; } - Vector4[] expected = source.Select(v => - { - Numerics.UnPremultiply(ref v); - return v; - }).ToArray(); + Vector4[] expected = + [ + .. source.Select(v => + { + Numerics.UnPremultiply(ref v); + return v; + }) + ]; Numerics.UnPremultiply(source); diff --git a/tests/ImageSharp.Tests/Helpers/ParallelRowIteratorTests.cs b/tests/ImageSharp.Tests/Helpers/ParallelRowIteratorTests.cs index 017926fc5..3edf3689a 100644 --- a/tests/ImageSharp.Tests/Helpers/ParallelRowIteratorTests.cs +++ b/tests/ImageSharp.Tests/Helpers/ParallelRowIteratorTests.cs @@ -101,7 +101,7 @@ public class ParallelRowIteratorTests Rectangle rectangle = new(0, minY, 10, maxY - minY); - int[] expectedData = Enumerable.Repeat(0, minY).Concat(Enumerable.Range(minY, maxY - minY)).ToArray(); + int[] expectedData = [.. Enumerable.Repeat(0, minY), .. Enumerable.Range(minY, maxY - minY)]; int[] actualData = new int[maxY]; void RowAction(RowInterval rows) @@ -180,7 +180,7 @@ public class ParallelRowIteratorTests Rectangle rectangle = new(0, minY, 10, maxY - minY); - int[] expectedData = Enumerable.Repeat(0, minY).Concat(Enumerable.Range(minY, maxY - minY)).ToArray(); + int[] expectedData = [.. Enumerable.Repeat(0, minY), .. Enumerable.Range(minY, maxY - minY)]; int[] actualData = new int[maxY]; void RowAction(RowInterval rows, Span buffer) diff --git a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs index 417ee18fb..391cff506 100644 --- a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs +++ b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs @@ -181,7 +181,7 @@ public abstract partial class ImageFrameCollectionTests this.Image, [imageFrame1, imageFrame2]); - IPixelSource[] framesSnapShot = collection.OfType>().ToArray(); + IPixelSource[] framesSnapShot = [.. collection.OfType>()]; Assert.All(framesSnapShot, f => Assert.False(f.PixelBuffer.IsDisposed)); diff --git a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs index cd1213c23..de06a51a9 100644 --- a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs +++ b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs @@ -29,7 +29,7 @@ public abstract partial class ImageFrameCollectionTests } Rgba32[] expectedAllBlue = - Enumerable.Repeat(Color.Blue.ToPixel(), this.Image.Width * this.Image.Height).ToArray(); + [.. Enumerable.Repeat(Color.Blue.ToPixel(), this.Image.Width * this.Image.Height)]; Assert.Equal(2, this.Collection.Count); ImageFrame actualFrame = (ImageFrame)this.Collection[1]; @@ -50,7 +50,7 @@ public abstract partial class ImageFrameCollectionTests } Rgba32[] expectedAllBlue = - Enumerable.Repeat(Color.Blue.ToPixel(), this.Image.Width * this.Image.Height).ToArray(); + [.. Enumerable.Repeat(Color.Blue.ToPixel(), this.Image.Width * this.Image.Height)]; Assert.Equal(2, this.Collection.Count); ImageFrame actualFrame = (ImageFrame)this.Collection[0]; diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs b/tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs index 0656f9e0b..af50cca69 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs @@ -26,7 +26,7 @@ public partial class ImageTests //TestImages.Pbm.GrayscaleBinaryWide ]; - public static object[][] IdentifyData { get; } = TestFileForEachCodec.Select(f => new object[] { f }).ToArray(); + public static object[][] IdentifyData { get; } = [.. TestFileForEachCodec.Select(f => new object[] { f })]; [Theory] [MemberData(nameof(IdentifyData))] diff --git a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs index 65eeb124f..f86ce344f 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs @@ -146,14 +146,14 @@ public partial class ImageTests { Rgba32[] source = [ - new Rgba32(1, 1, 1, 255), - new Rgba32(2, 2, 2, 255), - new Rgba32(3, 3, 3, 255), - new Rgba32(90, 90, 90, 255), - new Rgba32(4, 4, 4, 255), - new Rgba32(5, 5, 5, 255), - new Rgba32(6, 6, 6, 255), - new Rgba32(91, 91, 91, 255) + new(1, 1, 1, 255), + new(2, 2, 2, 255), + new(3, 3, 3, 255), + new(90, 90, 90, 255), + new(4, 4, 4, 255), + new(5, 5, 5, 255), + new(6, 6, 6, 255), + new(91, 91, 91, 255) ]; using Image image = Image.WrapMemory(source.AsMemory(), width: 3, height: 2, rowStride: 4); @@ -171,14 +171,14 @@ public partial class ImageTests { Rgba32[] source = [ - new Rgba32(1, 1, 1, 255), - new Rgba32(2, 2, 2, 255), - new Rgba32(3, 3, 3, 255), - new Rgba32(90, 90, 90, 255), - new Rgba32(4, 4, 4, 255), - new Rgba32(5, 5, 5, 255), - new Rgba32(6, 6, 6, 255), - new Rgba32(91, 91, 91, 255) + new(1, 1, 1, 255), + new(2, 2, 2, 255), + new(3, 3, 3, 255), + new(90, 90, 90, 255), + new(4, 4, 4, 255), + new(5, 5, 5, 255), + new(6, 6, 6, 255), + new(91, 91, 91, 255) ]; using Image image = Image.WrapMemory(source.AsMemory(), width: 3, height: 2, rowStride: 4); diff --git a/tests/ImageSharp.Tests/Memory/Allocators/SharedArrayPoolBufferTests.cs b/tests/ImageSharp.Tests/Memory/Allocators/SharedArrayPoolBufferTests.cs index 72b90c238..848cd1c1a 100644 --- a/tests/ImageSharp.Tests/Memory/Allocators/SharedArrayPoolBufferTests.cs +++ b/tests/ImageSharp.Tests/Memory/Allocators/SharedArrayPoolBufferTests.cs @@ -23,7 +23,7 @@ public class SharedArrayPoolBufferTests } byte[] array = ArrayPool.Shared.Rent(900); - byte[] expected = Enumerable.Repeat((byte)42, 900).ToArray(); + byte[] expected = [.. Enumerable.Repeat((byte)42, 900)]; Assert.True(expected.AsSpan().SequenceEqual(array.AsSpan(0, 900))); } @@ -48,7 +48,7 @@ public class SharedArrayPoolBufferTests buffer.ReleaseRef(); array = ArrayPool.Shared.Rent(900); - byte[] expected = Enumerable.Repeat((byte)42, 900).ToArray(); + byte[] expected = [.. Enumerable.Repeat((byte)42, 900)]; Assert.True(expected.AsSpan().SequenceEqual(array.AsSpan(0, 900))); ArrayPool.Shared.Return(array); } diff --git a/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.cs b/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.cs index ec79d91c3..ab388386a 100644 --- a/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.cs +++ b/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.cs @@ -18,8 +18,8 @@ public partial class UniformUnmanagedMemoryPoolTests private class CleanupUtil : IDisposable { private readonly UniformUnmanagedMemoryPool pool; - private readonly List handlesToDestroy = new(); - private readonly List ptrsToDestroy = new(); + private readonly List handlesToDestroy = []; + private readonly List ptrsToDestroy = []; public CleanupUtil(UniformUnmanagedMemoryPool pool) { @@ -151,8 +151,8 @@ public partial class UniformUnmanagedMemoryPoolTests { UniformUnmanagedMemoryPool pool = new(128, capacity); using CleanupUtil cleanup = new(pool); - HashSet allHandles = new(); - List handleUnits = new(); + HashSet allHandles = []; + List handleUnits = []; UnmanagedMemoryHandle[] handles; for (int i = 0; i < totalCount; i += rentUnit) @@ -261,7 +261,7 @@ public partial class UniformUnmanagedMemoryPoolTests pool.Release(); // Do some unmanaged allocations to make sure new pool buffers are different: - IntPtr[] dummy = Enumerable.Range(0, 100).Select(_ => Marshal.AllocHGlobal(16)).ToArray(); + IntPtr[] dummy = [.. Enumerable.Range(0, 100).Select(_ => Marshal.AllocHGlobal(16))]; cleanup.Register(dummy); if (bool.Parse(multipleInner)) @@ -312,7 +312,7 @@ public partial class UniformUnmanagedMemoryPoolTests Parallel.For(0, Environment.ProcessorCount, (int i) => { - List allHandles = new(); + List allHandles = []; int pauseAt = rnd.Next(100); for (int j = 0; j < 100; j++) { diff --git a/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedBufferTests.cs b/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedBufferTests.cs index 3b33eae5e..1fe33c346 100644 --- a/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedBufferTests.cs +++ b/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedBufferTests.cs @@ -76,7 +76,7 @@ public class UnmanagedBufferTests static List> FillList(int countInner) { - List> l = new(); + List> l = []; for (int i = 0; i < countInner; i++) { UnmanagedBuffer h = UnmanagedBuffer.Allocate(42); diff --git a/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedMemoryHandleTests.cs b/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedMemoryHandleTests.cs index 59b793e01..8818597a9 100644 --- a/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedMemoryHandleTests.cs +++ b/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedMemoryHandleTests.cs @@ -47,7 +47,7 @@ public class UnmanagedMemoryHandleTests static void RunTest(string countStr) { int countInner = int.Parse(countStr); - List l = new(); + List l = []; for (int i = 0; i < countInner; i++) { Assert.Equal(i, UnmanagedMemoryHandle.TotalOutstandingHandles); diff --git a/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.Allocate.cs b/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.Allocate.cs index cca2230e6..04d2bedf4 100644 --- a/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.Allocate.cs +++ b/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.Allocate.cs @@ -206,7 +206,7 @@ public partial class MemoryGroupTests { IReadOnlyList allocationLog = this.MemoryAllocator.AllocationLog; Assert.Equal(expectedBlockCount, allocationLog.Count); - bufferHashes = allocationLog.Select(l => l.HashCodeOfBuffer).ToHashSet(); + bufferHashes = [.. allocationLog.Select(l => l.HashCodeOfBuffer)]; Assert.Equal(expectedBlockCount, bufferHashes.Count); Assert.Equal(0, this.MemoryAllocator.ReturnLog.Count); diff --git a/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.cs b/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.cs index b82b20120..3cea414bf 100644 --- a/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.cs +++ b/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.cs @@ -29,9 +29,9 @@ public partial class MemoryGroupTests : MemoryGroupTestsBase [Fact] public void Wrap() { - int[] data0 = { 1, 2, 3, 4 }; - int[] data1 = { 5, 6, 7, 8 }; - int[] data2 = { 9, 10 }; + int[] data0 = [1, 2, 3, 4]; + int[] data1 = [5, 6, 7, 8]; + int[] data2 = [9, 10]; using TestMemoryManager mgr0 = new(data0); using TestMemoryManager mgr1 = new(data1); @@ -46,7 +46,7 @@ public partial class MemoryGroupTests : MemoryGroupTestsBase Assert.True(group[2].Span.SequenceEqual(data2)); int cnt = 0; - int[][] allData = { data0, data1, data2 }; + int[][] allData = [data0, data1, data2]; foreach (Memory memory in group) { Assert.True(memory.Span.SequenceEqual(allData[cnt])); @@ -106,7 +106,7 @@ public partial class MemoryGroupTests : MemoryGroupTestsBase using MemoryGroup group = this.CreateTestGroup(100, 10, true); group.Fill(42); - int[] expectedRow = Enumerable.Repeat(42, 10).ToArray(); + int[] expectedRow = [.. Enumerable.Repeat(42, 10)]; foreach (Memory memory in group) { Assert.True(memory.Span.SequenceEqual(expectedRow)); @@ -119,7 +119,7 @@ public partial class MemoryGroupTests : MemoryGroupTestsBase using MemoryGroup group = this.CreateTestGroup(100, 10, true); group.Fill(42); - int[] expectedRow = Enumerable.Repeat(42, 10).ToArray(); + int[] expectedRow = [.. Enumerable.Repeat(42, 10)]; IReadOnlyList> groupAsList = group; foreach (Memory memory in groupAsList) { @@ -133,7 +133,7 @@ public partial class MemoryGroupTests : MemoryGroupTestsBase using MemoryGroup group = this.CreateTestGroup(100, 10, true); group.Fill(42); - int[] expectedRow = Enumerable.Repeat(42, 10).ToArray(); + int[] expectedRow = [.. Enumerable.Repeat(42, 10)]; IEnumerable groupAsList = group; foreach (Memory memory in groupAsList) { diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifProfileTests.cs index c098ace09..a60b2f6da 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifProfileTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifProfileTests.cs @@ -374,7 +374,7 @@ public class ExifProfileTests Image image = new(100, 100); ExifProfile expectedProfile = CreateExifProfile(); - List expectedProfileTags = expectedProfile.Values.Select(x => x.Tag).ToList(); + List expectedProfileTags = [.. expectedProfile.Values.Select(x => x.Tag)]; expectedProfile.SetValue(tag, junk.ToString()); image.Metadata.ExifProfile = expectedProfile; @@ -470,9 +470,9 @@ public class ExifProfileTests public void ProfileToByteArray() { // Arrange - byte[] exifBytesWithoutExifCode = ExifConstants.LittleEndianByteOrderMarker.ToArray(); + byte[] exifBytesWithoutExifCode = [.. ExifConstants.LittleEndianByteOrderMarker]; ExifProfile expectedProfile = CreateExifProfile(); - List expectedProfileTags = expectedProfile.Values.Select(x => x.Tag).ToList(); + List expectedProfileTags = [.. expectedProfile.Values.Select(x => x.Tag)]; // Act byte[] actualBytes = expectedProfile.ToByteArray(); diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifReaderTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifReaderTests.cs index 983ff4493..bcd884ffa 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifReaderTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifReaderTests.cs @@ -11,7 +11,7 @@ public class ExifReaderTests [Fact] public void Read_DataIsEmpty_ReturnsEmptyCollection() { - ExifReader reader = new(Array.Empty()); + ExifReader reader = new([]); IList result = reader.ReadValues(); @@ -21,7 +21,7 @@ public class ExifReaderTests [Fact] public void Read_DataIsMinimal_ReturnsEmptyCollection() { - ExifReader reader = new(new byte[] { 69, 120, 105, 102, 0, 0 }); + ExifReader reader = new([69, 120, 105, 102, 0, 0]); IList result = reader.ReadValues(); diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/Exif/Values/ExifValuesTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/Exif/Values/ExifValuesTests.cs index d7d6741ba..4d733a8eb 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/Exif/Values/ExifValuesTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/Exif/Values/ExifValuesTests.cs @@ -458,7 +458,7 @@ public class ExifValuesTests [MemberData(nameof(NumberArrayTags))] public void ExifNumberArrayTests(ExifTag tag) { - Number[] expected = [new Number(uint.MaxValue)]; + Number[] expected = [new(uint.MaxValue)]; ExifValue value = ExifValues.Create(tag); Assert.False(value.TrySetValue(expected.ToString())); @@ -496,7 +496,7 @@ public class ExifValuesTests [MemberData(nameof(RationalArrayTags))] public void ExifRationalArrayTests(ExifTag tag) { - Rational[] expected = [new Rational(21, 42)]; + Rational[] expected = [new(21, 42)]; ExifValue value = ExifValues.Create(tag); Assert.False(value.TrySetValue(expected.ToString())); @@ -554,7 +554,7 @@ public class ExifValuesTests [MemberData(nameof(SignedRationalArrayTags))] public void ExifSignedRationalArrayTests(ExifTag tag) { - SignedRational[] expected = [new SignedRational(21, 42)]; + SignedRational[] expected = [new(21, 42)]; ExifValue value = ExifValues.Create(tag); Assert.False(value.TrySetValue(expected.ToString())); diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterPrimitivesTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterPrimitivesTests.cs index c8f46d3aa..534134147 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterPrimitivesTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterPrimitivesTests.cs @@ -42,7 +42,7 @@ public class IccDataWriterPrimitivesTests byte[] output = writer.GetData(); Assert.Equal(0, count); - Assert.Equal(Array.Empty(), output); + Assert.Empty(output); } [Fact] @@ -62,7 +62,7 @@ public class IccDataWriterPrimitivesTests byte[] output = writer.GetData(); Assert.Equal(0, count); - Assert.Equal(Array.Empty(), output); + Assert.Empty(output); } [Theory] diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs index 2dbe5d343..37f99517c 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs @@ -116,7 +116,7 @@ public class IptcProfileTests using (Image image = provider.GetImage(JpegDecoder.Instance)) { Assert.NotNull(image.Metadata.IptcProfile); - List iptcValues = image.Metadata.IptcProfile.Values.ToList(); + List iptcValues = [.. image.Metadata.IptcProfile.Values]; IptcProfileContainsExpectedValues(iptcValues); } } @@ -130,7 +130,7 @@ public class IptcProfileTests { IptcProfile iptc = image.Frames.RootFrame.Metadata.IptcProfile; Assert.NotNull(iptc); - List iptcValues = iptc.Values.ToList(); + List iptcValues = [.. iptc.Values]; IptcProfileContainsExpectedValues(iptcValues); } } @@ -182,7 +182,7 @@ public class IptcProfileTests IptcProfile profileFromBytes = new(profileBytes); // assert - List iptcValues = profileFromBytes.Values.ToList(); + List iptcValues = [.. profileFromBytes.Values]; ContainsIptcValue(iptcValues, IptcTag.CaptionWriter, expectedCaptionWriter); ContainsIptcValue(iptcValues, IptcTag.Caption, expectedCaption); } @@ -203,10 +203,10 @@ public class IptcProfileTests // assert Assert.Equal(2, clone.Values.Count()); - List cloneValues = clone.Values.ToList(); + List cloneValues = [.. clone.Values]; ContainsIptcValue(cloneValues, IptcTag.CaptionWriter, captionWriter); ContainsIptcValue(cloneValues, IptcTag.Caption, "changed"); - ContainsIptcValue(profile.Values.ToList(), IptcTag.Caption, caption); + ContainsIptcValue([.. profile.Values], IptcTag.Caption, caption); } [Fact] @@ -240,7 +240,7 @@ public class IptcProfileTests // assert IptcProfile actual = reloadedImage.Metadata.IptcProfile; Assert.NotNull(actual); - List iptcValues = actual.Values.ToList(); + List iptcValues = [.. actual.Values]; ContainsIptcValue(iptcValues, IptcTag.CaptionWriter, expectedCaptionWriter); ContainsIptcValue(iptcValues, IptcTag.Caption, expectedCaption); } @@ -272,7 +272,7 @@ public class IptcProfileTests profile.SetValue(tag, expectedValue2, false); // assert - List values = profile.Values.ToList(); + List values = [.. profile.Values]; Assert.Equal(2, values.Count); ContainsIptcValue(values, tag, expectedValue1); ContainsIptcValue(values, tag, expectedValue2); @@ -323,7 +323,7 @@ public class IptcProfileTests profile.SetValue(tag, expectedValue, false); // assert - List values = profile.Values.ToList(); + List values = [.. profile.Values]; Assert.Equal(1, values.Count); ContainsIptcValue(values, tag, expectedValue); } @@ -357,7 +357,7 @@ public class IptcProfileTests // assert Assert.True(result, "removed result should be true"); - ContainsIptcValue(profile.Values.ToList(), IptcTag.Byline, "test"); + ContainsIptcValue([.. profile.Values], IptcTag.Byline, "test"); } [Fact] diff --git a/tests/ImageSharp.Tests/PixelFormats/AssociatedAlphaPixelTests.cs b/tests/ImageSharp.Tests/PixelFormats/AssociatedAlphaPixelTests.cs index c115850fc..b3e5b434b 100644 --- a/tests/ImageSharp.Tests/PixelFormats/AssociatedAlphaPixelTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/AssociatedAlphaPixelTests.cs @@ -685,8 +685,8 @@ public class AssociatedAlphaPackedPixelConversionTests foreach (int length in lengths) { - Vector4[] nativeSource = source.AsSpan(0, length).ToArray(); - Vector4[] scaledSource = source.AsSpan(0, length).ToArray(); + Vector4[] nativeSource = [.. source.AsSpan(0, length)]; + Vector4[] scaledSource = [.. source.AsSpan(0, length)]; TPixel[] expectedNative = new TPixel[length]; TPixel[] expectedScaled = new TPixel[length]; TPixel[] actualNative = new TPixel[length]; diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs index 7562d8ff6..69bc96ece 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs @@ -1051,9 +1051,9 @@ public class PixelBlenderTests private static Rgba32P BlendWithCoverageScalar(PixelBlender blender, Rgba32P background, Rgba32P source, float amount, float coverage) { Span destination = stackalloc Rgba32P[1]; - Span backgroundSpan = stackalloc Rgba32P[1] { background }; - Span sourceSpan = stackalloc Rgba32P[1] { source }; - Span coverageSpan = stackalloc float[1] { coverage }; + Span backgroundSpan = [background]; + Span sourceSpan = [source]; + Span coverageSpan = [coverage]; Span buffer = stackalloc Vector4[3]; // A one-pixel span takes the scalar remainder path, providing an exact oracle for each SIMD coverage result. @@ -1161,9 +1161,9 @@ public class PixelBlenderTests where TPixel : unmanaged, IPixel { Span destination = stackalloc TPixel[1]; - Span backgroundSpan = stackalloc TPixel[1] { background }; - Span sourceSpan = stackalloc TPixel[1] { source }; - Span coverageSpan = stackalloc float[1] { coverage }; + Span backgroundSpan = [background]; + Span sourceSpan = [source]; + Span coverageSpan = [coverage]; Span buffer = stackalloc Vector4[3]; blender.BlendWithCoverage(Configuration.Default, destination, backgroundSpan, sourceSpan, amount, coverageSpan, buffer); diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTestsTPixel.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTestsTPixel.cs index a2d571ad3..00b86b743 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTestsTPixel.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTestsTPixel.cs @@ -14,7 +14,7 @@ public class PorterDuffFunctionsTestsTPixel private static Span AsSpan(T value) where T : struct { - return new Span(new[] { value }); + return new Span([value]); } private static T[] CreateFilledArray(T value) diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index c569919f5..ee6762e48 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -736,7 +736,7 @@ public abstract class PixelOperationsTests : MeasureFixture public void FromL8(int count) { byte[] sourceBytes = CreateByteTestData(count); - L8[] source = sourceBytes.Select(b => new L8(b)).ToArray(); + L8[] source = [.. sourceBytes.Select(b => new L8(b))]; TPixel[] expected = new TPixel[count]; for (int i = 0; i < count; i++) @@ -772,7 +772,7 @@ public abstract class PixelOperationsTests : MeasureFixture [MemberData(nameof(ArraySizesData))] public void FromL16(int count) { - L16[] source = CreateVector4TestData(count).Select(L16.FromVector4).ToArray(); + L16[] source = [.. CreateVector4TestData(count).Select(L16.FromVector4)]; TPixel[] expected = new TPixel[count]; diff --git a/tests/ImageSharp.Tests/Processing/Convolution/KernelSamplingMapTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/KernelSamplingMapTest.cs index eb1d3031a..d5dbb1b11 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/KernelSamplingMapTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/KernelSamplingMapTest.cs @@ -411,9 +411,9 @@ public class KernelSamplingMapTest map.BuildSamplingOffsetMap(kernelSize.Height, kernelSize.Width, bounds, xBorderMode, yBorderMode); // Assert - int[] xOffsets = map.GetColumnOffsetSpan().ToArray(); + int[] xOffsets = [.. map.GetColumnOffsetSpan()]; Assert.Equal(xExpected, xOffsets); - int[] yOffsets = map.GetRowOffsetSpan().ToArray(); + int[] yOffsets = [.. map.GetRowOffsetSpan()]; Assert.Equal(yExpected, yOffsets); } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs index 3d4c239c9..ea38c96a0 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs @@ -47,18 +47,20 @@ public class BokehBlurTest public void VerifyComplexComponents() { // Get the saved components - List components = new(); + List components = []; foreach (Match match in Regex.Matches(Components10x2, @"\[\[(.*?)\]\]", RegexOptions.Singleline)) { string[] values = match.Groups[1].Value.Trim().Split([' '], StringSplitOptions.RemoveEmptyEntries); - Complex64[] component = values.Select( - value => - { - Match pair = Regex.Match(value, @"([+-]?\d+\.\d+)([+-]?\d+\.\d+)j"); - return new Complex64( - float.Parse(pair.Groups[1].Value, CultureInfo.InvariantCulture), - float.Parse(pair.Groups[2].Value, CultureInfo.InvariantCulture)); - }).ToArray(); + Complex64[] component = + [ + .. values.Select(value => + { + Match pair = Regex.Match(value, @"([+-]?\d+\.\d+)([+-]?\d+\.\d+)j"); + return new Complex64( + float.Parse(pair.Groups[1].Value, CultureInfo.InvariantCulture), + float.Parse(pair.Groups[2].Value, CultureInfo.InvariantCulture)); + }) + ]; components.Add(component); } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs index 07e9a4b0d..9c1985840 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs @@ -82,8 +82,8 @@ public class PaletteQuantizerTests { Rgba32[] palette = [ - new Rgba32(0, 0, 0), - new Rgba32(7, 0, 0) + new(0, 0, 0), + new(7, 0, 0) ]; using PixelMap exact = CreatePixelMap(palette); @@ -152,7 +152,7 @@ public class PaletteQuantizerTests byte r = (byte)((i & 31) << 3); byte g = (byte)(((i >> 5) & 31) << 3); byte b = (byte)(((i >> 10) & 31) << 3); - return new(r, g, b); + return new Rgba32(r, g, b); } // Reconstruct the same 5-bit RGB bucket coordinates used by CreateEvictionFillerColor, then set the @@ -163,7 +163,7 @@ public class PaletteQuantizerTests byte r = (byte)(((i & 31) << 3) | 0x07); byte g = (byte)((((i >> 5) & 31) << 3) | 0x07); byte b = (byte)((((i >> 10) & 31) << 3) | 0x07); - return new(r, g, b); + return new Rgba32(r, g, b); } private static PixelMap CreatePixelMap(Rgba32[] palette) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs index 56e9a5201..838760144 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs @@ -35,7 +35,7 @@ public class CropTest { using Image image = provider.GetImage(); - image.Metadata.ExifProfile = new(); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectLocation, [5, 15]); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectArea, [5, 15, 50, 50]); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs index 9aa04e370..abb4443b9 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs @@ -50,7 +50,7 @@ public class FlipTests { using Image image = provider.GetImage(); - image.Metadata.ExifProfile = new(); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectLocation, [5, 15]); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectArea, [5, 15, 50, 50]); @@ -79,7 +79,7 @@ public class FlipTests { using Image image = provider.GetImage(); - image.Metadata.ExifProfile = new(); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectLocation, [5, 15]); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectArea, [5, 15, 50, 50]); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ProjectiveTransformTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ProjectiveTransformTests.cs index c65f136d6..2c2932667 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ProjectiveTransformTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ProjectiveTransformTests.cs @@ -239,7 +239,7 @@ public class ProjectiveTransformTests { using Image image = provider.GetImage(); - image.Metadata.ExifProfile = new(); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectLocation, [5, 15]); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectArea, [5, 15, 50, 50]); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.ReferenceKernelMap.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.ReferenceKernelMap.cs index e38bf64c1..ccc6bf29e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.ReferenceKernelMap.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.ReferenceKernelMap.cs @@ -97,6 +97,6 @@ public partial class ResizeKernelMapTests public int Length => this.Values.Length; public static implicit operator ReferenceKernel(ResizeKernel orig) - => new(orig.StartIndex, orig.Values.ToArray()); + => new(orig.StartIndex, [.. orig.Values]); } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs index 5f9a8055f..8e4f7e727 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs @@ -119,7 +119,7 @@ public partial class ResizeKernelMapTests this.Output.WriteLine($"Actual KernelMap:\n{PrintKernelMap(kernelMap)}\n"); #endif - ApproximateFloatComparer comparer = new ApproximateFloatComparer(1e-6f); + ApproximateFloatComparer comparer = new(1e-6f); for (int i = 0; i < kernelMap.DestinationLength; i++) { ResizeKernel kernel = kernelMap.GetKernel((uint)i); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index 4214cc5e0..e1a254246 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -720,7 +720,7 @@ public class ResizeTests { using Image image = provider.GetImage(); - image.Metadata.ExifProfile = new(); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectLocation, [5, 15]); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectArea, [5, 15, 20, 20]); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs index 5eee7313d..191f39cb2 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs @@ -48,7 +48,7 @@ public class RotateTests { using Image image = provider.GetImage(); - image.Metadata.ExifProfile = new(); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectLocation, [5, 15]); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectArea, [5, 15, 50, 50]); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs index 33e22d364..6b69d20b1 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs @@ -60,7 +60,7 @@ public class SwizzleTests { using Image image = provider.GetImage(); - image.Metadata.ExifProfile = new(); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectLocation, [5, 15]); image.Metadata.ExifProfile.SetValue(ExifTag.SubjectArea, [5, 15, 20, 20]); diff --git a/tests/ImageSharp.Tests/Quantization/AlphaAssociationQuantizerTests.cs b/tests/ImageSharp.Tests/Quantization/AlphaAssociationQuantizerTests.cs index ddad67b94..d93f92e70 100644 --- a/tests/ImageSharp.Tests/Quantization/AlphaAssociationQuantizerTests.cs +++ b/tests/ImageSharp.Tests/Quantization/AlphaAssociationQuantizerTests.cs @@ -68,8 +68,8 @@ public class AlphaAssociationQuantizerTests { Rgba32[] source = [ - new Rgba32(255, 255, 255, below), - new Rgba32(255, 255, 255, retained) + new(255, 255, 255, below), + new(255, 255, 255, retained) ]; QuantizerOptions options = new() diff --git a/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataMultiProcessElement.cs b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataMultiProcessElement.cs index f79666e3e..5c077d5c3 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataMultiProcessElement.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataMultiProcessElement.cs @@ -13,11 +13,10 @@ public class IccConversionDataMultiProcessElement { 2, 4, 6 }, { 3, 5, 7 }, }, - new float[] { 3, 4, 5 }); + [3, 4, 5]); private static readonly IccClut Clut = new( - new[] - { + [ 0.2f, 0.3f, 0.4f, 0.2f, @@ -28,9 +27,9 @@ public class IccConversionDataMultiProcessElement 0.42f, 0.52f, 0.23f, 0.33f, - 0.43f, 0.53f, - }, - new byte[] { 2, 2, 2 }, + 0.43f, 0.53f + ], + [2, 2, 2], IccClutDataType.Float, outputChannelCount: 2); @@ -42,39 +41,39 @@ public class IccConversionDataMultiProcessElement private static readonly IccCurveSetProcessElement CurveSet1DFormula2 = Create1DSingleCurveSet(FormulaCurveElement2); private static readonly IccCurveSetProcessElement CurveSet1DFormula3 = Create1DSingleCurveSet(FormulaCurveElement3); - private static readonly IccCurveSetProcessElement CurveSet1DFormula1And2 = Create1DMultiCurveSet(new[] { 0.5f }, FormulaCurveElement1, FormulaCurveElement2); + private static readonly IccCurveSetProcessElement CurveSet1DFormula1And2 = Create1DMultiCurveSet([0.5f], FormulaCurveElement1, FormulaCurveElement2); private static readonly IccClutProcessElement ClutElement = new(Clut); private static IccCurveSetProcessElement Create1DSingleCurveSet(IccCurveSegment segment) { - IccOneDimensionalCurve curve = new(new float[0], new[] { segment }); - return new IccCurveSetProcessElement(new[] { curve }); + IccOneDimensionalCurve curve = new([], [segment]); + return new IccCurveSetProcessElement([curve]); } private static IccCurveSetProcessElement Create1DMultiCurveSet(float[] breakPoints, params IccCurveSegment[] segments) { IccOneDimensionalCurve curve = new(breakPoints, segments); - return new IccCurveSetProcessElement(new[] { curve }); + return new IccCurveSetProcessElement([curve]); } public static object[][] MpeCurveConversionTestData = - { - new object[] { CurveSet1DFormula1, new[] { 0.51f }, new[] { 0.575982451f } }, - new object[] { CurveSet1DFormula2, new[] { 0.52f }, new[] { -0.4684991f } }, - new object[] { CurveSet1DFormula3, new[] { 0.53f }, new[] { 0.86126f } }, + [ + [CurveSet1DFormula1, new[] { 0.51f }, new[] { 0.575982451f }], + [CurveSet1DFormula2, new[] { 0.52f }, new[] { -0.4684991f }], + [CurveSet1DFormula3, new[] { 0.53f }, new[] { 0.86126f }], - new object[] { CurveSet1DFormula1And2, new[] { 0.31f }, new[] { 0.445982f } }, - new object[] { CurveSet1DFormula1And2, new[] { 0.61f }, new[] { -0.341274023f } }, - }; + [CurveSet1DFormula1And2, new[] { 0.31f }, new[] { 0.445982f }], + [CurveSet1DFormula1And2, new[] { 0.61f }, new[] { -0.341274023f }] + ]; public static object[][] MpeMatrixConversionTestData = - { - new object[] { Matrix, new float[] { 2, 4 }, new float[] { 19, 32, 45 } } - }; + [ + [Matrix, new float[] { 2, 4 }, new float[] { 19, 32, 45 }] + ]; public static object[][] MpeClutConversionTestData = - { - new object[] { ClutElement, new[] { 0.5f, 0.5f, 0.5f }, new[] { 0.5f, 0.5f } } - }; + [ + [ClutElement, new[] { 0.5f, 0.5f, 0.5f }, new[] { 0.5f, 0.5f }] + ]; } diff --git a/tests/ImageSharp.Tests/TestFontUtilities.cs b/tests/ImageSharp.Tests/TestFontUtilities.cs index a2c203267..d165ccf31 100644 --- a/tests/ImageSharp.Tests/TestFontUtilities.cs +++ b/tests/ImageSharp.Tests/TestFontUtilities.cs @@ -45,10 +45,10 @@ public static class TestFontUtilities "../../../../TestFonts/" ]; - directories = directories.SelectMany(x => new[] - { - Path.GetFullPath(x) - }).ToList(); + directories = + [ + .. directories.SelectMany(x => new[] { Path.GetFullPath(x) }) + ]; AddFormatsDirectoryFromTestAssemblyPath(directories); diff --git a/tests/ImageSharp.Tests/TestFormat.cs b/tests/ImageSharp.Tests/TestFormat.cs index a3de7b3fe..b178639f0 100644 --- a/tests/ImageSharp.Tests/TestFormat.cs +++ b/tests/ImageSharp.Tests/TestFormat.cs @@ -61,7 +61,7 @@ public class TestFormat : IImageFormatConfigurationModule, IImageFormat public void VerifySpecificDecodeCall(byte[] marker, Configuration config) where TPixel : unmanaged, IPixel { - DecodeOperation[] discovered = this.DecodeCalls.Where(x => x.IsMatch(marker, config, typeof(TPixel))).ToArray(); + DecodeOperation[] discovered = [.. this.DecodeCalls.Where(x => x.IsMatch(marker, config, typeof(TPixel)))]; Assert.True(discovered.Length > 0, "No calls to decode on this format with the provided options happened"); @@ -73,7 +73,8 @@ public class TestFormat : IImageFormatConfigurationModule, IImageFormat public void VerifyAgnosticDecodeCall(byte[] marker, Configuration config) { - DecodeOperation[] discovered = this.DecodeCalls.Where(x => x.IsMatch(marker, config, typeof(TestPixelForAgnosticDecode))).ToArray(); + DecodeOperation[] discovered = + [.. this.DecodeCalls.Where(x => x.IsMatch(marker, config, typeof(TestPixelForAgnosticDecode)))]; Assert.True(discovered.Length > 0, "No calls to decode on this format with the provided options happened"); @@ -219,7 +220,7 @@ public class TestFormat : IImageFormatConfigurationModule, IImageFormat Configuration configuration = options.GeneralOptions.Configuration; using MemoryStream ms = new(); stream.CopyTo(ms, configuration.StreamProcessingBufferSize); - byte[] marker = ms.ToArray().Skip(this.testFormat.header.Length).ToArray(); + byte[] marker = [.. ms.ToArray().Skip(this.testFormat.header.Length)]; this.testFormat.DecodeCalls.Add(new DecodeOperation { Marker = marker, diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index c0071e906..b7ef0d43f 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -409,7 +409,7 @@ public static class TestImages } } - public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray(); + public static readonly string[] All = [.. Baseline.All, .. Progressive.All]; public static class BenchmarkSuite { diff --git a/tests/ImageSharp.Tests/TestUtilities/ByteBuffer.cs b/tests/ImageSharp.Tests/TestUtilities/ByteBuffer.cs index 548354450..07d8db532 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ByteBuffer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ByteBuffer.cs @@ -8,7 +8,7 @@ using System.Collections.Generic; public class ByteBuffer { - private readonly List bytes = new(); + private readonly List bytes = []; private readonly bool isLittleEndian; public ByteBuffer(bool isLittleEndian) @@ -33,6 +33,6 @@ public class ByteBuffer public byte[] ToArray() { - return this.bytes.ToArray(); + return [.. this.bytes]; } } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDifferenceIsOverThresholdException.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDifferenceIsOverThresholdException.cs index 8d6a1ffc7..95f983834 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDifferenceIsOverThresholdException.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDifferenceIsOverThresholdException.cs @@ -12,7 +12,7 @@ public class ImageDifferenceIsOverThresholdException : ImagesSimilarityException public ImageDifferenceIsOverThresholdException(IEnumerable reports) : base("Image difference is over threshold!" + StringifyReports(reports)) - => this.Reports = reports.ToArray(); + => this.Reports = [.. reports]; private static string StringifyReports(IEnumerable reports) { diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs index 1594258e0..6553dc510 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs @@ -19,7 +19,7 @@ public class ImageSimilarityReport this.ExpectedImage = expectedImage; this.ActualImage = actualImage; this.TotalNormalizedDifference = totalNormalizedDifference; - this.Differences = differences.ToArray(); + this.Differences = [.. differences]; } public int Index { get; } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs index c7883fac1..376ff00fc 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs @@ -217,12 +217,15 @@ public class ImagingTestCaseUtility { encoder ??= TestEnvironment.GetReferenceEncoder($"foo.{extension}"); - (int Index, string FileName)[] files = this.GetTestOutputFileNamesMultiFrame( - image.Frames.Count, - extension, - testOutputDetails, - appendPixelTypeToFileName, - predicate: predicate).ToArray(); + (int Index, string FileName)[] files = + [ + .. this.GetTestOutputFileNamesMultiFrame( + image.Frames.Count, + extension, + testOutputDetails, + appendPixelTypeToFileName, + predicate: predicate) + ]; foreach ((int Index, string FileName) file in files) { @@ -249,8 +252,12 @@ public class ImagingTestCaseUtility object testOutputDetails, bool appendPixelTypeToFileName = true, Func predicate = null) - => this.GetTestOutputFileNamesMultiFrame(frameCount, extension, testOutputDetails, appendPixelTypeToFileName, predicate: predicate) - .Select(x => (x.Index, TestEnvironment.GetReferenceOutputFileName(x.FileName))).ToArray(); + => + [ + .. this.GetTestOutputFileNamesMultiFrame(frameCount, extension, testOutputDetails, + appendPixelTypeToFileName, predicate: predicate) + .Select(x => (x.Index, TestEnvironment.GetReferenceOutputFileName(x.FileName))) + ]; internal void Init(string typeName, string methodName, string outputSubfolderName) { diff --git a/tests/ImageSharp.Tests/TestUtilities/ScaledRgbaVectorP.cs b/tests/ImageSharp.Tests/TestUtilities/ScaledRgbaVectorP.cs index aed4ef243..afe320931 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ScaledRgbaVectorP.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ScaledRgbaVectorP.cs @@ -84,7 +84,7 @@ internal struct ScaledRgbaVectorP : IPixel Numerics.UnPremultiply(ref source); source = Numerics.Clamp(source, Vector4.Zero, Vector4.One); Numerics.Premultiply(ref source); - return new(source); + return new ScaledRgbaVectorP(source); } /// diff --git a/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs b/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs index f9a4c0a6a..667224912 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs @@ -33,8 +33,8 @@ internal class TestMemoryAllocator : MemoryAllocator public void EnableNonThreadSafeLogging() { - this.allocationLog = new List(); - this.returnLog = new List(); + this.allocationLog = []; + this.returnLog = []; } protected override AllocationTrackedMemoryManager AllocateCore(int length, AllocationOptions options = AllocationOptions.None) diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs index 2e2416952..910738327 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs @@ -25,9 +25,11 @@ public static class TestUtils private static readonly Dictionary PixelTypes2ClrTypes = new(); - private static readonly PixelTypes[] AllConcretePixelTypes = GetAllPixelTypes() - .Except([PixelTypes.Undefined, PixelTypes.All]) - .ToArray(); + private static readonly PixelTypes[] AllConcretePixelTypes = + [ + .. GetAllPixelTypes() + .Except([PixelTypes.Undefined, PixelTypes.All]) + ]; static TestUtils() { @@ -401,9 +403,11 @@ public static class TestUtils public static string[] GetAllResamplerNames(bool includeNearestNeighbour = true) { - return typeof(KnownResamplers).GetProperties(BindingFlags.Public | BindingFlags.Static) - .Select(p => p.Name) - .Where(name => includeNearestNeighbour || name != nameof(KnownResamplers.NearestNeighbor)) - .ToArray(); + return + [ + .. typeof(KnownResamplers).GetProperties(BindingFlags.Public | BindingFlags.Static) + .Select(p => p.Name) + .Where(name => includeNearestNeighbour || name != nameof(KnownResamplers.NearestNeighbor)) + ]; } } diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/FeatureTestRunnerTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/FeatureTestRunnerTests.cs index ee3d02670..6dfa5aa40 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/FeatureTestRunnerTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/FeatureTestRunnerTests.cs @@ -24,7 +24,7 @@ public class FeatureTestRunnerTests public void ToFeatureCollectionReturnsExpectedResult(HwIntrinsics expectedIntrinsics, string[] expectedValues) { Dictionary features = expectedIntrinsics.ToFeatureKeyValueCollection(); - HwIntrinsics[] keys = features.Keys.ToArray(); + HwIntrinsics[] keys = [.. features.Keys]; HwIntrinsics actualIntrinsics = keys[0]; for (int i = 1; i < keys.Length; i++) diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index 714dbd223..755cefd7b 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -119,7 +119,7 @@ public class TestUtilityExtensionsTests [Fact] public void ToTypes_All() { - KeyValuePair[] expanded = PixelTypes.All.ExpandAllTypes().ToArray(); + KeyValuePair[] expanded = [.. PixelTypes.All.ExpandAllTypes()]; Assert.True(expanded.Length >= TestUtils.GetAllPixelTypes().Length - 2); AssertContainsPixelType(PixelTypes.Rgba32, expanded);