|
|
|
@ -15,14 +15,26 @@ namespace SixLabors.ImageSharp.Tests.Drawing |
|
|
|
[GroupOutput("Drawing")] |
|
|
|
public class SolidFillBlendedShapesTests |
|
|
|
{ |
|
|
|
public static IEnumerable<object[]> modes = |
|
|
|
((PixelColorBlendingMode[])Enum.GetValues(typeof(PixelColorBlendingMode))).Select(x => new object[] { x }); |
|
|
|
public static IEnumerable<object[]> modes = GetAllModeCombinations(); |
|
|
|
|
|
|
|
private static IEnumerable<object[]> GetAllModeCombinations() |
|
|
|
{ |
|
|
|
foreach (var blending in Enum.GetValues(typeof(PixelColorBlendingMode))) |
|
|
|
{ |
|
|
|
foreach (var composition in Enum.GetValues(typeof(PixelAlphaCompositionMode))) |
|
|
|
{ |
|
|
|
yield return new object[] { blending, composition }; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)] |
|
|
|
public void _1DarkBlueRect_2BlendHotPinkRect<TPixel>( |
|
|
|
TestImageProvider<TPixel> provider, |
|
|
|
PixelColorBlendingMode mode) |
|
|
|
PixelColorBlendingMode blending, |
|
|
|
PixelAlphaCompositionMode composition) |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using (Image<TPixel> img = provider.GetImage()) |
|
|
|
@ -34,12 +46,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing |
|
|
|
NamedColors<TPixel>.DarkBlue, |
|
|
|
new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY) |
|
|
|
) |
|
|
|
.Fill(new GraphicsOptions(true) { ColorBlendingMode = mode }, |
|
|
|
.Fill(new GraphicsOptions(true) { ColorBlendingMode = blending }, |
|
|
|
NamedColors<TPixel>.HotPink, |
|
|
|
new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY)) |
|
|
|
); |
|
|
|
|
|
|
|
VerifyImage(provider, mode, img); |
|
|
|
VerifyImage(provider, blending, composition, img); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -47,7 +59,8 @@ namespace SixLabors.ImageSharp.Tests.Drawing |
|
|
|
[WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)] |
|
|
|
public void _1DarkBlueRect_2BlendHotPinkRect_3BlendTransparentEllipse<TPixel>( |
|
|
|
TestImageProvider<TPixel> provider, |
|
|
|
PixelColorBlendingMode mode) |
|
|
|
PixelColorBlendingMode blending, |
|
|
|
PixelAlphaCompositionMode composition) |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using (Image<TPixel> img = provider.GetImage()) |
|
|
|
@ -60,17 +73,17 @@ namespace SixLabors.ImageSharp.Tests.Drawing |
|
|
|
new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY))); |
|
|
|
img.Mutate( |
|
|
|
x => x.Fill( |
|
|
|
new GraphicsOptions(true) { ColorBlendingMode = mode }, |
|
|
|
new GraphicsOptions(true) { ColorBlendingMode = blending }, |
|
|
|
NamedColors<TPixel>.HotPink, |
|
|
|
new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY))); |
|
|
|
img.Mutate( |
|
|
|
x => x.Fill( |
|
|
|
new GraphicsOptions(true) { ColorBlendingMode = mode }, |
|
|
|
new GraphicsOptions(true) { ColorBlendingMode = blending }, |
|
|
|
NamedColors<TPixel>.Transparent, |
|
|
|
new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY)) |
|
|
|
); |
|
|
|
|
|
|
|
VerifyImage(provider, mode, img); |
|
|
|
VerifyImage(provider, blending, composition, img); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -78,7 +91,8 @@ namespace SixLabors.ImageSharp.Tests.Drawing |
|
|
|
[WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)] |
|
|
|
public void _1DarkBlueRect_2BlendHotPinkRect_3BlendSemiTransparentRedEllipse<TPixel>( |
|
|
|
TestImageProvider<TPixel> provider, |
|
|
|
PixelColorBlendingMode mode) |
|
|
|
PixelColorBlendingMode blending, |
|
|
|
PixelAlphaCompositionMode composition) |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using (Image<TPixel> img = provider.GetImage()) |
|
|
|
@ -91,7 +105,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing |
|
|
|
new Rectangle(0 * scaleX, 40, 100 * scaleX, 20 * scaleY))); |
|
|
|
img.Mutate( |
|
|
|
x => x.Fill( |
|
|
|
new GraphicsOptions(true) { ColorBlendingMode = mode }, |
|
|
|
new GraphicsOptions(true) { ColorBlendingMode = blending }, |
|
|
|
NamedColors<TPixel>.HotPink, |
|
|
|
new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY))); |
|
|
|
var c = NamedColors<TPixel>.Red.ToVector4(); |
|
|
|
@ -101,18 +115,21 @@ namespace SixLabors.ImageSharp.Tests.Drawing |
|
|
|
|
|
|
|
img.Mutate( |
|
|
|
x => x.Fill( |
|
|
|
new GraphicsOptions(true) { ColorBlendingMode = mode }, |
|
|
|
new GraphicsOptions(true) { ColorBlendingMode = blending }, |
|
|
|
pixel, |
|
|
|
new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY)) |
|
|
|
); |
|
|
|
|
|
|
|
VerifyImage(provider, mode, img); ; |
|
|
|
VerifyImage(provider, blending, composition, img); ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)] |
|
|
|
public void _1DarkBlueRect_2BlendBlackEllipse<TPixel>(TestImageProvider<TPixel> provider, PixelColorBlendingMode mode) |
|
|
|
public void _1DarkBlueRect_2BlendBlackEllipse<TPixel>( |
|
|
|
TestImageProvider<TPixel> provider, |
|
|
|
PixelColorBlendingMode blending, |
|
|
|
PixelAlphaCompositionMode composition) |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using(Image<TPixel> dstImg = provider.GetImage(), srcImg = provider.GetImage()) |
|
|
|
@ -131,28 +148,35 @@ namespace SixLabors.ImageSharp.Tests.Drawing |
|
|
|
new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY))); |
|
|
|
|
|
|
|
dstImg.Mutate( |
|
|
|
x => x.DrawImage(srcImg, new GraphicsOptions(true) { ColorBlendingMode = mode }) |
|
|
|
x => x.DrawImage(srcImg, new GraphicsOptions(true) { ColorBlendingMode = blending }) |
|
|
|
); |
|
|
|
|
|
|
|
VerifyImage(provider, mode, dstImg); |
|
|
|
VerifyImage(provider, blending, composition, dstImg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static void VerifyImage<TPixel>(TestImageProvider<TPixel> provider, PixelColorBlendingMode mode, Image<TPixel> img) |
|
|
|
private static void VerifyImage<TPixel>(TestImageProvider<TPixel> provider, PixelColorBlendingMode blending, PixelAlphaCompositionMode composition, Image<TPixel> img) |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
img.DebugSave( |
|
|
|
provider, |
|
|
|
new { mode }, |
|
|
|
new { blending }, |
|
|
|
appendPixelTypeToFileName: false, |
|
|
|
appendSourceFileOrDescription: false); |
|
|
|
|
|
|
|
var comparer = ImageComparer.TolerantPercentage(0.01f, 3); |
|
|
|
img.CompareFirstFrameToReferenceOutput(comparer, |
|
|
|
provider, |
|
|
|
new { mode }, |
|
|
|
appendPixelTypeToFileName: false, |
|
|
|
appendSourceFileOrDescription: false); |
|
|
|
try |
|
|
|
{ |
|
|
|
var comparer = ImageComparer.TolerantPercentage(0.01f, 3); |
|
|
|
img.CompareFirstFrameToReferenceOutput(comparer, |
|
|
|
provider, |
|
|
|
new { blending }, |
|
|
|
appendPixelTypeToFileName: false, |
|
|
|
appendSourceFileOrDescription: false); |
|
|
|
} |
|
|
|
catch(System.IO.FileNotFoundException) |
|
|
|
{ |
|
|
|
// temporary hack until reference images are in place.
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |