1+ // Copyright (c) Six Labors and contributors.
2+ // Licensed under the Apache License, Version 2.0.
3+
4+ // ReSharper disable InconsistentNaming
5+ namespace SixLabors . ImageSharp . Tests . Drawing
6+ {
7+ using System ;
8+ using System . Collections . Generic ;
9+ using System . Linq ;
10+
11+ using SixLabors . ImageSharp . PixelFormats ;
12+ using SixLabors . ImageSharp . Processing ;
13+ using SixLabors . ImageSharp . Processing . Drawing ;
14+ using SixLabors . Primitives ;
15+
16+ using Xunit ;
17+
18+ [ GroupOutput ( "Drawing" ) ]
19+ public class SolidFillBlendedShapesTests
20+ {
21+ public static IEnumerable < object [ ] > modes =
22+ ( ( PixelBlenderMode [ ] ) Enum . GetValues ( typeof ( PixelBlenderMode ) ) ) . Select ( x => new object [ ] { x } ) ;
23+
24+ [ Theory ]
25+ [ WithBlankImages ( nameof ( modes ) , 250 , 250 , PixelTypes . Rgba32 ) ]
26+ public void _1DarkBlueRect_2BlendHotPinkRect < TPixel > (
27+ TestImageProvider < TPixel > provider ,
28+ PixelBlenderMode mode )
29+ where TPixel : struct , IPixel < TPixel >
30+ {
31+ using ( Image < TPixel > img = provider . GetImage ( ) )
32+ {
33+ int scaleX = img . Width / 100 ;
34+ int scaleY = img . Height / 100 ;
35+ img . Mutate (
36+ x => x . Fill (
37+ NamedColors < TPixel > . DarkBlue ,
38+ new Rectangle ( 0 * scaleX , 40 * scaleY , 100 * scaleX , 20 * scaleY )
39+ )
40+ . Fill ( new GraphicsOptions ( true ) { BlenderMode = mode } ,
41+ NamedColors < TPixel > . HotPink ,
42+ new Rectangle ( 20 * scaleX , 0 * scaleY , 30 * scaleX , 100 * scaleY ) )
43+ ) ;
44+
45+ VerifyImage ( provider , mode , img ) ;
46+ }
47+ }
48+
49+ [ Theory ]
50+ [ WithBlankImages ( nameof ( modes ) , 250 , 250 , PixelTypes . Rgba32 ) ]
51+ public void _1DarkBlueRect_2BlendHotPinkRect_3BlendTransparentEllipse < TPixel > (
52+ TestImageProvider < TPixel > provider ,
53+ PixelBlenderMode mode )
54+ where TPixel : struct , IPixel < TPixel >
55+ {
56+ using ( Image < TPixel > img = provider . GetImage ( ) )
57+ {
58+ int scaleX = img . Width / 100 ;
59+ int scaleY = img . Height / 100 ;
60+ img . Mutate (
61+ x => x . Fill (
62+ NamedColors < TPixel > . DarkBlue ,
63+ new Rectangle ( 0 * scaleX , 40 * scaleY , 100 * scaleX , 20 * scaleY ) ) ) ;
64+ img . Mutate (
65+ x => x . Fill (
66+ new GraphicsOptions ( true ) { BlenderMode = mode } ,
67+ NamedColors < TPixel > . HotPink ,
68+ new Rectangle ( 20 * scaleX , 0 * scaleY , 30 * scaleX , 100 * scaleY ) ) ) ;
69+ img . Mutate (
70+ x => x . Fill (
71+ new GraphicsOptions ( true ) { BlenderMode = mode } ,
72+ NamedColors < TPixel > . Transparent ,
73+ new Shapes . EllipsePolygon ( 40 * scaleX , 50 * scaleY , 50 * scaleX , 50 * scaleY ) )
74+ ) ;
75+
76+ VerifyImage ( provider , mode , img ) ;
77+ }
78+ }
79+
80+ [ Theory ]
81+ [ WithBlankImages ( nameof ( modes ) , 250 , 250 , PixelTypes . Rgba32 ) ]
82+ public void _1DarkBlueRect_2BlendHotPinkRect_3BlendSemiTransparentRedEllipse < TPixel > (
83+ TestImageProvider < TPixel > provider ,
84+ PixelBlenderMode mode )
85+ where TPixel : struct , IPixel < TPixel >
86+ {
87+ using ( Image < TPixel > img = provider . GetImage ( ) )
88+ {
89+ int scaleX = ( img . Width / 100 ) ;
90+ int scaleY = ( img . Height / 100 ) ;
91+ img . Mutate (
92+ x => x . Fill (
93+ NamedColors < TPixel > . DarkBlue ,
94+ new Rectangle ( 0 * scaleX , 40 , 100 * scaleX , 20 * scaleY ) ) ) ;
95+ img . Mutate (
96+ x => x . Fill (
97+ new GraphicsOptions ( true ) { BlenderMode = mode } ,
98+ NamedColors < TPixel > . HotPink ,
99+ new Rectangle ( 20 * scaleX , 0 , 30 * scaleX , 100 * scaleY ) ) ) ;
100+ var c = NamedColors < TPixel > . Red . ToVector4 ( ) ;
101+ c . W *= 0.5f ;
102+ var pixel = default ( TPixel ) ;
103+ pixel . PackFromVector4 ( c ) ;
104+
105+ img . Mutate (
106+ x => x . Fill (
107+ new GraphicsOptions ( true ) { BlenderMode = mode } ,
108+ pixel ,
109+ new Shapes . EllipsePolygon ( 40 * scaleX , 50 * scaleY , 50 * scaleX , 50 * scaleY ) )
110+ ) ;
111+
112+ VerifyImage ( provider , mode , img ) ; ;
113+ }
114+ }
115+
116+ [ Theory ]
117+ [ WithBlankImages ( nameof ( modes ) , 250 , 250 , PixelTypes . Rgba32 ) ]
118+ public void _1DarkBlueRect_2BlendBlackEllipse < TPixel > ( TestImageProvider < TPixel > provider , PixelBlenderMode mode )
119+ where TPixel : struct , IPixel < TPixel >
120+ {
121+ using ( Image < TPixel > img = provider . GetImage ( ) )
122+ {
123+ int scaleX = ( img . Width / 100 ) ;
124+ int scaleY = ( img . Height / 100 ) ;
125+ img . Mutate (
126+ x => x . Fill (
127+ NamedColors < TPixel > . DarkBlue ,
128+ new Rectangle ( 0 * scaleX , 40 * scaleY , 100 * scaleX , 20 * scaleY ) ) ) ;
129+ img . Mutate (
130+ x => x . Fill (
131+ new GraphicsOptions ( true ) { BlenderMode = mode } ,
132+ NamedColors < TPixel > . Black ,
133+ new Shapes . EllipsePolygon ( 40 * scaleX , 50 * scaleY , 50 * scaleX , 50 * scaleY ) ) ) ;
134+
135+ VerifyImage ( provider , mode , img ) ;
136+ }
137+ }
138+
139+ private static void VerifyImage < TPixel > ( TestImageProvider < TPixel > provider , PixelBlenderMode mode , Image < TPixel > img )
140+ where TPixel : struct , IPixel < TPixel >
141+ {
142+ img . DebugSave (
143+ provider ,
144+ new { mode } ,
145+ appendPixelTypeToFileName : false ,
146+ appendSourceFileOrDescription : false ) ;
147+ }
148+ }
149+ }
0 commit comments