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 8d823c1e95..1016f829be 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 7f98c83754..86e2c14481 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.cs @@ -93,9 +93,11 @@ private static void DebugVerifySpanInput(ReadOnlySpan source, Span 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 cdfcf30164..292d357e43 100644 --- a/src/ImageSharp/Formats/Ani/AniDecoderCore.cs +++ b/src/ImageSharp/Formats/Ani/AniDecoderCore.cs @@ -66,7 +66,7 @@ protected override Image Decode(BufferedReadStream stream, Cance 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 @@ protected override ImageInfo Identify(BufferedReadStream stream, CancellationTok 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 50e4090e1b..5dec4a6748 100644 --- a/src/ImageSharp/Formats/Bmp/BmpFormat.cs +++ b/src/ImageSharp/Formats/Bmp/BmpFormat.cs @@ -30,5 +30,5 @@ private BmpFormat() 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 01248cc395..d5234bbae8 100644 --- a/src/ImageSharp/Formats/Exr/Compression/Compressors/ZipExrCompressor.cs +++ b/src/ImageSharp/Formats/Exr/Compression/Compressors/ZipExrCompressor.cs @@ -32,7 +32,7 @@ public ZipExrCompressor(Stream output, MemoryAllocator allocator, uint bytesPerB { 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 de1988674e..f619c086dc 100644 --- a/src/ImageSharp/Formats/Exr/ExrMetadata.cs +++ b/src/ImageSharp/Formats/Exr/ExrMetadata.cs @@ -102,7 +102,7 @@ public FormatConnectingMetadata ToFormatConnectingMetadata() ? EncodingType.Lossy : EncodingType.Lossless; - return new() + return new FormatConnectingMetadata { EncodingType = type, PixelTypeInfo = this.GetPixelTypeInfo() @@ -136,7 +136,7 @@ or PixelColorType.BGR | PixelColorType.Alpha } }; - 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 83a5710832..80bc373d22 100644 --- a/src/ImageSharp/Formats/Icon/IconDecoderCore.cs +++ b/src/ImageSharp/Formats/Icon/IconDecoderCore.cs @@ -69,7 +69,7 @@ protected override Image Decode(BufferedReadStream stream, Cance 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 @@ protected override ImageInfo Identify(BufferedReadStream stream, CancellationTok 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 23b517568d..3f36b8931f 100644 --- a/src/ImageSharp/Formats/ImageDecoderCore.cs +++ b/src/ImageSharp/Formats/ImageDecoderCore.cs @@ -279,7 +279,7 @@ protected bool TryConvertIccProfile(ImageFrame frame) // 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 ecf96855e5..733621036a 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 void SetDecoder(IImageFormat imageFormat, IImageDecoder decoder) /// /// 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 2b1271c82b..2c1b825e7e 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs @@ -119,49 +119,49 @@ private static JpegColorConverterBase[] CreateConverters() /// /// 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 ae26914e8e..6445911f81 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -1049,7 +1049,7 @@ private void ProcessApp13Marker(BufferedReadStream stream, int remaining) 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 98b6dd30a6..d86d5cad12 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.FrameConfig.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.FrameConfig.cs @@ -21,175 +21,159 @@ private static JpegFrameConfig[] CreateFrameConfigs() 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 0038b41344..1d6f280eff 100644 --- a/src/ImageSharp/Formats/Png/Chunks/FrameControl.cs +++ b/src/ImageSharp/Formats/Png/Chunks/FrameControl.cs @@ -153,7 +153,7 @@ public static FrameControl Parse(ReadOnlySpan data) 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 28f9a989b9..f99fca6804 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -291,10 +291,10 @@ protected override Image Decode(BufferedReadStream stream, Cance } 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 @@ protected override ImageInfo Identify(BufferedReadStream stream, CancellationTok 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 @@ private static bool TryExtractIptcFromPhotoshopIrb(ReadOnlySpan data, out if (resourceId == adobeIptcResourceId) { - iptcBytes = payload.ToArray(); + iptcBytes = [.. payload]; return true; } @@ -2119,7 +2119,7 @@ private void ReadInternationalTextChunk(ImageMetadata metadata, ReadOnlySpan 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 4ab9d7b94c..f5738c7d35 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/CostManager.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/CostManager.cs @@ -23,8 +23,8 @@ public CostManager(MemoryAllocator memoryAllocator, IMemoryOwner distArr { 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 58394c212f..fb9c1fd5ca 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 817641393e..008ca9e60c 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogramSet.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogramSet.cs @@ -51,7 +51,7 @@ public Vp8LHistogramSet(MemoryAllocator memoryAllocator, Vp8LBackwardRefs refs, 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 875149b1bb..880d8eeff2 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs @@ -438,7 +438,7 @@ private void ReadHuffmanCodes(Vp8LDecoder decoder, int xSize, int ySize, int col } // 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 6019a0bff7..2cf6376549 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 @@ public int WriteMultiLocalizedUnicodeTagDataEntry(IccMultiLocalizedUnicodeTagDat 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 084ec388d6..5e1c1942a2 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs @@ -102,7 +102,7 @@ private static IccTagDataEntry[] ReadTagData(IccDataReader reader) entries.Add(entry); } - return entries.ToArray(); + return [.. entries]; } private static IccTagTableEntry[] ReadTagTable(IccDataReader reader) @@ -132,6 +132,6 @@ private static IccTagTableEntry[] ReadTagTable(IccDataReader reader) } } - return table.ToArray(); + return [.. table]; } } diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs index 6bc0560f02..4a88a76f60 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs @@ -81,6 +81,6 @@ private static IccTagTableEntry[] WriteTagData(IccDataWriter writer, IccTagDataE } } - 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 7db26e5c58..5f94961409 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs @@ -102,7 +102,7 @@ public static explicit operator IccMultiLocalizedUnicodeTagDataEntry(IccTextDesc 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 5057a25bd8..1ba8b5dde9 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 8cc89620b0..44f9732fa6 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 1172aafb95..e70dc548c0 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4P.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4P.cs @@ -169,7 +169,7 @@ private static NormalizedByte4P PackAssociatedScaledVector4(Vector4 source) // 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 4b940a6a5f..08cc3afa1b 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs @@ -183,7 +183,7 @@ public static Rgb96 FromL8(L8 source) 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 static Rgb96 FromL16(L16 source) 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 static Rgb96 FromLa16(La16 source) 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 86fab4f61f..064b71af21 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs @@ -180,21 +180,21 @@ public static Rgba128 FromL8(L8 source) 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 61cde6e2a7..b4848c2d66 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 @@ public AffineTransformProcessor(Configuration configuration, AffineTransformProc { 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 c0380224c4..aa24878c66 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs @@ -73,10 +73,10 @@ public Span Values { 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 dbaf21a8ef..6e5c531f5f 100644 --- a/tests/ImageSharp.Benchmarks/Processing/ColorMatchingCaches.cs +++ b/tests/ImageSharp.Benchmarks/Processing/ColorMatchingCaches.cs @@ -146,7 +146,7 @@ private static Rgba32[] CreatePalette(int count) // 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 @@ private static Rgba32[] CreateRepeatedSeedColors(Rgba32[] palette) 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 @@ private static Rgba32[] CreateDitherLikeLookups() 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 cb349af96a..cfb4b8e726 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs @@ -189,7 +189,7 @@ private static List GetBulkActualTargetValues(List inputs, str { 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 @@ private static List GetBulkActualTargetValues(List inputs, str 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 8a38ea11fc..3896418e86 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/RgbWorkingSpaceTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/RgbWorkingSpaceTests.cs @@ -110,7 +110,7 @@ public void CompressAndExpand_RoundTripsWithTolerance(RgbWorkingSpace workingSpa 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 8421c1fd74..943c643c15 100644 --- a/tests/ImageSharp.Tests/Common/EncoderExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Common/EncoderExtensionsTests.cs @@ -20,7 +20,7 @@ public void GetString_EmptyBuffer_ReturnsEmptyString() [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 71335032c8..38a0a8d243 100644 --- a/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs +++ b/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs @@ -171,10 +171,10 @@ private static void TestImpl_BulkConvertByteToNormalizedFloat( 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 void BulkConvertNormalizedFloatToByteClampOverflows(int count) [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 void PackFromRgbPlanesAvx2Reduce_Rgb24() 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 void PackFromRgbPlanesAvx2Reduce_Rgba32() 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 @@ private static void TestImpl_BulkConvertNormalizedFloatToByteClampOverflows( { 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 5ea7afaf80..2cf62c10c5 100644 --- a/tests/ImageSharp.Tests/Common/StreamExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Common/StreamExtensionsTests.cs @@ -79,7 +79,7 @@ private class NonSeekableStream : MemoryStream { 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 b2f4dfe762..3437e800b9 100644 --- a/tests/ImageSharp.Tests/Common/TensorPrimitivesTests.cs +++ b/tests/ImageSharp.Tests/Common/TensorPrimitivesTests.cs @@ -251,7 +251,7 @@ public void AddScalarInt32MatchesScalarFormula(int length) public void NegateSingleMatchesScalarFormula(int length) { float[] values = - { + [ float.NaN, -0F, 0F, @@ -259,7 +259,7 @@ public void NegateSingleMatchesScalarFormula(int length) 1F, float.NegativeInfinity, float.PositiveInfinity - }; + ]; float[] source = new float[length]; float[] expected = new float[length]; @@ -287,7 +287,7 @@ public void NegateSingleMatchesScalarFormula(int length) public void NegateDoubleMatchesScalarFormula(int length) { double[] values = - { + [ double.NaN, -0D, 0D, @@ -295,7 +295,7 @@ public void NegateDoubleMatchesScalarFormula(int length) 1D, double.NegativeInfinity, double.PositiveInfinity - }; + ]; double[] source = new double[length]; double[] expected = new double[length]; @@ -349,7 +349,7 @@ public void ClampInt32MatchesScalarFormula(int length) public void ClampSingleMatchesRuntimeFormula(int length) { float[] values = - { + [ float.NaN, -0F, 0F, @@ -357,7 +357,7 @@ public void ClampSingleMatchesRuntimeFormula(int length) 1F, float.NegativeInfinity, float.PositiveInfinity - }; + ]; float[] source = new float[length]; float[] expected = new float[length]; @@ -381,13 +381,13 @@ public void ClampSingleMatchesRuntimeFormula(int length) 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 void ClampSinglePreservesRuntimeSpecialValueSemantics() 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 void DivideSingleMatchesScalarFormula(int length) public void MaxSingleMatchesRuntimeFormula(int length) { float[] values = - { + [ float.NaN, float.NegativeInfinity, -1F, @@ -473,7 +473,7 @@ public void MaxSingleMatchesRuntimeFormula(int length) 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 93de4d2d9f..8ad5a0a2d1 100644 --- a/tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs @@ -71,7 +71,7 @@ public void AniDecoder_Identify(string path, int expectedFrameCount) [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 void AniDecoder_InvalidSequenceReference_FollowsIntegrityHandling() [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 void AniDecoder_UnsupportedResource_FollowsIntegrityHandling() [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 void AniDecoder_InvalidRateChunk_FollowsIntegrityHandling() [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 void AniDecoder_OversizedControlChunk_FollowsIntegrityHandling(bool seque [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 2d59c02355..77aadae386 100644 --- a/tests/ImageSharp.Tests/Formats/Exr/ExrDecoderSecurityTests.cs +++ b/tests/ImageSharp.Tests/Formats/Exr/ExrDecoderSecurityTests.cs @@ -39,7 +39,7 @@ public void Decode_DataWindowOverflow_NegativeWidth_Throws() // 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 void Decode_CraftedRowOffsets_OutOfBounds_Throws() 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 void Decode_CraftedRowOffsets_IntoHeader_Throws() 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 void Decode_CraftedRowOffsets_IntoOffsetTable_Throws() // 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 void Decode_RgbaRowSizingExceedsBufferLimits_Throws() // 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 void Decode_DataWindowWidthExceedsRowBufferLimit_Throws() // 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 void Identify_RowOffsetTableExceedsStream_Throws() // 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 @@ private static byte[] BuildExrWithChannels( 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 bdbf67461f..46cd99aa35 100644 --- a/tests/ImageSharp.Tests/Formats/Icon/Ico/IcoDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Icon/Ico/IcoDecoderTests.cs @@ -320,7 +320,7 @@ public void MultiSize_CanIdentifySingleFrame(string imagePath) [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 void TruncatedEntry_FollowsImageDataIntegrityHandling() [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 37be0f8f56..6ea5288182 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegMetadataTests.cs @@ -71,7 +71,7 @@ public void Comment_EmptyComment() 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 1610df6eb4..89ca10c8a0 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 8884591128..370736c403 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs @@ -121,7 +121,7 @@ public static SpectralData ExtractSpectralData(string inputFile) { 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 7a31e35d0c..c9d84c3cab 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 void VerifyComponentSizes3( 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 eef8d5ba84..ed238e3fb4 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -287,7 +287,7 @@ public void WritesFileMarker(TestImageProvider provider) 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 42048426ee..574602704b 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs @@ -32,7 +32,7 @@ public void CloneIsDeep() 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 6aebf7b9c3..3bcf6c2c81 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs @@ -137,7 +137,7 @@ public void NotCoveredTags() }; // 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 void NotCoveredTags64bit() ////{ 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 990c583856..fa240c55b9 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/Vp8HistogramTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8HistogramTests.cs @@ -13,55 +13,59 @@ public static IEnumerable Data { 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 @@ private static void RunCollectHistogramTest() 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 @@ private static void RunCollectHistogramTest() 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 @@ private static void RunCollectHistogramTest() 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 35109d352f..0a498a0b74 100644 --- a/tests/ImageSharp.Tests/Helpers/NumericsTests.cs +++ b/tests/ImageSharp.Tests/Helpers/NumericsTests.cs @@ -178,11 +178,14 @@ public void PremultiplyVectorSpan(int length) }; } - 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 void UnPremultiplyVectorSpan(int length) }; } - 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 017926fc5d..3edf3689ad 100644 --- a/tests/ImageSharp.Tests/Helpers/ParallelRowIteratorTests.cs +++ b/tests/ImageSharp.Tests/Helpers/ParallelRowIteratorTests.cs @@ -101,7 +101,7 @@ public void IterateRows_OverMinimumPixelsLimit_ShouldVisitAllRows( 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 void IterateRowsWithTempBuffer_OverMinimumPixelsLimit_ShouldVisitAllRows( 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 417ee18fbe..391cff506a 100644 --- a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs +++ b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs @@ -181,7 +181,7 @@ public void Dispose_DisposesAllInnerFrames() 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 cd1213c230..de06a51a91 100644 --- a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs +++ b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs @@ -29,7 +29,7 @@ public void AddFrame_OfDifferentPixelType() } 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 void InsertFrame_OfDifferentPixelType() } 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 0656f9e0bc..af50cca696 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs @@ -26,7 +26,7 @@ public class Decode_Cancellation : ImageLoadTestBase //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 65eeb124f6..f86ce344f9 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs @@ -146,14 +146,14 @@ public void WrapMemory_MemoryOfT_Strided_CreatedImageIsCorrect() { 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 void WrapMemory_MemoryOfT_Strided_CopyPixelDataTo_UsesRowStrideLayout() { 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 72b90c2387..848cd1c1ab 100644 --- a/tests/ImageSharp.Tests/Memory/Allocators/SharedArrayPoolBufferTests.cs +++ b/tests/ImageSharp.Tests/Memory/Allocators/SharedArrayPoolBufferTests.cs @@ -23,7 +23,7 @@ static void RunTest() } 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 @@ static void RunTest() 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 ec79d91c3d..ab388386ae 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 void RentReturnRent_SameBuffers(int totalCount, int rentUnit, int capacit { 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 @@ static void RunTest(string multipleInner) 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 void RentReturn_IsThreadSafe() 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 3b33eae5e9..1fe33c3467 100644 --- a/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedBufferTests.cs +++ b/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedBufferTests.cs @@ -76,7 +76,7 @@ static void RunTest(string countStr) 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 59b793e012..8818597a94 100644 --- a/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedMemoryHandleTests.cs +++ b/tests/ImageSharp.Tests/Memory/Allocators/UnmanagedMemoryHandleTests.cs @@ -47,7 +47,7 @@ public void Create_Free_AllocationsAreTracked(int count) 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 cca2230e6f..04d2bedf44 100644 --- a/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.Allocate.cs +++ b/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.Allocate.cs @@ -206,7 +206,7 @@ public void MemoryAllocatorIsUtilizedCorrectly(AllocationOptions allocationOptio { 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 b82b20120a..3cea414bf1 100644 --- a/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.cs +++ b/tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.cs @@ -29,9 +29,9 @@ public void IsValid_FalseAfterDisposal() [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 void Wrap() 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 void FillWithFastEnumerator() 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 void FillWithSlowGenericEnumerator() 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 void FillWithSlowEnumerator() 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 c098ace09a..a60b2f6dad 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifProfileTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifProfileTests.cs @@ -374,7 +374,7 @@ public void ReadWriteLargeProfileJpg() 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 void WritingImagePreservesExifProfile(TestImageWriteFormat imageFormat) 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 983ff44937..bcd884ffa1 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 void Read_DataIsEmpty_ReturnsEmptyCollection() [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 d7d6741baf..4d733a8ebf 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 void ExifNumberTests(ExifTag tag) [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 void ExifRationalTests(ExifTag tag) [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 void ExifSignedRationalTests(ExifTag tag) [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 c8f46d3aa4..534134147b 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 void WriteAsciiStringWithNullWritesEmpty() byte[] output = writer.GetData(); Assert.Equal(0, count); - Assert.Equal(Array.Empty(), output); + Assert.Empty(output); } [Fact] @@ -62,7 +62,7 @@ public void WriteUnicodeStringWithNullWritesEmpty() 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 2dbe5d343d..37f99517c7 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs @@ -116,7 +116,7 @@ public void ReadIptcMetadata_FromJpg_Works(TestImageProvider pro 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 void ReadIptcMetadata_FromTiff_Works(TestImageProvider pr { 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 void IptcProfile_ToAndFromByteArray_Works() 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 void IptcProfile_CloneIsDeep() // 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 void WritingImage_PreservesIptcProfile() // 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 void IptcProfile_AddRepeatable_Works(IptcTag tag) 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 void IptcProfile_AddNoneRepeatable_DoesOverrideOldValue(IptcTag tag) 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 void IptcProfile_RemoveByTagAndValue_Works() // 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 c115850fc0..b3e5b434b7 100644 --- a/tests/ImageSharp.Tests/PixelFormats/AssociatedAlphaPixelTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/AssociatedAlphaPixelTests.cs @@ -685,8 +685,8 @@ private static void AssertScalarAndBulkFromAssociatedVectorsAreEqual() 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 7562d8ff6e..69bc96ecec 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs @@ -1051,9 +1051,9 @@ private static void AssertAssociatedBlenderMatchesScalar( 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 @@ private static TPixel BlendWithCoverageScalar(PixelBlender blend 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 a2d571ad3e..00b86b743b 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 c569919f5f..ee6762e489 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -736,7 +736,7 @@ public void ToBgra5551Bytes(int count) 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 void ToL8(int count) [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 eb1d3031a4..d5dbb1b110 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/KernelSamplingMapTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/KernelSamplingMapTest.cs @@ -411,9 +411,9 @@ private void AssertOffsets(Size kernelSize, Rectangle bounds, BorderWrappingMode 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 3d4c239c93..ea38c96a0e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs @@ -47,18 +47,20 @@ public void VerifyBokehBlurProcessorArguments_Fail(int radius, int components, f 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 07e9a4b0d6..9c1985840c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs @@ -82,8 +82,8 @@ public void ExactColorMatchingMatchesUncachedAfterCacheOverflow() { 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 @@ private static Rgba32 CreateEvictionFillerColor(int i) 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 @@ private static Rgba32 CreateEvictionProbeColor(int i) 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 56e9a5201b..8387601448 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs @@ -35,7 +35,7 @@ public void CropUpdatesSubject(TestImageProvider provider) { 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 9aa04e370a..abb4443b91 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs @@ -50,7 +50,7 @@ public void FlipVerticalUpdatesSubject(TestImageProvider provide { 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 void FlipHorizontalUpdatesSubject(TestImageProvider provi { 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 c65f136d66..2c29326672 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ProjectiveTransformTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ProjectiveTransformTests.cs @@ -239,7 +239,7 @@ public void TransformUpdatesSubject(TestImageProvider provider) { 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 e38bf64c1b..ccc6bf29ef 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 ReferenceKernel(int left, float[] values) 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 5f9a8055ff..8e4f7e7275 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs @@ -119,7 +119,7 @@ private void VerifyKernelMapContentIsCorrect(TResampler resampler, i 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 4214cc5e02..e1a254246f 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -720,7 +720,7 @@ public void ResizeUpdatesSubject(TestImageProvider provider) { 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 5eee7313d9..191f39cb28 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs @@ -48,7 +48,7 @@ public void RotateUpdatesSubject(TestImageProvider provider) { 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 33e22d3644..6b69d20b18 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs @@ -60,7 +60,7 @@ public void SwizzleUpdatesSubject(TestImageProvider provider) { 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 ddad67b949..d93f92e70e 100644 --- a/tests/ImageSharp.Tests/Quantization/AlphaAssociationQuantizerTests.cs +++ b/tests/ImageSharp.Tests/Quantization/AlphaAssociationQuantizerTests.cs @@ -68,8 +68,8 @@ public void WuQuantizerAppliesNormalizedTransparencyThresholdToAssociatedPixels( { 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 f79666e3e3..5c077d5c36 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 a2c2032672..d165ccf316 100644 --- a/tests/ImageSharp.Tests/TestFontUtilities.cs +++ b/tests/ImageSharp.Tests/TestFontUtilities.cs @@ -45,10 +45,10 @@ private static string GetFontsDirectory() "../../../../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 a3de7b3feb..b178639f09 100644 --- a/tests/ImageSharp.Tests/TestFormat.cs +++ b/tests/ImageSharp.Tests/TestFormat.cs @@ -61,7 +61,7 @@ public Stream CreateAsyncSemaphoreStream(SemaphoreSlim notifyWaitPositionReached 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 void VerifySpecificDecodeCall(byte[] marker, Configuration config 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 @@ protected override Image Decode(TestDecoderOptions options, Stre 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 c0071e9062..b7ef0d43f8 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -409,7 +409,7 @@ public static class Fuzz } } - 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 548354450c..07d8db5323 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ByteBuffer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ByteBuffer.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities; 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 void AddUInt32(uint value) 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 8d6a1ffc74..95f9838349 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 1594258e04..6553dc5103 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs @@ -19,7 +19,7 @@ protected 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 c7883fac15..376ff00fcc 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs @@ -217,12 +217,15 @@ public string SaveTestOutputFile( { 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 @@ internal string GetReferenceOutputFileName( 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 aed4ef243d..afe3209317 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ScaledRgbaVectorP.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ScaledRgbaVectorP.cs @@ -84,7 +84,7 @@ public static ScaledRgbaVectorP FromAssociatedScaledVector4(Vector4 source) 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 f9a4c0a6a8..6672249124 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs @@ -33,8 +33,8 @@ public TestMemoryAllocator(byte dirtyValue = 42) 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 2e2416952d..910738327a 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 IDither GetDither(string name) 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 ee3d02670e..6dfa5aa400 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 714dbd223d..755cefd7ba 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -119,7 +119,7 @@ public void ExpandAllTypes_2() [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);