|
|
|
@ -4,8 +4,8 @@ |
|
|
|
using System; |
|
|
|
using System.Buffers; |
|
|
|
using System.Numerics; |
|
|
|
|
|
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
using SixLabors.Memory; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
{ |
|
|
|
@ -38,7 +38,11 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
/// A value between 0 and 1 indicating the weight of the second source vector.
|
|
|
|
/// At amount = 0, "from" is returned, at amount = 1, "to" is returned.
|
|
|
|
/// </param>
|
|
|
|
protected abstract void BlendFunction(Span<Vector4> destination, ReadOnlySpan<Vector4> background, ReadOnlySpan<Vector4> source, float amount); |
|
|
|
protected abstract void BlendFunction( |
|
|
|
Span<Vector4> destination, |
|
|
|
ReadOnlySpan<Vector4> background, |
|
|
|
ReadOnlySpan<Vector4> source, |
|
|
|
float amount); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Blend 2 rows together.
|
|
|
|
@ -50,12 +54,16 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
/// A span with values between 0 and 1 indicating the weight of the second source vector.
|
|
|
|
/// At amount = 0, "from" is returned, at amount = 1, "to" is returned.
|
|
|
|
/// </param>
|
|
|
|
protected abstract void BlendFunction(Span<Vector4> destination, ReadOnlySpan<Vector4> background, ReadOnlySpan<Vector4> source, ReadOnlySpan<float> amount); |
|
|
|
protected abstract void BlendFunction( |
|
|
|
Span<Vector4> destination, |
|
|
|
ReadOnlySpan<Vector4> background, |
|
|
|
ReadOnlySpan<Vector4> source, |
|
|
|
ReadOnlySpan<float> amount); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Blends 2 rows together
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="memoryManager">memory manager to use internally</param>
|
|
|
|
/// <param name="configuration"><see cref="Configuration"/> to use internally</param>
|
|
|
|
/// <param name="destination">the destination span</param>
|
|
|
|
/// <param name="background">the background span</param>
|
|
|
|
/// <param name="source">the source span</param>
|
|
|
|
@ -63,16 +71,21 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
/// A span with values between 0 and 1 indicating the weight of the second source vector.
|
|
|
|
/// At amount = 0, "from" is returned, at amount = 1, "to" is returned.
|
|
|
|
/// </param>
|
|
|
|
public void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, ReadOnlySpan<TPixel> background, ReadOnlySpan<TPixel> source, ReadOnlySpan<float> amount) |
|
|
|
public void Blend( |
|
|
|
Configuration configuration, |
|
|
|
Span<TPixel> destination, |
|
|
|
ReadOnlySpan<TPixel> background, |
|
|
|
ReadOnlySpan<TPixel> source, |
|
|
|
ReadOnlySpan<float> amount) |
|
|
|
{ |
|
|
|
this.Blend<TPixel>(memoryManager, destination, background, source, amount); |
|
|
|
this.Blend<TPixel>(configuration, destination, background, source, amount); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Blends 2 rows together
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TPixelSrc">the pixel format of the source span</typeparam>
|
|
|
|
/// <param name="memoryManager">memory manager to use internally</param>
|
|
|
|
/// <param name="configuration"><see cref="Configuration"/> to use internally</param>
|
|
|
|
/// <param name="destination">the destination span</param>
|
|
|
|
/// <param name="background">the background span</param>
|
|
|
|
/// <param name="source">the source span</param>
|
|
|
|
@ -80,25 +93,40 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
/// A span with values between 0 and 1 indicating the weight of the second source vector.
|
|
|
|
/// At amount = 0, "from" is returned, at amount = 1, "to" is returned.
|
|
|
|
/// </param>
|
|
|
|
public void Blend<TPixelSrc>(MemoryAllocator memoryManager, Span<TPixel> destination, ReadOnlySpan<TPixel> background, ReadOnlySpan<TPixelSrc> source, ReadOnlySpan<float> amount) |
|
|
|
public void Blend<TPixelSrc>( |
|
|
|
Configuration configuration, |
|
|
|
Span<TPixel> destination, |
|
|
|
ReadOnlySpan<TPixel> background, |
|
|
|
ReadOnlySpan<TPixelSrc> source, |
|
|
|
ReadOnlySpan<float> amount) |
|
|
|
where TPixelSrc : struct, IPixel<TPixelSrc> |
|
|
|
{ |
|
|
|
Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); |
|
|
|
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); |
|
|
|
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); |
|
|
|
|
|
|
|
using (IMemoryOwner<Vector4> buffer = memoryManager.Allocate<Vector4>(destination.Length * 3)) |
|
|
|
using (IMemoryOwner<Vector4> buffer = |
|
|
|
configuration.MemoryAllocator.Allocate<Vector4>(destination.Length * 3)) |
|
|
|
{ |
|
|
|
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); |
|
|
|
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); |
|
|
|
Span<Vector4> sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); |
|
|
|
|
|
|
|
PixelOperations<TPixel>.Instance.ToScaledVector4(background.Slice(0, background.Length), backgroundSpan); |
|
|
|
PixelOperations<TPixelSrc>.Instance.ToScaledVector4(source.Slice(0, background.Length), sourceSpan); |
|
|
|
PixelOperations<TPixel>.Instance.ToScaledVector4( |
|
|
|
configuration, |
|
|
|
background.Slice(0, background.Length), |
|
|
|
backgroundSpan); |
|
|
|
PixelOperations<TPixelSrc>.Instance.ToScaledVector4( |
|
|
|
configuration, |
|
|
|
source.Slice(0, background.Length), |
|
|
|
sourceSpan); |
|
|
|
|
|
|
|
this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount); |
|
|
|
|
|
|
|
PixelOperations<TPixel>.Instance.FromScaledVector4(destinationSpan.Slice(0, background.Length), destination); |
|
|
|
PixelOperations<TPixel>.Instance.FromScaledVector4( |
|
|
|
configuration, |
|
|
|
destinationSpan.Slice(0, background.Length), |
|
|
|
destination); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -106,7 +134,7 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
/// Blends 2 rows together
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TPixelSrc">the pixel format of the source span</typeparam>
|
|
|
|
/// <param name="memoryManager">memory manager to use internally</param>
|
|
|
|
/// <param name="configuration"><see cref="Configuration"/> to use internally</param>
|
|
|
|
/// <param name="destination">the destination span</param>
|
|
|
|
/// <param name="background">the background span</param>
|
|
|
|
/// <param name="source">the source span</param>
|
|
|
|
@ -114,26 +142,41 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
/// A value between 0 and 1 indicating the weight of the second source vector.
|
|
|
|
/// At amount = 0, "from" is returned, at amount = 1, "to" is returned.
|
|
|
|
/// </param>
|
|
|
|
public void Blend<TPixelSrc>(MemoryAllocator memoryManager, Span<TPixel> destination, ReadOnlySpan<TPixel> background, ReadOnlySpan<TPixelSrc> source, float amount) |
|
|
|
public void Blend<TPixelSrc>( |
|
|
|
Configuration configuration, |
|
|
|
Span<TPixel> destination, |
|
|
|
ReadOnlySpan<TPixel> background, |
|
|
|
ReadOnlySpan<TPixelSrc> source, |
|
|
|
float amount) |
|
|
|
where TPixelSrc : struct, IPixel<TPixelSrc> |
|
|
|
{ |
|
|
|
Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); |
|
|
|
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); |
|
|
|
Guard.MustBeBetweenOrEqualTo(amount, 0, 1, nameof(amount)); |
|
|
|
|
|
|
|
using (IMemoryOwner<Vector4> buffer = memoryManager.Allocate<Vector4>(destination.Length * 3)) |
|
|
|
using (IMemoryOwner<Vector4> buffer = |
|
|
|
configuration.MemoryAllocator.Allocate<Vector4>(destination.Length * 3)) |
|
|
|
{ |
|
|
|
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); |
|
|
|
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); |
|
|
|
Span<Vector4> sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); |
|
|
|
|
|
|
|
PixelOperations<TPixel>.Instance.ToScaledVector4(background.Slice(0, background.Length), backgroundSpan); |
|
|
|
PixelOperations<TPixelSrc>.Instance.ToScaledVector4(source.Slice(0, background.Length), sourceSpan); |
|
|
|
PixelOperations<TPixel>.Instance.ToScaledVector4( |
|
|
|
configuration, |
|
|
|
background.Slice(0, background.Length), |
|
|
|
backgroundSpan); |
|
|
|
PixelOperations<TPixelSrc>.Instance.ToScaledVector4( |
|
|
|
configuration, |
|
|
|
source.Slice(0, background.Length), |
|
|
|
sourceSpan); |
|
|
|
|
|
|
|
this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount); |
|
|
|
|
|
|
|
PixelOperations<TPixel>.Instance.FromScaledVector4(destinationSpan.Slice(0, background.Length), destination); |
|
|
|
PixelOperations<TPixel>.Instance.FromScaledVector4( |
|
|
|
configuration, |
|
|
|
destinationSpan.Slice(0, background.Length), |
|
|
|
destination); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |