Browse Source

Merge remote-tracking branch 'origin/master' into tiff-format

pull/1570/head
Brian Popow 5 years ago
parent
commit
e7b77e3a9e
  1. 8
      .github/workflows/build-and-test.yml
  2. 1
      .gitignore
  3. 14
      src/ImageSharp/Color/Color.cs
  4. 2
      src/ImageSharp/ColorSpaces/Cmyk.cs
  5. 2
      src/ImageSharp/ColorSpaces/Companding/LCompanding.cs
  6. 6
      src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs
  7. 6
      src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs
  8. 2
      src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs
  9. 140
      src/ImageSharp/Common/Extensions/ComparableExtensions.cs
  10. 8
      src/ImageSharp/Common/Helpers/Buffer2DUtils.cs
  11. 177
      src/ImageSharp/Common/Helpers/ColorNumerics.cs
  12. 20
      src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
  13. 379
      src/ImageSharp/Common/Helpers/ImageMaths.cs
  14. 551
      src/ImageSharp/Common/Helpers/Numerics.cs
  15. 2
      src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs
  16. 4
      src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs
  17. 4
      src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
  18. 6
      src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs
  19. 24
      src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs
  20. 8
      src/ImageSharp/Common/Helpers/SimdUtils.cs
  21. 181
      src/ImageSharp/Common/Helpers/Vector4Utilities.cs
  22. 4
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  23. 17
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
  24. 6
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  25. 32
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs
  26. 2
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt
  27. 2
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
  28. 4
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
  29. 19
      src/ImageSharp/Formats/PixelTypeInfo.cs
  30. 8
      src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
  31. 14
      src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
  32. 4
      src/ImageSharp/Formats/Png/Filters/SubFilter.cs
  33. 2
      src/ImageSharp/Formats/Png/Filters/UpFilter.cs
  34. 6
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  35. 4
      src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
  36. 4
      src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
  37. 2
      src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
  38. 56
      src/ImageSharp/ImageSharp.csproj
  39. 2
      src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.cs
  40. 10
      src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs
  41. 6
      src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs
  42. 10
      src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs
  43. 2
      src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs
  44. 32
      src/ImageSharp/PixelFormats/PixelAlphaRepresentation.cs
  45. 648
      src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
  46. 6
      src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt
  47. 216
      src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs
  48. 2
      src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt
  49. 8
      src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
  50. 22
      src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
  51. 16
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
  52. 4
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
  53. 22
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
  54. 6
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
  55. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
  56. 6
      src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
  57. 4
      src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
  58. 6
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
  59. 4
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
  60. 54
      src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
  61. 34
      src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
  62. 38
      src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
  63. 64
      src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
  64. 4
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
  65. 6
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
  66. 4
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
  67. 6
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
  68. 26
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs
  69. 26
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs
  70. 26
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs
  71. 26
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs
  72. 26
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs
  73. 26
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs
  74. 26
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs
  75. 26
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs
  76. 72
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs
  77. 5
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.tt
  78. 72
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs
  79. 5
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.tt
  80. 72
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs
  81. 5
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.tt
  82. 82
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs
  83. 3
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.tt
  84. 84
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs
  85. 5
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.tt
  86. 84
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs
  87. 5
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.tt
  88. 82
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs
  89. 3
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.tt
  90. 82
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs
  91. 3
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.tt
  92. 73
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs
  93. 5
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.tt
  94. 84
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs
  95. 5
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.tt
  96. 58
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs
  97. 3
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.tt
  98. 84
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs
  99. 5
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.tt
  100. 70
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude

8
.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('**/*.csproj', '**/*.props', '**/*.targets') }}
restore-keys: ${{ runner.os }}-nuget-
- name: Build
shell: pwsh
run: ./ci-build.ps1 "${{matrix.options.framework}}"

1
.gitignore

@ -221,3 +221,4 @@ artifacts/
# Tests
**/Images/ActualOutput
**/Images/ReferenceOutput
.DS_Store

14
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));
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(
ImageMaths.UpscaleFrom8BitTo16Bit(r),
ImageMaths.UpscaleFrom8BitTo16Bit(g),
ImageMaths.UpscaleFrom8BitTo16Bit(b),
ColorNumerics.UpscaleFrom8BitTo16Bit(r),
ColorNumerics.UpscaleFrom8BitTo16Bit(g),
ColorNumerics.UpscaleFrom8BitTo16Bit(b),
ushort.MaxValue);
}

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

2
src/ImageSharp/ColorSpaces/Companding/LCompanding.cs

@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Companding
/// <returns>The <see cref="float"/> representing the linear channel value.</returns>
[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);
/// <summary>
/// Compresses an uncompanded channel (linear) to its nonlinear equivalent.

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

6
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));
}
}
}

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

140
src/ImageSharp/Common/Extensions/ComparableExtensions.cs

@ -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
{
/// <summary>
/// Extension methods for classes that implement <see cref="IComparable{T}"/>.
/// </summary>
internal static class ComparableExtensions
{
/// <summary>
/// Restricts a <see cref="byte"/> to be within a specified range.
/// </summary>
/// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum value. If value is less than min, min will be returned.</param>
/// <param name="max">The maximum value. If value is greater than max, max will be returned.</param>
/// <returns>
/// The <see cref="byte"/> representing the clamped value.
/// </returns>
[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;
}
/// <summary>
/// Restricts a <see cref="uint"/> to be within a specified range.
/// </summary>
/// <param name="value">The The value to clamp.</param>
/// <param name="min">The minimum value. If value is less than min, min will be returned.</param>
/// <param name="max">The maximum value. If value is greater than max, max will be returned.</param>
/// <returns>
/// The <see cref="int"/> representing the clamped value.
/// </returns>
[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;
}
/// <summary>
/// Restricts a <see cref="int"/> to be within a specified range.
/// </summary>
/// <param name="value">The The value to clamp.</param>
/// <param name="min">The minimum value. If value is less than min, min will be returned.</param>
/// <param name="max">The maximum value. If value is greater than max, max will be returned.</param>
/// <returns>
/// The <see cref="int"/> representing the clamped value.
/// </returns>
[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;
}
/// <summary>
/// Restricts a <see cref="float"/> to be within a specified range.
/// </summary>
/// <param name="value">The The value to clamp.</param>
/// <param name="min">The minimum value. If value is less than min, min will be returned.</param>
/// <param name="max">The maximum value. If value is greater than max, max will be returned.</param>
/// <returns>
/// The <see cref="float"/> representing the clamped value.
/// </returns>
[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;
}
/// <summary>
/// Restricts a <see cref="double"/> to be within a specified range.
/// </summary>
/// <param name="value">The The value to clamp.</param>
/// <param name="min">The minimum value. If value is less than min, min will be returned.</param>
/// <param name="max">The maximum value. If value is greater than max, max will be returned.</param>
/// <returns>
/// The <see cref="double"/> representing the clamped value.
/// </returns>
[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;
}
}
}

8
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<TPixel> 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));
}

177
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
{
/// <summary>
/// Provides optimized static methods for common mathematical functions specific
/// to color processing.
/// </summary>
internal static class ColorNumerics
{
/// <summary>
/// Vector for converting pixel to gray value as specified by
/// ITU-R Recommendation BT.709.
/// </summary>
private static readonly Vector4 Bt709 = new Vector4(.2126f, .7152f, .0722f, 0.0f);
/// <summary>
/// Convert a pixel value to grayscale using ITU-R Recommendation BT.709.
/// </summary>
/// <param name="vector">The vector to get the luminance from.</param>
/// <param name="luminanceLevels">
/// The number of luminance levels (256 for 8 bit, 65536 for 16 bit grayscale images).
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetBT709Luminance(ref Vector4 vector, int luminanceLevels)
=> (int)MathF.Round(Vector4.Dot(vector, Bt709) * (luminanceLevels - 1));
/// <summary>
/// Gets the luminance from the rgb components using the formula
/// as specified by ITU-R Recommendation BT.709.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <returns>The <see cref="byte"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte Get8BitBT709Luminance(byte r, byte g, byte b)
=> (byte)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
/// <summary>
/// Gets the luminance from the rgb components using the formula as
/// specified by ITU-R Recommendation BT.709.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <returns>The <see cref="ushort"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ushort Get16BitBT709Luminance(ushort r, ushort g, ushort b)
=> (ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
/// <summary>
/// Gets the luminance from the rgb components using the formula as specified
/// by ITU-R Recommendation BT.709.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <returns>The <see cref="ushort"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ushort Get16BitBT709Luminance(float r, float g, float b)
=> (ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
/// <summary>
/// Scales a value from a 16 bit <see cref="ushort"/> to an
/// 8 bit <see cref="byte"/> equivalent.
/// </summary>
/// <param name="component">The 8 bit component value.</param>
/// <returns>The <see cref="byte"/></returns>
[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);
}
/// <summary>
/// Scales a value from an 8 bit <see cref="byte"/> to
/// an 16 bit <see cref="ushort"/> equivalent.
/// </summary>
/// <param name="component">The 8 bit component value.</param>
/// <returns>The <see cref="ushort"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ushort UpscaleFrom8BitTo16Bit(byte component)
=> (ushort)(component * 257);
/// <summary>
/// Returns how many bits are required to store the specified number of colors.
/// Performs a Log2() on the value.
/// </summary>
/// <param name="colors">The number of colors.</param>
/// <returns>
/// The <see cref="int"/>
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetBitsNeededForColorDepth(int colors)
=> Math.Max(1, (int)Math.Ceiling(Math.Log(colors, 2)));
/// <summary>
/// Returns how many colors will be created by the specified number of bits.
/// </summary>
/// <param name="bitDepth">The bit depth.</param>
/// <returns>The <see cref="int"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetColorCountForBitDepth(int bitDepth)
=> 1 << bitDepth;
/// <summary>
/// Transforms a vector by the given color matrix.
/// </summary>
/// <param name="vector">The source vector.</param>
/// <param name="matrix">The transformation color matrix.</param>
[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;
}
/// <summary>
/// Bulk variant of <see cref="Transform(ref Vector4, ref ColorMatrix)"/>.
/// </summary>
/// <param name="vectors">The span of vectors</param>
/// <param name="matrix">The transformation color matrix.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Transform(Span<Vector4> 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);
}
}
}
}

20
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);
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);
Vector4Utilities.UnPremultiply(ref vector);
Numerics.UnPremultiply(ref vector);
target = vector;
}
@ -133,14 +133,14 @@ 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<TPixel> 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);
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;
Vector4Utilities.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);
Vector4Utilities.UnPremultiply(ref vector);
Numerics.UnPremultiply(ref vector);
target = vector;
}
@ -263,14 +263,14 @@ 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<TPixel> 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);
Numerics.Premultiply(ref currentColor);
vector += matrix[y, x] * currentColor;
}
}

