Browse Source

Drop Default, use DeepClone + tests

pull/1055/head
James Jackson-South 7 years ago
parent
commit
2a15aaca16
  1. 12
      src/ImageSharp.Drawing/Processing/Extensions/DrawImageExtensions.cs
  2. 2
      src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs
  3. 2
      src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs
  4. 2
      src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs
  5. 2
      src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs
  6. 8
      src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs
  7. 2
      src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs
  8. 2
      src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs
  9. 2
      src/ImageSharp.Drawing/Processing/Extensions/FillPathExtensions.cs
  10. 4
      src/ImageSharp.Drawing/Processing/Extensions/FillRegionExtensions.cs
  11. 50
      src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs
  12. 36
      src/ImageSharp/GraphicsOptions.cs
  13. 8
      src/ImageSharp/Processing/Extensions/BackgroundColorExtensions.cs
  14. 10
      src/ImageSharp/Processing/Extensions/GlowExtensions.cs
  15. 10
      src/ImageSharp/Processing/Extensions/VignetteExtensions.cs
  16. 2
      src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs
  17. 2
      src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs
  18. 2
      tests/ImageSharp.Tests/Drawing/DrawImageTests.cs
  19. 17
      tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs
  20. 17
      tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs
  21. 17
      tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs
  22. 17
      tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs
  23. 24
      tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs
  24. 85
      tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs
  25. 44
      tests/ImageSharp.Tests/GraphicsOptionsTests.cs
  26. 24
      tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs
  27. 23
      tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs
  28. 23
      tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs
  29. 21
      tests/ImageSharp.Tests/TestUtilities/GraphicsOptionsComparer.cs

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

@ -27,8 +27,8 @@ namespace SixLabors.ImageSharp.Processing
new DrawImageProcessor( new DrawImageProcessor(
image, image,
Point.Empty, Point.Empty,
GraphicsOptions.Default.ColorBlendingMode, new GraphicsOptions().ColorBlendingMode,
GraphicsOptions.Default.AlphaCompositionMode, new GraphicsOptions().AlphaCompositionMode,
opacity)); opacity));
/// <summary> /// <summary>
@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Processing
image, image,
Point.Empty, Point.Empty,
colorBlending, colorBlending,
GraphicsOptions.Default.AlphaCompositionMode, new GraphicsOptions().AlphaCompositionMode,
opacity)); opacity));
/// <summary> /// <summary>
@ -105,8 +105,8 @@ namespace SixLabors.ImageSharp.Processing
new DrawImageProcessor( new DrawImageProcessor(
image, image,
location, location,
GraphicsOptions.Default.ColorBlendingMode, new GraphicsOptions().ColorBlendingMode,
GraphicsOptions.Default.AlphaCompositionMode, new GraphicsOptions().AlphaCompositionMode,
opacity)); opacity));
/// <summary> /// <summary>
@ -129,7 +129,7 @@ namespace SixLabors.ImageSharp.Processing
image, image,
location, location,
colorBlending, colorBlending,
GraphicsOptions.Default.AlphaCompositionMode, new GraphicsOptions().AlphaCompositionMode,
opacity)); opacity));
/// <summary> /// <summary>

2
src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext public static IImageProcessingContext
Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths) => Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths) =>
source.Draw(GraphicsOptions.Default, pen, paths); source.Draw(new GraphicsOptions(), pen, paths);
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.

2
src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs

@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path) => public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path) =>
source.Draw(GraphicsOptions.Default, pen, path); source.Draw(new GraphicsOptions(), pen, path);
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.

2
src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs

@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.Processing
this IImageProcessingContext source, this IImageProcessingContext source,
IPen pen, IPen pen,
params PointF[] points) => params PointF[] points) =>
source.Draw(GraphicsOptions.Default, pen, new Polygon(new LinearLineSegment(points))); source.Draw(new GraphicsOptions(), pen, new Polygon(new LinearLineSegment(points)));
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// Draws the provided Points as a closed Linear Polygon with the provided Pen.

2
src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs

@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape) => public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape) =>
source.Draw(GraphicsOptions.Default, pen, shape); source.Draw(new GraphicsOptions(), pen, shape);
/// <summary> /// <summary>
/// Draws the outline of the rectangle with the provided brush at the provided thickness. /// Draws the outline of the rectangle with the provided brush at the provided thickness.

8
src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs

@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Processing
Font font, Font font,
Color color, Color color,
PointF location) => PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, color, location); source.DrawText(new TextGraphicsOptions(), text, font, color, location);
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush. /// Draws the text onto the the image filled via the brush.
@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Processing
Font font, Font font,
IBrush brush, IBrush brush,
PointF location) => PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, brush, location); source.DrawText(new TextGraphicsOptions(), text, font, brush, location);
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush. /// Draws the text onto the the image filled via the brush.
@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Processing
Font font, Font font,
IPen pen, IPen pen,
PointF location) => PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, pen, location); source.DrawText(new TextGraphicsOptions(), text, font, pen, location);
/// <summary> /// <summary>
/// Draws the text onto the the image outlined via the pen. /// Draws the text onto the the image outlined via the pen.
@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.Processing
IBrush brush, IBrush brush,
IPen pen, IPen pen,
PointF location) => PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, brush, pen, location); source.DrawText(new TextGraphicsOptions(), text, font, brush, pen, location);
/// <summary> /// <summary>
/// Draws the text using the default resolution of <value>72dpi</value> onto the the image filled via the brush then outlined via the pen. /// Draws the text using the default resolution of <value>72dpi</value> onto the the image filled via the brush then outlined via the pen.

2
src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs

@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Processing
this IImageProcessingContext source, this IImageProcessingContext source,
IBrush brush, IBrush brush,
Action<PathBuilder> path) => Action<PathBuilder> path) =>
source.Fill(GraphicsOptions.Default, brush, path); source.Fill(new GraphicsOptions(), brush, path);
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.

2
src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs

@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Processing
this IImageProcessingContext source, this IImageProcessingContext source,
IBrush brush, IBrush brush,
IPathCollection paths) => IPathCollection paths) =>
source.Fill(GraphicsOptions.Default, brush, paths); source.Fill(new GraphicsOptions(), brush, paths);
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.

2
src/ImageSharp.Drawing/Processing/Extensions/FillPathExtensions.cs

@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path) => public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path) =>
source.Fill(GraphicsOptions.Default, brush, new ShapeRegion(path)); source.Fill(new GraphicsOptions(), brush, new ShapeRegion(path));
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.. /// Flood fills the image in the shape of the provided polygon with the specified brush..

4
src/ImageSharp.Drawing/Processing/Extensions/FillRegionExtensions.cs

