From f3c3cb6413a462a9a8abf02839d72d82209ca475 Mon Sep 17 00:00:00 2001 From: Evangelink Date: Fri, 16 Oct 2020 11:14:19 +0200 Subject: [PATCH 01/39] wip - Add basic structure for the swizzler --- .../Transforms/SwizzleExtensions.cs | 24 ++++++++++++++ .../Processors/Transforms/ISwizzler.cs | 18 ++++++++++ .../SwizzleProcessor{TSwizzler,TPixel}.cs | 33 +++++++++++++++++++ .../Transforms/SwizzleProcessor{TSwizzler}.cs | 32 ++++++++++++++++++ .../Processing/Transforms/SwizzleTests.cs | 31 +++++++++++++++++ 5 files changed, 138 insertions(+) create mode 100644 src/ImageSharp/Processing/Extensions/Transforms/SwizzleExtensions.cs create mode 100644 src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs create mode 100644 src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs create mode 100644 src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler}.cs create mode 100644 tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs diff --git a/src/ImageSharp/Processing/Extensions/Transforms/SwizzleExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/SwizzleExtensions.cs new file mode 100644 index 000000000..c02b3a00d --- /dev/null +++ b/src/ImageSharp/Processing/Extensions/Transforms/SwizzleExtensions.cs @@ -0,0 +1,24 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Processing.Processors.Transforms; + +namespace SixLabors.ImageSharp.Processing.Extensions.Transforms +{ + /// + /// Defines extensions that allow the application of swizzle operations on an + /// + public static class SwizzleExtensions + { + /// + /// Swizzles an image. + /// + /// The image to swizzle. + /// The swizzler function. + /// The swizzler function type. + /// The to allow chaining of operations. + public static IImageProcessingContext Swizzle(this IImageProcessingContext source, TSwizzler swizzler) + where TSwizzler : struct, ISwizzler + => source.ApplyProcessor(new SwizzleProcessor(swizzler)); + } +} diff --git a/src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs b/src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs new file mode 100644 index 000000000..0230b7a86 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs @@ -0,0 +1,18 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.Processing.Processors.Transforms +{ + /// + /// Encapsulate an algorithm to swizzle pixels in an image. + /// + public interface ISwizzler + { + /// + /// Applies the swizzle transformation to a given point. + /// + /// Point to transform. + /// Transformed point. + Point Transform(Point point); + } +} diff --git a/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs new file mode 100644 index 000000000..a42a4bf77 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs @@ -0,0 +1,33 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Processors.Transforms +{ + internal class SwizzleProcessor : ImageProcessor + where TSwizzler : struct, ISwizzler + where TPixel : unmanaged, IPixel + { + private readonly TSwizzler swizzler; + + public SwizzleProcessor(Configuration configuration, TSwizzler swizzler, Image source, Rectangle sourceRectangle) + : base(configuration, source, sourceRectangle) + { + this.swizzler = swizzler; + } + + /// + protected override void OnFrameApply(ImageFrame source) + { + for (int y = 0; y < source.Height; y++) + { + var pixelRowSpan = source.GetPixelRowSpan(y); + for (int x = 0; x < source.Width; x++) + { + var newPoint = this.swizzler.Transform(new Point(x, y)); + } + } + } + } +} diff --git a/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler}.cs b/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler}.cs new file mode 100644 index 000000000..e5b95e673 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler}.cs @@ -0,0 +1,32 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Processors.Transforms +{ + /// + /// Defines a swizzle operation on an image. + /// + /// The swizzle function type. + public sealed class SwizzleProcessor : IImageProcessor + where TSwizzler : struct, ISwizzler + { + /// + /// Initializes a new instance of the class. + /// + /// The swizzler operation. + public SwizzleProcessor(TSwizzler swizzler) + => this.Swizzler = swizzler; + + /// + /// Gets the swizzler operation. + /// + public TSwizzler Swizzler { get; } + + /// + public IImageProcessor CreatePixelSpecificProcessor(Configuration configuration, Image source, Rectangle sourceRectangle) + where TPixel : unmanaged, IPixel + => new SwizzleProcessor(configuration, this, source, sourceRectangle); + } +} diff --git a/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs new file mode 100644 index 000000000..2862df212 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs @@ -0,0 +1,31 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Processing.Extensions.Transforms; +using SixLabors.ImageSharp.Processing.Processors.Transforms; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Transforms +{ + public class SwizzleTests : BaseImageOperationsExtensionTest + { + private struct InvertXAndYSwizzler : ISwizzler + { + public Point Transform(Point point) => new Point(point.Y, point.X); + } + + [Fact] + public void RotateDegreesFloatRotateProcessorWithAnglesSet() + { + this.operations.Swizzle(default(InvertXAndYSwizzler)); + SwizzleProcessor processor = this.Verify>(); + + // assert that pixels have been changed + + this.operations.Swizzle(default(InvertXAndYSwizzler)); + SwizzleProcessor processor2 = this.Verify>(); + + // assert that pixels have been changed (i.e. back to original) + } + } +} From 6a3411ed6bc309f26843abdcfb6965005f22338c Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 8 Nov 2020 19:48:05 +0000 Subject: [PATCH 02/39] Add new property and implement for TPixel types --- src/ImageSharp/Formats/PixelTypeInfo.cs | 19 +- src/ImageSharp/ImageSharp.csproj | 88 ++- .../PixelFormats/PixelAlphaRepresentation.cs | 32 + .../PixelFormats/PixelImplementations/A8.cs | 4 +- .../PixelImplementations/Bgr565.cs | 4 +- .../PixelImplementations/Bgra4444.cs | 4 +- .../PixelImplementations/Byte4.cs | 4 +- .../PixelImplementations/HalfSingle.cs | 4 +- .../PixelImplementations/HalfVector2.cs | 6 +- .../PixelImplementations/HalfVector4.cs | 4 +- .../PixelImplementations/NormalizedByte2.cs | 4 +- .../PixelImplementations/NormalizedByte4.cs | 4 +- .../PixelImplementations/NormalizedShort2.cs | 4 +- .../PixelImplementations/NormalizedShort4.cs | 4 +- .../PixelOperations/A8.PixelOperations.cs | 22 + .../PixelOperations/Bgr565.PixelOperations.cs | 22 + .../Bgra4444.PixelOperations.cs | 22 + .../PixelOperations/Byte4.PixelOperations.cs | 22 + .../Argb32.PixelOperations.Generated.cs | 64 +- .../Argb32.PixelOperations.Generated.tt | 4 +- .../Bgr24.PixelOperations.Generated.cs | 64 +- .../Bgr24.PixelOperations.Generated.tt | 4 +- .../Bgra32.PixelOperations.Generated.cs | 64 +- .../Bgra32.PixelOperations.Generated.tt | 4 +- .../Bgra5551.PixelOperations.Generated.cs | 66 +- .../Bgra5551.PixelOperations.Generated.tt | 2 +- .../L16.PixelOperations.Generated.cs | 68 +- .../L16.PixelOperations.Generated.tt | 4 +- .../Generated/L8.PixelOperations.Generated.cs | 68 +- .../Generated/L8.PixelOperations.Generated.tt | 4 +- .../La16.PixelOperations.Generated.cs | 66 +- .../La16.PixelOperations.Generated.tt | 2 +- .../La32.PixelOperations.Generated.cs | 66 +- .../La32.PixelOperations.Generated.tt | 2 +- .../Rgb24.PixelOperations.Generated.cs | 63 +- .../Rgb24.PixelOperations.Generated.tt | 4 +- .../Rgb48.PixelOperations.Generated.cs | 68 +- .../Rgb48.PixelOperations.Generated.tt | 4 +- .../Rgba32.PixelOperations.Generated.cs | 52 +- .../Rgba32.PixelOperations.Generated.tt | 4 +- .../Rgba64.PixelOperations.Generated.cs | 68 +- .../Rgba64.PixelOperations.Generated.tt | 4 +- .../Generated/_Common.ttinclude | 101 ++- .../HalfSingle.PixelOperations.cs | 22 + .../HalfVector2.PixelOperations.cs | 22 + .../HalfVector4.PixelOperations.cs | 22 + .../NormalizedByte2.PixelOperations.cs | 22 + .../NormalizedByte4.PixelOperations.cs | 22 + .../NormalizedShort2.PixelOperations.cs | 22 + .../NormalizedShort4.PixelOperations.cs | 22 + .../PixelOperations/Rg32.PixelOperations.cs | 22 + .../Rgba1010102.PixelOperations.cs | 22 + .../Rgba32.PixelOperations.cs | 0 .../RgbaVector.PixelOperations.cs | 15 +- .../PixelOperations/Short2.PixelOperations.cs | 22 + .../PixelOperations/Short4.PixelOperations.cs | 22 + .../PixelFormats/PixelImplementations/Rg32.cs | 4 +- .../PixelImplementations/Rgba1010102.cs | 4 +- .../PixelImplementations/Short2.cs | 4 +- .../PixelImplementations/Short4.cs | 4 +- .../PixelFormats/PixelOperations{TPixel}.cs | 47 +- .../Program.cs | 2 +- .../ImageSharp.Tests/ImageSharp.Tests.csproj | 24 + ...elOperationsTests.Specialized.Generated.cs | 718 ++++++++++++++++++ ...elOperationsTests.Specialized.Generated.tt | 11 + .../Generated/_Common.ttinclude | 117 +++ ...elOperationsTests.Argb32OperationsTests.cs | 24 - ...xelOperationsTests.Bgr24OperationsTests.cs | 25 - ...elOperationsTests.Bgra32OperationsTests.cs | 24 - ...OperationsTests.Bgra5551OperationsTests.cs | 20 - ...PixelOperationsTests.L16OperationsTests.cs | 24 - .../PixelOperationsTests.L8OperationsTests.cs | 24 - ...ixelOperationsTests.La16OperationsTests.cs | 24 - ...ixelOperationsTests.La32OperationsTests.cs | 24 - ...xelOperationsTests.Rgb24OperationsTests.cs | 24 - ...xelOperationsTests.Rgb48OperationsTests.cs | 24 - ...elOperationsTests.Rgba32OperationsTests.cs | 17 +- ...elOperationsTests.Rgba64OperationsTests.cs | 24 - ...erationsTests.RgbaVectorOperationsTests.cs | 24 - tests/Images/External | 2 +- 80 files changed, 2108 insertions(+), 581 deletions(-) create mode 100644 src/ImageSharp/PixelFormats/PixelAlphaRepresentation.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Argb32.PixelOperations.Generated.cs (86%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Argb32.PixelOperations.Generated.tt (84%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Bgr24.PixelOperations.Generated.cs (86%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Bgr24.PixelOperations.Generated.tt (84%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Bgra32.PixelOperations.Generated.cs (86%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Bgra32.PixelOperations.Generated.tt (84%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Bgra5551.PixelOperations.Generated.cs (80%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Bgra5551.PixelOperations.Generated.tt (90%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/L16.PixelOperations.Generated.cs (80%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/L16.PixelOperations.Generated.tt (84%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/L8.PixelOperations.Generated.cs (80%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/L8.PixelOperations.Generated.tt (84%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/La16.PixelOperations.Generated.cs (80%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/La16.PixelOperations.Generated.tt (91%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/La32.PixelOperations.Generated.cs (80%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/La32.PixelOperations.Generated.tt (91%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Rgb24.PixelOperations.Generated.cs (86%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Rgb24.PixelOperations.Generated.tt (84%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Rgb48.PixelOperations.Generated.cs (80%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Rgb48.PixelOperations.Generated.tt (84%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Rgba32.PixelOperations.Generated.cs (88%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Rgba32.PixelOperations.Generated.tt (84%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Rgba64.PixelOperations.Generated.cs (80%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/Rgba64.PixelOperations.Generated.tt (84%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Generated/_Common.ttinclude (71%) create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/Rgba32.PixelOperations.cs (100%) rename src/ImageSharp/PixelFormats/PixelImplementations/{ => PixelOperations}/RgbaVector.PixelOperations.cs (84%) create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs create mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs create mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.tt create mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Argb32OperationsTests.cs delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgr24OperationsTests.cs delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgra32OperationsTests.cs delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgra5551OperationsTests.cs delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.L16OperationsTests.cs delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.L8OperationsTests.cs delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.La16OperationsTests.cs delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.La32OperationsTests.cs delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgb24OperationsTests.cs delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgb48OperationsTests.cs delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgba64OperationsTests.cs delete mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.RgbaVectorOperationsTests.cs diff --git a/src/ImageSharp/Formats/PixelTypeInfo.cs b/src/ImageSharp/Formats/PixelTypeInfo.cs index d53d496fa..718b05e33 100644 --- a/src/ImageSharp/Formats/PixelTypeInfo.cs +++ b/src/ImageSharp/Formats/PixelTypeInfo.cs @@ -1,8 +1,7 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. using System.Runtime.CompilerServices; - using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats @@ -16,9 +15,11 @@ namespace SixLabors.ImageSharp.Formats /// Initializes a new instance of the class. /// /// Color depth, in number of bits per pixel. - internal PixelTypeInfo(int bitsPerPixel) + /// Tthe pixel alpha transparency behavior. + internal PixelTypeInfo(int bitsPerPixel, PixelAlphaRepresentation? alpha = null) { this.BitsPerPixel = bitsPerPixel; + this.AlphaRepresentation = alpha; } /// @@ -26,8 +27,20 @@ namespace SixLabors.ImageSharp.Formats /// public int BitsPerPixel { get; } + /// + /// Gets the pixel alpha transparency behavior. + /// means unknown, unspecified. + /// + public PixelAlphaRepresentation? AlphaRepresentation { get; } + internal static PixelTypeInfo Create() where TPixel : unmanaged, IPixel => new PixelTypeInfo(Unsafe.SizeOf() * 8); + + internal static PixelTypeInfo Create(PixelAlphaRepresentation alpha) + where TPixel : unmanaged, IPixel + { + return new PixelTypeInfo(Unsafe.SizeOf() * 8, alpha); + } } } diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index c3d9618c8..258deb44f 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -62,62 +62,102 @@ True PixelOperations{TPixel}.Generated.tt - + + True + True + A8.PixelOperations.Generated.tt + + True True Argb32.PixelOperations.Generated.tt - + True True Bgr24.PixelOperations.Generated.tt - + + True + True + Bgr565.PixelOperations.Generated.tt + + True True Bgra32.PixelOperations.Generated.tt - + + True + True + Bgra4444.PixelOperations.Generated.tt + + True True Bgra5551.PixelOperations.Generated.tt - + + True + True + Byte4.PixelOperations.Generated.tt + + + True + True + HalfSingle.PixelOperations.Generated.tt + + + True + True + HalfVector2.PixelOperations.Generated.tt + + + True + True + HalfVector4.PixelOperations.Generated.tt + + True True L8.PixelOperations.Generated.tt - + True True L16.PixelOperations.Generated.tt - + True True La16.PixelOperations.Generated.tt - + True True La32.PixelOperations.Generated.tt - + True True Rgb24.PixelOperations.Generated.tt - + + True + True + Rg32.PixelOperations.Generated.tt + + True True Rgba32.PixelOperations.Generated.tt - + True True Rgb48.PixelOperations.Generated.tt - + True True Rgba64.PixelOperations.Generated.tt @@ -156,51 +196,51 @@ TextTemplatingFileGenerator PixelOperations{TPixel}.Generated.cs - + TextTemplatingFileGenerator Argb32.PixelOperations.Generated.cs - + TextTemplatingFileGenerator Bgr24.PixelOperations.Generated.cs - + TextTemplatingFileGenerator Bgra32.PixelOperations.Generated.cs - + TextTemplatingFileGenerator Bgra5551.PixelOperations.Generated.cs - + TextTemplatingFileGenerator L8.PixelOperations.Generated.cs - + TextTemplatingFileGenerator L16.PixelOperations.Generated.cs - + TextTemplatingFileGenerator La16.PixelOperations.Generated.cs - + TextTemplatingFileGenerator La32.PixelOperations.Generated.cs - + TextTemplatingFileGenerator Rgb24.PixelOperations.Generated.cs - + TextTemplatingFileGenerator Rgba32.PixelOperations.Generated.cs - + TextTemplatingFileGenerator Rgb48.PixelOperations.Generated.cs - + TextTemplatingFileGenerator Rgba64.PixelOperations.Generated.cs diff --git a/src/ImageSharp/PixelFormats/PixelAlphaRepresentation.cs b/src/ImageSharp/PixelFormats/PixelAlphaRepresentation.cs new file mode 100644 index 000000000..4690fb66a --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelAlphaRepresentation.cs @@ -0,0 +1,32 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides enumeration of the alpha value transparency behavior of a pixel format. + /// + public enum PixelAlphaRepresentation + { + /// + /// Indicates that the pixel format does not contain an alpha channel. + /// + None, + + /// + /// Indicates that the transparency behavior is premultiplied. + /// Each color is first scaled by the alpha value. The alpha value itself is the same + /// in both straight and premultiplied alpha. Typically, no color channel value is + /// greater than the alpha channel value. + /// If a color channel value in a premultiplied format is greater than the alpha + /// channel, the standard source-over blending math results in an additive blend. + /// + Associated, + + /// + /// Indicates that the transparency behavior is not premultiplied. + /// The alpha channel indicates the transparency of the color. + /// + Unassociated + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs index b19c35a0a..fc0723e9a 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [0, 0, 0, 0] to [0, 0, 0, 1] in vector form. /// /// - public struct A8 : IPixel, IPackedVector + public partial struct A8 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(A8 left, A8 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs index 21ec24a6e..fd12b6837 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [0, 0, 0, 1] to [1, 1, 1, 1] in vector form. /// /// - public struct Bgr565 : IPixel, IPackedVector + public partial struct Bgr565 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(Bgr565 left, Bgr565 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs index b2af3045a..c8d2a82a8 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form. /// /// - public struct Bgra4444 : IPixel, IPackedVector + public partial struct Bgra4444 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(Bgra4444 left, Bgra4444 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs index 9c5289b86..ad22a5aa1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [0, 0, 0, 0] to [255, 255, 255, 255] in vector form. /// /// - public struct Byte4 : IPixel, IPackedVector + public partial struct Byte4 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(Byte4 left, Byte4 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs index e3e6e1383..5c4aa1cfb 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [-1, 0, 0, 1] to [1, 0, 0, 1] in vector form. /// /// - public struct HalfSingle : IPixel, IPackedVector + public partial struct HalfSingle : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(HalfSingle left, HalfSingle right) => !left.Equals(right); /// - public PixelOperations CreatePixelOperations() => new PixelOperations(); + public PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs index 43380eac0..39cb6f799 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [-1, -1, 0, 1] to [1, 1, 0, 1] in vector form. /// /// - public struct HalfVector2 : IPixel, IPackedVector + public partial struct HalfVector2 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. @@ -54,13 +54,13 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(HalfVector2 left, HalfVector2 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] public void FromScaledVector4(Vector4 vector) { - var scaled = new Vector2(vector.X, vector.Y) * 2F; + Vector2 scaled = new Vector2(vector.X, vector.Y) * 2F; scaled -= Vector2.One; this.PackedValue = Pack(scaled.X, scaled.Y); } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs index cb1ae1f40..9826d61a2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [-1, -1, -1, -1] to [1, 1, 1, 1] in vector form. /// /// - public struct HalfVector4 : IPixel, IPackedVector + public partial struct HalfVector4 : IPixel, IPackedVector { /// /// Initializes a new instance of the struct. @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(HalfVector4 left, HalfVector4 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs index 70098b666..8b244d391 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [-1, -1, 0, 1] to [1, 1, 0, 1] in vector form. /// /// - public struct NormalizedByte2 : IPixel, IPackedVector + public partial struct NormalizedByte2 : IPixel, IPackedVector { private static readonly Vector2 Half = new Vector2(127); private static readonly Vector2 MinusOne = new Vector2(-1F); @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(NormalizedByte2 left, NormalizedByte2 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs index 2762073aa..1b2ce0904 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [-1, -1, -1, -1] to [1, 1, 1, 1] in vector form. /// /// - public struct NormalizedByte4 : IPixel, IPackedVector + public partial struct NormalizedByte4 : IPixel, IPackedVector { private static readonly Vector4 Half = new Vector4(127); private static readonly Vector4 MinusOne = new Vector4(-1F); @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(NormalizedByte4 left, NormalizedByte4 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs index 8eaec1411..97bbc1206 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [-1, -1, 0, 1] to [1, 1, 0, 1] in vector form. /// /// - public struct NormalizedShort2 : IPixel, IPackedVector + public partial struct NormalizedShort2 : IPixel, IPackedVector { private static readonly Vector2 Max = new Vector2(0x7FFF); private static readonly Vector2 Min = Vector2.Negate(Max); @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(NormalizedShort2 left, NormalizedShort2 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs index ce7c0035f..1a5c89174 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [-1, -1, -1, -1] to [1, 1, 1, 1] in vector form. /// /// - public struct NormalizedShort4 : IPixel, IPackedVector + public partial struct NormalizedShort4 : IPixel, IPackedVector { private static readonly Vector4 Max = new Vector4(0x7FFF); private static readonly Vector4 Min = Vector4.Negate(Max); @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(NormalizedShort4 left, NormalizedShort4 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs new file mode 100644 index 000000000..48c2e145a --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct A8 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs new file mode 100644 index 000000000..d62761c61 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Bgr565 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs new file mode 100644 index 000000000..82113299b --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Bgra4444 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs new file mode 100644 index 000000000..73411a973 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Byte4 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs similarity index 86% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs index d30616997..ce72eba81 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs @@ -1,15 +1,14 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + /// public override void FromArgb32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -42,16 +45,25 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void FromVector4Destructive(Configuration configuration, Span sourceVectors, Span destinationPixels, PixelConversionModifiers modifiers) + public override void FromVector4Destructive( + Configuration configuration, + Span sourceVectors, + Span destinationPixels, + PixelConversionModifiers modifiers) { Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale)); } /// - public override void ToVector4(Configuration configuration, ReadOnlySpan sourcePixels, Span destVectors, PixelConversionModifiers modifiers) + public override void ToVector4( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destVectors, + PixelConversionModifiers modifiers) { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); } + /// public override void ToRgba32( Configuration configuration, @@ -79,6 +91,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToArgb32(source, dest); } + /// public override void ToBgra32( Configuration configuration, @@ -106,6 +119,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToArgb32(source, dest); } + /// public override void ToRgb24( Configuration configuration, @@ -133,6 +147,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToArgb32(source, dest); } + /// public override void ToBgr24( Configuration configuration, @@ -162,7 +177,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -180,7 +198,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -198,7 +219,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -216,7 +240,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -234,7 +261,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb48(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -252,7 +282,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba64(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -270,7 +303,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -286,6 +322,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } + /// public override void From( Configuration configuration, @@ -294,6 +331,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToArgb32(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.tt similarity index 84% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.tt index 3a4c7b459..1854bcd41 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ -<#@include file="_Common.ttinclude" #> +<#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("Argb32"); #> <# GenerateAllDefaultConversionMethods("Argb32"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs similarity index 86% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs index 50d4942ec..7b15a2611 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs @@ -1,15 +1,14 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + /// public override void FromBgr24(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -42,16 +45,25 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void FromVector4Destructive(Configuration configuration, Span sourceVectors, Span destinationPixels, PixelConversionModifiers modifiers) + public override void FromVector4Destructive( + Configuration configuration, + Span sourceVectors, + Span destinationPixels, + PixelConversionModifiers modifiers) { Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } /// - public override void ToVector4(Configuration configuration, ReadOnlySpan sourcePixels, Span destVectors, PixelConversionModifiers modifiers) + public override void ToVector4( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destVectors, + PixelConversionModifiers modifiers) { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } + /// public override void ToRgba32( Configuration configuration, @@ -79,6 +91,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgr24(source, dest); } + /// public override void ToArgb32( Configuration configuration, @@ -106,6 +119,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgr24(source, dest); } + /// public override void ToBgra32( Configuration configuration, @@ -133,6 +147,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToBgr24(source, dest); } + /// public override void ToRgb24( Configuration configuration, @@ -162,7 +177,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -180,7 +198,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -198,7 +219,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -216,7 +240,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -234,7 +261,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb48(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -252,7 +282,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba64(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -270,7 +303,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -286,6 +322,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } + /// public override void From( Configuration configuration, @@ -294,6 +331,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToBgr24(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.tt similarity index 84% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.tt index cfaefeda9..01c9fde89 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ -<#@include file="_Common.ttinclude" #> +<#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("Bgr24"); #> <# GenerateAllDefaultConversionMethods("Bgr24"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs similarity index 86% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs index b38e5f19d..8304ad2ca 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs @@ -1,15 +1,14 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + /// public override void FromBgra32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -42,16 +45,25 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void FromVector4Destructive(Configuration configuration, Span sourceVectors, Span destinationPixels, PixelConversionModifiers modifiers) + public override void FromVector4Destructive( + Configuration configuration, + Span sourceVectors, + Span destinationPixels, + PixelConversionModifiers modifiers) { Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale)); } /// - public override void ToVector4(Configuration configuration, ReadOnlySpan sourcePixels, Span destVectors, PixelConversionModifiers modifiers) + public override void ToVector4( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destVectors, + PixelConversionModifiers modifiers) { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); } + /// public override void ToRgba32( Configuration configuration, @@ -79,6 +91,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgra32(source, dest); } + /// public override void ToArgb32( Configuration configuration, @@ -106,6 +119,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgra32(source, dest); } + /// public override void ToRgb24( Configuration configuration, @@ -133,6 +147,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToBgra32(source, dest); } + /// public override void ToBgr24( Configuration configuration, @@ -162,7 +177,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -180,7 +198,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -198,7 +219,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -216,7 +240,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -234,7 +261,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb48(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -252,7 +282,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba64(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -270,7 +303,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -286,6 +322,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } + /// public override void From( Configuration configuration, @@ -294,6 +331,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToBgra32(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.tt similarity index 84% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.tt index 58ecfa5a6..606631431 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ -<#@include file="_Common.ttinclude" #> +<#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("Bgra32"); #> <# GenerateAllDefaultConversionMethods("Bgra32"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs similarity index 80% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs index f9662e0d0..33b955619 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs @@ -3,13 +3,12 @@ // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + /// public override void FromBgra5551(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -43,7 +46,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// - public override void ToArgb32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToArgb32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -61,7 +67,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgr24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgr24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -79,7 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -97,7 +109,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -115,7 +130,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -133,7 +151,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -151,7 +172,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -169,7 +193,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -187,7 +214,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -205,7 +235,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb48(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -223,7 +256,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba64(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -239,6 +275,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } + /// public override void From( Configuration configuration, @@ -247,6 +284,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToBgra5551(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.tt similarity index 90% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.tt index c4f2fc8bd..3c18f4744 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ <#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("Bgra5551"); #> <# GenerateAllDefaultConversionMethods("Bgra5551"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs similarity index 80% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs index d0c96def1..88dc85f57 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs @@ -1,15 +1,14 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + /// public override void FromL16(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -43,7 +46,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// - public override void ToArgb32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToArgb32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -61,7 +67,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgr24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgr24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -79,7 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -97,7 +109,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -115,7 +130,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -133,7 +151,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -151,7 +172,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -169,7 +193,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -187,7 +214,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb48(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -205,7 +235,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba64(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -223,7 +256,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -239,6 +275,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } + /// public override void From( Configuration configuration, @@ -247,6 +284,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToL16(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.tt similarity index 84% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.tt index 937902346..27b977059 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ -<#@include file="_Common.ttinclude" #> +<#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("L16"); #> <# GenerateAllDefaultConversionMethods("L16"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs similarity index 80% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs index 31b1c96ec..2b16851d6 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs @@ -1,15 +1,14 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + /// public override void FromL8(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -43,7 +46,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// - public override void ToArgb32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToArgb32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -61,7 +67,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgr24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgr24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -79,7 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -97,7 +109,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -115,7 +130,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -133,7 +151,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -151,7 +172,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -169,7 +193,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -187,7 +214,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb48(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -205,7 +235,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba64(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -223,7 +256,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -239,6 +275,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } + /// public override void From( Configuration configuration, @@ -247,6 +284,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToL8(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.tt similarity index 84% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.tt index d2e802a19..c054d0847 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ -<#@include file="_Common.ttinclude" #> +<#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("L8"); #> <# GenerateAllDefaultConversionMethods("L8"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs similarity index 80% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs index 48e7c76e5..7cc94ecae 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs @@ -3,13 +3,12 @@ // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + /// public override void FromLa16(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -43,7 +46,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// - public override void ToArgb32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToArgb32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -61,7 +67,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgr24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgr24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -79,7 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -97,7 +109,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -115,7 +130,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -133,7 +151,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -151,7 +172,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -169,7 +193,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -187,7 +214,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb48(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -205,7 +235,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba64(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -223,7 +256,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -239,6 +275,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } + /// public override void From( Configuration configuration, @@ -247,6 +284,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToLa16(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.tt similarity index 91% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.tt index 5d6661631..06d2ec1ab 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ <#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("La16"); #> <# GenerateAllDefaultConversionMethods("La16"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs similarity index 80% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs index f8b4bedc2..ccee68190 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs @@ -3,13 +3,12 @@ // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + /// public override void FromLa32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -43,7 +46,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// - public override void ToArgb32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToArgb32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -61,7 +67,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgr24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgr24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -79,7 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -97,7 +109,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -115,7 +130,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -133,7 +151,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -151,7 +172,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -169,7 +193,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -187,7 +214,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb48(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -205,7 +235,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba64(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -223,7 +256,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -239,6 +275,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } + /// public override void From( Configuration configuration, @@ -247,6 +284,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToLa32(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.tt similarity index 91% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.tt index e2fb4867a..34f54e77a 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ <#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("La32"); #> <# GenerateAllDefaultConversionMethods("La32"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs similarity index 86% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs index 9a4173892..23b982400 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs @@ -1,15 +1,14 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + /// public override void FromRgb24(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -42,16 +45,25 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void FromVector4Destructive(Configuration configuration, Span sourceVectors, Span destinationPixels, PixelConversionModifiers modifiers) + public override void FromVector4Destructive( + Configuration configuration, + Span sourceVectors, + Span destinationPixels, + PixelConversionModifiers modifiers) { Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } /// - public override void ToVector4(Configuration configuration, ReadOnlySpan sourcePixels, Span destVectors, PixelConversionModifiers modifiers) + public override void ToVector4( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destVectors, + PixelConversionModifiers modifiers) { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } + /// public override void ToRgba32( Configuration configuration, @@ -107,6 +119,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgb24(source, dest); } + /// public override void ToBgra32( Configuration configuration, @@ -134,6 +147,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgb24(source, dest); } + /// public override void ToBgr24( Configuration configuration, @@ -163,7 +177,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -181,7 +198,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -199,7 +219,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -217,7 +240,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -235,7 +261,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb48(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -253,7 +282,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba64(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -271,7 +303,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -287,6 +322,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } + /// public override void From( Configuration configuration, @@ -295,6 +331,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToRgb24(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.tt similarity index 84% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.tt index fc149b238..e1d2878ca 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ -<#@include file="_Common.ttinclude" #> +<#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("Rgb24"); #> <# GenerateAllDefaultConversionMethods("Rgb24"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs similarity index 80% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs index 9423aa2c8..ce067906c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs @@ -1,15 +1,14 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + /// public override void FromRgb48(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -43,7 +46,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// - public override void ToArgb32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToArgb32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -61,7 +67,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgr24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgr24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -79,7 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -97,7 +109,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -115,7 +130,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -133,7 +151,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -151,7 +172,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -169,7 +193,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -187,7 +214,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -205,7 +235,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba64(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -223,7 +256,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -239,6 +275,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } + /// public override void From( Configuration configuration, @@ -247,6 +284,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToRgb48(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.tt similarity index 84% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.tt index 957c8f886..6d05b4851 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ -<#@include file="_Common.ttinclude" #> +<#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("Rgb48"); #> <# GenerateAllDefaultConversionMethods("Rgb48"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs similarity index 88% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs index 5b60ec10e..90b05f786 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs @@ -1,15 +1,14 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + /// public override void FromRgba32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -41,6 +44,7 @@ namespace SixLabors.ImageSharp.PixelFormats sourcePixels.CopyTo(destinationPixels); } + /// public override void ToArgb32( Configuration configuration, @@ -68,6 +72,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgba32(source, dest); } + /// public override void ToBgra32( Configuration configuration, @@ -95,6 +100,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgba32(source, dest); } + /// public override void ToRgb24( Configuration configuration, @@ -122,6 +128,7 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToRgba32(source, dest); } + /// public override void ToBgr24( Configuration configuration, @@ -151,7 +158,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -169,7 +179,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -187,7 +200,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -205,7 +221,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -223,7 +242,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb48(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -241,7 +263,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba64(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -259,7 +284,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -275,6 +303,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } + /// public override void From( Configuration configuration, @@ -283,6 +312,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToRgba32(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.tt similarity index 84% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.tt index 905e2cc58..d40af0f4d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ -<#@include file="_Common.ttinclude" #> +<#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("Rgba32"); #> <# GenerateAllDefaultConversionMethods("Rgba32"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs similarity index 80% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs index 3fface03b..2cd27e8e3 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs @@ -1,15 +1,14 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats { @@ -23,6 +22,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + /// public override void FromRgba64(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -43,7 +46,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// - public override void ToArgb32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToArgb32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -61,7 +67,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgr24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgr24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -79,7 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -97,7 +109,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -115,7 +130,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -133,7 +151,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -151,7 +172,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToLa32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -169,7 +193,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb24(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -187,7 +214,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgba32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgba32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -205,7 +235,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToRgb48(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -223,7 +256,10 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -239,6 +275,7 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } + /// public override void From( Configuration configuration, @@ -247,6 +284,7 @@ namespace SixLabors.ImageSharp.PixelFormats { PixelOperations.Instance.ToRgba64(configuration, sourcePixels, destinationPixels); } + } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.tt similarity index 84% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.tt rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.tt index 03179a392..d0f4265f3 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.tt @@ -1,6 +1,5 @@ -<#@include file="_Common.ttinclude" #> +<#@include file="_Common.ttinclude" #> <#@ output extension=".cs" #> - namespace SixLabors.ImageSharp.PixelFormats { /// @@ -13,6 +12,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + <# GeneratePixelTypeInfo("Rgba64"); #> <# GenerateAllDefaultConversionMethods("Rgba64"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/_Common.ttinclude b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude similarity index 71% rename from src/ImageSharp/PixelFormats/PixelImplementations/Generated/_Common.ttinclude rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude index b728b0115..7a29e4659 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Generated/_Common.ttinclude +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude @@ -8,19 +8,85 @@ // -using SixLabors.ImageSharp.PixelFormats.Utils; using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats.Utils; <#+ - static readonly string[] CommonPixelTypes = { "Argb32", "Bgr24", "Bgra32", "L8", "L16", "La16", "La32", "Rgb24", "Rgba32", "Rgb48", "Rgba64", "Bgra5551" }; - - static readonly string[] OptimizedPixelTypes = { "Rgba32", "Argb32", "Bgra32", "Rgb24", "Bgr24" }; + private static readonly string[] UnassociatedAlphaPixelTypes = + { + "A8", + "Argb32", + "Bgra32", + "Bgra4444", + "Bgra5551", + "Byte4", + "HalfVector4", + "La16", + "La32", + "NormalizedByte4", + "NormalizedShort4", + "Rgba1010102", + "Rgba32", + "Rgba64", + "RgbaVector", + "Short4" + }; + + private static readonly string[] AssociatedAlphaPixelTypes = Array.Empty(); + + private static readonly string[] CommonPixelTypes = + { + "Argb32", + "Bgr24", + "Bgra32", + "L8", + "L16", + "La16", + "La32", + "Rgb24", + "Rgba32", + "Rgb48", + "Rgba64", + "Bgra5551" + }; + + private static readonly string[] OptimizedPixelTypes = + { + "Rgba32", + "Argb32", + "Bgra32", + "Rgb24", + "Bgr24" + }; + + // Types with Rgba32-combatable to/from Vector4 conversion + private static readonly string[] Rgba32CompatibleTypes = + { + "Argb32", + "Bgra32", + "Rgb24", + "Bgr24" + }; - // Types with Rgba32-combatible to/from Vector4 conversion - static readonly string[] Rgba32CompatibleTypes = { "Argb32", "Bgra32", "Rgb24", "Bgr24" }; + void GeneratePixelTypeInfo(string pixelType) + { + string alpha = "PixelAlphaRepresentation.None"; + if (AssociatedAlphaPixelTypes.Contains(pixelType)) + { + alpha = "PixelAlphaRepresentation.Associated"; + } + else if (UnassociatedAlphaPixelTypes.Contains(pixelType)) + { + alpha = "PixelAlphaRepresentation.Unassociated"; + } +#> + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<<#=pixelType#>>(<#=alpha#>); +<#+ + } void GenerateGenericConverterMethods(string pixelType) { @@ -33,13 +99,14 @@ using System.Runtime.InteropServices; { PixelOperations.Instance.To<#=pixelType#>(configuration, sourcePixels, destinationPixels); } + <#+ } void GenerateDefaultSelfConversionMethods(string pixelType) { #> -/// + /// public override void From<#=pixelType#>(Configuration configuration, ReadOnlySpan<<#=pixelType#>> source, Span<<#=pixelType#>> destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); @@ -63,9 +130,11 @@ using System.Runtime.InteropServices; void GenerateDefaultConvertToMethod(string fromPixelType, string toPixelType) { #> - /// - public override void To<#=toPixelType#>(Configuration configuration, ReadOnlySpan<<#=fromPixelType#>> sourcePixels, Span<<#=toPixelType#>> destinationPixels) + public override void To<#=toPixelType#>( + Configuration configuration, + ReadOnlySpan<<#=fromPixelType#>> sourcePixels, + Span<<#=toPixelType#>> destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -126,13 +195,21 @@ using System.Runtime.InteropServices; } #> /// - public override void FromVector4Destructive(Configuration configuration, Span sourceVectors, Span<<#=pixelType#>> destinationPixels, PixelConversionModifiers modifiers) + public override void FromVector4Destructive( + Configuration configuration, + Span sourceVectors, + Span<<#=pixelType#>> destinationPixels, + PixelConversionModifiers modifiers) { Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(<#=removeTheseModifiers#>)); } /// - public override void ToVector4(Configuration configuration, ReadOnlySpan<<#=pixelType#>> sourcePixels, Span destVectors, PixelConversionModifiers modifiers) + public override void ToVector4( + Configuration configuration, + ReadOnlySpan<<#=pixelType#>> sourcePixels, + Span destVectors, + PixelConversionModifiers modifiers) { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(<#=removeTheseModifiers#>)); } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs new file mode 100644 index 000000000..afbd3af4c --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct HalfSingle + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs new file mode 100644 index 000000000..e9cc88c15 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct HalfVector2 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs new file mode 100644 index 000000000..63b6e3af5 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct HalfVector4 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs new file mode 100644 index 000000000..f0f513860 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct NormalizedByte2 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs new file mode 100644 index 000000000..8874f1241 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct NormalizedByte4 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs new file mode 100644 index 000000000..a53587a06 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct NormalizedShort2 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs new file mode 100644 index 000000000..6a3dc505f --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct NormalizedShort4 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs new file mode 100644 index 000000000..c079d1e5b --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Rg32 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs new file mode 100644 index 000000000..b13fe2ec8 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Rgba1010102 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs similarity index 100% rename from src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs similarity index 84% rename from src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.PixelOperations.cs rename to src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs index aa0791d0c..b4ba02a95 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs @@ -5,7 +5,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,6 +20,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + /// public override void FromVector4Destructive( Configuration configuration, @@ -46,7 +49,10 @@ namespace SixLabors.ImageSharp.PixelFormats Vector4Converters.ApplyForwardConversionModifiers(destinationVectors, modifiers); } - public override void ToL8(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); @@ -62,7 +68,10 @@ namespace SixLabors.ImageSharp.PixelFormats } } - public override void ToL16(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) { Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs new file mode 100644 index 000000000..942e40f94 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Short2 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs new file mode 100644 index 000000000..b2d743f87 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Short4 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs index 7c805f148..d7e6f53cf 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [0, 0, 0, 1] to [1, 1, 0, 1] in vector form. /// /// - public struct Rg32 : IPixel, IPackedVector + public partial struct Rg32 : IPixel, IPackedVector { private static readonly Vector2 Max = new Vector2(ushort.MaxValue); @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(Rg32 left, Rg32 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs index 2bf9350f8..60f56fb06 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form. /// /// - public struct Rgba1010102 : IPixel, IPackedVector + public partial struct Rgba1010102 : IPixel, IPackedVector { private static readonly Vector4 Multiplier = new Vector4(1023F, 1023F, 1023F, 3F); @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(Rgba1010102 left, Rgba1010102 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs index 91c0e9ab5..f7a4f9994 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [-32767, -32767, 0, 1] to [32767, 32767, 0, 1] in vector form. /// /// - public struct Short2 : IPixel, IPackedVector + public partial struct Short2 : IPixel, IPackedVector { // Largest two byte positive number 0xFFFF >> 1; private const float MaxPos = 0x7FFF; @@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(Short2 left, Short2 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs index 3f74b6845..c67be71e5 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Ranges from [-37267, -37267, -37267, -37267] to [37267, 37267, 37267, 37267] in vector form. /// /// - public struct Short4 : IPixel, IPackedVector + public partial struct Short4 : IPixel, IPackedVector { // Largest two byte positive number 0xFFFF >> 1; private const float MaxPos = 0x7FFF; @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.PixelFormats public static bool operator !=(Short4 left, Short4 right) => !left.Equals(right); /// - public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs index 2fff67b58..14ad120bf 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs @@ -4,7 +4,7 @@ using System; using System.Buffers; using System.Numerics; - +using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.PixelFormats @@ -22,6 +22,12 @@ namespace SixLabors.ImageSharp.PixelFormats /// public static PixelOperations Instance { get; } = default(TPixel).CreatePixelOperations(); + /// + /// Gets the pixel type info for the given . + /// + /// The . + public virtual PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(); + /// /// Bulk version of converting 'sourceVectors.Length' pixels into 'destinationColors'. /// The method is DESTRUCTIVE altering the contents of . @@ -108,28 +114,27 @@ namespace SixLabors.ImageSharp.PixelFormats { const int SliceLength = 1024; int numberOfSlices = sourcePixels.Length / SliceLength; - using (IMemoryOwner tempVectors = configuration.MemoryAllocator.Allocate(SliceLength)) + + using IMemoryOwner tempVectors = configuration.MemoryAllocator.Allocate(SliceLength); + Span vectorSpan = tempVectors.GetSpan(); + for (int i = 0; i < numberOfSlices; i++) { - Span vectorSpan = tempVectors.GetSpan(); - for (int i = 0; i < numberOfSlices; i++) - { - int start = i * SliceLength; - ReadOnlySpan s = sourcePixels.Slice(start, SliceLength); - Span d = destinationPixels.Slice(start, SliceLength); - PixelOperations.Instance.ToVector4(configuration, s, vectorSpan); - this.FromVector4Destructive(configuration, vectorSpan, d); - } + int start = i * SliceLength; + ReadOnlySpan s = sourcePixels.Slice(start, SliceLength); + Span d = destinationPixels.Slice(start, SliceLength); + PixelOperations.Instance.ToVector4(configuration, s, vectorSpan); + this.FromVector4Destructive(configuration, vectorSpan, d); + } - int endOfCompleteSlices = numberOfSlices * SliceLength; - int remainder = sourcePixels.Length - endOfCompleteSlices; - if (remainder > 0) - { - ReadOnlySpan s = sourcePixels.Slice(endOfCompleteSlices); - Span d = destinationPixels.Slice(endOfCompleteSlices); - vectorSpan = vectorSpan.Slice(0, remainder); - PixelOperations.Instance.ToVector4(configuration, s, vectorSpan); - this.FromVector4Destructive(configuration, vectorSpan, d); - } + int endOfCompleteSlices = numberOfSlices * SliceLength; + int remainder = sourcePixels.Length - endOfCompleteSlices; + if (remainder > 0) + { + ReadOnlySpan s = sourcePixels.Slice(endOfCompleteSlices); + Span d = destinationPixels.Slice(endOfCompleteSlices); + vectorSpan = vectorSpan.Slice(0, remainder); + PixelOperations.Instance.ToVector4(configuration, s, vectorSpan); + this.FromVector4Destructive(configuration, vectorSpan, d); } } diff --git a/tests/ImageSharp.Tests.ProfilingSandbox/Program.cs b/tests/ImageSharp.Tests.ProfilingSandbox/Program.cs index 8155c6a58..5504a9978 100644 --- a/tests/ImageSharp.Tests.ProfilingSandbox/Program.cs +++ b/tests/ImageSharp.Tests.ProfilingSandbox/Program.cs @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Tests.ProfilingSandbox private static void RunToVector4ProfilingTest() { - var tests = new PixelOperationsTests.Rgba32OperationsTests(new ConsoleOutput()); + var tests = new PixelOperationsTests.Rgba32_OperationsTests(new ConsoleOutput()); tests.Benchmark_ToVector4(); } diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 07ade97d5..5e97370ff 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -17,6 +17,14 @@ + + + True + True + PixelOperationsTests.Specialized.Generated.tt + + + @@ -27,6 +35,10 @@ + + TextTemplatingFileGenerator + PixelOperationsTests.Specialized.Generated.cs + PreserveNewest @@ -38,5 +50,17 @@ + + + True + True + PixelOperationsTests.Specialized.Generated.tt + + + + + + + diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs new file mode 100644 index 000000000..5566ccd74 --- /dev/null +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs @@ -0,0 +1,718 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +// + +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +using Xunit.Abstractions; + + +namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations +{ + public partial class PixelOperationsTests + { + + public partial class A8_OperationsTests : PixelOperationsTests + { + public A8_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = A8.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = A8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class Argb32_OperationsTests : PixelOperationsTests + { + public Argb32_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Argb32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Argb32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class Bgr24_OperationsTests : PixelOperationsTests + { + public Bgr24_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Bgr24.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Bgr24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class Bgr565_OperationsTests : PixelOperationsTests + { + public Bgr565_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Bgr565.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Bgr565.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class Bgra32_OperationsTests : PixelOperationsTests + { + public Bgra32_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Bgra32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Bgra32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class Bgra4444_OperationsTests : PixelOperationsTests + { + public Bgra4444_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Bgra4444.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Bgra4444.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class Bgra5551_OperationsTests : PixelOperationsTests + { + public Bgra5551_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Bgra5551.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Bgra5551.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class Byte4_OperationsTests : PixelOperationsTests + { + public Byte4_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Byte4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Byte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class HalfSingle_OperationsTests : PixelOperationsTests + { + public HalfSingle_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = HalfSingle.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = HalfSingle.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class HalfVector2_OperationsTests : PixelOperationsTests + { + public HalfVector2_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = HalfVector2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = HalfVector2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class HalfVector4_OperationsTests : PixelOperationsTests + { + public HalfVector4_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = HalfVector4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = HalfVector4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class L16_OperationsTests : PixelOperationsTests + { + public L16_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = L16.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = L16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class L8_OperationsTests : PixelOperationsTests + { + public L8_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = L8.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = L8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class La16_OperationsTests : PixelOperationsTests + { + public La16_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = La16.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = La16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class La32_OperationsTests : PixelOperationsTests + { + public La32_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = La32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = La32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class NormalizedByte2_OperationsTests : PixelOperationsTests + { + public NormalizedByte2_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = NormalizedByte2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = NormalizedByte2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class NormalizedByte4_OperationsTests : PixelOperationsTests + { + public NormalizedByte4_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = NormalizedByte4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = NormalizedByte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class NormalizedShort2_OperationsTests : PixelOperationsTests + { + public NormalizedShort2_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = NormalizedShort2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = NormalizedShort2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class NormalizedShort4_OperationsTests : PixelOperationsTests + { + public NormalizedShort4_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = NormalizedShort4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = NormalizedShort4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class Rg32_OperationsTests : PixelOperationsTests + { + public Rg32_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Rg32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Rg32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class Rgb24_OperationsTests : PixelOperationsTests + { + public Rgb24_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Rgb24.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Rgb24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class Rgb48_OperationsTests : PixelOperationsTests + { + public Rgb48_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Rgb48.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Rgb48.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class Rgba1010102_OperationsTests : PixelOperationsTests + { + public Rgba1010102_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Rgba1010102.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Rgba1010102.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class Rgba32_OperationsTests : PixelOperationsTests + { + public Rgba32_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Rgba32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Rgba32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class Rgba64_OperationsTests : PixelOperationsTests + { + public Rgba64_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Rgba64.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Rgba64.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class RgbaVector_OperationsTests : PixelOperationsTests + { + public RgbaVector_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = RgbaVector.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = RgbaVector.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + + public partial class Short2_OperationsTests : PixelOperationsTests + { + public Short2_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Short2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Short2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); + } + } + + public partial class Short4_OperationsTests : PixelOperationsTests + { + public Short4_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = Short4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = Short4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } + } +} + diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.tt b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.tt new file mode 100644 index 000000000..502b66fb5 --- /dev/null +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.tt @@ -0,0 +1,11 @@ +<#@include file="_Common.ttinclude" #> +<#@ output extension=".cs" #> + +namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations +{ + public partial class PixelOperationsTests + { + <# GenerateAllSpecializedClasses(); #> + } +} + diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude new file mode 100644 index 000000000..cd6e2a09d --- /dev/null +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude @@ -0,0 +1,117 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +// + +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +using Xunit.Abstractions; +<#+ + private static readonly string[] UnassociatedAlphaPixelTypes = + { + "A8", + "Argb32", + "Bgra32", + "Bgra4444", + "Bgra5551", + "Byte4", + "HalfVector4", + "La16", + "La32", + "NormalizedByte4", + "NormalizedShort4", + "Rgba1010102", + "Rgba32", + "Rgba64", + "RgbaVector", + "Short4" + }; + + private static readonly string[] AssociatedAlphaPixelTypes = Array.Empty(); + + private static readonly string[] CommonPixelTypes = + { + "A8", + "Argb32", + "Bgr24", + "Bgr565", + "Bgra32", + "Bgra4444", + "Bgra5551", + "Byte4", + "HalfSingle", + "HalfVector2", + "HalfVector4", + "L16", + "L8", + "La16", + "La32", + "NormalizedByte2", + "NormalizedByte4", + "NormalizedShort2", + "NormalizedShort4", + "Rg32", + "Rgb24", + "Rgb48", + "Rgba1010102", + "Rgba32", + "Rgba64", + "RgbaVector", + "Short2", + "Short4", + }; + + void GenerateSpecializedClass(string pixelType, string alpha) + { +#> + public partial class <#=pixelType#>_OperationsTests : PixelOperationsTests<<#=pixelType#>> + { + public <#=pixelType#>_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void IsSpecialImplementation() => Assert.IsType<<#=pixelType#>.PixelOperations>(PixelOperations<<#=pixelType#>>.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = <#=pixelType#>.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf<<#=pixelType#>>() * 8, bits); + } + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = <#=pixelType#>.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(<#=alpha#>, alphaRepresentation); + } + } +<#+ + } + + void GenerateAllSpecializedClasses() + { + foreach (string pixelType in CommonPixelTypes) + { + string alpha = "PixelAlphaRepresentation.None"; + if (AssociatedAlphaPixelTypes.Contains(pixelType)) + { + alpha = "PixelAlphaRepresentation.Associated"; + } + else if (UnassociatedAlphaPixelTypes.Contains(pixelType)) + { + alpha = "PixelAlphaRepresentation.Unassociated"; + } + + GenerateSpecializedClass(pixelType, alpha); + } + } +#> diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Argb32OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Argb32OperationsTests.cs deleted file mode 100644 index 1d4d58341..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Argb32OperationsTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; - -using Xunit; -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class Argb32OperationsTests : PixelOperationsTests - { - public Argb32OperationsTests(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - } - } -} diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgr24OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgr24OperationsTests.cs deleted file mode 100644 index 712b1495b..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgr24OperationsTests.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; - -using Xunit; -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class Bgr24OperationsTests : PixelOperationsTests - { - public Bgr24OperationsTests(ITestOutputHelper output) - : base(output) - { - this.HasAlpha = false; - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgra32OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgra32OperationsTests.cs deleted file mode 100644 index 7f248b682..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgra32OperationsTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; - -using Xunit; -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class Bgra32OperationsTests : PixelOperationsTests - { - public Bgra32OperationsTests(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgra5551OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgra5551OperationsTests.cs deleted file mode 100644 index 9a0e51563..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Bgra5551OperationsTests.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; - -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class Bgra5551OperationsTests : PixelOperationsTests - { - public Bgra5551OperationsTests(ITestOutputHelper output) - : base(output) - { - } - } - } -} diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.L16OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.L16OperationsTests.cs deleted file mode 100644 index 6acd439f2..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.L16OperationsTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; - -using Xunit; -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class L16OperationsTests : PixelOperationsTests - { - public L16OperationsTests(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - } - } -} diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.L8OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.L8OperationsTests.cs deleted file mode 100644 index a16f8c66d..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.L8OperationsTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; - -using Xunit; -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class L8OperationsTests : PixelOperationsTests - { - public L8OperationsTests(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - } - } -} diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.La16OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.La16OperationsTests.cs deleted file mode 100644 index 07ec79777..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.La16OperationsTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; - -using Xunit; -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class La16OperationsTests : PixelOperationsTests - { - public La16OperationsTests(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - } - } -} diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.La32OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.La32OperationsTests.cs deleted file mode 100644 index bd8bb40da..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.La32OperationsTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; - -using Xunit; -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class La32OperationsTests : PixelOperationsTests - { - public La32OperationsTests(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - } - } -} diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgb24OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgb24OperationsTests.cs deleted file mode 100644 index 07bf838ee..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgb24OperationsTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; -using Xunit; -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class Rgb24OperationsTests : PixelOperationsTests - { - public Rgb24OperationsTests(ITestOutputHelper output) - : base(output) - { - this.HasAlpha = false; - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - } - } -} diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgb48OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgb48OperationsTests.cs deleted file mode 100644 index 7ab677766..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgb48OperationsTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; - -using Xunit; -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class Rgb48OperationsTests : PixelOperationsTests - { - public Rgb48OperationsTests(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgba32OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgba32OperationsTests.cs index e4f1fa462..85612d602 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgba32OperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgba32OperationsTests.cs @@ -1,29 +1,18 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. using System.Buffers; using System.Numerics; - using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; - using Xunit; -using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { public partial class PixelOperationsTests { - public class Rgba32OperationsTests : PixelOperationsTests + public partial class Rgba32_OperationsTests : PixelOperationsTests { - public Rgba32OperationsTests(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - [Fact(Skip = SkipProfilingBenchmarks)] public void Benchmark_ToVector4() { @@ -43,4 +32,4 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgba64OperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgba64OperationsTests.cs deleted file mode 100644 index a0ef2f765..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.Rgba64OperationsTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; - -using Xunit; -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class Rgba64OperationsTests : PixelOperationsTests - { - public Rgba64OperationsTests(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.RgbaVectorOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.RgbaVectorOperationsTests.cs deleted file mode 100644 index c552fb359..000000000 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.RgbaVectorOperationsTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; - -using Xunit; -using Xunit.Abstractions; - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations -{ - public partial class PixelOperationsTests - { - public class RgbaVectorOperationsTests : PixelOperationsTests - { - public RgbaVectorOperationsTests(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); - } - } -} \ No newline at end of file diff --git a/tests/Images/External b/tests/Images/External index 8b43d14d2..cc6465910 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 8b43d14d21ce9b436af3d12a70d38402cdba176b +Subproject commit cc6465910d092319ef9bf4e99698a0649996d3c5 From 7824852eb44e2db6b78fe744c882dd07cc12ef01 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 8 Nov 2020 19:59:35 +0000 Subject: [PATCH 03/39] Update External --- tests/Images/External | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Images/External b/tests/Images/External index cc6465910..8b43d14d2 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit cc6465910d092319ef9bf4e99698a0649996d3c5 +Subproject commit 8b43d14d21ce9b436af3d12a70d38402cdba176b From 36ebc4513db715063632e677b2e249a8a9a1fb0e Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 8 Nov 2020 21:36:39 +0000 Subject: [PATCH 04/39] Fix Short4 and tests --- .../RgbaVector.PixelOperations.cs | 2 +- .../PixelImplementations/Short4.cs | 2 +- ...elOperationsTests.Specialized.Generated.cs | 56 ++++++++++++++++++ .../Generated/_Common.ttinclude | 2 + .../PixelOperations/PixelOperationsTests.cs | 57 +++++++++++++------ 5 files changed, 99 insertions(+), 20 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs index b4ba02a95..11ef90e49 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.PixelFormats internal class PixelOperations : PixelOperations { /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); /// public override void FromVector4Destructive( diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs index c67be71e5..2e9db245f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs @@ -164,7 +164,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly bool Equals(Short4 other) => this.PackedValue.Equals(other); + public readonly bool Equals(Short4 other) => this.PackedValue.Equals(other.PackedValue); /// /// Gets the hash code for the current instance. diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs index 5566ccd74..5b1abb749 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs @@ -19,6 +19,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public A8_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = A8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -44,6 +46,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Argb32_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Argb32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -69,6 +73,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgr24_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Bgr24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -94,6 +100,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgr565_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Bgr565.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -119,6 +127,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgra32_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Bgra32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -144,6 +154,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgra4444_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Bgra4444.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -169,6 +181,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgra5551_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Bgra5551.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -194,6 +208,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Byte4_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Byte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -219,6 +235,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public HalfSingle_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = HalfSingle.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -244,6 +262,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public HalfVector2_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = HalfVector2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -269,6 +289,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public HalfVector4_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = HalfVector4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -294,6 +316,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public L16_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = L16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -319,6 +343,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public L8_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = L8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -344,6 +370,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public La16_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = La16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -369,6 +397,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public La32_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = La32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -394,6 +424,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedByte2_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = NormalizedByte2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -419,6 +451,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedByte4_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = NormalizedByte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -444,6 +478,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedShort2_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = NormalizedShort2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -469,6 +505,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedShort4_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = NormalizedShort4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -494,6 +532,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rg32_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rg32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -519,6 +559,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgb24_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rgb24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -544,6 +586,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgb48_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rgb48.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -569,6 +613,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgba1010102_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rgba1010102.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -594,6 +640,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgba32_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rgba32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -619,6 +667,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgba64_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rgba64.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -644,6 +694,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public RgbaVector_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = RgbaVector.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -669,6 +721,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Short2_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Short2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -694,6 +748,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Short4_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Short4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude index cd6e2a09d..bc093be85 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude @@ -75,6 +75,8 @@ using Xunit.Abstractions; public <#=pixelType#>_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = <#=pixelType#>.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index 3c4b9dc79..d18c3c860 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations null; #endif - protected bool HasAlpha { get; set; } = true; + protected bool HasUnassociatedAlpha { get; set; } = true; protected PixelOperationsTests(ITestOutputHelper output) : base(output) @@ -168,7 +168,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { void SourceAction(ref Vector4 v) { - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.Premultiply(ref v); } @@ -176,7 +176,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations void ExpectedAction(ref Vector4 v) { - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.UnPremultiply(ref v); } @@ -188,7 +188,14 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan(), PixelConversionModifiers.Premultiply)); + (s, d) => + { + PixelConversionModifiers modifiers = this.HasUnassociatedAlpha + ? PixelConversionModifiers.Premultiply + : PixelConversionModifiers.None; + + Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan(), modifiers); + }); } [Theory] @@ -197,7 +204,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { void SourceAction(ref Vector4 v) { - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.Premultiply(ref v); } @@ -205,7 +212,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations void ExpectedAction(ref Vector4 v) { - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.UnPremultiply(ref v); } @@ -217,11 +224,18 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromVector4Destructive( - this.Configuration, - s, - d.GetSpan(), - PixelConversionModifiers.Premultiply | PixelConversionModifiers.Scale)); + (s, d) => + { + PixelConversionModifiers modifiers = this.HasUnassociatedAlpha + ? PixelConversionModifiers.Premultiply + : PixelConversionModifiers.None; + + Operations.FromVector4Destructive( + this.Configuration, + s, + d.GetSpan(), + modifiers | PixelConversionModifiers.Scale); + }); } [Theory] @@ -232,7 +246,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { SRgbCompanding.Expand(ref v); - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.Premultiply(ref v); } @@ -240,7 +254,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations void ExpectedAction(ref Vector4 v) { - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.UnPremultiply(ref v); } @@ -254,11 +268,18 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromVector4Destructive( - this.Configuration, - s, - d.GetSpan(), - PixelConversionModifiers.SRgbCompand | PixelConversionModifiers.Premultiply | PixelConversionModifiers.Scale)); + (s, d) => + { + PixelConversionModifiers modifiers = this.HasUnassociatedAlpha + ? PixelConversionModifiers.Premultiply + : PixelConversionModifiers.None; + + Operations.FromVector4Destructive( + this.Configuration, + s, + d.GetSpan(), + modifiers | PixelConversionModifiers.SRgbCompand | PixelConversionModifiers.Scale); + }); } [Theory] From fd76f69eb1fb3da17eb45db24a41bd08da03f829 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 11 Nov 2020 19:46:01 +0000 Subject: [PATCH 05/39] Remove bas T4 refs --- src/ImageSharp/ImageSharp.csproj | 48 +++----------------------------- 1 file changed, 4 insertions(+), 44 deletions(-) diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 258deb44f..f4e985198 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -62,11 +62,6 @@ True PixelOperations{TPixel}.Generated.tt - - True - True - A8.PixelOperations.Generated.tt - True True @@ -77,56 +72,26 @@ True Bgr24.PixelOperations.Generated.tt - - True - True - Bgr565.PixelOperations.Generated.tt - True True Bgra32.PixelOperations.Generated.tt - - True - True - Bgra4444.PixelOperations.Generated.tt - True True Bgra5551.PixelOperations.Generated.tt - - True - True - Byte4.PixelOperations.Generated.tt - - - True - True - HalfSingle.PixelOperations.Generated.tt - - + True True - HalfVector2.PixelOperations.Generated.tt + L16.PixelOperations.Generated.tt - - True - True - HalfVector4.PixelOperations.Generated.tt - True True L8.PixelOperations.Generated.tt - - True - True - L16.PixelOperations.Generated.tt - True True @@ -142,21 +107,16 @@ True Rgb24.PixelOperations.Generated.tt - + True True - Rg32.PixelOperations.Generated.tt + Rgb48.PixelOperations.Generated.tt True True Rgba32.PixelOperations.Generated.tt - - True - True - Rgb48.PixelOperations.Generated.tt - True True From 86d4b7214e786fca619e238bba4dc693a32efe8e Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 11 Nov 2020 20:46:45 +0000 Subject: [PATCH 06/39] Don't autogenerate GetPixelTypeInfo --- .../PixelOperations/Argb32.PixelOperations.cs | 22 ++++++++++ .../PixelOperations/Bgr24.PixelOperations.cs | 23 +++++++++++ .../PixelOperations/Bgra32.PixelOperations.cs | 23 +++++++++++ .../Bgra5551.PixelOperations.cs | 23 +++++++++++ .../Argb32.PixelOperations.Generated.cs | 6 +-- .../Argb32.PixelOperations.Generated.tt | 3 +- .../Bgr24.PixelOperations.Generated.cs | 6 +-- .../Bgr24.PixelOperations.Generated.tt | 3 +- .../Bgra32.PixelOperations.Generated.cs | 6 +-- .../Bgra32.PixelOperations.Generated.tt | 3 +- .../Bgra5551.PixelOperations.Generated.cs | 7 +--- .../Bgra5551.PixelOperations.Generated.tt | 3 +- .../L16.PixelOperations.Generated.cs | 7 +--- .../L16.PixelOperations.Generated.tt | 3 +- .../Generated/L8.PixelOperations.Generated.cs | 7 +--- .../Generated/L8.PixelOperations.Generated.tt | 3 +- .../La16.PixelOperations.Generated.cs | 7 +--- .../La16.PixelOperations.Generated.tt | 3 +- .../La32.PixelOperations.Generated.cs | 7 +--- .../La32.PixelOperations.Generated.tt | 3 +- .../Rgb24.PixelOperations.Generated.cs | 6 +-- .../Rgb24.PixelOperations.Generated.tt | 3 +- .../Rgb48.PixelOperations.Generated.cs | 7 +--- .../Rgb48.PixelOperations.Generated.tt | 3 +- .../Rgba32.PixelOperations.Generated.cs | 5 --- .../Rgba32.PixelOperations.Generated.tt | 1 - .../Rgba64.PixelOperations.Generated.cs | 7 +--- .../Rgba64.PixelOperations.Generated.tt | 3 +- .../Generated/_Common.ttinclude | 41 ------------------- .../PixelOperations/L16.PixelOperations.cs | 23 +++++++++++ .../PixelOperations/L8.PixelOperations.cs | 23 +++++++++++ .../PixelOperations/La16.PixelOperations.cs | 23 +++++++++++ .../PixelOperations/La32.PixelOperations.cs | 23 +++++++++++ .../PixelOperations/Rgb24.PixelOperations.cs | 23 +++++++++++ .../PixelOperations/Rgb48.PixelOperations.cs | 23 +++++++++++ .../PixelOperations/Rgba32.PixelOperations.cs | 6 ++- .../PixelOperations/Rgba64.PixelOperations.cs | 23 +++++++++++ 37 files changed, 279 insertions(+), 132 deletions(-) create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs new file mode 100644 index 000000000..f81932955 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Argb32 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs new file mode 100644 index 000000000..cd77f5816 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Bgr24 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() + => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs new file mode 100644 index 000000000..849f53835 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Bgra32 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() + => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs new file mode 100644 index 000000000..4714a8be2 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Bgra5551 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() + => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs index ce72eba81..9df708d44 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,12 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); - /// public override void FromArgb32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.tt index 1854bcd41..bbee95f24 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.tt @@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("Argb32"); #> <# GenerateAllDefaultConversionMethods("Argb32"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs index 7b15a2611..a66a6e12c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,12 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); - /// public override void FromBgr24(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.tt index 01c9fde89..48b6daa3a 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.tt @@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("Bgr24"); #> <# GenerateAllDefaultConversionMethods("Bgr24"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs index 8304ad2ca..77b665a4c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,12 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); - /// public override void FromBgra32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.tt index 606631431..7e1597989 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.tt @@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("Bgra32"); #> <# GenerateAllDefaultConversionMethods("Bgra32"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs index 33b955619..1d13722e4 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,12 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); - /// public override void FromBgra5551(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -44,7 +40,6 @@ namespace SixLabors.ImageSharp.PixelFormats sourcePixels.CopyTo(destinationPixels); } - /// public override void ToArgb32( Configuration configuration, diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.tt index 3c18f4744..c74dfb4bd 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.tt @@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("Bgra5551"); #> <# GenerateAllDefaultConversionMethods("Bgra5551"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs index 88dc85f57..03b84be5d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,12 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); - /// public override void FromL16(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -44,7 +40,6 @@ namespace SixLabors.ImageSharp.PixelFormats sourcePixels.CopyTo(destinationPixels); } - /// public override void ToArgb32( Configuration configuration, diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.tt index 27b977059..9c0f725e6 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.tt @@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("L16"); #> <# GenerateAllDefaultConversionMethods("L16"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs index 2b16851d6..f52e77b1a 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,12 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); - /// public override void FromL8(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -44,7 +40,6 @@ namespace SixLabors.ImageSharp.PixelFormats sourcePixels.CopyTo(destinationPixels); } - /// public override void ToArgb32( Configuration configuration, diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.tt index c054d0847..e6d4a45ef 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.tt @@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("L8"); #> <# GenerateAllDefaultConversionMethods("L8"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs index 7cc94ecae..e01399b8a 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,12 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); - /// public override void FromLa16(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -44,7 +40,6 @@ namespace SixLabors.ImageSharp.PixelFormats sourcePixels.CopyTo(destinationPixels); } - /// public override void ToArgb32( Configuration configuration, diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.tt index 06d2ec1ab..7b88fd4f1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.tt @@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("La16"); #> <# GenerateAllDefaultConversionMethods("La16"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs index ccee68190..0aa2afef5 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,12 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); - /// public override void FromLa32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -44,7 +40,6 @@ namespace SixLabors.ImageSharp.PixelFormats sourcePixels.CopyTo(destinationPixels); } - /// public override void ToArgb32( Configuration configuration, diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.tt index 34f54e77a..f85652cad 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.tt @@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("La32"); #> <# GenerateAllDefaultConversionMethods("La32"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs index 23b982400..a9303f9d8 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,12 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); - /// public override void FromRgb24(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.tt index e1d2878ca..056c2a279 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.tt @@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("Rgb24"); #> <# GenerateAllDefaultConversionMethods("Rgb24"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs index ce067906c..30328366d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,12 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); - /// public override void FromRgb48(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -44,7 +40,6 @@ namespace SixLabors.ImageSharp.PixelFormats sourcePixels.CopyTo(destinationPixels); } - /// public override void ToArgb32( Configuration configuration, diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.tt index 6d05b4851..f46493e62 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.tt @@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("Rgb48"); #> <# GenerateAllDefaultConversionMethods("Rgb48"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs index 90b05f786..c23198e76 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -23,9 +22,6 @@ namespace SixLabors.ImageSharp.PixelFormats internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); - /// public override void FromRgba32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -44,7 +40,6 @@ namespace SixLabors.ImageSharp.PixelFormats sourcePixels.CopyTo(destinationPixels); } - /// public override void ToArgb32( Configuration configuration, diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.tt index d40af0f4d..6a6cac4e3 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.tt @@ -12,7 +12,6 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("Rgba32"); #> <# GenerateAllDefaultConversionMethods("Rgba32"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs index 2cd27e8e3..129e9ff0b 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs @@ -7,7 +7,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -20,12 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); - /// public override void FromRgba64(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { @@ -44,7 +40,6 @@ namespace SixLabors.ImageSharp.PixelFormats sourcePixels.CopyTo(destinationPixels); } - /// public override void ToArgb32( Configuration configuration, diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.tt index d0f4265f3..cf02d38ee 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.tt @@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Provides optimized overrides for bulk operations. /// - internal class PixelOperations : PixelOperations + internal partial class PixelOperations : PixelOperations { - <# GeneratePixelTypeInfo("Rgba64"); #> <# GenerateAllDefaultConversionMethods("Rgba64"); #> } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude index 7a29e4659..7c2eccedc 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude @@ -12,31 +12,8 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; <#+ - private static readonly string[] UnassociatedAlphaPixelTypes = - { - "A8", - "Argb32", - "Bgra32", - "Bgra4444", - "Bgra5551", - "Byte4", - "HalfVector4", - "La16", - "La32", - "NormalizedByte4", - "NormalizedShort4", - "Rgba1010102", - "Rgba32", - "Rgba64", - "RgbaVector", - "Short4" - }; - - private static readonly string[] AssociatedAlphaPixelTypes = Array.Empty(); - private static readonly string[] CommonPixelTypes = { "Argb32", @@ -71,23 +48,6 @@ using SixLabors.ImageSharp.PixelFormats.Utils; "Bgr24" }; - void GeneratePixelTypeInfo(string pixelType) - { - string alpha = "PixelAlphaRepresentation.None"; - if (AssociatedAlphaPixelTypes.Contains(pixelType)) - { - alpha = "PixelAlphaRepresentation.Associated"; - } - else if (UnassociatedAlphaPixelTypes.Contains(pixelType)) - { - alpha = "PixelAlphaRepresentation.Unassociated"; - } -#> - /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<<#=pixelType#>>(<#=alpha#>); -<#+ - } - void GenerateGenericConverterMethods(string pixelType) { #> @@ -123,7 +83,6 @@ using SixLabors.ImageSharp.PixelFormats.Utils; sourcePixels.CopyTo(destinationPixels); } - <#+ } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs new file mode 100644 index 000000000..62d0e6164 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct L16 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() + => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs new file mode 100644 index 000000000..5da55ffb4 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct L8 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() + => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs new file mode 100644 index 000000000..feb4b65fd --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct La16 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() + => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs new file mode 100644 index 000000000..f69e6c185 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct La32 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() + => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs new file mode 100644 index 000000000..c4c6ac8ad --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Rgb24 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() + => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs new file mode 100644 index 000000000..bbe12315f --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Rgb48 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() + => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs index dcf304e9b..bc4454859 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs @@ -4,7 +4,7 @@ using System; using System.Numerics; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats.Utils; namespace SixLabors.ImageSharp.PixelFormats @@ -19,6 +19,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + /// + public override PixelTypeInfo GetPixelTypeInfo() + => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + /// public override void ToVector4( Configuration configuration, diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs new file mode 100644 index 000000000..e953a378e --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Rgba64 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override PixelTypeInfo GetPixelTypeInfo() + => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + } + } +} From 20c598cb1fdf573293e8b20831b72ffc18ecfcc0 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 18 Nov 2020 22:06:56 +0000 Subject: [PATCH 07/39] Update tests --- ...elOperationsTests.Specialized.Generated.cs | 309 +++++------------- .../Generated/_Common.ttinclude | 12 +- .../PixelOperations/PixelOperationsTests.cs | 103 +++--- 3 files changed, 152 insertions(+), 272 deletions(-) diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs index 5b1abb749..9d6ec8960 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs @@ -3,7 +3,6 @@ // -using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; using Xunit; using Xunit.Abstractions; @@ -23,20 +22,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => A8.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = A8.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = A8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -50,20 +44,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Argb32.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Argb32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Argb32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -77,20 +66,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Bgr24.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Bgr24.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Bgr24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -104,20 +88,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Bgr565.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Bgr565.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Bgr565.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -131,20 +110,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Bgra32.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Bgra32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Bgra32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -158,20 +132,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Bgra4444.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Bgra4444.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Bgra4444.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -185,20 +154,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Bgra5551.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Bgra5551.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Bgra5551.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -212,20 +176,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Byte4.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Byte4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Byte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -239,20 +198,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => HalfSingle.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = HalfSingle.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = HalfSingle.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -266,20 +220,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => HalfVector2.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = HalfVector2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = HalfVector2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -293,20 +242,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => HalfVector4.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = HalfVector4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = HalfVector4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -320,20 +264,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => L16.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = L16.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = L16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -347,20 +286,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => L8.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = L8.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = L8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -374,20 +308,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => La16.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = La16.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = La16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -401,20 +330,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => La32.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = La32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = La32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -428,20 +352,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => NormalizedByte2.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = NormalizedByte2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = NormalizedByte2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -455,20 +374,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => NormalizedByte4.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = NormalizedByte4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = NormalizedByte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -482,20 +396,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => NormalizedShort2.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = NormalizedShort2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = NormalizedShort2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -509,20 +418,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => NormalizedShort4.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = NormalizedShort4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = NormalizedShort4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -536,20 +440,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rg32.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rg32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rg32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -563,20 +462,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rgb24.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rgb24.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rgb24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -590,20 +484,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rgb48.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rgb48.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rgb48.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -617,20 +506,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rgba1010102.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rgba1010102.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rgba1010102.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -644,20 +528,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rgba32.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rgba32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rgba32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -671,20 +550,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rgba64.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rgba64.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rgba64.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -698,20 +572,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => RgbaVector.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = RgbaVector.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = RgbaVector.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -725,20 +594,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Short2.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Short2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Short2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -752,20 +616,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Short4.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Short4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Short4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude index bc093be85..50026b3f8 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude @@ -8,7 +8,6 @@ // -using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; using Xunit; using Xunit.Abstractions; @@ -79,20 +78,15 @@ using Xunit.Abstractions; this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType<<#=pixelType#>.PixelOperations>(PixelOperations<<#=pixelType#>>.Instance); + protected override PixelOperations<<#=pixelType#>> Operations => <#=pixelType#>.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = <#=pixelType#>.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf<<#=pixelType#>>() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType<<#=pixelType#>.PixelOperations>(PixelOperations<<#=pixelType#>>.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = <#=pixelType#>.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(<#=alpha#>, alphaRepresentation); } } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index d18c3c860..543184e34 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations protected Configuration Configuration => Configuration.Default; - internal static PixelOperations Operations => PixelOperations.Instance; + protected virtual PixelOperations Operations => PixelOperations.Instance; internal static TPixel[] CreateExpectedPixelData(Vector4[] source, RefAction vectorModifier = null) { @@ -105,6 +105,33 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations return expected; } + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = this.Operations.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelAlphaRepresentation_DefinesPresenceOfAlphaChannel() + { + // We use 0 - 255 as we have pixel formats that store + // the alpha component in less than 8 bits. + const byte Alpha = byte.MinValue; + const byte NoAlpha = byte.MaxValue; + + TPixel pixel = default; + pixel.FromRgba32(new Rgba32(0, 0, 0, Alpha)); + + Rgba32 dest = default; + pixel.ToRgba32(ref dest); + + bool hasAlpha = this.Operations.GetPixelTypeInfo().AlphaRepresentation != PixelAlphaRepresentation.None; + + byte expectedAlpha = hasAlpha ? Alpha : NoAlpha; + Assert.Equal(expectedAlpha, dest.A); + } + [Theory] [MemberData(nameof(ArraySizesData))] public void FromVector4(int count) @@ -115,7 +142,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan())); } [Theory] @@ -131,7 +158,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations (s, d) => { Span destPixels = d.GetSpan(); - Operations.FromVector4Destructive(this.Configuration, (Span)s, destPixels, PixelConversionModifiers.Scale); + this.Operations.FromVector4Destructive(this.Configuration, (Span)s, destPixels, PixelConversionModifiers.Scale); }); } @@ -155,7 +182,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromVector4Destructive( + (s, d) => this.Operations.FromVector4Destructive( this.Configuration, s, d.GetSpan(), @@ -194,7 +221,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations ? PixelConversionModifiers.Premultiply : PixelConversionModifiers.None; - Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan(), modifiers); + this.Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan(), modifiers); }); } @@ -230,7 +257,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations ? PixelConversionModifiers.Premultiply : PixelConversionModifiers.None; - Operations.FromVector4Destructive( + this.Operations.FromVector4Destructive( this.Configuration, s, d.GetSpan(), @@ -274,7 +301,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations ? PixelConversionModifiers.Premultiply : PixelConversionModifiers.None; - Operations.FromVector4Destructive( + this.Operations.FromVector4Destructive( this.Configuration, s, d.GetSpan(), @@ -292,7 +319,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToVector4(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.ToVector4(this.Configuration, s, d.GetSpan())); } public static readonly TheoryData Generic_To_Data = new TheoryData @@ -317,7 +344,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations PixelConverterTests.ReferenceImplementations.To(this.Configuration, source, expected); - TestOperation(source, expected, (s, d) => Operations.To(this.Configuration, (ReadOnlySpan)s, d.GetSpan())); + TestOperation(source, expected, (s, d) => this.Operations.To(this.Configuration, (ReadOnlySpan)s, d.GetSpan())); } [Theory] @@ -333,7 +360,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations (s, d) => { Span destVectors = d.GetSpan(); - Operations.ToVector4(this.Configuration, (ReadOnlySpan)s, destVectors, PixelConversionModifiers.Scale); + this.Operations.ToVector4(this.Configuration, (ReadOnlySpan)s, destVectors, PixelConversionModifiers.Scale); }); } @@ -357,7 +384,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToVector4( + (s, d) => this.Operations.ToVector4( this.Configuration, s, d.GetSpan(), @@ -384,7 +411,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToVector4(this.Configuration, s, d.GetSpan(), PixelConversionModifiers.Premultiply)); + (s, d) => this.Operations.ToVector4(this.Configuration, s, d.GetSpan(), PixelConversionModifiers.Premultiply)); } [Theory] @@ -407,7 +434,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToVector4( + (s, d) => this.Operations.ToVector4( this.Configuration, s, d.GetSpan(), @@ -436,7 +463,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToVector4( + (s, d) => this.Operations.ToVector4( this.Configuration, s, d.GetSpan(), @@ -460,7 +487,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromArgb32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromArgb32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -485,7 +512,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToArgb32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToArgb32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -505,7 +532,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromBgr24Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromBgr24Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -528,7 +555,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToBgr24Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToBgr24Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -548,7 +575,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromBgra32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromBgra32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -572,7 +599,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToBgra32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToBgra32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -594,7 +621,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromBgra5551Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromBgra5551Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -618,7 +645,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToBgra5551Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToBgra5551Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -637,7 +664,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromL8(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.FromL8(this.Configuration, s, d.GetSpan())); } [Theory] @@ -655,7 +682,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToL8(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.ToL8(this.Configuration, s, d.GetSpan())); } [Theory] @@ -679,7 +706,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromL16(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.FromL16(this.Configuration, s, d.GetSpan())); } [Theory] @@ -697,7 +724,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToL16(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.ToL16(this.Configuration, s, d.GetSpan())); } [Theory] @@ -719,7 +746,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromLa16Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromLa16Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -743,7 +770,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToLa16Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToLa16Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -765,7 +792,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromLa32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromLa32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -791,7 +818,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToLa32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToLa32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -811,7 +838,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromRgb24Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromRgb24Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -834,7 +861,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToRgb24Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToRgb24Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -854,7 +881,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromRgba32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromRgba32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -878,7 +905,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToRgba32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToRgba32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -898,7 +925,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromRgb48Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromRgb48Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -925,7 +952,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToRgb48Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToRgb48Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -945,7 +972,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromRgba64Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromRgba64Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -974,7 +1001,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToRgba64Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToRgba64Bytes(this.Configuration, s, d.GetSpan(), count)); } public delegate void RefAction(ref T1 arg1); From 65909fcf5a712a539894b76ed59eb2aad526143a Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 18 Nov 2020 23:05:34 +0000 Subject: [PATCH 08/39] Make PixelTypeInfo lazy --- .../PixelOperations/A8.PixelOperations.cs | 6 +++++- .../PixelOperations/Argb32.PixelOperations.cs | 6 +++++- .../PixelOperations/Bgr24.PixelOperations.cs | 7 +++++-- .../PixelOperations/Bgr565.PixelOperations.cs | 6 +++++- .../PixelOperations/Bgra32.PixelOperations.cs | 7 +++++-- .../PixelOperations/Bgra4444.PixelOperations.cs | 6 +++++- .../PixelOperations/Bgra5551.PixelOperations.cs | 7 +++++-- .../PixelOperations/Byte4.PixelOperations.cs | 6 +++++- .../PixelOperations/HalfSingle.PixelOperations.cs | 6 +++++- .../PixelOperations/HalfVector2.PixelOperations.cs | 6 +++++- .../PixelOperations/HalfVector4.PixelOperations.cs | 6 +++++- .../PixelOperations/L16.PixelOperations.cs | 7 +++++-- .../PixelOperations/L8.PixelOperations.cs | 7 +++++-- .../PixelOperations/La16.PixelOperations.cs | 7 +++++-- .../PixelOperations/La32.PixelOperations.cs | 7 +++++-- .../PixelOperations/NormalizedByte2.PixelOperations.cs | 6 +++++- .../PixelOperations/NormalizedByte4.PixelOperations.cs | 6 +++++- .../PixelOperations/NormalizedShort2.PixelOperations.cs | 6 +++++- .../PixelOperations/NormalizedShort4.PixelOperations.cs | 6 +++++- .../PixelOperations/Rg32.PixelOperations.cs | 6 +++++- .../PixelOperations/Rgb24.PixelOperations.cs | 7 +++++-- .../PixelOperations/Rgb48.PixelOperations.cs | 7 +++++-- .../PixelOperations/Rgba1010102.PixelOperations.cs | 6 +++++- .../PixelOperations/Rgba32.PixelOperations.cs | 6 ++++-- .../PixelOperations/Rgba64.PixelOperations.cs | 7 +++++-- .../PixelOperations/RgbaVector.PixelOperations.cs | 5 ++++- .../PixelOperations/Short2.PixelOperations.cs | 6 +++++- .../PixelOperations/Short4.PixelOperations.cs | 6 +++++- src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs | 4 +++- 29 files changed, 141 insertions(+), 40 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs index 48c2e145a..7482a2e25 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs index f81932955..f8f5715bd 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs index cd77f5816..adae64d5d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,9 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() - => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs index d62761c61..d75b79f5d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs index 849f53835..5f7e516e5 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,9 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() - => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs index 82113299b..eac8e4f17 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs index 4714a8be2..d0470b7a1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,9 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() - => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs index 73411a973..0a2fa10b2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs index afbd3af4c..81b5f76b3 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs index e9cc88c15..228bb5c04 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs index 63b6e3af5..9ef132077 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs index 62d0e6164..3a9c24f46 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,9 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() - => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs index 5da55ffb4..18a9a4c8a 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,9 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() - => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs index feb4b65fd..bd7ddaebb 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,9 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() - => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs index f69e6c185..c0e6cdd4f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,9 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() - => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs index f0f513860..8d2739b2c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs index 8874f1241..7825d1679 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs index a53587a06..35cf605c1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs index 6a3dc505f..d298c85f5 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs index c079d1e5b..c0a5ae920 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs index c4c6ac8ad..73b656f36 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,9 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() - => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs index bbe12315f..4c26f1b0f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,9 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() - => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs index b13fe2ec8..60fa98ed1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs index bc4454859..d8322e37d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs @@ -19,9 +19,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() - => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; /// public override void ToVector4( diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs index e953a378e..055b87286 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,9 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() - => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs index 11ef90e49..1605d862e 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs @@ -20,8 +20,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; /// public override void FromVector4Destructive( diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs index 942e40f94..e8a6bac3a 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.None); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs index b2d743f87..8b99713d6 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp.PixelFormats @@ -15,8 +16,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal class PixelOperations : PixelOperations { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; } } } diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs index 14ad120bf..dbe06702d 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs @@ -17,6 +17,8 @@ namespace SixLabors.ImageSharp.PixelFormats public partial class PixelOperations where TPixel : unmanaged, IPixel { + private static readonly Lazy LazyInfo = new Lazy(() => PixelTypeInfo.Create(), true); + /// /// Gets the global instance for the pixel type /// @@ -26,7 +28,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Gets the pixel type info for the given . /// /// The . - public virtual PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(); + public virtual PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; /// /// Bulk version of converting 'sourceVectors.Length' pixels into 'destinationColors'. From b1eb8fac002d248680fa70e23582c691ad74414f Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 18 Nov 2020 23:32:51 +0000 Subject: [PATCH 09/39] Move property to base. --- ...elOperationsTests.Specialized.Generated.cs | 56 ------------------- .../Generated/_Common.ttinclude | 2 - .../PixelOperations/PixelOperationsTests.cs | 15 ++--- 3 files changed, 6 insertions(+), 67 deletions(-) diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs index 9d6ec8960..1069eb9ac 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs @@ -18,8 +18,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public A8_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = A8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => A8.PixelOperations.Instance; @@ -40,8 +38,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Argb32_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Argb32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Argb32.PixelOperations.Instance; @@ -62,8 +58,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgr24_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Bgr24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Bgr24.PixelOperations.Instance; @@ -84,8 +78,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgr565_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Bgr565.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Bgr565.PixelOperations.Instance; @@ -106,8 +98,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgra32_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Bgra32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Bgra32.PixelOperations.Instance; @@ -128,8 +118,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgra4444_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Bgra4444.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Bgra4444.PixelOperations.Instance; @@ -150,8 +138,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgra5551_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Bgra5551.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Bgra5551.PixelOperations.Instance; @@ -172,8 +158,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Byte4_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Byte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Byte4.PixelOperations.Instance; @@ -194,8 +178,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public HalfSingle_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = HalfSingle.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => HalfSingle.PixelOperations.Instance; @@ -216,8 +198,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public HalfVector2_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = HalfVector2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => HalfVector2.PixelOperations.Instance; @@ -238,8 +218,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public HalfVector4_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = HalfVector4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => HalfVector4.PixelOperations.Instance; @@ -260,8 +238,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public L16_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = L16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => L16.PixelOperations.Instance; @@ -282,8 +258,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public L8_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = L8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => L8.PixelOperations.Instance; @@ -304,8 +278,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public La16_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = La16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => La16.PixelOperations.Instance; @@ -326,8 +298,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public La32_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = La32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => La32.PixelOperations.Instance; @@ -348,8 +318,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedByte2_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = NormalizedByte2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => NormalizedByte2.PixelOperations.Instance; @@ -370,8 +338,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedByte4_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = NormalizedByte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => NormalizedByte4.PixelOperations.Instance; @@ -392,8 +358,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedShort2_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = NormalizedShort2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => NormalizedShort2.PixelOperations.Instance; @@ -414,8 +378,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedShort4_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = NormalizedShort4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => NormalizedShort4.PixelOperations.Instance; @@ -436,8 +398,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rg32_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Rg32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Rg32.PixelOperations.Instance; @@ -458,8 +418,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgb24_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Rgb24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Rgb24.PixelOperations.Instance; @@ -480,8 +438,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgb48_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Rgb48.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Rgb48.PixelOperations.Instance; @@ -502,8 +458,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgba1010102_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Rgba1010102.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Rgba1010102.PixelOperations.Instance; @@ -524,8 +478,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgba32_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Rgba32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Rgba32.PixelOperations.Instance; @@ -546,8 +498,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgba64_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Rgba64.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Rgba64.PixelOperations.Instance; @@ -568,8 +518,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public RgbaVector_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = RgbaVector.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => RgbaVector.PixelOperations.Instance; @@ -590,8 +538,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Short2_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Short2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Short2.PixelOperations.Instance; @@ -612,8 +558,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Short4_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = Short4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations Operations => Short4.PixelOperations.Instance; diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude index 50026b3f8..8c436eecc 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude @@ -74,8 +74,6 @@ using Xunit.Abstractions; public <#=pixelType#>_OperationsTests(ITestOutputHelper output) : base(output) { - var alphaRepresentation = <#=pixelType#>.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; - this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } protected override PixelOperations<<#=pixelType#>> Operations => <#=pixelType#>.PixelOperations.Instance; diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index 543184e34..059a21803 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -36,8 +36,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations null; #endif - protected bool HasUnassociatedAlpha { get; set; } = true; - protected PixelOperationsTests(ITestOutputHelper output) : base(output) { @@ -73,7 +71,9 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations protected Configuration Configuration => Configuration.Default; - protected virtual PixelOperations Operations => PixelOperations.Instance; + protected virtual PixelOperations Operations { get; } = PixelOperations.Instance; + + protected bool HasUnassociatedAlpha => this.Operations.GetPixelTypeInfo().AlphaRepresentation == PixelAlphaRepresentation.Unassociated; internal static TPixel[] CreateExpectedPixelData(Vector4[] source, RefAction vectorModifier = null) { @@ -217,8 +217,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations expected, (s, d) => { - PixelConversionModifiers modifiers = this.HasUnassociatedAlpha - ? PixelConversionModifiers.Premultiply + PixelConversionModifiers modifiers = this.HasUnassociatedAlpha ? PixelConversionModifiers.Premultiply : PixelConversionModifiers.None; this.Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan(), modifiers); @@ -253,8 +252,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations expected, (s, d) => { - PixelConversionModifiers modifiers = this.HasUnassociatedAlpha - ? PixelConversionModifiers.Premultiply + PixelConversionModifiers modifiers = this.HasUnassociatedAlpha ? PixelConversionModifiers.Premultiply : PixelConversionModifiers.None; this.Operations.FromVector4Destructive( @@ -297,8 +295,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations expected, (s, d) => { - PixelConversionModifiers modifiers = this.HasUnassociatedAlpha - ? PixelConversionModifiers.Premultiply + PixelConversionModifiers modifiers = this.HasUnassociatedAlpha ? PixelConversionModifiers.Premultiply : PixelConversionModifiers.None; this.Operations.FromVector4Destructive( From 204951d4db9e03114f114815c254f1f7965fa515 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 20 Nov 2020 21:44:38 +0000 Subject: [PATCH 10/39] Enable resize tests --- .gitignore | 1 + .../Processing/Processors/Transforms/ResizeTests.cs | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a89cfcf10..475d6e76b 100644 --- a/.gitignore +++ b/.gitignore @@ -221,3 +221,4 @@ artifacts/ # Tests **/Images/ActualOutput **/Images/ReferenceOutput +.DS_Store diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index 47d951837..f40b8d11a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -355,7 +355,6 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms } [Theory] - [PlatformSpecific(~TestPlatforms.OSX)] [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] public void ResizeFromSourceRectangle(TestImageProvider provider) where TPixel : unmanaged, IPixel @@ -438,7 +437,6 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms } [Theory] - [PlatformSpecific(~TestPlatforms.OSX)] [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] public void ResizeWithBoxPadMode(TestImageProvider provider) where TPixel : unmanaged, IPixel @@ -549,7 +547,6 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms } [Theory] - [PlatformSpecific(~TestPlatforms.OSX)] [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] public void ResizeWithPadMode(TestImageProvider provider) where TPixel : unmanaged, IPixel From c719148a43e1ff6a87ade71b7c308635415cf5f7 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 21 Nov 2020 00:14:40 +0000 Subject: [PATCH 11/39] Use doubles in ResizeHelper --- .../Transforms/Resize/ResizeHelper.cs | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs index 5ff82a096..2414305b8 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs @@ -47,12 +47,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms const int Min = 1; if (width == 0 && height > 0) { - width = (int)MathF.Max(Min, MathF.Round(sourceSize.Width * height / (float)sourceSize.Height)); + width = (int)Math.Max(Min, Math.Round(sourceSize.Width * height / (double)sourceSize.Height)); } if (height == 0 && width > 0) { - height = (int)MathF.Max(Min, MathF.Round(sourceSize.Height * width / (float)sourceSize.Width)); + height = (int)Math.Max(Min, Math.Round(sourceSize.Height * width / (double)sourceSize.Width)); } switch (options.Mode) @@ -86,11 +86,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int sourceHeight = source.Height; // Fractional variants for preserving aspect ratio. - float percentHeight = MathF.Abs(height / (float)sourceHeight); - float percentWidth = MathF.Abs(width / (float)sourceWidth); + double percentHeight = Math.Abs(height / (double)sourceHeight); + double percentWidth = Math.Abs(width / (double)sourceWidth); - int boxPadHeight = height > 0 ? height : (int)MathF.Round(sourceHeight * percentWidth); - int boxPadWidth = width > 0 ? width : (int)MathF.Round(sourceWidth * percentHeight); + int boxPadHeight = height > 0 ? height : (int)Math.Round(sourceHeight * percentWidth); + int boxPadWidth = width > 0 ? width : (int)Math.Round(sourceWidth * percentHeight); // Only calculate if upscaling. if (sourceWidth < boxPadWidth && sourceHeight < boxPadHeight) @@ -156,7 +156,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int width, int height) { - float ratio; + double ratio; int sourceWidth = source.Width; int sourceHeight = source.Height; @@ -166,8 +166,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int targetHeight = height; // Fractional variants for preserving aspect ratio. - float percentHeight = MathF.Abs(height / (float)sourceHeight); - float percentWidth = MathF.Abs(width / (float)sourceWidth); + double percentHeight = Math.Abs(height / (double)sourceHeight); + double percentWidth = Math.Abs(width / (double)sourceWidth); if (percentHeight < percentWidth) { @@ -175,17 +175,17 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms if (options.CenterCoordinates.HasValue) { - float center = -(ratio * sourceHeight) * options.CenterCoordinates.Value.Y; - targetY = (int)MathF.Round(center + (height / 2F)); + double center = -(ratio * sourceHeight) * options.CenterCoordinates.Value.Y; + targetY = (int)Math.Round(center + (height / 2F)); if (targetY > 0) { targetY = 0; } - if (targetY < (int)MathF.Round(height - (sourceHeight * ratio))) + if (targetY < (int)Math.Round(height - (sourceHeight * ratio))) { - targetY = (int)MathF.Round(height - (sourceHeight * ratio)); + targetY = (int)Math.Round(height - (sourceHeight * ratio)); } } else @@ -200,15 +200,15 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms case AnchorPositionMode.Bottom: case AnchorPositionMode.BottomLeft: case AnchorPositionMode.BottomRight: - targetY = (int)MathF.Round(height - (sourceHeight * ratio)); + targetY = (int)Math.Round(height - (sourceHeight * ratio)); break; default: - targetY = (int)MathF.Round((height - (sourceHeight * ratio)) / 2F); + targetY = (int)Math.Round((height - (sourceHeight * ratio)) / 2F); break; } } - targetHeight = (int)MathF.Ceiling(sourceHeight * percentWidth); + targetHeight = (int)Math.Ceiling(sourceHeight * percentWidth); } else { @@ -216,17 +216,17 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms if (options.CenterCoordinates.HasValue) { - float center = -(ratio * sourceWidth) * options.CenterCoordinates.Value.X; - targetX = (int)MathF.Round(center + (width / 2F)); + double center = -(ratio * sourceWidth) * options.CenterCoordinates.Value.X; + targetX = (int)Math.Round(center + (width / 2F)); if (targetX > 0) { targetX = 0; } - if (targetX < (int)MathF.Round(width - (sourceWidth * ratio))) + if (targetX < (int)Math.Round(width - (sourceWidth * ratio))) { - targetX = (int)MathF.Round(width - (sourceWidth * ratio)); + targetX = (int)Math.Round(width - (sourceWidth * ratio)); } } else @@ -241,15 +241,15 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms case AnchorPositionMode.Right: case AnchorPositionMode.TopRight: case AnchorPositionMode.BottomRight: - targetX = (int)MathF.Round(width - (sourceWidth * ratio)); + targetX = (int)Math.Round(width - (sourceWidth * ratio)); break; default: - targetX = (int)MathF.Round((width - (sourceWidth * ratio)) / 2F); + targetX = (int)Math.Round((width - (sourceWidth * ratio)) / 2F); break; } } - targetWidth = (int)MathF.Ceiling(sourceWidth * percentHeight); + targetWidth = (int)Math.Ceiling(sourceWidth * percentHeight); } // Target image width and height can be different to the rectangle width and height. @@ -265,20 +265,20 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int targetHeight = height; // Fractional variants for preserving aspect ratio. - float percentHeight = MathF.Abs(height / (float)source.Height); - float percentWidth = MathF.Abs(width / (float)source.Width); + double percentHeight = Math.Abs(height / (double)source.Height); + double percentWidth = Math.Abs(width / (double)source.Width); - // Integers must be cast to floats to get needed precision - float ratio = height / (float)width; - float sourceRatio = source.Height / (float)source.Width; + // Integers must be cast to doubles to get needed precision + double ratio = height / (double)width; + double sourceRatio = source.Height / (double)source.Width; if (sourceRatio < ratio) { - targetHeight = (int)MathF.Round(source.Height * percentWidth); + targetHeight = (int)Math.Round(source.Height * percentWidth); } else { - targetWidth = (int)MathF.Round(source.Width * percentHeight); + targetWidth = (int)Math.Round(source.Width * percentHeight); } // Replace the size to match the rectangle. @@ -307,25 +307,25 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms if (widthDiff < heightDiff) { - float sourceRatio = (float)sourceHeight / sourceWidth; - targetHeight = (int)MathF.Round(width * sourceRatio); + double sourceRatio = (double)sourceHeight / sourceWidth; + targetHeight = (int)Math.Round(width * sourceRatio); } else if (widthDiff > heightDiff) { - float sourceRatioInverse = (float)sourceWidth / sourceHeight; - targetWidth = (int)MathF.Round(height * sourceRatioInverse); + double sourceRatioInverse = (double)sourceWidth / sourceHeight; + targetWidth = (int)Math.Round(height * sourceRatioInverse); } else { if (height > width) { - float percentWidth = MathF.Abs(width / (float)sourceWidth); - targetHeight = (int)MathF.Round(sourceHeight * percentWidth); + double percentWidth = Math.Abs(width / (double)sourceWidth); + targetHeight = (int)Math.Round(sourceHeight * percentWidth); } else { - float percentHeight = MathF.Abs(height / (float)sourceHeight); - targetWidth = (int)MathF.Round(sourceWidth * percentHeight); + double percentHeight = Math.Abs(height / (double)sourceHeight); + targetWidth = (int)Math.Round(sourceWidth * percentHeight); } } @@ -339,7 +339,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int width, int height) { - float ratio; + double ratio; int sourceWidth = sourceSize.Width; int sourceHeight = sourceSize.Height; @@ -349,13 +349,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int targetHeight = height; // Fractional variants for preserving aspect ratio. - float percentHeight = MathF.Abs(height / (float)sourceHeight); - float percentWidth = MathF.Abs(width / (float)sourceWidth); + double percentHeight = Math.Abs(height / (double)sourceHeight); + double percentWidth = Math.Abs(width / (double)sourceWidth); if (percentHeight < percentWidth) { ratio = percentHeight; - targetWidth = (int)MathF.Round(sourceWidth * percentHeight); + targetWidth = (int)Math.Round(sourceWidth * percentHeight); switch (options.Position) { @@ -367,17 +367,17 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms case AnchorPositionMode.Right: case AnchorPositionMode.TopRight: case AnchorPositionMode.BottomRight: - targetX = (int)MathF.Round(width - (sourceWidth * ratio)); + targetX = (int)Math.Round(width - (sourceWidth * ratio)); break; default: - targetX = (int)MathF.Round((width - (sourceWidth * ratio)) / 2F); + targetX = (int)Math.Round((width - (sourceWidth * ratio)) / 2F); break; } } else { ratio = percentWidth; - targetHeight = (int)MathF.Round(sourceHeight * percentWidth); + targetHeight = (int)Math.Round(sourceHeight * percentWidth); switch (options.Position) { @@ -389,10 +389,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms case AnchorPositionMode.Bottom: case AnchorPositionMode.BottomLeft: case AnchorPositionMode.BottomRight: - targetY = (int)MathF.Round(height - (sourceHeight * ratio)); + targetY = (int)Math.Round(height - (sourceHeight * ratio)); break; default: - targetY = (int)MathF.Round((height - (sourceHeight * ratio)) / 2F); + targetY = (int)Math.Round((height - (sourceHeight * ratio)) / 2F); break; } } From 3cc5f81a79c6b7bbf8cbd5b10fb642ae491be483 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 21 Nov 2020 00:21:44 +0000 Subject: [PATCH 12/39] Revert "Use doubles in ResizeHelper" This reverts commit 2e3f3c1e390df3be2fe547b524fa6ea9200b2d0b. --- .../Transforms/Resize/ResizeHelper.cs | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs index 2414305b8..5ff82a096 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs @@ -47,12 +47,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms const int Min = 1; if (width == 0 && height > 0) { - width = (int)Math.Max(Min, Math.Round(sourceSize.Width * height / (double)sourceSize.Height)); + width = (int)MathF.Max(Min, MathF.Round(sourceSize.Width * height / (float)sourceSize.Height)); } if (height == 0 && width > 0) { - height = (int)Math.Max(Min, Math.Round(sourceSize.Height * width / (double)sourceSize.Width)); + height = (int)MathF.Max(Min, MathF.Round(sourceSize.Height * width / (float)sourceSize.Width)); } switch (options.Mode) @@ -86,11 +86,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int sourceHeight = source.Height; // Fractional variants for preserving aspect ratio. - double percentHeight = Math.Abs(height / (double)sourceHeight); - double percentWidth = Math.Abs(width / (double)sourceWidth); + float percentHeight = MathF.Abs(height / (float)sourceHeight); + float percentWidth = MathF.Abs(width / (float)sourceWidth); - int boxPadHeight = height > 0 ? height : (int)Math.Round(sourceHeight * percentWidth); - int boxPadWidth = width > 0 ? width : (int)Math.Round(sourceWidth * percentHeight); + int boxPadHeight = height > 0 ? height : (int)MathF.Round(sourceHeight * percentWidth); + int boxPadWidth = width > 0 ? width : (int)MathF.Round(sourceWidth * percentHeight); // Only calculate if upscaling. if (sourceWidth < boxPadWidth && sourceHeight < boxPadHeight) @@ -156,7 +156,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int width, int height) { - double ratio; + float ratio; int sourceWidth = source.Width; int sourceHeight = source.Height; @@ -166,8 +166,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int targetHeight = height; // Fractional variants for preserving aspect ratio. - double percentHeight = Math.Abs(height / (double)sourceHeight); - double percentWidth = Math.Abs(width / (double)sourceWidth); + float percentHeight = MathF.Abs(height / (float)sourceHeight); + float percentWidth = MathF.Abs(width / (float)sourceWidth); if (percentHeight < percentWidth) { @@ -175,17 +175,17 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms if (options.CenterCoordinates.HasValue) { - double center = -(ratio * sourceHeight) * options.CenterCoordinates.Value.Y; - targetY = (int)Math.Round(center + (height / 2F)); + float center = -(ratio * sourceHeight) * options.CenterCoordinates.Value.Y; + targetY = (int)MathF.Round(center + (height / 2F)); if (targetY > 0) { targetY = 0; } - if (targetY < (int)Math.Round(height - (sourceHeight * ratio))) + if (targetY < (int)MathF.Round(height - (sourceHeight * ratio))) { - targetY = (int)Math.Round(height - (sourceHeight * ratio)); + targetY = (int)MathF.Round(height - (sourceHeight * ratio)); } } else @@ -200,15 +200,15 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms case AnchorPositionMode.Bottom: case AnchorPositionMode.BottomLeft: case AnchorPositionMode.BottomRight: - targetY = (int)Math.Round(height - (sourceHeight * ratio)); + targetY = (int)MathF.Round(height - (sourceHeight * ratio)); break; default: - targetY = (int)Math.Round((height - (sourceHeight * ratio)) / 2F); + targetY = (int)MathF.Round((height - (sourceHeight * ratio)) / 2F); break; } } - targetHeight = (int)Math.Ceiling(sourceHeight * percentWidth); + targetHeight = (int)MathF.Ceiling(sourceHeight * percentWidth); } else { @@ -216,17 +216,17 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms if (options.CenterCoordinates.HasValue) { - double center = -(ratio * sourceWidth) * options.CenterCoordinates.Value.X; - targetX = (int)Math.Round(center + (width / 2F)); + float center = -(ratio * sourceWidth) * options.CenterCoordinates.Value.X; + targetX = (int)MathF.Round(center + (width / 2F)); if (targetX > 0) { targetX = 0; } - if (targetX < (int)Math.Round(width - (sourceWidth * ratio))) + if (targetX < (int)MathF.Round(width - (sourceWidth * ratio))) { - targetX = (int)Math.Round(width - (sourceWidth * ratio)); + targetX = (int)MathF.Round(width - (sourceWidth * ratio)); } } else @@ -241,15 +241,15 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms case AnchorPositionMode.Right: case AnchorPositionMode.TopRight: case AnchorPositionMode.BottomRight: - targetX = (int)Math.Round(width - (sourceWidth * ratio)); + targetX = (int)MathF.Round(width - (sourceWidth * ratio)); break; default: - targetX = (int)Math.Round((width - (sourceWidth * ratio)) / 2F); + targetX = (int)MathF.Round((width - (sourceWidth * ratio)) / 2F); break; } } - targetWidth = (int)Math.Ceiling(sourceWidth * percentHeight); + targetWidth = (int)MathF.Ceiling(sourceWidth * percentHeight); } // Target image width and height can be different to the rectangle width and height. @@ -265,20 +265,20 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int targetHeight = height; // Fractional variants for preserving aspect ratio. - double percentHeight = Math.Abs(height / (double)source.Height); - double percentWidth = Math.Abs(width / (double)source.Width); + float percentHeight = MathF.Abs(height / (float)source.Height); + float percentWidth = MathF.Abs(width / (float)source.Width); - // Integers must be cast to doubles to get needed precision - double ratio = height / (double)width; - double sourceRatio = source.Height / (double)source.Width; + // Integers must be cast to floats to get needed precision + float ratio = height / (float)width; + float sourceRatio = source.Height / (float)source.Width; if (sourceRatio < ratio) { - targetHeight = (int)Math.Round(source.Height * percentWidth); + targetHeight = (int)MathF.Round(source.Height * percentWidth); } else { - targetWidth = (int)Math.Round(source.Width * percentHeight); + targetWidth = (int)MathF.Round(source.Width * percentHeight); } // Replace the size to match the rectangle. @@ -307,25 +307,25 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms if (widthDiff < heightDiff) { - double sourceRatio = (double)sourceHeight / sourceWidth; - targetHeight = (int)Math.Round(width * sourceRatio); + float sourceRatio = (float)sourceHeight / sourceWidth; + targetHeight = (int)MathF.Round(width * sourceRatio); } else if (widthDiff > heightDiff) { - double sourceRatioInverse = (double)sourceWidth / sourceHeight; - targetWidth = (int)Math.Round(height * sourceRatioInverse); + float sourceRatioInverse = (float)sourceWidth / sourceHeight; + targetWidth = (int)MathF.Round(height * sourceRatioInverse); } else { if (height > width) { - double percentWidth = Math.Abs(width / (double)sourceWidth); - targetHeight = (int)Math.Round(sourceHeight * percentWidth); + float percentWidth = MathF.Abs(width / (float)sourceWidth); + targetHeight = (int)MathF.Round(sourceHeight * percentWidth); } else { - double percentHeight = Math.Abs(height / (double)sourceHeight); - targetWidth = (int)Math.Round(sourceWidth * percentHeight); + float percentHeight = MathF.Abs(height / (float)sourceHeight); + targetWidth = (int)MathF.Round(sourceWidth * percentHeight); } } @@ -339,7 +339,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int width, int height) { - double ratio; + float ratio; int sourceWidth = sourceSize.Width; int sourceHeight = sourceSize.Height; @@ -349,13 +349,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int targetHeight = height; // Fractional variants for preserving aspect ratio. - double percentHeight = Math.Abs(height / (double)sourceHeight); - double percentWidth = Math.Abs(width / (double)sourceWidth); + float percentHeight = MathF.Abs(height / (float)sourceHeight); + float percentWidth = MathF.Abs(width / (float)sourceWidth); if (percentHeight < percentWidth) { ratio = percentHeight; - targetWidth = (int)Math.Round(sourceWidth * percentHeight); + targetWidth = (int)MathF.Round(sourceWidth * percentHeight); switch (options.Position) { @@ -367,17 +367,17 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms case AnchorPositionMode.Right: case AnchorPositionMode.TopRight: case AnchorPositionMode.BottomRight: - targetX = (int)Math.Round(width - (sourceWidth * ratio)); + targetX = (int)MathF.Round(width - (sourceWidth * ratio)); break; default: - targetX = (int)Math.Round((width - (sourceWidth * ratio)) / 2F); + targetX = (int)MathF.Round((width - (sourceWidth * ratio)) / 2F); break; } } else { ratio = percentWidth; - targetHeight = (int)Math.Round(sourceHeight * percentWidth); + targetHeight = (int)MathF.Round(sourceHeight * percentWidth); switch (options.Position) { @@ -389,10 +389,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms case AnchorPositionMode.Bottom: case AnchorPositionMode.BottomLeft: case AnchorPositionMode.BottomRight: - targetY = (int)Math.Round(height - (sourceHeight * ratio)); + targetY = (int)MathF.Round(height - (sourceHeight * ratio)); break; default: - targetY = (int)Math.Round((height - (sourceHeight * ratio)) / 2F); + targetY = (int)MathF.Round((height - (sourceHeight * ratio)) / 2F); break; } } From 46f47eb97b2dac86f9b79f4eaed2c8c2c0e026ce Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 21 Nov 2020 00:26:38 +0000 Subject: [PATCH 13/39] Use higher tolerance on macOS CI runs --- .../Processing/Processors/Transforms/ResizeTests.cs | 3 ++- tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index f40b8d11a..daf217a5a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -35,7 +35,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms nameof(KnownResamplers.Lanczos5), }; - private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.07F); + private static readonly ImageComparer ValidatorComparer = + ImageComparer.TolerantPercentage(TestEnvironment.IsOSX && TestEnvironment.RunsOnCI ? 0.2595F : 0.07F); [Fact] public void Resize_PixelAgnostic() diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs index 48728faf0..b80a29646 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs @@ -108,6 +108,8 @@ namespace SixLabors.ImageSharp.Tests internal static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + internal static bool IsOSX => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + internal static bool IsMono => Type.GetType("Mono.Runtime") != null; // https://stackoverflow.com/a/721194 internal static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); From 12a62739f3866742e79a7ecd349ae5686cdf1b5d Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 21 Nov 2020 00:31:52 +0000 Subject: [PATCH 14/39] Bump tolerance --- .../Processing/Processors/Transforms/ResizeTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index daf217a5a..4a20f4e56 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms }; private static readonly ImageComparer ValidatorComparer = - ImageComparer.TolerantPercentage(TestEnvironment.IsOSX && TestEnvironment.RunsOnCI ? 0.2595F : 0.07F); + ImageComparer.TolerantPercentage(TestEnvironment.IsOSX && TestEnvironment.RunsOnCI ? 0.26F : 0.07F); [Fact] public void Resize_PixelAgnostic() From 9236cb1269a02deb05ab7d19ea6ee2877be40edc Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 21 Nov 2020 16:50:58 +0100 Subject: [PATCH 15/39] Added missing RgbaVector conversion override --- .../PixelOperations/RgbaVector.PixelOperations.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs index 1605d862e..c66526bbe 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs @@ -26,6 +26,17 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; + /// + public override void From( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Span destinationVectors = MemoryMarshal.Cast(destinationPixels); + + PixelOperations.Instance.ToVector4(configuration, sourcePixels, destinationVectors); + } + /// public override void FromVector4Destructive( Configuration configuration, From e9f734a9439924c2ec1ff4caf360dd4a959f9b71 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 22 Nov 2020 23:48:31 +0000 Subject: [PATCH 16/39] Introduce Numerics and migrate ImageMaths methods --- .../ColorSpaces/Companding/LCompanding.cs | 2 +- .../Converters/CieLabToCieXyzConverter.cs | 6 +- .../Converters/CieLuvToCieXyzConverter.cs | 6 +- .../Converters/HunterLabToCieXyzConverter.cs | 2 +- src/ImageSharp/Common/Helpers/ImageMaths.cs | 124 +----- src/ImageSharp/Common/Helpers/Numerics.cs | 417 ++++++++++++++++++ .../Common/Helpers/Shuffle/IShuffle4Slice3.cs | 2 +- .../Helpers/SimdUtils.BasicIntrinsics256.cs | 4 +- .../Helpers/SimdUtils.ExtendedIntrinsics.cs | 4 +- .../SimdUtils.FallbackIntrinsics128.cs | 4 +- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 24 +- src/ImageSharp/Common/Helpers/SimdUtils.cs | 4 +- .../Common/Helpers/Vector4Utilities.cs | 4 +- .../Formats/Png/Filters/AverageFilter.cs | 8 +- .../Formats/Png/Filters/PaethFilter.cs | 14 +- .../Formats/Png/Filters/SubFilter.cs | 4 +- .../Formats/Png/Filters/UpFilter.cs | 2 +- src/ImageSharp/Primitives/ComplexVector4.cs | 2 +- .../ConvolutionProcessorHelpers.cs | 6 +- ...alizationSlidingWindowProcessor{TPixel}.cs | 4 +- .../Transforms/Resamplers/LanczosResampler.cs | 2 +- .../Transforms/Resamplers/WelchResampler.cs | 2 +- .../Transforms/Resize/ResizeKernelMap.cs | 2 +- .../General/BasicMath/ClampSpan.cs | 42 ++ .../BasicMath/ModuloPowerOfTwoConstant.cs | 2 +- .../BasicMath/ModuloPowerOfTwoVariable.cs | 2 +- .../Helpers/ImageMathsTests.cs | 138 ------ .../ImageSharp.Tests/Helpers/NumericsTests.cs | 265 +++++++++++ 28 files changed, 781 insertions(+), 317 deletions(-) create mode 100644 src/ImageSharp/Common/Helpers/Numerics.cs create mode 100644 tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs create mode 100644 tests/ImageSharp.Tests/Helpers/NumericsTests.cs diff --git a/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs b/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs index 719565fd8..5cd89abfd 100644 --- a/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs +++ b/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Companding /// The representing the linear channel value. [MethodImpl(InliningOptions.ShortMethod)] public static float Expand(float channel) - => channel <= 0.08F ? (100F * channel) / CieConstants.Kappa : ImageMaths.Pow3((channel + 0.16F) / 1.16F); + => channel <= 0.08F ? (100F * channel) / CieConstants.Kappa : Numerics.Pow3((channel + 0.16F) / 1.16F); /// /// Compresses an uncompanded channel (linear) to its nonlinear equivalent. diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs index 31c3f4633..34354efe5 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs @@ -25,11 +25,11 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion float fx = (a / 500F) + fy; float fz = fy - (b / 200F); - float fx3 = ImageMaths.Pow3(fx); - float fz3 = ImageMaths.Pow3(fz); + float fx3 = Numerics.Pow3(fx); + float fz3 = Numerics.Pow3(fz); float xr = fx3 > CieConstants.Epsilon ? fx3 : ((116F * fx) - 16F) / CieConstants.Kappa; - float yr = l > CieConstants.Kappa * CieConstants.Epsilon ? ImageMaths.Pow3((l + 16F) / 116F) : l / CieConstants.Kappa; + float yr = l > CieConstants.Kappa * CieConstants.Epsilon ? Numerics.Pow3((l + 16F) / 116F) : l / CieConstants.Kappa; float zr = fz3 > CieConstants.Epsilon ? fz3 : ((116F * fz) - 16F) / CieConstants.Kappa; var wxyz = new Vector3(input.WhitePoint.X, input.WhitePoint.Y, input.WhitePoint.Z); diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs index 7f15fc77d..12c65105f 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. using System.Runtime.CompilerServices; @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion float v0 = ComputeV0(input.WhitePoint); float y = l > CieConstants.Kappa * CieConstants.Epsilon - ? ImageMaths.Pow3((l + 16) / 116) + ? Numerics.Pow3((l + 16) / 116) : l / CieConstants.Kappa; float a = ((52 * l / (u + (13 * l * u0))) - 1) / 3; @@ -71,4 +71,4 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion private static float ComputeV0(in CieXyz input) => (9 * input.Y) / (input.X + (15 * input.Y) + (3 * input.Z)); } -} \ No newline at end of file +} diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs index 4c3cdba22..f120d6f3d 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion float ka = ComputeKa(input.WhitePoint); float kb = ComputeKb(input.WhitePoint); - float pow = ImageMaths.Pow2(l / 100F); + float pow = Numerics.Pow2(l / 100F); float sqrtPow = MathF.Sqrt(pow); float y = pow * yn; diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMaths.cs index d24230fe1..55ac6f822 100644 --- a/src/ImageSharp/Common/Helpers/ImageMaths.cs +++ b/src/ImageSharp/Common/Helpers/ImageMaths.cs @@ -4,13 +4,12 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; - using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp { /// - /// Provides common mathematical methods. + /// Provides common mathematical methods used for image processing. /// internal static class ImageMaths { @@ -108,85 +107,6 @@ namespace SixLabors.ImageSharp [MethodImpl(InliningOptions.ShortMethod)] public static ushort UpscaleFrom8BitTo16Bit(byte component) => (ushort)(component * 257); - /// - /// Determine the Greatest CommonDivisor (GCD) of two numbers. - /// - public static int GreatestCommonDivisor(int a, int b) - { - while (b != 0) - { - int temp = b; - b = a % b; - a = temp; - } - - return a; - } - - /// - /// Determine the Least Common Multiple (LCM) of two numbers. - /// - public static int LeastCommonMultiple(int a, int b) - { - // https://en.wikipedia.org/wiki/Least_common_multiple#Reduction_by_the_greatest_common_divisor - return (a / GreatestCommonDivisor(a, b)) * b; - } - - /// - /// Calculates % 2 - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static int Modulo2(int x) => x & 1; - - /// - /// Calculates % 4 - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static int Modulo4(int x) => x & 3; - - /// - /// Calculates % 8 - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static int Modulo8(int x) => x & 7; - - /// - /// Fast (x mod m) calculator, with the restriction that - /// should be power of 2. - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static int ModuloP2(int x, int m) => x & (m - 1); - - /// - /// Returns the absolute value of a 32-bit signed integer. Uses bit shifting to speed up the operation. - /// - /// - /// A number that is greater than , but less than or equal to - /// - /// The - [MethodImpl(InliningOptions.ShortMethod)] - public static int FastAbs(int x) - { - int y = x >> 31; - return (x ^ y) - y; - } - - /// - /// Returns a specified number raised to the power of 2 - /// - /// A single-precision floating-point number - /// The number raised to the power of 2. - [MethodImpl(InliningOptions.ShortMethod)] - public static float Pow2(float x) => x * x; - - /// - /// Returns a specified number raised to the power of 3 - /// - /// A single-precision floating-point number - /// The number raised to the power of 3. - [MethodImpl(InliningOptions.ShortMethod)] - public static float Pow3(float x) => x * x * x; - /// /// Returns how many bits are required to store the specified number of colors. /// Performs a Log2() on the value. @@ -206,48 +126,6 @@ namespace SixLabors.ImageSharp [MethodImpl(InliningOptions.ShortMethod)] public static int GetColorCountForBitDepth(int bitDepth) => 1 << bitDepth; - /// - /// Implementation of 1D Gaussian G(x) function - /// - /// The x provided to G(x). - /// The spread of the blur. - /// The Gaussian G(x) - [MethodImpl(InliningOptions.ShortMethod)] - public static float Gaussian(float x, float sigma) - { - const float Numerator = 1.0f; - float denominator = MathF.Sqrt(2 * MathF.PI) * sigma; - - float exponentNumerator = -x * x; - float exponentDenominator = 2 * Pow2(sigma); - - float left = Numerator / denominator; - float right = MathF.Exp(exponentNumerator / exponentDenominator); - - return left * right; - } - - /// - /// Returns the result of a normalized sine cardinal function for the given value. - /// SinC(x) = sin(pi*x)/(pi*x). - /// - /// A single-precision floating-point number to calculate the result for. - /// - /// The sine cardinal of . - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static float SinC(float f) - { - if (MathF.Abs(f) > Constants.Epsilon) - { - f *= MathF.PI; - float result = MathF.Sin(f) / f; - return MathF.Abs(result) < Constants.Epsilon ? 0F : result; - } - - return 1F; - } - /// /// Gets the bounding from the given points. /// diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs new file mode 100644 index 000000000..d4dfa1202 --- /dev/null +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -0,0 +1,417 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace SixLabors.ImageSharp +{ + /// + /// Provides optimized static methods for trigonometric, logarithmic, + /// and other common mathematical functions. + /// + internal static class Numerics + { + /// + /// Determine the Greatest CommonDivisor (GCD) of two numbers. + /// + public static int GreatestCommonDivisor(int a, int b) + { + while (b != 0) + { + int temp = b; + b = a % b; + a = temp; + } + + return a; + } + + /// + /// Determine the Least Common Multiple (LCM) of two numbers. + /// + public static int LeastCommonMultiple(int a, int b) + { + // https://en.wikipedia.org/wiki/Least_common_multiple#Reduction_by_the_greatest_common_divisor + return (a / GreatestCommonDivisor(a, b)) * b; + } + + /// + /// Calculates % 2 + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Modulo2(int x) => x & 1; + + /// + /// Calculates % 4 + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Modulo4(int x) => x & 3; + + /// + /// Calculates % 8 + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Modulo8(int x) => x & 7; + + /// + /// Fast (x mod m) calculator, with the restriction that + /// should be power of 2. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int ModuloP2(int x, int m) => x & (m - 1); + + /// + /// Returns the absolute value of a 32-bit signed integer. + /// Uses bit shifting to speed up the operation compared to . + /// + /// + /// A number that is greater than , but less than + /// or equal to + /// + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Abs(int x) + { + int y = x >> 31; + return (x ^ y) - y; + } + + /// + /// Returns a specified number raised to the power of 2 + /// + /// A single-precision floating-point number + /// The number raised to the power of 2. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Pow2(float x) => x * x; + + /// + /// Returns a specified number raised to the power of 3 + /// + /// A single-precision floating-point number + /// The number raised to the power of 3. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Pow3(float x) => x * x * x; + + /// + /// Implementation of 1D Gaussian G(x) function + /// + /// The x provided to G(x). + /// The spread of the blur. + /// The Gaussian G(x) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Gaussian(float x, float sigma) + { + const float Numerator = 1.0f; + float denominator = MathF.Sqrt(2 * MathF.PI) * sigma; + + float exponentNumerator = -x * x; + float exponentDenominator = 2 * Pow2(sigma); + + float left = Numerator / denominator; + float right = MathF.Exp(exponentNumerator / exponentDenominator); + + return left * right; + } + + /// + /// Returns the result of a normalized sine cardinal function for the given value. + /// SinC(x) = sin(pi*x)/(pi*x). + /// + /// A single-precision floating-point number to calculate the result for. + /// + /// The sine cardinal of . + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float SinC(float f) + { + if (MathF.Abs(f) > Constants.Epsilon) + { + f *= MathF.PI; + float result = MathF.Sin(f) / f; + return MathF.Abs(result) < Constants.Epsilon ? 0F : result; + } + + return 1F; + } + + /// + /// Returns the value clamped to the inclusive range of min and max. + /// + /// The value to clamp. + /// The minimum inclusive value. + /// The maximum inclusive value. + /// The clamped . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte Clamp(byte value, byte min, byte max) + { + // Order is important here as someone might set min to higher than max. + if (value > max) + { + return max; + } + + if (value < min) + { + return min; + } + + return value; + } + + /// + /// Returns the value clamped to the inclusive range of min and max. + /// + /// The value to clamp. + /// The minimum inclusive value. + /// The maximum inclusive value. + /// The clamped . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint Clamp(uint value, uint min, uint max) + { + if (value > max) + { + return max; + } + + if (value < min) + { + return min; + } + + return value; + } + + /// + /// Returns the value clamped to the inclusive range of min and max. + /// + /// The value to clamp. + /// The minimum inclusive value. + /// The maximum inclusive value. + /// The clamped . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Clamp(int value, int min, int max) + { + if (value > max) + { + return max; + } + + if (value < min) + { + return min; + } + + return value; + } + + /// + /// Returns the value clamped to the inclusive range of min and max. + /// + /// The value to clamp. + /// The minimum inclusive value. + /// The maximum inclusive value. + /// The clamped . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Clamp(float value, float min, float max) + { + if (value > max) + { + return max; + } + + if (value < min) + { + return min; + } + + return value; + } + + /// + /// Returns the value clamped to the inclusive range of min and max. + /// + /// The value to clamp. + /// The minimum inclusive value. + /// The maximum inclusive value. + /// The clamped . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Clamp(double value, double min, double max) + { + if (value > max) + { + return max; + } + + if (value < min) + { + return min; + } + + return value; + } + + /// + /// Clamps the span values to the inclusive range of min and max. + /// + /// The span containing the values to clamp. + /// The minimum inclusive value. + /// The maximum inclusive value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Clamp(Span span, byte min, byte max) + { + int reduced = ClampReduce(span, min, max); + + if (reduced > 0) + { + for (int i = reduced; i < span.Length; i++) + { + ref byte v = ref span[i]; + v = Clamp(v, min, max); + } + } + } + + /// + /// Clamps the span values to the inclusive range of min and max. + /// + /// The span containing the values to clamp. + /// The minimum inclusive value. + /// The maximum inclusive value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Clamp(Span span, uint min, uint max) + { + int reduced = ClampReduce(span, min, max); + + if (reduced > 0) + { + for (int i = reduced; i < span.Length; i++) + { + ref uint v = ref span[i]; + v = Clamp(v, min, max); + } + } + } + + /// + /// Clamps the span values to the inclusive range of min and max. + /// + /// The span containing the values to clamp. + /// The minimum inclusive value. + /// The maximum inclusive value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Clamp(Span span, int min, int max) + { + int reduced = ClampReduce(span, min, max); + + if (reduced > 0) + { + for (int i = reduced; i < span.Length; i++) + { + ref int v = ref span[i]; + v = Clamp(v, min, max); + } + } + } + + /// + /// Clamps the span values to the inclusive range of min and max. + /// + /// The span containing the values to clamp. + /// The minimum inclusive value. + /// The maximum inclusive value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Clamp(Span span, float min, float max) + { + int reduced = ClampReduce(span, min, max); + + if (reduced > 0) + { + for (int i = reduced; i < span.Length; i++) + { + ref float v = ref span[i]; + v = Clamp(v, min, max); + } + } + } + + /// + /// Clamps the span values to the inclusive range of min and max. + /// + /// The span containing the values to clamp. + /// The minimum inclusive value. + /// The maximum inclusive value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Clamp(Span span, double min, double max) + { + int reduced = ClampReduce(span, min, max); + + if (reduced > 0) + { + for (int i = reduced; i < span.Length; i++) + { + ref double v = ref span[i]; + v = Clamp(v, min, max); + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int ClampReduce(Span span, T min, T max) + where T : unmanaged + { + if (Vector.IsHardwareAccelerated && span.Length >= Vector.Count) + { + int remainder = ModuloP2(span.Length, Vector.Count); + int adjustedCount = span.Length - remainder; + + if (adjustedCount > 0) + { + ClampImpl(span.Slice(0, adjustedCount), min, max); + } + + return adjustedCount; + } + + return 0; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static void ClampImpl(Span span, T min, T max) + where T : unmanaged + { + ref T sRef = ref MemoryMarshal.GetReference(span); + ref Vector vsBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(span)); + var vmin = new Vector(min); + var vmax = new Vector(max); + + int n = span.Length / Vector.Count; + int m = Modulo4(n); + int u = n - m; + + for (int i = 0; i < u; i += 4) + { + ref Vector vs0 = ref Unsafe.Add(ref vsBase, i); + ref Vector vs1 = ref Unsafe.Add(ref vs0, 1); + ref Vector vs2 = ref Unsafe.Add(ref vs0, 2); + ref Vector vs3 = ref Unsafe.Add(ref vs0, 3); + + vs0 = Vector.Min(Vector.Max(vmin, vs0), vmax); + vs1 = Vector.Min(Vector.Max(vmin, vs1), vmax); + vs2 = Vector.Min(Vector.Max(vmin, vs2), vmax); + vs3 = Vector.Min(Vector.Max(vmin, vs3), vmax); + } + + if (m > 0) + { + for (int i = u; i < n; i++) + { + ref Vector vs0 = ref Unsafe.Add(ref vsBase, i); + vs0 = Vector.Min(Vector.Max(vmin, vs0), vmax); + } + } + } + } +} diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs index 86e4174f1..3ecad3c5d 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp ref Byte3 dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = source.Length / 4; - int m = ImageMaths.Modulo4(n); + int m = Numerics.Modulo4(n); int u = n - m; ref uint sLoopEnd = ref Unsafe.Add(ref sBase, u); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs b/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs index de6990db5..75555f88a 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp return; } - int remainder = ImageMaths.Modulo8(source.Length); + int remainder = Numerics.Modulo8(source.Length); int adjustedCount = source.Length - remainder; if (adjustedCount > 0) @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp return; } - int remainder = ImageMaths.Modulo8(source.Length); + int remainder = Numerics.Modulo8(source.Length); int adjustedCount = source.Length - remainder; if (adjustedCount > 0) diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs index bd35d1583..0abc0e26d 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp return; } - int remainder = ImageMaths.ModuloP2(source.Length, Vector.Count); + int remainder = Numerics.ModuloP2(source.Length, Vector.Count); int adjustedCount = source.Length - remainder; if (adjustedCount > 0) @@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp return; } - int remainder = ImageMaths.ModuloP2(source.Length, Vector.Count); + int remainder = Numerics.ModuloP2(source.Length, Vector.Count); int adjustedCount = source.Length - remainder; if (adjustedCount > 0) diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs index 1e89aaeb8..a97510113 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp { DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!"); - int remainder = ImageMaths.Modulo4(source.Length); + int remainder = Numerics.Modulo4(source.Length); int adjustedCount = source.Length - remainder; if (adjustedCount > 0) @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp { DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!"); - int remainder = ImageMaths.Modulo4(source.Length); + int remainder = Numerics.Modulo4(source.Length); int adjustedCount = source.Length - remainder; if (adjustedCount > 0) diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 2ea7f2c9b..b76030116 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -38,8 +38,8 @@ namespace SixLabors.ImageSharp if (Avx.IsSupported || Sse.IsSupported) { int remainder = Avx.IsSupported - ? ImageMaths.ModuloP2(source.Length, Vector256.Count) - : ImageMaths.ModuloP2(source.Length, Vector128.Count); + ? Numerics.ModuloP2(source.Length, Vector256.Count) + : Numerics.ModuloP2(source.Length, Vector128.Count); int adjustedCount = source.Length - remainder; @@ -72,8 +72,8 @@ namespace SixLabors.ImageSharp if (Avx2.IsSupported || Ssse3.IsSupported) { int remainder = Avx2.IsSupported - ? ImageMaths.ModuloP2(source.Length, Vector256.Count) - : ImageMaths.ModuloP2(source.Length, Vector128.Count); + ? Numerics.ModuloP2(source.Length, Vector256.Count) + : Numerics.ModuloP2(source.Length, Vector128.Count); int adjustedCount = source.Length - remainder; @@ -203,7 +203,7 @@ namespace SixLabors.ImageSharp ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); int n = dest.Length / Vector256.Count; - int m = ImageMaths.Modulo4(n); + int m = Numerics.Modulo4(n); int u = n - m; for (int i = 0; i < u; i += 4) @@ -235,7 +235,7 @@ namespace SixLabors.ImageSharp ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); int n = dest.Length / Vector128.Count; - int m = ImageMaths.Modulo4(n); + int m = Numerics.Modulo4(n); int u = n - m; for (int i = 0; i < u; i += 4) @@ -288,7 +288,7 @@ namespace SixLabors.ImageSharp ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); int n = dest.Length / Vector256.Count; - int m = ImageMaths.Modulo4(n); + int m = Numerics.Modulo4(n); int u = n - m; for (int i = 0; i < u; i += 4) @@ -324,7 +324,7 @@ namespace SixLabors.ImageSharp ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); int n = dest.Length / Vector128.Count; - int m = ImageMaths.Modulo4(n); + int m = Numerics.Modulo4(n); int u = n - m; for (int i = 0; i < u; i += 4) @@ -550,11 +550,11 @@ namespace SixLabors.ImageSharp int remainder; if (Avx2.IsSupported) { - remainder = ImageMaths.ModuloP2(source.Length, Vector256.Count); + remainder = Numerics.ModuloP2(source.Length, Vector256.Count); } else { - remainder = ImageMaths.ModuloP2(source.Length, Vector128.Count); + remainder = Numerics.ModuloP2(source.Length, Vector128.Count); } int adjustedCount = source.Length - remainder; @@ -683,11 +683,11 @@ namespace SixLabors.ImageSharp int remainder; if (Avx2.IsSupported) { - remainder = ImageMaths.ModuloP2(source.Length, Vector256.Count); + remainder = Numerics.ModuloP2(source.Length, Vector256.Count); } else { - remainder = ImageMaths.ModuloP2(source.Length, Vector128.Count); + remainder = Numerics.ModuloP2(source.Length, Vector128.Count); } int adjustedCount = source.Length - remainder; diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.cs b/src/ImageSharp/Common/Helpers/SimdUtils.cs index 7cbb5bfe3..7691cb9ad 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.cs @@ -206,7 +206,7 @@ namespace SixLabors.ImageSharp { DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!"); DebugGuard.IsTrue( - ImageMaths.ModuloP2(dest.Length, shouldBeDivisibleBy) == 0, + Numerics.ModuloP2(dest.Length, shouldBeDivisibleBy) == 0, nameof(source), $"length should be divisible by {shouldBeDivisibleBy}!"); } @@ -216,7 +216,7 @@ namespace SixLabors.ImageSharp { DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!"); DebugGuard.IsTrue( - ImageMaths.ModuloP2(dest.Length, shouldBeDivisibleBy) == 0, + Numerics.ModuloP2(dest.Length, shouldBeDivisibleBy) == 0, nameof(source), $"length should be divisible by {shouldBeDivisibleBy}!"); } diff --git a/src/ImageSharp/Common/Helpers/Vector4Utilities.cs b/src/ImageSharp/Common/Helpers/Vector4Utilities.cs index f617e9a3e..464006570 100644 --- a/src/ImageSharp/Common/Helpers/Vector4Utilities.cs +++ b/src/ImageSharp/Common/Helpers/Vector4Utilities.cs @@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp vectorsBase = ref Unsafe.Add(ref vectorsBase, 1); } - if (ImageMaths.Modulo2(vectors.Length) != 0) + if (Numerics.Modulo2(vectors.Length) != 0) { // Vector4 fits neatly in pairs. Any overlap has to be equal to 1. Premultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1))); @@ -123,7 +123,7 @@ namespace SixLabors.ImageSharp vectorsBase = ref Unsafe.Add(ref vectorsBase, 1); } - if (ImageMaths.Modulo2(vectors.Length) != 0) + if (Numerics.Modulo2(vectors.Length) != 0) { // Vector4 fits neatly in pairs. Any overlap has to be equal to 1. UnPremultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1))); diff --git a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs index 8d9f6e415..d1c214e3d 100644 --- a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. using System; @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters ++x; ref byte res = ref Unsafe.Add(ref resultBaseRef, x); res = (byte)(scan - (above >> 1)); - sum += ImageMaths.FastAbs(unchecked((sbyte)res)); + sum += Numerics.Abs(unchecked((sbyte)res)); } for (int xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters ++x; ref byte res = ref Unsafe.Add(ref resultBaseRef, x); res = (byte)(scan - Average(left, above)); - sum += ImageMaths.FastAbs(unchecked((sbyte)res)); + sum += Numerics.Abs(unchecked((sbyte)res)); } sum -= 3; @@ -102,4 +102,4 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int Average(byte left, byte above) => (left + above) >> 1; } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs index 7b5c71a01..fab678806 100644 --- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. using System; @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters ++x; ref byte res = ref Unsafe.Add(ref resultBaseRef, x); res = (byte)(scan - PaethPredictor(0, above, 0)); - sum += ImageMaths.FastAbs(unchecked((sbyte)res)); + sum += Numerics.Abs(unchecked((sbyte)res)); } for (int xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) @@ -91,7 +91,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters ++x; ref byte res = ref Unsafe.Add(ref resultBaseRef, x); res = (byte)(scan - PaethPredictor(left, above, upperLeft)); - sum += ImageMaths.FastAbs(unchecked((sbyte)res)); + sum += Numerics.Abs(unchecked((sbyte)res)); } sum -= 4; @@ -111,9 +111,9 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters private static byte PaethPredictor(byte left, byte above, byte upperLeft) { int p = left + above - upperLeft; - int pa = ImageMaths.FastAbs(p - left); - int pb = ImageMaths.FastAbs(p - above); - int pc = ImageMaths.FastAbs(p - upperLeft); + int pa = Numerics.Abs(p - left); + int pb = Numerics.Abs(p - above); + int pc = Numerics.Abs(p - upperLeft); if (pa <= pb && pa <= pc) { @@ -128,4 +128,4 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters return upperLeft; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs index c448e71f4..cb4cfb471 100644 --- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters ++x; ref byte res = ref Unsafe.Add(ref resultBaseRef, x); res = scan; - sum += ImageMaths.FastAbs(unchecked((sbyte)res)); + sum += Numerics.Abs(unchecked((sbyte)res)); } for (int xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) @@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters ++x; ref byte res = ref Unsafe.Add(ref resultBaseRef, x); res = (byte)(scan - prev); - sum += ImageMaths.FastAbs(unchecked((sbyte)res)); + sum += Numerics.Abs(unchecked((sbyte)res)); } sum -= 1; diff --git a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs index 2a77bccb9..cf553cbb6 100644 --- a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters ++x; ref byte res = ref Unsafe.Add(ref resultBaseRef, x); res = (byte)(scan - above); - sum += ImageMaths.FastAbs(unchecked((sbyte)res)); + sum += Numerics.Abs(unchecked((sbyte)res)); } sum -= 2; diff --git a/src/ImageSharp/Primitives/ComplexVector4.cs b/src/ImageSharp/Primitives/ComplexVector4.cs index 3a1d4ac46..07f074502 100644 --- a/src/ImageSharp/Primitives/ComplexVector4.cs +++ b/src/ImageSharp/Primitives/ComplexVector4.cs @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp /// /// The input to sum [MethodImpl(InliningOptions.ShortMethod)] - public void Sum(in ComplexVector4 value) + public void Sum(ComplexVector4 value) { this.Real += value.Real; this.Imaginary += value.Imaginary; diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessorHelpers.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessorHelpers.cs index 7b1ceff27..9844f9956 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessorHelpers.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessorHelpers.cs @@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution for (int i = 0; i < size; i++) { float x = i - midpoint; - float gx = ImageMaths.Gaussian(x, weight); + float gx = Numerics.Gaussian(x, weight); sum += gx; kernel[0, i] = gx; } @@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution for (int i = 0; i < size; i++) { float x = i - midpoint; - float gx = ImageMaths.Gaussian(x, weight); + float gx = Numerics.Gaussian(x, weight); sum += gx; kernel[0, i] = gx; } @@ -88,4 +88,4 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution return kernel; } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs index a61c68de3..007a9a05d 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs @@ -182,7 +182,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization { if (y < 0) { - y = ImageMaths.FastAbs(y); + y = Numerics.Abs(y); } else if (y >= source.Height) { @@ -197,7 +197,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization int idx = 0; for (int dx = x; dx < x + tileWidth; dx++) { - rowPixels[idx] = source[ImageMaths.FastAbs(dx), y].ToVector4(); + rowPixels[idx] = source[Numerics.Abs(dx), y].ToVector4(); idx++; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resamplers/LanczosResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/Resamplers/LanczosResampler.cs index 7aefd8f6f..8742db580 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resamplers/LanczosResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resamplers/LanczosResampler.cs @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms float radius = this.Radius; if (x < radius) { - return ImageMaths.SinC(x) * ImageMaths.SinC(x / radius); + return Numerics.SinC(x) * Numerics.SinC(x / radius); } return 0F; diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resamplers/WelchResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/Resamplers/WelchResampler.cs index 93c50af13..18859d1ad 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resamplers/WelchResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resamplers/WelchResampler.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms if (x < 3F) { - return ImageMaths.SinC(x) * (1F - (x * x / 9F)); + return Numerics.SinC(x) * (1F - (x * x / 9F)); } return 0F; diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs index 7cbda76a5..ab6040c17 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs @@ -132,7 +132,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms // 'ratio' is a rational number. // Multiplying it by LCM(sourceSize, destSize)/sourceSize will result in a whole number "again". // This value is determining the length of the periods in repeating kernel map rows. - int period = ImageMaths.LeastCommonMultiple(sourceSize, destinationSize) / sourceSize; + int period = Numerics.LeastCommonMultiple(sourceSize, destinationSize) / sourceSize; // the center position at i == 0: double center0 = (ratio - 1) * 0.5; diff --git a/tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs b/tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs new file mode 100644 index 000000000..a5b49721d --- /dev/null +++ b/tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs @@ -0,0 +1,42 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System; +using BenchmarkDotNet.Attributes; + +namespace SixLabors.ImageSharp.Benchmarks.General.BasicMath +{ + public class ClampSpan + { + private static readonly int[] A = new int[2048]; + private static readonly int[] B = new int[2048]; + + public void Setup() + { + var r = new Random(); + + for (int i = 0; i < A.Length; i++) + { + int x = r.Next(); + A[i] = x; + B[i] = x; + } + } + + [Benchmark(Baseline = true)] + public void ClampNoIntrinsics() + { + for (int i = 0; i < A.Length; i++) + { + ref int x = ref A[i]; + x = x.Clamp(64, 128); + } + } + + [Benchmark] + public void ClampVectorIntrinsics() + { + Numerics.Clamp(B, 64, 128); + } + } +} diff --git a/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoConstant.cs b/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoConstant.cs index 55e26372b..27ae787bc 100644 --- a/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoConstant.cs +++ b/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoConstant.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General.BasicMath [Benchmark] public int Bitwise() { - return ImageMaths.Modulo8(this.value); + return Numerics.Modulo8(this.value); } } } diff --git a/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoVariable.cs b/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoVariable.cs index 9da7b9fdf..d336015a0 100644 --- a/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoVariable.cs +++ b/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoVariable.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General.BasicMath [Benchmark] public int Bitwise() { - return ImageMaths.ModuloP2(this.value, this.m); + return Numerics.ModuloP2(this.value, this.m); } // RESULTS: diff --git a/tests/ImageSharp.Tests/Helpers/ImageMathsTests.cs b/tests/ImageSharp.Tests/Helpers/ImageMathsTests.cs index 7d1662387..656d8ce3b 100644 --- a/tests/ImageSharp.Tests/Helpers/ImageMathsTests.cs +++ b/tests/ImageSharp.Tests/Helpers/ImageMathsTests.cs @@ -10,144 +10,6 @@ namespace SixLabors.ImageSharp.Tests.Helpers { public class ImageMathsTests { - [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(100)] - [InlineData(123)] - [InlineData(53436353)] - public void Modulo2(int x) - { - int actual = ImageMaths.Modulo2(x); - Assert.Equal(x % 2, actual); - } - - [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(100)] - [InlineData(123)] - [InlineData(53436353)] - public void Modulo4(int x) - { - int actual = ImageMaths.Modulo4(x); - Assert.Equal(x % 4, actual); - } - - [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(2)] - [InlineData(6)] - [InlineData(7)] - [InlineData(8)] - [InlineData(100)] - [InlineData(123)] - [InlineData(53436353)] - [InlineData(975)] - public void Modulo8(int x) - { - int actual = ImageMaths.Modulo8(x); - Assert.Equal(x % 8, actual); - } - - [Theory] - [InlineData(0, 2)] - [InlineData(1, 2)] - [InlineData(2, 2)] - [InlineData(0, 4)] - [InlineData(3, 4)] - [InlineData(5, 4)] - [InlineData(5, 8)] - [InlineData(8, 8)] - [InlineData(8, 16)] - [InlineData(15, 16)] - [InlineData(17, 16)] - [InlineData(17, 32)] - [InlineData(31, 32)] - [InlineData(32, 32)] - [InlineData(33, 32)] - public void Modulo2P(int x, int m) - { - int actual = ImageMaths.ModuloP2(x, m); - Assert.Equal(x % m, actual); - } - - [Theory] - [InlineData(0, 0, 0, 0)] - [InlineData(0.5f, 0, 1, 0.5f)] - [InlineData(-0.5f, -0.1f, 10, -0.1f)] - [InlineData(-0.05f, -0.1f, 10, -0.05f)] - [InlineData(9.9f, -0.1f, 10, 9.9f)] - [InlineData(10f, -0.1f, 10, 10f)] - [InlineData(10.1f, -0.1f, 10, 10f)] - public void Clamp(float x, float min, float max, float expected) - { - float actual = x.Clamp(min, max); - Assert.Equal(expected, actual); - } - - [Fact] - public void FasAbsResultMatchesMath() - { - const int X = -33; - int expected = Math.Abs(X); - - Assert.Equal(expected, ImageMaths.FastAbs(X)); - } - - [Fact] - public void Pow2ResultMatchesMath() - { - const float X = -33; - float expected = (float)Math.Pow(X, 2); - - Assert.Equal(expected, ImageMaths.Pow2(X)); - } - - [Fact] - public void Pow3ResultMatchesMath() - { - const float X = -33; - float expected = (float)Math.Pow(X, 3); - - Assert.Equal(expected, ImageMaths.Pow3(X)); - } - - [Theory] - [InlineData(1, 1, 1)] - [InlineData(1, 42, 1)] - [InlineData(10, 8, 2)] - [InlineData(12, 18, 6)] - [InlineData(4536, 1000, 8)] - [InlineData(1600, 1024, 64)] - public void GreatestCommonDivisor(int a, int b, int expected) - { - int actual = ImageMaths.GreatestCommonDivisor(a, b); - - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(1, 1, 1)] - [InlineData(1, 42, 42)] - [InlineData(3, 4, 12)] - [InlineData(6, 4, 12)] - [InlineData(1600, 1024, 25600)] - [InlineData(3264, 100, 81600)] - public void LeastCommonMultiple(int a, int b, int expected) - { - int actual = ImageMaths.LeastCommonMultiple(a, b); - - Assert.Equal(expected, actual); - } - [Theory] [InlineData(0.2f, 0.7f, 0.1f, 256, 140)] [InlineData(0.5f, 0.5f, 0.5f, 256, 128)] diff --git a/tests/ImageSharp.Tests/Helpers/NumericsTests.cs b/tests/ImageSharp.Tests/Helpers/NumericsTests.cs new file mode 100644 index 000000000..f1678cfa1 --- /dev/null +++ b/tests/ImageSharp.Tests/Helpers/NumericsTests.cs @@ -0,0 +1,265 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Helpers +{ + public class NumericsTests + { + public delegate void SpanAction(Span span, TArg arg, TArg1 arg1); + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(100)] + [InlineData(123)] + [InlineData(53436353)] + public void Modulo2(int x) + { + int actual = Numerics.Modulo2(x); + Assert.Equal(x % 2, actual); + } + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(100)] + [InlineData(123)] + [InlineData(53436353)] + public void Modulo4(int x) + { + int actual = Numerics.Modulo4(x); + Assert.Equal(x % 4, actual); + } + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(2)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + [InlineData(100)] + [InlineData(123)] + [InlineData(53436353)] + [InlineData(975)] + public void Modulo8(int x) + { + int actual = Numerics.Modulo8(x); + Assert.Equal(x % 8, actual); + } + + [Theory] + [InlineData(0, 2)] + [InlineData(1, 2)] + [InlineData(2, 2)] + [InlineData(0, 4)] + [InlineData(3, 4)] + [InlineData(5, 4)] + [InlineData(5, 8)] + [InlineData(8, 8)] + [InlineData(8, 16)] + [InlineData(15, 16)] + [InlineData(17, 16)] + [InlineData(17, 32)] + [InlineData(31, 32)] + [InlineData(32, 32)] + [InlineData(33, 32)] + public void Modulo2P(int x, int m) + { + int actual = Numerics.ModuloP2(x, m); + Assert.Equal(x % m, actual); + } + + [Theory] + [InlineData(-5)] + [InlineData(-17)] + [InlineData(-12856)] + [InlineData(-32)] + [InlineData(-7425)] + [InlineData(5)] + [InlineData(17)] + [InlineData(12856)] + [InlineData(32)] + [InlineData(7425)] + public void Abs(int x) + { + int expected = Math.Abs(x); + Assert.Equal(expected, Numerics.Abs(x)); + } + + [Theory] + [InlineData(-5)] + [InlineData(-17)] + [InlineData(-12856)] + [InlineData(-32)] + [InlineData(-7425)] + [InlineData(5)] + [InlineData(17)] + [InlineData(12856)] + [InlineData(32)] + [InlineData(7425)] + public void Pow2(float x) + { + float expected = (float)Math.Pow(x, 2); + Assert.Equal(expected, Numerics.Pow2(x)); + } + + [Theory] + [InlineData(-5)] + [InlineData(-17)] + [InlineData(-12856)] + [InlineData(-32)] + [InlineData(5)] + [InlineData(17)] + [InlineData(12856)] + [InlineData(32)] + public void Pow3(float x) + { + float expected = (float)Math.Pow(x, 3); + Assert.Equal(expected, Numerics.Pow3(x)); + } + + [Theory] + [InlineData(1, 1, 1)] + [InlineData(1, 42, 1)] + [InlineData(10, 8, 2)] + [InlineData(12, 18, 6)] + [InlineData(4536, 1000, 8)] + [InlineData(1600, 1024, 64)] + public void GreatestCommonDivisor(int a, int b, int expected) + { + int actual = Numerics.GreatestCommonDivisor(a, b); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(1, 1, 1)] + [InlineData(1, 42, 42)] + [InlineData(3, 4, 12)] + [InlineData(6, 4, 12)] + [InlineData(1600, 1024, 25600)] + [InlineData(3264, 100, 81600)] + public void LeastCommonMultiple(int a, int b, int expected) + { + int actual = Numerics.LeastCommonMultiple(a, b); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(64, 36, 96)] + [InlineData(128, 16, 196)] + [InlineData(567, 18, 142)] + [InlineData(1024, 0, 255)] + public void ClampByte(int length, byte min, byte max) + { + TestClampSpan( + length, + min, + max, + (s, m1, m2) => Numerics.Clamp(s, m1, m2), + (v, m1, m2) => Numerics.Clamp(v, m1, m2)); + } + + [Theory] + [InlineData(64, 36, 96)] + [InlineData(128, 16, 196)] + [InlineData(567, 18, 142)] + [InlineData(1024, 0, 255)] + public void ClampInt(int length, int min, int max) + { + TestClampSpan( + length, + min, + max, + (s, m1, m2) => Numerics.Clamp(s, m1, m2), + (v, m1, m2) => Numerics.Clamp(v, m1, m2)); + } + + [Theory] + [InlineData(64, 36, 96)] + [InlineData(128, 16, 196)] + [InlineData(567, 18, 142)] + [InlineData(1024, 0, 255)] + public void ClampUInt(int length, uint min, uint max) + { + TestClampSpan( + length, + min, + max, + (s, m1, m2) => Numerics.Clamp(s, m1, m2), + (v, m1, m2) => Numerics.Clamp(v, m1, m2)); + } + + [Theory] + [InlineData(64, 36, 96)] + [InlineData(128, 16, 196)] + [InlineData(567, 18, 142)] + [InlineData(1024, 0, 255)] + public void ClampFloat(int length, float min, float max) + { + TestClampSpan( + length, + min, + max, + (s, m1, m2) => Numerics.Clamp(s, m1, m2), + (v, m1, m2) => Numerics.Clamp(v, m1, m2)); + } + + [Theory] + [InlineData(64, 36, 96)] + [InlineData(128, 16, 196)] + [InlineData(567, 18, 142)] + [InlineData(1024, 0, 255)] + public void ClampDouble(int length, double min, double max) + { + TestClampSpan( + length, + min, + max, + (s, m1, m2) => Numerics.Clamp(s, m1, m2), + (v, m1, m2) => Numerics.Clamp(v, m1, m2)); + } + + private static void TestClampSpan( + int length, + T min, + T max, + SpanAction clampAction, + Func refClampFunc) + where T : unmanaged, IComparable + { + Span actual = new T[length]; + + var r = new Random(); + for (int i = 0; i < length; i++) + { + actual[i] = (T)Convert.ChangeType(r.Next(byte.MinValue, byte.MaxValue), typeof(T)); + } + + Span expected = new T[length]; + actual.CopyTo(expected); + + for (int i = 0; i < expected.Length; i++) + { + ref T v = ref expected[i]; + v = refClampFunc(v, min, max); + } + + clampAction(actual, min, max); + + for (int i = 0; i < expected.Length; i++) + { + Assert.Equal(expected[i], actual[i]); + } + } + } +} From 124a54c5ad8ab54ddcdfac3e4ac1e4c00b7537f3 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 22 Nov 2020 23:56:09 +0000 Subject: [PATCH 17/39] ImageMaths => ImageMath --- src/ImageSharp/Color/Color.cs | 14 +- .../Helpers/{ImageMaths.cs => ImageMath.cs} | 2 +- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 4 +- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 6 +- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 6 +- .../Formats/Png/PngEncoderOptionsHelpers.cs | 4 +- .../Formats/Png/PngScanlineProcessor.cs | 4 +- src/ImageSharp/Formats/Tga/TgaEncoderCore.cs | 2 +- .../PixelFormats/PixelImplementations/A8.cs | 2 +- .../PixelImplementations/Argb32.cs | 20 +-- .../PixelImplementations/Bgr24.cs | 16 +-- .../PixelImplementations/Bgra32.cs | 20 +-- .../PixelFormats/PixelImplementations/L16.cs | 52 ++++---- .../PixelFormats/PixelImplementations/L8.cs | 32 ++--- .../PixelFormats/PixelImplementations/La16.cs | 36 +++--- .../PixelFormats/PixelImplementations/La32.cs | 62 ++++----- .../PixelImplementations/Rgb24.cs | 16 +-- .../PixelImplementations/Rgb48.cs | 40 +++--- .../PixelImplementations/Rgba32.cs | 20 +-- .../PixelImplementations/Rgba64.cs | 122 +++++++++--------- .../BinaryThresholdProcessor{TPixel}.cs | 2 +- .../Processors/Dithering/OrderedDither.cs | 4 +- ...alizationSlidingWindowProcessor{TPixel}.cs | 4 +- ...lHistogramEqualizationProcessor{TPixel}.cs | 4 +- .../HistogramEqualizationProcessor{TPixel}.cs | 2 +- .../Quantization/OctreeQuantizer{TPixel}.cs | 2 +- .../EntropyCropProcessor{TPixel}.cs | 2 +- .../Formats/Png/PngEncoderTests.cs | 2 +- .../{ImageMathsTests.cs => ImageMathTests.cs} | 5 +- .../ImageSharp.Tests/PixelFormats/L16Tests.cs | 6 +- .../ImageSharp.Tests/PixelFormats/L8Tests.cs | 2 +- .../PixelFormats/La16Tests.cs | 2 +- .../PixelFormats/La32Tests.cs | 6 +- 33 files changed, 261 insertions(+), 262 deletions(-) rename src/ImageSharp/Common/Helpers/{ImageMaths.cs => ImageMath.cs} (99%) rename tests/ImageSharp.Tests/Helpers/{ImageMathsTests.cs => ImageMathTests.cs} (85%) diff --git a/src/ImageSharp/Color/Color.cs b/src/ImageSharp/Color/Color.cs index 554fcb835..424329863 100644 --- a/src/ImageSharp/Color/Color.cs +++ b/src/ImageSharp/Color/Color.cs @@ -27,19 +27,19 @@ namespace SixLabors.ImageSharp private Color(byte r, byte g, byte b, byte a) { this.data = new Rgba64( - ImageMaths.UpscaleFrom8BitTo16Bit(r), - ImageMaths.UpscaleFrom8BitTo16Bit(g), - ImageMaths.UpscaleFrom8BitTo16Bit(b), - ImageMaths.UpscaleFrom8BitTo16Bit(a)); + ImageMath.UpscaleFrom8BitTo16Bit(r), + ImageMath.UpscaleFrom8BitTo16Bit(g), + ImageMath.UpscaleFrom8BitTo16Bit(b), + ImageMath.UpscaleFrom8BitTo16Bit(a)); } [MethodImpl(InliningOptions.ShortMethod)] private Color(byte r, byte g, byte b) { this.data = new Rgba64( - ImageMaths.UpscaleFrom8BitTo16Bit(r), - ImageMaths.UpscaleFrom8BitTo16Bit(g), - ImageMaths.UpscaleFrom8BitTo16Bit(b), + ImageMath.UpscaleFrom8BitTo16Bit(r), + ImageMath.UpscaleFrom8BitTo16Bit(g), + ImageMath.UpscaleFrom8BitTo16Bit(b), ushort.MaxValue); } diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMath.cs similarity index 99% rename from src/ImageSharp/Common/Helpers/ImageMaths.cs rename to src/ImageSharp/Common/Helpers/ImageMath.cs index 55ac6f822..11fb60209 100644 --- a/src/ImageSharp/Common/Helpers/ImageMaths.cs +++ b/src/ImageSharp/Common/Helpers/ImageMath.cs @@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp /// /// Provides common mathematical methods used for image processing. /// - internal static class ImageMaths + internal static class ImageMath { /// /// Vector for converting pixel to gray value as specified by ITU-R Recommendation BT.709. diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 6f9223637..0dd667850 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -1385,7 +1385,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { case BmpFileMarkerType.Bitmap: colorMapSizeBytes = this.fileHeader.Offset - BmpFileHeader.Size - this.infoHeader.HeaderSize; - int colorCountForBitDepth = ImageMaths.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel); + int colorCountForBitDepth = ImageMath.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel); bytesPerColorMapEntry = colorMapSizeBytes / colorCountForBitDepth; // Edge case for less-than-full-sized palette: bytesPerColorMapEntry should be at least 3. @@ -1399,7 +1399,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp case BmpFileMarkerType.Pointer: // OS/2 bitmaps always have 3 colors per color palette entry. bytesPerColorMapEntry = 3; - colorMapSizeBytes = ImageMaths.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel) * bytesPerColorMapEntry; + colorMapSizeBytes = ImageMath.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel) * bytesPerColorMapEntry; break; } } diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 070864e60..f4288e97f 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.Formats.Gif } // Get the number of bits. - this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length); + this.bitDepth = ImageMath.GetBitsNeededForColorDepth(quantized.Palette.Length); // Write the header. this.WriteHeader(stream); @@ -212,7 +212,7 @@ namespace SixLabors.ImageSharp.Formats.Gif } } - this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length); + this.bitDepth = ImageMath.GetBitsNeededForColorDepth(quantized.Palette.Length); this.WriteGraphicalControlExtension(frameMetadata, this.GetTransparentIndex(quantized), stream); this.WriteImageDescriptor(frame, true, stream); this.WriteColorTable(quantized, stream); @@ -468,7 +468,7 @@ namespace SixLabors.ImageSharp.Formats.Gif where TPixel : unmanaged, IPixel { // The maximum number of colors for the bit depth - int colorTableLength = ImageMaths.GetColorCountForBitDepth(this.bitDepth) * Unsafe.SizeOf(); + int colorTableLength = ImageMath.GetColorCountForBitDepth(this.bitDepth) * Unsafe.SizeOf(); using IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength, AllocationOptions.Clean); PixelOperations.Instance.ToRgb24Bytes( diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 5cf11099c..4e05f459f 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -284,7 +284,7 @@ namespace SixLabors.ImageSharp.Formats.Png rowSpan.Length, AllocationOptions.Clean)) { - int scaleFactor = 255 / (ImageMaths.GetColorCountForBitDepth(this.bitDepth) - 1); + int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(this.bitDepth) - 1); Span tempSpan = temp.GetSpan(); // We need to first create an array of luminance bytes then scale them down to the correct bit depth. @@ -314,7 +314,7 @@ namespace SixLabors.ImageSharp.Formats.Png for (int x = 0, o = 0; x < rgbaSpan.Length; x++, o += 4) { Rgba64 rgba = Unsafe.Add(ref rgbaRef, x); - ushort luminance = ImageMaths.Get16BitBT709Luminance(rgba.R, rgba.G, rgba.B); + ushort luminance = ImageMath.Get16BitBT709Luminance(rgba.R, rgba.G, rgba.B); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), luminance); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgba.A); } @@ -329,7 +329,7 @@ namespace SixLabors.ImageSharp.Formats.Png { Unsafe.Add(ref rowSpanRef, x).ToRgba32(ref rgba); Unsafe.Add(ref rawScanlineSpanRef, o) = - ImageMaths.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B); + ImageMath.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B); Unsafe.Add(ref rawScanlineSpanRef, o + 1) = rgba.A; } } diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs index 9342e09df..3343923b7 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Formats.Png if (options.Quantizer is null) { byte bits = (byte)options.BitDepth; - var maxColors = ImageMaths.GetColorCountForBitDepth(bits); + var maxColors = ImageMath.GetColorCountForBitDepth(bits); options.Quantizer = new WuQuantizer(new QuantizerOptions { MaxColors = maxColors }); } @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Formats.Png byte bitDepth; if (options.ColorType == PngColorType.Palette) { - byte quantizedBits = (byte)ImageMaths.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length).Clamp(1, 8); + byte quantizedBits = (byte)ImageMath.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length).Clamp(1, 8); byte bits = Math.Max((byte)options.BitDepth, quantizedBits); // Png only supports in four pixel depths: 1, 2, 4, and 8 bits when using the PLTE chunk diff --git a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs index 48ec9bdcd..16d6aa19f 100644 --- a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs +++ b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Formats.Png TPixel pixel = default; ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan); ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan); - int scaleFactor = 255 / (ImageMaths.GetColorCountForBitDepth(header.BitDepth) - 1); + int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(header.BitDepth) - 1); if (!hasTrans) { @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Formats.Png TPixel pixel = default; ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan); ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan); - int scaleFactor = 255 / (ImageMaths.GetColorCountForBitDepth(header.BitDepth) - 1); + int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(header.BitDepth) - 1); if (!hasTrans) { diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs index d3a628531..92474b6fc 100644 --- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs @@ -365,7 +365,7 @@ namespace SixLabors.ImageSharp.Formats.Tga where TPixel : unmanaged, IPixel { var vector = sourcePixel.ToVector4(); - return ImageMaths.GetBT709Luminance(ref vector, 256); + return ImageMath.GetBT709Luminance(ref vector, 256); } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs index fc0723e9a..c293d181a 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromLa32(La32 source) => this.PackedValue = ImageMaths.DownScaleFrom16BitTo8Bit(source.A); + public void FromLa32(La32 source) => this.PackedValue = ImageMath.DownScaleFrom16BitTo8Bit(source.A); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs index 914b31672..a42be2482 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs @@ -244,7 +244,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.PackedValue); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -265,11 +265,11 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.L); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; - this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A); + this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); } /// @@ -306,9 +306,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B); + this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); + this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); + this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); this.A = byte.MaxValue; } @@ -316,10 +316,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B); - this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A); + this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); + this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); + this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); + this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs index a2ec185be..9063516a3 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.PackedValue); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.L); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; @@ -203,18 +203,18 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B); + this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); + this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); + this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B); + this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); + this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); + this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs index 68dcd8287..fea5643a8 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs @@ -197,7 +197,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.PackedValue); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -218,11 +218,11 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.L); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; - this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A); + this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); } /// @@ -259,9 +259,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B); + this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); + this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); + this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); this.A = byte.MaxValue; } @@ -269,10 +269,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B); - this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A); + this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); + this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); + this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); + this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs index 087becaf2..5d91486a6 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs @@ -74,30 +74,30 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromArgb32(Argb32 source) { - this.PackedValue = ImageMaths.Get16BitBT709Luminance( - ImageMaths.UpscaleFrom8BitTo16Bit(source.R), - ImageMaths.UpscaleFrom8BitTo16Bit(source.G), - ImageMaths.UpscaleFrom8BitTo16Bit(source.B)); + this.PackedValue = ImageMath.Get16BitBT709Luminance( + ImageMath.UpscaleFrom8BitTo16Bit(source.R), + ImageMath.UpscaleFrom8BitTo16Bit(source.G), + ImageMath.UpscaleFrom8BitTo16Bit(source.B)); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) { - this.PackedValue = ImageMaths.Get16BitBT709Luminance( - ImageMaths.UpscaleFrom8BitTo16Bit(source.R), - ImageMaths.UpscaleFrom8BitTo16Bit(source.G), - ImageMaths.UpscaleFrom8BitTo16Bit(source.B)); + this.PackedValue = ImageMath.Get16BitBT709Luminance( + ImageMath.UpscaleFrom8BitTo16Bit(source.R), + ImageMath.UpscaleFrom8BitTo16Bit(source.G), + ImageMath.UpscaleFrom8BitTo16Bit(source.B)); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) { - this.PackedValue = ImageMaths.Get16BitBT709Luminance( - ImageMaths.UpscaleFrom8BitTo16Bit(source.R), - ImageMaths.UpscaleFrom8BitTo16Bit(source.G), - ImageMaths.UpscaleFrom8BitTo16Bit(source.B)); + this.PackedValue = ImageMath.Get16BitBT709Luminance( + ImageMath.UpscaleFrom8BitTo16Bit(source.R), + ImageMath.UpscaleFrom8BitTo16Bit(source.G), + ImageMath.UpscaleFrom8BitTo16Bit(source.B)); } /// @@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromL8(L8 source) => this.PackedValue = ImageMaths.UpscaleFrom8BitTo16Bit(source.PackedValue); + public void FromL8(L8 source) => this.PackedValue = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromLa16(La16 source) => this.PackedValue = ImageMaths.UpscaleFrom8BitTo16Bit(source.L); + public void FromLa16(La16 source) => this.PackedValue = ImageMath.UpscaleFrom8BitTo16Bit(source.L); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -124,27 +124,27 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb24(Rgb24 source) { - this.PackedValue = ImageMaths.Get16BitBT709Luminance( - ImageMaths.UpscaleFrom8BitTo16Bit(source.R), - ImageMaths.UpscaleFrom8BitTo16Bit(source.G), - ImageMaths.UpscaleFrom8BitTo16Bit(source.B)); + this.PackedValue = ImageMath.Get16BitBT709Luminance( + ImageMath.UpscaleFrom8BitTo16Bit(source.R), + ImageMath.UpscaleFrom8BitTo16Bit(source.G), + ImageMath.UpscaleFrom8BitTo16Bit(source.B)); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) { - this.PackedValue = ImageMaths.Get16BitBT709Luminance( - ImageMaths.UpscaleFrom8BitTo16Bit(source.R), - ImageMaths.UpscaleFrom8BitTo16Bit(source.G), - ImageMaths.UpscaleFrom8BitTo16Bit(source.B)); + this.PackedValue = ImageMath.Get16BitBT709Luminance( + ImageMath.UpscaleFrom8BitTo16Bit(source.R), + ImageMath.UpscaleFrom8BitTo16Bit(source.G), + ImageMath.UpscaleFrom8BitTo16Bit(source.B)); } /// [MethodImpl(InliningOptions.ShortMethod)] public void ToRgba32(ref Rgba32 dest) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(this.PackedValue); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(this.PackedValue); dest.R = rgb; dest.G = rgb; dest.B = rgb; @@ -153,11 +153,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromRgb48(Rgb48 source) => this.PackedValue = ImageMaths.Get16BitBT709Luminance(source.R, source.G, source.B); + public void FromRgb48(Rgb48 source) => this.PackedValue = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromRgba64(Rgba64 source) => this.PackedValue = ImageMaths.Get16BitBT709Luminance(source.R, source.G, source.B); + public void FromRgba64(Rgba64 source) => this.PackedValue = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B); /// public override readonly bool Equals(object obj) => obj is L16 other && this.Equals(other); @@ -177,7 +177,7 @@ namespace SixLabors.ImageSharp.PixelFormats internal void ConvertFromRgbaScaledVector4(Vector4 vector) { vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max; - this.PackedValue = ImageMaths.Get16BitBT709Luminance( + this.PackedValue = ImageMath.Get16BitBT709Luminance( vector.X, vector.Y, vector.Z); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs index 32f963795..f395a5dfb 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs @@ -73,15 +73,15 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromArgb32(Argb32 source) => this.PackedValue = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B); + public void FromArgb32(Argb32 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromBgr24(Bgr24 source) => this.PackedValue = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B); + public void FromBgr24(Bgr24 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromBgra32(Bgra32 source) => this.PackedValue = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B); + public void FromBgra32(Bgra32 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromL16(L16 source) => this.PackedValue = ImageMaths.DownScaleFrom16BitTo8Bit(source.PackedValue); + public void FromL16(L16 source) => this.PackedValue = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -101,15 +101,15 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromLa32(La32 source) => this.PackedValue = ImageMaths.DownScaleFrom16BitTo8Bit(source.L); + public void FromLa32(La32 source) => this.PackedValue = ImageMath.DownScaleFrom16BitTo8Bit(source.L); /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromRgb24(Rgb24 source) => this.PackedValue = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B); + public void FromRgb24(Rgb24 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromRgba32(Rgba32 source) => this.PackedValue = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B); + public void FromRgba32(Rgba32 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -124,18 +124,18 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) - => this.PackedValue = ImageMaths.Get8BitBT709Luminance( - ImageMaths.DownScaleFrom16BitTo8Bit(source.R), - ImageMaths.DownScaleFrom16BitTo8Bit(source.G), - ImageMaths.DownScaleFrom16BitTo8Bit(source.B)); + => this.PackedValue = ImageMath.Get8BitBT709Luminance( + ImageMath.DownScaleFrom16BitTo8Bit(source.R), + ImageMath.DownScaleFrom16BitTo8Bit(source.G), + ImageMath.DownScaleFrom16BitTo8Bit(source.B)); /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) - => this.PackedValue = ImageMaths.Get8BitBT709Luminance( - ImageMaths.DownScaleFrom16BitTo8Bit(source.R), - ImageMaths.DownScaleFrom16BitTo8Bit(source.G), - ImageMaths.DownScaleFrom16BitTo8Bit(source.B)); + => this.PackedValue = ImageMath.Get8BitBT709Luminance( + ImageMath.DownScaleFrom16BitTo8Bit(source.R), + ImageMath.DownScaleFrom16BitTo8Bit(source.G), + ImageMath.DownScaleFrom16BitTo8Bit(source.B)); /// public override readonly bool Equals(object obj) => obj is L8 other && this.Equals(other); @@ -157,7 +157,7 @@ namespace SixLabors.ImageSharp.PixelFormats vector *= MaxBytes; vector += Half; vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes); - this.PackedValue = ImageMaths.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z); + this.PackedValue = ImageMath.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z); } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs index bcfe67249..bf9484399 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs @@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromArgb32(Argb32 source) { - this.L = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B); + this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); this.A = source.A; } @@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) { - this.L = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B); + this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); this.A = byte.MaxValue; } @@ -108,7 +108,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) { - this.L = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B); + this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); this.A = source.A; } @@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - this.L = ImageMaths.DownScaleFrom16BitTo8Bit(source.PackedValue); + this.L = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); this.A = byte.MaxValue; } @@ -140,15 +140,15 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - this.L = ImageMaths.DownScaleFrom16BitTo8Bit(source.L); - this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A); + this.L = ImageMath.DownScaleFrom16BitTo8Bit(source.L); + this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb24(Rgb24 source) { - this.L = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B); + this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); this.A = byte.MaxValue; } @@ -156,10 +156,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.L = ImageMaths.Get8BitBT709Luminance( - ImageMaths.DownScaleFrom16BitTo8Bit(source.R), - ImageMaths.DownScaleFrom16BitTo8Bit(source.G), - ImageMaths.DownScaleFrom16BitTo8Bit(source.B)); + this.L = ImageMath.Get8BitBT709Luminance( + ImageMath.DownScaleFrom16BitTo8Bit(source.R), + ImageMath.DownScaleFrom16BitTo8Bit(source.G), + ImageMath.DownScaleFrom16BitTo8Bit(source.B)); this.A = byte.MaxValue; } @@ -168,19 +168,19 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) { - this.L = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B); + this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); this.A = source.A; } /// public void FromRgba64(Rgba64 source) { - this.L = ImageMaths.Get8BitBT709Luminance( - ImageMaths.DownScaleFrom16BitTo8Bit(source.R), - ImageMaths.DownScaleFrom16BitTo8Bit(source.G), - ImageMaths.DownScaleFrom16BitTo8Bit(source.B)); + this.L = ImageMath.Get8BitBT709Luminance( + ImageMath.DownScaleFrom16BitTo8Bit(source.R), + ImageMath.DownScaleFrom16BitTo8Bit(source.G), + ImageMath.DownScaleFrom16BitTo8Bit(source.B)); - this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A); + this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); } /// @@ -220,7 +220,7 @@ namespace SixLabors.ImageSharp.PixelFormats vector *= MaxBytes; vector += Half; vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes); - this.L = ImageMaths.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z); + this.L = ImageMath.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z); this.A = (byte)vector.W; } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs index 23f4b8e17..102d1b7cd 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs @@ -95,22 +95,22 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromArgb32(Argb32 source) { - this.L = ImageMaths.Get16BitBT709Luminance( - ImageMaths.UpscaleFrom8BitTo16Bit(source.R), - ImageMaths.UpscaleFrom8BitTo16Bit(source.G), - ImageMaths.UpscaleFrom8BitTo16Bit(source.B)); + this.L = ImageMath.Get16BitBT709Luminance( + ImageMath.UpscaleFrom8BitTo16Bit(source.R), + ImageMath.UpscaleFrom8BitTo16Bit(source.G), + ImageMath.UpscaleFrom8BitTo16Bit(source.B)); - this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A); + this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) { - this.L = ImageMaths.Get16BitBT709Luminance( - ImageMaths.UpscaleFrom8BitTo16Bit(source.R), - ImageMaths.UpscaleFrom8BitTo16Bit(source.G), - ImageMaths.UpscaleFrom8BitTo16Bit(source.B)); + this.L = ImageMath.Get16BitBT709Luminance( + ImageMath.UpscaleFrom8BitTo16Bit(source.R), + ImageMath.UpscaleFrom8BitTo16Bit(source.G), + ImageMath.UpscaleFrom8BitTo16Bit(source.B)); this.A = ushort.MaxValue; } @@ -119,12 +119,12 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) { - this.L = ImageMaths.Get16BitBT709Luminance( - ImageMaths.UpscaleFrom8BitTo16Bit(source.R), - ImageMaths.UpscaleFrom8BitTo16Bit(source.G), - ImageMaths.UpscaleFrom8BitTo16Bit(source.B)); + this.L = ImageMath.Get16BitBT709Luminance( + ImageMath.UpscaleFrom8BitTo16Bit(source.R), + ImageMath.UpscaleFrom8BitTo16Bit(source.G), + ImageMath.UpscaleFrom8BitTo16Bit(source.B)); - this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A); + this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL8(L8 source) { - this.L = ImageMaths.UpscaleFrom8BitTo16Bit(source.PackedValue); + this.L = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue); this.A = ushort.MaxValue; } @@ -151,8 +151,8 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa16(La16 source) { - this.L = ImageMaths.UpscaleFrom8BitTo16Bit(source.L); - this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A); + this.L = ImageMath.UpscaleFrom8BitTo16Bit(source.L); + this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -163,10 +163,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb24(Rgb24 source) { - this.L = ImageMaths.Get16BitBT709Luminance( - ImageMaths.UpscaleFrom8BitTo16Bit(source.R), - ImageMaths.UpscaleFrom8BitTo16Bit(source.G), - ImageMaths.UpscaleFrom8BitTo16Bit(source.B)); + this.L = ImageMath.Get16BitBT709Luminance( + ImageMath.UpscaleFrom8BitTo16Bit(source.R), + ImageMath.UpscaleFrom8BitTo16Bit(source.G), + ImageMath.UpscaleFrom8BitTo16Bit(source.B)); this.A = ushort.MaxValue; } @@ -175,7 +175,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.L = ImageMaths.Get16BitBT709Luminance(source.R, source.G, source.B); + this.L = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B); this.A = ushort.MaxValue; } @@ -183,19 +183,19 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) { - this.L = ImageMaths.Get16BitBT709Luminance( - ImageMaths.UpscaleFrom8BitTo16Bit(source.R), - ImageMaths.UpscaleFrom8BitTo16Bit(source.G), - ImageMaths.UpscaleFrom8BitTo16Bit(source.B)); + this.L = ImageMath.Get16BitBT709Luminance( + ImageMath.UpscaleFrom8BitTo16Bit(source.R), + ImageMath.UpscaleFrom8BitTo16Bit(source.G), + ImageMath.UpscaleFrom8BitTo16Bit(source.B)); - this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A); + this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.L = ImageMaths.Get16BitBT709Luminance(source.R, source.G, source.B); + this.L = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B); this.A = source.A; } @@ -211,11 +211,11 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void ToRgba32(ref Rgba32 dest) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(this.L); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(this.L); dest.R = rgb; dest.G = rgb; dest.B = rgb; - dest.A = ImageMaths.DownScaleFrom16BitTo8Bit(this.A); + dest.A = ImageMath.DownScaleFrom16BitTo8Bit(this.A); } /// @@ -234,7 +234,7 @@ namespace SixLabors.ImageSharp.PixelFormats internal void ConvertFromRgbaScaledVector4(Vector4 vector) { vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max; - this.L = ImageMaths.Get16BitBT709Luminance( + this.L = ImageMath.Get16BitBT709Luminance( vector.X, vector.Y, vector.Z); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs index a50c18d42..fd9ed12d7 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs @@ -166,7 +166,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.PackedValue); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -185,7 +185,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.L); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; @@ -227,18 +227,18 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B); + this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); + this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); + this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B); + this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); + this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); + this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs index 08f3bcc71..280044ceb 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs @@ -99,27 +99,27 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromArgb32(Argb32 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); } /// @@ -134,7 +134,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL8(L8 source) { - ushort rgb = ImageMaths.UpscaleFrom8BitTo16Bit(source.PackedValue); + ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa16(La16 source) { - ushort rgb = ImageMaths.UpscaleFrom8BitTo16Bit(source.L); + ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; @@ -172,27 +172,27 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb24(Rgb24 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void ToRgba32(ref Rgba32 dest) { - dest.R = ImageMaths.DownScaleFrom16BitTo8Bit(this.R); - dest.G = ImageMaths.DownScaleFrom16BitTo8Bit(this.G); - dest.B = ImageMaths.DownScaleFrom16BitTo8Bit(this.B); + dest.R = ImageMath.DownScaleFrom16BitTo8Bit(this.R); + dest.G = ImageMath.DownScaleFrom16BitTo8Bit(this.G); + dest.B = ImageMath.DownScaleFrom16BitTo8Bit(this.B); dest.A = byte.MaxValue; } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs index 0b4235101..2c74dc878 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs @@ -351,7 +351,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.PackedValue); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -372,11 +372,11 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - byte rgb = ImageMaths.DownScaleFrom16BitTo8Bit(source.L); + byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; - this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A); + this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); } /// @@ -402,9 +402,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B); + this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); + this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); + this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); this.A = byte.MaxValue; } @@ -412,10 +412,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.R = ImageMaths.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B); - this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A); + this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); + this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); + this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); + this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs index 22f58ca4a..7e84c6e5b 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs @@ -62,10 +62,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public Rgba64(Rgba32 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -75,10 +75,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public Rgba64(Bgra32 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -88,10 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public Rgba64(Argb32 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -101,9 +101,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public Rgba64(Rgb24 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); this.A = ushort.MaxValue; } @@ -114,9 +114,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public Rgba64(Bgr24 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); this.A = ushort.MaxValue; } @@ -224,19 +224,19 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromArgb32(Argb32 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); this.A = ushort.MaxValue; } @@ -244,10 +244,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -258,7 +258,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL8(L8 source) { - ushort rgb = ImageMaths.UpscaleFrom8BitTo16Bit(source.PackedValue); + ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -279,11 +279,11 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa16(La16 source) { - ushort rgb = ImageMaths.UpscaleFrom8BitTo16Bit(source.L); + ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; - this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A); + this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -300,9 +300,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb24(Rgb24 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); this.A = ushort.MaxValue; } @@ -310,20 +310,20 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) { - this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A); + this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); + this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); + this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); } /// [MethodImpl(InliningOptions.ShortMethod)] public void ToRgba32(ref Rgba32 dest) { - dest.R = ImageMaths.DownScaleFrom16BitTo8Bit(this.R); - dest.G = ImageMaths.DownScaleFrom16BitTo8Bit(this.G); - dest.B = ImageMaths.DownScaleFrom16BitTo8Bit(this.B); - dest.A = ImageMaths.DownScaleFrom16BitTo8Bit(this.A); + dest.R = ImageMath.DownScaleFrom16BitTo8Bit(this.R); + dest.G = ImageMath.DownScaleFrom16BitTo8Bit(this.G); + dest.B = ImageMath.DownScaleFrom16BitTo8Bit(this.B); + dest.A = ImageMath.DownScaleFrom16BitTo8Bit(this.A); } /// @@ -345,10 +345,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Rgba32 ToRgba32() { - byte r = ImageMaths.DownScaleFrom16BitTo8Bit(this.R); - byte g = ImageMaths.DownScaleFrom16BitTo8Bit(this.G); - byte b = ImageMaths.DownScaleFrom16BitTo8Bit(this.B); - byte a = ImageMaths.DownScaleFrom16BitTo8Bit(this.A); + byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R); + byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G); + byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B); + byte a = ImageMath.DownScaleFrom16BitTo8Bit(this.A); return new Rgba32(r, g, b, a); } @@ -359,10 +359,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Bgra32 ToBgra32() { - byte r = ImageMaths.DownScaleFrom16BitTo8Bit(this.R); - byte g = ImageMaths.DownScaleFrom16BitTo8Bit(this.G); - byte b = ImageMaths.DownScaleFrom16BitTo8Bit(this.B); - byte a = ImageMaths.DownScaleFrom16BitTo8Bit(this.A); + byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R); + byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G); + byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B); + byte a = ImageMath.DownScaleFrom16BitTo8Bit(this.A); return new Bgra32(r, g, b, a); } @@ -373,10 +373,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Argb32 ToArgb32() { - byte r = ImageMaths.DownScaleFrom16BitTo8Bit(this.R); - byte g = ImageMaths.DownScaleFrom16BitTo8Bit(this.G); - byte b = ImageMaths.DownScaleFrom16BitTo8Bit(this.B); - byte a = ImageMaths.DownScaleFrom16BitTo8Bit(this.A); + byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R); + byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G); + byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B); + byte a = ImageMath.DownScaleFrom16BitTo8Bit(this.A); return new Argb32(r, g, b, a); } @@ -387,9 +387,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Rgb24 ToRgb24() { - byte r = ImageMaths.DownScaleFrom16BitTo8Bit(this.R); - byte g = ImageMaths.DownScaleFrom16BitTo8Bit(this.G); - byte b = ImageMaths.DownScaleFrom16BitTo8Bit(this.B); + byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R); + byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G); + byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B); return new Rgb24(r, g, b); } @@ -400,9 +400,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Bgr24 ToBgr24() { - byte r = ImageMaths.DownScaleFrom16BitTo8Bit(this.R); - byte g = ImageMaths.DownScaleFrom16BitTo8Bit(this.G); - byte b = ImageMaths.DownScaleFrom16BitTo8Bit(this.B); + byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R); + byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G); + byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B); return new Bgr24(r, g, b); } diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs index e5672ee9d..a47937baf 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization color.ToRgba32(ref rgba); // Convert to grayscale using ITU-R Recommendation BT.709 if required - byte luminance = this.isAlphaOnly ? rgba.A : ImageMaths.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B); + byte luminance = this.isAlphaOnly ? rgba.A : ImageMath.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B); color = luminance >= this.threshold ? this.upper : this.lower; } } diff --git a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs index 448eb3833..80c777cd7 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs @@ -218,7 +218,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering this.source = source; this.destination = destination; this.bounds = bounds; - this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(destination.Palette.Length); + this.bitDepth = ImageMath.GetBitsNeededForColorDepth(destination.Palette.Length); } [MethodImpl(InliningOptions.ShortMethod)] @@ -262,7 +262,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering this.source = source; this.bounds = bounds; this.scale = processor.DitherScale; - this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(processor.Palette.Length); + this.bitDepth = ImageMath.GetBitsNeededForColorDepth(processor.Palette.Length); } [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs index 007a9a05d..255812078 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs @@ -259,7 +259,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization { for (int idx = 0; idx < length; idx++) { - int luminance = ImageMaths.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); + int luminance = ImageMath.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); Unsafe.Add(ref histogramBase, luminance)++; } } @@ -276,7 +276,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization { for (int idx = 0; idx < length; idx++) { - int luminance = ImageMaths.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); + int luminance = ImageMath.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); Unsafe.Add(ref histogramBase, luminance)--; } } diff --git a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs index 74d293566..b45773e9a 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs @@ -123,7 +123,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization { // TODO: We should bulk convert here. var vector = pixelRow[x].ToVector4(); - int luminance = ImageMaths.GetBT709Luminance(ref vector, levels); + int luminance = ImageMath.GetBT709Luminance(ref vector, levels); Interlocked.Increment(ref Unsafe.Add(ref histogramBase, luminance)); } } @@ -174,7 +174,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization // TODO: We should bulk convert here. ref TPixel pixel = ref pixelRow[x]; var vector = pixel.ToVector4(); - int luminance = ImageMaths.GetBT709Luminance(ref vector, levels); + int luminance = ImageMath.GetBT709Luminance(ref vector, levels); float luminanceEqualized = Unsafe.Add(ref cdfBase, luminance) / noOfPixelsMinusCdfMin; pixel.FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, vector.W)); } diff --git a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs index 2849574bc..3bba95bc6 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization public static int GetLuminance(TPixel sourcePixel, int luminanceLevels) { var vector = sourcePixel.ToVector4(); - return ImageMaths.GetBT709Luminance(ref vector, luminanceLevels); + return ImageMath.GetBT709Luminance(ref vector, luminanceLevels); } } } diff --git a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs index f4d55ebeb..50eeef8ca 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization this.Options = options; this.maxColors = this.Options.MaxColors; - this.octree = new Octree(ImageMaths.GetBitsNeededForColorDepth(this.maxColors).Clamp(1, 8)); + this.octree = new Octree(ImageMath.GetBitsNeededForColorDepth(this.maxColors).Clamp(1, 8)); this.paletteOwner = configuration.MemoryAllocator.Allocate(this.maxColors, AllocationOptions.Clean); this.palette = default; this.pixelMap = default; diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs index dd9c06938..27d40e77b 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms new BinaryThresholdProcessor(this.definition.Threshold).Execute(this.Configuration, temp, this.SourceRectangle); // Search for the first white pixels - rectangle = ImageMaths.GetFilteredBoundingRectangle(temp.Frames.RootFrame, 0); + rectangle = ImageMath.GetFilteredBoundingRectangle(temp.Frames.RootFrame, 0); } new CropProcessor(rectangle, this.Source.Size()).Execute(this.Configuration, this.Source, this.SourceRectangle); diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index b4670cb5d..cd5e3a5e4 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -435,7 +435,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png Rgba32 expectedColor = Color.Blue; if (colorType == PngColorType.Grayscale || colorType == PngColorType.GrayscaleWithAlpha) { - var luminance = ImageMaths.Get8BitBT709Luminance(expectedColor.R, expectedColor.G, expectedColor.B); + var luminance = ImageMath.Get8BitBT709Luminance(expectedColor.R, expectedColor.G, expectedColor.B); expectedColor = new Rgba32(luminance, luminance, luminance); } diff --git a/tests/ImageSharp.Tests/Helpers/ImageMathsTests.cs b/tests/ImageSharp.Tests/Helpers/ImageMathTests.cs similarity index 85% rename from tests/ImageSharp.Tests/Helpers/ImageMathsTests.cs rename to tests/ImageSharp.Tests/Helpers/ImageMathTests.cs index 656d8ce3b..687c13fd5 100644 --- a/tests/ImageSharp.Tests/Helpers/ImageMathsTests.cs +++ b/tests/ImageSharp.Tests/Helpers/ImageMathTests.cs @@ -1,14 +1,13 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. -using System; using System.Numerics; using Xunit; namespace SixLabors.ImageSharp.Tests.Helpers { - public class ImageMathsTests + public class ImageMathTests { [Theory] [InlineData(0.2f, 0.7f, 0.1f, 256, 140)] @@ -21,7 +20,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers var vector = new Vector4(x, y, z, 0.0f); // act - int actual = ImageMaths.GetBT709Luminance(ref vector, luminanceLevels); + int actual = ImageMath.GetBT709Luminance(ref vector, luminanceLevels); // assert Assert.Equal(expected, actual); diff --git a/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs b/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs index 4204fc2f7..113a39bff 100644 --- a/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs @@ -113,8 +113,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats // Arrange L16 gray = default; const byte rgb = 128; - ushort scaledRgb = ImageMaths.UpscaleFrom8BitTo16Bit(rgb); - ushort expected = ImageMaths.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb); + ushort scaledRgb = ImageMath.UpscaleFrom8BitTo16Bit(rgb); + ushort expected = ImageMath.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb); // Act gray.FromRgba32(new Rgba32(rgb, rgb, rgb)); @@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public void L16_ToRgba32(ushort input) { // Arrange - ushort expected = ImageMaths.DownScaleFrom16BitTo8Bit(input); + ushort expected = ImageMath.DownScaleFrom16BitTo8Bit(input); var gray = new L16(input); // Act diff --git a/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs b/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs index 09d67ab9a..798eb3b1a 100644 --- a/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs @@ -136,7 +136,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats { // Arrange L8 gray = default; - byte expected = ImageMaths.Get8BitBT709Luminance(rgb, rgb, rgb); + byte expected = ImageMath.Get8BitBT709Luminance(rgb, rgb, rgb); // Act gray.FromRgba32(new Rgba32(rgb, rgb, rgb)); diff --git a/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs b/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs index f36d9765c..46d7d09b4 100644 --- a/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs @@ -138,7 +138,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats { // Arrange La16 gray = default; - byte expected = ImageMaths.Get8BitBT709Luminance(rgb, rgb, rgb); + byte expected = ImageMath.Get8BitBT709Luminance(rgb, rgb, rgb); // Act gray.FromRgba32(new Rgba32(rgb, rgb, rgb)); diff --git a/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs index d3fdbd085..159abac4a 100644 --- a/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs @@ -117,8 +117,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats // Arrange La32 gray = default; const byte rgb = 128; - ushort scaledRgb = ImageMaths.UpscaleFrom8BitTo16Bit(rgb); - ushort expected = ImageMaths.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb); + ushort scaledRgb = ImageMath.UpscaleFrom8BitTo16Bit(rgb); + ushort expected = ImageMath.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb); // Act gray.FromRgba32(new Rgba32(rgb, rgb, rgb)); @@ -136,7 +136,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public void La32_ToRgba32(ushort input) { // Arrange - ushort expected = ImageMaths.DownScaleFrom16BitTo8Bit(input); + ushort expected = ImageMath.DownScaleFrom16BitTo8Bit(input); var gray = new La32(input, ushort.MaxValue); // Act From 3bdbfe620e16b7c9d45d260d475861982ce3b3c6 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 23 Nov 2020 00:44:32 +0000 Subject: [PATCH 18/39] Replace clamp extensions --- .../Common/Extensions/ComparableExtensions.cs | 140 ---- .../Common/Helpers/Buffer2DUtils.cs | 8 +- .../Common/Helpers/DenseMatrixUtils.cs | 8 +- src/ImageSharp/Common/Helpers/ImageMath.cs | 4 +- src/ImageSharp/Common/Helpers/SimdUtils.cs | 2 +- .../Formats/Jpeg/JpegEncoderCore.cs | 4 +- .../Formats/Png/PngEncoderOptionsHelpers.cs | 2 +- .../Profiles/ICC/DataReader/IccDataReader.cs | 2 +- .../ICC/DataWriter/IccDataWriter.Lut.cs | 10 +- .../DataWriter/IccDataWriter.NonPrimitives.cs | 6 +- .../DataWriter/IccDataWriter.Primitives.cs | 10 +- .../DataWriter/IccDataWriter.TagDataEntry.cs | 2 +- .../DefaultPixelBlenders.Generated.cs | 648 +++++++++--------- .../DefaultPixelBlenders.Generated.tt | 6 +- .../PorterDuffFunctions.Generated.cs | 216 +++--- .../PorterDuffFunctions.Generated.tt | 2 +- .../PixelFormats/PixelImplementations/A8.cs | 2 +- src/ImageSharp/Primitives/Number.cs | 8 +- .../Processors/Dithering/OrderedDither.cs | 8 +- .../Dithering/PaletteDitherProcessor.cs | 2 +- .../Effects/OilPaintingProcessor{TPixel}.cs | 5 +- .../Overlays/GlowProcessor{TPixel}.cs | 2 +- .../Overlays/VignetteProcessor{TPixel}.cs | 2 +- .../Quantization/OctreeQuantizer{TPixel}.cs | 2 +- .../Quantization/QuantizerOptions.cs | 4 +- .../ImageSharp.Benchmarks/Color/YcbCrToRgb.cs | 19 +- .../General/BasicMath/ClampSpan.cs | 2 +- 27 files changed, 492 insertions(+), 634 deletions(-) delete mode 100644 src/ImageSharp/Common/Extensions/ComparableExtensions.cs diff --git a/src/ImageSharp/Common/Extensions/ComparableExtensions.cs b/src/ImageSharp/Common/Extensions/ComparableExtensions.cs deleted file mode 100644 index ef3d1deac..000000000 --- a/src/ImageSharp/Common/Extensions/ComparableExtensions.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Runtime.CompilerServices; - -namespace SixLabors.ImageSharp -{ - /// - /// Extension methods for classes that implement . - /// - internal static class ComparableExtensions - { - /// - /// Restricts a to be within a specified range. - /// - /// The value to clamp. - /// The minimum value. If value is less than min, min will be returned. - /// The maximum value. If value is greater than max, max will be returned. - /// - /// The representing the clamped value. - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static byte Clamp(this byte value, byte min, byte max) - { - // Order is important here as someone might set min to higher than max. - if (value >= max) - { - return max; - } - - if (value <= min) - { - return min; - } - - return value; - } - - /// - /// Restricts a to be within a specified range. - /// - /// The The value to clamp. - /// The minimum value. If value is less than min, min will be returned. - /// The maximum value. If value is greater than max, max will be returned. - /// - /// The representing the clamped value. - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static uint Clamp(this uint value, uint min, uint max) - { - if (value >= max) - { - return max; - } - - if (value <= min) - { - return min; - } - - return value; - } - - /// - /// Restricts a to be within a specified range. - /// - /// The The value to clamp. - /// The minimum value. If value is less than min, min will be returned. - /// The maximum value. If value is greater than max, max will be returned. - /// - /// The representing the clamped value. - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static int Clamp(this int value, int min, int max) - { - if (value >= max) - { - return max; - } - - if (value <= min) - { - return min; - } - - return value; - } - - /// - /// Restricts a to be within a specified range. - /// - /// The The value to clamp. - /// The minimum value. If value is less than min, min will be returned. - /// The maximum value. If value is greater than max, max will be returned. - /// - /// The representing the clamped value. - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static float Clamp(this float value, float min, float max) - { - if (value >= max) - { - return max; - } - - if (value <= min) - { - return min; - } - - return value; - } - - /// - /// Restricts a to be within a specified range. - /// - /// The The value to clamp. - /// The minimum value. If value is less than min, min will be returned. - /// The maximum value. If value is greater than max, max will be returned. - /// - /// The representing the clamped value. - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static double Clamp(this double value, double min, double max) - { - if (value >= max) - { - return max; - } - - if (value <= min) - { - return min; - } - - return value; - } - } -} diff --git a/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs b/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs index f4811d6ca..02a5afff7 100644 --- a/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs +++ b/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs @@ -50,8 +50,8 @@ namespace SixLabors.ImageSharp for (int i = 0; i < kernelLength; i++) { - int offsetY = (row + i - radiusY).Clamp(minRow, maxRow); - int offsetX = sourceOffsetColumnBase.Clamp(minColumn, maxColumn); + int offsetY = Numerics.Clamp(row + i - radiusY, minRow, maxRow); + int offsetX = Numerics.Clamp(sourceOffsetColumnBase, minColumn, maxColumn); Span sourceRowSpan = sourcePixels.GetRowSpan(offsetY); var currentColor = sourceRowSpan[offsetX].ToVector4(); @@ -93,13 +93,13 @@ namespace SixLabors.ImageSharp int radiusX = kernelLength >> 1; int sourceOffsetColumnBase = column + minColumn; - int offsetY = row.Clamp(minRow, maxRow); + int offsetY = Numerics.Clamp(row, minRow, maxRow); ref ComplexVector4 sourceRef = ref MemoryMarshal.GetReference(sourceValues.GetRowSpan(offsetY)); ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel); for (int x = 0; x < kernelLength; x++) { - int offsetX = (sourceOffsetColumnBase + x - radiusX).Clamp(minColumn, maxColumn); + int offsetX = Numerics.Clamp(sourceOffsetColumnBase + x - radiusX, minColumn, maxColumn); vector.Sum(Unsafe.Add(ref baseRef, x) * Unsafe.Add(ref sourceRef, offsetX)); } diff --git a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs index 61f90e23e..69c50573f 100644 --- a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs +++ b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs @@ -133,12 +133,12 @@ namespace SixLabors.ImageSharp for (int y = 0; y < matrixHeight; y++) { - int offsetY = (row + y - radiusY).Clamp(minRow, maxRow); + int offsetY = Numerics.Clamp(row + y - radiusY, minRow, maxRow); Span sourceRowSpan = sourcePixels.GetRowSpan(offsetY); for (int x = 0; x < matrixWidth; x++) { - int offsetX = (sourceOffsetColumnBase + x - radiusX).Clamp(minColumn, maxColumn); + int offsetX = Numerics.Clamp(sourceOffsetColumnBase + x - radiusX, minColumn, maxColumn); var currentColor = sourceRowSpan[offsetX].ToVector4(); Vector4Utilities.Premultiply(ref currentColor); @@ -263,12 +263,12 @@ namespace SixLabors.ImageSharp for (int y = 0; y < matrixHeight; y++) { - int offsetY = (row + y - radiusY).Clamp(minRow, maxRow); + int offsetY = Numerics.Clamp(row + y - radiusY, minRow, maxRow); Span sourceRowSpan = sourcePixels.GetRowSpan(offsetY); for (int x = 0; x < matrixWidth; x++) { - int offsetX = (sourceOffsetColumnBase + x - radiusX).Clamp(minColumn, maxColumn); + int offsetX = Numerics.Clamp(sourceOffsetColumnBase + x - radiusX, minColumn, maxColumn); var currentColor = sourceRowSpan[offsetX].ToVector4(); Vector4Utilities.Premultiply(ref currentColor); vector += matrix[y, x] * currentColor; diff --git a/src/ImageSharp/Common/Helpers/ImageMath.cs b/src/ImageSharp/Common/Helpers/ImageMath.cs index 11fb60209..59f9ad021 100644 --- a/src/ImageSharp/Common/Helpers/ImageMath.cs +++ b/src/ImageSharp/Common/Helpers/ImageMath.cs @@ -248,8 +248,8 @@ namespace SixLabors.ImageSharp topLeft.Y = GetMinY(bitmap); topLeft.X = GetMinX(bitmap); - bottomRight.Y = (GetMaxY(bitmap) + 1).Clamp(0, height); - bottomRight.X = (GetMaxX(bitmap) + 1).Clamp(0, width); + bottomRight.Y = Numerics.Clamp(GetMaxY(bitmap) + 1, 0, height); + bottomRight.X = Numerics.Clamp(GetMaxX(bitmap) + 1, 0, width); return GetBoundingRectangle(topLeft, bottomRight); } diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.cs b/src/ImageSharp/Common/Helpers/SimdUtils.cs index 7691cb9ad..a0cb513ef 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.cs @@ -190,7 +190,7 @@ namespace SixLabors.ImageSharp } [MethodImpl(InliningOptions.ShortMethod)] - private static byte ConvertToByte(float f) => (byte)ComparableExtensions.Clamp((f * 255f) + 0.5f, 0, 255f); + private static byte ConvertToByte(float f) => (byte)Numerics.Clamp((f * 255F) + 0.5F, 0, 255F); [Conditional("DEBUG")] private static void VerifyHasVector8(string operation) diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index c4ff1c036..36766d05f 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -212,8 +212,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg ImageMetadata metadata = image.Metadata; // System.Drawing produces identical output for jpegs with a quality parameter of 0 and 1. - int qlty = (this.quality ?? metadata.GetJpegMetadata().Quality).Clamp(1, 100); - this.subsample = this.subsample ?? (qlty >= 91 ? JpegSubsample.Ratio444 : JpegSubsample.Ratio420); + int qlty = Numerics.Clamp(this.quality ?? metadata.GetJpegMetadata().Quality, 1, 100); + this.subsample ??= qlty >= 91 ? JpegSubsample.Ratio444 : JpegSubsample.Ratio420; // Convert from a quality rating to a scaling factor. int scale; diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs index 3343923b7..f1f5145ca 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Formats.Png byte bitDepth; if (options.ColorType == PngColorType.Palette) { - byte quantizedBits = (byte)ImageMath.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length).Clamp(1, 8); + byte quantizedBits = (byte)Numerics.Clamp(ImageMath.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length), 1, 8); byte bits = Math.Max((byte)options.BitDepth, quantizedBits); // Png only supports in four pixel depths: 1, 2, 4, and 8 bits when using the PLTE chunk diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.cs index 925a86ac2..8e9cad563 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.cs @@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc /// The new index position public void SetIndex(int index) { - this.currentIndex = index.Clamp(0, this.data.Length); + this.currentIndex = Numerics.Clamp(index, 0, this.data.Length); } /// diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs index a5eef3d23..40a1792e2 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. namespace SixLabors.ImageSharp.Metadata.Profiles.Icc @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc { foreach (float item in value.Values) { - this.WriteByte((byte)((item * byte.MaxValue) + 0.5f).Clamp(0, byte.MaxValue)); + this.WriteByte((byte)Numerics.Clamp((item * byte.MaxValue) + 0.5F, 0, byte.MaxValue)); } return value.Values.Length; @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc { foreach (float item in value.Values) { - this.WriteUInt16((ushort)((item * ushort.MaxValue) + 0.5f).Clamp(0, ushort.MaxValue)); + this.WriteUInt16((ushort)Numerics.Clamp((item * ushort.MaxValue) + 0.5F, 0, ushort.MaxValue)); } return value.Values.Length * 2; @@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc { foreach (float item in inArray) { - count += this.WriteByte((byte)((item * byte.MaxValue) + 0.5f).Clamp(0, byte.MaxValue)); + count += this.WriteByte((byte)Numerics.Clamp((item * byte.MaxValue) + 0.5F, 0, byte.MaxValue)); } } @@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc { foreach (float item in inArray) { - count += this.WriteUInt16((ushort)((item * ushort.MaxValue) + 0.5f).Clamp(0, ushort.MaxValue)); + count += this.WriteUInt16((ushort)Numerics.Clamp((item * ushort.MaxValue) + 0.5F, 0, ushort.MaxValue)); } } diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs index 53dd5f008..305fe47fd 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs @@ -33,9 +33,9 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc /// the number of bytes written public int WriteVersionNumber(in IccVersion value) { - int major = value.Major.Clamp(0, byte.MaxValue); - int minor = value.Minor.Clamp(0, 15); - int bugfix = value.Patch.Clamp(0, 15); + int major = Numerics.Clamp(value.Major, 0, byte.MaxValue); + int minor = Numerics.Clamp(value.Minor, 0, 15); + int bugfix = Numerics.Clamp(value.Patch, 0, 15); int version = (major << 24) | (minor << 20) | (bugfix << 16); return this.WriteInt32(version); diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs index 5fb8e57d2..c58dd9656 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. using System; @@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc const double Max = short.MaxValue + (65535d / 65536d); const double Min = short.MinValue; - value = value.Clamp(Min, Max); + value = Numerics.Clamp(value, Min, Max); value *= 65536d; return this.WriteInt32((int)Math.Round(value, MidpointRounding.AwayFromZero)); @@ -128,7 +128,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc const double Max = ushort.MaxValue + (65535d / 65536d); const double Min = ushort.MinValue; - value = value.Clamp(Min, Max); + value = Numerics.Clamp(value, Min, Max); value *= 65536d; return this.WriteUInt32((uint)Math.Round(value, MidpointRounding.AwayFromZero)); @@ -144,7 +144,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc const double Max = 1 + (32767d / 32768d); const double Min = 0; - value = value.Clamp(Min, Max); + value = Numerics.Clamp(value, Min, Max); value *= 32768d; return this.WriteUInt16((ushort)Math.Round(value, MidpointRounding.AwayFromZero)); @@ -160,7 +160,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc const double Max = byte.MaxValue + (255d / 256d); const double Min = byte.MinValue; - value = value.Clamp(Min, Max); + value = Numerics.Clamp(value, Min, Max); value *= 256d; return this.WriteUInt16((ushort)Math.Round(value, MidpointRounding.AwayFromZero)); diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs index fdbf2a477..25454fa95 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs @@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc count += this.WriteUInt32((uint)value.CurveData.Length); for (int i = 0; i < value.CurveData.Length; i++) { - count += this.WriteUInt16((ushort)((value.CurveData[i] * ushort.MaxValue) + 0.5f).Clamp(0, ushort.MaxValue)); + count += this.WriteUInt16((ushort)Numerics.Clamp((value.CurveData[i] * ushort.MaxValue) + 0.5F, 0, ushort.MaxValue)); } } diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs index 2cb528a03..db61d9383 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs @@ -36,14 +36,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalSrc(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrc(background[i], source[i], amount); @@ -55,7 +55,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalSrc(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalSrc(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -74,14 +74,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplySrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplySrc(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrc(background[i], source[i], amount); @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplySrc(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplySrc(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -112,14 +112,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddSrc(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrc(background[i], source[i], amount); @@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddSrc(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddSrc(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -150,14 +150,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractSrc(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrc(background[i], source[i], amount); @@ -169,7 +169,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractSrc(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractSrc(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -188,14 +188,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenSrc(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrc(background[i], source[i], amount); @@ -207,7 +207,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenSrc(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenSrc(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -226,14 +226,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenSrc(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrc(background[i], source[i], amount); @@ -245,7 +245,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenSrc(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenSrc(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -264,14 +264,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenSrc(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrc(background[i], source[i], amount); @@ -283,7 +283,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenSrc(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenSrc(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -302,14 +302,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlaySrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlaySrc(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrc(background[i], source[i], amount); @@ -321,7 +321,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlaySrc(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlaySrc(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -340,14 +340,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightSrc(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrc(background[i], source[i], amount); @@ -359,7 +359,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightSrc(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightSrc(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -378,14 +378,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcAtop(background[i], source[i], amount); @@ -397,7 +397,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalSrcAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -416,14 +416,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcAtop(background[i], source[i], amount); @@ -435,7 +435,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplySrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplySrcAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -454,14 +454,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcAtop(background[i], source[i], amount); @@ -473,7 +473,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddSrcAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -492,14 +492,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcAtop(background[i], source[i], amount); @@ -511,7 +511,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractSrcAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -530,14 +530,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcAtop(background[i], source[i], amount); @@ -549,7 +549,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenSrcAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -568,14 +568,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcAtop(background[i], source[i], amount); @@ -587,7 +587,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenSrcAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -606,14 +606,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcAtop(background[i], source[i], amount); @@ -625,7 +625,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenSrcAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -644,14 +644,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcAtop(background[i], source[i], amount); @@ -663,7 +663,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlaySrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlaySrcAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -682,14 +682,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcAtop(background[i], source[i], amount); @@ -701,7 +701,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightSrcAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightSrcAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -720,14 +720,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcOver(background[i], source[i], amount); @@ -739,7 +739,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalSrcOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -758,14 +758,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcOver(background[i], source[i], amount); @@ -777,7 +777,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplySrcOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplySrcOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -796,14 +796,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcOver(background[i], source[i], amount); @@ -815,7 +815,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddSrcOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -834,14 +834,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcOver(background[i], source[i], amount); @@ -853,7 +853,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractSrcOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -872,14 +872,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcOver(background[i], source[i], amount); @@ -891,7 +891,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenSrcOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -910,14 +910,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcOver(background[i], source[i], amount); @@ -929,7 +929,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenSrcOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -948,14 +948,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcOver(background[i], source[i], amount); @@ -967,7 +967,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenSrcOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -986,14 +986,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcOver(background[i], source[i], amount); @@ -1005,7 +1005,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlaySrcOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlaySrcOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1024,14 +1024,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcOver(background[i], source[i], amount); @@ -1043,7 +1043,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightSrcOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightSrcOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1062,14 +1062,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcIn(background[i], source[i], amount); @@ -1081,7 +1081,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalSrcIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1100,14 +1100,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcIn(background[i], source[i], amount); @@ -1119,7 +1119,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplySrcIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplySrcIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1138,14 +1138,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcIn(background[i], source[i], amount); @@ -1157,7 +1157,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddSrcIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1176,14 +1176,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcIn(background[i], source[i], amount); @@ -1195,7 +1195,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractSrcIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1214,14 +1214,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcIn(background[i], source[i], amount); @@ -1233,7 +1233,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenSrcIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1252,14 +1252,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcIn(background[i], source[i], amount); @@ -1271,7 +1271,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenSrcIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1290,14 +1290,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcIn(background[i], source[i], amount); @@ -1309,7 +1309,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenSrcIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1328,14 +1328,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcIn(background[i], source[i], amount); @@ -1347,7 +1347,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlaySrcIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlaySrcIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1366,14 +1366,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcIn(background[i], source[i], amount); @@ -1385,7 +1385,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightSrcIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightSrcIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1404,14 +1404,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalSrcOut(background[i], source[i], amount); @@ -1423,7 +1423,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalSrcOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1442,14 +1442,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplySrcOut(background[i], source[i], amount); @@ -1461,7 +1461,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplySrcOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplySrcOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1480,14 +1480,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddSrcOut(background[i], source[i], amount); @@ -1499,7 +1499,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddSrcOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1518,14 +1518,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractSrcOut(background[i], source[i], amount); @@ -1537,7 +1537,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractSrcOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1556,14 +1556,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenSrcOut(background[i], source[i], amount); @@ -1575,7 +1575,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenSrcOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1594,14 +1594,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenSrcOut(background[i], source[i], amount); @@ -1613,7 +1613,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenSrcOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1632,14 +1632,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenSrcOut(background[i], source[i], amount); @@ -1651,7 +1651,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenSrcOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1670,14 +1670,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlaySrcOut(background[i], source[i], amount); @@ -1689,7 +1689,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlaySrcOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlaySrcOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1708,14 +1708,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightSrcOut(background[i], source[i], amount); @@ -1727,7 +1727,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightSrcOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightSrcOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1746,14 +1746,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalDest(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDest(background[i], source[i], amount); @@ -1765,7 +1765,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalDest(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalDest(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1784,14 +1784,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplyDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplyDest(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDest(background[i], source[i], amount); @@ -1803,7 +1803,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplyDest(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplyDest(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1822,14 +1822,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddDest(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDest(background[i], source[i], amount); @@ -1841,7 +1841,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddDest(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddDest(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1860,14 +1860,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractDest(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDest(background[i], source[i], amount); @@ -1879,7 +1879,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractDest(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractDest(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1898,14 +1898,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenDest(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDest(background[i], source[i], amount); @@ -1917,7 +1917,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenDest(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenDest(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1936,14 +1936,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenDest(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDest(background[i], source[i], amount); @@ -1955,7 +1955,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenDest(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenDest(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -1974,14 +1974,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenDest(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDest(background[i], source[i], amount); @@ -1993,7 +1993,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenDest(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenDest(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2012,14 +2012,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlayDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlayDest(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDest(background[i], source[i], amount); @@ -2031,7 +2031,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlayDest(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlayDest(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2050,14 +2050,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightDest(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightDest(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDest(background[i], source[i], amount); @@ -2069,7 +2069,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightDest(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightDest(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2088,14 +2088,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestAtop(background[i], source[i], amount); @@ -2107,7 +2107,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalDestAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2126,14 +2126,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestAtop(background[i], source[i], amount); @@ -2145,7 +2145,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplyDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplyDestAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2164,14 +2164,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestAtop(background[i], source[i], amount); @@ -2183,7 +2183,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddDestAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2202,14 +2202,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestAtop(background[i], source[i], amount); @@ -2221,7 +2221,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractDestAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2240,14 +2240,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestAtop(background[i], source[i], amount); @@ -2259,7 +2259,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenDestAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2278,14 +2278,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestAtop(background[i], source[i], amount); @@ -2297,7 +2297,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenDestAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2316,14 +2316,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestAtop(background[i], source[i], amount); @@ -2335,7 +2335,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenDestAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2354,14 +2354,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlayDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlayDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestAtop(background[i], source[i], amount); @@ -2373,7 +2373,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlayDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlayDestAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2392,14 +2392,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightDestAtop(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestAtop(background[i], source[i], amount); @@ -2411,7 +2411,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightDestAtop(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightDestAtop(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2430,14 +2430,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalDestOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestOver(background[i], source[i], amount); @@ -2449,7 +2449,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalDestOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalDestOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2468,14 +2468,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestOver(background[i], source[i], amount); @@ -2487,7 +2487,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplyDestOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplyDestOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2506,14 +2506,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddDestOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestOver(background[i], source[i], amount); @@ -2525,7 +2525,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddDestOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddDestOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2544,14 +2544,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractDestOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestOver(background[i], source[i], amount); @@ -2563,7 +2563,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractDestOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractDestOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2582,14 +2582,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenDestOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestOver(background[i], source[i], amount); @@ -2601,7 +2601,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenDestOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenDestOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2620,14 +2620,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenDestOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestOver(background[i], source[i], amount); @@ -2639,7 +2639,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenDestOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenDestOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2658,14 +2658,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenDestOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestOver(background[i], source[i], amount); @@ -2677,7 +2677,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenDestOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenDestOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2696,14 +2696,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlayDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlayDestOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestOver(background[i], source[i], amount); @@ -2715,7 +2715,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlayDestOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlayDestOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2734,14 +2734,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightDestOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightDestOver(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestOver(background[i], source[i], amount); @@ -2753,7 +2753,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightDestOver(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightDestOver(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2772,14 +2772,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalDestIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestIn(background[i], source[i], amount); @@ -2791,7 +2791,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalDestIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalDestIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2810,14 +2810,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestIn(background[i], source[i], amount); @@ -2829,7 +2829,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplyDestIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplyDestIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2848,14 +2848,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddDestIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestIn(background[i], source[i], amount); @@ -2867,7 +2867,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddDestIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddDestIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2886,14 +2886,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractDestIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestIn(background[i], source[i], amount); @@ -2905,7 +2905,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractDestIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractDestIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2924,14 +2924,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenDestIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestIn(background[i], source[i], amount); @@ -2943,7 +2943,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenDestIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenDestIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -2962,14 +2962,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenDestIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestIn(background[i], source[i], amount); @@ -2981,7 +2981,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenDestIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenDestIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3000,14 +3000,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenDestIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestIn(background[i], source[i], amount); @@ -3019,7 +3019,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenDestIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenDestIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3038,14 +3038,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlayDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlayDestIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestIn(background[i], source[i], amount); @@ -3057,7 +3057,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlayDestIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlayDestIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3076,14 +3076,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightDestIn(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightDestIn(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestIn(background[i], source[i], amount); @@ -3095,7 +3095,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightDestIn(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightDestIn(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3114,14 +3114,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalDestOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalDestOut(background[i], source[i], amount); @@ -3133,7 +3133,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalDestOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalDestOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3152,14 +3152,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplyDestOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyDestOut(background[i], source[i], amount); @@ -3171,7 +3171,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplyDestOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplyDestOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3190,14 +3190,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddDestOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddDestOut(background[i], source[i], amount); @@ -3209,7 +3209,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddDestOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddDestOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3228,14 +3228,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractDestOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractDestOut(background[i], source[i], amount); @@ -3247,7 +3247,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractDestOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractDestOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3266,14 +3266,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenDestOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenDestOut(background[i], source[i], amount); @@ -3285,7 +3285,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenDestOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenDestOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3304,14 +3304,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenDestOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenDestOut(background[i], source[i], amount); @@ -3323,7 +3323,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenDestOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenDestOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3342,14 +3342,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenDestOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenDestOut(background[i], source[i], amount); @@ -3361,7 +3361,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenDestOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenDestOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3380,14 +3380,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlayDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlayDestOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayDestOut(background[i], source[i], amount); @@ -3399,7 +3399,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlayDestOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlayDestOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3418,14 +3418,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightDestOut(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightDestOut(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightDestOut(background[i], source[i], amount); @@ -3437,7 +3437,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightDestOut(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightDestOut(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3456,14 +3456,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalClear(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalClear(background[i], source[i], amount); @@ -3475,7 +3475,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalClear(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalClear(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3494,14 +3494,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplyClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplyClear(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyClear(background[i], source[i], amount); @@ -3513,7 +3513,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplyClear(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplyClear(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3532,14 +3532,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddClear(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddClear(background[i], source[i], amount); @@ -3551,7 +3551,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddClear(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddClear(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3570,14 +3570,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractClear(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractClear(background[i], source[i], amount); @@ -3589,7 +3589,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractClear(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractClear(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3608,14 +3608,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenClear(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenClear(background[i], source[i], amount); @@ -3627,7 +3627,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenClear(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenClear(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3646,14 +3646,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenClear(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenClear(background[i], source[i], amount); @@ -3665,7 +3665,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenClear(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenClear(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3684,14 +3684,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenClear(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenClear(background[i], source[i], amount); @@ -3703,7 +3703,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenClear(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenClear(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3722,14 +3722,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlayClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlayClear(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayClear(background[i], source[i], amount); @@ -3741,7 +3741,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlayClear(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlayClear(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3760,14 +3760,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightClear(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightClear(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightClear(background[i], source[i], amount); @@ -3779,7 +3779,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightClear(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightClear(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3798,14 +3798,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.NormalXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.NormalXor(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.NormalXor(background[i], source[i], amount); @@ -3817,7 +3817,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.NormalXor(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.NormalXor(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3836,14 +3836,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.MultiplyXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.MultiplyXor(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.MultiplyXor(background[i], source[i], amount); @@ -3855,7 +3855,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.MultiplyXor(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.MultiplyXor(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3874,14 +3874,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.AddXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.AddXor(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.AddXor(background[i], source[i], amount); @@ -3893,7 +3893,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.AddXor(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.AddXor(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3912,14 +3912,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.SubtractXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.SubtractXor(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.SubtractXor(background[i], source[i], amount); @@ -3931,7 +3931,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.SubtractXor(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.SubtractXor(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3950,14 +3950,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.ScreenXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.ScreenXor(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.ScreenXor(background[i], source[i], amount); @@ -3969,7 +3969,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.ScreenXor(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.ScreenXor(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -3988,14 +3988,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.DarkenXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.DarkenXor(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.DarkenXor(background[i], source[i], amount); @@ -4007,7 +4007,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.DarkenXor(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.DarkenXor(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -4026,14 +4026,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.LightenXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.LightenXor(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.LightenXor(background[i], source[i], amount); @@ -4045,7 +4045,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.LightenXor(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.LightenXor(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -4064,14 +4064,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.OverlayXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.OverlayXor(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.OverlayXor(background[i], source[i], amount); @@ -4083,7 +4083,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.OverlayXor(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.OverlayXor(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } @@ -4102,14 +4102,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.HardLightXor(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.HardLightXor(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.HardLightXor(background[i], source[i], amount); @@ -4121,7 +4121,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.HardLightXor(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.HardLightXor(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt index 46990b53c..694931fe7 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt @@ -79,14 +79,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public override TPixel Blend(TPixel background, TPixel source, float amount) { TPixel dest = default; - dest.FromScaledVector4(PorterDuffFunctions.<#=blender_composer#>(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); + dest.FromScaledVector4(PorterDuffFunctions.<#=blender_composer#>(background.ToScaledVector4(), source.ToScaledVector4(), Numerics.Clamp(amount, 0, 1))); return dest; } /// protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount) { - amount = amount.Clamp(0, 1); + amount = Numerics.Clamp(amount, 0, 1); for (int i = 0; i < destination.Length; i++) { destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount); @@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { for (int i = 0; i < destination.Length; i++) { - destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount[i].Clamp(0, 1)); + destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], Numerics.Clamp(amount[i], 0, 1)); } } } diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs index 5fccb1fa6..cd67db32b 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs @@ -203,7 +203,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalSrc(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalSrc(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -222,7 +222,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalSrcAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalSrcAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -241,7 +241,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalSrcOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalSrcOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -260,7 +260,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalSrcIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalSrcIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -279,7 +279,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalSrcOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalSrcOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -298,7 +298,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalDest(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalDest(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -317,7 +317,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalDestAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalDestAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -336,7 +336,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalDestOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalDestOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -355,7 +355,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalDestIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalDestIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -374,7 +374,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalDestOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalDestOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -393,7 +393,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalClear(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalClear(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -412,7 +412,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel NormalXor(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(NormalXor(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -608,7 +608,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplySrc(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplySrc(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -627,7 +627,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplySrcAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplySrcAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -646,7 +646,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplySrcOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplySrcOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -665,7 +665,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplySrcIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplySrcIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -684,7 +684,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplySrcOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplySrcOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -703,7 +703,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplyDest(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplyDest(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -722,7 +722,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplyDestAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplyDestAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -741,7 +741,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplyDestOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplyDestOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -760,7 +760,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplyDestIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplyDestIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -779,7 +779,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplyDestOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplyDestOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -798,7 +798,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplyClear(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplyClear(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -817,7 +817,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel MultiplyXor(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(MultiplyXor(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1013,7 +1013,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddSrc(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddSrc(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1032,7 +1032,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddSrcAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddSrcAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1051,7 +1051,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddSrcOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddSrcOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1070,7 +1070,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddSrcIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddSrcIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1089,7 +1089,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddSrcOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddSrcOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1108,7 +1108,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddDest(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddDest(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1127,7 +1127,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddDestAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddDestAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1146,7 +1146,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddDestOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddDestOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1165,7 +1165,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddDestIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddDestIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1184,7 +1184,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddDestOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddDestOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1203,7 +1203,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddClear(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddClear(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1222,7 +1222,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel AddXor(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(AddXor(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1418,7 +1418,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractSrc(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractSrc(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1437,7 +1437,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractSrcAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractSrcAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1456,7 +1456,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractSrcOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractSrcOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1475,7 +1475,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractSrcIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractSrcIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1494,7 +1494,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractSrcOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractSrcOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1513,7 +1513,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractDest(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractDest(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1532,7 +1532,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractDestAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractDestAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1551,7 +1551,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractDestOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractDestOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1570,7 +1570,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractDestIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractDestIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1589,7 +1589,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractDestOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractDestOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1608,7 +1608,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractClear(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractClear(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1627,7 +1627,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel SubtractXor(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(SubtractXor(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1823,7 +1823,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenSrc(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenSrc(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1842,7 +1842,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenSrcAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenSrcAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1861,7 +1861,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenSrcOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenSrcOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1880,7 +1880,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenSrcIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenSrcIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1899,7 +1899,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenSrcOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenSrcOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1918,7 +1918,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenDest(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenDest(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1937,7 +1937,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenDestAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenDestAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1956,7 +1956,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenDestOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenDestOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1975,7 +1975,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenDestIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenDestIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -1994,7 +1994,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenDestOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenDestOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2013,7 +2013,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenClear(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenClear(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2032,7 +2032,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel ScreenXor(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(ScreenXor(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2228,7 +2228,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenSrc(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenSrc(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2247,7 +2247,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenSrcAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenSrcAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2266,7 +2266,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenSrcOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenSrcOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2285,7 +2285,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenSrcIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenSrcIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2304,7 +2304,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenSrcOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenSrcOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2323,7 +2323,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenDest(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenDest(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2342,7 +2342,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenDestAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenDestAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2361,7 +2361,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenDestOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenDestOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2380,7 +2380,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenDestIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenDestIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2399,7 +2399,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenDestOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenDestOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2418,7 +2418,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenClear(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenClear(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2437,7 +2437,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel DarkenXor(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(DarkenXor(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2633,7 +2633,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenSrc(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenSrc(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2652,7 +2652,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenSrcAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenSrcAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2671,7 +2671,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenSrcOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenSrcOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2690,7 +2690,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenSrcIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenSrcIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2709,7 +2709,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenSrcOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenSrcOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2728,7 +2728,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenDest(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenDest(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2747,7 +2747,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenDestAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenDestAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2766,7 +2766,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenDestOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenDestOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2785,7 +2785,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenDestIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenDestIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2804,7 +2804,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenDestOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenDestOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2823,7 +2823,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenClear(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenClear(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -2842,7 +2842,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel LightenXor(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(LightenXor(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3038,7 +3038,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlaySrc(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlaySrc(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3057,7 +3057,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlaySrcAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlaySrcAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3076,7 +3076,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlaySrcOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlaySrcOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3095,7 +3095,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlaySrcIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlaySrcIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3114,7 +3114,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlaySrcOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlaySrcOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3133,7 +3133,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlayDest(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlayDest(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3152,7 +3152,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlayDestAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlayDestAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3171,7 +3171,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlayDestOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlayDestOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3190,7 +3190,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlayDestIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlayDestIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3209,7 +3209,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlayDestOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlayDestOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3228,7 +3228,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlayClear(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlayClear(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3247,7 +3247,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel OverlayXor(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(OverlayXor(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3443,7 +3443,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightSrc(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightSrc(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3462,7 +3462,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightSrcAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightSrcAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3481,7 +3481,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightSrcOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightSrcOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3500,7 +3500,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightSrcIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightSrcIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3519,7 +3519,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightSrcOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightSrcOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3538,7 +3538,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightDest(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightDest(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3557,7 +3557,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightDestAtop(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightDestAtop(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3576,7 +3576,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightDestOver(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightDestOver(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3595,7 +3595,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightDestIn(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightDestIn(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3614,7 +3614,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightDestOut(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightDestOut(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3633,7 +3633,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightClear(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightClear(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; @@ -3652,7 +3652,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel HardLightXor(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(HardLightXor(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt index 31b502908..3ce185e7d 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt @@ -219,7 +219,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static TPixel <#=blender#><#=composer#>(TPixel backdrop, TPixel source, float opacity) where TPixel : unmanaged, IPixel { - opacity = opacity.Clamp(0, 1); + opacity = Numerics.Clamp(opacity, 0, 1); TPixel dest = default; dest.FromScaledVector4(<#=blender#><#=composer#>(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity)); return dest; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs index c293d181a..fa08bbe62 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs @@ -162,6 +162,6 @@ namespace SixLabors.ImageSharp.PixelFormats /// The float containing the value to pack. /// The containing the packed values. [MethodImpl(InliningOptions.ShortMethod)] - private static byte Pack(float alpha) => (byte)Math.Round(alpha.Clamp(0, 1F) * 255F); + private static byte Pack(float alpha) => (byte)Math.Round(Numerics.Clamp(alpha, 0, 1F) * 255F); } } diff --git a/src/ImageSharp/Primitives/Number.cs b/src/ImageSharp/Primitives/Number.cs index f6748d856..e33d2344a 100644 --- a/src/ImageSharp/Primitives/Number.cs +++ b/src/ImageSharp/Primitives/Number.cs @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp { return number.isSigned ? number.signedValue - : (int)number.unsignedValue.Clamp(0, int.MaxValue); + : (int)Numerics.Clamp(number.unsignedValue, 0, int.MaxValue); } /// @@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp public static explicit operator uint(Number number) { return number.isSigned - ? (uint)number.signedValue.Clamp(0, int.MaxValue) + ? (uint)Numerics.Clamp(number.signedValue, 0, int.MaxValue) : number.unsignedValue; } @@ -91,8 +91,8 @@ namespace SixLabors.ImageSharp public static explicit operator ushort(Number number) { return number.isSigned - ? (ushort)number.signedValue.Clamp(ushort.MinValue, ushort.MaxValue) - : (ushort)number.unsignedValue.Clamp(ushort.MinValue, ushort.MaxValue); + ? (ushort)Numerics.Clamp(number.signedValue, ushort.MinValue, ushort.MaxValue) + : (ushort)Numerics.Clamp(number.unsignedValue, ushort.MinValue, ushort.MaxValue); } /// diff --git a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs index 80c777cd7..0f3c20f5e 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs @@ -165,10 +165,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering int spread = 256 / bitDepth; float factor = spread * this.thresholdMatrix[y % this.modulusY, x % this.modulusX] * scale; - attempt.R = (byte)(rgba.R + factor).Clamp(byte.MinValue, byte.MaxValue); - attempt.G = (byte)(rgba.G + factor).Clamp(byte.MinValue, byte.MaxValue); - attempt.B = (byte)(rgba.B + factor).Clamp(byte.MinValue, byte.MaxValue); - attempt.A = (byte)(rgba.A + factor).Clamp(byte.MinValue, byte.MaxValue); + attempt.R = (byte)Numerics.Clamp(rgba.R + factor, byte.MinValue, byte.MaxValue); + attempt.G = (byte)Numerics.Clamp(rgba.G + factor, byte.MinValue, byte.MaxValue); + attempt.B = (byte)Numerics.Clamp(rgba.B + factor, byte.MinValue, byte.MaxValue); + attempt.A = (byte)Numerics.Clamp(rgba.A + factor, byte.MinValue, byte.MaxValue); TPixel result = default; result.FromRgba32(attempt); diff --git a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs index bb6614a7e..1b321a99f 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering Guard.MustBeGreaterThan(palette.Length, 0, nameof(palette)); Guard.NotNull(dither, nameof(dither)); this.Dither = dither; - this.DitherScale = ditherScale.Clamp(QuantizerConstants.MinDitherScale, QuantizerConstants.MaxDitherScale); + this.DitherScale = Numerics.Clamp(ditherScale, QuantizerConstants.MinDitherScale, QuantizerConstants.MaxDitherScale); this.Palette = palette; } diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs index 21ec8a9c7..42216417e 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs @@ -137,8 +137,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects { int fyr = fy - this.radius; int offsetY = y + fyr; - - offsetY = offsetY.Clamp(0, maxY); + offsetY = Numerics.Clamp(offsetY, 0, maxY); Span sourceOffsetRow = this.source.GetPixelRowSpan(offsetY); @@ -146,7 +145,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects { int fxr = fx - this.radius; int offsetX = x + fxr; - offsetX = offsetX.Clamp(0, maxX); + offsetX = Numerics.Clamp(offsetX, 0, maxX); var vector = sourceOffsetRow[offsetX].ToVector4(); diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs index c028903f4..78cf7f3c6 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays for (int i = 0; i < this.bounds.Width; i++) { float distance = Vector2.Distance(this.center, new Vector2(i + this.bounds.X, y)); - span[i] = (this.blendPercent * (1 - (.95F * (distance / this.maxDistance)))).Clamp(0, 1); + span[i] = Numerics.Clamp(this.blendPercent * (1 - (.95F * (distance / this.maxDistance))), 0, 1F); } Span destination = this.source.GetPixelRowSpan(y).Slice(this.bounds.X, this.bounds.Width); diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs index d09e3b22a..c853377ad 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs @@ -110,7 +110,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays for (int i = 0; i < this.bounds.Width; i++) { float distance = Vector2.Distance(this.center, new Vector2(i + this.bounds.X, y)); - span[i] = (this.blendPercent * (.9F * (distance / this.maxDistance))).Clamp(0, 1); + span[i] = Numerics.Clamp(this.blendPercent * (.9F * (distance / this.maxDistance)), 0, 1F); } Span destination = this.source.GetPixelRowSpan(y).Slice(this.bounds.X, this.bounds.Width); diff --git a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs index 50eeef8ca..1e1d1c953 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization this.Options = options; this.maxColors = this.Options.MaxColors; - this.octree = new Octree(ImageMath.GetBitsNeededForColorDepth(this.maxColors).Clamp(1, 8)); + this.octree = new Octree(Numerics.Clamp(ImageMath.GetBitsNeededForColorDepth(this.maxColors), 1, 8)); this.paletteOwner = configuration.MemoryAllocator.Allocate(this.maxColors, AllocationOptions.Clean); this.palette = default; this.pixelMap = default; diff --git a/src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs index d30481043..b983904d2 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization public float DitherScale { get { return this.ditherScale; } - set { this.ditherScale = value.Clamp(QuantizerConstants.MinDitherScale, QuantizerConstants.MaxDitherScale); } + set { this.ditherScale = Numerics.Clamp(value, QuantizerConstants.MinDitherScale, QuantizerConstants.MaxDitherScale); } } /// @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization public int MaxColors { get { return this.maxColors; } - set { this.maxColors = value.Clamp(QuantizerConstants.MinColors, QuantizerConstants.MaxColors); } + set { this.maxColors = Numerics.Clamp(value, QuantizerConstants.MinColors, QuantizerConstants.MaxColors); } } } } diff --git a/tests/ImageSharp.Benchmarks/Color/YcbCrToRgb.cs b/tests/ImageSharp.Benchmarks/Color/YcbCrToRgb.cs index c962886d1..07707029a 100644 --- a/tests/ImageSharp.Benchmarks/Color/YcbCrToRgb.cs +++ b/tests/ImageSharp.Benchmarks/Color/YcbCrToRgb.cs @@ -1,12 +1,11 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System.Numerics; +using BenchmarkDotNet.Attributes; + namespace SixLabors.ImageSharp.Benchmarks { - using System.Numerics; - - using BenchmarkDotNet.Attributes; - public class YcbCrToRgb { [Benchmark(Baseline = true, Description = "Floating Point Conversion")] @@ -19,9 +18,9 @@ namespace SixLabors.ImageSharp.Benchmarks int ccb = cb - 128; int ccr = cr - 128; - byte r = (byte)(y + (1.402F * ccr)).Clamp(0, 255); - byte g = (byte)(y - (0.34414F * ccb) - (0.71414F * ccr)).Clamp(0, 255); - byte b = (byte)(y + (1.772F * ccb)).Clamp(0, 255); + byte r = (byte)Numerics.Clamp(y + (1.402F * ccr), 0, 255); + byte g = (byte)Numerics.Clamp(y - (0.34414F * ccb) - (0.71414F * ccr), 0, 255); + byte b = (byte)Numerics.Clamp(y + (1.772F * ccb), 0, 255); return new Vector3(r, g, b); } @@ -42,9 +41,9 @@ namespace SixLabors.ImageSharp.Benchmarks int g1 = 731 * ccr; // (0.71414F * 1024) + .5F int b0 = 1815 * ccb; // (1.772F * 1024) + .5F - byte r = (byte)(y + (r0 >> 10)).Clamp(0, 255); - byte g = (byte)(y - (g0 >> 10) - (g1 >> 10)).Clamp(0, 255); - byte b = (byte)(y + (b0 >> 10)).Clamp(0, 255); + byte r = (byte)Numerics.Clamp(y + (r0 >> 10), 0, 255); + byte g = (byte)Numerics.Clamp(y - (g0 >> 10) - (g1 >> 10), 0, 255); + byte b = (byte)Numerics.Clamp(y + (b0 >> 10), 0, 255); return new Vector3(r, g, b); } diff --git a/tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs b/tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs index a5b49721d..f69dca26e 100644 --- a/tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs +++ b/tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General.BasicMath for (int i = 0; i < A.Length; i++) { ref int x = ref A[i]; - x = x.Clamp(64, 128); + x = Numerics.Clamp(x, 64, 128); } } From 289b5326c132169bab79ffe25f0828a3034c3ec0 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 23 Nov 2020 00:53:21 +0000 Subject: [PATCH 19/39] Move FastClamp to Numerics --- src/ImageSharp/ColorSpaces/Cmyk.cs | 2 +- src/ImageSharp/Common/Helpers/Numerics.cs | 13 ++++++++ .../SimdUtils.FallbackIntrinsics128.cs | 2 +- src/ImageSharp/Common/Helpers/SimdUtils.cs | 2 +- .../Common/Helpers/Vector4Utilities.cs | 12 ------- .../Jpeg/Components/Block8x8F.Generated.cs | 32 +++++++++---------- .../Jpeg/Components/Block8x8F.Generated.tt | 2 +- .../Formats/Jpeg/Components/Block8x8F.cs | 2 +- .../PixelImplementations/Argb32.cs | 2 +- .../PixelImplementations/Bgra32.cs | 2 +- .../PixelImplementations/Bgra4444.cs | 2 +- .../PixelImplementations/Bgra5551.cs | 2 +- .../PixelImplementations/Byte4.cs | 2 +- .../PixelFormats/PixelImplementations/L16.cs | 2 +- .../PixelFormats/PixelImplementations/L8.cs | 2 +- .../PixelFormats/PixelImplementations/La16.cs | 2 +- .../PixelFormats/PixelImplementations/La32.cs | 2 +- .../PixelImplementations/NormalizedByte4.cs | 2 +- .../PixelImplementations/NormalizedShort4.cs | 2 +- .../PixelImplementations/Rgb24.cs | 2 +- .../PixelImplementations/Rgb48.cs | 2 +- .../PixelImplementations/Rgba1010102.cs | 2 +- .../PixelImplementations/Rgba32.cs | 4 +-- .../PixelImplementations/Rgba64.cs | 4 +-- .../PixelImplementations/RgbaVector.cs | 2 +- .../PixelImplementations/Short4.cs | 2 +- .../Convolution/BokehBlurProcessor{TPixel}.cs | 2 +- .../Linear/LinearTransformUtilities.cs | 2 +- 28 files changed, 56 insertions(+), 55 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs index 0aab29554..675f1f814 100644 --- a/src/ImageSharp/ColorSpaces/Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Cmyk.cs @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.ColorSpaces [MethodImpl(InliningOptions.ShortMethod)] public Cmyk(Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, Min, Max); + vector = Numerics.Clamp(vector, Min, Max); this.C = vector.X; this.M = vector.Y; this.Y = vector.Z; diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index d4dfa1202..da226db11 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -253,6 +253,19 @@ namespace SixLabors.ImageSharp return value; } + /// + /// Returns the value clamped to the inclusive range of min and max. + /// 5x Faster than + /// on platforms < NET 5. + /// + /// The value to clamp. + /// The minimum inclusive value. + /// The maximum inclusive value. + /// The clamped . + [MethodImpl(InliningOptions.ShortMethod)] + public static Vector4 Clamp(Vector4 value, Vector4 min, Vector4 max) + => Vector4.Min(Vector4.Max(value, min), max); + /// /// Clamps the span values to the inclusive range of min and max. /// diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs index a97510113..15133770f 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs @@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp Vector4 s = Unsafe.Add(ref sBase, i); s *= maxBytes; s += half; - s = Vector4Utilities.FastClamp(s, Vector4.Zero, maxBytes); + s = Numerics.Clamp(s, Vector4.Zero, maxBytes); ref ByteVector4 d = ref Unsafe.Add(ref dBase, i); d.X = (byte)s.X; diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.cs b/src/ImageSharp/Common/Helpers/SimdUtils.cs index a0cb513ef..aaf6d405c 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.cs @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Vector4 PseudoRound(this Vector4 v) { - Vector4 sign = Vector4Utilities.FastClamp(v, new Vector4(-1), new Vector4(1)); + Vector4 sign = Numerics.Clamp(v, new Vector4(-1), new Vector4(1)); return v + (sign * 0.5f); } diff --git a/src/ImageSharp/Common/Helpers/Vector4Utilities.cs b/src/ImageSharp/Common/Helpers/Vector4Utilities.cs index 464006570..cab5d5675 100644 --- a/src/ImageSharp/Common/Helpers/Vector4Utilities.cs +++ b/src/ImageSharp/Common/Helpers/Vector4Utilities.cs @@ -20,18 +20,6 @@ namespace SixLabors.ImageSharp private const int BlendAlphaControl = 0b_10_00_10_00; private const int ShuffleAlphaControl = 0b_11_11_11_11; - /// - /// Restricts a vector between a minimum and a maximum value. - /// 5x Faster then . - /// - /// The vector to restrict. - /// The minimum value. - /// The maximum value. - /// The . - [MethodImpl(InliningOptions.ShortMethod)] - public static Vector4 FastClamp(Vector4 x, Vector4 min, Vector4 max) - => Vector4.Min(Vector4.Max(x, min), max); - /// /// Pre-multiplies the "x", "y", "z" components of a vector by its "w" component leaving the "w" component intact. /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs index 0efefc06b..dd5d3f196 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs @@ -19,22 +19,22 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components var CMax4 = new Vector4(maximum); var COff4 = new Vector4(MathF.Ceiling(maximum / 2)); - this.V0L = Vector4Utilities.FastClamp(this.V0L + COff4, CMin4, CMax4); - this.V0R = Vector4Utilities.FastClamp(this.V0R + COff4, CMin4, CMax4); - this.V1L = Vector4Utilities.FastClamp(this.V1L + COff4, CMin4, CMax4); - this.V1R = Vector4Utilities.FastClamp(this.V1R + COff4, CMin4, CMax4); - this.V2L = Vector4Utilities.FastClamp(this.V2L + COff4, CMin4, CMax4); - this.V2R = Vector4Utilities.FastClamp(this.V2R + COff4, CMin4, CMax4); - this.V3L = Vector4Utilities.FastClamp(this.V3L + COff4, CMin4, CMax4); - this.V3R = Vector4Utilities.FastClamp(this.V3R + COff4, CMin4, CMax4); - this.V4L = Vector4Utilities.FastClamp(this.V4L + COff4, CMin4, CMax4); - this.V4R = Vector4Utilities.FastClamp(this.V4R + COff4, CMin4, CMax4); - this.V5L = Vector4Utilities.FastClamp(this.V5L + COff4, CMin4, CMax4); - this.V5R = Vector4Utilities.FastClamp(this.V5R + COff4, CMin4, CMax4); - this.V6L = Vector4Utilities.FastClamp(this.V6L + COff4, CMin4, CMax4); - this.V6R = Vector4Utilities.FastClamp(this.V6R + COff4, CMin4, CMax4); - this.V7L = Vector4Utilities.FastClamp(this.V7L + COff4, CMin4, CMax4); - this.V7R = Vector4Utilities.FastClamp(this.V7R + COff4, CMin4, CMax4); + this.V0L = Numerics.Clamp(this.V0L + COff4, CMin4, CMax4); + this.V0R = Numerics.Clamp(this.V0R + COff4, CMin4, CMax4); + this.V1L = Numerics.Clamp(this.V1L + COff4, CMin4, CMax4); + this.V1R = Numerics.Clamp(this.V1R + COff4, CMin4, CMax4); + this.V2L = Numerics.Clamp(this.V2L + COff4, CMin4, CMax4); + this.V2R = Numerics.Clamp(this.V2R + COff4, CMin4, CMax4); + this.V3L = Numerics.Clamp(this.V3L + COff4, CMin4, CMax4); + this.V3R = Numerics.Clamp(this.V3R + COff4, CMin4, CMax4); + this.V4L = Numerics.Clamp(this.V4L + COff4, CMin4, CMax4); + this.V4R = Numerics.Clamp(this.V4R + COff4, CMin4, CMax4); + this.V5L = Numerics.Clamp(this.V5L + COff4, CMin4, CMax4); + this.V5R = Numerics.Clamp(this.V5R + COff4, CMin4, CMax4); + this.V6L = Numerics.Clamp(this.V6L + COff4, CMin4, CMax4); + this.V6R = Numerics.Clamp(this.V6R + COff4, CMin4, CMax4); + this.V7L = Numerics.Clamp(this.V7L + COff4, CMin4, CMax4); + this.V7R = Numerics.Clamp(this.V7R + COff4, CMin4, CMax4); } /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt index e5a62dc07..8897efbe0 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components for (int j = 0; j < 2; j++) { char side = j == 0 ? 'L' : 'R'; - Write($"this.V{i}{side} = Vector4Utilities.FastClamp(this.V{i}{side} + COff4, CMin4, CMax4);\r\n"); + Write($"this.V{i}{side} = Numerics.Clamp(this.V{i}{side} + COff4, CMin4, CMax4);\r\n"); } } PopIndent(); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs index 0dbdadbeb..fd4748fa9 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs @@ -671,7 +671,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components private static Vector4 DivideRound(Vector4 dividend, Vector4 divisor) { // sign(dividend) = max(min(dividend, 1), -1) - Vector4 sign = Vector4Utilities.FastClamp(dividend, NegativeOne, Vector4.One); + Vector4 sign = Numerics.Clamp(dividend, NegativeOne, Vector4.One); // AlmostRound(dividend/divisor) = dividend/divisor + 0.5*sign(dividend) return (dividend / divisor) + (sign * Offset); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs index a42be2482..9e6db8b70 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs @@ -373,7 +373,7 @@ namespace SixLabors.ImageSharp.PixelFormats { vector *= MaxBytes; vector += Half; - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes); + vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes); this.R = (byte)vector.X; this.G = (byte)vector.Y; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs index fea5643a8..2058c4e00 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs @@ -296,7 +296,7 @@ namespace SixLabors.ImageSharp.PixelFormats { vector *= MaxBytes; vector += Half; - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes); + vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes); this.R = (byte)vector.X; this.G = (byte)vector.Y; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs index c8d2a82a8..8fa5219d5 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs @@ -162,7 +162,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] private static ushort Pack(ref Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One); + vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One); return (ushort)((((int)Math.Round(vector.W * 15F) & 0x0F) << 12) | (((int)Math.Round(vector.X * 15F) & 0x0F) << 8) | (((int)Math.Round(vector.Y * 15F) & 0x0F) << 4) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs index 31fa0c29c..b3a0d0896 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs @@ -163,7 +163,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] private static ushort Pack(ref Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One); + vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One); return (ushort)( (((int)Math.Round(vector.X * 31F) & 0x1F) << 10) | (((int)Math.Round(vector.Y * 31F) & 0x1F) << 5) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs index ad22a5aa1..e26121291 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs @@ -171,7 +171,7 @@ namespace SixLabors.ImageSharp.PixelFormats const float Max = 255F; // Clamp the value between min and max values - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, new Vector4(Max)); + vector = Numerics.Clamp(vector, Vector4.Zero, new Vector4(Max)); uint byte4 = (uint)Math.Round(vector.X) & 0xFF; uint byte3 = ((uint)Math.Round(vector.Y) & 0xFF) << 0x8; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs index 5d91486a6..cda2f32e8 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs @@ -176,7 +176,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] internal void ConvertFromRgbaScaledVector4(Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max; + vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Max; this.PackedValue = ImageMath.Get16BitBT709Luminance( vector.X, vector.Y, diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs index f395a5dfb..938d83feb 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs @@ -156,7 +156,7 @@ namespace SixLabors.ImageSharp.PixelFormats { vector *= MaxBytes; vector += Half; - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes); + vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes); this.PackedValue = ImageMath.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs index bf9484399..21d983494 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs @@ -219,7 +219,7 @@ namespace SixLabors.ImageSharp.PixelFormats { vector *= MaxBytes; vector += Half; - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes); + vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes); this.L = ImageMath.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z); this.A = (byte)vector.W; } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs index 102d1b7cd..319775061 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs @@ -233,7 +233,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] internal void ConvertFromRgbaScaledVector4(Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max; + vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Max; this.L = ImageMath.Get16BitBT709Luminance( vector.X, vector.Y, diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs index 1b2ce0904..84f0bb022 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs @@ -174,7 +174,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] private static uint Pack(ref Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, MinusOne, Vector4.One) * Half; + vector = Numerics.Clamp(vector, MinusOne, Vector4.One) * Half; uint byte4 = ((uint)MathF.Round(vector.X) & 0xFF) << 0; uint byte3 = ((uint)MathF.Round(vector.Y) & 0xFF) << 8; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs index 1a5c89174..a3fd8989c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs @@ -177,7 +177,7 @@ namespace SixLabors.ImageSharp.PixelFormats private static ulong Pack(ref Vector4 vector) { vector *= Max; - vector = Vector4Utilities.FastClamp(vector, Min, Max); + vector = Numerics.Clamp(vector, Min, Max); // Round rather than truncate. ulong word4 = ((ulong)MathF.Round(vector.X) & 0xFFFF) << 0x00; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs index fd9ed12d7..b7e831cfa 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs @@ -264,7 +264,7 @@ namespace SixLabors.ImageSharp.PixelFormats { vector *= MaxBytes; vector += Half; - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes); + vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes); this.R = (byte)vector.X; this.G = (byte)vector.Y; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs index 280044ceb..23297806d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs @@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromVector4(Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max; + vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Max; this.R = (ushort)MathF.Round(vector.X); this.G = (ushort)MathF.Round(vector.Y); this.B = (ushort)MathF.Round(vector.Z); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs index 60f56fb06..dee2f9fcb 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs @@ -163,7 +163,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] private static uint Pack(ref Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Multiplier; + vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Multiplier; return (uint)( (((int)Math.Round(vector.X) & 0x03FF) << 0) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs index 2c74dc878..19c1bd083 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs @@ -452,7 +452,7 @@ namespace SixLabors.ImageSharp.PixelFormats { vector *= MaxBytes; vector += Half; - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes); + vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes); return new Rgba32((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W); } @@ -491,7 +491,7 @@ namespace SixLabors.ImageSharp.PixelFormats { vector *= MaxBytes; vector += Half; - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes); + vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes); this.R = (byte)vector.X; this.G = (byte)vector.Y; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs index 7e84c6e5b..f8b40d7e0 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs @@ -127,7 +127,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public Rgba64(Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max; + vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Max; this.R = (ushort)MathF.Round(vector.X); this.G = (ushort)MathF.Round(vector.Y); this.B = (ushort)MathF.Round(vector.Z); @@ -209,7 +209,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromVector4(Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max; + vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Max; this.R = (ushort)MathF.Round(vector.X); this.G = (ushort)MathF.Round(vector.Y); this.B = (ushort)MathF.Round(vector.Z); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs index 6ea80ca3b..97e103d0f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs @@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromVector4(Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One); + vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One); this.R = vector.X; this.G = vector.Y; this.B = vector.Z; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs index 2e9db245f..409f46c72 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs @@ -183,7 +183,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] private static ulong Pack(ref Vector4 vector) { - vector = Vector4Utilities.FastClamp(vector, Min, Max); + vector = Numerics.Clamp(vector, Min, Max); // Clamp the value between min and max values ulong word4 = ((ulong)Math.Round(vector.X) & 0xFFFF) << 0x00; diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs index a3b366590..cf5367343 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs @@ -304,7 +304,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution for (int x = 0; x < this.bounds.Width; x++) { ref Vector4 v = ref Unsafe.Add(ref sourceRef, x); - var clamp = Vector4Utilities.FastClamp(v, low, high); + var clamp = Numerics.Clamp(v, low, high); v.X = MathF.Pow(clamp.X, this.inverseGamma); v.Y = MathF.Pow(clamp.Y, this.inverseGamma); v.Z = MathF.Pow(clamp.Z, this.inverseGamma); diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtilities.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtilities.cs index e19854147..5c2f66a94 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtilities.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtilities.cs @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms MathF.Floor(maxXY.X), MathF.Floor(maxXY.Y)); - sourceExtents = Vector4Utilities.FastClamp(sourceExtents, Vector4.Zero, maxSourceExtents); + sourceExtents = Numerics.Clamp(sourceExtents, Vector4.Zero, maxSourceExtents); int left = (int)sourceExtents.X; int top = (int)sourceExtents.Y; From f66fe45ac1d21eefd4e77282d8ac927e807c9398 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 23 Nov 2020 00:59:46 +0000 Subject: [PATCH 20/39] Utils FTW --- .../Common/Helpers/DenseMatrixUtils.cs | 12 +++++----- .../{Vector4Utilities.cs => Vector4Utils.cs} | 2 +- .../PixelFormats/Utils/Vector4Converters.cs | 4 ++-- .../Filters/FilterProcessor{TPixel}.cs | 2 +- .../AffineTransformProcessor{TPixel}.cs | 6 ++--- ...rmUtilities.cs => LinearTransformUtils.cs} | 6 ++--- .../ProjectiveTransformProcessor{TPixel}.cs | 6 ++--- .../Color/Bulk/PremultiplyVector4.cs | 2 +- .../Color/Bulk/UnPremultiplyVector4.cs | 2 +- .../Helpers/Vector4UtilsTests.cs | 8 +++---- .../PixelOperations/PixelOperationsTests.cs | 24 +++++++++---------- 11 files changed, 37 insertions(+), 37 deletions(-) rename src/ImageSharp/Common/Helpers/{Vector4Utilities.cs => Vector4Utils.cs} (99%) rename src/ImageSharp/Processing/Processors/Transforms/Linear/{LinearTransformUtilities.cs => LinearTransformUtils.cs} (95%) diff --git a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs index 69c50573f..7da2528fa 100644 --- a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs +++ b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column); vector.W = target.W; - Vector4Utilities.UnPremultiply(ref vector); + Vector4Utils.UnPremultiply(ref vector); target = vector; } @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp out Vector4 vector); ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column); - Vector4Utilities.UnPremultiply(ref vector); + Vector4Utils.UnPremultiply(ref vector); target = vector; } @@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp { int offsetX = Numerics.Clamp(sourceOffsetColumnBase + x - radiusX, minColumn, maxColumn); var currentColor = sourceRowSpan[offsetX].ToVector4(); - Vector4Utilities.Premultiply(ref currentColor); + Vector4Utils.Premultiply(ref currentColor); vectorX += matrixX[y, x] * currentColor; vectorY += matrixY[y, x] * currentColor; @@ -193,7 +193,7 @@ namespace SixLabors.ImageSharp ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column); vector.W = target.W; - Vector4Utilities.UnPremultiply(ref vector); + Vector4Utils.UnPremultiply(ref vector); target = vector; } @@ -238,7 +238,7 @@ namespace SixLabors.ImageSharp ref vector); ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column); - Vector4Utilities.UnPremultiply(ref vector); + Vector4Utils.UnPremultiply(ref vector); target = vector; } @@ -270,7 +270,7 @@ namespace SixLabors.ImageSharp { int offsetX = Numerics.Clamp(sourceOffsetColumnBase + x - radiusX, minColumn, maxColumn); var currentColor = sourceRowSpan[offsetX].ToVector4(); - Vector4Utilities.Premultiply(ref currentColor); + Vector4Utils.Premultiply(ref currentColor); vector += matrix[y, x] * currentColor; } } diff --git a/src/ImageSharp/Common/Helpers/Vector4Utilities.cs b/src/ImageSharp/Common/Helpers/Vector4Utils.cs similarity index 99% rename from src/ImageSharp/Common/Helpers/Vector4Utilities.cs rename to src/ImageSharp/Common/Helpers/Vector4Utils.cs index cab5d5675..05661991a 100644 --- a/src/ImageSharp/Common/Helpers/Vector4Utilities.cs +++ b/src/ImageSharp/Common/Helpers/Vector4Utils.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp /// /// Utility methods for the struct. /// - internal static class Vector4Utilities + internal static class Vector4Utils { private const int BlendAlphaControl = 0b_10_00_10_00; private const int ShuffleAlphaControl = 0b_11_11_11_11; diff --git a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs index 2dca8f2c1..977722b81 100644 --- a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs +++ b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils if (modifiers.IsDefined(PixelConversionModifiers.Premultiply)) { - Vector4Utilities.Premultiply(vectors); + Vector4Utils.Premultiply(vectors); } } @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils { if (modifiers.IsDefined(PixelConversionModifiers.Premultiply)) { - Vector4Utilities.UnPremultiply(vectors); + Vector4Utils.UnPremultiply(vectors); } if (modifiers.IsDefined(PixelConversionModifiers.SRgbCompand)) diff --git a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs index 584ba072c..e28d4add7 100644 --- a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs @@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters Span rowSpan = this.source.GetPixelRowSpan(y).Slice(this.startX, span.Length); PixelOperations.Instance.ToVector4(this.configuration, rowSpan, span); - Vector4Utilities.Transform(span, ref Unsafe.AsRef(this.matrix)); + Vector4Utils.Transform(span, ref Unsafe.AsRef(this.matrix)); PixelOperations.Instance.FromVector4Destructive(this.configuration, span, rowSpan); } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs index cd7f46d92..c08f5d3d3 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs @@ -80,8 +80,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms return; } - int yRadius = LinearTransformUtilities.GetSamplingRadius(in sampler, source.Height, destination.Height); - int xRadius = LinearTransformUtilities.GetSamplingRadius(in sampler, source.Width, destination.Width); + int yRadius = LinearTransformUtils.GetSamplingRadius(in sampler, source.Height, destination.Height); + int xRadius = LinearTransformUtils.GetSamplingRadius(in sampler, source.Width, destination.Width); var radialExtents = new Vector2(xRadius, yRadius); int yLength = (yRadius * 2) + 1; int xLength = (xRadius * 2) + 1; @@ -207,7 +207,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms // Use the single precision position to calculate correct bounding pixels // otherwise we get rogue pixels outside of the bounds. var point = Vector2.Transform(new Vector2(x, y), this.matrix); - LinearTransformUtilities.Convolve( + LinearTransformUtils.Convolve( in this.sampler, point, sourceBuffer, diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtilities.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtils.cs similarity index 95% rename from src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtilities.cs rename to src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtils.cs index 5c2f66a94..07e784ec5 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtilities.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtils.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// /// Utility methods for affine and projective transforms. /// - internal static class LinearTransformUtilities + internal static class LinearTransformUtils { [MethodImpl(InliningOptions.ShortMethod)] internal static int GetSamplingRadius(in TResampler sampler, int sourceSize, int destinationSize) @@ -78,13 +78,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms // Values are first premultiplied to prevent darkening of edge pixels. var current = sourcePixels[x, y].ToVector4(); - Vector4Utilities.Premultiply(ref current); + Vector4Utils.Premultiply(ref current); sum += current * xWeight * yWeight; } } // Reverse the premultiplication - Vector4Utilities.UnPremultiply(ref sum); + Vector4Utils.UnPremultiply(ref sum); targetRow[column] = sum; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs index 4f7537796..811bb1a88 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs @@ -80,8 +80,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms return; } - int yRadius = LinearTransformUtilities.GetSamplingRadius(in sampler, source.Height, destination.Height); - int xRadius = LinearTransformUtilities.GetSamplingRadius(in sampler, source.Width, destination.Width); + int yRadius = LinearTransformUtils.GetSamplingRadius(in sampler, source.Height, destination.Height); + int xRadius = LinearTransformUtils.GetSamplingRadius(in sampler, source.Width, destination.Width); var radialExtents = new Vector2(xRadius, yRadius); int yLength = (yRadius * 2) + 1; int xLength = (xRadius * 2) + 1; @@ -207,7 +207,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms // Use the single precision position to calculate correct bounding pixels // otherwise we get rogue pixels outside of the bounds. Vector2 point = TransformUtilities.ProjectiveTransform2D(x, y, this.matrix); - LinearTransformUtilities.Convolve( + LinearTransformUtils.Convolve( in this.sampler, point, sourceBuffer, diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs index 2a886c687..d441b5e0b 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark] public void Premultiply() { - Vector4Utilities.Premultiply(Vectors); + Vector4Utils.Premultiply(Vectors); } [MethodImpl(InliningOptions.ShortMethod)] diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs index 1312c767b..819f34b92 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark] public void UnPremultiply() { - Vector4Utilities.UnPremultiply(Vectors); + Vector4Utils.UnPremultiply(Vectors); } [MethodImpl(InliningOptions.ShortMethod)] diff --git a/tests/ImageSharp.Tests/Helpers/Vector4UtilsTests.cs b/tests/ImageSharp.Tests/Helpers/Vector4UtilsTests.cs index 2bb43c440..605aa7d5a 100644 --- a/tests/ImageSharp.Tests/Helpers/Vector4UtilsTests.cs +++ b/tests/ImageSharp.Tests/Helpers/Vector4UtilsTests.cs @@ -24,11 +24,11 @@ namespace SixLabors.ImageSharp.Tests.Helpers Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1); Vector4[] expected = source.Select(v => { - Vector4Utilities.Premultiply(ref v); + Vector4Utils.Premultiply(ref v); return v; }).ToArray(); - Vector4Utilities.Premultiply(source); + Vector4Utils.Premultiply(source); Assert.Equal(expected, source, this.approximateFloatComparer); } @@ -44,11 +44,11 @@ namespace SixLabors.ImageSharp.Tests.Helpers Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1); Vector4[] expected = source.Select(v => { - Vector4Utilities.UnPremultiply(ref v); + Vector4Utils.UnPremultiply(ref v); return v; }).ToArray(); - Vector4Utilities.UnPremultiply(source); + Vector4Utils.UnPremultiply(source); Assert.Equal(expected, source, this.approximateFloatComparer); } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index 059a21803..e56cfe226 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -197,7 +197,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { if (this.HasUnassociatedAlpha) { - Vector4Utilities.Premultiply(ref v); + Vector4Utils.Premultiply(ref v); } } @@ -205,7 +205,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { if (this.HasUnassociatedAlpha) { - Vector4Utilities.UnPremultiply(ref v); + Vector4Utils.UnPremultiply(ref v); } } @@ -232,7 +232,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { if (this.HasUnassociatedAlpha) { - Vector4Utilities.Premultiply(ref v); + Vector4Utils.Premultiply(ref v); } } @@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { if (this.HasUnassociatedAlpha) { - Vector4Utilities.UnPremultiply(ref v); + Vector4Utils.UnPremultiply(ref v); } } @@ -273,7 +273,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations if (this.HasUnassociatedAlpha) { - Vector4Utilities.Premultiply(ref v); + Vector4Utils.Premultiply(ref v); } } @@ -281,7 +281,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { if (this.HasUnassociatedAlpha) { - Vector4Utilities.UnPremultiply(ref v); + Vector4Utils.UnPremultiply(ref v); } SRgbCompanding.Compress(ref v); @@ -394,12 +394,12 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { void SourceAction(ref Vector4 v) { - Vector4Utilities.UnPremultiply(ref v); + Vector4Utils.UnPremultiply(ref v); } void ExpectedAction(ref Vector4 v) { - Vector4Utilities.Premultiply(ref v); + Vector4Utils.Premultiply(ref v); } TPixel[] source = CreatePixelTestData(count, (ref Vector4 v) => SourceAction(ref v)); @@ -417,12 +417,12 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { void SourceAction(ref Vector4 v) { - Vector4Utilities.UnPremultiply(ref v); + Vector4Utils.UnPremultiply(ref v); } void ExpectedAction(ref Vector4 v) { - Vector4Utilities.Premultiply(ref v); + Vector4Utils.Premultiply(ref v); } TPixel[] source = CreateScaledPixelTestData(count, (ref Vector4 v) => SourceAction(ref v)); @@ -444,14 +444,14 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { void SourceAction(ref Vector4 v) { - Vector4Utilities.UnPremultiply(ref v); + Vector4Utils.UnPremultiply(ref v); SRgbCompanding.Compress(ref v); } void ExpectedAction(ref Vector4 v) { SRgbCompanding.Expand(ref v); - Vector4Utilities.Premultiply(ref v); + Vector4Utils.Premultiply(ref v); } TPixel[] source = CreateScaledPixelTestData(count, (ref Vector4 v) => SourceAction(ref v)); From ddacec2b419a1ca44d376fd0d3ea5d70a799d2b0 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 23 Nov 2020 01:04:38 +0000 Subject: [PATCH 21/39] Moar Utils --- .../Processing/AffineTransformBuilder.cs | 14 +++++++------- .../Extensions/Transforms/TransformExtensions.cs | 4 ++-- .../Linear/ProjectiveTransformProcessor{TPixel}.cs | 4 ++-- .../Transforms/Linear/RotateProcessor.cs | 4 ++-- .../Processors/Transforms/Linear/SkewProcessor.cs | 4 ++-- .../{TransformUtilities.cs => TransformUtils.cs} | 2 +- .../Processing/ProjectiveTransformBuilder.cs | 14 +++++++------- .../Transforms/TransformBuilderTestBase.cs | 4 ++-- 8 files changed, 25 insertions(+), 25 deletions(-) rename src/ImageSharp/Processing/Processors/Transforms/{TransformUtilities.cs => TransformUtils.cs} (99%) diff --git a/src/ImageSharp/Processing/AffineTransformBuilder.cs b/src/ImageSharp/Processing/AffineTransformBuilder.cs index 75f23c6b4..ed3483dc4 100644 --- a/src/ImageSharp/Processing/AffineTransformBuilder.cs +++ b/src/ImageSharp/Processing/AffineTransformBuilder.cs @@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Processing /// The amount of rotation, in radians. /// The . public AffineTransformBuilder PrependRotationRadians(float radians) - => this.Prepend(size => TransformUtilities.CreateRotationMatrixRadians(radians, size)); + => this.Prepend(size => TransformUtils.CreateRotationMatrixRadians(radians, size)); /// /// Prepends a rotation matrix using the given rotation in degrees at the given origin. @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Processing /// The amount of rotation, in radians. /// The . public AffineTransformBuilder AppendRotationRadians(float radians) - => this.Append(size => TransformUtilities.CreateRotationMatrixRadians(radians, size)); + => this.Append(size => TransformUtils.CreateRotationMatrixRadians(radians, size)); /// /// Appends a rotation matrix using the given rotation in degrees at the given origin. @@ -142,7 +142,7 @@ namespace SixLabors.ImageSharp.Processing /// The Y angle, in degrees. /// The . public AffineTransformBuilder PrependSkewDegrees(float degreesX, float degreesY) - => this.Prepend(size => TransformUtilities.CreateSkewMatrixDegrees(degreesX, degreesY, size)); + => this.Prepend(size => TransformUtils.CreateSkewMatrixDegrees(degreesX, degreesY, size)); /// /// Prepends a centered skew matrix from the give angles in radians. @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.Processing /// The Y angle, in radians. /// The . public AffineTransformBuilder PrependSkewRadians(float radiansX, float radiansY) - => this.Prepend(size => TransformUtilities.CreateSkewMatrixRadians(radiansX, radiansY, size)); + => this.Prepend(size => TransformUtils.CreateSkewMatrixRadians(radiansX, radiansY, size)); /// /// Prepends a skew matrix using the given angles in degrees at the given origin. @@ -180,7 +180,7 @@ namespace SixLabors.ImageSharp.Processing /// The Y angle, in degrees. /// The . public AffineTransformBuilder AppendSkewDegrees(float degreesX, float degreesY) - => this.Append(size => TransformUtilities.CreateSkewMatrixDegrees(degreesX, degreesY, size)); + => this.Append(size => TransformUtils.CreateSkewMatrixDegrees(degreesX, degreesY, size)); /// /// Appends a centered skew matrix from the give angles in radians. @@ -189,7 +189,7 @@ namespace SixLabors.ImageSharp.Processing /// The Y angle, in radians. /// The . public AffineTransformBuilder AppendSkewRadians(float radiansX, float radiansY) - => this.Append(size => TransformUtilities.CreateSkewMatrixRadians(radiansX, radiansY, size)); + => this.Append(size => TransformUtils.CreateSkewMatrixRadians(radiansX, radiansY, size)); /// /// Appends a skew matrix using the given angles in degrees at the given origin. @@ -314,7 +314,7 @@ namespace SixLabors.ImageSharp.Processing private static void CheckDegenerate(Matrix3x2 matrix) { - if (TransformUtilities.IsDegenerate(matrix)) + if (TransformUtils.IsDegenerate(matrix)) { throw new DegenerateTransformException("Matrix is degenerate. Check input values."); } diff --git a/src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs b/src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs index 15430b28f..57acf78ee 100644 --- a/src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing IResampler sampler) { Matrix3x2 transform = builder.BuildMatrix(sourceRectangle); - Size targetDimensions = TransformUtilities.GetTransformedSize(sourceRectangle.Size, transform); + Size targetDimensions = TransformUtils.GetTransformedSize(sourceRectangle.Size, transform); return ctx.Transform(sourceRectangle, transform, targetDimensions, sampler); } @@ -116,7 +116,7 @@ namespace SixLabors.ImageSharp.Processing IResampler sampler) { Matrix4x4 transform = builder.BuildMatrix(sourceRectangle); - Size targetDimensions = TransformUtilities.GetTransformedSize(sourceRectangle.Size, transform); + Size targetDimensions = TransformUtils.GetTransformedSize(sourceRectangle.Size, transform); return ctx.Transform(sourceRectangle, transform, targetDimensions, sampler); } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs index 811bb1a88..f16a495b1 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs @@ -139,7 +139,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms for (int x = 0; x < this.maxX; x++) { - Vector2 point = TransformUtilities.ProjectiveTransform2D(x, y, this.matrix); + Vector2 point = TransformUtils.ProjectiveTransform2D(x, y, this.matrix); int px = (int)MathF.Round(point.X); int py = (int)MathF.Round(point.Y); @@ -206,7 +206,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms { // Use the single precision position to calculate correct bounding pixels // otherwise we get rogue pixels outside of the bounds. - Vector2 point = TransformUtilities.ProjectiveTransform2D(x, y, this.matrix); + Vector2 point = TransformUtils.ProjectiveTransform2D(x, y, this.matrix); LinearTransformUtils.Convolve( in this.sampler, point, diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor.cs index 3b4604075..641466847 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor.cs @@ -28,14 +28,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The source image size public RotateProcessor(float degrees, IResampler sampler, Size sourceSize) : this( - TransformUtilities.CreateRotationMatrixDegrees(degrees, sourceSize), + TransformUtils.CreateRotationMatrixDegrees(degrees, sourceSize), sampler, sourceSize) => this.Degrees = degrees; // Helper constructor private RotateProcessor(Matrix3x2 rotationMatrix, IResampler sampler, Size sourceSize) - : base(rotationMatrix, sampler, TransformUtilities.GetTransformedSize(sourceSize, rotationMatrix)) + : base(rotationMatrix, sampler, TransformUtils.GetTransformedSize(sourceSize, rotationMatrix)) { } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/SkewProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/SkewProcessor.cs index e5791b82f..0d82d145e 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/SkewProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/SkewProcessor.cs @@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The source image size public SkewProcessor(float degreesX, float degreesY, IResampler sampler, Size sourceSize) : this( - TransformUtilities.CreateSkewMatrixDegrees(degreesX, degreesY, sourceSize), + TransformUtils.CreateSkewMatrixDegrees(degreesX, degreesY, sourceSize), sampler, sourceSize) { @@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms // Helper constructor: private SkewProcessor(Matrix3x2 skewMatrix, IResampler sampler, Size sourceSize) - : base(skewMatrix, sampler, TransformUtilities.GetTransformedSize(sourceSize, skewMatrix)) + : base(skewMatrix, sampler, TransformUtils.GetTransformedSize(sourceSize, skewMatrix)) { } diff --git a/src/ImageSharp/Processing/Processors/Transforms/TransformUtilities.cs b/src/ImageSharp/Processing/Processors/Transforms/TransformUtils.cs similarity index 99% rename from src/ImageSharp/Processing/Processors/Transforms/TransformUtilities.cs rename to src/ImageSharp/Processing/Processors/Transforms/TransformUtils.cs index 2b4c2ff14..a92aa54a5 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/TransformUtilities.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/TransformUtils.cs @@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// /// Contains utility methods for working with transforms. /// - internal static class TransformUtilities + internal static class TransformUtils { /// /// Returns a value that indicates whether the specified matrix is degenerate diff --git a/src/ImageSharp/Processing/ProjectiveTransformBuilder.cs b/src/ImageSharp/Processing/ProjectiveTransformBuilder.cs index d81ce2890..d1469d43e 100644 --- a/src/ImageSharp/Processing/ProjectiveTransformBuilder.cs +++ b/src/ImageSharp/Processing/ProjectiveTransformBuilder.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing /// The amount to taper. /// The . public ProjectiveTransformBuilder PrependTaper(TaperSide side, TaperCorner corner, float fraction) - => this.Prepend(size => TransformUtilities.CreateTaperMatrix(size, side, corner, fraction)); + => this.Prepend(size => TransformUtils.CreateTaperMatrix(size, side, corner, fraction)); /// /// Appends a matrix that performs a tapering projective transform. @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing /// The amount to taper. /// The . public ProjectiveTransformBuilder AppendTaper(TaperSide side, TaperCorner corner, float fraction) - => this.Append(size => TransformUtilities.CreateTaperMatrix(size, side, corner, fraction)); + => this.Append(size => TransformUtils.CreateTaperMatrix(size, side, corner, fraction)); /// /// Prepends a centered rotation matrix using the given rotation in degrees. @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing /// The amount of rotation, in radians. /// The . public ProjectiveTransformBuilder PrependRotationRadians(float radians) - => this.Prepend(size => new Matrix4x4(TransformUtilities.CreateRotationMatrixRadians(radians, size))); + => this.Prepend(size => new Matrix4x4(TransformUtils.CreateRotationMatrixRadians(radians, size))); /// /// Prepends a centered rotation matrix using the given rotation in degrees at the given origin. @@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp.Processing /// The amount of rotation, in radians. /// The . public ProjectiveTransformBuilder AppendRotationRadians(float radians) - => this.Append(size => new Matrix4x4(TransformUtilities.CreateRotationMatrixRadians(radians, size))); + => this.Append(size => new Matrix4x4(TransformUtils.CreateRotationMatrixRadians(radians, size))); /// /// Appends a centered rotation matrix using the given rotation in degrees at the given origin. @@ -168,7 +168,7 @@ namespace SixLabors.ImageSharp.Processing /// The Y angle, in radians. /// The . public ProjectiveTransformBuilder PrependSkewRadians(float radiansX, float radiansY) - => this.Prepend(size => new Matrix4x4(TransformUtilities.CreateSkewMatrixRadians(radiansX, radiansY, size))); + => this.Prepend(size => new Matrix4x4(TransformUtils.CreateSkewMatrixRadians(radiansX, radiansY, size))); /// /// Prepends a skew matrix using the given angles in degrees at the given origin. @@ -206,7 +206,7 @@ namespace SixLabors.ImageSharp.Processing /// The Y angle, in radians. /// The . public ProjectiveTransformBuilder AppendSkewRadians(float radiansX, float radiansY) - => this.Append(size => new Matrix4x4(TransformUtilities.CreateSkewMatrixRadians(radiansX, radiansY, size))); + => this.Append(size => new Matrix4x4(TransformUtils.CreateSkewMatrixRadians(radiansX, radiansY, size))); /// /// Appends a skew matrix using the given angles in degrees at the given origin. @@ -332,7 +332,7 @@ namespace SixLabors.ImageSharp.Processing private static void CheckDegenerate(Matrix4x4 matrix) { - if (TransformUtilities.IsDegenerate(matrix)) + if (TransformUtils.IsDegenerate(matrix)) { throw new DegenerateTransformException("Matrix is degenerate. Check input values."); } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/TransformBuilderTestBase.cs b/tests/ImageSharp.Tests/Processing/Transforms/TransformBuilderTestBase.cs index 4306732e8..2e0dfd59e 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/TransformBuilderTestBase.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/TransformBuilderTestBase.cs @@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms this.AppendRotationDegrees(builder, degrees); // TODO: We should also test CreateRotationMatrixDegrees() (and all TransformUtils stuff!) for correctness - Matrix3x2 matrix = TransformUtilities.CreateRotationMatrixDegrees(degrees, size); + Matrix3x2 matrix = TransformUtils.CreateRotationMatrixDegrees(degrees, size); var position = new Vector2(x, y); var expected = Vector2.Transform(position, matrix); @@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms this.AppendSkewDegrees(builder, degreesX, degreesY); - Matrix3x2 matrix = TransformUtilities.CreateSkewMatrixDegrees(degreesX, degreesY, size); + Matrix3x2 matrix = TransformUtils.CreateSkewMatrixDegrees(degreesX, degreesY, size); var position = new Vector2(x, y); var expected = Vector2.Transform(position, matrix); From 8799ca53d67d17c464e6b3456282433ac58673e9 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 23 Nov 2020 01:19:26 +0000 Subject: [PATCH 22/39] Add benchmark results. --- .../General/BasicMath/ClampSpan.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs b/tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs index f69dca26e..59e2d68c9 100644 --- a/tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs +++ b/tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs @@ -40,3 +40,18 @@ namespace SixLabors.ImageSharp.Benchmarks.General.BasicMath } } } + +// 23-11-2020 +// ########## +// +// BenchmarkDotNet = v0.12.1, OS = Windows 10.0.19041.630(2004 /?/ 20H1) +// Intel Core i7-8650U CPU 1.90GHz (Kaby Lake R), 1 CPU, 8 logical and 4 physical cores +// .NET Core SDK=5.0.100 +// [Host] : .NET Core 3.1.10 (CoreCLR 4.700.20.51601, CoreFX 4.700.20.51901), X64 RyuJIT +// DefaultJob : .NET Core 3.1.10 (CoreCLR 4.700.20.51601, CoreFX 4.700.20.51901), X64 RyuJIT +// +// +// | Method | Mean | Error | StdDev | Ratio | +// |---------------------- |-----------:| ---------:| ----------:| ------:| +// | ClampNoIntrinsics | 3,629.9 ns | 70.80 ns | 129.47 ns | 1.00 | +// | ClampVectorIntrinsics | 131.9 ns | 2.68 ns | 6.66 ns | 0.04 | From 5e0ceaa593c4a8b9c3f400a7b6c4d691c2796000 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 23 Nov 2020 01:48:39 +0000 Subject: [PATCH 23/39] Fix Numerics fallback logic for 32 bit --- src/ImageSharp/Common/Helpers/Numerics.cs | 40 +++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index da226db11..2a9b5ca08 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -275,13 +275,13 @@ namespace SixLabors.ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span span, byte min, byte max) { - int reduced = ClampReduce(span, min, max); + Span remainder = span.Slice(ClampReduce(span, min, max)); - if (reduced > 0) + if (remainder.Length > 0) { - for (int i = reduced; i < span.Length; i++) + for (int i = 0; i < remainder.Length; i++) { - ref byte v = ref span[i]; + ref byte v = ref remainder[i]; v = Clamp(v, min, max); } } @@ -296,13 +296,13 @@ namespace SixLabors.ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span span, uint min, uint max) { - int reduced = ClampReduce(span, min, max); + Span remainder = span.Slice(ClampReduce(span, min, max)); - if (reduced > 0) + if (remainder.Length > 0) { - for (int i = reduced; i < span.Length; i++) + for (int i = 0; i < remainder.Length; i++) { - ref uint v = ref span[i]; + ref uint v = ref remainder[i]; v = Clamp(v, min, max); } } @@ -317,13 +317,13 @@ namespace SixLabors.ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span span, int min, int max) { - int reduced = ClampReduce(span, min, max); + Span remainder = span.Slice(ClampReduce(span, min, max)); - if (reduced > 0) + if (remainder.Length > 0) { - for (int i = reduced; i < span.Length; i++) + for (int i = 0; i < remainder.Length; i++) { - ref int v = ref span[i]; + ref int v = ref remainder[i]; v = Clamp(v, min, max); } } @@ -338,13 +338,13 @@ namespace SixLabors.ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span span, float min, float max) { - int reduced = ClampReduce(span, min, max); + Span remainder = span.Slice(ClampReduce(span, min, max)); - if (reduced > 0) + if (remainder.Length > 0) { - for (int i = reduced; i < span.Length; i++) + for (int i = 0; i < remainder.Length; i++) { - ref float v = ref span[i]; + ref float v = ref remainder[i]; v = Clamp(v, min, max); } } @@ -359,13 +359,13 @@ namespace SixLabors.ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span span, double min, double max) { - int reduced = ClampReduce(span, min, max); + Span remainder = span.Slice(ClampReduce(span, min, max)); - if (reduced > 0) + if (remainder.Length > 0) { - for (int i = reduced; i < span.Length; i++) + for (int i = 0; i < remainder.Length; i++) { - ref double v = ref span[i]; + ref double v = ref remainder[i]; v = Clamp(v, min, max); } } From e342e2c0d27fa2e949705c131f750db4101a5c74 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 23 Nov 2020 12:54:13 +0000 Subject: [PATCH 24/39] Update src/ImageSharp/Common/Helpers/Numerics.cs Co-authored-by: Anton Firszov --- src/ImageSharp/Common/Helpers/Numerics.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index 2a9b5ca08..c1e564781 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -393,7 +393,7 @@ namespace SixLabors.ImageSharp [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ClampImpl(Span span, T min, T max) - where T : unmanaged + where T : unmanaged { ref T sRef = ref MemoryMarshal.GetReference(span); ref Vector vsBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(span)); From 8d3cddab3069568e0a9e3cb79f5dcfdc94df2a9e Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 23 Nov 2020 13:36:23 +0000 Subject: [PATCH 25/39] No more Vector4Utils & ImageMath --- src/ImageSharp/Color/Color.cs | 14 +- .../Common/Helpers/ColorNumerics.cs | 177 ++++++++++++ .../Common/Helpers/DenseMatrixUtils.cs | 12 +- src/ImageSharp/Common/Helpers/ImageMath.cs | 257 ------------------ src/ImageSharp/Common/Helpers/Numerics.cs | 123 ++++++++- src/ImageSharp/Common/Helpers/Vector4Utils.cs | 169 ------------ src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 4 +- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 6 +- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 6 +- .../Formats/Png/PngEncoderOptionsHelpers.cs | 4 +- .../Formats/Png/PngScanlineProcessor.cs | 4 +- src/ImageSharp/Formats/Tga/TgaEncoderCore.cs | 2 +- .../PixelFormats/PixelImplementations/A8.cs | 2 +- .../PixelImplementations/Argb32.cs | 20 +- .../PixelImplementations/Bgr24.cs | 16 +- .../PixelImplementations/Bgra32.cs | 20 +- .../PixelFormats/PixelImplementations/L16.cs | 52 ++-- .../PixelFormats/PixelImplementations/L8.cs | 32 +-- .../PixelFormats/PixelImplementations/La16.cs | 36 +-- .../PixelFormats/PixelImplementations/La32.cs | 62 ++--- .../PixelImplementations/Rgb24.cs | 16 +- .../PixelImplementations/Rgb48.cs | 40 +-- .../PixelImplementations/Rgba32.cs | 20 +- .../PixelImplementations/Rgba64.cs | 122 ++++----- .../PixelFormats/Utils/Vector4Converters.cs | 4 +- .../BinaryThresholdProcessor{TPixel}.cs | 2 +- .../Processors/Dithering/OrderedDither.cs | 4 +- .../Filters/FilterProcessor{TPixel}.cs | 2 +- ...alizationSlidingWindowProcessor{TPixel}.cs | 4 +- ...lHistogramEqualizationProcessor{TPixel}.cs | 4 +- .../HistogramEqualizationProcessor{TPixel}.cs | 2 +- .../Quantization/OctreeQuantizer{TPixel}.cs | 2 +- .../EntropyCropProcessor{TPixel}.cs | 135 ++++++++- .../Transforms/Linear/LinearTransformUtils.cs | 4 +- .../Color/Bulk/PremultiplyVector4.cs | 2 +- .../Color/Bulk/UnPremultiplyVector4.cs | 2 +- .../Formats/Png/PngEncoderTests.cs | 2 +- ...mageMathTests.cs => ColorNumericsTests.cs} | 6 +- .../ImageSharp.Tests/Helpers/NumericsTests.cs | 46 +++- .../Helpers/Vector4UtilsTests.cs | 56 ---- .../ImageSharp.Tests/PixelFormats/L16Tests.cs | 6 +- .../ImageSharp.Tests/PixelFormats/L8Tests.cs | 2 +- .../PixelFormats/La16Tests.cs | 2 +- .../PixelFormats/La32Tests.cs | 6 +- .../PixelOperations/PixelOperationsTests.cs | 24 +- 45 files changed, 763 insertions(+), 770 deletions(-) create mode 100644 src/ImageSharp/Common/Helpers/ColorNumerics.cs delete mode 100644 src/ImageSharp/Common/Helpers/ImageMath.cs delete mode 100644 src/ImageSharp/Common/Helpers/Vector4Utils.cs rename tests/ImageSharp.Tests/Helpers/{ImageMathTests.cs => ColorNumericsTests.cs} (79%) delete mode 100644 tests/ImageSharp.Tests/Helpers/Vector4UtilsTests.cs diff --git a/src/ImageSharp/Color/Color.cs b/src/ImageSharp/Color/Color.cs index 424329863..72f16528a 100644 --- a/src/ImageSharp/Color/Color.cs +++ b/src/ImageSharp/Color/Color.cs @@ -27,19 +27,19 @@ namespace SixLabors.ImageSharp private Color(byte r, byte g, byte b, byte a) { this.data = new Rgba64( - ImageMath.UpscaleFrom8BitTo16Bit(r), - ImageMath.UpscaleFrom8BitTo16Bit(g), - ImageMath.UpscaleFrom8BitTo16Bit(b), - ImageMath.UpscaleFrom8BitTo16Bit(a)); + ColorNumerics.UpscaleFrom8BitTo16Bit(r), + ColorNumerics.UpscaleFrom8BitTo16Bit(g), + ColorNumerics.UpscaleFrom8BitTo16Bit(b), + ColorNumerics.UpscaleFrom8BitTo16Bit(a)); } [MethodImpl(InliningOptions.ShortMethod)] private Color(byte r, byte g, byte b) { this.data = new Rgba64( - ImageMath.UpscaleFrom8BitTo16Bit(r), - ImageMath.UpscaleFrom8BitTo16Bit(g), - ImageMath.UpscaleFrom8BitTo16Bit(b), + ColorNumerics.UpscaleFrom8BitTo16Bit(r), + ColorNumerics.UpscaleFrom8BitTo16Bit(g), + ColorNumerics.UpscaleFrom8BitTo16Bit(b), ushort.MaxValue); } diff --git a/src/ImageSharp/Common/Helpers/ColorNumerics.cs b/src/ImageSharp/Common/Helpers/ColorNumerics.cs new file mode 100644 index 000000000..6f225b110 --- /dev/null +++ b/src/ImageSharp/Common/Helpers/ColorNumerics.cs @@ -0,0 +1,177 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace SixLabors.ImageSharp +{ + /// + /// Provides optimized static methods for common mathematical functions specific + /// to color processing. + /// + internal static class ColorNumerics + { + /// + /// Vector for converting pixel to gray value as specified by + /// ITU-R Recommendation BT.709. + /// + private static readonly Vector4 Bt709 = new Vector4(.2126f, .7152f, .0722f, 0.0f); + + /// + /// Convert a pixel value to grayscale using ITU-R Recommendation BT.709. + /// + /// The vector to get the luminance from. + /// + /// The number of luminance levels (256 for 8 bit, 65536 for 16 bit grayscale images). + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int GetBT709Luminance(ref Vector4 vector, int luminanceLevels) + => (int)MathF.Round(Vector4.Dot(vector, Bt709) * (luminanceLevels - 1)); + + /// + /// Gets the luminance from the rgb components using the formula + /// as specified by ITU-R Recommendation BT.709. + /// + /// The red component. + /// The green component. + /// The blue component. + /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte Get8BitBT709Luminance(byte r, byte g, byte b) + => (byte)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F); + + /// + /// Gets the luminance from the rgb components using the formula as + /// specified by ITU-R Recommendation BT.709. + /// + /// The red component. + /// The green component. + /// The blue component. + /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ushort Get16BitBT709Luminance(ushort r, ushort g, ushort b) + => (ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F); + + /// + /// Gets the luminance from the rgb components using the formula as specified + /// by ITU-R Recommendation BT.709. + /// + /// The red component. + /// The green component. + /// The blue component. + /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ushort Get16BitBT709Luminance(float r, float g, float b) + => (ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F); + + /// + /// Scales a value from a 16 bit to an + /// 8 bit equivalent. + /// + /// The 8 bit component value. + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte DownScaleFrom16BitTo8Bit(ushort component) + { + // To scale to 8 bits From a 16-bit value V the required value (from the PNG specification) is: + // + // (V * 255) / 65535 + // + // This reduces to round(V / 257), or floor((V + 128.5)/257) + // + // Represent V as the two byte value vhi.vlo. Make a guess that the + // result is the top byte of V, vhi, then the correction to this value + // is: + // + // error = floor(((V-vhi.vhi) + 128.5) / 257) + // = floor(((vlo-vhi) + 128.5) / 257) + // + // This can be approximated using integer arithmetic (and a signed + // shift): + // + // error = (vlo-vhi+128) >> 8; + // + // The approximate differs from the exact answer only when (vlo-vhi) is + // 128; it then gives a correction of +1 when the exact correction is + // 0. This gives 128 errors. The exact answer (correct for all 16-bit + // input values) is: + // + // error = (vlo-vhi+128)*65535 >> 24; + // + // An alternative arithmetic calculation which also gives no errors is: + // + // (V * 255 + 32895) >> 16 + return (byte)(((component * 255) + 32895) >> 16); + } + + /// + /// Scales a value from an 8 bit to + /// an 16 bit equivalent. + /// + /// The 8 bit component value. + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ushort UpscaleFrom8BitTo16Bit(byte component) + => (ushort)(component * 257); + + /// + /// Returns how many bits are required to store the specified number of colors. + /// Performs a Log2() on the value. + /// + /// The number of colors. + /// + /// The + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int GetBitsNeededForColorDepth(int colors) + => Math.Max(1, (int)Math.Ceiling(Math.Log(colors, 2))); + + /// + /// Returns how many colors will be created by the specified number of bits. + /// + /// The bit depth. + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int GetColorCountForBitDepth(int bitDepth) + => 1 << bitDepth; + + /// + /// Transforms a vector by the given color matrix. + /// + /// The source vector. + /// The transformation color matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Transform(ref Vector4 vector, ref ColorMatrix matrix) + { + float x = vector.X; + float y = vector.Y; + float z = vector.Z; + float w = vector.W; + + vector.X = (x * matrix.M11) + (y * matrix.M21) + (z * matrix.M31) + (w * matrix.M41) + matrix.M51; + vector.Y = (x * matrix.M12) + (y * matrix.M22) + (z * matrix.M32) + (w * matrix.M42) + matrix.M52; + vector.Z = (x * matrix.M13) + (y * matrix.M23) + (z * matrix.M33) + (w * matrix.M43) + matrix.M53; + vector.W = (x * matrix.M14) + (y * matrix.M24) + (z * matrix.M34) + (w * matrix.M44) + matrix.M54; + } + + /// + /// Bulk variant of . + /// + /// The span of vectors + /// The transformation color matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Transform(Span vectors, ref ColorMatrix matrix) + { + ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors); + + for (int i = 0; i < vectors.Length; i++) + { + ref Vector4 v = ref Unsafe.Add(ref baseRef, i); + Transform(ref v, ref matrix); + } + } + } +} diff --git a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs index 7da2528fa..f265bdd51 100644 --- a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs +++ b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column); vector.W = target.W; - Vector4Utils.UnPremultiply(ref vector); + Numerics.UnPremultiply(ref vector); target = vector; } @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp out Vector4 vector); ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column); - Vector4Utils.UnPremultiply(ref vector); + Numerics.UnPremultiply(ref vector); target = vector; } @@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp { int offsetX = Numerics.Clamp(sourceOffsetColumnBase + x - radiusX, minColumn, maxColumn); var currentColor = sourceRowSpan[offsetX].ToVector4(); - Vector4Utils.Premultiply(ref currentColor); + Numerics.Premultiply(ref currentColor); vectorX += matrixX[y, x] * currentColor; vectorY += matrixY[y, x] * currentColor; @@ -193,7 +193,7 @@ namespace SixLabors.ImageSharp ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column); vector.W = target.W; - Vector4Utils.UnPremultiply(ref vector); + Numerics.UnPremultiply(ref vector); target = vector; } @@ -238,7 +238,7 @@ namespace SixLabors.ImageSharp ref vector); ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column); - Vector4Utils.UnPremultiply(ref vector); + Numerics.UnPremultiply(ref vector); target = vector; } @@ -270,7 +270,7 @@ namespace SixLabors.ImageSharp { int offsetX = Numerics.Clamp(sourceOffsetColumnBase + x - radiusX, minColumn, maxColumn); var currentColor = sourceRowSpan[offsetX].ToVector4(); - Vector4Utils.Premultiply(ref currentColor); + Numerics.Premultiply(ref currentColor); vector += matrix[y, x] * currentColor; } } diff --git a/src/ImageSharp/Common/Helpers/ImageMath.cs b/src/ImageSharp/Common/Helpers/ImageMath.cs deleted file mode 100644 index 59f9ad021..000000000 --- a/src/ImageSharp/Common/Helpers/ImageMath.cs +++ /dev/null @@ -1,257 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Numerics; -using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp -{ - /// - /// Provides common mathematical methods used for image processing. - /// - internal static class ImageMath - { - /// - /// Vector for converting pixel to gray value as specified by ITU-R Recommendation BT.709. - /// - private static readonly Vector4 Bt709 = new Vector4(.2126f, .7152f, .0722f, 0.0f); - - /// - /// Convert a pixel value to grayscale using ITU-R Recommendation BT.709. - /// - /// The vector to get the luminance from. - /// The number of luminance levels (256 for 8 bit, 65536 for 16 bit grayscale images) - [MethodImpl(InliningOptions.ShortMethod)] - public static int GetBT709Luminance(ref Vector4 vector, int luminanceLevels) - => (int)MathF.Round(Vector4.Dot(vector, Bt709) * (luminanceLevels - 1)); - - /// - /// Gets the luminance from the rgb components using the formula as specified by ITU-R Recommendation BT.709. - /// - /// The red component. - /// The green component. - /// The blue component. - /// The . - [MethodImpl(InliningOptions.ShortMethod)] - public static byte Get8BitBT709Luminance(byte r, byte g, byte b) => - (byte)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F); - - /// - /// Gets the luminance from the rgb components using the formula as specified by ITU-R Recommendation BT.709. - /// - /// The red component. - /// The green component. - /// The blue component. - /// The . - [MethodImpl(InliningOptions.ShortMethod)] - public static ushort Get16BitBT709Luminance(ushort r, ushort g, ushort b) => - (ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F); - - /// - /// Gets the luminance from the rgb components using the formula as specified by ITU-R Recommendation BT.709. - /// - /// The red component. - /// The green component. - /// The blue component. - /// The . - [MethodImpl(InliningOptions.ShortMethod)] - public static ushort Get16BitBT709Luminance(float r, float g, float b) => - (ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F); - - /// - /// Scales a value from a 16 bit to it's 8 bit equivalent. - /// - /// The 8 bit component value. - /// The - [MethodImpl(InliningOptions.ShortMethod)] - public static byte DownScaleFrom16BitTo8Bit(ushort component) - { - // To scale to 8 bits From a 16-bit value V the required value (from the PNG specification) is: - // - // (V * 255) / 65535 - // - // This reduces to round(V / 257), or floor((V + 128.5)/257) - // - // Represent V as the two byte value vhi.vlo. Make a guess that the - // result is the top byte of V, vhi, then the correction to this value - // is: - // - // error = floor(((V-vhi.vhi) + 128.5) / 257) - // = floor(((vlo-vhi) + 128.5) / 257) - // - // This can be approximated using integer arithmetic (and a signed - // shift): - // - // error = (vlo-vhi+128) >> 8; - // - // The approximate differs from the exact answer only when (vlo-vhi) is - // 128; it then gives a correction of +1 when the exact correction is - // 0. This gives 128 errors. The exact answer (correct for all 16-bit - // input values) is: - // - // error = (vlo-vhi+128)*65535 >> 24; - // - // An alternative arithmetic calculation which also gives no errors is: - // - // (V * 255 + 32895) >> 16 - return (byte)(((component * 255) + 32895) >> 16); - } - - /// - /// Scales a value from an 8 bit to it's 16 bit equivalent. - /// - /// The 8 bit component value. - /// The - [MethodImpl(InliningOptions.ShortMethod)] - public static ushort UpscaleFrom8BitTo16Bit(byte component) => (ushort)(component * 257); - - /// - /// Returns how many bits are required to store the specified number of colors. - /// Performs a Log2() on the value. - /// - /// The number of colors. - /// - /// The - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static int GetBitsNeededForColorDepth(int colors) => Math.Max(1, (int)Math.Ceiling(Math.Log(colors, 2))); - - /// - /// Returns how many colors will be created by the specified number of bits. - /// - /// The bit depth. - /// The - [MethodImpl(InliningOptions.ShortMethod)] - public static int GetColorCountForBitDepth(int bitDepth) => 1 << bitDepth; - - /// - /// Gets the bounding from the given points. - /// - /// - /// The designating the top left position. - /// - /// - /// The designating the bottom right position. - /// - /// - /// The bounding . - /// - [MethodImpl(InliningOptions.ShortMethod)] - public static Rectangle GetBoundingRectangle(Point topLeft, Point bottomRight) => new Rectangle(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y); - - /// - /// Finds the bounding rectangle based on the first instance of any color component other - /// than the given one. - /// - /// The pixel format. - /// The to search within. - /// The color component value to remove. - /// The channel to test against. - /// - /// The . - /// - public static Rectangle GetFilteredBoundingRectangle(ImageFrame bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B) - where TPixel : unmanaged, IPixel - { - int width = bitmap.Width; - int height = bitmap.Height; - Point topLeft = default; - Point bottomRight = default; - - Func, int, int, float, bool> delegateFunc; - - // Determine which channel to check against - switch (channel) - { - case RgbaComponent.R: - delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().X - b) > Constants.Epsilon; - break; - - case RgbaComponent.G: - delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Y - b) > Constants.Epsilon; - break; - - case RgbaComponent.B: - delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Z - b) > Constants.Epsilon; - break; - - default: - delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().W - b) > Constants.Epsilon; - break; - } - - int GetMinY(ImageFrame pixels) - { - for (int y = 0; y < height; y++) - { - for (int x = 0; x < width; x++) - { - if (delegateFunc(pixels, x, y, componentValue)) - { - return y; - } - } - } - - return 0; - } - - int GetMaxY(ImageFrame pixels) - { - for (int y = height - 1; y > -1; y--) - { - for (int x = 0; x < width; x++) - { - if (delegateFunc(pixels, x, y, componentValue)) - { - return y; - } - } - } - - return height; - } - - int GetMinX(ImageFrame pixels) - { - for (int x = 0; x < width; x++) - { - for (int y = 0; y < height; y++) - { - if (delegateFunc(pixels, x, y, componentValue)) - { - return x; - } - } - } - - return 0; - } - - int GetMaxX(ImageFrame pixels) - { - for (int x = width - 1; x > -1; x--) - { - for (int y = 0; y < height; y++) - { - if (delegateFunc(pixels, x, y, componentValue)) - { - return x; - } - } - } - - return width; - } - - topLeft.Y = GetMinY(bitmap); - topLeft.X = GetMinX(bitmap); - bottomRight.Y = Numerics.Clamp(GetMaxY(bitmap) + 1, 0, height); - bottomRight.X = Numerics.Clamp(GetMaxX(bitmap) + 1, 0, width); - - return GetBoundingRectangle(topLeft, bottomRight); - } - } -} diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index c1e564781..b2bedb87b 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -5,6 +5,10 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +#if SUPPORTS_RUNTIME_INTRINSICS +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; +#endif namespace SixLabors.ImageSharp { @@ -14,9 +18,15 @@ namespace SixLabors.ImageSharp /// internal static class Numerics { +#if SUPPORTS_RUNTIME_INTRINSICS + private const int BlendAlphaControl = 0b_10_00_10_00; + private const int ShuffleAlphaControl = 0b_11_11_11_11; +#endif + /// /// Determine the Greatest CommonDivisor (GCD) of two numbers. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GreatestCommonDivisor(int a, int b) { while (b != 0) @@ -32,6 +42,7 @@ namespace SixLabors.ImageSharp /// /// Determine the Least Common Multiple (LCM) of two numbers. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LeastCommonMultiple(int a, int b) { // https://en.wikipedia.org/wiki/Least_common_multiple#Reduction_by_the_greatest_common_divisor @@ -262,7 +273,7 @@ namespace SixLabors.ImageSharp /// The minimum inclusive value. /// The maximum inclusive value. /// The clamped . - [MethodImpl(InliningOptions.ShortMethod)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector4 Clamp(Vector4 value, Vector4 min, Vector4 max) => Vector4.Min(Vector4.Max(value, min), max); @@ -426,5 +437,115 @@ namespace SixLabors.ImageSharp } } } + + /// + /// Pre-multiplies the "x", "y", "z" components of a vector by its "w" component leaving the "w" component intact. + /// + /// The to premultiply + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Premultiply(ref Vector4 source) + { + float w = source.W; + source *= w; + source.W = w; + } + + /// + /// Reverses the result of premultiplying a vector via . + /// + /// The to premultiply + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void UnPremultiply(ref Vector4 source) + { + float w = source.W; + source /= w; + source.W = w; + } + + /// + /// Bulk variant of + /// + /// The span of vectors + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Premultiply(Span vectors) + { +#if SUPPORTS_RUNTIME_INTRINSICS + if (Avx2.IsSupported && vectors.Length >= 2) + { + ref Vector256 vectorsBase = + ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors)); + + // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 + ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u)); + + while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast)) + { + Vector256 source = vectorsBase; + Vector256 multiply = Avx.Shuffle(source, source, ShuffleAlphaControl); + vectorsBase = Avx.Blend(Avx.Multiply(source, multiply), source, BlendAlphaControl); + vectorsBase = ref Unsafe.Add(ref vectorsBase, 1); + } + + if (Modulo2(vectors.Length) != 0) + { + // Vector4 fits neatly in pairs. Any overlap has to be equal to 1. + Premultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1))); + } + } + else +#endif + { + ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors); + + for (int i = 0; i < vectors.Length; i++) + { + ref Vector4 v = ref Unsafe.Add(ref baseRef, i); + Premultiply(ref v); + } + } + } + + /// + /// Bulk variant of + /// + /// The span of vectors + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void UnPremultiply(Span vectors) + { +#if SUPPORTS_RUNTIME_INTRINSICS + if (Avx2.IsSupported && vectors.Length >= 2) + { + ref Vector256 vectorsBase = + ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors)); + + // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 + ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u)); + + while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast)) + { + Vector256 source = vectorsBase; + Vector256 multiply = Avx.Shuffle(source, source, ShuffleAlphaControl); + vectorsBase = Avx.Blend(Avx.Divide(source, multiply), source, BlendAlphaControl); + vectorsBase = ref Unsafe.Add(ref vectorsBase, 1); + } + + if (Modulo2(vectors.Length) != 0) + { + // Vector4 fits neatly in pairs. Any overlap has to be equal to 1. + UnPremultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1))); + } + } + else +#endif + { + ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors); + + for (int i = 0; i < vectors.Length; i++) + { + ref Vector4 v = ref Unsafe.Add(ref baseRef, i); + UnPremultiply(ref v); + } + } + } } } diff --git a/src/ImageSharp/Common/Helpers/Vector4Utils.cs b/src/ImageSharp/Common/Helpers/Vector4Utils.cs deleted file mode 100644 index 05661991a..000000000 --- a/src/ImageSharp/Common/Helpers/Vector4Utils.cs +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Numerics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -#if SUPPORTS_RUNTIME_INTRINSICS -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; -#endif - -namespace SixLabors.ImageSharp -{ - /// - /// Utility methods for the struct. - /// - internal static class Vector4Utils - { - private const int BlendAlphaControl = 0b_10_00_10_00; - private const int ShuffleAlphaControl = 0b_11_11_11_11; - - /// - /// Pre-multiplies the "x", "y", "z" components of a vector by its "w" component leaving the "w" component intact. - /// - /// The to premultiply - [MethodImpl(InliningOptions.ShortMethod)] - public static void Premultiply(ref Vector4 source) - { - float w = source.W; - source *= w; - source.W = w; - } - - /// - /// Reverses the result of premultiplying a vector via . - /// - /// The to premultiply - [MethodImpl(InliningOptions.ShortMethod)] - public static void UnPremultiply(ref Vector4 source) - { - float w = source.W; - source /= w; - source.W = w; - } - - /// - /// Bulk variant of - /// - /// The span of vectors - [MethodImpl(InliningOptions.ShortMethod)] - public static void Premultiply(Span vectors) - { -#if SUPPORTS_RUNTIME_INTRINSICS - if (Avx2.IsSupported && vectors.Length >= 2) - { - ref Vector256 vectorsBase = - ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors)); - - // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 - ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u)); - - while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast)) - { - Vector256 source = vectorsBase; - Vector256 multiply = Avx.Shuffle(source, source, ShuffleAlphaControl); - vectorsBase = Avx.Blend(Avx.Multiply(source, multiply), source, BlendAlphaControl); - vectorsBase = ref Unsafe.Add(ref vectorsBase, 1); - } - - if (Numerics.Modulo2(vectors.Length) != 0) - { - // Vector4 fits neatly in pairs. Any overlap has to be equal to 1. - Premultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1))); - } - } - else -#endif - { - ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors); - - for (int i = 0; i < vectors.Length; i++) - { - ref Vector4 v = ref Unsafe.Add(ref baseRef, i); - Premultiply(ref v); - } - } - } - - /// - /// Bulk variant of - /// - /// The span of vectors - [MethodImpl(InliningOptions.ShortMethod)] - public static void UnPremultiply(Span vectors) - { -#if SUPPORTS_RUNTIME_INTRINSICS - if (Avx2.IsSupported && vectors.Length >= 2) - { - ref Vector256 vectorsBase = - ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors)); - - // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 - ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u)); - - while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast)) - { - Vector256 source = vectorsBase; - Vector256 multiply = Avx.Shuffle(source, source, ShuffleAlphaControl); - vectorsBase = Avx.Blend(Avx.Divide(source, multiply), source, BlendAlphaControl); - vectorsBase = ref Unsafe.Add(ref vectorsBase, 1); - } - - if (Numerics.Modulo2(vectors.Length) != 0) - { - // Vector4 fits neatly in pairs. Any overlap has to be equal to 1. - UnPremultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1))); - } - } - else -#endif - { - ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors); - - for (int i = 0; i < vectors.Length; i++) - { - ref Vector4 v = ref Unsafe.Add(ref baseRef, i); - UnPremultiply(ref v); - } - } - } - - /// - /// Transforms a vector by the given matrix. - /// - /// The source vector. - /// The transformation matrix. - [MethodImpl(InliningOptions.ShortMethod)] - public static void Transform(ref Vector4 vector, ref ColorMatrix matrix) - { - float x = vector.X; - float y = vector.Y; - float z = vector.Z; - float w = vector.W; - - vector.X = (x * matrix.M11) + (y * matrix.M21) + (z * matrix.M31) + (w * matrix.M41) + matrix.M51; - vector.Y = (x * matrix.M12) + (y * matrix.M22) + (z * matrix.M32) + (w * matrix.M42) + matrix.M52; - vector.Z = (x * matrix.M13) + (y * matrix.M23) + (z * matrix.M33) + (w * matrix.M43) + matrix.M53; - vector.W = (x * matrix.M14) + (y * matrix.M24) + (z * matrix.M34) + (w * matrix.M44) + matrix.M54; - } - - /// - /// Bulk variant of . - /// - /// The span of vectors - /// The transformation matrix. - [MethodImpl(InliningOptions.ShortMethod)] - public static void Transform(Span vectors, ref ColorMatrix matrix) - { - ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors); - - for (int i = 0; i < vectors.Length; i++) - { - ref Vector4 v = ref Unsafe.Add(ref baseRef, i); - Transform(ref v, ref matrix); - } - } - } -} diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 0dd667850..0be038572 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -1385,7 +1385,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { case BmpFileMarkerType.Bitmap: colorMapSizeBytes = this.fileHeader.Offset - BmpFileHeader.Size - this.infoHeader.HeaderSize; - int colorCountForBitDepth = ImageMath.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel); + int colorCountForBitDepth = ColorNumerics.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel); bytesPerColorMapEntry = colorMapSizeBytes / colorCountForBitDepth; // Edge case for less-than-full-sized palette: bytesPerColorMapEntry should be at least 3. @@ -1399,7 +1399,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp case BmpFileMarkerType.Pointer: // OS/2 bitmaps always have 3 colors per color palette entry. bytesPerColorMapEntry = 3; - colorMapSizeBytes = ImageMath.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel) * bytesPerColorMapEntry; + colorMapSizeBytes = ColorNumerics.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel) * bytesPerColorMapEntry; break; } } diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index f4288e97f..9c1e95285 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.Formats.Gif } // Get the number of bits. - this.bitDepth = ImageMath.GetBitsNeededForColorDepth(quantized.Palette.Length); + this.bitDepth = ColorNumerics.GetBitsNeededForColorDepth(quantized.Palette.Length); // Write the header. this.WriteHeader(stream); @@ -212,7 +212,7 @@ namespace SixLabors.ImageSharp.Formats.Gif } } - this.bitDepth = ImageMath.GetBitsNeededForColorDepth(quantized.Palette.Length); + this.bitDepth = ColorNumerics.GetBitsNeededForColorDepth(quantized.Palette.Length); this.WriteGraphicalControlExtension(frameMetadata, this.GetTransparentIndex(quantized), stream); this.WriteImageDescriptor(frame, true, stream); this.WriteColorTable(quantized, stream); @@ -468,7 +468,7 @@ namespace SixLabors.ImageSharp.Formats.Gif where TPixel : unmanaged, IPixel { // The maximum number of colors for the bit depth - int colorTableLength = ImageMath.GetColorCountForBitDepth(this.bitDepth) * Unsafe.SizeOf(); + int colorTableLength = ColorNumerics.GetColorCountForBitDepth(this.bitDepth) * Unsafe.SizeOf(); using IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength, AllocationOptions.Clean); PixelOperations.Instance.ToRgb24Bytes( diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 4e05f459f..5d2af8ec6 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -284,7 +284,7 @@ namespace SixLabors.ImageSharp.Formats.Png rowSpan.Length, AllocationOptions.Clean)) { - int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(this.bitDepth) - 1); + int scaleFactor = 255 / (ColorNumerics.GetColorCountForBitDepth(this.bitDepth) - 1); Span tempSpan = temp.GetSpan(); // We need to first create an array of luminance bytes then scale them down to the correct bit depth. @@ -314,7 +314,7 @@ namespace SixLabors.ImageSharp.Formats.Png for (int x = 0, o = 0; x < rgbaSpan.Length; x++, o += 4) { Rgba64 rgba = Unsafe.Add(ref rgbaRef, x); - ushort luminance = ImageMath.Get16BitBT709Luminance(rgba.R, rgba.G, rgba.B); + ushort luminance = ColorNumerics.Get16BitBT709Luminance(rgba.R, rgba.G, rgba.B); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), luminance); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgba.A); } @@ -329,7 +329,7 @@ namespace SixLabors.ImageSharp.Formats.Png { Unsafe.Add(ref rowSpanRef, x).ToRgba32(ref rgba); Unsafe.Add(ref rawScanlineSpanRef, o) = - ImageMath.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B); + ColorNumerics.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B); Unsafe.Add(ref rawScanlineSpanRef, o + 1) = rgba.A; } } diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs index f1f5145ca..23ca86993 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Formats.Png if (options.Quantizer is null) { byte bits = (byte)options.BitDepth; - var maxColors = ImageMath.GetColorCountForBitDepth(bits); + var maxColors = ColorNumerics.GetColorCountForBitDepth(bits); options.Quantizer = new WuQuantizer(new QuantizerOptions { MaxColors = maxColors }); } @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Formats.Png byte bitDepth; if (options.ColorType == PngColorType.Palette) { - byte quantizedBits = (byte)Numerics.Clamp(ImageMath.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length), 1, 8); + byte quantizedBits = (byte)Numerics.Clamp(ColorNumerics.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length), 1, 8); byte bits = Math.Max((byte)options.BitDepth, quantizedBits); // Png only supports in four pixel depths: 1, 2, 4, and 8 bits when using the PLTE chunk diff --git a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs index 16d6aa19f..58fa5aca8 100644 --- a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs +++ b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Formats.Png TPixel pixel = default; ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan); ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan); - int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(header.BitDepth) - 1); + int scaleFactor = 255 / (ColorNumerics.GetColorCountForBitDepth(header.BitDepth) - 1); if (!hasTrans) { @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Formats.Png TPixel pixel = default; ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan); ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan); - int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(header.BitDepth) - 1); + int scaleFactor = 255 / (ColorNumerics.GetColorCountForBitDepth(header.BitDepth) - 1); if (!hasTrans) { diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs index 92474b6fc..1d31ea9f4 100644 --- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs @@ -365,7 +365,7 @@ namespace SixLabors.ImageSharp.Formats.Tga where TPixel : unmanaged, IPixel { var vector = sourcePixel.ToVector4(); - return ImageMath.GetBT709Luminance(ref vector, 256); + return ColorNumerics.GetBT709Luminance(ref vector, 256); } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs index fa08bbe62..77df2bc80 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromLa32(La32 source) => this.PackedValue = ImageMath.DownScaleFrom16BitTo8Bit(source.A); + public void FromLa32(La32 source) => this.PackedValue = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs index 9e6db8b70..3ac9b523f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs @@ -244,7 +244,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -265,11 +265,11 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; - this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); + this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A); } /// @@ -306,9 +306,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); this.A = byte.MaxValue; } @@ -316,10 +316,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); - this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); + this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs index 9063516a3..6cff5fd77 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; @@ -203,18 +203,18 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs index 2058c4e00..190345dda 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs @@ -197,7 +197,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -218,11 +218,11 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; - this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); + this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A); } /// @@ -259,9 +259,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); this.A = byte.MaxValue; } @@ -269,10 +269,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); - this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); + this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs index cda2f32e8..dd31aae2f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs @@ -74,30 +74,30 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromArgb32(Argb32 source) { - this.PackedValue = ImageMath.Get16BitBT709Luminance( - ImageMath.UpscaleFrom8BitTo16Bit(source.R), - ImageMath.UpscaleFrom8BitTo16Bit(source.G), - ImageMath.UpscaleFrom8BitTo16Bit(source.B)); + this.PackedValue = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) { - this.PackedValue = ImageMath.Get16BitBT709Luminance( - ImageMath.UpscaleFrom8BitTo16Bit(source.R), - ImageMath.UpscaleFrom8BitTo16Bit(source.G), - ImageMath.UpscaleFrom8BitTo16Bit(source.B)); + this.PackedValue = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) { - this.PackedValue = ImageMath.Get16BitBT709Luminance( - ImageMath.UpscaleFrom8BitTo16Bit(source.R), - ImageMath.UpscaleFrom8BitTo16Bit(source.G), - ImageMath.UpscaleFrom8BitTo16Bit(source.B)); + this.PackedValue = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); } /// @@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromL8(L8 source) => this.PackedValue = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue); + public void FromL8(L8 source) => this.PackedValue = ColorNumerics.UpscaleFrom8BitTo16Bit(source.PackedValue); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromLa16(La16 source) => this.PackedValue = ImageMath.UpscaleFrom8BitTo16Bit(source.L); + public void FromLa16(La16 source) => this.PackedValue = ColorNumerics.UpscaleFrom8BitTo16Bit(source.L); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -124,27 +124,27 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb24(Rgb24 source) { - this.PackedValue = ImageMath.Get16BitBT709Luminance( - ImageMath.UpscaleFrom8BitTo16Bit(source.R), - ImageMath.UpscaleFrom8BitTo16Bit(source.G), - ImageMath.UpscaleFrom8BitTo16Bit(source.B)); + this.PackedValue = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) { - this.PackedValue = ImageMath.Get16BitBT709Luminance( - ImageMath.UpscaleFrom8BitTo16Bit(source.R), - ImageMath.UpscaleFrom8BitTo16Bit(source.G), - ImageMath.UpscaleFrom8BitTo16Bit(source.B)); + this.PackedValue = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); } /// [MethodImpl(InliningOptions.ShortMethod)] public void ToRgba32(ref Rgba32 dest) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(this.PackedValue); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(this.PackedValue); dest.R = rgb; dest.G = rgb; dest.B = rgb; @@ -153,11 +153,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromRgb48(Rgb48 source) => this.PackedValue = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B); + public void FromRgb48(Rgb48 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromRgba64(Rgba64 source) => this.PackedValue = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B); + public void FromRgba64(Rgba64 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance(source.R, source.G, source.B); /// public override readonly bool Equals(object obj) => obj is L16 other && this.Equals(other); @@ -177,7 +177,7 @@ namespace SixLabors.ImageSharp.PixelFormats internal void ConvertFromRgbaScaledVector4(Vector4 vector) { vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Max; - this.PackedValue = ImageMath.Get16BitBT709Luminance( + this.PackedValue = ColorNumerics.Get16BitBT709Luminance( vector.X, vector.Y, vector.Z); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs index 938d83feb..c570c33a1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs @@ -73,15 +73,15 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromArgb32(Argb32 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); + public void FromArgb32(Argb32 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromBgr24(Bgr24 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); + public void FromBgr24(Bgr24 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromBgra32(Bgra32 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); + public void FromBgra32(Bgra32 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromL16(L16 source) => this.PackedValue = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); + public void FromL16(L16 source) => this.PackedValue = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -101,15 +101,15 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromLa32(La32 source) => this.PackedValue = ImageMath.DownScaleFrom16BitTo8Bit(source.L); + public void FromLa32(La32 source) => this.PackedValue = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L); /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromRgb24(Rgb24 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); + public void FromRgb24(Rgb24 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromRgba32(Rgba32 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); + public void FromRgba32(Rgba32 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -124,18 +124,18 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) - => this.PackedValue = ImageMath.Get8BitBT709Luminance( - ImageMath.DownScaleFrom16BitTo8Bit(source.R), - ImageMath.DownScaleFrom16BitTo8Bit(source.G), - ImageMath.DownScaleFrom16BitTo8Bit(source.B)); + => this.PackedValue = ColorNumerics.Get8BitBT709Luminance( + ColorNumerics.DownScaleFrom16BitTo8Bit(source.R), + ColorNumerics.DownScaleFrom16BitTo8Bit(source.G), + ColorNumerics.DownScaleFrom16BitTo8Bit(source.B)); /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) - => this.PackedValue = ImageMath.Get8BitBT709Luminance( - ImageMath.DownScaleFrom16BitTo8Bit(source.R), - ImageMath.DownScaleFrom16BitTo8Bit(source.G), - ImageMath.DownScaleFrom16BitTo8Bit(source.B)); + => this.PackedValue = ColorNumerics.Get8BitBT709Luminance( + ColorNumerics.DownScaleFrom16BitTo8Bit(source.R), + ColorNumerics.DownScaleFrom16BitTo8Bit(source.G), + ColorNumerics.DownScaleFrom16BitTo8Bit(source.B)); /// public override readonly bool Equals(object obj) => obj is L8 other && this.Equals(other); @@ -157,7 +157,7 @@ namespace SixLabors.ImageSharp.PixelFormats vector *= MaxBytes; vector += Half; vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes); - this.PackedValue = ImageMath.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z); + this.PackedValue = ColorNumerics.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z); } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs index 21d983494..5a69431a1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs @@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromArgb32(Argb32 source) { - this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); + this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); this.A = source.A; } @@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) { - this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); + this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); this.A = byte.MaxValue; } @@ -108,7 +108,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) { - this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); + this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); this.A = source.A; } @@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - this.L = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); + this.L = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue); this.A = byte.MaxValue; } @@ -140,15 +140,15 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - this.L = ImageMath.DownScaleFrom16BitTo8Bit(source.L); - this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); + this.L = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L); + this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb24(Rgb24 source) { - this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); + this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); this.A = byte.MaxValue; } @@ -156,10 +156,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.L = ImageMath.Get8BitBT709Luminance( - ImageMath.DownScaleFrom16BitTo8Bit(source.R), - ImageMath.DownScaleFrom16BitTo8Bit(source.G), - ImageMath.DownScaleFrom16BitTo8Bit(source.B)); + this.L = ColorNumerics.Get8BitBT709Luminance( + ColorNumerics.DownScaleFrom16BitTo8Bit(source.R), + ColorNumerics.DownScaleFrom16BitTo8Bit(source.G), + ColorNumerics.DownScaleFrom16BitTo8Bit(source.B)); this.A = byte.MaxValue; } @@ -168,19 +168,19 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) { - this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B); + this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); this.A = source.A; } /// public void FromRgba64(Rgba64 source) { - this.L = ImageMath.Get8BitBT709Luminance( - ImageMath.DownScaleFrom16BitTo8Bit(source.R), - ImageMath.DownScaleFrom16BitTo8Bit(source.G), - ImageMath.DownScaleFrom16BitTo8Bit(source.B)); + this.L = ColorNumerics.Get8BitBT709Luminance( + ColorNumerics.DownScaleFrom16BitTo8Bit(source.R), + ColorNumerics.DownScaleFrom16BitTo8Bit(source.G), + ColorNumerics.DownScaleFrom16BitTo8Bit(source.B)); - this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); + this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A); } /// @@ -220,7 +220,7 @@ namespace SixLabors.ImageSharp.PixelFormats vector *= MaxBytes; vector += Half; vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes); - this.L = ImageMath.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z); + this.L = ColorNumerics.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z); this.A = (byte)vector.W; } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs index 319775061..66d0e38c7 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs @@ -95,22 +95,22 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromArgb32(Argb32 source) { - this.L = ImageMath.Get16BitBT709Luminance( - ImageMath.UpscaleFrom8BitTo16Bit(source.R), - ImageMath.UpscaleFrom8BitTo16Bit(source.G), - ImageMath.UpscaleFrom8BitTo16Bit(source.B)); + this.L = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); - this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) { - this.L = ImageMath.Get16BitBT709Luminance( - ImageMath.UpscaleFrom8BitTo16Bit(source.R), - ImageMath.UpscaleFrom8BitTo16Bit(source.G), - ImageMath.UpscaleFrom8BitTo16Bit(source.B)); + this.L = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); this.A = ushort.MaxValue; } @@ -119,12 +119,12 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) { - this.L = ImageMath.Get16BitBT709Luminance( - ImageMath.UpscaleFrom8BitTo16Bit(source.R), - ImageMath.UpscaleFrom8BitTo16Bit(source.G), - ImageMath.UpscaleFrom8BitTo16Bit(source.B)); + this.L = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); - this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL8(L8 source) { - this.L = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue); + this.L = ColorNumerics.UpscaleFrom8BitTo16Bit(source.PackedValue); this.A = ushort.MaxValue; } @@ -151,8 +151,8 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa16(La16 source) { - this.L = ImageMath.UpscaleFrom8BitTo16Bit(source.L); - this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); + this.L = ColorNumerics.UpscaleFrom8BitTo16Bit(source.L); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -163,10 +163,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb24(Rgb24 source) { - this.L = ImageMath.Get16BitBT709Luminance( - ImageMath.UpscaleFrom8BitTo16Bit(source.R), - ImageMath.UpscaleFrom8BitTo16Bit(source.G), - ImageMath.UpscaleFrom8BitTo16Bit(source.B)); + this.L = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); this.A = ushort.MaxValue; } @@ -175,7 +175,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.L = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B); + this.L = ColorNumerics.Get16BitBT709Luminance(source.R, source.G, source.B); this.A = ushort.MaxValue; } @@ -183,19 +183,19 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) { - this.L = ImageMath.Get16BitBT709Luminance( - ImageMath.UpscaleFrom8BitTo16Bit(source.R), - ImageMath.UpscaleFrom8BitTo16Bit(source.G), - ImageMath.UpscaleFrom8BitTo16Bit(source.B)); + this.L = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); - this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.L = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B); + this.L = ColorNumerics.Get16BitBT709Luminance(source.R, source.G, source.B); this.A = source.A; } @@ -211,11 +211,11 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void ToRgba32(ref Rgba32 dest) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(this.L); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(this.L); dest.R = rgb; dest.G = rgb; dest.B = rgb; - dest.A = ImageMath.DownScaleFrom16BitTo8Bit(this.A); + dest.A = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A); } /// @@ -234,7 +234,7 @@ namespace SixLabors.ImageSharp.PixelFormats internal void ConvertFromRgbaScaledVector4(Vector4 vector) { vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Max; - this.L = ImageMath.Get16BitBT709Luminance( + this.L = ColorNumerics.Get16BitBT709Luminance( vector.X, vector.Y, vector.Z); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs index b7e831cfa..7fd63c676 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs @@ -166,7 +166,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -185,7 +185,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; @@ -227,18 +227,18 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs index 23297806d..e3738b70c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs @@ -99,27 +99,27 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromArgb32(Argb32 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); } /// @@ -134,7 +134,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL8(L8 source) { - ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue); + ushort rgb = ColorNumerics.UpscaleFrom8BitTo16Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa16(La16 source) { - ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.L); + ushort rgb = ColorNumerics.UpscaleFrom8BitTo16Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; @@ -172,27 +172,27 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb24(Rgb24 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); } /// [MethodImpl(InliningOptions.ShortMethod)] public void ToRgba32(ref Rgba32 dest) { - dest.R = ImageMath.DownScaleFrom16BitTo8Bit(this.R); - dest.G = ImageMath.DownScaleFrom16BitTo8Bit(this.G); - dest.B = ImageMath.DownScaleFrom16BitTo8Bit(this.B); + dest.R = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R); + dest.G = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G); + dest.B = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B); dest.A = byte.MaxValue; } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs index 19c1bd083..868165e9c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs @@ -351,7 +351,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL16(L16 source) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -372,11 +372,11 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa32(La32 source) { - byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L); + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; - this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); + this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A); } /// @@ -402,9 +402,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb48(Rgb48 source) { - this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); this.A = byte.MaxValue; } @@ -412,10 +412,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba64(Rgba64 source) { - this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R); - this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G); - this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B); - this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A); + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); + this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs index f8b40d7e0..9add3d718 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs @@ -62,10 +62,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public Rgba64(Rgba32 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -75,10 +75,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public Rgba64(Bgra32 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -88,10 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public Rgba64(Argb32 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -101,9 +101,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public Rgba64(Rgb24 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); this.A = ushort.MaxValue; } @@ -114,9 +114,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public Rgba64(Bgr24 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); this.A = ushort.MaxValue; } @@ -224,19 +224,19 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromArgb32(Argb32 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); this.A = ushort.MaxValue; } @@ -244,10 +244,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -258,7 +258,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromL8(L8 source) { - ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue); + ushort rgb = ColorNumerics.UpscaleFrom8BitTo16Bit(source.PackedValue); this.R = rgb; this.G = rgb; this.B = rgb; @@ -279,11 +279,11 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromLa16(La16 source) { - ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.L); + ushort rgb = ColorNumerics.UpscaleFrom8BitTo16Bit(source.L); this.R = rgb; this.G = rgb; this.B = rgb; - this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } /// @@ -300,9 +300,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgb24(Rgb24 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); this.A = ushort.MaxValue; } @@ -310,20 +310,20 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) { - this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R); - this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G); - this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B); - this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A); + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } /// [MethodImpl(InliningOptions.ShortMethod)] public void ToRgba32(ref Rgba32 dest) { - dest.R = ImageMath.DownScaleFrom16BitTo8Bit(this.R); - dest.G = ImageMath.DownScaleFrom16BitTo8Bit(this.G); - dest.B = ImageMath.DownScaleFrom16BitTo8Bit(this.B); - dest.A = ImageMath.DownScaleFrom16BitTo8Bit(this.A); + dest.R = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R); + dest.G = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G); + dest.B = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B); + dest.A = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A); } /// @@ -345,10 +345,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Rgba32 ToRgba32() { - byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R); - byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G); - byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B); - byte a = ImageMath.DownScaleFrom16BitTo8Bit(this.A); + byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R); + byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G); + byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B); + byte a = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A); return new Rgba32(r, g, b, a); } @@ -359,10 +359,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Bgra32 ToBgra32() { - byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R); - byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G); - byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B); - byte a = ImageMath.DownScaleFrom16BitTo8Bit(this.A); + byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R); + byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G); + byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B); + byte a = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A); return new Bgra32(r, g, b, a); } @@ -373,10 +373,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Argb32 ToArgb32() { - byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R); - byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G); - byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B); - byte a = ImageMath.DownScaleFrom16BitTo8Bit(this.A); + byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R); + byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G); + byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B); + byte a = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A); return new Argb32(r, g, b, a); } @@ -387,9 +387,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Rgb24 ToRgb24() { - byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R); - byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G); - byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B); + byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R); + byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G); + byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B); return new Rgb24(r, g, b); } @@ -400,9 +400,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Bgr24 ToBgr24() { - byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R); - byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G); - byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B); + byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R); + byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G); + byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B); return new Bgr24(r, g, b); } diff --git a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs index 977722b81..acc2725ce 100644 --- a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs +++ b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils if (modifiers.IsDefined(PixelConversionModifiers.Premultiply)) { - Vector4Utils.Premultiply(vectors); + Numerics.Premultiply(vectors); } } @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils { if (modifiers.IsDefined(PixelConversionModifiers.Premultiply)) { - Vector4Utils.UnPremultiply(vectors); + Numerics.UnPremultiply(vectors); } if (modifiers.IsDefined(PixelConversionModifiers.SRgbCompand)) diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs index a47937baf..df95b6f1b 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization color.ToRgba32(ref rgba); // Convert to grayscale using ITU-R Recommendation BT.709 if required - byte luminance = this.isAlphaOnly ? rgba.A : ImageMath.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B); + byte luminance = this.isAlphaOnly ? rgba.A : ColorNumerics.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B); color = luminance >= this.threshold ? this.upper : this.lower; } } diff --git a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs index 0f3c20f5e..9b99a5257 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs @@ -218,7 +218,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering this.source = source; this.destination = destination; this.bounds = bounds; - this.bitDepth = ImageMath.GetBitsNeededForColorDepth(destination.Palette.Length); + this.bitDepth = ColorNumerics.GetBitsNeededForColorDepth(destination.Palette.Length); } [MethodImpl(InliningOptions.ShortMethod)] @@ -262,7 +262,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering this.source = source; this.bounds = bounds; this.scale = processor.DitherScale; - this.bitDepth = ImageMath.GetBitsNeededForColorDepth(processor.Palette.Length); + this.bitDepth = ColorNumerics.GetBitsNeededForColorDepth(processor.Palette.Length); } [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs index e28d4add7..4dc9e4196 100644 --- a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs @@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters Span rowSpan = this.source.GetPixelRowSpan(y).Slice(this.startX, span.Length); PixelOperations.Instance.ToVector4(this.configuration, rowSpan, span); - Vector4Utils.Transform(span, ref Unsafe.AsRef(this.matrix)); + ColorNumerics.Transform(span, ref Unsafe.AsRef(this.matrix)); PixelOperations.Instance.FromVector4Destructive(this.configuration, span, rowSpan); } diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs index 255812078..b9383e331 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs @@ -259,7 +259,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization { for (int idx = 0; idx < length; idx++) { - int luminance = ImageMath.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); + int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); Unsafe.Add(ref histogramBase, luminance)++; } } @@ -276,7 +276,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization { for (int idx = 0; idx < length; idx++) { - int luminance = ImageMath.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); + int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); Unsafe.Add(ref histogramBase, luminance)--; } } diff --git a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs index b45773e9a..70d3e075d 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs @@ -123,7 +123,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization { // TODO: We should bulk convert here. var vector = pixelRow[x].ToVector4(); - int luminance = ImageMath.GetBT709Luminance(ref vector, levels); + int luminance = ColorNumerics.GetBT709Luminance(ref vector, levels); Interlocked.Increment(ref Unsafe.Add(ref histogramBase, luminance)); } } @@ -174,7 +174,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization // TODO: We should bulk convert here. ref TPixel pixel = ref pixelRow[x]; var vector = pixel.ToVector4(); - int luminance = ImageMath.GetBT709Luminance(ref vector, levels); + int luminance = ColorNumerics.GetBT709Luminance(ref vector, levels); float luminanceEqualized = Unsafe.Add(ref cdfBase, luminance) / noOfPixelsMinusCdfMin; pixel.FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, vector.W)); } diff --git a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs index 3bba95bc6..59df3058d 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization public static int GetLuminance(TPixel sourcePixel, int luminanceLevels) { var vector = sourcePixel.ToVector4(); - return ImageMath.GetBT709Luminance(ref vector, luminanceLevels); + return ColorNumerics.GetBT709Luminance(ref vector, luminanceLevels); } } } diff --git a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs index 1e1d1c953..6b64da1c9 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization this.Options = options; this.maxColors = this.Options.MaxColors; - this.octree = new Octree(Numerics.Clamp(ImageMath.GetBitsNeededForColorDepth(this.maxColors), 1, 8)); + this.octree = new Octree(Numerics.Clamp(ColorNumerics.GetBitsNeededForColorDepth(this.maxColors), 1, 8)); this.paletteOwner = configuration.MemoryAllocator.Allocate(this.maxColors, AllocationOptions.Clean); this.palette = default; this.pixelMap = default; diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs index 27d40e77b..675d6fe0d 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; +using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Binarization; @@ -48,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms new BinaryThresholdProcessor(this.definition.Threshold).Execute(this.Configuration, temp, this.SourceRectangle); // Search for the first white pixels - rectangle = ImageMath.GetFilteredBoundingRectangle(temp.Frames.RootFrame, 0); + rectangle = GetFilteredBoundingRectangle(temp.Frames.RootFrame, 0); } new CropProcessor(rectangle, this.Source.Size()).Execute(this.Configuration, this.Source, this.SourceRectangle); @@ -61,5 +63,136 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms { // All processing happens at the image level within BeforeImageApply(); } + + /// + /// Gets the bounding from the given points. + /// + /// + /// The designating the top left position. + /// + /// + /// The designating the bottom right position. + /// + /// + /// The bounding . + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Rectangle GetBoundingRectangle(Point topLeft, Point bottomRight) + => new Rectangle( + topLeft.X, + topLeft.Y, + bottomRight.X - topLeft.X, + bottomRight.Y - topLeft.Y); + + /// + /// Finds the bounding rectangle based on the first instance of any color component other + /// than the given one. + /// + /// The to search within. + /// The color component value to remove. + /// The channel to test against. + /// + /// The . + /// + private static Rectangle GetFilteredBoundingRectangle(ImageFrame bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B) + { + int width = bitmap.Width; + int height = bitmap.Height; + Point topLeft = default; + Point bottomRight = default; + + Func, int, int, float, bool> delegateFunc; + + // Determine which channel to check against + switch (channel) + { + case RgbaComponent.R: + delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().X - b) > Constants.Epsilon; + break; + + case RgbaComponent.G: + delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Y - b) > Constants.Epsilon; + break; + + case RgbaComponent.B: + delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Z - b) > Constants.Epsilon; + break; + + default: + delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().W - b) > Constants.Epsilon; + break; + } + + int GetMinY(ImageFrame pixels) + { + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + if (delegateFunc(pixels, x, y, componentValue)) + { + return y; + } + } + } + + return 0; + } + + int GetMaxY(ImageFrame pixels) + { + for (int y = height - 1; y > -1; y--) + { + for (int x = 0; x < width; x++) + { + if (delegateFunc(pixels, x, y, componentValue)) + { + return y; + } + } + } + + return height; + } + + int GetMinX(ImageFrame pixels) + { + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + if (delegateFunc(pixels, x, y, componentValue)) + { + return x; + } + } + } + + return 0; + } + + int GetMaxX(ImageFrame pixels) + { + for (int x = width - 1; x > -1; x--) + { + for (int y = 0; y < height; y++) + { + if (delegateFunc(pixels, x, y, componentValue)) + { + return x; + } + } + } + + return width; + } + + topLeft.Y = GetMinY(bitmap); + topLeft.X = GetMinX(bitmap); + bottomRight.Y = Numerics.Clamp(GetMaxY(bitmap) + 1, 0, height); + bottomRight.X = Numerics.Clamp(GetMaxX(bitmap) + 1, 0, width); + + return GetBoundingRectangle(topLeft, bottomRight); + } } } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtils.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtils.cs index 07e784ec5..e65b2cbe9 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtils.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtils.cs @@ -78,13 +78,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms // Values are first premultiplied to prevent darkening of edge pixels. var current = sourcePixels[x, y].ToVector4(); - Vector4Utils.Premultiply(ref current); + Numerics.Premultiply(ref current); sum += current * xWeight * yWeight; } } // Reverse the premultiplication - Vector4Utils.UnPremultiply(ref sum); + Numerics.UnPremultiply(ref sum); targetRow[column] = sum; } diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs index d441b5e0b..b88f5090b 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark] public void Premultiply() { - Vector4Utils.Premultiply(Vectors); + Numerics.Premultiply(Vectors); } [MethodImpl(InliningOptions.ShortMethod)] diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs index 819f34b92..aa73bc3d0 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark] public void UnPremultiply() { - Vector4Utils.UnPremultiply(Vectors); + Numerics.UnPremultiply(Vectors); } [MethodImpl(InliningOptions.ShortMethod)] diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index cd5e3a5e4..11bab17fb 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -435,7 +435,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png Rgba32 expectedColor = Color.Blue; if (colorType == PngColorType.Grayscale || colorType == PngColorType.GrayscaleWithAlpha) { - var luminance = ImageMath.Get8BitBT709Luminance(expectedColor.R, expectedColor.G, expectedColor.B); + var luminance = ColorNumerics.Get8BitBT709Luminance(expectedColor.R, expectedColor.G, expectedColor.B); expectedColor = new Rgba32(luminance, luminance, luminance); } diff --git a/tests/ImageSharp.Tests/Helpers/ImageMathTests.cs b/tests/ImageSharp.Tests/Helpers/ColorNumericsTests.cs similarity index 79% rename from tests/ImageSharp.Tests/Helpers/ImageMathTests.cs rename to tests/ImageSharp.Tests/Helpers/ColorNumericsTests.cs index 687c13fd5..7d7f5f15a 100644 --- a/tests/ImageSharp.Tests/Helpers/ImageMathTests.cs +++ b/tests/ImageSharp.Tests/Helpers/ColorNumericsTests.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Helpers { - public class ImageMathTests + public class ColorNumericsTests { [Theory] [InlineData(0.2f, 0.7f, 0.1f, 256, 140)] @@ -20,12 +20,12 @@ namespace SixLabors.ImageSharp.Tests.Helpers var vector = new Vector4(x, y, z, 0.0f); // act - int actual = ImageMath.GetBT709Luminance(ref vector, luminanceLevels); + int actual = ColorNumerics.GetBT709Luminance(ref vector, luminanceLevels); // assert Assert.Equal(expected, actual); } - // TODO: We need to test all ImageMaths methods! + // TODO: We need to test all ColorNumerics methods! } } diff --git a/tests/ImageSharp.Tests/Helpers/NumericsTests.cs b/tests/ImageSharp.Tests/Helpers/NumericsTests.cs index f1678cfa1..98363b751 100644 --- a/tests/ImageSharp.Tests/Helpers/NumericsTests.cs +++ b/tests/ImageSharp.Tests/Helpers/NumericsTests.cs @@ -2,13 +2,17 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Linq; +using System.Numerics; using Xunit; namespace SixLabors.ImageSharp.Tests.Helpers { public class NumericsTests { - public delegate void SpanAction(Span span, TArg arg, TArg1 arg1); + private delegate void SpanAction(Span span, TArg arg, TArg1 arg1); + + private readonly ApproximateFloatComparer approximateFloatComparer = new ApproximateFloatComparer(1e-6f); [Theory] [InlineData(0)] @@ -154,6 +158,46 @@ namespace SixLabors.ImageSharp.Tests.Helpers Assert.Equal(expected, actual); } + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(30)] + [InlineData(63)] + public void PremultiplyVectorSpan(int length) + { + var rnd = new Random(42); + Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1); + Vector4[] expected = source.Select(v => + { + Numerics.Premultiply(ref v); + return v; + }).ToArray(); + + Numerics.Premultiply(source); + + Assert.Equal(expected, source, this.approximateFloatComparer); + } + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(30)] + [InlineData(63)] + public void UnPremultiplyVectorSpan(int length) + { + var rnd = new Random(42); + Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1); + Vector4[] expected = source.Select(v => + { + Numerics.UnPremultiply(ref v); + return v; + }).ToArray(); + + Numerics.UnPremultiply(source); + + Assert.Equal(expected, source, this.approximateFloatComparer); + } + [Theory] [InlineData(64, 36, 96)] [InlineData(128, 16, 196)] diff --git a/tests/ImageSharp.Tests/Helpers/Vector4UtilsTests.cs b/tests/ImageSharp.Tests/Helpers/Vector4UtilsTests.cs deleted file mode 100644 index 605aa7d5a..000000000 --- a/tests/ImageSharp.Tests/Helpers/Vector4UtilsTests.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Linq; -using System.Numerics; - -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Helpers -{ - public class Vector4UtilsTests - { - private readonly ApproximateFloatComparer approximateFloatComparer = new ApproximateFloatComparer(1e-6f); - - [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(30)] - [InlineData(63)] - public void Premultiply_VectorSpan(int length) - { - var rnd = new Random(42); - Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1); - Vector4[] expected = source.Select(v => - { - Vector4Utils.Premultiply(ref v); - return v; - }).ToArray(); - - Vector4Utils.Premultiply(source); - - Assert.Equal(expected, source, this.approximateFloatComparer); - } - - [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(30)] - [InlineData(63)] - public void UnPremultiply_VectorSpan(int length) - { - var rnd = new Random(42); - Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1); - Vector4[] expected = source.Select(v => - { - Vector4Utils.UnPremultiply(ref v); - return v; - }).ToArray(); - - Vector4Utils.UnPremultiply(source); - - Assert.Equal(expected, source, this.approximateFloatComparer); - } - } -} diff --git a/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs b/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs index 113a39bff..453eac568 100644 --- a/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs @@ -113,8 +113,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats // Arrange L16 gray = default; const byte rgb = 128; - ushort scaledRgb = ImageMath.UpscaleFrom8BitTo16Bit(rgb); - ushort expected = ImageMath.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb); + ushort scaledRgb = ColorNumerics.UpscaleFrom8BitTo16Bit(rgb); + ushort expected = ColorNumerics.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb); // Act gray.FromRgba32(new Rgba32(rgb, rgb, rgb)); @@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public void L16_ToRgba32(ushort input) { // Arrange - ushort expected = ImageMath.DownScaleFrom16BitTo8Bit(input); + ushort expected = ColorNumerics.DownScaleFrom16BitTo8Bit(input); var gray = new L16(input); // Act diff --git a/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs b/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs index 798eb3b1a..a0895df12 100644 --- a/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs @@ -136,7 +136,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats { // Arrange L8 gray = default; - byte expected = ImageMath.Get8BitBT709Luminance(rgb, rgb, rgb); + byte expected = ColorNumerics.Get8BitBT709Luminance(rgb, rgb, rgb); // Act gray.FromRgba32(new Rgba32(rgb, rgb, rgb)); diff --git a/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs b/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs index 46d7d09b4..b241adb20 100644 --- a/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs @@ -138,7 +138,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats { // Arrange La16 gray = default; - byte expected = ImageMath.Get8BitBT709Luminance(rgb, rgb, rgb); + byte expected = ColorNumerics.Get8BitBT709Luminance(rgb, rgb, rgb); // Act gray.FromRgba32(new Rgba32(rgb, rgb, rgb)); diff --git a/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs index 159abac4a..6d1b595c7 100644 --- a/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs @@ -117,8 +117,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats // Arrange La32 gray = default; const byte rgb = 128; - ushort scaledRgb = ImageMath.UpscaleFrom8BitTo16Bit(rgb); - ushort expected = ImageMath.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb); + ushort scaledRgb = ColorNumerics.UpscaleFrom8BitTo16Bit(rgb); + ushort expected = ColorNumerics.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb); // Act gray.FromRgba32(new Rgba32(rgb, rgb, rgb)); @@ -136,7 +136,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public void La32_ToRgba32(ushort input) { // Arrange - ushort expected = ImageMath.DownScaleFrom16BitTo8Bit(input); + ushort expected = ColorNumerics.DownScaleFrom16BitTo8Bit(input); var gray = new La32(input, ushort.MaxValue); // Act diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index e56cfe226..0d83e2e7f 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -197,7 +197,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { if (this.HasUnassociatedAlpha) { - Vector4Utils.Premultiply(ref v); + Numerics.Premultiply(ref v); } } @@ -205,7 +205,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { if (this.HasUnassociatedAlpha) { - Vector4Utils.UnPremultiply(ref v); + Numerics.UnPremultiply(ref v); } } @@ -232,7 +232,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { if (this.HasUnassociatedAlpha) { - Vector4Utils.Premultiply(ref v); + Numerics.Premultiply(ref v); } } @@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { if (this.HasUnassociatedAlpha) { - Vector4Utils.UnPremultiply(ref v); + Numerics.UnPremultiply(ref v); } } @@ -273,7 +273,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations if (this.HasUnassociatedAlpha) { - Vector4Utils.Premultiply(ref v); + Numerics.Premultiply(ref v); } } @@ -281,7 +281,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { if (this.HasUnassociatedAlpha) { - Vector4Utils.UnPremultiply(ref v); + Numerics.UnPremultiply(ref v); } SRgbCompanding.Compress(ref v); @@ -394,12 +394,12 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { void SourceAction(ref Vector4 v) { - Vector4Utils.UnPremultiply(ref v); + Numerics.UnPremultiply(ref v); } void ExpectedAction(ref Vector4 v) { - Vector4Utils.Premultiply(ref v); + Numerics.Premultiply(ref v); } TPixel[] source = CreatePixelTestData(count, (ref Vector4 v) => SourceAction(ref v)); @@ -417,12 +417,12 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { void SourceAction(ref Vector4 v) { - Vector4Utils.UnPremultiply(ref v); + Numerics.UnPremultiply(ref v); } void ExpectedAction(ref Vector4 v) { - Vector4Utils.Premultiply(ref v); + Numerics.Premultiply(ref v); } TPixel[] source = CreateScaledPixelTestData(count, (ref Vector4 v) => SourceAction(ref v)); @@ -444,14 +444,14 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { void SourceAction(ref Vector4 v) { - Vector4Utils.UnPremultiply(ref v); + Numerics.UnPremultiply(ref v); SRgbCompanding.Compress(ref v); } void ExpectedAction(ref Vector4 v) { SRgbCompanding.Expand(ref v); - Vector4Utils.Premultiply(ref v); + Numerics.Premultiply(ref v); } TPixel[] source = CreateScaledPixelTestData(count, (ref Vector4 v) => SourceAction(ref v)); From a5e969466747fe87fde8b802c945d34786afd848 Mon Sep 17 00:00:00 2001 From: Evangelink Date: Tue, 24 Nov 2020 15:05:09 +0100 Subject: [PATCH 26/39] More progress toward a working swizzler --- .../Processors/Transforms/ISwizzler.cs | 9 +++-- .../SwizzleProcessor{TSwizzler,TPixel}.cs | 21 +++++++---- .../Transforms/SwizzleProcessor{TSwizzler}.cs | 6 ++-- .../Processors/Transforms/SwizzleTests.cs | 35 +++++++++++++++++++ .../Processing/Transforms/SwizzleTests.cs | 18 +++++++--- 5 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs diff --git a/src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs b/src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs index 0230b7a86..075ea2d52 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs @@ -8,11 +8,16 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// public interface ISwizzler { + /// + /// Gets the size of the image after transformation. + /// + Size DestinationSize { get; } + /// /// Applies the swizzle transformation to a given point. /// /// Point to transform. - /// Transformed point. - Point Transform(Point point); + /// The transformed point. + void Transform(Point point, out Point newPoint); } } diff --git a/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs index a42a4bf77..c9b9b4570 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs @@ -1,31 +1,38 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Transforms { - internal class SwizzleProcessor : ImageProcessor + internal class SwizzleProcessor : TransformProcessor where TSwizzler : struct, ISwizzler where TPixel : unmanaged, IPixel { private readonly TSwizzler swizzler; + private readonly Size destinationSize; public SwizzleProcessor(Configuration configuration, TSwizzler swizzler, Image source, Rectangle sourceRectangle) : base(configuration, source, sourceRectangle) { this.swizzler = swizzler; + this.destinationSize = swizzler.DestinationSize; } - /// - protected override void OnFrameApply(ImageFrame source) + protected override Size GetDestinationSize() + => this.destinationSize; + + protected override void OnFrameApply(ImageFrame source, ImageFrame destination) { - for (int y = 0; y < source.Height; y++) + Point p = default; + Point newPoint; + for (p.Y = 0; p.Y < source.Height; p.Y++) { - var pixelRowSpan = source.GetPixelRowSpan(y); - for (int x = 0; x < source.Width; x++) + for (p.X = 0; p.X < source.Width; p.X++) { - var newPoint = this.swizzler.Transform(new Point(x, y)); + this.swizzler.Transform(p, out newPoint); + destination[newPoint.X, newPoint.Y] = source[p.X, p.Y]; } } } diff --git a/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler}.cs b/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler}.cs index e5b95e673..d48257334 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler}.cs @@ -17,7 +17,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// /// The swizzler operation. public SwizzleProcessor(TSwizzler swizzler) - => this.Swizzler = swizzler; + { + this.Swizzler = swizzler; + } /// /// Gets the swizzler operation. @@ -27,6 +29,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// public IImageProcessor CreatePixelSpecificProcessor(Configuration configuration, Image source, Rectangle sourceRectangle) where TPixel : unmanaged, IPixel - => new SwizzleProcessor(configuration, this, source, sourceRectangle); + => new SwizzleProcessor(configuration, this.Swizzler, source, sourceRectangle); } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs new file mode 100644 index 000000000..b951a7fb0 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs @@ -0,0 +1,35 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Extensions.Transforms; +using SixLabors.ImageSharp.Processing.Processors.Transforms; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms +{ + [GroupOutput("Transforms")] + public class SwizzleTests + { + private struct InvertXAndYSwizzler : ISwizzler + { + public Size DestinationSize => new Size(10, 10); + + public void Transform(Point point, out Point newPoint) + => newPoint = new Point(point.Y, point.X); + } + + [Theory] + [WithTestPatternImages(20, 37, PixelTypes.Rgba32)] + [WithTestPatternImages(53, 37, PixelTypes.Byte4)] + [WithTestPatternImages(17, 32, PixelTypes.Rgba32)] + public void InvertXAndYSwizzle(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + provider.RunValidatingProcessorTest( + ctx => ctx.Swizzle(default(InvertXAndYSwizzler)), + testOutputDetails: nameof(InvertXAndYSwizzler), + appendPixelTypeToFileName: false); + } + } +} diff --git a/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs index 2862df212..c54bfa25e 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs @@ -11,21 +11,29 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { private struct InvertXAndYSwizzler : ISwizzler { - public Point Transform(Point point) => new Point(point.Y, point.X); + public Size DestinationSize => new Size(10, 10); + + public void Transform(Point point, out Point newPoint) + => newPoint = new Point(point.Y, point.X); } [Fact] - public void RotateDegreesFloatRotateProcessorWithAnglesSet() + public void InvertXAndYSwizzlerSetsCorrectSizes() { + int width = 5; + int height = 10; + this.operations.Swizzle(default(InvertXAndYSwizzler)); SwizzleProcessor processor = this.Verify>(); - // assert that pixels have been changed + Assert.Equal(processor.Swizzler.DestinationSize.Width, height); + Assert.Equal(processor.Swizzler.DestinationSize.Height, width); this.operations.Swizzle(default(InvertXAndYSwizzler)); - SwizzleProcessor processor2 = this.Verify>(); + SwizzleProcessor processor2 = this.Verify>(1); - // assert that pixels have been changed (i.e. back to original) + Assert.Equal(processor2.Swizzler.DestinationSize.Width, width); + Assert.Equal(processor2.Swizzler.DestinationSize.Height, height); } } } From e9738f21eb964fb7a1d0db23c2a3f6c8336dd18d Mon Sep 17 00:00:00 2001 From: Evangelink Date: Tue, 24 Nov 2020 15:38:55 +0100 Subject: [PATCH 27/39] Fix unit test --- .../Processing/Transforms/SwizzleTests.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs index c54bfa25e..9c2701ae7 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs @@ -11,7 +11,12 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { private struct InvertXAndYSwizzler : ISwizzler { - public Size DestinationSize => new Size(10, 10); + public InvertXAndYSwizzler(Size sourceSize) + { + this.DestinationSize = new Size(sourceSize.Height, sourceSize.Width); + } + + public Size DestinationSize { get; } public void Transform(Point point, out Point newPoint) => newPoint = new Point(point.Y, point.X); @@ -23,13 +28,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms int width = 5; int height = 10; - this.operations.Swizzle(default(InvertXAndYSwizzler)); + this.operations.Swizzle(new InvertXAndYSwizzler(new Size(width, height))); SwizzleProcessor processor = this.Verify>(); Assert.Equal(processor.Swizzler.DestinationSize.Width, height); Assert.Equal(processor.Swizzler.DestinationSize.Height, width); - this.operations.Swizzle(default(InvertXAndYSwizzler)); + this.operations.Swizzle(new InvertXAndYSwizzler(processor.Swizzler.DestinationSize)); SwizzleProcessor processor2 = this.Verify>(1); Assert.Equal(processor2.Swizzler.DestinationSize.Width, width); From a665bce50e370effd28ec92ee34e15c5d2dd78dd Mon Sep 17 00:00:00 2001 From: Evangelink Date: Tue, 24 Nov 2020 15:55:59 +0100 Subject: [PATCH 28/39] Update integration tests --- .../Processing/Processors/Transforms/SwizzleTests.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs index b951a7fb0..4d3b60494 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs @@ -13,7 +13,12 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { private struct InvertXAndYSwizzler : ISwizzler { - public Size DestinationSize => new Size(10, 10); + public InvertXAndYSwizzler(Size sourceSize) + { + this.DestinationSize = new Size(sourceSize.Height, sourceSize.Width); + } + + public Size DestinationSize { get; } public void Transform(Point point, out Point newPoint) => newPoint = new Point(point.Y, point.X); @@ -26,8 +31,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public void InvertXAndYSwizzle(TestImageProvider provider) where TPixel : unmanaged, IPixel { + Image image = provider.GetImage(); provider.RunValidatingProcessorTest( - ctx => ctx.Swizzle(default(InvertXAndYSwizzler)), + ctx => ctx.Swizzle(new InvertXAndYSwizzler(new Size(image.Width, image.Height))), testOutputDetails: nameof(InvertXAndYSwizzler), appendPixelTypeToFileName: false); } From 9d72a840d2cd0fec9e2c5937953a769d60425f72 Mon Sep 17 00:00:00 2001 From: AlexNDRmac Date: Tue, 24 Nov 2020 21:45:47 +0200 Subject: [PATCH 29/39] Add cache for Nuget packages --- .github/workflows/build-and-test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index b618e1e65..823158e0c 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -56,6 +56,14 @@ jobs: git fetch --prune --unshallow git submodule -q update --init --recursive + - name: Setup nuget cache + uses: actions/cache@v2 + id: nuget-cache + with: + path: ~/.nuget + key: ${{ runner.os }}-nuget-${{ hashFiles('**/ImageSharp*.csproj') }} + restore-keys: ${{ runner.os }}-nuget- + - name: Build shell: pwsh run: ./ci-build.ps1 "${{matrix.options.framework}}" From a0bf4e331ca62888781b152edb255abc721c367a Mon Sep 17 00:00:00 2001 From: AlexNDRmac Date: Tue, 24 Nov 2020 22:08:13 +0200 Subject: [PATCH 30/39] Add props and targets to hash for cache key --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 823158e0c..402319c26 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -61,7 +61,7 @@ jobs: id: nuget-cache with: path: ~/.nuget - key: ${{ runner.os }}-nuget-${{ hashFiles('**/ImageSharp*.csproj') }} + key: ${{ runner.os }}-nuget-${{ hashFiles('**/ImageSharp*.csproj', '**/*.props', '**/*.targets') }} restore-keys: ${{ runner.os }}-nuget- - name: Build From 41ed93cbebe4c3ef8831bf6eb26a6816a9c3a6c2 Mon Sep 17 00:00:00 2001 From: AlexNDRmac Date: Tue, 24 Nov 2020 22:17:10 +0200 Subject: [PATCH 31/39] Fix file pattern for hashFiles --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 402319c26..04b1d745f 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -61,7 +61,7 @@ jobs: id: nuget-cache with: path: ~/.nuget - key: ${{ runner.os }}-nuget-${{ hashFiles('**/ImageSharp*.csproj', '**/*.props', '**/*.targets') }} + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.props', '**/*.targets') }} restore-keys: ${{ runner.os }}-nuget- - name: Build From 14129427519ac33a9fe7188c40473577f13c4907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 26 Nov 2020 09:36:38 +0100 Subject: [PATCH 32/39] Apply suggested change for test Avoid relying on the submodule change by implementing the invert swizzle operation --- .../Processors/Transforms/SwizzleTests.cs | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs index 4d3b60494..97b6a6414 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs @@ -2,8 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Extensions.Transforms; using SixLabors.ImageSharp.Processing.Processors.Transforms; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms @@ -31,11 +33,26 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public void InvertXAndYSwizzle(TestImageProvider provider) where TPixel : unmanaged, IPixel { - Image image = provider.GetImage(); - provider.RunValidatingProcessorTest( - ctx => ctx.Swizzle(new InvertXAndYSwizzler(new Size(image.Width, image.Height))), - testOutputDetails: nameof(InvertXAndYSwizzler), - appendPixelTypeToFileName: false); + using Image expectedImage = provider.GetImage(); + using Image image = provider.GetImage(); + + image.Mutate(ctx => ctx.Swizzle(new InvertXAndYSwizzler(new Size(image.Width, image.Height)))); + + image.DebugSave( + provider, + nameof(InvertXAndYSwizzler), + appendPixelTypeToFileName: false, + appendSourceFileOrDescription: true); + + image.Mutate(ctx => ctx.Swizzle(new InvertXAndYSwizzler(new Size(image.Width, image.Height)))); + + image.DebugSave( + provider, + "Unswizzle", + appendPixelTypeToFileName: false, + appendSourceFileOrDescription: true); + + ImageComparer.Exact.VerifySimilarity(expectedImage, image); } } } From ea7c8a157dcf90c85ff2a261dee541f372c8642d Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 26 Nov 2020 11:12:19 +0100 Subject: [PATCH 33/39] Ensure Span length of source and destination are equal during pixel conversions. --- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 01bdbd1c0..7819b1ebd 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -262,7 +262,9 @@ namespace SixLabors.ImageSharp.Formats.Bmp private void Write24Bit(Stream stream, Buffer2D pixels) where TPixel : unmanaged, IPixel { - using (IManagedByteBuffer row = this.AllocateRow(pixels.Width, 3)) + int width = pixels.Width; + int rowBytesWithoutPadding = width * 3; + using (IManagedByteBuffer row = this.AllocateRow(width, 3)) { for (int y = pixels.Height - 1; y >= 0; y--) { @@ -270,8 +272,8 @@ namespace SixLabors.ImageSharp.Formats.Bmp PixelOperations.Instance.ToBgr24Bytes( this.configuration, pixelSpan, - row.GetSpan(), - pixelSpan.Length); + row.Slice(0, rowBytesWithoutPadding), + width); stream.Write(row.Array, 0, row.Length()); } } @@ -286,7 +288,9 @@ namespace SixLabors.ImageSharp.Formats.Bmp private void Write16Bit(Stream stream, Buffer2D pixels) where TPixel : unmanaged, IPixel { - using (IManagedByteBuffer row = this.AllocateRow(pixels.Width, 2)) + int width = pixels.Width; + int rowBytesWithoutPadding = width * 2; + using (IManagedByteBuffer row = this.AllocateRow(width, 2)) { for (int y = pixels.Height - 1; y >= 0; y--) { @@ -295,7 +299,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp PixelOperations.Instance.ToBgra5551Bytes( this.configuration, pixelSpan, - row.GetSpan(), + row.Slice(0, rowBytesWithoutPadding), pixelSpan.Length); stream.Write(row.Array, 0, row.Length()); @@ -341,7 +345,8 @@ namespace SixLabors.ImageSharp.Formats.Bmp using IndexedImageFrame quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(image, image.Bounds()); ReadOnlySpan quantizedColors = quantized.Palette.Span; - PixelOperations.Instance.ToBgra32(this.configuration, quantizedColors, MemoryMarshal.Cast(colorPalette)); + var quantizedColorBytes = quantizedColors.Length * 4; + PixelOperations.Instance.ToBgra32(this.configuration, quantizedColors, MemoryMarshal.Cast(colorPalette.Slice(0, quantizedColorBytes))); Span colorPaletteAsUInt = MemoryMarshal.Cast(colorPalette); for (int i = 0; i < colorPaletteAsUInt.Length; i++) { From e687f7b10acdd13facceb3e80d2d0cb0fdfb5b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 26 Nov 2020 23:12:33 +0100 Subject: [PATCH 34/39] Address review comments --- src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs | 4 ++-- .../Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs b/src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs index 075ea2d52..efa3e35a4 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ISwizzler.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// Applies the swizzle transformation to a given point. /// /// Point to transform. - /// The transformed point. - void Transform(Point point, out Point newPoint); + /// The transformed point. + Point Transform(Point point); } } diff --git a/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs index c9b9b4570..aab17d292 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs @@ -29,10 +29,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms Point newPoint; for (p.Y = 0; p.Y < source.Height; p.Y++) { + Span rowSpan = source.GetPixelRowSpan(p.Y); for (p.X = 0; p.X < source.Width; p.X++) { - this.swizzler.Transform(p, out newPoint); - destination[newPoint.X, newPoint.Y] = source[p.X, p.Y]; + newPoint = this.swizzler.Transform(p); + destination[newPoint.X, newPoint.Y] = rowSpan[p.X]; } } } From 1547379bdd95974b8e756f6ce8f60c9c215e4f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 26 Nov 2020 23:25:36 +0100 Subject: [PATCH 35/39] Forgot to commit tests --- .../Processing/Processors/Transforms/SwizzleTests.cs | 4 ++-- tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs index 97b6a6414..f508744fa 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SwizzleTests.cs @@ -22,8 +22,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public Size DestinationSize { get; } - public void Transform(Point point, out Point newPoint) - => newPoint = new Point(point.Y, point.X); + public Point Transform(Point point) + => new Point(point.Y, point.X); } [Theory] diff --git a/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs index 9c2701ae7..cde6aeca3 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/SwizzleTests.cs @@ -18,8 +18,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms public Size DestinationSize { get; } - public void Transform(Point point, out Point newPoint) - => newPoint = new Point(point.Y, point.X); + public Point Transform(Point point) + => new Point(point.Y, point.X); } [Fact] From c71f9e3393ec74ae95478b4f9f87cce3ebc6f874 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 27 Nov 2020 17:12:49 +0100 Subject: [PATCH 36/39] Reduce code duplication due to reified generics --- .../Convolution/BokehBlurProcessor.cs | 56 +++++++++++++++++++ .../Convolution/BokehBlurProcessor{TPixel}.cs | 50 +---------------- 2 files changed, 58 insertions(+), 48 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs index 8a4c703e0..352960f41 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs @@ -1,6 +1,11 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Convolution @@ -77,5 +82,56 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution public IImageProcessor CreatePixelSpecificProcessor(Configuration configuration, Image source, Rectangle sourceRectangle) where TPixel : unmanaged, IPixel => new BokehBlurProcessor(configuration, this, source, sourceRectangle); + + /// + /// A implementing the horizontal convolution logic for . + /// + /// + /// This type is located in the non-generic class and not in , where + /// it is actually used, because it does not use any generic parameters internally. Defining in a non-generic class means that there will only + /// ever be a single instantiation of this type for the JIT/AOT compilers to process, instead of having duplicate versions for each pixel type. + /// + internal readonly struct ApplyHorizontalConvolutionRowOperation : IRowOperation + { + private readonly Rectangle bounds; + private readonly Buffer2D targetValues; + private readonly Buffer2D sourceValues; + private readonly Complex64[] kernel; + private readonly float z; + private readonly float w; + private readonly int maxY; + private readonly int maxX; + + [MethodImpl(InliningOptions.ShortMethod)] + public ApplyHorizontalConvolutionRowOperation( + Rectangle bounds, + Buffer2D targetValues, + Buffer2D sourceValues, + Complex64[] kernel, + float z, + float w) + { + this.bounds = bounds; + this.maxY = this.bounds.Bottom - 1; + this.maxX = this.bounds.Right - 1; + this.targetValues = targetValues; + this.sourceValues = sourceValues; + this.kernel = kernel; + this.z = z; + this.w = w; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void Invoke(int y) + { + Span targetRowSpan = this.targetValues.GetRowSpan(y).Slice(this.bounds.X); + + for (int x = 0; x < this.bounds.Width; x++) + { + Buffer2DUtils.Convolve4AndAccumulatePartials(this.kernel, this.sourceValues, targetRowSpan, y, x, this.bounds.Y, this.maxY, this.bounds.X, this.maxX, this.z, this.w); + } + } + } } } diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs index cf5367343..dfe54bf2e 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs @@ -127,7 +127,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution in verticalOperation); // Compute the horizontal 1D convolutions and accumulate the partial results on the target buffer - var horizontalOperation = new ApplyHorizontalConvolutionRowOperation(sourceRectangle, processingBuffer, firstPassBuffer, kernel, parameters.Z, parameters.W); + var horizontalOperation = new BokehBlurProcessor.ApplyHorizontalConvolutionRowOperation(sourceRectangle, processingBuffer, firstPassBuffer, kernel, parameters.Z, parameters.W); ParallelRowIterator.IterateRows( configuration, sourceRectangle, @@ -175,52 +175,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution } } - /// - /// A implementing the horizontal convolution logic for . - /// - private readonly struct ApplyHorizontalConvolutionRowOperation : IRowOperation - { - private readonly Rectangle bounds; - private readonly Buffer2D targetValues; - private readonly Buffer2D sourceValues; - private readonly Complex64[] kernel; - private readonly float z; - private readonly float w; - private readonly int maxY; - private readonly int maxX; - - [MethodImpl(InliningOptions.ShortMethod)] - public ApplyHorizontalConvolutionRowOperation( - Rectangle bounds, - Buffer2D targetValues, - Buffer2D sourceValues, - Complex64[] kernel, - float z, - float w) - { - this.bounds = bounds; - this.maxY = this.bounds.Bottom - 1; - this.maxX = this.bounds.Right - 1; - this.targetValues = targetValues; - this.sourceValues = sourceValues; - this.kernel = kernel; - this.z = z; - this.w = w; - } - - /// - [MethodImpl(InliningOptions.ShortMethod)] - public void Invoke(int y) - { - Span targetRowSpan = this.targetValues.GetRowSpan(y).Slice(this.bounds.X); - - for (int x = 0; x < this.bounds.Width; x++) - { - Buffer2DUtils.Convolve4AndAccumulatePartials(this.kernel, this.sourceValues, targetRowSpan, y, x, this.bounds.Y, this.maxY, this.bounds.X, this.maxX, this.z, this.w); - } - } - } - /// /// A implementing the gamma exposure logic for . /// @@ -304,7 +258,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution for (int x = 0; x < this.bounds.Width; x++) { ref Vector4 v = ref Unsafe.Add(ref sourceRef, x); - var clamp = Numerics.Clamp(v, low, high); + Vector4 clamp = Numerics.Clamp(v, low, high); v.X = MathF.Pow(clamp.X, this.inverseGamma); v.Y = MathF.Pow(clamp.Y, this.inverseGamma); v.Z = MathF.Pow(clamp.Z, this.inverseGamma); From 9323852f218abd7e7f72aa5d3910668219c76e06 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 29 Nov 2020 14:55:49 +0100 Subject: [PATCH 37/39] Slice destination to (0, count) --- .../PixelOperations{TPixel}.Generated.cs | 48 +++++++++---------- .../PixelOperations{TPixel}.Generated.tt | 4 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs index cc36c7d13..7919eb978 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromArgb32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromArgb32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromArgb32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToArgb32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgr24Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgr24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromBgr24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgr24Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgr24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToBgr24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -187,7 +187,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgra32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgra32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromBgra32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -223,7 +223,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgra32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgra32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToBgra32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -259,7 +259,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromL8Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromL8(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromL8(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -295,7 +295,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToL8Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToL8(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToL8(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -331,7 +331,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromL16Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromL16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromL16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -367,7 +367,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToL16Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToL16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToL16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -403,7 +403,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromLa16Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromLa16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromLa16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -439,7 +439,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToLa16Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToLa16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToLa16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -475,7 +475,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromLa32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromLa32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromLa32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -511,7 +511,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToLa32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToLa32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToLa32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -547,7 +547,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgb24Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgb24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromRgb24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -583,7 +583,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgb24Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgb24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToRgb24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -619,7 +619,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgba32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgba32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromRgba32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -655,7 +655,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgba32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgba32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToRgba32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -691,7 +691,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgb48Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgb48(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromRgb48(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -727,7 +727,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgb48Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgb48(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToRgb48(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -763,7 +763,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgba64Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgba64(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromRgba64(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -799,7 +799,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgba64Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -835,7 +835,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgra5551Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgra5551(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromBgra5551(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -871,7 +871,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgra5551Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } } } diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt index 21ed328fa..75f884774 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt @@ -48,7 +48,7 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public void From<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.From<#=pixelType#>(configuration, MemoryMarshal.Cast>(sourceBytes).Slice(0, count), destinationPixels); + this.From<#=pixelType#>(configuration, MemoryMarshal.Cast>(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } <# @@ -90,7 +90,7 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public void To<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.To<#=pixelType#>(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast>(destBytes)); + this.To<#=pixelType#>(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast>(destBytes.Slice(0, count))); } <# } From 74b2e359c1414d1720567ac27e9b248c3f91a766 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 29 Nov 2020 15:56:41 +0100 Subject: [PATCH 38/39] Revert "Slice destination to (0, count)" This reverts commit 3fba6f81edd9297cd44ffffcc4a7a79cf0b76021. --- .../PixelOperations{TPixel}.Generated.cs | 48 +++++++++---------- .../PixelOperations{TPixel}.Generated.tt | 4 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs index 7919eb978..cc36c7d13 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromArgb32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromArgb32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromArgb32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToArgb32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgr24Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgr24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromBgr24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgr24Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgr24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToBgr24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -187,7 +187,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgra32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgra32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromBgra32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -223,7 +223,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgra32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgra32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToBgra32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -259,7 +259,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromL8Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromL8(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromL8(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -295,7 +295,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToL8Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToL8(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToL8(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -331,7 +331,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromL16Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromL16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromL16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -367,7 +367,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToL16Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToL16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToL16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -403,7 +403,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromLa16Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromLa16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromLa16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -439,7 +439,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToLa16Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToLa16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToLa16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -475,7 +475,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromLa32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromLa32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromLa32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -511,7 +511,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToLa32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToLa32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToLa32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -547,7 +547,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgb24Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgb24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromRgb24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -583,7 +583,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgb24Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgb24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToRgb24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -619,7 +619,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgba32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgba32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromRgba32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -655,7 +655,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgba32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgba32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToRgba32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -691,7 +691,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgb48Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgb48(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromRgb48(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -727,7 +727,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgb48Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgb48(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToRgb48(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -763,7 +763,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgba64Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgba64(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromRgba64(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -799,7 +799,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgba64Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -835,7 +835,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgra5551Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgra5551(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromBgra5551(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -871,7 +871,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgra5551Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } } } diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt index 75f884774..21ed328fa 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt @@ -48,7 +48,7 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public void From<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.From<#=pixelType#>(configuration, MemoryMarshal.Cast>(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.From<#=pixelType#>(configuration, MemoryMarshal.Cast>(sourceBytes).Slice(0, count), destinationPixels); } <# @@ -90,7 +90,7 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public void To<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.To<#=pixelType#>(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast>(destBytes.Slice(0, count))); + this.To<#=pixelType#>(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast>(destBytes)); } <# } From 2fd1aa12cb05b7bd41c180ad089a655f4bfc29af Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 29 Nov 2020 16:27:11 +0100 Subject: [PATCH 39/39] Another attempt using Slice for the destination in PixelOperations convert From and To --- .../Argb32.PixelOperations.Generated.cs | 22 ++++--------------- .../Bgr24.PixelOperations.Generated.cs | 22 ++++--------------- .../Bgra32.PixelOperations.Generated.cs | 22 ++++--------------- .../Bgra5551.PixelOperations.Generated.cs | 21 ++++-------------- .../L16.PixelOperations.Generated.cs | 21 ++++-------------- .../Generated/L8.PixelOperations.Generated.cs | 21 ++++-------------- .../La16.PixelOperations.Generated.cs | 21 ++++-------------- .../La32.PixelOperations.Generated.cs | 21 ++++-------------- .../Rgb24.PixelOperations.Generated.cs | 22 ++++--------------- .../Rgb48.PixelOperations.Generated.cs | 21 ++++-------------- .../Rgba32.PixelOperations.Generated.cs | 21 ++++-------------- .../Rgba64.PixelOperations.Generated.cs | 21 ++++-------------- .../Generated/_Common.ttinclude | 6 ++--- 13 files changed, 51 insertions(+), 211 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs index 9df708d44..cedd1762d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromArgb32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void FromVector4Destructive( Configuration configuration, @@ -59,7 +57,6 @@ namespace SixLabors.ImageSharp.PixelFormats { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToArgb32(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -115,7 +111,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToArgb32(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -143,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToArgb32(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -171,7 +165,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToArgb32(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToArgb32(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToArgb32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs index a66a6e12c..c98e35656 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromBgr24(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void FromVector4Destructive( Configuration configuration, @@ -59,7 +57,6 @@ namespace SixLabors.ImageSharp.PixelFormats { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgr24(source, dest); } - /// public override void ToArgb32( Configuration configuration, @@ -115,7 +111,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgr24(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -143,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToBgr24(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -171,7 +165,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToBgr24(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToBgr24(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToBgr24(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs index 77b665a4c..02bb67532 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromBgra32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void FromVector4Destructive( Configuration configuration, @@ -59,7 +57,6 @@ namespace SixLabors.ImageSharp.PixelFormats { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgra32(source, dest); } - /// public override void ToArgb32( Configuration configuration, @@ -115,7 +111,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgra32(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -143,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToBgra32(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -171,7 +165,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToBgra32(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToBgra32(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToBgra32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs index 1d13722e4..a02ffc3a4 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromBgra5551(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToBgra5551(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToBgra5551(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs index 03b84be5d..954ef2d98 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromL16(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToL16(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToL16(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs index f52e77b1a..b3d809de5 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromL8(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToL16( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToL8(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToL8(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs index e01399b8a..14618d026 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromLa16(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToLa16(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToLa16(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs index 0aa2afef5..9620a1df4 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromLa32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToLa32(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToLa32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs index a9303f9d8..2fe7f3c20 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromRgb24(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void FromVector4Destructive( Configuration configuration, @@ -59,7 +57,6 @@ namespace SixLabors.ImageSharp.PixelFormats { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToRgb24(source, dest); } - /// public override void ToArgb32( Configuration configuration, @@ -115,7 +111,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgb24(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -143,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgb24(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -171,7 +165,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToRgb24(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToRgb24(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToRgb24(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs index 30328366d..031008fe1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromRgb48(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToRgb48(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToRgb48(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs index c23198e76..16f96d2da 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromRgba32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -67,7 +65,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgba32(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -95,7 +92,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgba32(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -123,7 +119,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToRgba32(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -151,7 +146,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToRgba32(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -172,7 +166,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -193,7 +186,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -214,7 +206,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -235,7 +226,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -256,7 +246,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -277,7 +266,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -298,14 +286,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToRgba32(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToRgba32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs index 129e9ff0b..1f1571e91 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromRgba64(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToRgba64(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToRgba64(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude index 7c2eccedc..784ecf6fb 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude @@ -57,7 +57,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils; ReadOnlySpan sourcePixels, Span<<#=pixelType#>> destinationPixels) { - PixelOperations.Instance.To<#=pixelType#>(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.To<#=pixelType#>(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } <#+ @@ -72,7 +72,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils; Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -81,7 +81,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils; Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } <#+ }