379
src/ImageSharp/Common/Helpers/ImageMaths.cs

@ -1,379 +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
{
/// <summary>
/// Provides common mathematical methods.
/// </summary>
internal static class ImageMaths
{
/// <summary>
/// Vector for converting pixel to gray value as specified by ITU-R Recommendation BT.709.
/// </summary>
private static readonly Vector4 Bt709 = new Vector4(.2126f, .7152f, .0722f, 0.0f);
/// <summary>
/// Convert a pixel value to grayscale using ITU-R Recommendation BT.709.
/// </summary>
/// <param name="vector">The vector to get the luminance from.</param>
/// <param name="luminanceLevels">The number of luminance levels (256 for 8 bit, 65536 for 16 bit grayscale images)</param>
[MethodImpl(InliningOptions.ShortMethod)]
public static int GetBT709Luminance(ref Vector4 vector, int luminanceLevels)
=> (int)MathF.Round(Vector4.Dot(vector, Bt709) * (luminanceLevels - 1));
/// <summary>
/// Gets the luminance from the rgb components using the formula as specified by ITU-R Recommendation BT.709.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <returns>The <see cref="byte"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static byte Get8BitBT709Luminance(byte r, byte g, byte b) =>
(byte)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
/// <summary>
/// Gets the luminance from the rgb components using the formula as specified by ITU-R Recommendation BT.709.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <returns>The <see cref="ushort"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static ushort Get16BitBT709Luminance(ushort r, ushort g, ushort b) =>
(ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
/// <summary>
/// Gets the luminance from the rgb components using the formula as specified by ITU-R Recommendation BT.709.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <returns>The <see cref="ushort"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static ushort Get16BitBT709Luminance(float r, float g, float b) =>
(ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
/// <summary>
/// Scales a value from a 16 bit <see cref="ushort"/> to it's 8 bit <see cref="byte"/> equivalent.
/// </summary>
/// <param name="component">The 8 bit component value.</param>
/// <returns>The <see cref="byte"/></returns>
[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);
}
/// <summary>
/// Scales a value from an 8 bit <see cref="byte"/> to it's 16 bit <see cref="ushort"/> equivalent.
/// </summary>
/// <param name="component">The 8 bit component value.</param>
/// <returns>The <see cref="ushort"/></returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static ushort UpscaleFrom8BitTo16Bit(byte component) => (ushort)(component * 257);
/// <summary>
/// Determine the Greatest CommonDivisor (GCD) of two numbers.
/// </summary>
public static int GreatestCommonDivisor(int a, int b)
{
while (b != 0)
{
int temp = b;
b = a % b;
a = temp;
}
return a;
}
/// <summary>
/// Determine the Least Common Multiple (LCM) of two numbers.
/// </summary>
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;
}
/// <summary>
/// Calculates <paramref name="x"/> % 2
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static int Modulo2(int x) => x & 1;
/// <summary>
/// Calculates <paramref name="x"/> % 4
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static int Modulo4(int x) => x & 3;
/// <summary>
/// Calculates <paramref name="x"/> % 8
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static int Modulo8(int x) => x & 7;
/// <summary>
/// Fast (x mod m) calculator, with the restriction that
/// <paramref name="m"/> should be power of 2.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static int ModuloP2(int x, int m) => x & (m - 1);
/// <summary>
/// Returns the absolute value of a 32-bit signed integer. Uses bit shifting to speed up the operation.
/// </summary>
/// <param name="x">
/// A number that is greater than <see cref="int.MinValue"/>, but less than or equal to <see cref="int.MaxValue"/>
/// </param>
/// <returns>The <see cref="int"/></returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static int FastAbs(int x)
{
int y = x >> 31;
return (x ^ y) - y;
}
/// <summary>
/// Returns a specified number raised to the power of 2
/// </summary>
/// <param name="x">A single-precision floating-point number</param>
/// <returns>The number <paramref name="x" /> raised to the power of 2.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static float Pow2(float x) => x * x;
/// <summary>
/// Returns a specified number raised to the power of 3
/// </summary>
/// <param name="x">A single-precision floating-point number</param>
/// <returns>The number <paramref name="x" /> raised to the power of 3.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static float Pow3(float x) => x * x * x;
/// <summary>
/// Returns how many bits are required to store the specified number of colors.
/// Performs a Log2() on the value.
/// </summary>
/// <param name="colors">The number of colors.</param>
/// <returns>
/// The <see cref="int"/>
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static int GetBitsNeededForColorDepth(int colors) => Math.Max(1, (int)Math.Ceiling(Math.Log(colors, 2)));
/// <summary>
/// Returns how many colors will be created by the specified number of bits.
/// </summary>
/// <param name="bitDepth">The bit depth.</param>
/// <returns>The <see cref="int"/></returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static int GetColorCountForBitDepth(int bitDepth) => 1 << bitDepth;
/// <summary>
/// Implementation of 1D Gaussian G(x) function
/// </summary>
/// <param name="x">The x provided to G(x).</param>
/// <param name="sigma">The spread of the blur.</param>
/// <returns>The Gaussian G(x)</returns>
[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;
}
/// <summary>
/// Returns the result of a normalized sine cardinal function for the given value.
/// SinC(x) = sin(pi*x)/(pi*x).
/// </summary>
/// <param name="f">A single-precision floating-point number to calculate the result for.</param>
/// <returns>
/// The sine cardinal of <paramref name="f" />.
/// </returns>
[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;
}
/// <summary>
/// Gets the bounding <see cref="Rectangle"/> from the given points.
/// </summary>
/// <param name="topLeft">
/// The <see cref="Point"/> designating the top left position.
/// </param>
/// <param name="bottomRight">
/// The <see cref="Point"/> designating the bottom right position.
/// </param>
/// <returns>
/// The bounding <see cref="Rectangle"/>.
/// </returns>
[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);
/// <summary>
/// Finds the bounding rectangle based on the first instance of any color component other
/// than the given one.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="bitmap">The <see cref="Image{TPixel}"/> to search within.</param>
/// <param name="componentValue">The color component value to remove.</param>
/// <param name="channel">The <see cref="RgbaComponent"/> channel to test against.</param>
/// <returns>
/// The <see cref="Rectangle"/>.
/// </returns>
public static Rectangle GetFilteredBoundingRectangle<TPixel>(ImageFrame<TPixel> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
where TPixel : unmanaged, IPixel<TPixel>
{
int width = bitmap.Width;
int height = bitmap.Height;
Point topLeft = default;
Point bottomRight = default;
Func<ImageFrame<TPixel>, 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<TPixel> 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<TPixel> 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<TPixel> 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<TPixel> 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 = (GetMaxY(bitmap) + 1).Clamp(0, height);
bottomRight.X = (GetMaxX(bitmap) + 1).Clamp(0, width);
return GetBoundingRectangle(topLeft, bottomRight);
}
}
}

551
src/ImageSharp/Common/Helpers/Numerics.cs

@ -0,0 +1,551 @@
// 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
{
/// <summary>
/// Provides optimized static methods for trigonometric, logarithmic,
/// and other common mathematical functions.
/// </summary>
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
/// <summary>
/// Determine the Greatest CommonDivisor (GCD) of two numbers.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GreatestCommonDivisor(int a, int b)
{
while (b != 0)
{
int temp = b;
b = a % b;
a = temp;
}
return a;
}
/// <summary>
/// Determine the Least Common Multiple (LCM) of two numbers.
/// </summary>
[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
return (a / GreatestCommonDivisor(a, b)) * b;
}
/// <summary>
/// Calculates <paramref name="x"/> % 2
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Modulo2(int x) => x & 1;
/// <summary>
/// Calculates <paramref name="x"/> % 4
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Modulo4(int x) => x & 3;
/// <summary>
/// Calculates <paramref name="x"/> % 8
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Modulo8(int x) => x & 7;
/// <summary>
/// Fast (x mod m) calculator, with the restriction that
/// <paramref name="m"/> should be power of 2.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ModuloP2(int x, int m) => x & (m - 1);
/// <summary>
/// Returns the absolute value of a 32-bit signed integer.
/// Uses bit shifting to speed up the operation compared to <see cref="Math"/>.
/// </summary>
/// <param name="x">
/// A number that is greater than <see cref="int.MinValue"/>, but less than
/// or equal to <see cref="int.MaxValue"/>
/// </param>
/// <returns>The <see cref="int"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Abs(int x)
{
int y = x >> 31;
return (x ^ y) - y;
}
/// <summary>
/// Returns a specified number raised to the power of 2
/// </summary>
/// <param name="x">A single-precision floating-point number</param>
/// <returns>The number <paramref name="x" /> raised to the power of 2.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Pow2(float x) => x * x;
/// <summary>
/// Returns a specified number raised to the power of 3
/// </summary>
/// <param name="x">A single-precision floating-point number</param>
/// <returns>The number <paramref name="x" /> raised to the power of 3.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Pow3(float x) => x * x * x;
/// <summary>
/// Implementation of 1D Gaussian G(x) function
/// </summary>
/// <param name="x">The x provided to G(x).</param>
/// <param name="sigma">The spread of the blur.</param>
/// <returns>The Gaussian G(x)</returns>
[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;
}
/// <summary>
/// Returns the result of a normalized sine cardinal function for the given value.
/// SinC(x) = sin(pi*x)/(pi*x).
/// </summary>
/// <param name="f">A single-precision floating-point number to calculate the result for.</param>
/// <returns>
/// The sine cardinal of <paramref name="f" />.
/// </returns>
[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;
}
/// <summary>
/// Returns the value clamped to the inclusive range of min and max.
/// </summary>
/// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum inclusive value.</param>
/// <param name="max">The maximum inclusive value.</param>
/// <returns>The clamped <see cref="byte"/>.</returns>
[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;
}
/// <summary>
/// Returns the value clamped to the inclusive range of min and max.
/// </summary>
/// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum inclusive value.</param>
/// <param name="max">The maximum inclusive value.</param>
/// <returns>The clamped <see cref="uint"/>.</returns>
[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;
}
/// <summary>
/// Returns the value clamped to the inclusive range of min and max.
/// </summary>
/// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum inclusive value.</param>
/// <param name="max">The maximum inclusive value.</param>
/// <returns>The clamped <see cref="uint"/>.</returns>
[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;
}
/// <summary>
/// Returns the value clamped to the inclusive range of min and max.
/// </summary>
/// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum inclusive value.</param>
/// <param name="max">The maximum inclusive value.</param>
/// <returns>The clamped <see cref="float"/>.</returns>
[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;
}
/// <summary>
/// Returns the value clamped to the inclusive range of min and max.
/// </summary>
/// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum inclusive value.</param>
/// <param name="max">The maximum inclusive value.</param>
/// <returns>The clamped <see cref="double"/>.</returns>
[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;
}
/// <summary>
/// Returns the value clamped to the inclusive range of min and max.
/// 5x Faster than <see cref="Vector4.Clamp(Vector4, Vector4, Vector4)"/>
/// on platforms &lt; NET 5.
/// </summary>
/// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum inclusive value.</param>
/// <param name="max">The maximum inclusive value.</param>
/// <returns>The clamped <see cref="Vector4"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 Clamp(Vector4 value, Vector4 min, Vector4 max)
=> Vector4.Min(Vector4.Max(value, min), max);
/// <summary>
/// Clamps the span values to the inclusive range of min and max.
/// </summary>
/// <param name="span">The span containing the values to clamp.</param>
/// <param name="min">The minimum inclusive value.</param>
/// <param name="max">The maximum inclusive value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clamp(Span<byte> span, byte min, byte max)
{
Span<byte> remainder = span.Slice(ClampReduce(span, min, max));
if (remainder.Length > 0)
{
for (int i = 0; i < remainder.Length; i++)
{
ref byte v = ref remainder[i];
v = Clamp(v, min, max);
}
}
}
/// <summary>
/// Clamps the span values to the inclusive range of min and max.
/// </summary>
/// <param name="span">The span containing the values to clamp.</param>
/// <param name="min">The minimum inclusive value.</param>
/// <param name="max">The maximum inclusive value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clamp(Span<uint> span, uint min, uint max)
{
Span<uint> remainder = span.Slice(ClampReduce(span, min, max));
if (remainder.Length > 0)
{
for (int i = 0; i < remainder.Length; i++)
{
ref uint v = ref remainder[i];
v = Clamp(v, min, max);
}
}
}
/// <summary>
/// Clamps the span values to the inclusive range of min and max.
/// </summary>
/// <param name="span">The span containing the values to clamp.</param>
/// <param name="min">The minimum inclusive value.</param>
/// <param name="max">The maximum inclusive value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clamp(Span<int> span, int min, int max)
{
Span<int> remainder = span.Slice(ClampReduce(span, min, max));
if (remainder.Length > 0)
{
for (int i = 0; i < remainder.Length; i++)
{
ref int v = ref remainder[i];
v = Clamp(v, min, max);
}
}
}
/// <summary>
/// Clamps the span values to the inclusive range of min and max.
/// </summary>
/// <param name="span">The span containing the values to clamp.</param>
/// <param name="min">The minimum inclusive value.</param>
/// <param name="max">The maximum inclusive value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clamp(Span<float> span, float min, float max)
{
Span<float> remainder = span.Slice(ClampReduce(span, min, max));
if (remainder.Length > 0)
{
for (int i = 0; i < remainder.Length; i++)
{
ref float v = ref remainder[i];
v = Clamp(v, min, max);
}
}
}
/// <summary>
/// Clamps the span values to the inclusive range of min and max.
/// </summary>
/// <param name="span">The span containing the values to clamp.</param>
/// <param name="min">The minimum inclusive value.</param>
/// <param name="max">The maximum inclusive value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clamp(Span<double> span, double min, double max)
{
Span<double> remainder = span.Slice(ClampReduce(span, min, max));
if (remainder.Length > 0)
{
for (int i = 0; i < remainder.Length; i++)
{
ref double v = ref remainder[i];
v = Clamp(v, min, max);
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int ClampReduce<T>(Span<T> span, T min, T max)
where T : unmanaged
{
if (Vector.IsHardwareAccelerated && span.Length >= Vector<T>.Count)
{
int remainder = ModuloP2(span.Length, Vector<T>.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<T>(Span<T> span, T min, T max)
where T : unmanaged
{
ref T sRef = ref MemoryMarshal.GetReference(span);
ref Vector<T> vsBase = ref Unsafe.As<T, Vector<T>>(ref MemoryMarshal.GetReference(span));
var vmin = new Vector<T>(min);
var vmax = new Vector<T>(max);
int n = span.Length / Vector<T>.Count;
int m = Modulo4(n);
int u = n - m;
for (int i = 0; i < u; i += 4)
{
ref Vector<T> vs0 = ref Unsafe.Add(ref vsBase, i);
ref Vector<T> vs1 = ref Unsafe.Add(ref vs0, 1);
ref Vector<T> vs2 = ref Unsafe.Add(ref vs0, 2);
ref Vector<T> 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<T> vs0 = ref Unsafe.Add(ref vsBase, i);
vs0 = Vector.Min(Vector.Max(vmin, vs0), vmax);
}
}
}
/// <summary>
/// Pre-multiplies the "x", "y", "z" components of a vector by its "w" component leaving the "w" component intact.
/// </summary>
/// <param name="source">The <see cref="Vector4"/> to premultiply</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Premultiply(ref Vector4 source)
{
float w = source.W;
source *= w;
source.W = w;
}
/// <summary>
/// Reverses the result of premultiplying a vector via <see cref="Premultiply(ref Vector4)"/>.
/// </summary>
/// <param name="source">The <see cref="Vector4"/> to premultiply</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UnPremultiply(ref Vector4 source)
{
float w = source.W;
source /= w;
source.W = w;
}
/// <summary>
/// Bulk variant of <see cref="Premultiply(ref Vector4)"/>
/// </summary>
/// <param name="vectors">The span of vectors</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Premultiply(Span<Vector4> vectors)
{
#if SUPPORTS_RUNTIME_INTRINSICS
if (Avx2.IsSupported && vectors.Length >= 2)
{
ref Vector256<float> vectorsBase =
ref Unsafe.As<Vector4, Vector256<float>>(ref MemoryMarshal.GetReference(vectors));
// Divide by 2 as 4 elements per Vector4 and 8 per Vector256<float>
ref Vector256<float> vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u));
while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast))
{
Vector256<float> source = vectorsBase;
Vector256<float> 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);
}
}
}
/// <summary>
/// Bulk variant of <see cref="UnPremultiply(ref Vector4)"/>
/// </summary>
/// <param name="vectors">The span of vectors</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UnPremultiply(Span<Vector4> vectors)
{
#if SUPPORTS_RUNTIME_INTRINSICS
if (Avx2.IsSupported && vectors.Length >= 2)
{
ref Vector256<float> vectorsBase =
ref Unsafe.As<Vector4, Vector256<float>>(ref MemoryMarshal.GetReference(vectors));
// Divide by 2 as 4 elements per Vector4 and 8 per Vector256<float>
ref Vector256<float> vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u));
while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast))
{
Vector256<float> source = vectorsBase;
Vector256<float> 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);
}
}
}
}
}

