Browse Source

Drop Default, use DeepClone + tests

af/merge-core
James Jackson-South 7 years ago
parent
commit
241c50a79e
  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(
image,
Point.Empty,
GraphicsOptions.Default.ColorBlendingMode,
GraphicsOptions.Default.AlphaCompositionMode,
new GraphicsOptions().ColorBlendingMode,
new GraphicsOptions().AlphaCompositionMode,
opacity));
/// <summary>
@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Processing
image,
Point.Empty,
colorBlending,
GraphicsOptions.Default.AlphaCompositionMode,
new GraphicsOptions().AlphaCompositionMode,
opacity));
/// <summary>
@ -105,8 +105,8 @@ namespace SixLabors.ImageSharp.Processing
new DrawImageProcessor(
image,
location,
GraphicsOptions.Default.ColorBlendingMode,
GraphicsOptions.Default.AlphaCompositionMode,
new GraphicsOptions().ColorBlendingMode,
new GraphicsOptions().AlphaCompositionMode,
opacity));
/// <summary>
@ -129,7 +129,7 @@ namespace SixLabors.ImageSharp.Processing
image,
location,
colorBlending,
GraphicsOptions.Default.AlphaCompositionMode,
new GraphicsOptions().AlphaCompositionMode,
opacity));
/// <summary>

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

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext
Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths) =>
source.Draw(GraphicsOptions.Default, pen, paths);
source.Draw(new GraphicsOptions(), pen, paths);
/// <summary>
/// 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>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path) =>
source.Draw(GraphicsOptions.Default, pen, path);
source.Draw(new GraphicsOptions(), pen, path);
/// <summary>
/// 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,
IPen pen,
params PointF[] points) =>
source.Draw(GraphicsOptions.Default, pen, new Polygon(new LinearLineSegment(points)));
source.Draw(new GraphicsOptions(), pen, new Polygon(new LinearLineSegment(points)));
/// <summary>
/// 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>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape) =>
source.Draw(GraphicsOptions.Default, pen, shape);
source.Draw(new GraphicsOptions(), pen, shape);
/// <summary>
/// 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,
Color color,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, color, location);
source.DrawText(new TextGraphicsOptions(), text, font, color, location);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Processing
Font font,
IBrush brush,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, brush, location);
source.DrawText(new TextGraphicsOptions(), text, font, brush, location);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Processing
Font font,
IPen pen,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, pen, location);
source.DrawText(new TextGraphicsOptions(), text, font, pen, location);
/// <summary>
/// Draws the text onto the the image outlined via the pen.
@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.Processing
IBrush brush,
IPen pen,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, brush, pen, location);
source.DrawText(new TextGraphicsOptions(), text, font, brush, pen, location);
/// <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.

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

@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Processing
this IImageProcessingContext source,
IBrush brush,
Action<PathBuilder> path) =>
source.Fill(GraphicsOptions.Default, brush, path);
source.Fill(new GraphicsOptions(), brush, path);
/// <summary>
/// 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,
IBrush brush,
IPathCollection paths) =>
source.Fill(GraphicsOptions.Default, brush, paths);
source.Fill(new GraphicsOptions(), brush, paths);
/// <summary>
/// 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>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
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>
/// 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>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush) =>
source.Fill(GraphicsOptions.Default, brush);
source.Fill(new GraphicsOptions(), brush);
/// <summary>
/// Flood fills the image with the specified color.
@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="region">The region.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region) =>
source.Fill(GraphicsOptions.Default, brush, region);
source.Fill(new GraphicsOptions(), brush, region);
/// <summary>
/// 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.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.Fonts;
using SixLabors.ImageSharp.PixelFormats;
@ -10,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing
/// <summary>
/// Options for influencing the drawing functions.
/// </summary>
public class TextGraphicsOptions
public class TextGraphicsOptions : IDeepCloneable<TextGraphicsOptions>
{
private int antialiasSubpixelDepth = 16;
private float blendPercentage = 1F;
@ -18,6 +17,29 @@ namespace SixLabors.ImageSharp.Processing
private float dpiX = 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>
/// Gets the default <see cref="TextGraphicsOptions"/> instance.
/// </summary>
@ -194,27 +216,7 @@ namespace SixLabors.ImageSharp.Processing
};
}
/// <summary>
/// Creates a shallow copy of the <see cref="TextGraphicsOptions"/>.
/// </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
};
}
/// <inheritdoc/>
public TextGraphicsOptions DeepClone() => new TextGraphicsOptions(this);
}
}

36
src/ImageSharp/GraphicsOptions.cs

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

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.
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>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, Color color) =>
BackgroundColor(source, GraphicsOptions.Default, color);
BackgroundColor(source, new GraphicsOptions(), color);
/// <summary>
/// Replaces the background color of image with the given one.
@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing
this IImageProcessingContext source,
Color color,
Rectangle rectangle) =>
BackgroundColor(source, GraphicsOptions.Default, color, rectangle);
BackgroundColor(source, new GraphicsOptions(), color, rectangle);
/// <summary>
/// Replaces the background color of image with the given one.
@ -66,4 +66,4 @@ namespace SixLabors.ImageSharp.Processing
Rectangle 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>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Glow(this IImageProcessingContext source) =>
Glow(source, GraphicsOptions.Default);
Glow(source, new GraphicsOptions());
/// <summary>
/// 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>
public static IImageProcessingContext Glow(this IImageProcessingContext source, Color color)
{
return Glow(source, GraphicsOptions.Default, color);
return Glow(source, new GraphicsOptions(), color);
}
/// <summary>
@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="radius">The the radius.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius) =>
Glow(source, GraphicsOptions.Default, radius);
Glow(source, new GraphicsOptions(), radius);
/// <summary>
/// Applies a radial glow effect to an image.
@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle) =>
source.Glow(GraphicsOptions.Default, rectangle);
source.Glow(new GraphicsOptions(), rectangle);
/// <summary>
/// Applies a radial glow effect to an image.
@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Processing
Color color,
float radius,
Rectangle rectangle) =>
source.Glow(GraphicsOptions.Default, color, ValueSize.Absolute(radius), rectangle);
source.Glow(new GraphicsOptions(), color, ValueSize.Absolute(radius), rectangle);
/// <summary>
/// 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>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Vignette(this IImageProcessingContext source) =>
Vignette(source, GraphicsOptions.Default);
Vignette(source, new GraphicsOptions());
/// <summary>
/// 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>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Vignette(this IImageProcessingContext source, Color color) =>
Vignette(source, GraphicsOptions.Default, color);
Vignette(source, new GraphicsOptions(), color);
/// <summary>
/// Applies a radial vignette effect to an image.
@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing
this IImageProcessingContext source,
float radiusX,
float radiusY) =>
Vignette(source, GraphicsOptions.Default, radiusX, radiusY);
Vignette(source, new GraphicsOptions(), radiusX, radiusY);
/// <summary>
/// Applies a radial vignette effect to an image.
@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle) =>
Vignette(source, GraphicsOptions.Default, rectangle);
Vignette(source, new GraphicsOptions(), rectangle);
/// <summary>
/// Applies a radial vignette effect to an image.
@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Processing
float radiusX,
float radiusY,
Rectangle rectangle) =>
source.Vignette(GraphicsOptions.Default, color, radiusX, radiusY, rectangle);
source.Vignette(new GraphicsOptions(), color, radiusX, radiusY, rectangle);
/// <summary>
/// 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="radius">The radius of the glow.</param>
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>
/// <param name="color">The color of the vignette.</param>
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()
{
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.Processors.Drawing;
using SixLabors.ImageSharp.Tests.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Shapes;
using Xunit;
@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{
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;
Pen pen = Pens.Solid(Rgba32.HotPink, 1);
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);
Assert.Equal(GraphicsOptions.Default, processor.Options);
Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapePath region = Assert.IsType<ShapePath>(processor.Region);
@ -60,13 +63,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
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++)
{
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);
Assert.IsType<ComplexPolygon>(region.Shape);
@ -84,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{
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);
Assert.IsType<ComplexPolygon>(region.Shape);
@ -97,13 +100,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
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++)
{
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);
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.Processors.Drawing;
using SixLabors.ImageSharp.Tests.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Shapes;
using Xunit;
@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{
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;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
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);
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);
@ -44,10 +47,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
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>();
Assert.Equal(this.noneDefault, processor.Options);
Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -62,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
this.operations.Fill(this.color, this.path);
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);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -75,10 +78,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
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>();
Assert.Equal(this.noneDefault, processor.Options);
Assert.Equal(this.nonDefault, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
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.Processors.Drawing;
using SixLabors.ImageSharp.Tests.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Shapes;
using Xunit;
@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{
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;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
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);
Assert.Equal(GraphicsOptions.Default, processor.Options);
Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
@ -61,13 +64,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
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++)
{
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);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -86,7 +89,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{
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);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -100,13 +103,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
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++)
{
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);
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.Processors.Drawing;
using SixLabors.ImageSharp.Tests.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Shapes;
using Xunit;
@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{
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;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
SixLabors.Primitives.PointF[] path = {
@ -32,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
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);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -44,10 +47,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
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>();
Assert.Equal(this.noneDefault, processor.Options);
Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -63,7 +66,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
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);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
@ -76,10 +79,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
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>();
Assert.Equal(this.noneDefault, processor.Options);
Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
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.Processors.Drawing;
using SixLabors.ImageSharp.Tests.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{
public class FillRectangle : BaseImageOperationsExtensionTest
{
GraphicsOptions noneDefault = new GraphicsOptions { Antialias = false };
Color color = Color.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
SixLabors.Primitives.Rectangle rectangle = new SixLabors.Primitives.Rectangle(10, 10, 77, 76);
private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
private GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false };
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]
public void CorrectlySetsBrushAndRectangle()
@ -24,7 +26,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
this.operations.Fill(this.brush, this.rectangle);
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);
Shapes.RectangularPolygon rect = Assert.IsType<Shapes.RectangularPolygon>(region.Shape);
@ -39,10 +41,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
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>();
Assert.Equal(this.noneDefault, processor.Options);
Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
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);
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);
Shapes.RectangularPolygon rect = Assert.IsType<Shapes.RectangularPolygon>(region.Shape);
@ -76,10 +78,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
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>();
Assert.Equal(this.noneDefault, processor.Options);
Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
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
{
private readonly TextGraphicsOptions newTextGraphicsOptions = new TextGraphicsOptions();
private readonly TextGraphicsOptions defaultTextGraphicsOptions = TextGraphicsOptions.Default;
private readonly TextGraphicsOptions cloneTextGraphicsOptions = TextGraphicsOptions.Default.Clone();
private readonly TextGraphicsOptions cloneTextGraphicsOptions = new TextGraphicsOptions().DeepClone();
[Fact]
public void DefaultTextGraphicsOptionsIsNotNull() => Assert.True(this.defaultTextGraphicsOptions != null);
public void CloneTextGraphicsOptionsIsNotNull() => Assert.True(this.cloneTextGraphicsOptions != null);
[Fact]
public void DefaultTextGraphicsOptionsAntialias()
{
Assert.True(this.newTextGraphicsOptions.Antialias);
Assert.True(this.defaultTextGraphicsOptions.Antialias);
Assert.True(this.cloneTextGraphicsOptions.Antialias);
}
@ -31,7 +29,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
const int Expected = 16;
Assert.Equal(Expected, this.newTextGraphicsOptions.AntialiasSubpixelDepth);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.AntialiasSubpixelDepth);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.AntialiasSubpixelDepth);
}
@ -40,7 +37,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
const float Expected = 1F;
Assert.Equal(Expected, this.newTextGraphicsOptions.BlendPercentage);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.BlendPercentage);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.BlendPercentage);
}
@ -49,7 +45,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
const PixelColorBlendingMode Expected = PixelColorBlendingMode.Normal;
Assert.Equal(Expected, this.newTextGraphicsOptions.ColorBlendingMode);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.ColorBlendingMode);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.ColorBlendingMode);
}
@ -58,7 +53,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
const PixelAlphaCompositionMode Expected = PixelAlphaCompositionMode.SrcOver;
Assert.Equal(Expected, this.newTextGraphicsOptions.AlphaCompositionMode);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.AlphaCompositionMode);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.AlphaCompositionMode);
}
@ -67,7 +61,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
const bool Expected = true;
Assert.Equal(Expected, this.newTextGraphicsOptions.ApplyKerning);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.ApplyKerning);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.ApplyKerning);
}
@ -76,7 +69,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
const HorizontalAlignment Expected = HorizontalAlignment.Left;
Assert.Equal(Expected, this.newTextGraphicsOptions.HorizontalAlignment);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.HorizontalAlignment);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.HorizontalAlignment);
}
@ -85,7 +77,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
const VerticalAlignment Expected = VerticalAlignment.Top;
Assert.Equal(Expected, this.newTextGraphicsOptions.VerticalAlignment);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.VerticalAlignment);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.VerticalAlignment);
}
@ -94,7 +85,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
const float Expected = 72F;
Assert.Equal(Expected, this.newTextGraphicsOptions.DpiX);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.DpiX);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.DpiX);
}
@ -103,7 +93,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
const float Expected = 72F;
Assert.Equal(Expected, this.newTextGraphicsOptions.DpiY);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.DpiY);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.DpiY);
}
@ -112,7 +101,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
const float Expected = 4F;
Assert.Equal(Expected, this.newTextGraphicsOptions.TabWidth);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.TabWidth);
Assert.Equal(Expected, this.cloneTextGraphicsOptions.TabWidth);
}
@ -121,10 +109,77 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
const float Expected = 0F;
Assert.Equal(Expected, this.newTextGraphicsOptions.WrapTextWidth);
Assert.Equal(Expected, this.defaultTextGraphicsOptions.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]
public void ExplicitCastOfGraphicsOptions()
{

44
tests/ImageSharp.Tests/GraphicsOptionsTests.cs

@ -2,24 +2,24 @@
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit;
namespace SixLabors.ImageSharp.Tests
{
public class GraphicsOptionsTests
{
private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
private readonly GraphicsOptions newGraphicsOptions = new GraphicsOptions();
private readonly GraphicsOptions defaultGraphicsOptions = GraphicsOptions.Default;
private readonly GraphicsOptions cloneGraphicsOptions = GraphicsOptions.Default.Clone();
private readonly GraphicsOptions cloneGraphicsOptions = new GraphicsOptions().DeepClone();
[Fact]
public void DefaultGraphicsOptionsIsNotNull() => Assert.True(this.defaultGraphicsOptions != null);
public void CloneGraphicsOptionsIsNotNull() => Assert.True(this.cloneGraphicsOptions != null);
[Fact]
public void DefaultGraphicsOptionsAntialias()
{
Assert.True(this.newGraphicsOptions.Antialias);
Assert.True(this.defaultGraphicsOptions.Antialias);
Assert.True(this.cloneGraphicsOptions.Antialias);
}
@ -28,7 +28,6 @@ namespace SixLabors.ImageSharp.Tests
{
const int Expected = 16;
Assert.Equal(Expected, this.newGraphicsOptions.AntialiasSubpixelDepth);
Assert.Equal(Expected, this.defaultGraphicsOptions.AntialiasSubpixelDepth);
Assert.Equal(Expected, this.cloneGraphicsOptions.AntialiasSubpixelDepth);
}
@ -37,7 +36,6 @@ namespace SixLabors.ImageSharp.Tests
{
const float Expected = 1F;
Assert.Equal(Expected, this.newGraphicsOptions.BlendPercentage);
Assert.Equal(Expected, this.defaultGraphicsOptions.BlendPercentage);
Assert.Equal(Expected, this.cloneGraphicsOptions.BlendPercentage);
}
@ -46,7 +44,6 @@ namespace SixLabors.ImageSharp.Tests
{
const PixelColorBlendingMode Expected = PixelColorBlendingMode.Normal;
Assert.Equal(Expected, this.newGraphicsOptions.ColorBlendingMode);
Assert.Equal(Expected, this.defaultGraphicsOptions.ColorBlendingMode);
Assert.Equal(Expected, this.cloneGraphicsOptions.ColorBlendingMode);
}
@ -55,10 +52,41 @@ namespace SixLabors.ImageSharp.Tests
{
const PixelAlphaCompositionMode Expected = PixelAlphaCompositionMode.SrcOver;
Assert.Equal(Expected, this.newGraphicsOptions.AlphaCompositionMode);
Assert.Equal(Expected, this.defaultGraphicsOptions.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]
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.
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Overlays;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Effects
{
public class BackgroundColorTest : BaseImageOperationsExtensionTest
{
private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
[Fact]
public void BackgroundColor_amount_BackgroundColorProcessorDefaultsSet()
{
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);
}
@ -24,9 +26,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects
public void BackgroundColor_amount_rect_BackgroundColorProcessorDefaultsSet()
{
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);
}
@ -34,9 +36,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects
public void BackgroundColor_amount_options_BackgroundColorProcessorDefaultsSet()
{
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);
}
@ -44,10 +46,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects
public void BackgroundColor_amount_rect_options_BackgroundColorProcessorDefaultsSet()
{
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);
}
}
}
}

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.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Overlays;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Primitives;
using Xunit;
@ -12,13 +13,15 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
{
public class GlowTest : BaseImageOperationsExtensionTest
{
private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
[Fact]
public void Glow_GlowProcessorWithDefaultValues()
{
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(ValueSize.PercentageOfWidth(.5f), p.Radius);
}
@ -27,9 +30,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
public void Glow_Color_GlowProcessorWithDefaultValues()
{
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(ValueSize.PercentageOfWidth(.5f), p.Radius);
}
@ -38,9 +41,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
public void Glow_Radux_GlowProcessorWithDefaultValues()
{
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(ValueSize.Absolute(3.5f), p.Radius);
}
@ -50,11 +53,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
{
var rect = new Rectangle(12, 123, 43, 65);
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(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.
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Overlays;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.Primitives;
using Xunit;
@ -11,13 +12,15 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
{
public class VignetteTest : BaseImageOperationsExtensionTest
{
private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer();
[Fact]
public void Vignette_VignetteProcessorWithDefaultValues()
{
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(ValueSize.PercentageOfWidth(.5f), p.RadiusX);
Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY);
@ -27,9 +30,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
public void Vignette_Color_VignetteProcessorWithDefaultValues()
{
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(ValueSize.PercentageOfWidth(.5f), p.RadiusX);
Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY);
@ -39,9 +42,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
public void Vignette_Radux_VignetteProcessorWithDefaultValues()
{
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(ValueSize.Absolute(3.5f), p.RadiusX);
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);
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(ValueSize.PercentageOfWidth(.5f), p.RadiusX);
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