Browse Source

Replace clamp extensions

js/color-alpha-handling
James Jackson-South 5 years ago
parent
commit
3bdbfe620e
  1. 140
      src/ImageSharp/Common/Extensions/ComparableExtensions.cs
  2. 8
      src/ImageSharp/Common/Helpers/Buffer2DUtils.cs
  3. 8
      src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
  4. 4
      src/ImageSharp/Common/Helpers/ImageMath.cs
  5. 2
      src/ImageSharp/Common/Helpers/SimdUtils.cs
  6. 4
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
  7. 2
      src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
  8. 2
      src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.cs
  9. 10
      src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs
  10. 6
      src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs
  11. 10
      src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs
  12. 2
      src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs
  13. 648
      src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
  14. 6
      src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt
  15. 216
      src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs
  16. 2
      src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt
  17. 2
      src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
  18. 8
      src/ImageSharp/Primitives/Number.cs
  19. 8
      src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs
  20. 2
      src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs
  21. 5
      src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs
  22. 2
      src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs
  23. 2
      src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs
  24. 2
      src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs
  25. 4
      src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs
  26. 19
      tests/ImageSharp.Benchmarks/Color/YcbCrToRgb.cs
  27. 2
      tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs

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

8
src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs

@ -133,12 +133,12 @@ namespace SixLabors.ImageSharp
for (int y = 0; y < matrixHeight; y++)
{
int offsetY = (row + y - radiusY).Clamp(minRow, maxRow);
int offsetY = Numerics.Clamp(row + y - radiusY, minRow, maxRow);
Span<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);
@ -263,12 +263,12 @@ namespace SixLabors.ImageSharp
for (int y = 0; y < matrixHeight; y++)
{
int offsetY = (row + y - radiusY).Clamp(minRow, maxRow);
int offsetY = Numerics.Clamp(row + y - radiusY, minRow, maxRow);
Span<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);
vector += matrix[y, x] * currentColor;

4
src/ImageSharp/Common/Helpers/ImageMath.cs

@ -248,8 +248,8 @@ namespace SixLabors.ImageSharp
topLeft.Y = GetMinY(bitmap);
topLeft.X = GetMinX(bitmap);
bottomRight.Y = (GetMaxY(bitmap) + 1).Clamp(0, height);
bottomRight.X = (GetMaxX(bitmap) + 1).Clamp(0, width);
bottomRight.Y = Numerics.Clamp(GetMaxY(bitmap) + 1, 0, height);
bottomRight.X = Numerics.Clamp(GetMaxX(bitmap) + 1, 0, width);
return GetBoundingRectangle(topLeft, bottomRight);
}

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

@ -190,7 +190,7 @@ namespace SixLabors.ImageSharp
}
[MethodImpl(InliningOptions.ShortMethod)]
private static byte ConvertToByte(float f) => (byte)ComparableExtensions.Clamp((f * 255f) + 0.5f, 0, 255f);
private static byte ConvertToByte(float f) => (byte)Numerics.Clamp((f * 255F) + 0.5F, 0, 255F);
[Conditional("DEBUG")]
private static void VerifyHasVector8(string operation)

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;

2
src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs

@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Formats.Png
byte bitDepth;
if (options.ColorType == PngColorType.Palette)
{
byte quantizedBits = (byte)ImageMath.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length).Clamp(1, 8);
byte quantizedBits = (byte)Numerics.Clamp(ImageMath.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length), 1, 8);
byte bits = Math.Max((byte)options.BitDepth, quantizedBits);
// Png only supports in four pixel depths: 1, 2, 4, and 8 bits when using the PLTE chunk

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

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;

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

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

8
src/ImageSharp/Primitives/Number.cs