2
src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs

@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp
ref Byte3 dBase = ref Unsafe.As<byte, Byte3>(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);

4
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)

4
src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs

@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp
return;
}
int remainder = ImageMaths.ModuloP2(source.Length, Vector<byte>.Count);
int remainder = Numerics.ModuloP2(source.Length, Vector<byte>.Count);
int adjustedCount = source.Length - remainder;
if (adjustedCount > 0)
@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp
return;
}
int remainder = ImageMaths.ModuloP2(source.Length, Vector<byte>.Count);
int remainder = Numerics.ModuloP2(source.Length, Vector<byte>.Count);
int adjustedCount = source.Length - remainder;
if (adjustedCount > 0)

6
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)
@ -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;

24
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<float>.Count)
: ImageMaths.ModuloP2(source.Length, Vector128<float>.Count);
? Numerics.ModuloP2(source.Length, Vector256<float>.Count)
: Numerics.ModuloP2(source.Length, Vector128<float>.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<byte>.Count)
: ImageMaths.ModuloP2(source.Length, Vector128<byte>.Count);
? Numerics.ModuloP2(source.Length, Vector256<byte>.Count)
: Numerics.ModuloP2(source.Length, Vector128<byte>.Count);
int adjustedCount = source.Length - remainder;
@ -203,7 +203,7 @@ namespace SixLabors.ImageSharp
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(dest));
int n = dest.Length / Vector256<float>.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<float, Vector128<float>>(ref MemoryMarshal.GetReference(dest));
int n = dest.Length / Vector128<float>.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<byte, Vector256<byte>>(ref MemoryMarshal.GetReference(dest));
int n = dest.Length / Vector256<byte>.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<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(dest));
int n = dest.Length / Vector128<byte>.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<byte>.Count);
remainder = Numerics.ModuloP2(source.Length, Vector256<byte>.Count);
}
else
{
remainder = ImageMaths.ModuloP2(source.Length, Vector128<byte>.Count);
remainder = Numerics.ModuloP2(source.Length, Vector128<byte>.Count);
}
int adjustedCount = source.Length - remainder;
@ -683,11 +683,11 @@ namespace SixLabors.ImageSharp
int remainder;
if (Avx2.IsSupported)
{
remainder = ImageMaths.ModuloP2(source.Length, Vector256<byte>.Count);
remainder = Numerics.ModuloP2(source.Length, Vector256<byte>.Count);
}
else
{
remainder = ImageMaths.ModuloP2(source.Length, Vector128<byte>.Count);
remainder = Numerics.ModuloP2(source.Length, Vector128<byte>.Count);
}
int adjustedCount = source.Length - remainder;

8
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);
}
@ -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)
@ -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}!");
}

181
src/ImageSharp/Common/Helpers/Vector4Utilities.cs

