@ -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 ( ) ;
( ( PixelBlenderMode [ ] ) Enum . GetValues ( typeof ( PixelBlenderMode ) ) ) . Select ( x = > new object [ ] { x } ) ;
private static IEnumerable < object [ ] > GetAllModeCombinations ( )
{
foreach ( var composition in Enum . GetValues ( typeof ( PixelAlphaCompositionMode ) ) )
{
foreach ( var blending in Enum . GetValues ( typeof ( PixelColorBlendingMode ) ) )
{
yield return new object [ ] { blending , composition } ;
}
}
}
[Theory]
[Theory]
[WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)]
[WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)]
public void _ 1D arkBlueRect_2BlendHotPinkRect < TPixel > (
public void _ 1D arkBlueRect_2BlendHotPinkRect < TPixel > (
TestImageProvider < TPixel > provider ,
TestImageProvider < TPixel > provider ,
PixelBlenderMode 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 , 4 0 * scaleY , 1 0 0 * scaleX , 2 0 * scaleY )
new Rectangle ( 0 * scaleX , 4 0 * scaleY , 1 0 0 * scaleX , 2 0 * scaleY )
)
)
. Fill ( new GraphicsOptions ( true ) { Blender Mode = mode } ,
. Fill ( new GraphicsOptions ( true ) { ColorBlending Mode = blending , AlphaCo mpositionM ode= composition } ,
NamedColors < TPixel > . HotPink ,
NamedColors < TPixel > . HotPink ,
new Rectangle ( 2 0 * scaleX , 0 * scaleY , 3 0 * scaleX , 1 0 0 * scaleY ) )
new Rectangle ( 2 0 * scaleX , 0 * scaleY , 3 0 * scaleX , 1 0 0 * 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 _ 1D arkBlueRect_2BlendHotPinkRect_3BlendTransparentEllipse < TPixel > (
public void _ 1D arkBlueRect_2BlendHotPinkRect_3BlendTransparentEllipse < TPixel > (
TestImageProvider < TPixel > provider ,
TestImageProvider < TPixel > provider ,
PixelBlenderMode 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 , 4 0 * scaleY , 1 0 0 * scaleX , 2 0 * scaleY ) ) ) ;
new Rectangle ( 0 * scaleX , 4 0 * scaleY , 1 0 0 * scaleX , 2 0 * scaleY ) ) ) ;
img . Mutate (
img . Mutate (
x = > x . Fill (
x = > x . Fill (
new GraphicsOptions ( true ) { Blender Mode = mode } ,
new GraphicsOptions ( true ) { ColorBlending Mode = blending , AlphaCo mpositionM ode = composition } ,
NamedColors < TPixel > . HotPink ,
NamedColors < TPixel > . HotPink ,
new Rectangle ( 2 0 * scaleX , 0 * scaleY , 3 0 * scaleX , 1 0 0 * scaleY ) ) ) ;
new Rectangle ( 2 0 * scaleX , 0 * scaleY , 3 0 * scaleX , 1 0 0 * scaleY ) ) ) ;
img . Mutate (
img . Mutate (
x = > x . Fill (
x = > x . Fill (
new GraphicsOptions ( true ) { Blender Mode = mode } ,
new GraphicsOptions ( true ) { ColorBlending Mode = blending , AlphaCo mpositionM ode = composition } ,
NamedColors < TPixel > . Transparent ,
NamedColors < TPixel > . Transparent ,
new Shapes . EllipsePolygon ( 4 0 * scaleX , 5 0 * scaleY , 5 0 * scaleX , 5 0 * scaleY ) )
new Shapes . EllipsePolygon ( 4 0 * scaleX , 5 0 * scaleY , 5 0 * scaleX , 5 0 * 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 _ 1D arkBlueRect_2BlendHotPinkRect_3BlendSemiTransparentRedEllipse < TPixel > (
public void _ 1D arkBlueRect_2BlendHotPinkRect_3BlendSemiTransparentRedEllipse < TPixel > (
TestImageProvider < TPixel > provider ,
TestImageProvider < TPixel > provider ,
PixelBlenderMode 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 , 4 0 , 1 0 0 * scaleX , 2 0 * scaleY ) ) ) ;
new Rectangle ( 0 * scaleX , 4 0 , 1 0 0 * scaleX , 2 0 * scaleY ) ) ) ;
img . Mutate (
img . Mutate (
x = > x . Fill (
x = > x . Fill (
new GraphicsOptions ( true ) { Blender Mode = mode } ,
new GraphicsOptions ( true ) { ColorBlending Mode = blending , AlphaCo mpositionM ode = composition } ,
NamedColors < TPixel > . HotPink ,
NamedColors < TPixel > . HotPink ,
new Rectangle ( 2 0 * scaleX , 0 , 3 0 * scaleX , 1 0 0 * scaleY ) ) ) ;
new Rectangle ( 2 0 * scaleX , 0 , 3 0 * scaleX , 1 0 0 * 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 ) { Blender Mode = mode } ,
new GraphicsOptions ( true ) { ColorBlending Mode = blending , AlphaCo mpositionM ode = composition } ,
pixel ,
pixel ,
new Shapes . EllipsePolygon ( 4 0 * scaleX , 5 0 * scaleY , 5 0 * scaleX , 5 0 * scaleY ) )
new Shapes . EllipsePolygon ( 4 0 * scaleX , 5 0 * scaleY , 5 0 * scaleX , 5 0 * 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 _ 1D arkBlueRect_2BlendBlackEllipse < TPixel > ( TestImageProvider < TPixel > provider , PixelBlenderMode mode )
public void _ 1D arkBlueRect_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,26 +148,30 @@ namespace SixLabors.ImageSharp.Tests.Drawing
new Shapes . EllipsePolygon ( 4 0 * scaleX , 5 0 * scaleY , 5 0 * scaleX , 5 0 * scaleY ) ) ) ;
new Shapes . EllipsePolygon ( 4 0 * scaleX , 5 0 * scaleY , 5 0 * scaleX , 5 0 * scaleY ) ) ) ;
dstImg . Mutate (
dstImg . Mutate (
x = > x . DrawImage ( new GraphicsOptions ( true ) { BlenderMode = mode } , srcImg )
x = > x . DrawImage ( srcImg , new GraphicsOptions ( true ) { ColorBlendingMode = blending , AlphaCompositionMode = composition } )
) ;
) ;
VerifyImage ( provider , mode , dstImg ) ;
VerifyImage ( provider , blending , composition , dstImg ) ;
}
}
}
}
private static void VerifyImage < TPixel > ( TestImageProvider < TPixel > provider , PixelBlenderMode 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 { composition , blending } ,
appendPixelTypeToFileName : false ,
appendPixelTypeToFileName : false ,
appendSourceFileOrDescription : false ) ;
appendSourceFileOrDescription : false ) ;
var comparer = ImageComparer . TolerantPercentage ( 0.01f , 3 ) ;
var comparer = ImageComparer . TolerantPercentage ( 0.01f , 3 ) ;
img . CompareFirstFrameToReferenceOutput ( comparer ,
img . CompareFirstFrameToReferenceOutput ( comparer ,
provider ,
provider ,
new { mode } ,
new { composition , blending } ,
appendPixelTypeToFileName : false ,
appendPixelTypeToFileName : false ,
appendSourceFileOrDescription : false ) ;
appendSourceFileOrDescription : false ) ;
}
}