@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="brush">The details how to fill the region of interest.</param> /// <param name="brush">The details how to fill the region of interest.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush) => public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush) =>
source.Fill(GraphicsOptions.Default, brush); source.Fill(new GraphicsOptions(), brush);
/// <summary> /// <summary>
/// Flood fills the image with the specified color. /// Flood fills the image with the specified color.
@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region) => public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region) =>
source.Fill(GraphicsOptions.Default, brush, region); source.Fill(new GraphicsOptions(), brush, region);
/// <summary> /// <summary>
/// Flood fills the image with in the region with the specified color. /// Flood fills the image with in the region with the specified color.

50
src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.Fonts; using SixLabors.Fonts;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -10,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Options for influencing the drawing functions. /// Options for influencing the drawing functions.
/// </summary> /// </summary>
public class TextGraphicsOptions public class TextGraphicsOptions : IDeepCloneable<TextGraphicsOptions>
{ {
private int antialiasSubpixelDepth = 16; private int antialiasSubpixelDepth = 16;
private float blendPercentage = 1F; private float blendPercentage = 1F;
@ -18,6 +17,29 @@ namespace SixLabors.ImageSharp.Processing
private float dpiX = 72F; private float dpiX = 72F;
private float dpiY = 72F; private float dpiY = 72F;
/// <summary>
/// Initializes a new instance of the <see cref="TextGraphicsOptions"/> class.
/// </summary>
public TextGraphicsOptions()
{
}
private TextGraphicsOptions(TextGraphicsOptions source)
{
this.AlphaCompositionMode = source.AlphaCompositionMode;
this.Antialias = source.Antialias;
this.AntialiasSubpixelDepth = source.AntialiasSubpixelDepth;
this.ApplyKerning = source.ApplyKerning;
this.BlendPercentage = source.BlendPercentage;
this.ColorBlendingMode = source.ColorBlendingMode;
this.DpiX = source.DpiX;
this.DpiY = source.DpiY;
this.HorizontalAlignment = source.HorizontalAlignment;
this.TabWidth = source.TabWidth;
this.WrapTextWidth = source.WrapTextWidth;
this.VerticalAlignment = source.VerticalAlignment;
}
/// <summary> /// <summary>
/// Gets the default <see cref="TextGraphicsOptions"/> instance. /// Gets the default <see cref="TextGraphicsOptions"/> instance.
/// </summary> /// </summary>
@ -194,27 +216,7 @@ namespace SixLabors.ImageSharp.Processing
}; };
} }
/// <summary> /// <inheritdoc/>
/// Creates a shallow copy of the <see cref="TextGraphicsOptions"/>. public TextGraphicsOptions DeepClone() => new TextGraphicsOptions(this);
/// </summary>
/// <returns>A new options instance.</returns>
public TextGraphicsOptions Clone()
{
return new TextGraphicsOptions
{
AlphaCompositionMode = this.AlphaCompositionMode,
Antialias = this.Antialias,
AntialiasSubpixelDepth = this.AntialiasSubpixelDepth,
ApplyKerning = this.ApplyKerning,
BlendPercentage = this.BlendPercentage,
ColorBlendingMode = this.ColorBlendingMode,
DpiX = this.DpiX,
DpiY = this.DpiY,
HorizontalAlignment = this.HorizontalAlignment,
TabWidth = this.TabWidth,
WrapTextWidth = this.WrapTextWidth,
VerticalAlignment = this.VerticalAlignment
};
}
} }
} }

36
src/ImageSharp/GraphicsOptions.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp
@ -9,11 +8,27 @@ namespace SixLabors.ImageSharp
/// <summary> /// <summary>
/// Options for influencing the drawing functions. /// Options for influencing the drawing functions.
/// </summary> /// </summary>
public class GraphicsOptions public class GraphicsOptions : IDeepCloneable<GraphicsOptions>
{ {
private int antialiasSubpixelDepth = 16; private int antialiasSubpixelDepth = 16;
private float blendPercentage = 1F; private float blendPercentage = 1F;
/// <summary>
/// Initializes a new instance of the <see cref="GraphicsOptions"/> class.
/// </summary>
public GraphicsOptions()
{
}
private GraphicsOptions(GraphicsOptions source)
{
this.AlphaCompositionMode = source.AlphaCompositionMode;
this.Antialias = source.Antialias;
this.AntialiasSubpixelDepth = source.AntialiasSubpixelDepth;
this.BlendPercentage = source.BlendPercentage;
this.ColorBlendingMode = source.ColorBlendingMode;
}
/// <summary> /// <summary>
/// Gets the default <see cref="GraphicsOptions"/> instance. /// Gets the default <see cref="GraphicsOptions"/> instance.
/// </summary> /// </summary>
@ -73,20 +88,7 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public PixelAlphaCompositionMode AlphaCompositionMode { get; set; } = PixelAlphaCompositionMode.SrcOver; public PixelAlphaCompositionMode AlphaCompositionMode { get; set; } = PixelAlphaCompositionMode.SrcOver;
/// <summary> /// <inheritdoc/>
/// Creates a shallow copy of the <see cref="GraphicsOptions"/>. public GraphicsOptions DeepClone() => new GraphicsOptions(this);
/// </summary>
/// <returns>A new options instance.</returns>
public GraphicsOptions Clone()
{
return new GraphicsOptions
{
AlphaCompositionMode = this.AlphaCompositionMode,
Antialias = this.Antialias,
AntialiasSubpixelDepth = this.AntialiasSubpixelDepth,
BlendPercentage = this.BlendPercentage,
ColorBlendingMode = this.ColorBlendingMode
};
}
} }
} }

8
src/ImageSharp/Processing/Extensions/BackgroundColorExtensions.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.ImageSharp.Processing.Processors.Overlays;
@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="color">The color to set as the background.</param> /// <param name="color">The color to set as the background.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, Color color) => public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, Color color) =>
BackgroundColor(source, GraphicsOptions.Default, color); BackgroundColor(source, new GraphicsOptions(), color);
/// <summary> /// <summary>
/// Replaces the background color of image with the given one. /// Replaces the background color of image with the given one.
@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing
this IImageProcessingContext source, this IImageProcessingContext source,
Color color, Color color,
Rectangle rectangle) => Rectangle rectangle) =>
BackgroundColor(source, GraphicsOptions.Default, color, rectangle); BackgroundColor(source, new GraphicsOptions(), color, rectangle);
/// <summary> /// <summary>
/// Replaces the background color of image with the given one. /// Replaces the background color of image with the given one.
@ -66,4 +66,4 @@ namespace SixLabors.ImageSharp.Processing
Rectangle rectangle) => Rectangle rectangle) =>
source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle); source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle);
} }
} }