@ -1,181 +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
{
/// <summary>
/// Utility methods for the <see cref="Vector4"/> struct.
/// </summary>
internal static class Vector4Utilities
{
private const int BlendAlphaControl = 0b_10_00_10_00;
private const int ShuffleAlphaControl = 0b_11_11_11_11;
/// <summary>
/// Restricts a vector between a minimum and a maximum value.
/// 5x Faster then <see cref="Vector4.Clamp(Vector4, Vector4, Vector4)"/>.
/// </summary>
/// <param name="x">The vector to restrict.</param>
/// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static Vector4 FastClamp(Vector4 x, Vector4 min, Vector4 max)
=> Vector4.Min(Vector4.Max(x, min), max);
/// <summary>
/// Pre-multiplies the "x", "y", "z" components of a vector by its "w" component leaving the "w" component intact.
/// </summary>
/// <param name="source">The <see cref="Vector4"/> to premultiply</param>
[MethodImpl(InliningOptions.ShortMethod)]
public static void Premultiply(ref Vector4 source)
{
float w = source.W;
source *= w;
source.W = w;
}
/// <summary>
/// Reverses the result of premultiplying a vector via <see cref="Premultiply(ref Vector4)"/>.
/// </summary>
/// <param name="source">The <see cref="Vector4"/> to premultiply</param>
[MethodImpl(InliningOptions.ShortMethod)]
public static void UnPremultiply(ref Vector4 source)
{
float w = source.W;
source /= w;
source.W = w;
}
/// <summary>
/// Bulk variant of <see cref="Premultiply(ref Vector4)"/>
/// </summary>
/// <param name="vectors">The span of vectors</param>
[MethodImpl(InliningOptions.ShortMethod)]
public static void Premultiply(Span<Vector4> vectors)
{
#if SUPPORTS_RUNTIME_INTRINSICS
if (Avx2.IsSupported && vectors.Length >= 2)
{
ref Vector256<float> vectorsBase =
ref Unsafe.As<Vector4, Vector256<float>>(ref MemoryMarshal.GetReference(vectors));
// Divide by 2 as 4 elements per Vector4 and 8 per Vector256<float>
ref Vector256<float> vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u));
while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast))
{
Vector256<float> source = vectorsBase;
Vector256<float> multiply = Avx.Shuffle(source, source, ShuffleAlphaControl);
vectorsBase = Avx.Blend(Avx.Multiply(source, multiply), source, BlendAlphaControl);
vectorsBase = ref Unsafe.Add(ref vectorsBase, 1);
}
if (ImageMaths.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);
}
}
}
/// <summary>
/// Bulk variant of <see cref="UnPremultiply(ref Vector4)"/>
/// </summary>
/// <param name="vectors">The span of vectors</param>
[MethodImpl(InliningOptions.ShortMethod)]
public static void UnPremultiply(Span<Vector4> vectors)
{
#if SUPPORTS_RUNTIME_INTRINSICS
if (Avx2.IsSupported && vectors.Length >= 2)
{
ref Vector256<float> vectorsBase =
ref Unsafe.As<Vector4, Vector256<float>>(ref MemoryMarshal.GetReference(vectors));
// Divide by 2 as 4 elements per Vector4 and 8 per Vector256<float>
ref Vector256<float> vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u));
while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast))
{
Vector256<float> source = vectorsBase;
Vector256<float> multiply = Avx.Shuffle(source, source, ShuffleAlphaControl);
vectorsBase = Avx.Blend(Avx.Divide(source, multiply), source, BlendAlphaControl);
vectorsBase = ref Unsafe.Add(ref vectorsBase, 1);
}
if (ImageMaths.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);
}
}
}
/// <summary>
/// Transforms a vector by the given matrix.
/// </summary>
/// <param name="vector">The source vector.</param>
/// <param name="matrix">The transformation matrix.</param>
[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;
}
/// <summary>
/// Bulk variant of <see cref="Transform(ref Vector4, ref ColorMatrix)"/>.
/// </summary>
/// <param name="vectors">The span of vectors</param>
/// <param name="matrix">The transformation matrix.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public static void Transform(Span<Vector4> 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);
}
}
}
}

4
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 = 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 = ImageMaths.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel) * bytesPerColorMapEntry;
colorMapSizeBytes = ColorNumerics.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel) * bytesPerColorMapEntry;
break;
}
}

17
src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

@ -262,7 +262,9 @@ namespace SixLabors.ImageSharp.Formats.Bmp
private void Write24Bit<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
where TPixel : unmanaged, IPixel<TPixel>
{
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<TPixel>.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<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
where TPixel : unmanaged, IPixel<TPixel>
{
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<TPixel>.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<TPixel> quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(image, image.Bounds());
ReadOnlySpan<TPixel> quantizedColors = quantized.Palette.Span;
PixelOperations<TPixel>.Instance.ToBgra32(this.configuration, quantizedColors, MemoryMarshal.Cast<byte, Bgra32>(colorPalette));
var quantizedColorBytes = quantizedColors.Length * 4;
PixelOperations<TPixel>.Instance.ToBgra32(this.configuration, quantizedColors, MemoryMarshal.Cast<byte, Bgra32>(colorPalette.Slice(0, quantizedColorBytes)));
Span<uint> colorPaletteAsUInt = MemoryMarshal.Cast<byte, uint>(colorPalette);
for (int i = 0; i < colorPaletteAsUInt.Length; i++)
{

6
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 = ColorNumerics.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 = 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<TPixel>
{
// The maximum number of colors for the bit depth
int colorTableLength = ImageMaths.GetColorCountForBitDepth(this.bitDepth) * Unsafe.SizeOf<Rgb24>();
int colorTableLength = ColorNumerics.GetColorCountForBitDepth(this.bitDepth) * Unsafe.SizeOf<Rgb24>();
using IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength, AllocationOptions.Clean);
PixelOperations<TPixel>.Instance.ToRgb24Bytes(

32
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);
}
/// <summary>

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

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

4
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;

19
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 <see cref="PixelTypeInfo"/> class.
/// </summary>
/// <param name="bitsPerPixel">Color depth, in number of bits per pixel.</param>
internal PixelTypeInfo(int bitsPerPixel)
/// <param name="alpha">Tthe pixel alpha transparency behavior.</param>
internal PixelTypeInfo(int bitsPerPixel, PixelAlphaRepresentation? alpha = null)
{
this.BitsPerPixel = bitsPerPixel;
this.AlphaRepresentation = alpha;
}
/// <summary>
@ -26,8 +27,20 @@ namespace SixLabors.ImageSharp.Formats
/// </summary>
public int BitsPerPixel { get; }
/// <summary>
/// Gets the pixel alpha transparency behavior.
/// <see langword="null"/> means unknown, unspecified.
/// </summary>
public PixelAlphaRepresentation? AlphaRepresentation { get; }
internal static PixelTypeInfo Create<TPixel>()
where TPixel : unmanaged, IPixel<TPixel> =>
new PixelTypeInfo(Unsafe.SizeOf<TPixel>() * 8);
internal static PixelTypeInfo Create<TPixel>(PixelAlphaRepresentation alpha)
where TPixel : unmanaged, IPixel<TPixel>
{
return new PixelTypeInfo(Unsafe.SizeOf<TPixel>() * 8, alpha);
}
}
}

8
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;
}
}
}

14
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;
}
}
}
}

4
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;

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

6
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 / (ColorNumerics.GetColorCountForBitDepth(this.bitDepth) - 1);
Span<byte> 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 = 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) =
ImageMaths.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B);
ColorNumerics.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B);
Unsafe.Add(ref rawScanlineSpanRef, o + 1) = rgba.A;
}
}

4
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 = 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)ImageMaths.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length).Clamp(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

4
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 / (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 / (ImageMaths.GetColorCountForBitDepth(header.BitDepth) - 1);
int scaleFactor = 255 / (ColorNumerics.GetColorCountForBitDepth(header.BitDepth) - 1);
if (!hasTrans)
{

2
src/ImageSharp/Formats/Tga/TgaEncoderCore.cs

@ -365,7 +365,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
where TPixel : unmanaged, IPixel<TPixel>
{
var vector = sourcePixel.ToVector4();
return ImageMaths.GetBT709Luminance(ref vector, 256);
return ColorNumerics.GetBT709Luminance(ref vector, 256);
}
}
}

56
src/ImageSharp/ImageSharp.csproj

@ -68,62 +68,62 @@
<AutoGen>True</AutoGen>
<DependentUpon>PixelOperations{TPixel}.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\Argb32.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Argb32.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Argb32.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\Bgr24.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Bgr24.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Bgr24.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\Bgra32.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Bgra32.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Bgra32.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\Bgra5551.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Bgra5551.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Bgra5551.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\L8.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\L16.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>L8.PixelOperations.Generated.tt</DependentUpon>
<DependentUpon>L16.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\L16.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\L8.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>L16.PixelOperations.Generated.tt</DependentUpon>
<DependentUpon>L8.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\La16.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\La16.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>La16.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\La32.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\La32.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>La32.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\Rgb24.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Rgb24.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Rgb24.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\Rgba32.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Rgb48.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Rgba32.PixelOperations.Generated.tt</DependentUpon>
<DependentUpon>Rgb48.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\Rgb48.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Rgba32.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Rgb48.PixelOperations.Generated.tt</DependentUpon>
<DependentUpon>Rgba32.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\Generated\Rgba64.PixelOperations.Generated.cs">
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Rgba64.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Rgba64.PixelOperations.Generated.tt</DependentUpon>
@ -162,51 +162,51 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>PixelOperations{TPixel}.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\Argb32.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Argb32.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Argb32.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\Bgr24.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Bgr24.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Bgr24.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\Bgra32.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Bgra32.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Bgra32.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\Bgra5551.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Bgra5551.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Bgra5551.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\L8.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\L8.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>L8.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\L16.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\L16.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>L16.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\La16.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\La16.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>La16.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\La32.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\La32.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>La32.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\Rgb24.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Rgb24.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Rgb24.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\Rgba32.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Rgba32.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Rgba32.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\Rgb48.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Rgb48.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Rgb48.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\Generated\Rgba64.PixelOperations.Generated.tt">
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Rgba64.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Rgba64.PixelOperations.Generated.cs</LastGenOutput>
</None>

2
src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.cs

@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
/// <param name="index">The new index position</param>
public void SetIndex(int index)
{
this.currentIndex = index.Clamp(0, this.data.Length);
this.currentIndex = Numerics.Clamp(index, 0, this.data.Length);
}
/// <summary>

10
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));
}
}

6
src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs

@ -33,9 +33,9 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
/// <returns>the number of bytes written</returns>
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);

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

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

32
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
{
/// <summary>
/// Provides enumeration of the alpha value transparency behavior of a pixel format.
/// </summary>
public enum PixelAlphaRepresentation
{
/// <summary>
/// Indicates that the pixel format does not contain an alpha channel.
/// </summary>
None,
/// <summary>
/// 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.
/// </summary>
Associated,
/// <summary>
/// Indicates that the transparency behavior is not premultiplied.
/// The alpha channel indicates the transparency of the color.
/// </summary>
Unassociated
}
}

648
src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs

File diff suppressed because it is too large

6
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;
}
/// <inheritdoc />
protected override void BlendFunction(Span<Vector4> destination, ReadOnlySpan<Vector4> background, ReadOnlySpan<Vector4> 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));
}
}
}

216
src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs

@ -203,7 +203,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
public static TPixel NormalSrc<TPixel>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
opacity = opacity.Clamp(0, 1);
opacity = Numerics.Clamp(opacity, 0, 1);
TPixel dest = default;
dest.FromScaledVector4(HardLightXor(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity));
return dest;

