Browse Source

Use Collection expressions and Target-typed new

1. Collection expressions (`[]` syntax) replacing `new List<T>()`, `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
pull/3167/head
Stefan Nikolei 2 weeks ago
parent
commit
eb549bcda3
  1. 2
      src/ImageSharp/ColorProfiles/Icc/Calculators/GrayTrcCalculator.cs
  2. 2
      src/ImageSharp/Common/Helpers/SimdUtils.cs
  3. 4
      src/ImageSharp/Formats/Ani/AniDecoderCore.cs
  4. 2
      src/ImageSharp/Formats/Bmp/BmpFormat.cs
  5. 2
      src/ImageSharp/Formats/Exr/Compression/Compressors/ZipExrCompressor.cs
  6. 4
      src/ImageSharp/Formats/Exr/ExrMetadata.cs
  7. 4
      src/ImageSharp/Formats/Icon/IconDecoderCore.cs
  8. 2
      src/ImageSharp/Formats/ImageDecoderCore.cs
  9. 6
      src/ImageSharp/Formats/ImageFormatManager.cs
  10. 14
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs
  11. 2
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  12. 182
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.FrameConfig.cs
  13. 2
      src/ImageSharp/Formats/Png/Chunks/FrameControl.cs
  14. 12
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  15. 2
      src/ImageSharp/Formats/Qoi/QoiDecoderCore.cs
  16. 2
      src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs
  17. 4
      src/ImageSharp/Formats/Webp/Lossless/CostManager.cs
  18. 2
      src/ImageSharp/Formats/Webp/Lossless/CrunchConfig.cs
  19. 2
      src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogramSet.cs
  20. 2
      src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs
  21. 2
      src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs
  22. 4
      src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs
  23. 2
      src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs
  24. 2
      src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs
  25. 2
      src/ImageSharp/PixelFormats/PixelBlenders/AssociatedAlphaPorterDuffFunctions.Generated.cs
  26. 24
      src/ImageSharp/PixelFormats/PixelBlenders/AssociatedAlphaPorterDuffFunctions.Generated.tt
  27. 2
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4P.cs
  28. 6
      src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs
  29. 6
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs
  30. 2
      src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs
  31. 4
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs
  32. 6
      tests/ImageSharp.Benchmarks/Processing/ColorMatchingCaches.cs
  33. 4
      tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs
  34. 2
      tests/ImageSharp.Tests/ColorProfiles/RgbWorkingSpaceTests.cs
  35. 2
      tests/ImageSharp.Tests/Common/EncoderExtensionsTests.cs
  36. 20
      tests/ImageSharp.Tests/Common/SimdUtilsTests.cs
  37. 2
      tests/ImageSharp.Tests/Common/StreamExtensionsTests.cs
  38. 24
      tests/ImageSharp.Tests/Common/TensorPrimitivesTests.cs
  39. 10
      tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs
  40. 18
      tests/ImageSharp.Tests/Formats/Exr/ExrDecoderSecurityTests.cs
  41. 4
      tests/ImageSharp.Tests/Formats/Icon/Ico/IcoDecoderTests.cs
  42. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegMetadataTests.cs
  43. 2
      tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs
  44. 2
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs
  45. 2
      tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs
  46. 2
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  47. 2
      tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs
  48. 4
      tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs
  49. 110
      tests/ImageSharp.Tests/Formats/WebP/Vp8HistogramTests.cs
  50. 26
      tests/ImageSharp.Tests/Helpers/NumericsTests.cs
  51. 4
      tests/ImageSharp.Tests/Helpers/ParallelRowIteratorTests.cs
  52. 2
      tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs
  53. 4
      tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs
  54. 2
      tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs
  55. 32
      tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs
  56. 4
      tests/ImageSharp.Tests/Memory/Allocators/SharedArrayPoolBufferTests.cs
  57. 12
      tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.cs
  58. 2
      tests/ImageSharp.Tests/Memory/Allocators/UnmanagedBufferTests.cs
  59. 2
      tests/ImageSharp.Tests/Memory/Allocators/UnmanagedMemoryHandleTests.cs
  60. 2
      tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.Allocate.cs
  61. 14
      tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.cs
  62. 6
      tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifProfileTests.cs
  63. 4
      tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifReaderTests.cs
  64. 6
      tests/ImageSharp.Tests/Metadata/Profiles/Exif/Values/ExifValuesTests.cs
  65. 4
      tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterPrimitivesTests.cs
  66. 18
      tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs
  67. 4
      tests/ImageSharp.Tests/PixelFormats/AssociatedAlphaPixelTests.cs
  68. 12
      tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs
  69. 2
      tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTestsTPixel.cs
  70. 4
      tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs
  71. 4
      tests/ImageSharp.Tests/Processing/Convolution/KernelSamplingMapTest.cs
  72. 20
      tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs
  73. 8
      tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs
  74. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs
  75. 4
      tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs
  76. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ProjectiveTransformTests.cs
  77. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.ReferenceKernelMap.cs
  78. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs
  79. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
  80. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs
  81. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs
  82. 4
      tests/ImageSharp.Tests/Quantization/AlphaAssociationQuantizerTests.cs
  83. 45
      tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataMultiProcessElement.cs
  84. 8
      tests/ImageSharp.Tests/TestFontUtilities.cs
  85. 7
      tests/ImageSharp.Tests/TestFormat.cs
  86. 2
      tests/ImageSharp.Tests/TestImages.cs
  87. 4
      tests/ImageSharp.Tests/TestUtilities/ByteBuffer.cs
  88. 2
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDifferenceIsOverThresholdException.cs
  89. 2
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs
  90. 23
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
  91. 2
      tests/ImageSharp.Tests/TestUtilities/ScaledRgbaVectorP.cs
  92. 4
      tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs
  93. 18
      tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
  94. 2
      tests/ImageSharp.Tests/TestUtilities/Tests/FeatureTestRunnerTests.cs
  95. 2
      tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

2
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);

2
src/ImageSharp/Common/Helpers/SimdUtils.cs

@ -93,9 +93,11 @@ internal static partial class SimdUtils
private struct ByteTuple4
{
#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value
public byte V0;
public byte V1;
public byte V2;
public byte V3;
#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value
}
}

4
src/ImageSharp/Formats/Ani/AniDecoderCore.cs

@ -66,7 +66,7 @@ internal sealed class AniDecoderCore : ImageDecoderCore, IDisposable
cancellationToken.ThrowIfCancellationRequested();
Image<TPixel> resource = DecodeFrame<TPixel>(format, frameOptions, frameStream, cancellationToken);
this.Dimensions = new(Math.Max(this.Dimensions.Width, resource.Width), Math.Max(this.Dimensions.Height, resource.Height));
this.Dimensions = new Size(Math.Max(this.Dimensions.Width, resource.Width), Math.Max(this.Dimensions.Height, resource.Height));
return resource;
});
@ -165,7 +165,7 @@ internal sealed class AniDecoderCore : ImageDecoderCore, IDisposable
cancellationToken.ThrowIfCancellationRequested();
ImageInfo info = IdentifyFrame(format, frameOptions, frameStream, cancellationToken);
this.Dimensions = new(Math.Max(this.Dimensions.Width, info.Width), Math.Max(this.Dimensions.Height, info.Height));
this.Dimensions = new Size(Math.Max(this.Dimensions.Width, info.Width), Math.Max(this.Dimensions.Height, info.Height));
return info;
});

2
src/ImageSharp/Formats/Bmp/BmpFormat.cs

@ -30,5 +30,5 @@ public sealed class BmpFormat : IImageFormat<BmpMetadata>
public IEnumerable<string> FileExtensions => BmpConstants.FileExtensions;
/// <inheritdoc/>
public BmpMetadata CreateDefaultFormatMetadata() => new BmpMetadata();
public BmpMetadata CreateDefaultFormatMetadata() => new();
}

2
src/ImageSharp/Formats/Exr/Compression/Compressors/ZipExrCompressor.cs

@ -32,7 +32,7 @@ internal class ZipExrCompressor : ExrBaseCompressor
{
this.compressionLevel = compressionLevel;
this.buffer = allocator.Allocate<byte>((int)bytesPerBlock);
this.memoryStream = new();
this.memoryStream = new MemoryStream();
}
/// <inheritdoc/>

4
src/ImageSharp/Formats/Exr/ExrMetadata.cs

@ -102,7 +102,7 @@ public class ExrMetadata : IFormatMetadata<ExrMetadata>
? EncodingType.Lossy
: EncodingType.Lossless;
return new()
return new FormatConnectingMetadata
{
EncodingType = type,
PixelTypeInfo = this.GetPixelTypeInfo()
@ -136,7 +136,7 @@ public class ExrMetadata : IFormatMetadata<ExrMetadata>
}
};
return new()
return new ExrMetadata
{
PixelType = bitsPerComponent <= 16 ? ExrPixelType.Half : ExrPixelType.Float,
ImageDataType = imageDataType,

4
src/ImageSharp/Formats/Icon/IconDecoderCore.cs

@ -69,7 +69,7 @@ internal abstract class IconDecoderCore : ImageDecoderCore
decodedEntries[decodedCount++] = (entryIndex, decoded, compression);
// The embedded header is authoritative because a zero directory dimension can represent 256 pixels or a larger Vista-era PNG.
this.Dimensions = new(Math.Max(this.Dimensions.Width, decoded.Width), Math.Max(this.Dimensions.Height, decoded.Height));
this.Dimensions = new Size(Math.Max(this.Dimensions.Width, decoded.Width), Math.Max(this.Dimensions.Height, decoded.Height));
});
}
@ -233,7 +233,7 @@ internal abstract class IconDecoderCore : ImageDecoderCore
frames[frameCount++] = frameMetadata;
// Identification uses the same embedded-header dimensions as decoding, without allocating pixel buffers.
this.Dimensions = new(Math.Max(this.Dimensions.Width, frameInfo.Width), Math.Max(this.Dimensions.Height, frameInfo.Height));
this.Dimensions = new Size(Math.Max(this.Dimensions.Width, frameInfo.Width), Math.Max(this.Dimensions.Height, frameInfo.Height));
});
}

2
src/ImageSharp/Formats/ImageDecoderCore.cs

@ -279,7 +279,7 @@ internal abstract class ImageDecoderCore
// and Wrap(Memory<T>[]) 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<TPixel> memorySource = MemoryGroup<TPixel>.Wrap(m.ToArray());
MemoryGroup<TPixel> memorySource = MemoryGroup<TPixel>.Wrap([.. m]);
using Image<TPixel> image = new(frame.Configuration, memorySource, frame.Width, frame.Height, metadata);
converter.Convert(image);

6
src/ImageSharp/Formats/ImageFormatManager.cs

@ -32,12 +32,12 @@ public class ImageFormatManager
/// <summary>
/// The list of supported <see cref="IImageFormat"/>s.
/// </summary>
private readonly HashSet<IImageFormat> imageFormats = new();
private readonly HashSet<IImageFormat> imageFormats = [];
/// <summary>
/// The list of supported <see cref="IImageFormatDetector"/>s.
/// </summary>
private ConcurrentBag<IImageFormatDetector> imageFormatDetectors = new();
private ConcurrentBag<IImageFormatDetector> imageFormatDetectors = [];
/// <summary>
/// Initializes a new instance of the <see cref="ImageFormatManager" /> class.
@ -161,7 +161,7 @@ public class ImageFormatManager
/// <summary>
/// Removes all the registered image format detectors.
/// </summary>
public void ClearImageFormatDetectors() => this.imageFormatDetectors = new ConcurrentBag<IImageFormatDetector>();
public void ClearImageFormatDetectors() => this.imageFormatDetectors = [];
/// <summary>
/// Adds a new detector for detecting mime types.

14
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs

@ -119,49 +119,49 @@ internal abstract partial class JpegColorConverterBase
/// </summary>
/// <param name="precision">The precision in bits.</param>
private static JpegColorConverter<YCbCrOperator> GetYCbCrConverter(int precision)
=> new JpegColorConverter<YCbCrOperator>(precision);
=> new(precision);
/// <summary>
/// Returns the <see cref="JpegColorConverterBase"/>s for the YccK colorspace.
/// </summary>
/// <param name="precision">The precision in bits.</param>
private static JpegColorConverter<YccKOperator> GetYccKConverter(int precision)
=> new JpegColorConverter<YccKOperator>(precision);
=> new(precision);
/// <summary>
/// Returns the <see cref="JpegColorConverterBase"/>s for the CMYK colorspace.
/// </summary>
/// <param name="precision">The precision in bits.</param>
private static JpegColorConverter<CmykOperator> GetCmykConverter(int precision)
=> new JpegColorConverter<CmykOperator>(precision);
=> new(precision);
/// <summary>
/// Returns the <see cref="JpegColorConverterBase"/>s for the gray scale colorspace.
/// </summary>
/// <param name="precision">The precision in bits.</param>
private static JpegColorConverter<GrayScaleOperator> GetGrayScaleConverter(int precision)
=> new JpegColorConverter<GrayScaleOperator>(precision);
=> new(precision);
/// <summary>
/// Returns the <see cref="JpegColorConverterBase"/>s for the RGB colorspace.
/// </summary>
/// <param name="precision">The precision in bits.</param>
private static JpegColorConverter<RgbOperator> GetRgbConverter(int precision)
=> new JpegColorConverter<RgbOperator>(precision);
=> new(precision);
/// <summary>
/// Returns the <see cref="JpegColorConverterBase"/> for non-inverted TIFF CMYK.
/// </summary>
/// <param name="precision">The precision in bits.</param>
private static JpegColorConverter<TiffCmykOperator> GetTiffCmykConverter(int precision)
=> new JpegColorConverter<TiffCmykOperator>(precision);
=> new(precision);
/// <summary>
/// Returns the <see cref="JpegColorConverterBase"/> for non-inverted TIFF YccK.
/// </summary>
/// <param name="precision">The precision in bits.</param>
private static JpegColorConverter<TiffYccKOperator> GetTiffYccKConverter(int precision)
=> new JpegColorConverter<TiffYccKOperator>(precision);
=> new(precision);
/// <summary>
/// A stack-only struct to reference the input buffers using <see cref="ReadOnlySpan{T}"/>-s.

2
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -1049,7 +1049,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
if (resourceDataSize > 0 && blockDataSpan.Length >= dataStartIdx + resourceDataSize)
{
this.hasIptc = true;
this.iptcData = blockDataSpan.Slice(dataStartIdx, resourceDataSize).ToArray();
this.iptcData = [.. blockDataSpan.Slice(dataStartIdx, resourceDataSize)];
break;
}

182
src/ImageSharp/Formats/Jpeg/JpegEncoderCore.FrameConfig.cs

@ -21,175 +21,159 @@ internal sealed unsafe partial class JpegEncoderCore
JpegQuantizationTableConfig defaultLuminanceQuantTable = new(0, Quantization.LuminanceTable);
JpegQuantizationTableConfig defaultChrominanceQuantTable = new(1, Quantization.ChrominanceTable);
JpegHuffmanTableConfig[] yCbCrHuffmanConfigs = new JpegHuffmanTableConfig[]
{
JpegHuffmanTableConfig[] yCbCrHuffmanConfigs =
[
defaultLuminanceHuffmanDC,
defaultLuminanceHuffmanAC,
defaultChrominanceHuffmanDC,
defaultChrominanceHuffmanAC,
};
defaultChrominanceHuffmanAC
];
JpegQuantizationTableConfig[] yCbCrQuantTableConfigs = new JpegQuantizationTableConfig[]
{
JpegQuantizationTableConfig[] yCbCrQuantTableConfigs =
[
defaultLuminanceQuantTable,
defaultChrominanceQuantTable,
};
defaultChrominanceQuantTable
];
return
[
return new JpegFrameConfig[]
{
// YCbCr 4:4:4
new(
new JpegFrameConfig(
JpegColorSpace.YCbCr,
JpegColorType.YCbCrRatio444,
new JpegComponentConfig[]
{
new(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
},
[
new JpegComponentConfig(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1)
],
yCbCrHuffmanConfigs,
yCbCrQuantTableConfigs),
// YCbCr 4:2:2
new(
new JpegFrameConfig(
JpegColorSpace.YCbCr,
JpegColorType.YCbCrRatio422,
new JpegComponentConfig[]
{
new(id: 1, hsf: 2, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
},
[
new JpegComponentConfig(id: 1, hsf: 2, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1)
],
yCbCrHuffmanConfigs,
yCbCrQuantTableConfigs),
// YCbCr 4:2:0
new(
new JpegFrameConfig(
JpegColorSpace.YCbCr,
JpegColorType.YCbCrRatio420,
new JpegComponentConfig[]
{
new(id: 1, hsf: 2, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
},
[
new JpegComponentConfig(id: 1, hsf: 2, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1)
],
yCbCrHuffmanConfigs,
yCbCrQuantTableConfigs),
// YCbCr 4:1:1
new(
new JpegFrameConfig(
JpegColorSpace.YCbCr,
JpegColorType.YCbCrRatio411,
new JpegComponentConfig[]
{
new(id: 1, hsf: 4, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
},
[
new JpegComponentConfig(id: 1, hsf: 4, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1)
],
yCbCrHuffmanConfigs,
yCbCrQuantTableConfigs),
// YCbCr 4:1:0
new(
new JpegFrameConfig(
JpegColorSpace.YCbCr,
JpegColorType.YCbCrRatio410,
new JpegComponentConfig[]
{
new(id: 1, hsf: 4, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
},
[
new JpegComponentConfig(id: 1, hsf: 4, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1)
],
yCbCrHuffmanConfigs,
yCbCrQuantTableConfigs),
// Luminance
new(
new JpegFrameConfig(
JpegColorSpace.Grayscale,
JpegColorType.Luminance,
new JpegComponentConfig[]
{
new(id: 0, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
},
new JpegHuffmanTableConfig[]
{
[
new JpegComponentConfig(id: 0, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0)
],
[
defaultLuminanceHuffmanDC,
defaultLuminanceHuffmanAC
},
new JpegQuantizationTableConfig[]
{
],
[
defaultLuminanceQuantTable
}),
]),
// Rgb
new(
new JpegFrameConfig(
JpegColorSpace.RGB,
JpegColorType.Rgb,
new JpegComponentConfig[]
{
new(id: 82, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 71, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 66, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
},
new JpegHuffmanTableConfig[]
{
[
new JpegComponentConfig(id: 82, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 71, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 66, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0)
],
[
defaultLuminanceHuffmanDC,
defaultLuminanceHuffmanAC
},
new JpegQuantizationTableConfig[]
{
],
[
defaultLuminanceQuantTable
})
])
{
AdobeColorTransformMarkerFlag = JpegConstants.Adobe.ColorTransformUnknown
},
// Cmyk
new(
new JpegFrameConfig(
JpegColorSpace.Cmyk,
JpegColorType.Cmyk,
new JpegComponentConfig[]
{
new(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
},
new JpegHuffmanTableConfig[]
{
[
new JpegComponentConfig(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0)
],
[
defaultLuminanceHuffmanDC,
defaultLuminanceHuffmanAC
},
new JpegQuantizationTableConfig[]
{
],
[
defaultLuminanceQuantTable
})
])
{
AdobeColorTransformMarkerFlag = JpegConstants.Adobe.ColorTransformUnknown,
},
// YccK
new(
new JpegFrameConfig(
JpegColorSpace.Ycck,
JpegColorType.Ycck,
new JpegComponentConfig[]
{
new(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
},
new JpegHuffmanTableConfig[]
{
[
new JpegComponentConfig(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0)
],
[
defaultLuminanceHuffmanDC,
defaultLuminanceHuffmanAC
},
new JpegQuantizationTableConfig[]
{
],
[
defaultLuminanceQuantTable
})
])
{
AdobeColorTransformMarkerFlag = JpegConstants.Adobe.ColorTransformYcck,
},
};
}
];
}
}

2
src/ImageSharp/Formats/Png/Chunks/FrameControl.cs

@ -153,7 +153,7 @@ internal readonly struct FrameControl
PngThrowHelper.ThrowInvalidImageContentException("The frame control chunk does not contain enough data!");
}
return new(
return new FrameControl(
sequenceNumber: BinaryPrimitives.ReadUInt32BigEndian(data[..4]),
width: BinaryPrimitives.ReadUInt32BigEndian(data[4..8]),
height: BinaryPrimitives.ReadUInt32BigEndian(data[8..12]),

12
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -291,10 +291,10 @@ internal sealed class PngDecoderCore : ImageDecoderCore
}
case PngChunkType.Palette:
this.palette = chunk.Data.GetSpan().ToArray();
this.palette = [.. chunk.Data.GetSpan()];
break;
case PngChunkType.Transparency:
this.paletteAlpha = chunk.Data.GetSpan().ToArray();
this.paletteAlpha = [.. chunk.Data.GetSpan()];
this.AssignTransparentMarkers(this.paletteAlpha, pngMetadata);
break;
case PngChunkType.Text:
@ -465,11 +465,11 @@ internal sealed class PngDecoderCore : ImageDecoderCore
this.SkipChunkDataAndCrc(chunk);
break;
case PngChunkType.Palette:
this.palette = chunk.Data.GetSpan().ToArray();
this.palette = [.. chunk.Data.GetSpan()];
break;
case PngChunkType.Transparency:
this.paletteAlpha = chunk.Data.GetSpan().ToArray();
this.paletteAlpha = [.. chunk.Data.GetSpan()];
this.AssignTransparentMarkers(this.paletteAlpha, pngMetadata);
// Spec says tRNS must be after PLTE so safe to exit.
@ -1903,7 +1903,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
if (resourceId == adobeIptcResourceId)
{
iptcBytes = payload.ToArray();
iptcBytes = [.. payload];
return true;
}
@ -2119,7 +2119,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
}
else if (IsXmpTextData(keywordBytes))
{
metadata.XmpProfile = new XmpProfile(data[dataStartIdx..].ToArray());
metadata.XmpProfile = new XmpProfile([.. data[dataStartIdx..]]);
}
else
{

2
src/ImageSharp/Formats/Qoi/QoiDecoderCore.cs

@ -85,7 +85,7 @@ internal class QoiDecoderCore : ImageDecoderCore
// Read magic bytes
int read = stream.Read(magicBytes);
if (read != 4 || !magicBytes.SequenceEqual(QoiConstants.Magic.ToArray()))
if (read != 4 || !magicBytes.SequenceEqual([.. QoiConstants.Magic]))
{
ThrowInvalidImageContentException();
}

2
src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs

@ -67,7 +67,7 @@ internal static class TiffDecoderOptionsParser
TiffSampleFormat? sampleFormat = null;
if (exifProfile.TryGetValue(ExifTag.SampleFormat, out IExifValue<ushort[]> 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)
{

4
src/ImageSharp/Formats/Webp/Lossless/CostManager.cs

@ -23,8 +23,8 @@ internal sealed class CostManager : IDisposable
{
int costCacheSize = pixCount > BackwardReferenceEncoder.MaxLength ? BackwardReferenceEncoder.MaxLength : pixCount;
this.CacheIntervals = new List<CostCacheInterval>();
this.CostCache = new List<double>();
this.CacheIntervals = [];
this.CostCache = [];
this.Costs = memoryAllocator.Allocate<float>(pixCount);
this.DistArray = distArray;
this.Count = 0;

2
src/ImageSharp/Formats/Webp/Lossless/CrunchConfig.cs

@ -7,5 +7,5 @@ internal class CrunchConfig
{
public EntropyIx EntropyIdx { get; set; }
public List<CrunchSubConfig> SubConfigs { get; } = new();
public List<CrunchSubConfig> SubConfigs { get; } = [];
}

2
src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogramSet.cs

@ -51,7 +51,7 @@ internal sealed class Vp8LHistogramSet : IEnumerable<Vp8LHistogram>, IDisposable
public Vp8LHistogramSet(int capacity) => this.items = new List<Vp8LHistogram>(capacity);
public Vp8LHistogramSet() => this.items = new List<Vp8LHistogram>();
public Vp8LHistogramSet() => this.items = [];
public int Count => this.items.Count;

2
src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs

@ -438,7 +438,7 @@ internal sealed class WebpLosslessDecoder
}
// TODO: Avoid allocation.
hTreeGroup.HTrees.Add(huffmanTable[..size].ToArray());
hTreeGroup.HTrees.Add([.. huffmanTable[..size]]);
HuffmanCode huffTableZero = huffmanTable[0];
if (isTrivialLiteral && LiteralMap[j] == 1)

2
src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs

@ -478,7 +478,7 @@ internal sealed partial class IccDataWriter
this.dataStream.Position += cultureCount * 12;
// TODO: Investigate cost of Linq GroupBy
IGrouping<string, IccLocalizedString>[] texts = value.Texts.GroupBy(t => t.Text).ToArray();
IGrouping<string, IccLocalizedString>[] texts = [.. value.Texts.GroupBy(t => t.Text)];
uint[] offset = new uint[texts.Length];
int[] lengths = new int[texts.Length];

4
src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs

@ -102,7 +102,7 @@ internal sealed class IccReader
entries.Add(entry);
}
return entries.ToArray();
return [.. entries];
}
private static IccTagTableEntry[] ReadTagTable(IccDataReader reader)
@ -132,6 +132,6 @@ internal sealed class IccReader
}
}
return table.ToArray();
return [.. table];
}
}

2
src/ImageSharp/Metadata/Profiles/ICC/IccWriter.cs

@ -81,6 +81,6 @@ internal sealed class IccWriter
}
}
return table.ToArray();
return [.. table];
}
}

2
src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs

@ -102,7 +102,7 @@ internal sealed class IccTextDescriptionTagDataEntry : IccTagDataEntry, IEquatab
localString = new IccLocalizedString(string.Empty);
}
return new IccMultiLocalizedUnicodeTagDataEntry(new[] { localString }, textEntry.TagSignature);
return new IccMultiLocalizedUnicodeTagDataEntry([localString], textEntry.TagSignature);
static CultureInfo GetCulture(uint value)
{

2
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.
// <auto-generated />

24
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<float>",
"Vector512<float>",
};
"Vector512<float>"
];
private static string GetComposition(string blender, string composer, string zero)
{

2
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4P.cs

@ -169,7 +169,7 @@ public partial struct NormalizedByte4P : IPixel<NormalizedByte4P>, IPackedVector
// Signed-normalized storage uses the native [-1, 1] range even though association is defined in scaled opacity space.
source *= 2F;
source -= Vector4.One;
return new() { PackedValue = Pack(source) };
return new NormalizedByte4P { PackedValue = Pack(source) };
}
/// <inheritdoc />

6
src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs

@ -183,7 +183,7 @@ public partial struct Rgb96 : IPixel<Rgb96>, IEquatable<Rgb96>
public static Rgb96 FromL16(L16 source)
{
uint rgb = ColorNumerics.From16BitTo32Bit(source.PackedValue);
return new(rgb, rgb, rgb);
return new Rgb96(rgb, rgb, rgb);
}
/// <inheritdoc/>
@ -191,7 +191,7 @@ public partial struct Rgb96 : IPixel<Rgb96>, IEquatable<Rgb96>
public static Rgb96 FromLa16(La16 source)
{
uint rgb = ColorNumerics.From8BitTo32Bit((byte)source.PackedValue);
return new(rgb, rgb, rgb);
return new Rgb96(rgb, rgb, rgb);
}
/// <inheritdoc/>
@ -199,7 +199,7 @@ public partial struct Rgb96 : IPixel<Rgb96>, IEquatable<Rgb96>
public static Rgb96 FromLa32(La32 source)
{
uint rgb = ColorNumerics.From16BitTo32Bit(source.L);
return new(rgb, rgb, rgb);
return new Rgb96(rgb, rgb, rgb);
}
/// <inheritdoc/>

6
src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs

@ -180,21 +180,21 @@ public partial struct Rgba128 : IPixel<Rgba128>, IEquatable<Rgba128>
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);
}
/// <inheritdoc/>
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);
}
/// <inheritdoc/>
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);
}
/// <inheritdoc/>

2
src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs

@ -35,7 +35,7 @@ internal class AffineTransformProcessor<TPixel> : TransformProcessor<TPixel>, IR
{
this.destinationSize = definition.DestinationSize;
this.transformMatrix = definition.TransformMatrix;
this.transformMatrix4x4 = new(this.transformMatrix);
this.transformMatrix4x4 = new Matrix4x4(this.transformMatrix);
this.resampler = definition.Sampler;
}

4
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs

@ -73,10 +73,10 @@ internal readonly unsafe struct ResizeKernel
{
if (Vector256.IsHardwareAccelerated)
{
return new(this.bufferPtr, this.Length * 4);
return new Span<float>(this.bufferPtr, this.Length * 4);
}
return new(this.bufferPtr, this.Length);
return new Span<float>(this.bufferPtr, this.Length);
}
}

6
tests/ImageSharp.Benchmarks/Processing/ColorMatchingCaches.cs

@ -146,7 +146,7 @@ public class ColorMatchingCaches
// RGBA space without clustering into a gradient. That keeps the benchmark from
// accidentally favoring any cache because the palette itself is too regular.
uint value = unchecked((uint)(i + 1) * 2654435761U);
result[i] = new(
result[i] = new Rgba32(
(byte)value,
(byte)(value >> 8),
(byte)(value >> 16),
@ -166,7 +166,7 @@ public class ColorMatchingCaches
for (int i = 0; i < result.Length; i++)
{
Rgba32 source = palette[(i * 17) % palette.Length];
result[i] = new(
result[i] = new Rgba32(
(byte)(source.R + ((i * 3) & 0x07)),
(byte)(source.G + ((i * 5) & 0x07)),
(byte)(source.B + ((i * 7) & 0x07)),
@ -200,7 +200,7 @@ public class ColorMatchingCaches
int x = i & 511;
int y = i >> 9;
result[i] = new(
result[i] = new Rgba32(
(byte)((x * 17) + (y * 13)),
(byte)((x * 29) + (y * 7)),
(byte)((x * 11) + (y * 23)),

4
tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs

@ -189,7 +189,7 @@ public class ColorProfileConverterTests(ITestOutputHelper testOutputHelper)
{
case IccColorSpaceType.Cmyk:
{
Span<Cmyk> inputSpan = inputs.Select(x => new Cmyk(new Vector4(x))).ToArray();
Span<Cmyk> inputSpan = [.. inputs.Select(x => new Cmyk(new Vector4(x)))];
switch (targetDataSpace)
{
@ -214,7 +214,7 @@ public class ColorProfileConverterTests(ITestOutputHelper testOutputHelper)
case IccColorSpaceType.Rgb:
{
Span<Rgb> inputSpan = inputs.Select(x => new Rgb(new Vector3(x))).ToArray();
Span<Rgb> inputSpan = [.. inputs.Select(x => new Rgb(new Vector3(x)))];
switch (targetDataSpace)
{

2
tests/ImageSharp.Tests/ColorProfiles/RgbWorkingSpaceTests.cs

@ -110,7 +110,7 @@ public class RgbWorkingSpaceTests
Assert.Equal(linear[i], expanded, TolerantComparer);
}
Vector4[] actualCompressed = linear.ToArray();
Vector4[] actualCompressed = [.. linear];
workingSpace.Compress(actualCompressed);
Assert.Equal(expectedCompressed, actualCompressed, TolerantComparer);

2
tests/ImageSharp.Tests/Common/EncoderExtensionsTests.cs

@ -20,7 +20,7 @@ public class EncoderExtensionsTests
[Fact]
public void GetString_Buffer_ReturnsString()
{
ReadOnlySpan<byte> buffer = new(new byte[] { 73, 109, 97, 103, 101, 83, 104, 97, 114, 112 });
ReadOnlySpan<byte> buffer = new([73, 109, 97, 103, 101, 83, 104, 97, 114, 112]);
string result = Encoding.UTF8.GetString(buffer);

20
tests/ImageSharp.Tests/Common/SimdUtilsTests.cs

@ -171,10 +171,10 @@ public partial class SimdUtilsTests
int count,
Action<Memory<byte>, Memory<float>> convert)
{
byte[] source = Enumerable.Range(0, count).Select(i => (byte)i).ToArray();
byte[] source = [.. Enumerable.Range(0, count).Select(i => (byte)i)];
float[] result = new float[count];
// A double-precision oracle keeps this expectation independent from either production implementation.
float[] expected = source.Select(b => (float)(b / (double)byte.MaxValue)).ToArray();
float[] expected = [.. source.Select(b => (float)(b / (double)byte.MaxValue))];
convert(source, result);
@ -222,7 +222,7 @@ public partial class SimdUtilsTests
[Fact]
public void BulkConvertNormalizedFloatToByteRoundsMidpointsAwayFromZero()
{
float[] midpointValues = Enumerable.Range(0, byte.MaxValue).Select(x => (x + 0.5F) / byte.MaxValue).ToArray();
float[] midpointValues = [.. Enumerable.Range(0, byte.MaxValue).Select(x => (x + 0.5F) / byte.MaxValue)];
float[] source = new float[1024];
byte[] expected = new byte[source.Length];
byte[] actual = new byte[source.Length];
@ -280,9 +280,9 @@ public partial class SimdUtilsTests
return;
}
byte[] r = Enumerable.Range(0, 32).Select(x => (byte)x).ToArray();
byte[] g = Enumerable.Range(100, 32).Select(x => (byte)x).ToArray();
byte[] b = Enumerable.Range(200, 32).Select(x => (byte)x).ToArray();
byte[] r = [.. Enumerable.Range(0, 32).Select(x => (byte)x)];
byte[] g = [.. Enumerable.Range(100, 32).Select(x => (byte)x)];
byte[] b = [.. Enumerable.Range(200, 32).Select(x => (byte)x)];
const int padding = 4;
Rgb24[] d = new Rgb24[32 + padding];
@ -314,9 +314,9 @@ public partial class SimdUtilsTests
return;
}
byte[] r = Enumerable.Range(0, 32).Select(x => (byte)x).ToArray();
byte[] g = Enumerable.Range(100, 32).Select(x => (byte)x).ToArray();
byte[] b = Enumerable.Range(200, 32).Select(x => (byte)x).ToArray();
byte[] r = [.. Enumerable.Range(0, 32).Select(x => (byte)x)];
byte[] g = [.. Enumerable.Range(100, 32).Select(x => (byte)x)];
byte[] b = [.. Enumerable.Range(200, 32).Select(x => (byte)x)];
Rgba32[] d = new Rgba32[32];
@ -369,7 +369,7 @@ public partial class SimdUtilsTests
{
seed = seed > 0 ? seed : count;
float[] source = new Random(seed).GenerateRandomFloatArray(count, -0.2f, 1.2f);
byte[] expected = source.Select(NormalizedFloatToByte).ToArray();
byte[] expected = [.. source.Select(NormalizedFloatToByte)];
byte[] actual = new byte[count];
convert(source, actual);

2
tests/ImageSharp.Tests/Common/StreamExtensionsTests.cs

@ -79,7 +79,7 @@ public class StreamExtensionsTests
{
public override bool CanSeek => false;
public List<int> Counts = new();
public List<int> Counts = [];
public NonSeekableStream()
: base(4)

24
tests/ImageSharp.Tests/Common/TensorPrimitivesTests.cs

@ -251,7 +251,7 @@ public class TensorPrimitivesTests
public void NegateSingleMatchesScalarFormula(int length)
{
float[] values =
{
[
float.NaN,
-0F,
0F,
@ -259,7 +259,7 @@ public class TensorPrimitivesTests
1F,
float.NegativeInfinity,
float.PositiveInfinity
};
];
float[] source = new float[length];
float[] expected = new float[length];
@ -287,7 +287,7 @@ public class TensorPrimitivesTests
public void NegateDoubleMatchesScalarFormula(int length)
{
double[] values =
{
[
double.NaN,
-0D,
0D,
@ -295,7 +295,7 @@ public class TensorPrimitivesTests
1D,
double.NegativeInfinity,
double.PositiveInfinity
};
];
double[] source = new double[length];
double[] expected = new double[length];
@ -349,7 +349,7 @@ public class TensorPrimitivesTests
public void ClampSingleMatchesRuntimeFormula(int length)
{
float[] values =
{
[
float.NaN,
-0F,
0F,
@ -357,7 +357,7 @@ public class TensorPrimitivesTests
1F,
float.NegativeInfinity,
float.PositiveInfinity
};
];
float[] source = new float[length];
float[] expected = new float[length];
@ -381,13 +381,13 @@ public class TensorPrimitivesTests
public void ClampSinglePreservesRuntimeSpecialValueSemantics()
{
float[] values =
{
[
float.NaN,
float.NegativeInfinity,
-0F,
0F,
float.PositiveInfinity
};
];
float[] actual = new float[129];
float[] expected = new float[actual.Length];
@ -409,13 +409,13 @@ public class TensorPrimitivesTests
public void ClampDoublePreservesRuntimeSpecialValueSemantics()
{
double[] values =
{
[
double.NaN,
double.NegativeInfinity,
-0D,
0D,
double.PositiveInfinity
};
];
double[] actual = new double[65];
double[] expected = new double[actual.Length];
@ -465,7 +465,7 @@ public class TensorPrimitivesTests
public void MaxSingleMatchesRuntimeFormula(int length)
{
float[] values =
{
[
float.NaN,
float.NegativeInfinity,
-1F,
@ -473,7 +473,7 @@ public class TensorPrimitivesTests
0F,
1F,
float.PositiveInfinity
};
];
float[] actual = new float[length];
float[] expected = new float[length];

10
tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs

@ -71,7 +71,7 @@ public class AniDecoderTests
[Fact]
public void AniDecoder_InvalidSequenceReference_FollowsIntegrityHandling()
{
byte[] data = TestFile.Create(Help).Bytes.ToArray();
byte[] data = [.. TestFile.Create(Help).Bytes];
int sequenceOffset = data.AsSpan().IndexOf("seq "u8);
Assert.True(sequenceOffset >= 0);
@ -94,7 +94,7 @@ public class AniDecoderTests
[Fact]
public void AniDecoder_UnsupportedResource_FollowsIntegrityHandling()
{
byte[] data = TestFile.Create(Work).Bytes.ToArray();
byte[] data = [.. TestFile.Create(Work).Bytes];
int resourceOffset = data.AsSpan().IndexOf("icon"u8);
Assert.True(resourceOffset >= 0);
@ -119,7 +119,7 @@ public class AniDecoderTests
[Fact]
public void AniDecoder_InvalidRateChunk_FollowsIntegrityHandling()
{
byte[] source = TestFile.Create(Help).Bytes.ToArray();
byte[] source = [.. TestFile.Create(Help).Bytes];
int rateOffset = source.AsSpan().IndexOf("rate"u8);
Assert.True(rateOffset >= 0);
@ -155,7 +155,7 @@ public class AniDecoderTests
[InlineData(true)]
public void AniDecoder_OversizedControlChunk_FollowsIntegrityHandling(bool sequence)
{
byte[] source = TestFile.Create(Help).Bytes.ToArray();
byte[] source = [.. TestFile.Create(Help).Bytes];
int chunkOffset = (source.Length + 1) & ~1;
int payloadSize = AniConstants.MaxAncillaryChunkSize + sizeof(uint);
byte[] data = new byte[chunkOffset + AniConstants.ChunkHeaderSize + payloadSize];
@ -182,7 +182,7 @@ public class AniDecoderTests
[Fact]
public void AniDecoder_OversizedInformationText_FollowsIntegrityHandling()
{
byte[] source = TestFile.Create(Help).Bytes.ToArray();
byte[] source = [.. TestFile.Create(Help).Bytes];
int listOffset = (source.Length + 1) & ~1;
int textSize = AniConstants.MaxAncillaryChunkSize + 1;
int paddedTextSize = textSize + (textSize & 1);

18
tests/ImageSharp.Tests/Formats/Exr/ExrDecoderSecurityTests.cs

@ -39,7 +39,7 @@ public class ExrDecoderSecurityTests
// Width = 1073741823 - (-1073741825) + 1 = 2^31 + 1 → wraps to -2147483647
byte[] data = BuildMinimalExr(xMin: -1073741825, yMin: 0, xMax: 1073741823, yMax: 0);
using var stream = new MemoryStream(data);
using MemoryStream stream = new(data);
Assert.Throws<InvalidImageContentException>(
() => ExrDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream));
}
@ -74,7 +74,7 @@ public class ExrDecoderSecurityTests
xMin: 0, yMin: 0, xMax: 1, yMax: 1,
rowOffsetTableAppend: invalidOffsets);
using var stream = new MemoryStream(data);
using MemoryStream stream = new(data);
Assert.Throws<InvalidImageContentException>(
() => ExrDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream));
}
@ -90,7 +90,7 @@ public class ExrDecoderSecurityTests
xMin: 0, yMin: 0, xMax: 1, yMax: 1,
rowOffsetTableAppend: headerOffsets);
using var stream = new MemoryStream(data);
using MemoryStream stream = new(data);
Assert.Throws<InvalidImageContentException>(
() => ExrDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream));
}
@ -105,7 +105,7 @@ public class ExrDecoderSecurityTests
// Point the first row offset at the second row offset entry.
BinaryPrimitives.WriteUInt64LittleEndian(data.AsSpan(data.Length - 16), (ulong)(data.Length - 8));
using var stream = new MemoryStream(data);
using MemoryStream stream = new(data);
Assert.Throws<InvalidImageContentException>(
() => ExrDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream));
}
@ -128,7 +128,7 @@ public class ExrDecoderSecurityTests
// int-sized row staging or block buffers.
byte[] data = BuildMinimalRgbaExr(xMin: 0, yMin: 0, xMax: 536870911, yMax: 0);
using var stream = new MemoryStream(data);
using MemoryStream stream = new(data);
Assert.Throws<InvalidImageContentException>(
() => ExrDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream));
}
@ -140,7 +140,7 @@ public class ExrDecoderSecurityTests
// still stages four color planes and must reject widths that overflow width × 4.
byte[] data = BuildMinimalExr(xMin: 0, yMin: 0, xMax: int.MaxValue / 4, yMax: 0);
using var stream = new MemoryStream(data);
using MemoryStream stream = new(data);
Assert.Throws<InvalidImageContentException>(
() => ExrDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream));
}
@ -152,7 +152,7 @@ public class ExrDecoderSecurityTests
// validated before scanline decoding reads from the table.
byte[] data = BuildMinimalExr(xMin: 0, yMin: 0, xMax: 1, yMax: 1);
using var stream = new MemoryStream(data);
using MemoryStream stream = new(data);
Assert.Throws<InvalidImageContentException>(
() => ExrDecoder.Instance.Identify(DecoderOptions.Default, stream));
}
@ -223,8 +223,8 @@ public class ExrDecoderSecurityTests
byte[] channelData,
byte[] rowOffsetTableAppend = null)
{
using var ms = new MemoryStream();
using var bw = new BinaryWriter(ms, System.Text.Encoding.ASCII, leaveOpen: true);
using MemoryStream ms = new();
using BinaryWriter bw = new(ms, System.Text.Encoding.ASCII, leaveOpen: true);
// Magic (0x01312F76 LE) + version 2, scanline (flags = 0x00)
bw.Write(new byte[] { 0x76, 0x2F, 0x31, 0x01, 0x02, 0x00, 0x00, 0x00 });

4
tests/ImageSharp.Tests/Formats/Icon/Ico/IcoDecoderTests.cs

@ -320,7 +320,7 @@ public class IcoDecoderTests
[Fact]
public void TruncatedEntry_FollowsImageDataIntegrityHandling()
{
byte[] data = TestFile.Create(Flutter).Bytes.ToArray();
byte[] data = [.. TestFile.Create(Flutter).Bytes];
ushort entryCount = BinaryPrimitives.ReadUInt16LittleEndian(data.AsSpan(4));
Assert.True(entryCount > 1);
@ -347,7 +347,7 @@ public class IcoDecoderTests
[Fact]
public void EntryAtEndOfStream_ThrowsInvalidResourceRange()
{
byte[] data = TestFile.Create(Bpp32Size1x1).Bytes.ToArray();
byte[] data = [.. TestFile.Create(Bpp32Size1x1).Bytes];
Assert.Equal(1, BinaryPrimitives.ReadUInt16LittleEndian(data.AsSpan(4)));
// ImageOffset is the final DWORD in the sole directory entry. The stream length is an exclusive boundary,

2
tests/ImageSharp.Tests/Formats/Jpg/JpegMetadataTests.cs

@ -71,7 +71,7 @@ public class JpegMetadataTests
public void Comment_OnlyComment()
{
string comment = "test comment";
Collection<string> expectedCollection = new() { comment };
Collection<string> expectedCollection = [comment];
JpegMetadata meta = new();
meta.Comments.Add(JpegComData.FromString(comment));

2
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)]

2
tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs

@ -121,7 +121,7 @@ internal static partial class LibJpegTools
{
rdr.Read(buffer, 0, buffer.Length);
short[] block = MemoryMarshal.Cast<byte, short>(buffer.AsSpan()).ToArray();
short[] block = [.. MemoryMarshal.Cast<byte, short>(buffer.AsSpan())];
c.MakeBlock(block, y, x);
}
}

2
tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs

@ -34,7 +34,7 @@ internal static class VerifyJpeg
int xBc2,
int yBc2)
{
IJpegComponent[] c = components.ToArray();
IJpegComponent[] c = [.. components];
Assert.Equal(3, components.Count());
VerifySize(c[0], xBc0, yBc0);

2
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -287,7 +287,7 @@ public partial class PngEncoderTests
using MemoryStream ms = new();
image.Save(ms, PngEncoder);
byte[] data = ms.ToArray().Take(8).ToArray();
byte[] data = [.. ms.ToArray().Take(8)];
byte[] expected =
[
0x89, // Set the high bit.

2
tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs

@ -32,7 +32,7 @@ public class PngMetadataTests
ColorType = PngColorType.GrayscaleWithAlpha,
InterlaceMethod = PngInterlaceMode.Adam7,
Gamma = 2,
TextData = [new("name", "value", "foo", "bar")],
TextData = [new PngTextData("name", "value", "foo", "bar")],
RepeatCount = 123,
AnimateRootFrame = false
};

4
tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs

@ -137,7 +137,7 @@ public class BigTiffMetadataTests
};
// arrange
List<IExifValue> values = new();
List<IExifValue> values = [];
foreach (KeyValuePair<ExifTag, (ExifDataType DataType, object Value)> tag in testTags)
{
ExifValue newExifValue = ExifValues.Create((ExifTagValue)(ushort)tag.Key, tag.Value.DataType, tag.Value.Value is Array);
@ -182,7 +182,7 @@ public class BigTiffMetadataTests
////{ new ExifTag<long[]>((ExifTagValue)0xdd14), (ExifDataType.SignedLong8, new long[] { -1234, 56789L, long.MaxValue }) },
};
List<IExifValue> values = new();
List<IExifValue> values = [];
foreach (KeyValuePair<ExifTag, (ExifDataType DataType, object Value)> tag in testTags)
{
ExifValue newExifValue = ExifValues.Create((ExifTagValue)(ushort)tag.Key, tag.Value.DataType, tag.Value.Value is Array);

110
tests/ImageSharp.Tests/Formats/WebP/Vp8HistogramTests.cs

@ -13,55 +13,59 @@ public class Vp8HistogramTests
{
get
{
List<object[]> 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<object[]> result =
[
[
new byte[]
{
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 19, 16, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 204, 204,
204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204, 204, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 19, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204,
204, 204, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 19, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204,
204, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 24, 16, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204
},
new byte[]
{
128, 128, 128, 128, 129, 129, 129, 129, 127, 127, 127, 127, 129, 129, 129, 129, 128,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128,
128, 128, 129, 129, 129, 129, 127, 127, 127, 127, 129, 129, 129, 129, 129, 128, 127,
127, 128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 128, 128,
129, 129, 129, 129, 127, 127, 127, 127, 129, 129, 129, 129, 129, 129, 128, 127, 129,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 128, 128, 129, 129,
129, 129, 127, 127, 127, 127, 129, 129, 129, 129, 129, 129, 129, 128, 129, 128, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 127, 127, 129, 129, 129, 129,
204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 129, 129, 128, 128, 129, 129, 129, 129, 204, 204,
204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204,
204, 204, 204, 204, 204, 129, 129, 129, 129, 129, 129, 129, 129, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204,
204, 204, 204, 129, 129, 129, 129, 129, 129, 129, 129, 204, 204, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204
}
]
];
return result;
}
}
@ -72,7 +76,7 @@ public class Vp8HistogramTests
Vp8Histogram histogram = new();
byte[] reference =
{
[
154, 154, 151, 151, 149, 148, 151, 157, 163, 163, 154, 132, 102, 98, 104, 108, 107, 104, 104, 103,
101, 106, 123, 119, 170, 171, 172, 171, 168, 175, 171, 173, 151, 151, 149, 150, 147, 147, 146, 159,
164, 165, 154, 129, 92, 90, 101, 105, 104, 103, 104, 101, 100, 105, 123, 117, 172, 172, 172, 168,
@ -99,9 +103,9 @@ public class Vp8HistogramTests
95, 102, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 151, 130,
82, 82, 89, 134, 154, 161, 161, 157, 152, 129, 81, 77, 95, 102, 204, 204, 204, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 204, 204
};
];
byte[] pred =
{
[
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129,
@ -154,7 +158,7 @@ public class Vp8HistogramTests
129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129,
129, 129, 129, 129
};
];
int expectedAlpha = 146;
// act

26
tests/ImageSharp.Tests/Helpers/NumericsTests.cs

@ -178,11 +178,14 @@ public class NumericsTests
};
}
Vector4[] expected = source.Select(v =>
{
Numerics.Premultiply(ref v);
return v;
}).ToArray();
Vector4[] expected =
[
.. source.Select(v =>
{
Numerics.Premultiply(ref v);
return v;
})
];
Numerics.Premultiply(source);
@ -213,11 +216,14 @@ public class NumericsTests
};
}
Vector4[] expected = source.Select(v =>
{
Numerics.UnPremultiply(ref v);
return v;
}).ToArray();
Vector4[] expected =
[
.. source.Select(v =>
{
Numerics.UnPremultiply(ref v);
return v;
})
];
Numerics.UnPremultiply(source);

4
tests/ImageSharp.Tests/Helpers/ParallelRowIteratorTests.cs

@ -101,7 +101,7 @@ public class ParallelRowIteratorTests
Rectangle rectangle = new(0, minY, 10, maxY - minY);
int[] expectedData = Enumerable.Repeat(0, minY).Concat(Enumerable.Range(minY, maxY - minY)).ToArray();
int[] expectedData = [.. Enumerable.Repeat(0, minY), .. Enumerable.Range(minY, maxY - minY)];
int[] actualData = new int[maxY];
void RowAction(RowInterval rows)
@ -180,7 +180,7 @@ public class ParallelRowIteratorTests
Rectangle rectangle = new(0, minY, 10, maxY - minY);
int[] expectedData = Enumerable.Repeat(0, minY).Concat(Enumerable.Range(minY, maxY - minY)).ToArray();
int[] expectedData = [.. Enumerable.Repeat(0, minY), .. Enumerable.Range(minY, maxY - minY)];
int[] actualData = new int[maxY];
void RowAction(RowInterval rows, Span<Vector4> buffer)

2
tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs

@ -181,7 +181,7 @@ public abstract partial class ImageFrameCollectionTests
this.Image,
[imageFrame1, imageFrame2]);
IPixelSource<Rgba32>[] framesSnapShot = collection.OfType<IPixelSource<Rgba32>>().ToArray();
IPixelSource<Rgba32>[] framesSnapShot = [.. collection.OfType<IPixelSource<Rgba32>>()];
Assert.All(framesSnapShot, f => Assert.False(f.PixelBuffer.IsDisposed));

4
tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs

@ -29,7 +29,7 @@ public abstract partial class ImageFrameCollectionTests
}
Rgba32[] expectedAllBlue =
Enumerable.Repeat(Color.Blue.ToPixel<Rgba32>(), this.Image.Width * this.Image.Height).ToArray();
[.. Enumerable.Repeat(Color.Blue.ToPixel<Rgba32>(), this.Image.Width * this.Image.Height)];
Assert.Equal(2, this.Collection.Count);
ImageFrame<Rgba32> actualFrame = (ImageFrame<Rgba32>)this.Collection[1];
@ -50,7 +50,7 @@ public abstract partial class ImageFrameCollectionTests
}
Rgba32[] expectedAllBlue =
Enumerable.Repeat(Color.Blue.ToPixel<Rgba32>(), this.Image.Width * this.Image.Height).ToArray();
[.. Enumerable.Repeat(Color.Blue.ToPixel<Rgba32>(), this.Image.Width * this.Image.Height)];
Assert.Equal(2, this.Collection.Count);
ImageFrame<Rgba32> actualFrame = (ImageFrame<Rgba32>)this.Collection[0];

2
tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs

@ -26,7 +26,7 @@ public partial class ImageTests
//TestImages.Pbm.GrayscaleBinaryWide
];
public static object[][] IdentifyData { get; } = TestFileForEachCodec.Select(f => new object[] { f }).ToArray();
public static object[][] IdentifyData { get; } = [.. TestFileForEachCodec.Select(f => new object[] { f })];
[Theory]
[MemberData(nameof(IdentifyData))]

32
tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs

@ -146,14 +146,14 @@ public partial class ImageTests
{
Rgba32[] source =
[
new Rgba32(1, 1, 1, 255),
new Rgba32(2, 2, 2, 255),
new Rgba32(3, 3, 3, 255),
new Rgba32(90, 90, 90, 255),
new Rgba32(4, 4, 4, 255),
new Rgba32(5, 5, 5, 255),
new Rgba32(6, 6, 6, 255),
new Rgba32(91, 91, 91, 255)
new(1, 1, 1, 255),
new(2, 2, 2, 255),
new(3, 3, 3, 255),
new(90, 90, 90, 255),
new(4, 4, 4, 255),
new(5, 5, 5, 255),
new(6, 6, 6, 255),
new(91, 91, 91, 255)
];
using Image<Rgba32> image = Image.WrapMemory(source.AsMemory(), width: 3, height: 2, rowStride: 4);
@ -171,14 +171,14 @@ public partial class ImageTests
{
Rgba32[] source =
[
new Rgba32(1, 1, 1, 255),
new Rgba32(2, 2, 2, 255),
new Rgba32(3, 3, 3, 255),
new Rgba32(90, 90, 90, 255),
new Rgba32(4, 4, 4, 255),
new Rgba32(5, 5, 5, 255),
new Rgba32(6, 6, 6, 255),
new Rgba32(91, 91, 91, 255)
new(1, 1, 1, 255),
new(2, 2, 2, 255),
new(3, 3, 3, 255),
new(90, 90, 90, 255),
new(4, 4, 4, 255),
new(5, 5, 5, 255),
new(6, 6, 6, 255),
new(91, 91, 91, 255)
];
using Image<Rgba32> image = Image.WrapMemory(source.AsMemory(), width: 3, height: 2, rowStride: 4);

4
tests/ImageSharp.Tests/Memory/Allocators/SharedArrayPoolBufferTests.cs

@ -23,7 +23,7 @@ public class SharedArrayPoolBufferTests
}
byte[] array = ArrayPool<byte>.Shared.Rent(900);
byte[] expected = Enumerable.Repeat((byte)42, 900).ToArray();
byte[] expected = [.. Enumerable.Repeat((byte)42, 900)];
Assert.True(expected.AsSpan().SequenceEqual(array.AsSpan(0, 900)));
}
@ -48,7 +48,7 @@ public class SharedArrayPoolBufferTests
buffer.ReleaseRef();
array = ArrayPool<byte>.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<byte>.Shared.Return(array);
}

12
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<UnmanagedMemoryHandle> handlesToDestroy = new();
private readonly List<IntPtr> ptrsToDestroy = new();
private readonly List<UnmanagedMemoryHandle> handlesToDestroy = [];
private readonly List<IntPtr> ptrsToDestroy = [];
public CleanupUtil(UniformUnmanagedMemoryPool pool)
{
@ -151,8 +151,8 @@ public partial class UniformUnmanagedMemoryPoolTests
{
UniformUnmanagedMemoryPool pool = new(128, capacity);
using CleanupUtil cleanup = new(pool);
HashSet<UnmanagedMemoryHandle> allHandles = new();
List<UnmanagedMemoryHandle[]> handleUnits = new();
HashSet<UnmanagedMemoryHandle> allHandles = [];
List<UnmanagedMemoryHandle[]> handleUnits = [];
UnmanagedMemoryHandle[] handles;
for (int i = 0; i < totalCount; i += rentUnit)
@ -261,7 +261,7 @@ public partial class UniformUnmanagedMemoryPoolTests
pool.Release();
// Do some unmanaged allocations to make sure new pool buffers are different:
IntPtr[] dummy = Enumerable.Range(0, 100).Select(_ => Marshal.AllocHGlobal(16)).ToArray();
IntPtr[] dummy = [.. Enumerable.Range(0, 100).Select(_ => Marshal.AllocHGlobal(16))];
cleanup.Register(dummy);
if (bool.Parse(multipleInner))
@ -312,7 +312,7 @@ public partial class UniformUnmanagedMemoryPoolTests
Parallel.For(0, Environment.ProcessorCount, (int i) =>
{
List<UnmanagedMemoryHandle> allHandles = new();
List<UnmanagedMemoryHandle> allHandles = [];
int pauseAt = rnd.Next(100);
for (int j = 0; j < 100; j++)
{

2
tests/ImageSharp.Tests/Memory/Allocators/UnmanagedBufferTests.cs

@ -76,7 +76,7 @@ public class UnmanagedBufferTests
static List<UnmanagedBuffer<byte>> FillList(int countInner)
{
List<UnmanagedBuffer<byte>> l = new();
List<UnmanagedBuffer<byte>> l = [];
for (int i = 0; i < countInner; i++)
{
UnmanagedBuffer<byte> h = UnmanagedBuffer<byte>.Allocate(42);

2
tests/ImageSharp.Tests/Memory/Allocators/UnmanagedMemoryHandleTests.cs

@ -47,7 +47,7 @@ public class UnmanagedMemoryHandleTests
static void RunTest(string countStr)
{
int countInner = int.Parse(countStr);
List<UnmanagedMemoryHandle> l = new();
List<UnmanagedMemoryHandle> l = [];
for (int i = 0; i < countInner; i++)
{
Assert.Equal(i, UnmanagedMemoryHandle.TotalOutstandingHandles);

2
tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.Allocate.cs

@ -206,7 +206,7 @@ public partial class MemoryGroupTests
{
IReadOnlyList<TestMemoryAllocator.AllocationRequest> 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);

14
tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.cs

@ -29,9 +29,9 @@ public partial class MemoryGroupTests : MemoryGroupTestsBase
[Fact]
public void Wrap()
{
int[] data0 = { 1, 2, 3, 4 };
int[] data1 = { 5, 6, 7, 8 };
int[] data2 = { 9, 10 };
int[] data0 = [1, 2, 3, 4];
int[] data1 = [5, 6, 7, 8];
int[] data2 = [9, 10];
using TestMemoryManager<int> mgr0 = new(data0);
using TestMemoryManager<int> mgr1 = new(data1);
@ -46,7 +46,7 @@ public partial class MemoryGroupTests : MemoryGroupTestsBase
Assert.True(group[2].Span.SequenceEqual(data2));
int cnt = 0;
int[][] allData = { data0, data1, data2 };
int[][] allData = [data0, data1, data2];
foreach (Memory<int> memory in group)
{
Assert.True(memory.Span.SequenceEqual(allData[cnt]));
@ -106,7 +106,7 @@ public partial class MemoryGroupTests : MemoryGroupTestsBase
using MemoryGroup<int> group = this.CreateTestGroup(100, 10, true);
group.Fill(42);
int[] expectedRow = Enumerable.Repeat(42, 10).ToArray();
int[] expectedRow = [.. Enumerable.Repeat(42, 10)];
foreach (Memory<int> memory in group)
{
Assert.True(memory.Span.SequenceEqual(expectedRow));
@ -119,7 +119,7 @@ public partial class MemoryGroupTests : MemoryGroupTestsBase
using MemoryGroup<int> group = this.CreateTestGroup(100, 10, true);
group.Fill(42);
int[] expectedRow = Enumerable.Repeat(42, 10).ToArray();
int[] expectedRow = [.. Enumerable.Repeat(42, 10)];
IReadOnlyList<Memory<int>> groupAsList = group;
foreach (Memory<int> memory in groupAsList)
{
@ -133,7 +133,7 @@ public partial class MemoryGroupTests : MemoryGroupTestsBase
using MemoryGroup<int> 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<int> memory in groupAsList)
{

6
tests/ImageSharp.Tests/Metadata/Profiles/Exif/ExifProfileTests.cs

@ -374,7 +374,7 @@ public class ExifProfileTests
Image<Rgba32> image = new(100, 100);
ExifProfile expectedProfile = CreateExifProfile();
List<ExifTag> expectedProfileTags = expectedProfile.Values.Select(x => x.Tag).ToList();
List<ExifTag> expectedProfileTags = [.. expectedProfile.Values.Select(x => x.Tag)];
expectedProfile.SetValue(tag, junk.ToString());
image.Metadata.ExifProfile = expectedProfile;
@ -470,9 +470,9 @@ public class ExifProfileTests
public void ProfileToByteArray()
{
// Arrange
byte[] exifBytesWithoutExifCode = ExifConstants.LittleEndianByteOrderMarker.ToArray();
byte[] exifBytesWithoutExifCode = [.. ExifConstants.LittleEndianByteOrderMarker];
ExifProfile expectedProfile = CreateExifProfile();
List<ExifTag> expectedProfileTags = expectedProfile.Values.Select(x => x.Tag).ToList();
List<ExifTag> expectedProfileTags = [.. expectedProfile.Values.Select(x => x.Tag)];
// Act
byte[] actualBytes = expectedProfile.ToByteArray();

4
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<byte>());
ExifReader reader = new([]);
IList<IExifValue> result = reader.ReadValues();
@ -21,7 +21,7 @@ public class ExifReaderTests
[Fact]
public void Read_DataIsMinimal_ReturnsEmptyCollection()
{
ExifReader reader = new(new byte[] { 69, 120, 105, 102, 0, 0 });
ExifReader reader = new([69, 120, 105, 102, 0, 0]);
IList<IExifValue> result = reader.ReadValues();

6
tests/ImageSharp.Tests/Metadata/Profiles/Exif/Values/ExifValuesTests.cs

@ -458,7 +458,7 @@ public class ExifValuesTests
[MemberData(nameof(NumberArrayTags))]
public void ExifNumberArrayTests(ExifTag tag)
{
Number[] expected = [new Number(uint.MaxValue)];
Number[] expected = [new(uint.MaxValue)];
ExifValue value = ExifValues.Create(tag);
Assert.False(value.TrySetValue(expected.ToString()));
@ -496,7 +496,7 @@ public class ExifValuesTests
[MemberData(nameof(RationalArrayTags))]
public void ExifRationalArrayTests(ExifTag tag)
{
Rational[] expected = [new Rational(21, 42)];
Rational[] expected = [new(21, 42)];
ExifValue value = ExifValues.Create(tag);
Assert.False(value.TrySetValue(expected.ToString()));
@ -554,7 +554,7 @@ public class ExifValuesTests
[MemberData(nameof(SignedRationalArrayTags))]
public void ExifSignedRationalArrayTests(ExifTag tag)
{
SignedRational[] expected = [new SignedRational(21, 42)];
SignedRational[] expected = [new(21, 42)];
ExifValue value = ExifValues.Create(tag);
Assert.False(value.TrySetValue(expected.ToString()));

4
tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterPrimitivesTests.cs

@ -42,7 +42,7 @@ public class IccDataWriterPrimitivesTests
byte[] output = writer.GetData();
Assert.Equal(0, count);
Assert.Equal(Array.Empty<byte>(), output);
Assert.Empty(output);
}
[Fact]
@ -62,7 +62,7 @@ public class IccDataWriterPrimitivesTests
byte[] output = writer.GetData();
Assert.Equal(0, count);
Assert.Equal(Array.Empty<byte>(), output);
Assert.Empty(output);
}
[Theory]

18
tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs

@ -116,7 +116,7 @@ public class IptcProfileTests
using (Image<TPixel> image = provider.GetImage(JpegDecoder.Instance))
{
Assert.NotNull(image.Metadata.IptcProfile);
List<IptcValue> iptcValues = image.Metadata.IptcProfile.Values.ToList();
List<IptcValue> iptcValues = [.. image.Metadata.IptcProfile.Values];
IptcProfileContainsExpectedValues(iptcValues);
}
}
@ -130,7 +130,7 @@ public class IptcProfileTests
{
IptcProfile iptc = image.Frames.RootFrame.Metadata.IptcProfile;
Assert.NotNull(iptc);
List<IptcValue> iptcValues = iptc.Values.ToList();
List<IptcValue> iptcValues = [.. iptc.Values];
IptcProfileContainsExpectedValues(iptcValues);
}
}
@ -182,7 +182,7 @@ public class IptcProfileTests
IptcProfile profileFromBytes = new(profileBytes);
// assert
List<IptcValue> iptcValues = profileFromBytes.Values.ToList();
List<IptcValue> iptcValues = [.. profileFromBytes.Values];
ContainsIptcValue(iptcValues, IptcTag.CaptionWriter, expectedCaptionWriter);
ContainsIptcValue(iptcValues, IptcTag.Caption, expectedCaption);
}
@ -203,10 +203,10 @@ public class IptcProfileTests
// assert
Assert.Equal(2, clone.Values.Count());
List<IptcValue> cloneValues = clone.Values.ToList();
List<IptcValue> cloneValues = [.. clone.Values];
ContainsIptcValue(cloneValues, IptcTag.CaptionWriter, captionWriter);
ContainsIptcValue(cloneValues, IptcTag.Caption, "changed");
ContainsIptcValue(profile.Values.ToList(), IptcTag.Caption, caption);
ContainsIptcValue([.. profile.Values], IptcTag.Caption, caption);
}
[Fact]
@ -240,7 +240,7 @@ public class IptcProfileTests
// assert
IptcProfile actual = reloadedImage.Metadata.IptcProfile;
Assert.NotNull(actual);
List<IptcValue> iptcValues = actual.Values.ToList();
List<IptcValue> iptcValues = [.. actual.Values];
ContainsIptcValue(iptcValues, IptcTag.CaptionWriter, expectedCaptionWriter);
ContainsIptcValue(iptcValues, IptcTag.Caption, expectedCaption);
}
@ -272,7 +272,7 @@ public class IptcProfileTests
profile.SetValue(tag, expectedValue2, false);
// assert
List<IptcValue> values = profile.Values.ToList();
List<IptcValue> values = [.. profile.Values];
Assert.Equal(2, values.Count);
ContainsIptcValue(values, tag, expectedValue1);
ContainsIptcValue(values, tag, expectedValue2);
@ -323,7 +323,7 @@ public class IptcProfileTests
profile.SetValue(tag, expectedValue, false);
// assert
List<IptcValue> values = profile.Values.ToList();
List<IptcValue> values = [.. profile.Values];
Assert.Equal(1, values.Count);
ContainsIptcValue(values, tag, expectedValue);
}
@ -357,7 +357,7 @@ public class IptcProfileTests
// assert
Assert.True(result, "removed result should be true");
ContainsIptcValue(profile.Values.ToList(), IptcTag.Byline, "test");
ContainsIptcValue([.. profile.Values], IptcTag.Byline, "test");
}
[Fact]

4
tests/ImageSharp.Tests/PixelFormats/AssociatedAlphaPixelTests.cs

@ -685,8 +685,8 @@ public class AssociatedAlphaPackedPixelConversionTests
foreach (int length in lengths)
{
Vector4[] nativeSource = source.AsSpan(0, length).ToArray();
Vector4[] scaledSource = source.AsSpan(0, length).ToArray();
Vector4[] nativeSource = [.. source.AsSpan(0, length)];
Vector4[] scaledSource = [.. source.AsSpan(0, length)];
TPixel[] expectedNative = new TPixel[length];
TPixel[] expectedScaled = new TPixel[length];
TPixel[] actualNative = new TPixel[length];

12
tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs

@ -1051,9 +1051,9 @@ public class PixelBlenderTests
private static Rgba32P BlendWithCoverageScalar(PixelBlender<Rgba32P> blender, Rgba32P background, Rgba32P source, float amount, float coverage)
{
Span<Rgba32P> destination = stackalloc Rgba32P[1];
Span<Rgba32P> backgroundSpan = stackalloc Rgba32P[1] { background };
Span<Rgba32P> sourceSpan = stackalloc Rgba32P[1] { source };
Span<float> coverageSpan = stackalloc float[1] { coverage };
Span<Rgba32P> backgroundSpan = [background];
Span<Rgba32P> sourceSpan = [source];
Span<float> coverageSpan = [coverage];
Span<Vector4> buffer = stackalloc Vector4[3];
// A one-pixel span takes the scalar remainder path, providing an exact oracle for each SIMD coverage result.
@ -1161,9 +1161,9 @@ public class PixelBlenderTests
where TPixel : unmanaged, IPixel<TPixel>
{
Span<TPixel> destination = stackalloc TPixel[1];
Span<TPixel> backgroundSpan = stackalloc TPixel[1] { background };
Span<TPixel> sourceSpan = stackalloc TPixel[1] { source };
Span<float> coverageSpan = stackalloc float[1] { coverage };
Span<TPixel> backgroundSpan = [background];
Span<TPixel> sourceSpan = [source];
Span<float> coverageSpan = [coverage];
Span<Vector4> buffer = stackalloc Vector4[3];
blender.BlendWithCoverage<TPixel>(Configuration.Default, destination, backgroundSpan, sourceSpan, amount, coverageSpan, buffer);

2
tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTestsTPixel.cs

@ -14,7 +14,7 @@ public class PorterDuffFunctionsTestsTPixel
private static Span<T> AsSpan<T>(T value)
where T : struct
{
return new Span<T>(new[] { value });
return new Span<T>([value]);
}
private static T[] CreateFilledArray<T>(T value)

4
tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs

@ -736,7 +736,7 @@ public abstract class PixelOperationsTests<TPixel> : MeasureFixture
public void FromL8(int count)
{
byte[] sourceBytes = CreateByteTestData(count);
L8[] source = sourceBytes.Select(b => new L8(b)).ToArray();
L8[] source = [.. sourceBytes.Select(b => new L8(b))];
TPixel[] expected = new TPixel[count];
for (int i = 0; i < count; i++)
@ -772,7 +772,7 @@ public abstract class PixelOperationsTests<TPixel> : MeasureFixture
[MemberData(nameof(ArraySizesData))]
public void FromL16(int count)
{
L16[] source = CreateVector4TestData(count).Select(L16.FromVector4).ToArray();
L16[] source = [.. CreateVector4TestData(count).Select(L16.FromVector4)];
TPixel[] expected = new TPixel[count];

4
tests/ImageSharp.Tests/Processing/Convolution/KernelSamplingMapTest.cs

@ -411,9 +411,9 @@ public class KernelSamplingMapTest
map.BuildSamplingOffsetMap(kernelSize.Height, kernelSize.Width, bounds, xBorderMode, yBorderMode);
// Assert
int[] xOffsets = map.GetColumnOffsetSpan().ToArray();
int[] xOffsets = [.. map.GetColumnOffsetSpan()];
Assert.Equal(xExpected, xOffsets);
int[] yOffsets = map.GetRowOffsetSpan().ToArray();
int[] yOffsets = [.. map.GetRowOffsetSpan()];
Assert.Equal(yExpected, yOffsets);
}
}

20
tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs

@ -47,18 +47,20 @@ public class BokehBlurTest
public void VerifyComplexComponents()
{
// Get the saved components
List<Complex64[]> components = new();
List<Complex64[]> 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);
}

8
tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs

@ -82,8 +82,8 @@ public class PaletteQuantizerTests
{
Rgba32[] palette =
[
new Rgba32(0, 0, 0),
new Rgba32(7, 0, 0)
new(0, 0, 0),
new(7, 0, 0)
];
using PixelMap<Rgba32> exact = CreatePixelMap<UncachedCache>(palette);
@ -152,7 +152,7 @@ public class PaletteQuantizerTests
byte r = (byte)((i & 31) << 3);
byte g = (byte)(((i >> 5) & 31) << 3);
byte b = (byte)(((i >> 10) & 31) << 3);
return new(r, g, b);
return new Rgba32(r, g, b);
}
// Reconstruct the same 5-bit RGB bucket coordinates used by CreateEvictionFillerColor, then set the
@ -163,7 +163,7 @@ public class PaletteQuantizerTests
byte r = (byte)(((i & 31) << 3) | 0x07);
byte g = (byte)((((i >> 5) & 31) << 3) | 0x07);
byte b = (byte)((((i >> 10) & 31) << 3) | 0x07);
return new(r, g, b);
return new Rgba32(r, g, b);
}
private static PixelMap<Rgba32> CreatePixelMap<TCache>(Rgba32[] palette)

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs

@ -35,7 +35,7 @@ public class CropTest
{
using Image<TPixel> 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]);

4
tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs

@ -50,7 +50,7 @@ public class FlipTests
{
using Image<TPixel> image = provider.GetImage();
image.Metadata.ExifProfile = new();
image.Metadata.ExifProfile = new ExifProfile();
image.Metadata.ExifProfile.SetValue(ExifTag.SubjectLocation, [5, 15]);
image.Metadata.ExifProfile.SetValue(ExifTag.SubjectArea, [5, 15, 50, 50]);
@ -79,7 +79,7 @@ public class FlipTests
{
using Image<TPixel> 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]);

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/ProjectiveTransformTests.cs

@ -239,7 +239,7 @@ public class ProjectiveTransformTests
{
using Image<TPixel> 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]);

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.ReferenceKernelMap.cs

@ -97,6 +97,6 @@ public partial class ResizeKernelMapTests
public int Length => this.Values.Length;
public static implicit operator ReferenceKernel(ResizeKernel orig)
=> new(orig.StartIndex, orig.Values.ToArray());
=> new(orig.StartIndex, [.. orig.Values]);
}
}

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs

@ -119,7 +119,7 @@ public partial class ResizeKernelMapTests
this.Output.WriteLine($"Actual KernelMap:\n{PrintKernelMap(kernelMap)}\n");
#endif
ApproximateFloatComparer comparer = new ApproximateFloatComparer(1e-6f);
ApproximateFloatComparer comparer = new(1e-6f);
for (int i = 0; i < kernelMap.DestinationLength; i++)
{
ResizeKernel kernel = kernelMap.GetKernel((uint)i);

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

@ -720,7 +720,7 @@ public class ResizeTests
{
using Image<TPixel> 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]);

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs

@ -48,7 +48,7 @@ public class RotateTests
{
using Image<TPixel> 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]);

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs

@ -60,7 +60,7 @@ public class SwizzleTests
{
using Image<TPixel> 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]);

4
tests/ImageSharp.Tests/Quantization/AlphaAssociationQuantizerTests.cs

@ -68,8 +68,8 @@ public class AlphaAssociationQuantizerTests
{
Rgba32[] source =
[
new Rgba32(255, 255, 255, below),
new Rgba32(255, 255, 255, retained)
new(255, 255, 255, below),
new(255, 255, 255, retained)
];
QuantizerOptions options = new()

45
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 }]
];
}

8
tests/ImageSharp.Tests/TestFontUtilities.cs

@ -45,10 +45,10 @@ public static class TestFontUtilities
"../../../../TestFonts/"
];
directories = directories.SelectMany(x => new[]
{
Path.GetFullPath(x)
}).ToList();
directories =
[
.. directories.SelectMany(x => new[] { Path.GetFullPath(x) })
];
AddFormatsDirectoryFromTestAssemblyPath(directories);

7
tests/ImageSharp.Tests/TestFormat.cs

@ -61,7 +61,7 @@ public class TestFormat : IImageFormatConfigurationModule, IImageFormat
public void VerifySpecificDecodeCall<TPixel>(byte[] marker, Configuration config)
where TPixel : unmanaged, IPixel<TPixel>
{
DecodeOperation[] discovered = this.DecodeCalls.Where(x => x.IsMatch(marker, config, typeof(TPixel))).ToArray();
DecodeOperation[] discovered = [.. this.DecodeCalls.Where(x => x.IsMatch(marker, config, typeof(TPixel)))];
Assert.True(discovered.Length > 0, "No calls to decode on this format with the provided options happened");
@ -73,7 +73,8 @@ public class TestFormat : IImageFormatConfigurationModule, IImageFormat
public void VerifyAgnosticDecodeCall(byte[] marker, Configuration config)
{
DecodeOperation[] discovered = this.DecodeCalls.Where(x => x.IsMatch(marker, config, typeof(TestPixelForAgnosticDecode))).ToArray();
DecodeOperation[] discovered =
[.. this.DecodeCalls.Where(x => x.IsMatch(marker, config, typeof(TestPixelForAgnosticDecode)))];
Assert.True(discovered.Length > 0, "No calls to decode on this format with the provided options happened");
@ -219,7 +220,7 @@ public class TestFormat : IImageFormatConfigurationModule, IImageFormat
Configuration configuration = options.GeneralOptions.Configuration;
using MemoryStream ms = new();
stream.CopyTo(ms, configuration.StreamProcessingBufferSize);
byte[] marker = ms.ToArray().Skip(this.testFormat.header.Length).ToArray();
byte[] marker = [.. ms.ToArray().Skip(this.testFormat.header.Length)];
this.testFormat.DecodeCalls.Add(new DecodeOperation
{
Marker = marker,

2
tests/ImageSharp.Tests/TestImages.cs

@ -409,7 +409,7 @@ public static class TestImages
}
}
public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray();
public static readonly string[] All = [.. Baseline.All, .. Progressive.All];
public static class BenchmarkSuite
{

4
tests/ImageSharp.Tests/TestUtilities/ByteBuffer.cs

@ -8,7 +8,7 @@ using System.Collections.Generic;
public class ByteBuffer
{
private readonly List<byte> bytes = new();
private readonly List<byte> bytes = [];
private readonly bool isLittleEndian;
public ByteBuffer(bool isLittleEndian)
@ -33,6 +33,6 @@ public class ByteBuffer
public byte[] ToArray()
{
return this.bytes.ToArray();
return [.. this.bytes];
}
}

2
tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDifferenceIsOverThresholdException.cs

@ -12,7 +12,7 @@ public class ImageDifferenceIsOverThresholdException : ImagesSimilarityException
public ImageDifferenceIsOverThresholdException(IEnumerable<ImageSimilarityReport> reports)
: base("Image difference is over threshold!" + StringifyReports(reports))
=> this.Reports = reports.ToArray();
=> this.Reports = [.. reports];
private static string StringifyReports(IEnumerable<ImageSimilarityReport> reports)
{

2
tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs

@ -19,7 +19,7 @@ public class ImageSimilarityReport
this.ExpectedImage = expectedImage;
this.ActualImage = actualImage;
this.TotalNormalizedDifference = totalNormalizedDifference;
this.Differences = differences.ToArray();
this.Differences = [.. differences];
}
public int Index { get; }

23
tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs

@ -217,12 +217,15 @@ public class ImagingTestCaseUtility
{
encoder ??= TestEnvironment.GetReferenceEncoder($"foo.{extension}");
(int Index, string FileName)[] files = this.GetTestOutputFileNamesMultiFrame(
image.Frames.Count,
extension,
testOutputDetails,
appendPixelTypeToFileName,
predicate: predicate).ToArray();
(int Index, string FileName)[] files =
[
.. this.GetTestOutputFileNamesMultiFrame(
image.Frames.Count,
extension,
testOutputDetails,
appendPixelTypeToFileName,
predicate: predicate)
];
foreach ((int Index, string FileName) file in files)
{
@ -249,8 +252,12 @@ public class ImagingTestCaseUtility
object testOutputDetails,
bool appendPixelTypeToFileName = true,
Func<int, int, bool> 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)
{

2
tests/ImageSharp.Tests/TestUtilities/ScaledRgbaVectorP.cs

@ -84,7 +84,7 @@ internal struct ScaledRgbaVectorP : IPixel<ScaledRgbaVectorP>
Numerics.UnPremultiply(ref source);
source = Numerics.Clamp(source, Vector4.Zero, Vector4.One);
Numerics.Premultiply(ref source);
return new(source);
return new ScaledRgbaVectorP(source);
}
/// <inheritdoc />

4
tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs

@ -33,8 +33,8 @@ internal class TestMemoryAllocator : MemoryAllocator
public void EnableNonThreadSafeLogging()
{
this.allocationLog = new List<AllocationRequest>();
this.returnLog = new List<ReturnRequest>();
this.allocationLog = [];
this.returnLog = [];
}
protected override AllocationTrackedMemoryManager<T> AllocateCore<T>(int length, AllocationOptions options = AllocationOptions.None)

18
tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

@ -25,9 +25,11 @@ public static class TestUtils
private static readonly Dictionary<PixelTypes, Type> PixelTypes2ClrTypes = new();
private static readonly PixelTypes[] AllConcretePixelTypes = GetAllPixelTypes()
.Except([PixelTypes.Undefined, PixelTypes.All])
.ToArray();
private static readonly PixelTypes[] AllConcretePixelTypes =
[
.. GetAllPixelTypes()
.Except([PixelTypes.Undefined, PixelTypes.All])
];
static TestUtils()
{
@ -401,9 +403,11 @@ public static class TestUtils
public static string[] GetAllResamplerNames(bool includeNearestNeighbour = true)
{
return typeof(KnownResamplers).GetProperties(BindingFlags.Public | BindingFlags.Static)
.Select(p => p.Name)
.Where(name => includeNearestNeighbour || name != nameof(KnownResamplers.NearestNeighbor))
.ToArray();
return
[
.. typeof(KnownResamplers).GetProperties(BindingFlags.Public | BindingFlags.Static)
.Select(p => p.Name)
.Where(name => includeNearestNeighbour || name != nameof(KnownResamplers.NearestNeighbor))
];
}
}

2
tests/ImageSharp.Tests/TestUtilities/Tests/FeatureTestRunnerTests.cs

@ -24,7 +24,7 @@ public class FeatureTestRunnerTests
public void ToFeatureCollectionReturnsExpectedResult(HwIntrinsics expectedIntrinsics, string[] expectedValues)
{
Dictionary<HwIntrinsics, string> features = expectedIntrinsics.ToFeatureKeyValueCollection();
HwIntrinsics[] keys = features.Keys.ToArray();
HwIntrinsics[] keys = [.. features.Keys];
HwIntrinsics actualIntrinsics = keys[0];
for (int i = 1; i < keys.Length; i++)

2
tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

@ -119,7 +119,7 @@ public class TestUtilityExtensionsTests
[Fact]
public void ToTypes_All()
{
KeyValuePair<PixelTypes, Type>[] expanded = PixelTypes.All.ExpandAllTypes().ToArray();
KeyValuePair<PixelTypes, Type>[] expanded = [.. PixelTypes.All.ExpandAllTypes()];
Assert.True(expanded.Length >= TestUtils.GetAllPixelTypes().Length - 2);
AssertContainsPixelType<Rgba32>(PixelTypes.Rgba32, expanded);

Loading…
Cancel
Save