@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp
{
return number.isSigned
? number.signedValue
: (int)number.unsignedValue.Clamp(0, int.MaxValue);
: (int)Numerics.Clamp(number.unsignedValue, 0, int.MaxValue);
}
/// <summary>
@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp
public static explicit operator uint(Number number)
{
return number.isSigned
? (uint)number.signedValue.Clamp(0, int.MaxValue)
? (uint)Numerics.Clamp(number.signedValue, 0, int.MaxValue)
: number.unsignedValue;
}
@ -91,8 +91,8 @@ namespace SixLabors.ImageSharp
public static explicit operator ushort(Number number)
{
return number.isSigned
? (ushort)number.signedValue.Clamp(ushort.MinValue, ushort.MaxValue)
: (ushort)number.unsignedValue.Clamp(ushort.MinValue, ushort.MaxValue);
? (ushort)Numerics.Clamp(number.signedValue, ushort.MinValue, ushort.MaxValue)
: (ushort)Numerics.Clamp(number.unsignedValue, ushort.MinValue, ushort.MaxValue);
}
/// <summary>

8
src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs

@ -165,10 +165,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
int spread = 256 / bitDepth;
float factor = spread * this.thresholdMatrix[y % this.modulusY, x % this.modulusX] * scale;
attempt.R = (byte)(rgba.R + factor).Clamp(byte.MinValue, byte.MaxValue);
attempt.G = (byte)(rgba.G + factor).Clamp(byte.MinValue, byte.MaxValue);
attempt.B = (byte)(rgba.B + factor).Clamp(byte.MinValue, byte.MaxValue);
attempt.A = (byte)(rgba.A + factor).Clamp(byte.MinValue, byte.MaxValue);
attempt.R = (byte)Numerics.Clamp(rgba.R + factor, byte.MinValue, byte.MaxValue);
attempt.G = (byte)Numerics.Clamp(rgba.G + factor, byte.MinValue, byte.MaxValue);
attempt.B = (byte)Numerics.Clamp(rgba.B + factor, byte.MinValue, byte.MaxValue);
attempt.A = (byte)Numerics.Clamp(rgba.A + factor, byte.MinValue, byte.MaxValue);
TPixel result = default;
result.FromRgba32(attempt);

2
src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs

@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
Guard.MustBeGreaterThan(palette.Length, 0, nameof(palette));
Guard.NotNull(dither, nameof(dither));
this.Dither = dither;
this.DitherScale = ditherScale.Clamp(QuantizerConstants.MinDitherScale, QuantizerConstants.MaxDitherScale);
this.DitherScale = Numerics.Clamp(ditherScale, QuantizerConstants.MinDitherScale, QuantizerConstants.MaxDitherScale);
this.Palette = palette;
}

5
src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs

@ -137,8 +137,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
int fyr = fy - this.radius;
int offsetY = y + fyr;
offsetY = offsetY.Clamp(0, maxY);
offsetY = Numerics.Clamp(offsetY, 0, maxY);
Span<TPixel> sourceOffsetRow = this.source.GetPixelRowSpan(offsetY);
@ -146,7 +145,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
int fxr = fx - this.radius;
int offsetX = x + fxr;
offsetX = offsetX.Clamp(0, maxX);
offsetX = Numerics.Clamp(offsetX, 0, maxX);
var vector = sourceOffsetRow[offsetX].ToVector4();

2
src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs

@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
for (int i = 0; i < this.bounds.Width; i++)
{
float distance = Vector2.Distance(this.center, new Vector2(i + this.bounds.X, y));
span[i] = (this.blendPercent * (1 - (.95F * (distance / this.maxDistance)))).Clamp(0, 1);
span[i] = Numerics.Clamp(this.blendPercent * (1 - (.95F * (distance / this.maxDistance))), 0, 1F);
}
Span<TPixel> destination = this.source.GetPixelRowSpan(y).Slice(this.bounds.X, this.bounds.Width);

2
src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs

@ -110,7 +110,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
for (int i = 0; i < this.bounds.Width; i++)
{
float distance = Vector2.Distance(this.center, new Vector2(i + this.bounds.X, y));
span[i] = (this.blendPercent * (.9F * (distance / this.maxDistance))).Clamp(0, 1);
span[i] = Numerics.Clamp(this.blendPercent * (.9F * (distance / this.maxDistance)), 0, 1F);
}
Span<TPixel> destination = this.source.GetPixelRowSpan(y).Slice(this.bounds.X, this.bounds.Width);

2
src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs

@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
this.Options = options;
this.maxColors = this.Options.MaxColors;
this.octree = new Octree(ImageMath.GetBitsNeededForColorDepth(this.maxColors).Clamp(1, 8));
this.octree = new Octree(Numerics.Clamp(ImageMath.GetBitsNeededForColorDepth(this.maxColors), 1, 8));
this.paletteOwner = configuration.MemoryAllocator.Allocate<TPixel>(this.maxColors, AllocationOptions.Clean);
this.palette = default;
this.pixelMap = default;

4
src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs

@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
public float DitherScale
{
get { return this.ditherScale; }
set { this.ditherScale = value.Clamp(QuantizerConstants.MinDitherScale, QuantizerConstants.MaxDitherScale); }
set { this.ditherScale = Numerics.Clamp(value, QuantizerConstants.MinDitherScale, QuantizerConstants.MaxDitherScale); }
}
/// <summary>
@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
public int MaxColors
{
get { return this.maxColors; }
set { this.maxColors = value.Clamp(QuantizerConstants.MinColors, QuantizerConstants.MaxColors); }
set { this.maxColors = Numerics.Clamp(value, QuantizerConstants.MinColors, QuantizerConstants.MaxColors); }
}
}
}

19
tests/ImageSharp.Benchmarks/Color/YcbCrToRgb.cs

@ -1,12 +1,11 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks
{
using System.Numerics;
using BenchmarkDotNet.Attributes;
public class YcbCrToRgb
{
[Benchmark(Baseline = true, Description = "Floating Point Conversion")]
@ -19,9 +18,9 @@ namespace SixLabors.ImageSharp.Benchmarks
int ccb = cb - 128;
int ccr = cr - 128;
byte r = (byte)(y + (1.402F * ccr)).Clamp(0, 255);
byte g = (byte)(y - (0.34414F * ccb) - (0.71414F * ccr)).Clamp(0, 255);
byte b = (byte)(y + (1.772F * ccb)).Clamp(0, 255);
byte r = (byte)Numerics.Clamp(y + (1.402F * ccr), 0, 255);
byte g = (byte)Numerics.Clamp(y - (0.34414F * ccb) - (0.71414F * ccr), 0, 255);
byte b = (byte)Numerics.Clamp(y + (1.772F * ccb), 0, 255);
return new Vector3(r, g, b);
}
@ -42,9 +41,9 @@ namespace SixLabors.ImageSharp.Benchmarks
int g1 = 731 * ccr; // (0.71414F * 1024) + .5F
int b0 = 1815 * ccb; // (1.772F * 1024) + .5F
byte r = (byte)(y + (r0 >> 10)).Clamp(0, 255);
byte g = (byte)(y - (g0 >> 10) - (g1 >> 10)).Clamp(0, 255);
byte b = (byte)(y + (b0 >> 10)).Clamp(0, 255);
byte r = (byte)Numerics.Clamp(y + (r0 >> 10), 0, 255);
byte g = (byte)Numerics.Clamp(y - (g0 >> 10) - (g1 >> 10), 0, 255);
byte b = (byte)Numerics.Clamp(y + (b0 >> 10), 0, 255);
return new Vector3(r, g, b);
}

2
tests/ImageSharp.Benchmarks/General/BasicMath/ClampSpan.cs

@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General.BasicMath
for (int i = 0; i < A.Length; i++)
{
ref int x = ref A[i];
x = x.Clamp(64, 128);
x = Numerics.Clamp(x, 64, 128);
}
}

Loading…
Cancel
Save