2
src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt

@ -219,7 +219,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
public static TPixel <#=blender#><#=composer#><TPixel>(TPixel backdrop, TPixel source, float opacity)
where TPixel : unmanaged, IPixel<TPixel>
{
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;

8
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.
/// </para>
/// </summary>
public struct A8 : IPixel<A8>, IPackedVector<byte>
public partial struct A8 : IPixel<A8>, IPackedVector<byte>
{
/// <summary>
/// Initializes a new instance of the <see cref="A8"/> struct.
@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.PixelFormats
public static bool operator !=(A8 left, A8 right) => !left.Equals(right);
/// <inheritdoc />
public readonly PixelOperations<A8> CreatePixelOperations() => new PixelOperations<A8>();
public readonly PixelOperations<A8> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa32(La32 source) => this.PackedValue = ImageMaths.DownScaleFrom16BitTo8Bit(source.A);
public void FromLa32(La32 source) => this.PackedValue = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
@ -162,6 +162,6 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="alpha">The float containing the value to pack.</param>
/// <returns>The <see cref="byte"/> containing the packed values.</returns>
[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);
}
}

22
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 = 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 = ImageMaths.DownScaleFrom16BitTo8Bit(source.L);
byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
this.R = rgb;
this.G = rgb;
this.B = rgb;
this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A);
this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
/// <inheritdoc/>
@ -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 = 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 = ImageMaths.DownScaleFrom16BitTo8Bit(source.R);
this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G);
this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B);
this.A = ImageMaths.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);
}
/// <inheritdoc/>
@ -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;

16
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 = 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 = ImageMaths.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 = ImageMaths.DownScaleFrom16BitTo8Bit(source.R);
this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G);
this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B);
this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
}
/// <inheritdoc/>
[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 = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
}
/// <inheritdoc/>

4
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.
/// </para>
/// </summary>
public struct Bgr565 : IPixel<Bgr565>, IPackedVector<ushort>
public partial struct Bgr565 : IPixel<Bgr565>, IPackedVector<ushort>
{
/// <summary>
/// Initializes a new instance of the <see cref="Bgr565"/> struct.
@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.PixelFormats
public static bool operator !=(Bgr565 left, Bgr565 right) => !left.Equals(right);
/// <inheritdoc />
public readonly PixelOperations<Bgr565> CreatePixelOperations() => new PixelOperations<Bgr565>();
public readonly PixelOperations<Bgr565> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]

22
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 = 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 = ImageMaths.DownScaleFrom16BitTo8Bit(source.L);
byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
this.R = rgb;
this.G = rgb;
this.B = rgb;
this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A);
this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
/// <inheritdoc/>
@ -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 = 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 = ImageMaths.DownScaleFrom16BitTo8Bit(source.R);
this.G = ImageMaths.DownScaleFrom16BitTo8Bit(source.G);
this.B = ImageMaths.DownScaleFrom16BitTo8Bit(source.B);
this.A = ImageMaths.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);
}
/// <inheritdoc/>
@ -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;

6
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.
/// </para>
/// </summary>
public struct Bgra4444 : IPixel<Bgra4444>, IPackedVector<ushort>
public partial struct Bgra4444 : IPixel<Bgra4444>, IPackedVector<ushort>
{
/// <summary>
/// Initializes a new instance of the <see cref="Bgra4444"/> struct.
@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.PixelFormats
public static bool operator !=(Bgra4444 left, Bgra4444 right) => !left.Equals(right);
/// <inheritdoc />
public readonly PixelOperations<Bgra4444> CreatePixelOperations() => new PixelOperations<Bgra4444>();
public readonly PixelOperations<Bgra4444> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
@ -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)

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

6
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.
/// </para>
/// </summary>
public struct Byte4 : IPixel<Byte4>, IPackedVector<uint>
public partial struct Byte4 : IPixel<Byte4>, IPackedVector<uint>
{
/// <summary>
/// Initializes a new instance of the <see cref="Byte4"/> struct.
@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.PixelFormats
public static bool operator !=(Byte4 left, Byte4 right) => !left.Equals(right);
/// <inheritdoc />
public readonly PixelOperations<Byte4> CreatePixelOperations() => new PixelOperations<Byte4>();
public readonly PixelOperations<Byte4> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
@ -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;

4
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.
/// </para>
/// </summary>
public struct HalfSingle : IPixel<HalfSingle>, IPackedVector<ushort>
public partial struct HalfSingle : IPixel<HalfSingle>, IPackedVector<ushort>
{
/// <summary>
/// Initializes a new instance of the <see cref="HalfSingle"/> struct.
@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.PixelFormats
public static bool operator !=(HalfSingle left, HalfSingle right) => !left.Equals(right);
/// <inheritdoc />
public PixelOperations<HalfSingle> CreatePixelOperations() => new PixelOperations<HalfSingle>();
public PixelOperations<HalfSingle> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]

6
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.
/// </para>
/// </summary>
public struct HalfVector2 : IPixel<HalfVector2>, IPackedVector<uint>
public partial struct HalfVector2 : IPixel<HalfVector2>, IPackedVector<uint>
{
/// <summary>
/// Initializes a new instance of the <see cref="HalfVector2"/> struct.
@ -54,13 +54,13 @@ namespace SixLabors.ImageSharp.PixelFormats
public static bool operator !=(HalfVector2 left, HalfVector2 right) => !left.Equals(right);
/// <inheritdoc />
public readonly PixelOperations<HalfVector2> CreatePixelOperations() => new PixelOperations<HalfVector2>();
public readonly PixelOperations<HalfVector2> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[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);
}

4
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.
/// </para>
/// </summary>
public struct HalfVector4 : IPixel<HalfVector4>, IPackedVector<ulong>
public partial struct HalfVector4 : IPixel<HalfVector4>, IPackedVector<ulong>
{
/// <summary>
/// Initializes a new instance of the <see cref="HalfVector4"/> struct.
@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.PixelFormats
public static bool operator !=(HalfVector4 left, HalfVector4 right) => !left.Equals(right);
/// <inheritdoc />
public readonly PixelOperations<HalfVector4> CreatePixelOperations() => new PixelOperations<HalfVector4>();
public readonly PixelOperations<HalfVector4> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]

54
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 = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}
/// <inheritdoc/>
[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 = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}
/// <inheritdoc/>
[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 = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}
/// <inheritdoc/>
@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL8(L8 source) => this.PackedValue = ImageMaths.UpscaleFrom8BitTo16Bit(source.PackedValue);
public void FromL8(L8 source) => this.PackedValue = ColorNumerics.UpscaleFrom8BitTo16Bit(source.PackedValue);
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa16(La16 source) => this.PackedValue = ImageMaths.UpscaleFrom8BitTo16Bit(source.L);
public void FromLa16(La16 source) => this.PackedValue = ColorNumerics.UpscaleFrom8BitTo16Bit(source.L);
/// <inheritdoc/>
[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 = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}
/// <inheritdoc />
[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 = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
byte rgb = ImageMaths.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
/// <inheritdoc/>
[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 = ColorNumerics.Get16BitBT709Luminance(source.R, source.G, source.B);
/// <inheritdoc/>
[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 = ColorNumerics.Get16BitBT709Luminance(source.R, source.G, source.B);
/// <inheritdoc />
public override readonly bool Equals(object obj) => obj is L16 other && this.Equals(other);
@ -176,8 +176,8 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
internal void ConvertFromRgbaScaledVector4(Vector4 vector)
{
vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max;
this.PackedValue = ImageMaths.Get16BitBT709Luminance(
vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Max;
this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
vector.X,
vector.Y,
vector.Z);

34
src/ImageSharp/PixelFormats/PixelImplementations/L8.cs

@ -73,15 +73,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc/>
[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 = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
/// <inheritdoc/>
[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 = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
/// <inheritdoc/>
[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 = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL16(L16 source) => this.PackedValue = ImageMaths.DownScaleFrom16BitTo8Bit(source.PackedValue);
public void FromL16(L16 source) => this.PackedValue = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
@ -101,15 +101,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa32(La32 source) => this.PackedValue = ImageMaths.DownScaleFrom16BitTo8Bit(source.L);
public void FromLa32(La32 source) => this.PackedValue = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
/// <inheritdoc/>
[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 = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
/// <inheritdoc />
[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 = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
@ -124,18 +124,18 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc/>
[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 = ColorNumerics.Get8BitBT709Luminance(
ColorNumerics.DownScaleFrom16BitTo8Bit(source.R),
ColorNumerics.DownScaleFrom16BitTo8Bit(source.G),
ColorNumerics.DownScaleFrom16BitTo8Bit(source.B));
/// <inheritdoc/>
[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 = ColorNumerics.Get8BitBT709Luminance(
ColorNumerics.DownScaleFrom16BitTo8Bit(source.R),
ColorNumerics.DownScaleFrom16BitTo8Bit(source.G),
ColorNumerics.DownScaleFrom16BitTo8Bit(source.B));
/// <inheritdoc />
public override readonly bool Equals(object obj) => obj is L8 other && this.Equals(other);
@ -156,8 +156,8 @@ 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);
vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes);
this.PackedValue = ColorNumerics.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z);
}
}
}

38
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 = 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 = ImageMaths.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 = ImageMaths.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 = ImageMaths.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 = ImageMaths.DownScaleFrom16BitTo8Bit(source.L);
this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A);
this.L = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb24(Rgb24 source)
{
this.L = ImageMaths.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 = ImageMaths.Get8BitBT709Luminance(
ImageMaths.DownScaleFrom16BitTo8Bit(source.R),
ImageMaths.DownScaleFrom16BitTo8Bit(source.G),
ImageMaths.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 = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B);
this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
this.A = source.A;
}
/// <inheritdoc/>
public void FromRgba64(Rgba64 source)
{
this.L = ImageMaths.Get8BitBT709Luminance(
ImageMaths.DownScaleFrom16BitTo8Bit(source.R),
ImageMaths.DownScaleFrom16BitTo8Bit(source.G),
ImageMaths.DownScaleFrom16BitTo8Bit(source.B));
this.L = ColorNumerics.Get8BitBT709Luminance(
ColorNumerics.DownScaleFrom16BitTo8Bit(source.R),
ColorNumerics.DownScaleFrom16BitTo8Bit(source.G),
ColorNumerics.DownScaleFrom16BitTo8Bit(source.B));
this.A = ImageMaths.DownScaleFrom16BitTo8Bit(source.A);
this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
/// <inheritdoc/>
@ -219,8 +219,8 @@ 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);
vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes);
this.L = ColorNumerics.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z);
this.A = (byte)vector.W;
}
}

