Browse Source

Update field names and fix assignment bug

pull/2995/head
James Jackson-South 3 weeks 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
Image foreground,
float opacity,
int repeatCount)
int foregroundRepeatCount = 0)
{
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>
@ -35,16 +39,20 @@ public static class DrawImageExtensions
/// <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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
Image foreground,
Rectangle foregroundRectangle,
float opacity,
int repeatCount)
int foregroundRepeatCount = 0)
{
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>
@ -54,14 +62,18 @@ public static class DrawImageExtensions
/// <param name="foreground">The image to draw on the currently processing image.</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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
Image foreground,
PixelColorBlendingMode colorBlending,
float opacity,
int repeatCount)
=> DrawImage(source, foreground, Point.Empty, colorBlending, opacity, repeatCount);
int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, colorBlending, opacity, foregroundRepeatCount);
/// <summary>
/// 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
@ -78,8 +94,8 @@ public static class DrawImageExtensions
Rectangle foregroundRectangle,
PixelColorBlendingMode colorBlending,
float opacity,
int repeatCount)
=> DrawImage(source, foreground, Point.Empty, foregroundRectangle, colorBlending, opacity, repeatCount);
int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, foregroundRectangle, colorBlending, opacity, foregroundRepeatCount);
/// <summary>
/// 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
@ -96,8 +116,8 @@ public static class DrawImageExtensions
PixelColorBlendingMode colorBlending,
PixelAlphaCompositionMode alphaComposition,
float opacity,
int repeatCount)
=> DrawImage(source, foreground, Point.Empty, colorBlending, alphaComposition, opacity, repeatCount);
int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, colorBlending, alphaComposition, opacity, foregroundRepeatCount);
/// <summary>
/// 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
@ -116,8 +140,8 @@ public static class DrawImageExtensions
PixelColorBlendingMode colorBlending,
PixelAlphaCompositionMode alphaComposition,
float opacity,
int repeatCount)
=> DrawImage(source, foreground, Point.Empty, foregroundRectangle, colorBlending, alphaComposition, opacity, repeatCount);
int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, foregroundRectangle, colorBlending, alphaComposition, opacity, foregroundRepeatCount);
/// <summary>
/// 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
Image foreground,
GraphicsOptions options,
int repeatCount)
=> DrawImage(source, foreground, Point.Empty, options, repeatCount);
int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, options, foregroundRepeatCount);
/// <summary>
/// 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
Image foreground,
Rectangle foregroundRectangle,
GraphicsOptions options,
int repeatCount)
=> DrawImage(source, foreground, Point.Empty, foregroundRectangle, options, repeatCount);
int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, Point.Empty, foregroundRectangle, options, foregroundRepeatCount);
/// <summary>
/// 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
Image foreground,
Point backgroundLocation,
float opacity,
int repeatCount)
int foregroundRepeatCount = 0)
{
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>
@ -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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
@ -183,10 +223,10 @@ public static class DrawImageExtensions
Point backgroundLocation,
Rectangle foregroundRectangle,
float opacity,
int repeatCount)
int foregroundRepeatCount = 0)
{
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>
@ -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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
@ -204,8 +248,8 @@ public static class DrawImageExtensions
Point backgroundLocation,
PixelColorBlendingMode colorBlending,
float opacity,
int repeatCount)
=> DrawImage(source, foreground, backgroundLocation, colorBlending, source.GetGraphicsOptions().AlphaCompositionMode, opacity, repeatCount);
int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, backgroundLocation, colorBlending, source.GetGraphicsOptions().AlphaCompositionMode, opacity, foregroundRepeatCount);
/// <summary>
/// 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
@ -224,8 +272,8 @@ public static class DrawImageExtensions
Rectangle foregroundRectangle,
PixelColorBlendingMode colorBlending,
float opacity,
int repeatCount)
=> DrawImage(source, foreground, backgroundLocation, foregroundRectangle, colorBlending, source.GetGraphicsOptions().AlphaCompositionMode, opacity, repeatCount);
int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, backgroundLocation, foregroundRectangle, colorBlending, source.GetGraphicsOptions().AlphaCompositionMode, opacity, foregroundRepeatCount);
/// <summary>
/// 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
Image foreground,
Point backgroundLocation,
GraphicsOptions options,
int repeatCount)
=> DrawImage(source, foreground, backgroundLocation, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage, repeatCount);
int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, backgroundLocation, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage, foregroundRepeatCount);
/// <summary>
/// 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
@ -258,8 +314,8 @@ public static class DrawImageExtensions
Point backgroundLocation,
Rectangle foregroundRectangle,
GraphicsOptions options,
int repeatCount)
=> DrawImage(source, foreground, backgroundLocation, foregroundRectangle, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage, repeatCount);
int foregroundRepeatCount = 0)
=> DrawImage(source, foreground, backgroundLocation, foregroundRectangle, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage, foregroundRepeatCount);
/// <summary>
/// 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
@ -278,8 +338,8 @@ public static class DrawImageExtensions
PixelColorBlendingMode colorBlending,
PixelAlphaCompositionMode alphaComposition,
float opacity,
int repeatCount)
=> source.ApplyProcessor(new DrawImageProcessor(foreground, backgroundLocation, foreground.Bounds, colorBlending, alphaComposition, opacity, repeatCount));
int foregroundRepeatCount = 0)
=> source.ApplyProcessor(new DrawImageProcessor(foreground, backgroundLocation, foreground.Bounds, colorBlending, alphaComposition, opacity, foregroundRepeatCount));
/// <summary>
/// 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="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="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>
public static IImageProcessingContext DrawImage(
this IImageProcessingContext source,
@ -300,8 +364,8 @@ public static class DrawImageExtensions
PixelColorBlendingMode colorBlending,
PixelAlphaCompositionMode alphaComposition,
float opacity,
int repeatCount) =>
int foregroundRepeatCount = 0) =>
source.ApplyProcessor(
new DrawImageProcessor(foreground, backgroundLocation, foregroundRectangle, colorBlending, alphaComposition, opacity, repeatCount),
new DrawImageProcessor(foreground, backgroundLocation, foregroundRectangle, colorBlending, alphaComposition, opacity, foregroundRepeatCount),
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="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="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(
Image foreground,
Point backgroundLocation,
PixelColorBlendingMode colorBlendingMode,
PixelAlphaCompositionMode alphaCompositionMode,
float opacity,
int repeatCount)
: this(foreground, backgroundLocation, foreground.Bounds, colorBlendingMode, alphaCompositionMode, opacity, repeatCount)
int foregroundRepeatCount)
: 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="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="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(
Image foreground,
Point backgroundLocation,
@ -48,7 +48,7 @@ public class DrawImageProcessor : IImageProcessor
PixelColorBlendingMode colorBlendingMode,
PixelAlphaCompositionMode alphaCompositionMode,
float opacity,
int repeatCount)
int foregroundRepeatCount)
{
this.ForeGround = foreground;
this.BackgroundLocation = backgroundLocation;
@ -56,7 +56,7 @@ public class DrawImageProcessor : IImageProcessor
this.ColorBlendingMode = colorBlendingMode;
this.AlphaCompositionMode = alphaCompositionMode;
this.Opacity = opacity;
this.RepeatCount = repeatCount;
this.ForegroundRepeatCount = foregroundRepeatCount;
}
/// <summary>
@ -90,9 +90,9 @@ public class DrawImageProcessor : IImageProcessor
public float Opacity { get; }
/// <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>
public int RepeatCount { get; }
public int ForegroundRepeatCount { get; }
/// <inheritdoc />
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.AlphaCompositionMode,
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 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>
/// 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="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="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(
Configuration configuration,
Image<TPixelFg> foregroundImage,
@ -40,10 +47,10 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
PixelColorBlendingMode colorBlendingMode,
PixelAlphaCompositionMode alphaCompositionMode,
float opacity,
int repeatCount)
int foregroundRepeatCount)
: base(configuration, backgroundImage, backgroundImage.Bounds)
{
Guard.MustBeGreaterThanOrEqualTo(repeatCount, 0, nameof(repeatCount));
Guard.MustBeGreaterThanOrEqualTo(foregroundRepeatCount, 0, nameof(foregroundRepeatCount));
Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
this.ForegroundImage = foregroundImage;
@ -51,6 +58,7 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
this.Opacity = opacity;
this.Blender = PixelOperations<TPixelBg>.Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode);
this.BackgroundLocation = backgroundLocation;
this.ForegroundRepeatCount = foregroundRepeatCount;
}
/// <summary>
@ -79,9 +87,10 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
public Point BackgroundLocation { get; }
/// <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>
public int RepeatCount { get; }
public int ForegroundRepeatCount { get; }
/// <inheritdoc/>
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.
Rectangle backgroundRectangle = Rectangle.Intersect(new Rectangle(left, top, width, height), this.SourceRectangle);
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(
configuration,
source.PixelBuffer,
@ -141,9 +150,11 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
new Rectangle(0, 0, foregroundRectangle.Width, foregroundRectangle.Height),
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