diff --git a/src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs b/src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs
index 8ccbe22ac..a8ee4d90b 100644
--- a/src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs
+++ b/src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs
@@ -1,121 +1,137 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.Processing.Processors.Drawing;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the drawing of images to the type.
- ///
- public static class DrawImageExtensions
- {
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The pixel format.
- /// The image this method extends.
- /// The image to blend with the currently processing image.
- /// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, float opacity)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity));
-
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The pixel format.
- /// The image this method extends.
- /// The image to blend with the currently processing image.
- /// The blending mode.
- /// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelColorBlendingMode colorBlending, float opacity)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity));
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The pixel format.
- /// The image this method extends.
- /// The image to blend with the currently processing image.
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Processing.Processors.Drawing;
+using SixLabors.Primitives;
+
+namespace SixLabors.ImageSharp.Processing
+{
+ ///
+ /// Adds extensions that allow the drawing of images to the type.
+ ///
+ public static class DrawImageExtensions
+ {
+ ///
+ /// Draws the given image together with the current one by blending their pixels.
+ ///
+ /// The pixel format of the destination image.
+ /// The pixel format of the source image.
+ /// The image this method extends.
+ /// The image to blend with the currently processing image.
+ /// The opacity of the image to blend. Must be between 0 and 1.
+ /// The .
+ public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, float opacity)
+ where TPixelDst : struct, IPixel
+ where TPixelSrc : struct, IPixel
+ => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity));
+
+ ///
+ /// Draws the given image together with the current one by blending their pixels.
+ ///
+ /// The pixel format of the destination image.
+ /// The pixel format of the source image.
+ /// The image this method extends.
+ /// The image to blend with the currently processing image.
+ /// The blending mode.
+ /// The opacity of the image to blend. Must be between 0 and 1.
+ /// The .
+ public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelColorBlendingMode colorBlending, float opacity)
+ where TPixelDst : struct, IPixel
+ where TPixelSrc : struct, IPixel
+ => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity));
+
+ ///
+ /// Draws the given image together with the current one by blending their pixels.
+ ///
+ /// The pixel format of the destination image.
+ /// The pixel format of the source image.
+ /// The image this method extends.
+ /// The image to blend with the currently processing image.
/// The color blending mode.
- /// The alpha composition mode.
- /// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, colorBlending, alphaComposition, opacity));
+ /// The alpha composition mode.
+ /// The opacity of the image to blend. Must be between 0 and 1.
+ /// The .
+ public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity)
+ where TPixelDst : struct, IPixel
+ where TPixelSrc : struct, IPixel
+ => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, colorBlending, alphaComposition, opacity));
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The pixel format.
+ ///
+ /// Draws the given image together with the current one by blending their pixels.
+ ///
+ /// The pixel format of the destination image.
+ /// The pixel format of the source image.
/// The image this method extends.
- /// The image to blend with the currently processing image.
+ /// The image to blend with the currently processing image.
/// The options, including the blending type and blending amount.
- /// The .
- public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, GraphicsOptions options)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage));
+ /// The .
+ public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, GraphicsOptions options)
+ where TPixelDst : struct, IPixel
+ where TPixelSrc : struct, IPixel
+ => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage));
- ///
- /// Draws the given image together with the current one by blending their pixels.
+ ///
+ /// Draws the given image together with the current one by blending their pixels.
///
- /// The pixel format.
- /// The image this method extends.
+ /// The pixel format of the destination image.
+ /// The pixel format of the source image.
+ /// The image this method extends.
/// The image to blend with the currently processing image.
- /// The location to draw the blended image.
+ /// The location to draw the blended image.
/// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, float opacity)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new DrawImageProcessor(image, location, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity));
+ /// The .
+ public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, float opacity)
+ where TPixelDst : struct, IPixel
+ where TPixelSrc : struct, IPixel
+ => source.ApplyProcessor(new DrawImageProcessor(image, location, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity));
- ///
- /// Draws the given image together with the current one by blending their pixels.
+ ///
+ /// Draws the given image together with the current one by blending their pixels.
///
- /// The pixel format.
- /// The image this method extends.
+ /// The pixel format of the destination image.
+ /// The pixel format of the source image.
+ /// The image this method extends.
/// The image to blend with the currently processing image.
- /// The location to draw the blended image.
- /// The color blending to apply.
+ /// The location to draw the blended image.
+ /// The color blending to apply.
/// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, PixelColorBlendingMode colorBlending, float opacity)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new DrawImageProcessor(image, location, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity));
+ /// The .
+ public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, PixelColorBlendingMode colorBlending, float opacity)
+ where TPixelDst : struct, IPixel
+ where TPixelSrc : struct, IPixel
+ => source.ApplyProcessor(new DrawImageProcessor(image, location, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity));
- ///
- /// Draws the given image together with the current one by blending their pixels.
+ ///
+ /// Draws the given image together with the current one by blending their pixels.
///
- /// The pixel format.
- /// The image this method extends.
+ /// The pixel format of the destination image.
+ /// The pixel format of the source image.
+ /// The image this method extends.
/// The image to blend with the currently processing image.
- /// The location to draw the blended image.
+ /// The location to draw the blended image.
/// The color blending to apply.
- /// The alpha composition mode.
+ /// The alpha composition mode.
/// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new DrawImageProcessor(image, location, colorBlending, alphaComposition, opacity));
+ /// The .
+ public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity)
+ where TPixelDst : struct, IPixel
+ where TPixelSrc : struct, IPixel
+ => source.ApplyProcessor(new DrawImageProcessor(image, location, colorBlending, alphaComposition, opacity));
- ///
- /// Draws the given image together with the current one by blending their pixels.
+ ///
+ /// Draws the given image together with the current one by blending their pixels.
///
- /// The pixel format.
+ /// The pixel format of the destination image.
+ /// The pixel format of the source image.
/// The image this method extends.
/// The image to blend with the currently processing image.
/// The location to draw the blended image.
- /// The options containing the blend mode and opacity.
- /// The .
- public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, GraphicsOptions options)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new DrawImageProcessor(image, location, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage));
- }
+ /// The options containing the blend mode and opacity.
+ /// The .
+ public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, GraphicsOptions options)
+ where TPixelDst : struct, IPixel
+ where TPixelSrc : struct, IPixel
+ => source.ApplyProcessor(new DrawImageProcessor(image, location, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage));
+ }
}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs
index 324d25e09..4e6018e07 100644
--- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs
+++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs
@@ -15,32 +15,34 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
///
/// Combines two images together by blending the pixels.
///
- /// The pixel format.
- internal class DrawImageProcessor : ImageProcessor
- where TPixel : struct, IPixel
+ /// The pixel format of destination image.
+ /// The pixel format os source image.
+ internal class DrawImageProcessor : ImageProcessor
+ where TPixelDst : struct, IPixel
+ where TPixelSrc : struct, IPixel
{
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The image to blend with the currently processing image.
/// The location to draw the blended image.
/// The blending mode to use when drawing the image.
/// The Alpha blending mode to use when drawing the image.
/// The opacity of the image to blend. Must be between 0 and 1.
- public DrawImageProcessor(Image image, Point location, PixelColorBlendingMode colorBlendingMode, PixelAlphaCompositionMode alphaCompositionMode, float opacity)
+ public DrawImageProcessor(Image image, Point location, PixelColorBlendingMode colorBlendingMode, PixelAlphaCompositionMode alphaCompositionMode, float opacity)
{
Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
this.Image = image;
this.Opacity = opacity;
- this.Blender = PixelOperations.Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode);
+ this.Blender = PixelOperations.Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode);
this.Location = location;
}
///
/// Gets the image to blend
///
- public Image Image { get; }
+ public Image Image { get; }
///
/// Gets the opacity of the image to blend
@@ -50,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
///
/// Gets the pixel blender
///
- public PixelBlender Blender { get; }
+ public PixelBlender Blender { get; }
///
/// Gets the location to draw the blended image
@@ -58,10 +60,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
public Point Location { get; }
///
- protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
+ protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- Image targetImage = this.Image;
- PixelBlender blender = this.Blender;
+ Image targetImage = this.Image;
+ PixelBlender blender = this.Blender;
int locationY = this.Location.Y;
// Align start/end positions.
@@ -76,23 +78,18 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
int width = maxX - minX;
- MemoryAllocator memoryAllocator = this.Image.GetConfiguration().MemoryAllocator;
-
- using (IMemoryOwner amount = memoryAllocator.Allocate(width))
- {
- amount.GetSpan().Fill(this.Opacity);
-
- ParallelFor.WithConfiguration(
- minY,
- maxY,
- configuration,
- y =>
- {
- Span background = source.GetPixelRowSpan(y).Slice(minX, width);
- Span foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width);
- blender.Blend(memoryAllocator, background, background, foreground, amount.GetSpan());
- });
- }
+ MemoryAllocator memoryAllocator = this.Image.GetConfiguration().MemoryAllocator;
+
+ ParallelFor.WithConfiguration(
+ minY,
+ maxY,
+ configuration,
+ y =>
+ {
+ Span background = source.GetPixelRowSpan(y).Slice(minX, width);
+ Span foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width);
+ blender.Blend(memoryAllocator, background, background, foreground, this.Opacity);
+ });
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
index 9b1e29db8..19d1c5dad 100644
--- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
@@ -1,4242 +1,3926 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-//
-using System;
-using System.Numerics;
-using System.Buffers;
-
-using SixLabors.ImageSharp.Memory;
-using SixLabors.Memory;
-
-namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
-{
- ///
- /// Collection of Porter Duff alpha blending functions applying different composition models.
- ///
- ///
- /// These functions are designed to be a general solution for all color cases,
- /// that is, they take in account the alpha value of both the backdrop
- /// and source, and there's no need to alpha-premultiply neither the backdrop
- /// nor the source.
- /// Note there are faster functions for when the backdrop color is known
- /// to be opaque
- ///
- internal static class DefaultPixelBlenders
- where TPixel : struct, IPixel
- {
-
- internal class NormalSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static NormalSrc Instance { get; } = new NormalSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- return PorterDuffFunctions.NormalSrc(background, source, amount);
- }
-
- ///
- public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount)
- {
- 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 buffer = memoryManager.Allocate(destination.Length * 3))
- {
- Span destinationSpan = buffer.Slice(0, destination.Length);
- Span backgroundSpan = buffer.Slice(destination.Length, destination.Length);
- Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
-
- PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length);
- PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length);
-
- for (int i = 0; i < destination.Length; i++)
- {
- destinationSpan[i] = PorterDuffFunctions.NormalSrc(backgroundSpan[i], sourceSpan[i], amount[i]);
- }
-
- PixelOperations.Instance.PackFromVector4(destinationSpan, destination, destination.Length);
- }
- }
- }
-
- internal class MultiplySrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static MultiplySrc Instance { get; } = new MultiplySrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- return PorterDuffFunctions.MultiplySrc(background, source, amount);
- }
-
- ///
- public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount)
- {
- 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 buffer = memoryManager.Allocate(destination.Length * 3))
- {
- Span destinationSpan = buffer.Slice(0, destination.Length);
- Span backgroundSpan = buffer.Slice(destination.Length, destination.Length);
- Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
-
- PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length);
- PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length);
-
- for (int i = 0; i < destination.Length; i++)
- {
- destinationSpan[i] = PorterDuffFunctions.MultiplySrc(backgroundSpan[i], sourceSpan[i], amount[i]);
- }
-
- PixelOperations.Instance.PackFromVector4(destinationSpan, destination, destination.Length);
- }
- }
- }
-
- internal class AddSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static AddSrc Instance { get; } = new AddSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- return PorterDuffFunctions.AddSrc(background, source, amount);
- }
-
- ///
- public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount)
- {
- 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 buffer = memoryManager.Allocate(destination.Length * 3))
- {
- Span destinationSpan = buffer.Slice(0, destination.Length);
- Span backgroundSpan = buffer.Slice(destination.Length, destination.Length);
- Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
-
- PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length);
- PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length);
-
- for (int i = 0; i < destination.Length; i++)
- {
- destinationSpan[i] = PorterDuffFunctions.AddSrc(backgroundSpan[i], sourceSpan[i], amount[i]);
- }
-
- PixelOperations.Instance.PackFromVector4(destinationSpan, destination, destination.Length);
- }
- }
- }
-
- internal class SubtractSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static SubtractSrc Instance { get; } = new SubtractSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- return PorterDuffFunctions.SubtractSrc(background, source, amount);
- }
-
- ///
- public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount)
- {
- 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 buffer = memoryManager.Allocate(destination.Length * 3))
- {
- Span destinationSpan = buffer.Slice(0, destination.Length);
- Span backgroundSpan = buffer.Slice(destination.Length, destination.Length);
- Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
-
- PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length);
- PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length);
-
- for (int i = 0; i < destination.Length; i++)
- {
- destinationSpan[i] = PorterDuffFunctions.SubtractSrc(backgroundSpan[i], sourceSpan[i], amount[i]);
- }
-
- PixelOperations.Instance.PackFromVector4(destinationSpan, destination, destination.Length);
- }
- }
- }
-
- internal class ScreenSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static ScreenSrc Instance { get; } = new ScreenSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- return PorterDuffFunctions.ScreenSrc(background, source, amount);
- }
-
- ///
- public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount)
- {
- 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 buffer = memoryManager.Allocate(destination.Length * 3))
- {
- Span destinationSpan = buffer.Slice(0, destination.Length);
- Span backgroundSpan = buffer.Slice(destination.Length, destination.Length);
- Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
-
- PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length);
- PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length);
-
- for (int i = 0; i < destination.Length; i++)
- {
- destinationSpan[i] = PorterDuffFunctions.ScreenSrc(backgroundSpan[i], sourceSpan[i], amount[i]);
- }
-
- PixelOperations.Instance.PackFromVector4(destinationSpan, destination, destination.Length);
- }
- }
- }
-
- internal class DarkenSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static DarkenSrc Instance { get; } = new DarkenSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- return PorterDuffFunctions.DarkenSrc(background, source, amount);
- }
-
- ///
- public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount)
- {
- 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 buffer = memoryManager.Allocate(destination.Length * 3))
- {
- Span destinationSpan = buffer.Slice(0, destination.Length);
- Span backgroundSpan = buffer.Slice(destination.Length, destination.Length);
- Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
-
- PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length);
- PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length);
-
- for (int i = 0; i < destination.Length; i++)
- {
- destinationSpan[i] = PorterDuffFunctions.DarkenSrc(backgroundSpan[i], sourceSpan[i], amount[i]);
- }
-
- PixelOperations.Instance.PackFromVector4(destinationSpan, destination, destination.Length);
- }
- }
- }
-
- internal class LightenSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static LightenSrc Instance { get; } = new LightenSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- return PorterDuffFunctions.LightenSrc(background, source, amount);
- }
-
- ///
- public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount)
- {
- 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 buffer = memoryManager.Allocate(destination.Length * 3))
- {
- Span destinationSpan = buffer.Slice(0, destination.Length);
- Span backgroundSpan = buffer.Slice(destination.Length, destination.Length);
- Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
-
- PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length);
- PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length);
-
- for (int i = 0; i < destination.Length; i++)
- {
- destinationSpan[i] = PorterDuffFunctions.LightenSrc(backgroundSpan[i], sourceSpan[i], amount[i]);
- }
-
- PixelOperations.Instance.PackFromVector4(destinationSpan, destination, destination.Length);
- }
- }
- }
-
- internal class OverlaySrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static OverlaySrc Instance { get; } = new OverlaySrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- return PorterDuffFunctions.OverlaySrc(background, source, amount);
- }
-
- ///
- public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount)
- {
- 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 buffer = memoryManager.Allocate(destination.Length * 3))
- {
- Span destinationSpan = buffer.Slice(0, destination.Length);
- Span backgroundSpan = buffer.Slice(destination.Length, destination.Length);
- Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
-
- PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length);
- PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length);
-
- for (int i = 0; i < destination.Length; i++)
- {
- destinationSpan[i] = PorterDuffFunctions.OverlaySrc(backgroundSpan[i], sourceSpan[i], amount[i]);
- }
-
- PixelOperations.Instance.PackFromVector4(destinationSpan, destination, destination.Length);
- }
- }
- }
-
- internal class HardLightSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static HardLightSrc Instance { get; } = new HardLightSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- return PorterDuffFunctions.HardLightSrc(background, source, amount);
- }
-
- ///
- public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount)
- {
- 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 buffer = memoryManager.Allocate(destination.Length * 3))
- {
- Span destinationSpan = buffer.Slice(0, destination.Length);
- Span backgroundSpan = buffer.Slice(destination.Length, destination.Length);
- Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
-
- PixelOperations