Browse Source

Update field names and fix assignment bug

pull/2995/head
James Jackson-South 4 months ago
parent
commit
74e8321cd5
  1. 128
      src/ImageSharp/Processing/Extensions/Drawing/DrawImageExtensions.cs
  2. 18
      src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor.cs
  3. 31
      src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs

128
src/ImageSharp/Processing/Extensions/Drawing/DrawImageExtensions.cs

@ -17,15 +17,19 @@ public static class DrawImageExtensions
/// <param name="source">The current image processing context.</param> /// <param name="source">The current image processing context.</param>
/// <param name="foreground">The image to draw on the currently processing image.</param> /// <param name="foreground">The image to draw on the currently processing image.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
Image foreground, Image foreground,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount = 0)
{ {
GraphicsOptions options = source.GetGraphicsOptions(); GraphicsOptions options = source.GetGraphicsOptions();
return DrawImage(source, foreground, options.ColorBlendingMode, options.AlphaCompositionMode, opacity, repeatCount); return DrawImage(source, foreground, options.ColorBlendingMode, options.AlphaCompositionMode, opacity, foregroundRepeatCount);
} }
/// <summary> /// <summary>
@ -35,16 +39,20 @@ public static class DrawImageExtensions
/// <param name="foreground">The image to draw on the currently processing image.</param> /// <param name="foreground">The image to draw on the currently processing image.</param>
/// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param> /// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
Image foreground, Image foreground,
Rectangle foregroundRectangle, Rectangle foregroundRectangle,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount = 0)
{ {
GraphicsOptions options = source.GetGraphicsOptions(); GraphicsOptions options = source.GetGraphicsOptions();
return DrawImage(source, foreground, foregroundRectangle, options.ColorBlendingMode, options.AlphaCompositionMode, opacity, repeatCount); return DrawImage(source, foreground, foregroundRectangle, options.ColorBlendingMode, options.AlphaCompositionMode, opacity, foregroundRepeatCount);
} }
/// <summary> /// <summary>
@ -54,14 +62,18 @@ public static class DrawImageExtensions
/// <param name="foreground">The image to draw on the currently processing image.</param> /// <param name="foreground">The image to draw on the currently processing image.</param>
/// <param name="colorBlending">The color blending mode.</param> /// <param name="colorBlending">The color blending mode.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
Image foreground, Image foreground,
PixelColorBlendingMode colorBlending, PixelColorBlendingMode colorBlending,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, colorBlending, opacity, repeatCount); => DrawImage(source, foreground, Point.Empty, colorBlending, opacity, foregroundRepeatCount);
/// <summary> /// <summary>
/// Draws the given image together with the currently processing image by blending their pixels. /// Draws the given image together with the currently processing image by blending their pixels.
@ -71,6 +83,10 @@ public static class DrawImageExtensions
/// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param> /// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param>
/// <param name="colorBlending">The color blending mode.</param> /// <param name="colorBlending">The color blending mode.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
@ -78,8 +94,8 @@ public static class DrawImageExtensions
Rectangle foregroundRectangle, Rectangle foregroundRectangle,
PixelColorBlendingMode colorBlending, PixelColorBlendingMode colorBlending,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, foregroundRectangle, colorBlending, opacity, repeatCount); => DrawImage(source, foreground, Point.Empty, foregroundRectangle, colorBlending, opacity, foregroundRepeatCount);
/// <summary> /// <summary>
/// Draws the given image together with the currently processing image by blending their pixels. /// Draws the given image together with the currently processing image by blending their pixels.
@ -89,6 +105,10 @@ public static class DrawImageExtensions
/// <param name="colorBlending">The color blending mode.</param> /// <param name="colorBlending">The color blending mode.</param>
/// <param name="alphaComposition">The alpha composition mode.</param> /// <param name="alphaComposition">The alpha composition mode.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
@ -96,8 +116,8 @@ public static class DrawImageExtensions
PixelColorBlendingMode colorBlending, PixelColorBlendingMode colorBlending,
PixelAlphaCompositionMode alphaComposition, PixelAlphaCompositionMode alphaComposition,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, colorBlending, alphaComposition, opacity, repeatCount); => DrawImage(source, foreground, Point.Empty, colorBlending, alphaComposition, opacity, foregroundRepeatCount);
/// <summary> /// <summary>
/// Draws the given image together with the currently processing image by blending their pixels. /// Draws the given image together with the currently processing image by blending their pixels.
@ -108,6 +128,10 @@ public static class DrawImageExtensions
/// <param name="colorBlending">The color blending mode.</param> /// <param name="colorBlending">The color blending mode.</param>
/// <param name="alphaComposition">The alpha composition mode.</param> /// <param name="alphaComposition">The alpha composition mode.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
@ -116,8 +140,8 @@ public static class DrawImageExtensions
PixelColorBlendingMode colorBlending, PixelColorBlendingMode colorBlending,
PixelAlphaCompositionMode alphaComposition, PixelAlphaCompositionMode alphaComposition,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, foregroundRectangle, colorBlending, alphaComposition, opacity, repeatCount); => DrawImage(source, foreground, Point.Empty, foregroundRectangle, colorBlending, alphaComposition, opacity, foregroundRepeatCount);
/// <summary> /// <summary>
/// Draws the given image together with the currently processing image by blending their pixels. /// Draws the given image together with the currently processing image by blending their pixels.
@ -125,13 +149,17 @@ public static class DrawImageExtensions
/// <param name="source">The current image processing context.</param> /// <param name="source">The current image processing context.</param>
/// <param name="foreground">The image to draw on the currently processing image.</param> /// <param name="foreground">The image to draw on the currently processing image.</param>
/// <param name="options">The options, including the blending type and blending amount.</param> /// <param name="options">The options, including the blending type and blending amount.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
Image foreground, Image foreground,
GraphicsOptions options, GraphicsOptions options,
int repeatCount) int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, options, repeatCount); => DrawImage(source, foreground, Point.Empty, options, foregroundRepeatCount);
/// <summary> /// <summary>
/// Draws the given image together with the currently processing image by blending their pixels. /// Draws the given image together with the currently processing image by blending their pixels.
@ -140,14 +168,18 @@ public static class DrawImageExtensions
/// <param name="foreground">The image to draw on the currently processing image.</param> /// <param name="foreground">The image to draw on the currently processing image.</param>
/// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param> /// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param>
/// <param name="options">The options, including the blending type and blending amount.</param> /// <param name="options">The options, including the blending type and blending amount.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
Image foreground, Image foreground,
Rectangle foregroundRectangle, Rectangle foregroundRectangle,
GraphicsOptions options, GraphicsOptions options,
int repeatCount) int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, foregroundRectangle, options, repeatCount); => DrawImage(source, foreground, Point.Empty, foregroundRectangle, options, foregroundRepeatCount);
/// <summary> /// <summary>
/// Draws the given image together with the currently processing image by blending their pixels. /// Draws the given image together with the currently processing image by blending their pixels.
@ -156,16 +188,20 @@ public static class DrawImageExtensions
/// <param name="foreground">The image to draw on the currently processing image.</param> /// <param name="foreground">The image to draw on the currently processing image.</param>
/// <param name="backgroundLocation">The location on the currently processing image at which to draw.</param> /// <param name="backgroundLocation">The location on the currently processing image at which to draw.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
Image foreground, Image foreground,
Point backgroundLocation, Point backgroundLocation,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount = 0)
{ {
GraphicsOptions options = source.GetGraphicsOptions(); GraphicsOptions options = source.GetGraphicsOptions();
return DrawImage(source, foreground, backgroundLocation, options.ColorBlendingMode, options.AlphaCompositionMode, opacity, repeatCount); return DrawImage(source, foreground, backgroundLocation, options.ColorBlendingMode, options.AlphaCompositionMode, opacity, foregroundRepeatCount);
} }
/// <summary> /// <summary>
@ -176,6 +212,10 @@ public static class DrawImageExtensions
/// <param name="backgroundLocation">The location on the currently processing image at which to draw.</param> /// <param name="backgroundLocation">The location on the currently processing image at which to draw.</param>
/// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param> /// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
@ -183,10 +223,10 @@ public static class DrawImageExtensions
Point backgroundLocation, Point backgroundLocation,
Rectangle foregroundRectangle, Rectangle foregroundRectangle,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount = 0)
{ {
GraphicsOptions options = source.GetGraphicsOptions(); GraphicsOptions options = source.GetGraphicsOptions();
return DrawImage(source, foreground, backgroundLocation, foregroundRectangle, options.ColorBlendingMode, options.AlphaCompositionMode, opacity, repeatCount); return DrawImage(source, foreground, backgroundLocation, foregroundRectangle, options.ColorBlendingMode, options.AlphaCompositionMode, opacity, foregroundRepeatCount);
} }
/// <summary> /// <summary>
@ -197,6 +237,10 @@ public static class DrawImageExtensions
/// <param name="backgroundLocation">The location on the currently processing image at which to draw.</param> /// <param name="backgroundLocation">The location on the currently processing image at which to draw.</param>
/// <param name="colorBlending">The color blending to apply.</param> /// <param name="colorBlending">The color blending to apply.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
@ -204,8 +248,8 @@ public static class DrawImageExtensions
Point backgroundLocation, Point backgroundLocation,
PixelColorBlendingMode colorBlending, PixelColorBlendingMode colorBlending,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, backgroundLocation, colorBlending, source.GetGraphicsOptions().AlphaCompositionMode, opacity, repeatCount); => DrawImage(source, foreground, backgroundLocation, colorBlending, source.GetGraphicsOptions().AlphaCompositionMode, opacity, foregroundRepeatCount);
/// <summary> /// <summary>
/// Draws the given image together with the currently processing image by blending their pixels. /// Draws the given image together with the currently processing image by blending their pixels.
@ -216,6 +260,10 @@ public static class DrawImageExtensions
/// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param> /// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param>
/// <param name="colorBlending">The color blending to apply.</param> /// <param name="colorBlending">The color blending to apply.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
@ -224,8 +272,8 @@ public static class DrawImageExtensions
Rectangle foregroundRectangle, Rectangle foregroundRectangle,
PixelColorBlendingMode colorBlending, PixelColorBlendingMode colorBlending,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, backgroundLocation, foregroundRectangle, colorBlending, source.GetGraphicsOptions().AlphaCompositionMode, opacity, repeatCount); => DrawImage(source, foreground, backgroundLocation, foregroundRectangle, colorBlending, source.GetGraphicsOptions().AlphaCompositionMode, opacity, foregroundRepeatCount);
/// <summary> /// <summary>
/// Draws the given image together with the currently processing image by blending their pixels. /// Draws the given image together with the currently processing image by blending their pixels.
@ -234,14 +282,18 @@ public static class DrawImageExtensions
/// <param name="foreground">The image to draw on the currently processing image.</param> /// <param name="foreground">The image to draw on the currently processing image.</param>
/// <param name="backgroundLocation">The location on the currently processing image at which to draw.</param> /// <param name="backgroundLocation">The location on the currently processing image at which to draw.</param>
/// <param name="options">The options containing the blend mode and opacity.</param> /// <param name="options">The options containing the blend mode and opacity.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
Image foreground, Image foreground,
Point backgroundLocation, Point backgroundLocation,
GraphicsOptions options, GraphicsOptions options,
int repeatCount) int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, backgroundLocation, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage, repeatCount); => DrawImage(source, foreground, backgroundLocation, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage, foregroundRepeatCount);
/// <summary> /// <summary>
/// Draws the given image together with the currently processing image by blending their pixels. /// Draws the given image together with the currently processing image by blending their pixels.
@ -251,6 +303,10 @@ public static class DrawImageExtensions
/// <param name="backgroundLocation">The location on the currently processing image at which to draw.</param> /// <param name="backgroundLocation">The location on the currently processing image at which to draw.</param>
/// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param> /// <param name="foregroundRectangle">The rectangle structure that specifies the portion of the image to draw.</param>
/// <param name="options">The options containing the blend mode and opacity.</param> /// <param name="options">The options containing the blend mode and opacity.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
@ -258,8 +314,8 @@ public static class DrawImageExtensions
Point backgroundLocation, Point backgroundLocation,
Rectangle foregroundRectangle, Rectangle foregroundRectangle,
GraphicsOptions options, GraphicsOptions options,
int repeatCount) int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, backgroundLocation, foregroundRectangle, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage, repeatCount); => DrawImage(source, foreground, backgroundLocation, foregroundRectangle, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage, foregroundRepeatCount);
/// <summary> /// <summary>
/// Draws the given image together with the currently processing image by blending their pixels. /// Draws the given image together with the currently processing image by blending their pixels.
@ -270,6 +326,10 @@ public static class DrawImageExtensions
/// <param name="colorBlending">The color blending to apply.</param> /// <param name="colorBlending">The color blending to apply.</param>
/// <param name="alphaComposition">The alpha composition mode.</param> /// <param name="alphaComposition">The alpha composition mode.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
@ -278,8 +338,8 @@ public static class DrawImageExtensions
PixelColorBlendingMode colorBlending, PixelColorBlendingMode colorBlending,
PixelAlphaCompositionMode alphaComposition, PixelAlphaCompositionMode alphaComposition,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount = 0)
=> source.ApplyProcessor(new DrawImageProcessor(foreground, backgroundLocation, foreground.Bounds, colorBlending, alphaComposition, opacity, repeatCount)); => source.ApplyProcessor(new DrawImageProcessor(foreground, backgroundLocation, foreground.Bounds, colorBlending, alphaComposition, opacity, foregroundRepeatCount));
/// <summary> /// <summary>
/// Draws the given image together with the currently processing image by blending their pixels. /// Draws the given image together with the currently processing image by blending their pixels.
@ -291,6 +351,10 @@ public static class DrawImageExtensions
/// <param name="colorBlending">The color blending to apply.</param> /// <param name="colorBlending">The color blending to apply.</param>
/// <param name="alphaComposition">The alpha composition mode.</param> /// <param name="alphaComposition">The alpha composition mode.</param>
/// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to draw. Must be between 0 and 1.</param>
/// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this operation across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns> /// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext DrawImage( public static IImageProcessingContext DrawImage(
this IImageProcessingContext source, this IImageProcessingContext source,
@ -300,8 +364,8 @@ public static class DrawImageExtensions
PixelColorBlendingMode colorBlending, PixelColorBlendingMode colorBlending,
PixelAlphaCompositionMode alphaComposition, PixelAlphaCompositionMode alphaComposition,
float opacity, float opacity,
int repeatCount) => int foregroundRepeatCount = 0) =>
source.ApplyProcessor( source.ApplyProcessor(
new DrawImageProcessor(foreground, backgroundLocation, foregroundRectangle, colorBlending, alphaComposition, opacity, repeatCount), new DrawImageProcessor(foreground, backgroundLocation, foregroundRectangle, colorBlending, alphaComposition, opacity, foregroundRepeatCount),
foregroundRectangle); foregroundRectangle);
} }