10
src/ImageSharp/Processing/Extensions/GlowExtensions.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Glow(this IImageProcessingContext source) => public static IImageProcessingContext Glow(this IImageProcessingContext source) =>
Glow(source, GraphicsOptions.Default); Glow(source, new GraphicsOptions());
/// <summary> /// <summary>
/// Applies a radial glow effect to an image. /// Applies a radial glow effect to an image.
@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Processing
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Glow(this IImageProcessingContext source, Color color) public static IImageProcessingContext Glow(this IImageProcessingContext source, Color color)
{ {
return Glow(source, GraphicsOptions.Default, color); return Glow(source, new GraphicsOptions(), color);
} }
/// <summary> /// <summary>
@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="radius">The the radius.</param> /// <param name="radius">The the radius.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius) => public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius) =>
Glow(source, GraphicsOptions.Default, radius); Glow(source, new GraphicsOptions(), radius);
/// <summary> /// <summary>
/// Applies a radial glow effect to an image. /// Applies a radial glow effect to an image.
@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing
/// </param> /// </param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle) => public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle) =>
source.Glow(GraphicsOptions.Default, rectangle); source.Glow(new GraphicsOptions(), rectangle);
/// <summary> /// <summary>
/// Applies a radial glow effect to an image. /// Applies a radial glow effect to an image.
@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Processing
Color color, Color color,
float radius, float radius,
Rectangle rectangle) => Rectangle rectangle) =>
source.Glow(GraphicsOptions.Default, color, ValueSize.Absolute(radius), rectangle); source.Glow(new GraphicsOptions(), color, ValueSize.Absolute(radius), rectangle);
/// <summary> /// <summary>
/// Applies a radial glow effect to an image. /// Applies a radial glow effect to an image.

10
src/ImageSharp/Processing/Extensions/VignetteExtensions.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Vignette(this IImageProcessingContext source) => public static IImageProcessingContext Vignette(this IImageProcessingContext source) =>
Vignette(source, GraphicsOptions.Default); Vignette(source, new GraphicsOptions());
/// <summary> /// <summary>
/// Applies a radial vignette effect to an image. /// Applies a radial vignette effect to an image.
@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="color">The color to set as the vignette.</param> /// <param name="color">The color to set as the vignette.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Vignette(this IImageProcessingContext source, Color color) => public static IImageProcessingContext Vignette(this IImageProcessingContext source, Color color) =>
Vignette(source, GraphicsOptions.Default, color); Vignette(source, new GraphicsOptions(), color);
/// <summary> /// <summary>
/// Applies a radial vignette effect to an image. /// Applies a radial vignette effect to an image.
@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing
this IImageProcessingContext source, this IImageProcessingContext source,
float radiusX, float radiusX,
float radiusY) => float radiusY) =>
Vignette(source, GraphicsOptions.Default, radiusX, radiusY); Vignette(source, new GraphicsOptions(), radiusX, radiusY);
/// <summary> /// <summary>
/// Applies a radial vignette effect to an image. /// Applies a radial vignette effect to an image.
@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing
/// </param> /// </param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle) => public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle) =>
Vignette(source, GraphicsOptions.Default, rectangle); Vignette(source, new GraphicsOptions(), rectangle);
/// <summary> /// <summary>
/// Applies a radial vignette effect to an image. /// Applies a radial vignette effect to an image.
@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Processing
float radiusX, float radiusX,
float radiusY, float radiusY,
Rectangle rectangle) => Rectangle rectangle) =>
source.Vignette(GraphicsOptions.Default, color, radiusX, radiusY, rectangle); source.Vignette(new GraphicsOptions(), color, radiusX, radiusY, rectangle);
/// <summary> /// <summary>
/// Applies a radial vignette effect to an image. /// Applies a radial vignette effect to an image.

2
src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs

@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
/// <param name="color">The color or the glow.</param> /// <param name="color">The color or the glow.</param>
/// <param name="radius">The radius of the glow.</param> /// <param name="radius">The radius of the glow.</param>
internal GlowProcessor(Color color, ValueSize radius) internal GlowProcessor(Color color, ValueSize radius)
: this(color, radius, GraphicsOptions.Default) : this(color, radius, new GraphicsOptions())
{ {
} }

2
src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs

@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
/// </summary> /// </summary>
/// <param name="color">The color of the vignette.</param> /// <param name="color">The color of the vignette.</param>
public VignetteProcessor(Color color) public VignetteProcessor(Color color)
: this(color, GraphicsOptions.Default) : this(color, new GraphicsOptions())
{ {
} }

2
tests/ImageSharp.Tests/Drawing/DrawImageTests.cs

@ -190,7 +190,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
void Test() void Test()
{ {
background.Mutate(context => context.DrawImage(overlay, new Point(x, y), GraphicsOptions.Default)); background.Mutate(context => context.DrawImage(overlay, new Point(x, y), new GraphicsOptions()));
} }
} }
} }

17
tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs

@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Processing.Processors.Drawing;
using SixLabors.ImageSharp.Tests.Processing; using SixLabors.ImageSharp.Tests.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Shapes; using SixLabors.Shapes;
using Xunit; using Xunit;
@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{ {
public class DrawPathCollection : BaseImageOperationsExtensionTest public class DrawPathCollection : BaseImageOperationsExtensionTest
{ {
GraphicsOptions noneDefault = new GraphicsOptions { Antialias = false }; private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false };
Color color = Color.HotPink; Color color = Color.HotPink;
Pen pen = Pens.Solid(Rgba32.HotPink, 1); Pen pen = Pens.Solid(Rgba32.HotPink, 1);
IPath path1 = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { IPath path1 = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] {
@ -46,7 +49,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{ {
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i); FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i);
Assert.Equal(GraphicsOptions.Default, processor.Options); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapePath region = Assert.IsType<ShapePath>(processor.Region); ShapePath region = Assert.IsType<ShapePath>(processor.Region);
@ -60,13 +63,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact] [Fact]
public void CorrectlySetsBrushPathOptions() public void CorrectlySetsBrushPathOptions()
{ {
this.operations.Draw(this.noneDefault, this.pen, this.pathCollection); this.operations.Draw(this.nonDefault, this.pen, this.pathCollection);
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i); FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i);
Assert.Equal(this.noneDefault, processor.Options); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapePath region = Assert.IsType<ShapePath>(processor.Region); ShapePath region = Assert.IsType<ShapePath>(processor.Region);
Assert.IsType<ComplexPolygon>(region.Shape); Assert.IsType<ComplexPolygon>(region.Shape);
@ -84,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{ {
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i); FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i);
Assert.Equal(GraphicsOptions.Default, processor.Options); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapePath region = Assert.IsType<ShapePath>(processor.Region); ShapePath region = Assert.IsType<ShapePath>(processor.Region);
Assert.IsType<ComplexPolygon>(region.Shape); Assert.IsType<ComplexPolygon>(region.Shape);
@ -97,13 +100,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact] [Fact]
public void CorrectlySetsColorPathAndOptions() public void CorrectlySetsColorPathAndOptions()
{ {
this.operations.Draw(this.noneDefault, this.color, 1, this.pathCollection); this.operations.Draw(this.nonDefault, this.color, 1, this.pathCollection);
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i); FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i);
Assert.Equal(this.noneDefault, processor.Options); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapePath region = Assert.IsType<ShapePath>(processor.Region); ShapePath region = Assert.IsType<ShapePath>(processor.Region);
Assert.IsType<ComplexPolygon>(region.Shape); Assert.IsType<ComplexPolygon>(region.Shape);

17
tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs

@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Processing.Processors.Drawing;
using SixLabors.ImageSharp.Tests.Processing; using SixLabors.ImageSharp.Tests.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Shapes; using SixLabors.Shapes;
using Xunit; using Xunit;
@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{ {
public class FillPath : BaseImageOperationsExtensionTest public class FillPath : BaseImageOperationsExtensionTest
{ {
GraphicsOptions noneDefault = new GraphicsOptions { Antialias = false }; private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false };
Color color = Color.HotPink; Color color = Color.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink); SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
IPath path = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { IPath path = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] {
@ -30,7 +33,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
this.operations.Fill(this.brush, this.path); this.operations.Fill(this.brush, this.path);
var processor = this.Verify<FillRegionProcessor>(); var processor = this.Verify<FillRegionProcessor>();
Assert.Equal(GraphicsOptions.Default, processor.Options); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
@ -44,10 +47,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact] [Fact]
public void CorrectlySetsBrushPathOptions() public void CorrectlySetsBrushPathOptions()
{ {
this.operations.Fill(this.noneDefault, this.brush, this.path); this.operations.Fill(this.nonDefault, this.brush, this.path);
var processor = this.Verify<FillRegionProcessor>(); var processor = this.Verify<FillRegionProcessor>();
Assert.Equal(this.noneDefault, processor.Options); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape); Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -62,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
this.operations.Fill(this.color, this.path); this.operations.Fill(this.color, this.path);
var processor = this.Verify<FillRegionProcessor>(); var processor = this.Verify<FillRegionProcessor>();
Assert.Equal(GraphicsOptions.Default, processor.Options); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape); Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -75,10 +78,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact] [Fact]
public void CorrectlySetsColorPathAndOptions() public void CorrectlySetsColorPathAndOptions()
{ {
this.operations.Fill(this.noneDefault, this.color, this.path); this.operations.Fill(this.nonDefault, this.color, this.path);
var processor = this.Verify<FillRegionProcessor>(); var processor = this.Verify<FillRegionProcessor>();
Assert.Equal(this.noneDefault, processor.Options); Assert.Equal(this.nonDefault, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape); Polygon polygon = Assert.IsType<Polygon>(region.Shape);

17
tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs

@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Processing.Processors.Drawing;
using SixLabors.ImageSharp.Tests.Processing; using SixLabors.ImageSharp.Tests.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Shapes; using SixLabors.Shapes;
using Xunit; using Xunit;
@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{ {
public class FillPathCollection : BaseImageOperationsExtensionTest public class FillPathCollection : BaseImageOperationsExtensionTest
{ {
GraphicsOptions noneDefault = new GraphicsOptions { Antialias = false }; private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false };
Color color = Color.HotPink; Color color = Color.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink); SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
IPath path1 = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { IPath path1 = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] {
@ -46,7 +49,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{ {
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i); FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i);
Assert.Equal(GraphicsOptions.Default, processor.Options); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
@ -61,13 +64,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact] [Fact]
public void CorrectlySetsBrushPathOptions() public void CorrectlySetsBrushPathOptions()
{ {
this.operations.Fill(this.noneDefault, this.brush, this.pathCollection); this.operations.Fill(this.nonDefault, this.brush, this.pathCollection);
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i); FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i);
Assert.Equal(this.noneDefault, processor.Options); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape); Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -86,7 +89,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{ {
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i); FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i);
Assert.Equal(GraphicsOptions.Default, processor.Options); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape); Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -100,13 +103,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact] [Fact]
public void CorrectlySetsColorPathAndOptions() public void CorrectlySetsColorPathAndOptions()
{ {
this.operations.Fill(this.noneDefault, this.color, this.pathCollection); this.operations.Fill(this.nonDefault, this.color, this.pathCollection);
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i); FillRegionProcessor processor = this.Verify<FillRegionProcessor>(i);
Assert.Equal(this.noneDefault, processor.Options); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape); Polygon polygon = Assert.IsType<Polygon>(region.Shape);

17
tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs

@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Processing.Processors.Drawing;
using SixLabors.ImageSharp.Tests.Processing; using SixLabors.ImageSharp.Tests.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Shapes; using SixLabors.Shapes;
using Xunit; using Xunit;
@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{ {
public class FillPolygon : BaseImageOperationsExtensionTest public class FillPolygon : BaseImageOperationsExtensionTest
{ {
GraphicsOptions noneDefault = new GraphicsOptions { Antialias = false }; private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false };
Color color = Color.HotPink; Color color = Color.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink); SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
SixLabors.Primitives.PointF[] path = { SixLabors.Primitives.PointF[] path = {
@ -32,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(); FillRegionProcessor processor = this.Verify<FillRegionProcessor>();
Assert.Equal(GraphicsOptions.Default, processor.Options); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape); Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -44,10 +47,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact] [Fact]
public void CorrectlySetsBrushPathAndOptions() public void CorrectlySetsBrushPathAndOptions()
{ {
this.operations.FillPolygon(this.noneDefault, this.brush, this.path); this.operations.FillPolygon(this.nonDefault, this.brush, this.path);
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(); FillRegionProcessor processor = this.Verify<FillRegionProcessor>();
Assert.Equal(this.noneDefault, processor.Options); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape); Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -63,7 +66,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(); FillRegionProcessor processor = this.Verify<FillRegionProcessor>();
Assert.Equal(GraphicsOptions.Default, processor.Options); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape); Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -76,10 +79,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact] [Fact]
public void CorrectlySetsColorPathAndOptions() public void CorrectlySetsColorPathAndOptions()
{ {
this.operations.FillPolygon(this.noneDefault, this.color, this.path); this.operations.FillPolygon(this.nonDefault, this.color, this.path);
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(); FillRegionProcessor processor = this.Verify<FillRegionProcessor>();
Assert.Equal(this.noneDefault, processor.Options); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape); Polygon polygon = Assert.IsType<Polygon>(region.Shape);

24
tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs

@ -6,17 +6,19 @@ using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Processing.Processors.Drawing;
using SixLabors.ImageSharp.Tests.Processing; using SixLabors.ImageSharp.Tests.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing.Paths namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{ {
public class FillRectangle : BaseImageOperationsExtensionTest public class FillRectangle : BaseImageOperationsExtensionTest
{ {
GraphicsOptions noneDefault = new GraphicsOptions { Antialias = false }; private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
Color color = Color.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink); private GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false };
SixLabors.Primitives.Rectangle rectangle = new SixLabors.Primitives.Rectangle(10, 10, 77, 76); private Color color = Color.HotPink;
private SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
private SixLabors.Primitives.Rectangle rectangle = new SixLabors.Primitives.Rectangle(10, 10, 77, 76);
[Fact] [Fact]
public void CorrectlySetsBrushAndRectangle() public void CorrectlySetsBrushAndRectangle()
@ -24,7 +26,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
this.operations.Fill(this.brush, this.rectangle); this.operations.Fill(this.brush, this.rectangle);
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(); FillRegionProcessor processor = this.Verify<FillRegionProcessor>();
Assert.Equal(GraphicsOptions.Default, processor.Options); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Shapes.RectangularPolygon rect = Assert.IsType<Shapes.RectangularPolygon>(region.Shape); Shapes.RectangularPolygon rect = Assert.IsType<Shapes.RectangularPolygon>(region.Shape);
@ -39,10 +41,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact] [Fact]
public void CorrectlySetsBrushRectangleAndOptions() public void CorrectlySetsBrushRectangleAndOptions()
{ {
this.operations.Fill(this.noneDefault, this.brush, this.rectangle); this.operations.Fill(this.nonDefault, this.brush, this.rectangle);
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(); FillRegionProcessor processor = this.Verify<FillRegionProcessor>();
Assert.Equal(this.noneDefault, processor.Options); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Shapes.RectangularPolygon rect = Assert.IsType<Shapes.RectangularPolygon>(region.Shape); Shapes.RectangularPolygon rect = Assert.IsType<Shapes.RectangularPolygon>(region.Shape);
@ -60,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
this.operations.Fill(this.color, this.rectangle); this.operations.Fill(this.color, this.rectangle);
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(); FillRegionProcessor processor = this.Verify<FillRegionProcessor>();
Assert.Equal(GraphicsOptions.Default, processor.Options); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Shapes.RectangularPolygon rect = Assert.IsType<Shapes.RectangularPolygon>(region.Shape); Shapes.RectangularPolygon rect = Assert.IsType<Shapes.RectangularPolygon>(region.Shape);
@ -76,10 +78,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact] [Fact]
public void CorrectlySetsColorRectangleAndOptions() public void CorrectlySetsColorRectangleAndOptions()
{ {
this.operations.Fill(this.noneDefault, this.color, this.rectangle); this.operations.Fill(this.nonDefault, this.color, this.rectangle);
FillRegionProcessor processor = this.Verify<FillRegionProcessor>(); FillRegionProcessor processor = this.Verify<FillRegionProcessor>();
Assert.Equal(this.noneDefault, processor.Options); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Shapes.RectangularPolygon rect = Assert.IsType<Shapes.RectangularPolygon>(region.Shape); Shapes.RectangularPolygon rect = Assert.IsType<Shapes.RectangularPolygon>(region.Shape);

85
tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs

@ -12,17 +12,15 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
public class TextGraphicsOptionsTests public class TextGraphicsOptionsTests
{ {
private readonly TextGraphicsOptions newTextGraphicsOptions = new TextGraphicsOptions(); private readonly TextGraphicsOptions newTextGraphicsOptions = new TextGraphicsOptions();
private readonly TextGraphicsOptions defaultTextGraphicsOptions = TextGraphicsOptions.Default; private readonly TextGraphicsOptions cloneTextGraphicsOptions = new TextGraphicsOptions().DeepClone();
private readonly TextGraphicsOptions cloneTextGraphicsOptions = TextGraphicsOptions.Default.Clone();
[Fact] [Fact]
public void DefaultTextGraphicsOptionsIsNotNull() => Assert.True(this.defaultTextGraphicsOptions != null); public void CloneTextGraphicsOptionsIsNotNull() => Assert.True(this.cloneTextGraphicsOptions != null);
[Fact] [Fact]
public void DefaultTextGraphicsOptionsAntialias() public void DefaultTextGraphicsOptionsAntialias()
{ {
Assert.True(this.newTextGraphicsOptions.Antialias); Assert.True(this.newTextGraphicsOptions.Antialias);
Assert.True(this.defaultTextGraphicsOptions.Antialias);
Assert.True(this.cloneTextGraphicsOptions.Antialias); Assert.True(this.cloneTextGraphicsOptions.Antialias);
} }
@ -31,7 +29,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{ {
const int Expected = 16; const int Expected = 16;
Assert.Equal(Expected, this.newTextGraphicsOptions.AntialiasSubpixelDepth); Assert.Equal(Expected, this.newTextGraphicsOptions.AntialiasSubpixelDepth);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.AntialiasSubpixelDepth);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.AntialiasSubpixelDepth); Assert.Equal(Expected, this.cloneTextGraphicsOptions.AntialiasSubpixelDepth);
} }
@ -40,7 +37,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{ {
const float Expected = 1F; const float Expected = 1F;
Assert.Equal(Expected, this.newTextGraphicsOptions.BlendPercentage); Assert.Equal(Expected, this.newTextGraphicsOptions.BlendPercentage);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.BlendPercentage);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.BlendPercentage); Assert.Equal(Expected, this.cloneTextGraphicsOptions.BlendPercentage);
} }
@ -49,7 +45,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{ {
const PixelColorBlendingMode Expected = PixelColorBlendingMode.Normal; const PixelColorBlendingMode Expected = PixelColorBlendingMode.Normal;
Assert.Equal(Expected, this.newTextGraphicsOptions.ColorBlendingMode); Assert.Equal(Expected, this.newTextGraphicsOptions.ColorBlendingMode);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.ColorBlendingMode);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.ColorBlendingMode); Assert.Equal(Expected, this.cloneTextGraphicsOptions.ColorBlendingMode);
} }
@ -58,7 +53,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{ {
const PixelAlphaCompositionMode Expected = PixelAlphaCompositionMode.SrcOver; const PixelAlphaCompositionMode Expected = PixelAlphaCompositionMode.SrcOver;
Assert.Equal(Expected, this.newTextGraphicsOptions.AlphaCompositionMode); Assert.Equal(Expected, this.newTextGraphicsOptions.AlphaCompositionMode);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.AlphaCompositionMode);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.AlphaCompositionMode); Assert.Equal(Expected, this.cloneTextGraphicsOptions.AlphaCompositionMode);
} }
@ -67,7 +61,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{ {
const bool Expected = true; const bool Expected = true;
Assert.Equal(Expected, this.newTextGraphicsOptions.ApplyKerning); Assert.Equal(Expected, this.newTextGraphicsOptions.ApplyKerning);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.ApplyKerning);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.ApplyKerning); Assert.Equal(Expected, this.cloneTextGraphicsOptions.ApplyKerning);
} }
@ -76,7 +69,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{ {
const HorizontalAlignment Expected = HorizontalAlignment.Left; const HorizontalAlignment Expected = HorizontalAlignment.Left;
Assert.Equal(Expected, this.newTextGraphicsOptions.HorizontalAlignment); Assert.Equal(Expected, this.newTextGraphicsOptions.HorizontalAlignment);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.HorizontalAlignment);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.HorizontalAlignment); Assert.Equal(Expected, this.cloneTextGraphicsOptions.HorizontalAlignment);
} }
@ -85,7 +77,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{ {
const VerticalAlignment Expected = VerticalAlignment.Top; const VerticalAlignment Expected = VerticalAlignment.Top;
Assert.Equal(Expected, this.newTextGraphicsOptions.VerticalAlignment); Assert.Equal(Expected, this.newTextGraphicsOptions.VerticalAlignment);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.VerticalAlignment);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.VerticalAlignment); Assert.Equal(Expected, this.cloneTextGraphicsOptions.VerticalAlignment);
} }
@ -94,7 +85,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{ {
const float Expected = 72F; const float Expected = 72F;
Assert.Equal(Expected, this.newTextGraphicsOptions.DpiX); Assert.Equal(Expected, this.newTextGraphicsOptions.DpiX);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.DpiX);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.DpiX); Assert.Equal(Expected, this.cloneTextGraphicsOptions.DpiX);
} }
@ -103,7 +93,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{ {
const float Expected = 72F; const float Expected = 72F;
Assert.Equal(Expected, this.newTextGraphicsOptions.DpiY); Assert.Equal(Expected, this.newTextGraphicsOptions.DpiY);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.DpiY);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.DpiY); Assert.Equal(Expected, this.cloneTextGraphicsOptions.DpiY);
} }
@ -112,7 +101,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{ {
const float Expected = 4F; const float Expected = 4F;
Assert.Equal(Expected, this.newTextGraphicsOptions.TabWidth); Assert.Equal(Expected, this.newTextGraphicsOptions.TabWidth);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.TabWidth);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.TabWidth); Assert.Equal(Expected, this.cloneTextGraphicsOptions.TabWidth);
} }
@ -121,10 +109,77 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{ {
const float Expected = 0F; const float Expected = 0F;
Assert.Equal(Expected, this.newTextGraphicsOptions.WrapTextWidth); Assert.Equal(Expected, this.newTextGraphicsOptions.WrapTextWidth);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.WrapTextWidth);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.WrapTextWidth); Assert.Equal(Expected, this.cloneTextGraphicsOptions.WrapTextWidth);
} }
[Fact]
public void NonDefaultClone()
{
var expected = new TextGraphicsOptions
{
AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop,
Antialias = false,
AntialiasSubpixelDepth = 23,
ApplyKerning = false,
BlendPercentage = .25F,
ColorBlendingMode = PixelColorBlendingMode.HardLight,
DpiX = 46F,
DpiY = 52F,
HorizontalAlignment = HorizontalAlignment.Center,
TabWidth = 3F,
VerticalAlignment = VerticalAlignment.Bottom,
WrapTextWidth = 42F
};
TextGraphicsOptions actual = expected.DeepClone();
Assert.Equal(expected.AlphaCompositionMode, actual.AlphaCompositionMode);
Assert.Equal(expected.Antialias, actual.Antialias);
Assert.Equal(expected.AntialiasSubpixelDepth, actual.AntialiasSubpixelDepth);
Assert.Equal(expected.ApplyKerning, actual.ApplyKerning);
Assert.Equal(expected.BlendPercentage, actual.BlendPercentage);
Assert.Equal(expected.ColorBlendingMode, actual.ColorBlendingMode);
Assert.Equal(expected.DpiX, actual.DpiX);
Assert.Equal(expected.DpiY, actual.DpiY);
Assert.Equal(expected.HorizontalAlignment, actual.HorizontalAlignment);
Assert.Equal(expected.TabWidth, actual.TabWidth);
Assert.Equal(expected.VerticalAlignment, actual.VerticalAlignment);
Assert.Equal(expected.WrapTextWidth, actual.WrapTextWidth);
}
[Fact]
public void CloneIsDeep()
{
var expected = new TextGraphicsOptions();
TextGraphicsOptions actual = expected.DeepClone();
actual.AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop;
actual.Antialias = false;
actual.AntialiasSubpixelDepth = 23;
actual.ApplyKerning = false;
actual.BlendPercentage = .25F;
actual.ColorBlendingMode = PixelColorBlendingMode.HardLight;
actual.DpiX = 46F;
actual.DpiY = 52F;
actual.HorizontalAlignment = HorizontalAlignment.Center;
actual.TabWidth = 3F;
actual.VerticalAlignment = VerticalAlignment.Bottom;
actual.WrapTextWidth = 42F;
Assert.NotEqual(expected.AlphaCompositionMode, actual.AlphaCompositionMode);
Assert.NotEqual(expected.Antialias, actual.Antialias);
Assert.NotEqual(expected.AntialiasSubpixelDepth, actual.AntialiasSubpixelDepth);
Assert.NotEqual(expected.ApplyKerning, actual.ApplyKerning);
Assert.NotEqual(expected.BlendPercentage, actual.BlendPercentage);
Assert.NotEqual(expected.ColorBlendingMode, actual.ColorBlendingMode);
Assert.NotEqual(expected.DpiX, actual.DpiX);
Assert.NotEqual(expected.DpiY, actual.DpiY);
Assert.NotEqual(expected.HorizontalAlignment, actual.HorizontalAlignment);
Assert.NotEqual(expected.TabWidth, actual.TabWidth);
Assert.NotEqual(expected.VerticalAlignment, actual.VerticalAlignment);
Assert.NotEqual(expected.WrapTextWidth, actual.WrapTextWidth);
}
[Fact] [Fact]
public void ExplicitCastOfGraphicsOptions() public void ExplicitCastOfGraphicsOptions()
{ {

44
tests/ImageSharp.Tests/GraphicsOptionsTests.cs

@ -2,24 +2,24 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
public class GraphicsOptionsTests public class GraphicsOptionsTests
{ {
private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
private readonly GraphicsOptions newGraphicsOptions = new GraphicsOptions(); private readonly GraphicsOptions newGraphicsOptions = new GraphicsOptions();
private readonly GraphicsOptions defaultGraphicsOptions = GraphicsOptions.Default; private readonly GraphicsOptions cloneGraphicsOptions = new GraphicsOptions().DeepClone();
private readonly GraphicsOptions cloneGraphicsOptions = GraphicsOptions.Default.Clone();
[Fact] [Fact]
public void DefaultGraphicsOptionsIsNotNull() => Assert.True(this.defaultGraphicsOptions != null); public void CloneGraphicsOptionsIsNotNull() => Assert.True(this.cloneGraphicsOptions != null);
[Fact] [Fact]
public void DefaultGraphicsOptionsAntialias() public void DefaultGraphicsOptionsAntialias()
{ {
Assert.True(this.newGraphicsOptions.Antialias); Assert.True(this.newGraphicsOptions.Antialias);
Assert.True(this.defaultGraphicsOptions.Antialias);
Assert.True(this.cloneGraphicsOptions.Antialias); Assert.True(this.cloneGraphicsOptions.Antialias);
} }
@ -28,7 +28,6 @@ namespace SixLabors.ImageSharp.Tests
{ {
const int Expected = 16; const int Expected = 16;
Assert.Equal(Expected, this.newGraphicsOptions.AntialiasSubpixelDepth); Assert.Equal(Expected, this.newGraphicsOptions.AntialiasSubpixelDepth);
Assert.Equal(Expected, this.defaultGraphicsOptions.AntialiasSubpixelDepth);
Assert.Equal(Expected, this.cloneGraphicsOptions.AntialiasSubpixelDepth); Assert.Equal(Expected, this.cloneGraphicsOptions.AntialiasSubpixelDepth);
} }
@ -37,7 +36,6 @@ namespace SixLabors.ImageSharp.Tests
{ {
const float Expected = 1F; const float Expected = 1F;
Assert.Equal(Expected, this.newGraphicsOptions.BlendPercentage); Assert.Equal(Expected, this.newGraphicsOptions.BlendPercentage);
Assert.Equal(Expected, this.defaultGraphicsOptions.BlendPercentage);
Assert.Equal(Expected, this.cloneGraphicsOptions.BlendPercentage); Assert.Equal(Expected, this.cloneGraphicsOptions.BlendPercentage);
} }
@ -46,7 +44,6 @@ namespace SixLabors.ImageSharp.Tests
{ {
const PixelColorBlendingMode Expected = PixelColorBlendingMode.Normal; const PixelColorBlendingMode Expected = PixelColorBlendingMode.Normal;
Assert.Equal(Expected, this.newGraphicsOptions.ColorBlendingMode); Assert.Equal(Expected, this.newGraphicsOptions.ColorBlendingMode);
Assert.Equal(Expected, this.defaultGraphicsOptions.ColorBlendingMode);
Assert.Equal(Expected, this.cloneGraphicsOptions.ColorBlendingMode); Assert.Equal(Expected, this.cloneGraphicsOptions.ColorBlendingMode);
} }
@ -55,10 +52,41 @@ namespace SixLabors.ImageSharp.Tests
{ {
const PixelAlphaCompositionMode Expected = PixelAlphaCompositionMode.SrcOver; const PixelAlphaCompositionMode Expected = PixelAlphaCompositionMode.SrcOver;
Assert.Equal(Expected, this.newGraphicsOptions.AlphaCompositionMode); Assert.Equal(Expected, this.newGraphicsOptions.AlphaCompositionMode);
Assert.Equal(Expected, this.defaultGraphicsOptions.AlphaCompositionMode);
Assert.Equal(Expected, this.cloneGraphicsOptions.AlphaCompositionMode); Assert.Equal(Expected, this.cloneGraphicsOptions.AlphaCompositionMode);
} }
[Fact]
public void NonDefaultClone()
{
var expected = new GraphicsOptions
{
AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop,
Antialias = false,
AntialiasSubpixelDepth = 23,
BlendPercentage = .25F,
ColorBlendingMode = PixelColorBlendingMode.HardLight,
};
GraphicsOptions actual = expected.DeepClone();
Assert.Equal(expected, actual, graphicsOptionsComparer);
}
[Fact]
public void CloneIsDeep()
{
var expected = new GraphicsOptions();
GraphicsOptions actual = expected.DeepClone();
actual.AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop;
actual.Antialias = false;
actual.AntialiasSubpixelDepth = 23;
actual.BlendPercentage = .25F;
actual.ColorBlendingMode = PixelColorBlendingMode.HardLight;
Assert.NotEqual(expected, actual, graphicsOptionsComparer);
}
[Fact] [Fact]
public void IsOpaqueColor() public void IsOpaqueColor()
{ {

24
tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs

@ -1,22 +1,24 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.ImageSharp.Processing.Processors.Overlays;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Effects namespace SixLabors.ImageSharp.Tests.Processing.Effects
{ {
public class BackgroundColorTest : BaseImageOperationsExtensionTest public class BackgroundColorTest : BaseImageOperationsExtensionTest
{ {
private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
[Fact] [Fact]
public void BackgroundColor_amount_BackgroundColorProcessorDefaultsSet() public void BackgroundColor_amount_BackgroundColorProcessorDefaultsSet()
{ {
this.operations.BackgroundColor(Color.BlanchedAlmond); this.operations.BackgroundColor(Color.BlanchedAlmond);
var processor = this.Verify<BackgroundColorProcessor>(); BackgroundColorProcessor processor = this.Verify<BackgroundColorProcessor>();
Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions); Assert.Equal(new GraphicsOptions(), processor.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.BlanchedAlmond, processor.Color); Assert.Equal(Color.BlanchedAlmond, processor.Color);
} }
@ -24,9 +26,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects
public void BackgroundColor_amount_rect_BackgroundColorProcessorDefaultsSet() public void BackgroundColor_amount_rect_BackgroundColorProcessorDefaultsSet()
{ {
this.operations.BackgroundColor(Color.BlanchedAlmond, this.rect); this.operations.BackgroundColor(Color.BlanchedAlmond, this.rect);
var processor = this.Verify<BackgroundColorProcessor>(this.rect); BackgroundColorProcessor processor = this.Verify<BackgroundColorProcessor>(this.rect);
Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions); Assert.Equal(new GraphicsOptions(), processor.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.BlanchedAlmond, processor.Color); Assert.Equal(Color.BlanchedAlmond, processor.Color);
} }
@ -34,9 +36,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects
public void BackgroundColor_amount_options_BackgroundColorProcessorDefaultsSet() public void BackgroundColor_amount_options_BackgroundColorProcessorDefaultsSet()
{ {
this.operations.BackgroundColor(this.options, Color.BlanchedAlmond); this.operations.BackgroundColor(this.options, Color.BlanchedAlmond);
var processor = this.Verify<BackgroundColorProcessor>(); BackgroundColorProcessor processor = this.Verify<BackgroundColorProcessor>();
Assert.Equal(this.options, processor.GraphicsOptions); Assert.Equal(this.options, processor.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.BlanchedAlmond, processor.Color); Assert.Equal(Color.BlanchedAlmond, processor.Color);
} }
@ -44,10 +46,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects
public void BackgroundColor_amount_rect_options_BackgroundColorProcessorDefaultsSet() public void BackgroundColor_amount_rect_options_BackgroundColorProcessorDefaultsSet()
{ {
this.operations.BackgroundColor(this.options, Color.BlanchedAlmond, this.rect); this.operations.BackgroundColor(this.options, Color.BlanchedAlmond, this.rect);
var processor = this.Verify<BackgroundColorProcessor>(this.rect); BackgroundColorProcessor processor = this.Verify<BackgroundColorProcessor>(this.rect);
Assert.Equal(this.options, processor.GraphicsOptions); Assert.Equal(this.options, processor.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.BlanchedAlmond, processor.Color); Assert.Equal(Color.BlanchedAlmond, processor.Color);
} }
} }
} }

23
tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs

@ -1,10 +1,11 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.ImageSharp.Processing.Processors.Overlays;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Primitives; using SixLabors.Primitives;
using Xunit; using Xunit;
@ -12,13 +13,15 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
{ {
public class GlowTest : BaseImageOperationsExtensionTest public class GlowTest : BaseImageOperationsExtensionTest
{ {
private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
[Fact] [Fact]
public void Glow_GlowProcessorWithDefaultValues() public void Glow_GlowProcessorWithDefaultValues()
{ {
this.operations.Glow(); this.operations.Glow();
var p = this.Verify<GlowProcessor>(); GlowProcessor p = this.Verify<GlowProcessor>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.Black, p.GlowColor); Assert.Equal(Color.Black, p.GlowColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius);
} }
@ -27,9 +30,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
public void Glow_Color_GlowProcessorWithDefaultValues() public void Glow_Color_GlowProcessorWithDefaultValues()
{ {
this.operations.Glow(Rgba32.Aquamarine); this.operations.Glow(Rgba32.Aquamarine);
var p = this.Verify<GlowProcessor>(); GlowProcessor p = this.Verify<GlowProcessor>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.Aquamarine, p.GlowColor); Assert.Equal(Color.Aquamarine, p.GlowColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius);
} }
@ -38,9 +41,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
public void Glow_Radux_GlowProcessorWithDefaultValues() public void Glow_Radux_GlowProcessorWithDefaultValues()
{ {
this.operations.Glow(3.5f); this.operations.Glow(3.5f);
var p = this.Verify<GlowProcessor>(); GlowProcessor p = this.Verify<GlowProcessor>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.Black, p.GlowColor); Assert.Equal(Color.Black, p.GlowColor);
Assert.Equal(ValueSize.Absolute(3.5f), p.Radius); Assert.Equal(ValueSize.Absolute(3.5f), p.Radius);
} }
@ -50,11 +53,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
{ {
var rect = new Rectangle(12, 123, 43, 65); var rect = new Rectangle(12, 123, 43, 65);
this.operations.Glow(rect); this.operations.Glow(rect);
var p = this.Verify<GlowProcessor>(rect); GlowProcessor p = this.Verify<GlowProcessor>(rect);
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.Black, p.GlowColor); Assert.Equal(Color.Black, p.GlowColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius);
} }
} }
} }

