Browse Source

Updated SolidFill tests to cover all possible Blending-Composition combinations, reference images not in place yet

af/merge-core
Vicente Penades 8 years ago
parent
commit
20daca0e6e
  1. 72
      tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs
  2. 2
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

72
tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs

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

2
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -365,7 +365,7 @@ namespace SixLabors.ImageSharp.Tests
if (!File.Exists(referenceOutputFile)) if (!File.Exists(referenceOutputFile))
{ {
throw new Exception("Reference output file missing: " + referenceOutputFile); throw new System.IO.FileNotFoundException("Reference output file missing: " + referenceOutputFile, referenceOutputFile);
} }
IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(referenceOutputFile); IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(referenceOutputFile);

Loading…
Cancel
Save