18
src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor.cs

@ -19,15 +19,15 @@ public class DrawImageProcessor : IImageProcessor
/// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param> /// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param>
/// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param> /// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param>
/// <param name="opacity">The opacity of the image to blend.</param> /// <param name="opacity">The opacity of the image to blend.</param>
/// <param name="repeatCount">The loop count. The number of times to loop the animation. 0 means infinitely.</param> /// <param name="foregroundRepeatCount">The number of times the foreground frames are allowed to loop. 0 means infinitely.</param>
public DrawImageProcessor( public DrawImageProcessor(
Image foreground, Image foreground,
Point backgroundLocation, Point backgroundLocation,
PixelColorBlendingMode colorBlendingMode, PixelColorBlendingMode colorBlendingMode,
PixelAlphaCompositionMode alphaCompositionMode, PixelAlphaCompositionMode alphaCompositionMode,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount)
: this(foreground, backgroundLocation, foreground.Bounds, colorBlendingMode, alphaCompositionMode, opacity, repeatCount) : this(foreground, backgroundLocation, foreground.Bounds, colorBlendingMode, alphaCompositionMode, opacity, foregroundRepeatCount)
{ {
} }
@ -40,7 +40,7 @@ public class DrawImageProcessor : IImageProcessor
/// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param> /// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param>
/// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param> /// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param>
/// <param name="opacity">The opacity of the image to blend.</param> /// <param name="opacity">The opacity of the image to blend.</param>
/// <param name="repeatCount">The loop count. The number of times to loop the animation. 0 means infinitely.</param> /// <param name="foregroundRepeatCount">The number of times the foreground frames are allowed to loop. 0 means infinitely.</param>
public DrawImageProcessor( public DrawImageProcessor(
Image foreground, Image foreground,
Point backgroundLocation, Point backgroundLocation,
@ -48,7 +48,7 @@ public class DrawImageProcessor : IImageProcessor
PixelColorBlendingMode colorBlendingMode, PixelColorBlendingMode colorBlendingMode,
PixelAlphaCompositionMode alphaCompositionMode, PixelAlphaCompositionMode alphaCompositionMode,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount)
{ {
this.ForeGround = foreground; this.ForeGround = foreground;
this.BackgroundLocation = backgroundLocation; this.BackgroundLocation = backgroundLocation;
@ -56,7 +56,7 @@ public class DrawImageProcessor : IImageProcessor
this.ColorBlendingMode = colorBlendingMode; this.ColorBlendingMode = colorBlendingMode;
this.AlphaCompositionMode = alphaCompositionMode; this.AlphaCompositionMode = alphaCompositionMode;
this.Opacity = opacity; this.Opacity = opacity;
this.RepeatCount = repeatCount; this.ForegroundRepeatCount = foregroundRepeatCount;
} }
/// <summary> /// <summary>
@ -90,9 +90,9 @@ public class DrawImageProcessor : IImageProcessor
public float Opacity { get; } public float Opacity { get; }
/// <summary> /// <summary>
/// Gets the loop count. The number of times to loop the animation. 0 means infinitely. /// Gets the number of times the foreground frames are allowed to loop. 0 means infinitely.
/// </summary> /// </summary>
public int RepeatCount { get; } public int ForegroundRepeatCount { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixelBg> CreatePixelSpecificProcessor<TPixelBg>(Configuration configuration, Image<TPixelBg> source, Rectangle sourceRectangle) public IImageProcessor<TPixelBg> CreatePixelSpecificProcessor<TPixelBg>(Configuration configuration, Image<TPixelBg> source, Rectangle sourceRectangle)
@ -133,6 +133,6 @@ public class DrawImageProcessor : IImageProcessor
this.definition.ColorBlendingMode, this.definition.ColorBlendingMode,
this.definition.AlphaCompositionMode, this.definition.AlphaCompositionMode,
this.definition.Opacity, this.definition.Opacity,
this.definition.RepeatCount); this.definition.ForegroundRepeatCount);
} }
} }

31
src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs

@ -17,7 +17,11 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
where TPixelBg : unmanaged, IPixel<TPixelBg> where TPixelBg : unmanaged, IPixel<TPixelBg>
where TPixelFg : unmanaged, IPixel<TPixelFg> where TPixelFg : unmanaged, IPixel<TPixelFg>
{ {
private int currentFrameLoop; /// <summary>
/// Counts how many times <see cref="OnFrameApply"/> has been called for this processor instance.
/// Used to select the current foreground frame.
/// </summary>
private int foregroundFrameCounter;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixelBg, TPixelFg}"/> class. /// Initializes a new instance of the <see cref="DrawImageProcessor{TPixelBg, TPixelFg}"/> class.
@ -30,7 +34,10 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
/// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param> /// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param>
/// <param name="alphaCompositionMode">The alpha blending mode to use when drawing the image.</param> /// <param name="alphaCompositionMode">The alpha blending mode to use when drawing the image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <param name="repeatCount">The loop count. The number of times to loop the animation. 0 means infinitely.</param> /// <param name="foregroundRepeatCount">
/// The number of times the foreground frames are allowed to loop while applying this processor across successive frames.
/// A value of 0 means loop indefinitely.
/// </param>
public DrawImageProcessor( public DrawImageProcessor(
Configuration configuration, Configuration configuration,
Image<TPixelFg> foregroundImage, Image<TPixelFg> foregroundImage,
@ -40,10 +47,10 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
PixelColorBlendingMode colorBlendingMode, PixelColorBlendingMode colorBlendingMode,
PixelAlphaCompositionMode alphaCompositionMode, PixelAlphaCompositionMode alphaCompositionMode,
float opacity, float opacity,
int repeatCount) int foregroundRepeatCount)
: base(configuration, backgroundImage, backgroundImage.Bounds) : base(configuration, backgroundImage, backgroundImage.Bounds)
{ {
Guard.MustBeGreaterThanOrEqualTo(repeatCount, 0, nameof(repeatCount)); Guard.MustBeGreaterThanOrEqualTo(foregroundRepeatCount, 0, nameof(foregroundRepeatCount));
Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
this.ForegroundImage = foregroundImage; this.ForegroundImage = foregroundImage;
@ -51,6 +58,7 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
this.Opacity = opacity; this.Opacity = opacity;
this.Blender = PixelOperations<TPixelBg>.Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode); this.Blender = PixelOperations<TPixelBg>.Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode);
this.BackgroundLocation = backgroundLocation; this.BackgroundLocation = backgroundLocation;
this.ForegroundRepeatCount = foregroundRepeatCount;
} }
/// <summary> /// <summary>
@ -79,9 +87,10 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
public Point BackgroundLocation { get; } public Point BackgroundLocation { get; }
/// <summary> /// <summary>
/// Gets the loop count. The number of times to loop the animation. 0 means infinitely. /// Gets the number of times the foreground frames are allowed to loop while applying this processor across
/// successive frames. A value of 0 means loop indefinitely.
/// </summary> /// </summary>
public int RepeatCount { get; } public int ForegroundRepeatCount { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixelBg> source) protected override void OnFrameApply(ImageFrame<TPixelBg> source)
@ -124,9 +133,9 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
// Sanitize the dimensions so that we don't try and sample outside the image. // Sanitize the dimensions so that we don't try and sample outside the image.
Rectangle backgroundRectangle = Rectangle.Intersect(new Rectangle(left, top, width, height), this.SourceRectangle); Rectangle backgroundRectangle = Rectangle.Intersect(new Rectangle(left, top, width, height), this.SourceRectangle);
Configuration configuration = this.Configuration; Configuration configuration = this.Configuration;
int currentFrameIndex = this.currentFrameLoop % this.ForegroundImage.Frames.Count; int currentFrameIndex = this.foregroundFrameCounter % this.ForegroundImage.Frames.Count;
DrawImageProcessor<TPixelBg, TPixelFg>.RowOperation operation = RowOperation operation =
new( new(
configuration, configuration,
source.PixelBuffer, source.PixelBuffer,
@ -141,9 +150,11 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
new Rectangle(0, 0, foregroundRectangle.Width, foregroundRectangle.Height), new Rectangle(0, 0, foregroundRectangle.Width, foregroundRectangle.Height),
in operation); in operation);
if (this.RepeatCount is 0 || this.currentFrameLoop / this.ForegroundImage.Frames.Count < this.RepeatCount) // The repeat count only affects how the foreground frame advances across successive background frames.
// When exhausted, the selected foreground frame stops advancing.
if (this.ForegroundRepeatCount is 0 || this.foregroundFrameCounter / this.ForegroundImage.Frames.Count < this.ForegroundRepeatCount)
{ {
this.currentFrameLoop++; this.foregroundFrameCounter++;
} }
} }

Loading…
Cancel
Save