64
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 = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A);
this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
/// <inheritdoc/>
[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 = 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 = ImageMaths.Get16BitBT709Luminance(
ImageMaths.UpscaleFrom8BitTo16Bit(source.R),
ImageMaths.UpscaleFrom8BitTo16Bit(source.G),
ImageMaths.UpscaleFrom8BitTo16Bit(source.B));
this.L = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A);
this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
/// <inheritdoc/>
@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL8(L8 source)
{
this.L = ImageMaths.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 = ImageMaths.UpscaleFrom8BitTo16Bit(source.L);
this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A);
this.L = ColorNumerics.UpscaleFrom8BitTo16Bit(source.L);
this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
/// <inheritdoc/>
@ -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 = 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 = ImageMaths.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 = ImageMaths.Get16BitBT709Luminance(
ImageMaths.UpscaleFrom8BitTo16Bit(source.R),
ImageMaths.UpscaleFrom8BitTo16Bit(source.G),
ImageMaths.UpscaleFrom8BitTo16Bit(source.B));
this.L = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A);
this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba64(Rgba64 source)
{
this.L = ImageMaths.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 = ImageMaths.DownScaleFrom16BitTo8Bit(this.L);
byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(this.L);
dest.R = rgb;
dest.G = rgb;
dest.B = rgb;
dest.A = ImageMaths.DownScaleFrom16BitTo8Bit(this.A);
dest.A = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A);
}
/// <inheritdoc/>
@ -233,8 +233,8 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
internal void ConvertFromRgbaScaledVector4(Vector4 vector)
{
vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max;
this.L = ImageMaths.Get16BitBT709Luminance(
vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Max;
this.L = ColorNumerics.Get16BitBT709Luminance(
vector.X,
vector.Y,
vector.Z);

4
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.
/// </para>
/// </summary>
public struct NormalizedByte2 : IPixel<NormalizedByte2>, IPackedVector<ushort>
public partial struct NormalizedByte2 : IPixel<NormalizedByte2>, IPackedVector<ushort>
{
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);
/// <inheritdoc />
public readonly PixelOperations<NormalizedByte2> CreatePixelOperations() => new PixelOperations<NormalizedByte2>();
public readonly PixelOperations<NormalizedByte2> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]

6
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.
/// </para>
/// </summary>
public struct NormalizedByte4 : IPixel<NormalizedByte4>, IPackedVector<uint>
public partial struct NormalizedByte4 : IPixel<NormalizedByte4>, IPackedVector<uint>
{
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);
/// <inheritdoc />
public readonly PixelOperations<NormalizedByte4> CreatePixelOperations() => new PixelOperations<NormalizedByte4>();
public readonly PixelOperations<NormalizedByte4> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
@ -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;

4
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.
/// </para>
/// </summary>
public struct NormalizedShort2 : IPixel<NormalizedShort2>, IPackedVector<uint>
public partial struct NormalizedShort2 : IPixel<NormalizedShort2>, IPackedVector<uint>
{
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);
/// <inheritdoc />
public readonly PixelOperations<NormalizedShort2> CreatePixelOperations() => new PixelOperations<NormalizedShort2>();
public readonly PixelOperations<NormalizedShort2> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]

6
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.
/// </para>
/// </summary>
public struct NormalizedShort4 : IPixel<NormalizedShort4>, IPackedVector<ulong>
public partial struct NormalizedShort4 : IPixel<NormalizedShort4>, IPackedVector<ulong>
{
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);
/// <inheritdoc />
public readonly PixelOperations<NormalizedShort4> CreatePixelOperations() => new PixelOperations<NormalizedShort4>();
public readonly PixelOperations<NormalizedShort4> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
@ -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;

26
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct A8
{
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<A8>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<A8>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
}
}

26
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Argb32
{
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Argb32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Argb32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
}
}

26
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Bgr24
{
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Bgr24>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgr24>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
}
}

26
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Bgr565
{
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgr565>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgr565>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
}
}

26
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Bgra32
{
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Bgra32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgra32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
}
}

26
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Bgra4444
{
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgra4444>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgra4444>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
}
}

26
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Bgra5551
{
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Bgra5551>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgra5551>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
}
}

26
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Byte4
{
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Byte4>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Byte4>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
}
}

72
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs

@ -1,15 +1,13 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -21,15 +19,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Argb32>
internal partial class PixelOperations : PixelOperations<Argb32>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromArgb32(Configuration configuration, ReadOnlySpan<Argb32> source, Span<Argb32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,17 +36,24 @@ 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));
}
/// <inheritdoc />
public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Argb32> destinationPixels, PixelConversionModifiers modifiers)
public override void FromVector4Destructive(
Configuration configuration,
Span<Vector4> sourceVectors,
Span<Argb32> destinationPixels,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale));
}
/// <inheritdoc />
public override void ToVector4(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Vector4> destVectors, PixelConversionModifiers modifiers)
public override void ToVector4(
Configuration configuration,
ReadOnlySpan<Argb32> sourcePixels,
Span<Vector4> destVectors,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale));
}
@ -160,9 +165,11 @@ namespace SixLabors.ImageSharp.PixelFormats
Span<byte> dest = MemoryMarshal.Cast<Argb32, byte>(destinationPixels);
PixelConverter.FromBgr24.ToArgb32(source, dest);
}
/// <inheritdoc />
public override void ToL8(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<L8> destinationPixels)
public override void ToL8(
Configuration configuration,
ReadOnlySpan<Argb32> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -178,9 +185,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromArgb32(sp);
}
}
/// <inheritdoc />
public override void ToL16(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<L16> destinationPixels)
public override void ToL16(
Configuration configuration,
ReadOnlySpan<Argb32> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -196,9 +205,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromArgb32(sp);
}
}
/// <inheritdoc />
public override void ToLa16(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<La16> destinationPixels)
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<Argb32> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -214,9 +225,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromArgb32(sp);
}
}
/// <inheritdoc />
public override void ToLa32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<La32> destinationPixels)
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<Argb32> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -232,9 +245,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromArgb32(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgb48> destinationPixels)
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<Argb32> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -250,9 +265,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromArgb32(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgba64> destinationPixels)
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<Argb32> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -268,9 +285,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromArgb32(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Bgra5551> destinationPixels)
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<Argb32> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -292,8 +311,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Argb32> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToArgb32(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToArgb32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

5
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.tt → 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
{
/// <content>
@ -11,7 +10,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Argb32>
internal partial class PixelOperations : PixelOperations<Argb32>
{
<# GenerateAllDefaultConversionMethods("Argb32"); #>
}

72
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs

@ -1,15 +1,13 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -21,15 +19,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgr24>
internal partial class PixelOperations : PixelOperations<Bgr24>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromBgr24(Configuration configuration, ReadOnlySpan<Bgr24> source, Span<Bgr24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,17 +36,24 @@ 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));
}
/// <inheritdoc />
public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Bgr24> destinationPixels, PixelConversionModifiers modifiers)
public override void FromVector4Destructive(
Configuration configuration,
Span<Vector4> sourceVectors,
Span<Bgr24> destinationPixels,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply));
}
/// <inheritdoc />
public override void ToVector4(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Vector4> destVectors, PixelConversionModifiers modifiers)
public override void ToVector4(
Configuration configuration,
ReadOnlySpan<Bgr24> sourcePixels,
Span<Vector4> destVectors,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply));
}
@ -160,9 +165,11 @@ namespace SixLabors.ImageSharp.PixelFormats
Span<byte> dest = MemoryMarshal.Cast<Bgr24, byte>(destinationPixels);
PixelConverter.FromRgb24.ToBgr24(source, dest);
}
/// <inheritdoc />
public override void ToL8(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<L8> destinationPixels)
public override void ToL8(
Configuration configuration,
ReadOnlySpan<Bgr24> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -178,9 +185,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgr24(sp);
}
}
/// <inheritdoc />
public override void ToL16(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<L16> destinationPixels)
public override void ToL16(
Configuration configuration,
ReadOnlySpan<Bgr24> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -196,9 +205,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgr24(sp);
}
}
/// <inheritdoc />
public override void ToLa16(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<La16> destinationPixels)
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<Bgr24> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -214,9 +225,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgr24(sp);
}
}
/// <inheritdoc />
public override void ToLa32(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<La32> destinationPixels)
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<Bgr24> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -232,9 +245,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgr24(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Rgb48> destinationPixels)
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<Bgr24> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -250,9 +265,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgr24(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Rgba64> destinationPixels)
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<Bgr24> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -268,9 +285,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgr24(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Bgra5551> destinationPixels)
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<Bgr24> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -292,8 +311,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Bgr24> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToBgr24(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToBgr24(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

5
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.tt → 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
{
/// <content>
@ -11,7 +10,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgr24>
internal partial class PixelOperations : PixelOperations<Bgr24>
{
<# GenerateAllDefaultConversionMethods("Bgr24"); #>
}

72
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs

@ -1,15 +1,13 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -21,15 +19,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgra32>
internal partial class PixelOperations : PixelOperations<Bgra32>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromBgra32(Configuration configuration, ReadOnlySpan<Bgra32> source, Span<Bgra32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,17 +36,24 @@ 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));
}
/// <inheritdoc />
public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Bgra32> destinationPixels, PixelConversionModifiers modifiers)
public override void FromVector4Destructive(
Configuration configuration,
Span<Vector4> sourceVectors,
Span<Bgra32> destinationPixels,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale));
}
/// <inheritdoc />
public override void ToVector4(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Vector4> destVectors, PixelConversionModifiers modifiers)
public override void ToVector4(
Configuration configuration,
ReadOnlySpan<Bgra32> sourcePixels,
Span<Vector4> destVectors,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale));
}
@ -160,9 +165,11 @@ namespace SixLabors.ImageSharp.PixelFormats
Span<byte> dest = MemoryMarshal.Cast<Bgra32, byte>(destinationPixels);
PixelConverter.FromBgr24.ToBgra32(source, dest);
}
/// <inheritdoc />
public override void ToL8(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<L8> destinationPixels)
public override void ToL8(
Configuration configuration,
ReadOnlySpan<Bgra32> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -178,9 +185,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra32(sp);
}
}
/// <inheritdoc />
public override void ToL16(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<L16> destinationPixels)
public override void ToL16(
Configuration configuration,
ReadOnlySpan<Bgra32> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -196,9 +205,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra32(sp);
}
}
/// <inheritdoc />
public override void ToLa16(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<La16> destinationPixels)
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<Bgra32> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -214,9 +225,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra32(sp);
}
}
/// <inheritdoc />
public override void ToLa32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<La32> destinationPixels)
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<Bgra32> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -232,9 +245,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra32(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgb48> destinationPixels)
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<Bgra32> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -250,9 +265,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra32(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgba64> destinationPixels)
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<Bgra32> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -268,9 +285,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra32(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Bgra5551> destinationPixels)
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<Bgra32> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -292,8 +311,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Bgra32> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToBgra32(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToBgra32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

5
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.tt → 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
{
/// <content>
@ -11,7 +10,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgra32>
internal partial class PixelOperations : PixelOperations<Bgra32>
{
<# GenerateAllDefaultConversionMethods("Bgra32"); #>
}

82
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs

@ -3,13 +3,11 @@
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -21,15 +19,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgra5551>
internal partial class PixelOperations : PixelOperations<Bgra5551>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromBgra5551(Configuration configuration, ReadOnlySpan<Bgra5551> source, Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,12 +36,13 @@ 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));
}
/// <inheritdoc />
public override void ToArgb32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Argb32> destinationPixels)
public override void ToArgb32(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<Argb32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -59,9 +58,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra5551(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Bgr24> destinationPixels)
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<Bgr24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -77,9 +78,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra5551(sp);
}
}
/// <inheritdoc />
public override void ToBgra32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Bgra32> destinationPixels)
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<Bgra32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -95,9 +98,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra5551(sp);
}
}
/// <inheritdoc />
public override void ToL8(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<L8> destinationPixels)
public override void ToL8(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -113,9 +118,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra5551(sp);
}
}
/// <inheritdoc />
public override void ToL16(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<L16> destinationPixels)
public override void ToL16(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -131,9 +138,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra5551(sp);
}
}
/// <inheritdoc />
public override void ToLa16(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<La16> destinationPixels)
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -149,9 +158,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra5551(sp);
}
}
/// <inheritdoc />
public override void ToLa32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<La32> destinationPixels)
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -167,9 +178,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra5551(sp);
}
}
/// <inheritdoc />
public override void ToRgb24(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgb24> destinationPixels)
public override void ToRgb24(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<Rgb24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -185,9 +198,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra5551(sp);
}
}
/// <inheritdoc />
public override void ToRgba32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgba32> destinationPixels)
public override void ToRgba32(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<Rgba32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -203,9 +218,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra5551(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgb48> destinationPixels)
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -221,9 +238,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromBgra5551(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgba64> destinationPixels)
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -245,8 +264,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Bgra5551> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToBgra5551(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToBgra5551(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

3
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.tt → 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
{
/// <content>
@ -11,7 +10,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgra5551>
internal partial class PixelOperations : PixelOperations<Bgra5551>
{
<# GenerateAllDefaultConversionMethods("Bgra5551"); #>
}

84
src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs

@ -1,15 +1,13 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -21,15 +19,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<L16>
internal partial class PixelOperations : PixelOperations<L16>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromL16(Configuration configuration, ReadOnlySpan<L16> source, Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,12 +36,13 @@ 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));
}
/// <inheritdoc />
public override void ToArgb32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Argb32> destinationPixels)
public override void ToArgb32(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<Argb32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -59,9 +58,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL16(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Bgr24> destinationPixels)
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<Bgr24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -77,9 +78,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL16(sp);
}
}
/// <inheritdoc />
public override void ToBgra32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Bgra32> destinationPixels)
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<Bgra32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -95,9 +98,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL16(sp);
}
}
/// <inheritdoc />
public override void ToL8(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<L8> destinationPixels)
public override void ToL8(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -113,9 +118,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL16(sp);
}
}
/// <inheritdoc />
public override void ToLa16(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<La16> destinationPixels)
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -131,9 +138,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL16(sp);
}
}
/// <inheritdoc />
public override void ToLa32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<La32> destinationPixels)
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -149,9 +158,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL16(sp);
}
}
/// <inheritdoc />
public override void ToRgb24(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgb24> destinationPixels)
public override void ToRgb24(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<Rgb24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -167,9 +178,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL16(sp);
}
}
/// <inheritdoc />
public override void ToRgba32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgba32> destinationPixels)
public override void ToRgba32(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<Rgba32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -185,9 +198,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL16(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgb48> destinationPixels)
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -203,9 +218,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL16(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgba64> destinationPixels)
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -221,9 +238,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL16(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Bgra5551> destinationPixels)
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -245,8 +264,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<L16> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToL16(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToL16(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

5
src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.tt → 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
{
/// <content>
@ -11,7 +10,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<L16>
internal partial class PixelOperations : PixelOperations<L16>
{
<# GenerateAllDefaultConversionMethods("L16"); #>
}

84
src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs

@ -1,15 +1,13 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -21,15 +19,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<L8>
internal partial class PixelOperations : PixelOperations<L8>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromL8(Configuration configuration, ReadOnlySpan<L8> source, Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,12 +36,13 @@ 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));
}
/// <inheritdoc />
public override void ToArgb32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Argb32> destinationPixels)
public override void ToArgb32(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<Argb32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -59,9 +58,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL8(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Bgr24> destinationPixels)
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<Bgr24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -77,9 +78,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL8(sp);
}
}
/// <inheritdoc />
public override void ToBgra32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Bgra32> destinationPixels)
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<Bgra32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -95,9 +98,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL8(sp);
}
}
/// <inheritdoc />
public override void ToL16(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<L16> destinationPixels)
public override void ToL16(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -113,9 +118,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL8(sp);
}
}
/// <inheritdoc />
public override void ToLa16(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<La16> destinationPixels)
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -131,9 +138,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL8(sp);
}
}
/// <inheritdoc />
public override void ToLa32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<La32> destinationPixels)
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -149,9 +158,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL8(sp);
}
}
/// <inheritdoc />
public override void ToRgb24(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgb24> destinationPixels)
public override void ToRgb24(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<Rgb24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -167,9 +178,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL8(sp);
}
}
/// <inheritdoc />
public override void ToRgba32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgba32> destinationPixels)
public override void ToRgba32(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<Rgba32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -185,9 +198,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL8(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgb48> destinationPixels)
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -203,9 +218,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL8(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgba64> destinationPixels)
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -221,9 +238,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromL8(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Bgra5551> destinationPixels)
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -245,8 +264,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<L8> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToL8(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToL8(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

5
src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.tt → 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
{
/// <content>
@ -11,7 +10,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<L8>
internal partial class PixelOperations : PixelOperations<L8>
{
<# GenerateAllDefaultConversionMethods("L8"); #>
}

82
src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs

@ -3,13 +3,11 @@
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -21,15 +19,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<La16>
internal partial class PixelOperations : PixelOperations<La16>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromLa16(Configuration configuration, ReadOnlySpan<La16> source, Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,12 +36,13 @@ 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));
}
/// <inheritdoc />
public override void ToArgb32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Argb32> destinationPixels)
public override void ToArgb32(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<Argb32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -59,9 +58,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa16(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Bgr24> destinationPixels)
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<Bgr24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -77,9 +78,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa16(sp);
}
}
/// <inheritdoc />
public override void ToBgra32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Bgra32> destinationPixels)
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<Bgra32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -95,9 +98,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa16(sp);
}
}
/// <inheritdoc />
public override void ToL8(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<L8> destinationPixels)
public override void ToL8(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -113,9 +118,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa16(sp);
}
}
/// <inheritdoc />
public override void ToL16(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<L16> destinationPixels)
public override void ToL16(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -131,9 +138,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa16(sp);
}
}
/// <inheritdoc />
public override void ToLa32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<La32> destinationPixels)
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -149,9 +158,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa16(sp);
}
}
/// <inheritdoc />
public override void ToRgb24(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgb24> destinationPixels)
public override void ToRgb24(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<Rgb24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -167,9 +178,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa16(sp);
}
}
/// <inheritdoc />
public override void ToRgba32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgba32> destinationPixels)
public override void ToRgba32(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<Rgba32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -185,9 +198,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa16(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgb48> destinationPixels)
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -203,9 +218,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa16(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgba64> destinationPixels)
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -221,9 +238,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa16(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Bgra5551> destinationPixels)
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -245,8 +264,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<La16> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToLa16(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToLa16(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

3
src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.tt → 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
{
/// <content>
@ -11,7 +10,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<La16>
internal partial class PixelOperations : PixelOperations<La16>
{
<# GenerateAllDefaultConversionMethods("La16"); #>
}

82
src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs

@ -3,13 +3,11 @@
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -21,15 +19,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<La32>
internal partial class PixelOperations : PixelOperations<La32>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromLa32(Configuration configuration, ReadOnlySpan<La32> source, Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,12 +36,13 @@ 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));
}
/// <inheritdoc />
public override void ToArgb32(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Argb32> destinationPixels)
public override void ToArgb32(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<Argb32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -59,9 +58,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa32(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Bgr24> destinationPixels)
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<Bgr24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -77,9 +78,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa32(sp);
}
}
/// <inheritdoc />
public override void ToBgra32(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Bgra32> destinationPixels)
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<Bgra32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -95,9 +98,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa32(sp);
}
}
/// <inheritdoc />
public override void ToL8(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<L8> destinationPixels)
public override void ToL8(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -113,9 +118,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa32(sp);
}
}
/// <inheritdoc />
public override void ToL16(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<L16> destinationPixels)
public override void ToL16(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -131,9 +138,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa32(sp);
}
}
/// <inheritdoc />
public override void ToLa16(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<La16> destinationPixels)
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -149,9 +158,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa32(sp);
}
}
/// <inheritdoc />
public override void ToRgb24(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgb24> destinationPixels)
public override void ToRgb24(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<Rgb24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -167,9 +178,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa32(sp);
}
}
/// <inheritdoc />
public override void ToRgba32(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgba32> destinationPixels)
public override void ToRgba32(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<Rgba32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -185,9 +198,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa32(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgb48> destinationPixels)
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -203,9 +218,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa32(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgba64> destinationPixels)
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -221,9 +238,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromLa32(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Bgra5551> destinationPixels)
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -245,8 +264,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<La32> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToLa32(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToLa32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

3
src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.tt → 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
{
/// <content>
@ -11,7 +10,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<La32>
internal partial class PixelOperations : PixelOperations<La32>
{
<# GenerateAllDefaultConversionMethods("La32"); #>
}

73
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs

@ -1,15 +1,13 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -21,15 +19,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Rgb24>
internal partial class PixelOperations : PixelOperations<Rgb24>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromRgb24(Configuration configuration, ReadOnlySpan<Rgb24> source, Span<Rgb24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,17 +36,24 @@ 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));
}
/// <inheritdoc />
public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Rgb24> destinationPixels, PixelConversionModifiers modifiers)
public override void FromVector4Destructive(
Configuration configuration,
Span<Vector4> sourceVectors,
Span<Rgb24> destinationPixels,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply));
}
/// <inheritdoc />
public override void ToVector4(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Vector4> destVectors, PixelConversionModifiers modifiers)
public override void ToVector4(
Configuration configuration,
ReadOnlySpan<Rgb24> sourcePixels,
Span<Vector4> destVectors,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply));
}
@ -79,7 +84,6 @@ namespace SixLabors.ImageSharp.PixelFormats
Span<byte> dest = MemoryMarshal.Cast<Rgb24, byte>(destinationPixels);
PixelConverter.FromRgba32.ToRgb24(source, dest);
}
/// <inheritdoc />
public override void ToArgb32(
Configuration configuration,
@ -161,9 +165,11 @@ namespace SixLabors.ImageSharp.PixelFormats
Span<byte> dest = MemoryMarshal.Cast<Rgb24, byte>(destinationPixels);
PixelConverter.FromBgr24.ToRgb24(source, dest);
}
/// <inheritdoc />
public override void ToL8(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<L8> destinationPixels)
public override void ToL8(
Configuration configuration,
ReadOnlySpan<Rgb24> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -179,9 +185,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb24(sp);
}
}
/// <inheritdoc />
public override void ToL16(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<L16> destinationPixels)
public override void ToL16(
Configuration configuration,
ReadOnlySpan<Rgb24> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -197,9 +205,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb24(sp);
}
}
/// <inheritdoc />
public override void ToLa16(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<La16> destinationPixels)
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<Rgb24> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -215,9 +225,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb24(sp);
}
}
/// <inheritdoc />
public override void ToLa32(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<La32> destinationPixels)
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<Rgb24> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -233,9 +245,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb24(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Rgb48> destinationPixels)
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<Rgb24> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -251,9 +265,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb24(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Rgba64> destinationPixels)
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<Rgb24> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -269,9 +285,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb24(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Bgra5551> destinationPixels)
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<Rgb24> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -293,8 +311,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Rgb24> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToRgb24(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToRgb24(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

5
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.tt → 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
{
/// <content>
@ -11,7 +10,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Rgb24>
internal partial class PixelOperations : PixelOperations<Rgb24>
{
<# GenerateAllDefaultConversionMethods("Rgb24"); #>
}

84
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs

@ -1,15 +1,13 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -21,15 +19,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Rgb48>
internal partial class PixelOperations : PixelOperations<Rgb48>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromRgb48(Configuration configuration, ReadOnlySpan<Rgb48> source, Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,12 +36,13 @@ 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));
}
/// <inheritdoc />
public override void ToArgb32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Argb32> destinationPixels)
public override void ToArgb32(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<Argb32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -59,9 +58,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb48(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Bgr24> destinationPixels)
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<Bgr24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -77,9 +78,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb48(sp);
}
}
/// <inheritdoc />
public override void ToBgra32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Bgra32> destinationPixels)
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<Bgra32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -95,9 +98,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb48(sp);
}
}
/// <inheritdoc />
public override void ToL8(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<L8> destinationPixels)
public override void ToL8(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -113,9 +118,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb48(sp);
}
}
/// <inheritdoc />
public override void ToL16(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<L16> destinationPixels)
public override void ToL16(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -131,9 +138,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb48(sp);
}
}
/// <inheritdoc />
public override void ToLa16(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<La16> destinationPixels)
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -149,9 +158,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb48(sp);
}
}
/// <inheritdoc />
public override void ToLa32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<La32> destinationPixels)
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -167,9 +178,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb48(sp);
}
}
/// <inheritdoc />
public override void ToRgb24(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Rgb24> destinationPixels)
public override void ToRgb24(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<Rgb24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -185,9 +198,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb48(sp);
}
}
/// <inheritdoc />
public override void ToRgba32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Rgba32> destinationPixels)
public override void ToRgba32(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<Rgba32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -203,9 +218,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb48(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Rgba64> destinationPixels)
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -221,9 +238,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgb48(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Bgra5551> destinationPixels)
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -245,8 +264,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Rgb48> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToRgb48(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToRgb48(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

5
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.tt → 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
{
/// <content>
@ -11,7 +10,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Rgb48>
internal partial class PixelOperations : PixelOperations<Rgb48>
{
<# GenerateAllDefaultConversionMethods("Rgb48"); #>
}

58
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs

@ -1,15 +1,13 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -23,13 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary>
internal partial class PixelOperations : PixelOperations<Rgba32>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromRgba32(Configuration configuration, ReadOnlySpan<Rgba32> source, Span<Rgba32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,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));
}
/// <inheritdoc />
public override void ToArgb32(
Configuration configuration,
@ -149,9 +146,11 @@ namespace SixLabors.ImageSharp.PixelFormats
Span<byte> dest = MemoryMarshal.Cast<Rgba32, byte>(destinationPixels);
PixelConverter.FromBgr24.ToRgba32(source, dest);
}
/// <inheritdoc />
public override void ToL8(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<L8> destinationPixels)
public override void ToL8(
Configuration configuration,
ReadOnlySpan<Rgba32> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -167,9 +166,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba32(sp);
}
}
/// <inheritdoc />
public override void ToL16(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<L16> destinationPixels)
public override void ToL16(
Configuration configuration,
ReadOnlySpan<Rgba32> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -185,9 +186,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba32(sp);
}
}
/// <inheritdoc />
public override void ToLa16(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<La16> destinationPixels)
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<Rgba32> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -203,9 +206,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba32(sp);
}
}
/// <inheritdoc />
public override void ToLa32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<La32> destinationPixels)
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<Rgba32> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -221,9 +226,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba32(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Rgb48> destinationPixels)
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<Rgba32> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -239,9 +246,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba32(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Rgba64> destinationPixels)
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<Rgba32> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -257,9 +266,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba32(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Bgra5551> destinationPixels)
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<Rgba32> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -281,8 +292,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Rgba32> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToRgba32(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToRgba32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

3
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.tt → 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
{
/// <content>

84
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.cs → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs

@ -1,15 +1,13 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -21,15 +19,15 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Rgba64>
internal partial class PixelOperations : PixelOperations<Rgba64>
{
/// <inheritdoc />
/// <inheritdoc />
public override void FromRgba64(Configuration configuration, ReadOnlySpan<Rgba64> source, Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -38,12 +36,13 @@ 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));
}
/// <inheritdoc />
public override void ToArgb32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Argb32> destinationPixels)
public override void ToArgb32(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<Argb32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -59,9 +58,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba64(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Bgr24> destinationPixels)
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<Bgr24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -77,9 +78,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba64(sp);
}
}
/// <inheritdoc />
public override void ToBgra32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Bgra32> destinationPixels)
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<Bgra32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -95,9 +98,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba64(sp);
}
}
/// <inheritdoc />
public override void ToL8(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<L8> destinationPixels)
public override void ToL8(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -113,9 +118,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba64(sp);
}
}
/// <inheritdoc />
public override void ToL16(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<L16> destinationPixels)
public override void ToL16(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -131,9 +138,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba64(sp);
}
}
/// <inheritdoc />
public override void ToLa16(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<La16> destinationPixels)
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -149,9 +158,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba64(sp);
}
}
/// <inheritdoc />
public override void ToLa32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<La32> destinationPixels)
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -167,9 +178,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba64(sp);
}
}
/// <inheritdoc />
public override void ToRgb24(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Rgb24> destinationPixels)
public override void ToRgb24(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<Rgb24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -185,9 +198,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba64(sp);
}
}
/// <inheritdoc />
public override void ToRgba32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Rgba32> destinationPixels)
public override void ToRgba32(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<Rgba32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -203,9 +218,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba64(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Rgb48> destinationPixels)
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -221,9 +238,11 @@ namespace SixLabors.ImageSharp.PixelFormats
dp.FromRgba64(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Bgra5551> destinationPixels)
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
@ -245,8 +264,9 @@ namespace SixLabors.ImageSharp.PixelFormats
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Rgba64> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToRgba64(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToRgba64(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

5
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.tt → 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
{
/// <content>
@ -11,7 +10,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Rgba64>
internal partial class PixelOperations : PixelOperations<Rgba64>
{
<# GenerateAllDefaultConversionMethods("Rgba64"); #>
}

70
src/ImageSharp/PixelFormats/PixelImplementations/Generated/_Common.ttinclude → src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude

@ -8,19 +8,45 @@
// <auto-generated />
using SixLabors.ImageSharp.PixelFormats.Utils;
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
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" };
// Types with Rgba32-combatible to/from Vector4 conversion
static readonly string[] Rgba32CompatibleTypes = { "Argb32", "Bgra32", "Rgb24", "Bgr24" };
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"
};
void GenerateGenericConverterMethods(string pixelType)
{
@ -31,21 +57,22 @@ using System.Runtime.InteropServices;
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<<#=pixelType#>> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.To<#=pixelType#>(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.To<#=pixelType#>(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
<#+
}
void GenerateDefaultSelfConversionMethods(string pixelType)
{
#>
/// <inheritdoc />
/// <inheritdoc />
public override void From<#=pixelType#>(Configuration configuration, ReadOnlySpan<<#=pixelType#>> source, Span<<#=pixelType#>> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
@ -54,18 +81,19 @@ using System.Runtime.InteropServices;
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destinationPixels);
sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length));
}
<#+
}
void GenerateDefaultConvertToMethod(string fromPixelType, string toPixelType)
{
#>
/// <inheritdoc />
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 +154,21 @@ using System.Runtime.InteropServices;
}
#>
/// <inheritdoc />
public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<<#=pixelType#>> destinationPixels, PixelConversionModifiers modifiers)
public override void FromVector4Destructive(
Configuration configuration,
Span<Vector4> sourceVectors,
Span<<#=pixelType#>> destinationPixels,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(<#=removeTheseModifiers#>));
}
/// <inheritdoc />
public override void ToVector4(Configuration configuration, ReadOnlySpan<<#=pixelType#>> sourcePixels, Span<Vector4> destVectors, PixelConversionModifiers modifiers)
public override void ToVector4(
Configuration configuration,
ReadOnlySpan<<#=pixelType#>> sourcePixels,
Span<Vector4> destVectors,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(<#=removeTheseModifiers#>));
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save