|
|
|
@ -1,10 +1,10 @@ |
|
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
using System; |
|
|
|
using System.Buffers; |
|
|
|
using System.Numerics; |
|
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
{ |
|
|
|
@ -27,25 +27,6 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
/// <returns>The final pixel value after composition.</returns>
|
|
|
|
public abstract TPixel Blend(TPixel background, TPixel source, float amount); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Blends 2 rows together
|
|
|
|
/// </summary>
|
|
|
|
/// <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>
|
|
|
|
/// <param name="amount">
|
|
|
|
/// A span with values between 0 and 1 indicating the weight of the second source vector.
|
|
|
|
/// At amount = 0, "background" is returned, at amount = 1, "source" is returned.
|
|
|
|
/// </param>
|
|
|
|
public void Blend( |
|
|
|
Configuration configuration, |
|
|
|
Span<TPixel> destination, |
|
|
|
ReadOnlySpan<TPixel> background, |
|
|
|
ReadOnlySpan<TPixel> source, |
|
|
|
ReadOnlySpan<float> amount) |
|
|
|
=> this.Blend<TPixel>(configuration, destination, background, source, amount); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Blends 2 rows together
|
|
|
|
/// </summary>
|
|
|
|
@ -55,7 +36,7 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
/// <param name="background">the background span</param>
|
|
|
|
/// <param name="source">the source span</param>
|
|
|
|
/// <param name="amount">
|
|
|
|
/// A span with values between 0 and 1 indicating the weight of the second source vector.
|
|
|
|
/// A value between 0 and 1 indicating the weight of the second source vector.
|
|
|
|
/// At amount = 0, "background" is returned, at amount = 1, "source" is returned.
|
|
|
|
/// </param>
|
|
|
|
public void Blend<TPixelSrc>( |
|
|
|
@ -63,12 +44,12 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
Span<TPixel> destination, |
|
|
|
ReadOnlySpan<TPixel> background, |
|
|
|
ReadOnlySpan<TPixelSrc> source, |
|
|
|
ReadOnlySpan<float> amount) |
|
|
|
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)); |
|
|
|
Guard.MustBeBetweenOrEqualTo(amount, 0, 1, nameof(amount)); |
|
|
|
|
|
|
|
using (IMemoryOwner<Vector4> buffer = |
|
|
|
configuration.MemoryAllocator.Allocate<Vector4>(destination.Length * 3)) |
|
|
|
@ -89,6 +70,25 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Blends 2 rows together
|
|
|
|
/// </summary>
|
|
|
|
/// <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>
|
|
|
|
/// <param name="amount">
|
|
|
|
/// A span with values between 0 and 1 indicating the weight of the second source vector.
|
|
|
|
/// At amount = 0, "background" is returned, at amount = 1, "source" is returned.
|
|
|
|
/// </param>
|
|
|
|
public void Blend( |
|
|
|
Configuration configuration, |
|
|
|
Span<TPixel> destination, |
|
|
|
ReadOnlySpan<TPixel> background, |
|
|
|
ReadOnlySpan<TPixel> source, |
|
|
|
ReadOnlySpan<float> amount) |
|
|
|
=> this.Blend<TPixel>(configuration, destination, background, source, amount); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Blends 2 rows together
|
|
|
|
/// </summary>
|
|
|
|
@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
/// <param name="background">the background span</param>
|
|
|
|
/// <param name="source">the source span</param>
|
|
|
|
/// <param name="amount">
|
|
|
|
/// A value between 0 and 1 indicating the weight of the second source vector.
|
|
|
|
/// A span with values between 0 and 1 indicating the weight of the second source vector.
|
|
|
|
/// At amount = 0, "background" is returned, at amount = 1, "source" is returned.
|
|
|
|
/// </param>
|
|
|
|
public void Blend<TPixelSrc>( |
|
|
|
@ -106,12 +106,12 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
Span<TPixel> destination, |
|
|
|
ReadOnlySpan<TPixel> background, |
|
|
|
ReadOnlySpan<TPixelSrc> source, |
|
|
|
float amount) |
|
|
|
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.MustBeBetweenOrEqualTo(amount, 0, 1, nameof(amount)); |
|
|
|
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); |
|
|
|
|
|
|
|
using (IMemoryOwner<Vector4> buffer = |
|
|
|
configuration.MemoryAllocator.Allocate<Vector4>(destination.Length * 3)) |
|
|
|
|