23
tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs

@ -1,9 +1,10 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.ImageSharp.Processing.Processors.Overlays;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Primitives; using SixLabors.Primitives;
using Xunit; using Xunit;
@ -11,13 +12,15 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
{ {
public class VignetteTest : BaseImageOperationsExtensionTest public class VignetteTest : BaseImageOperationsExtensionTest
{ {
private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
[Fact] [Fact]
public void Vignette_VignetteProcessorWithDefaultValues() public void Vignette_VignetteProcessorWithDefaultValues()
{ {
this.operations.Vignette(); this.operations.Vignette();
var p = this.Verify<VignetteProcessor>(); VignetteProcessor p = this.Verify<VignetteProcessor>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.Black, p.VignetteColor); Assert.Equal(Color.Black, p.VignetteColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX);
Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY); Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY);
@ -27,9 +30,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
public void Vignette_Color_VignetteProcessorWithDefaultValues() public void Vignette_Color_VignetteProcessorWithDefaultValues()
{ {
this.operations.Vignette(Color.Aquamarine); this.operations.Vignette(Color.Aquamarine);
var p = this.Verify<VignetteProcessor>(); VignetteProcessor p = this.Verify<VignetteProcessor>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.Aquamarine, p.VignetteColor); Assert.Equal(Color.Aquamarine, p.VignetteColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX);
Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY); Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY);
@ -39,9 +42,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
public void Vignette_Radux_VignetteProcessorWithDefaultValues() public void Vignette_Radux_VignetteProcessorWithDefaultValues()
{ {
this.operations.Vignette(3.5f, 12123f); this.operations.Vignette(3.5f, 12123f);
var p = this.Verify<VignetteProcessor>(); VignetteProcessor p = this.Verify<VignetteProcessor>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.Black, p.VignetteColor); Assert.Equal(Color.Black, p.VignetteColor);
Assert.Equal(ValueSize.Absolute(3.5f), p.RadiusX); Assert.Equal(ValueSize.Absolute(3.5f), p.RadiusX);
Assert.Equal(ValueSize.Absolute(12123f), p.RadiusY); Assert.Equal(ValueSize.Absolute(12123f), p.RadiusY);
@ -52,12 +55,12 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
{ {
var rect = new Rectangle(12, 123, 43, 65); var rect = new Rectangle(12, 123, 43, 65);
this.operations.Vignette(rect); this.operations.Vignette(rect);
var p = this.Verify<VignetteProcessor>(rect); VignetteProcessor p = this.Verify<VignetteProcessor>(rect);
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer);
Assert.Equal(Color.Black, p.VignetteColor); Assert.Equal(Color.Black, p.VignetteColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX);
Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY); Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY);
} }
} }
} }

21
tests/ImageSharp.Tests/TestUtilities/GraphicsOptionsComparer.cs

@ -0,0 +1,21 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
namespace SixLabors.ImageSharp.Tests.TestUtilities
{
public class GraphicsOptionsComparer : IEqualityComparer<GraphicsOptions>
{
public bool Equals(GraphicsOptions x, GraphicsOptions y)
{
return x.AlphaCompositionMode == y.AlphaCompositionMode
&& x.Antialias == y.Antialias
&& x.AntialiasSubpixelDepth == y.AntialiasSubpixelDepth
&& x.BlendPercentage == y.BlendPercentage
&& x.ColorBlendingMode == y.ColorBlendingMode;
}
public int GetHashCode(GraphicsOptions obj) => obj.GetHashCode();
}
}
Loading…
Cancel
Save