Skip to content

Commit 994f5fc

Browse files
committed
"BlendedShapes" -> SolidFillBlendedShapesTests
1 parent 87103b7 commit 994f5fc

File tree

5 files changed

+199
-112
lines changed

5 files changed

+199
-112
lines changed

tests/ImageSharp.Tests/Drawing/BlendedShapes.cs

Lines changed: 0 additions & 92 deletions
This file was deleted.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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+
}

tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private static void TestPngEncoderCore<TPixel>(
153153
}
154154

155155
IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(actualOutputFile);
156-
string referenceOutputFile = ((ITestImageProvider)provider).Utility.GetReferenceOutputFileName("png", debugInfo, appendPixelType);
156+
string referenceOutputFile = ((ITestImageProvider)provider).Utility.GetReferenceOutputFileName("png", debugInfo, appendPixelType, true);
157157

158158
using (var actualImage = Image.Load<TPixel>(actualOutputFile, referenceDecoder))
159159
using (var referenceImage = Image.Load<TPixel>(referenceOutputFile, referenceDecoder))

tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,20 @@ public class ImagingTestCaseUtility
4141
/// </summary>
4242
public string TestName { get; set; } = string.Empty;
4343

44-
private string GetTestOutputFileNameImpl(string extension, string details, bool appendPixelTypeToFileName)
44+
private string GetTestOutputFileNameImpl(
45+
string extension,
46+
string details,
47+
bool appendPixelTypeToFileName,
48+
bool appendSourceFileOrDescription)
4549
{
46-
string fn = string.Empty;
47-
4850
if (string.IsNullOrWhiteSpace(extension))
4951
{
5052
extension = null;
5153
}
5254

53-
fn = Path.GetFileNameWithoutExtension(this.SourceFileOrDescription);
55+
string fn = appendSourceFileOrDescription
56+
? Path.GetFileNameWithoutExtension(this.SourceFileOrDescription)
57+
: "";
5458

5559
if (string.IsNullOrWhiteSpace(extension))
5660
{
@@ -92,20 +96,24 @@ private string GetTestOutputFileNameImpl(string extension, string details, bool
9296
}
9397

9498
private static string Inv(FormattableString formattable) => System.FormattableString.Invariant(formattable);
95-
99+
96100
/// <summary>
97101
/// Gets the recommended file name for the output of the test
98102
/// </summary>
99103
/// <param name="extension">The required extension</param>
100104
/// <param name="testOutputDetails">The settings modifying the output path</param>
101105
/// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to output file name.</param>
106+
/// <param name="appendSourceFileOrDescription">A boolean indicating whether to append <see cref="ITestImageProvider.SourceFileOrDescription"/> to the test output file name.</param>
102107
/// <returns>The file test name</returns>
103-
public string GetTestOutputFileName(string extension = null, object testOutputDetails = null, bool appendPixelTypeToFileName = true)
108+
public string GetTestOutputFileName(
109+
string extension = null,
110+
object testOutputDetails = null,
111+
bool appendPixelTypeToFileName = true,
112+
bool appendSourceFileOrDescription = true)
104113
{
105114
string detailsString = null;
106-
string s = testOutputDetails as string;
107115

108-
if (s != null)
116+
if (testOutputDetails is string s)
109117
{
110118
detailsString = s;
111119
}
@@ -128,7 +136,12 @@ public string GetTestOutputFileName(string extension = null, object testOutputDe
128136
);
129137
}
130138
}
131-
return this.GetTestOutputFileNameImpl(extension, detailsString, appendPixelTypeToFileName);
139+
140+
return this.GetTestOutputFileNameImpl(
141+
extension,
142+
detailsString,
143+
appendPixelTypeToFileName,
144+
appendSourceFileOrDescription);
132145
}
133146

134147

@@ -139,15 +152,22 @@ public string GetTestOutputFileName(string extension = null, object testOutputDe
139152
/// <param name="image">The image instance</param>
140153
/// <param name="extension">The requested extension</param>
141154
/// <param name="encoder">Optional encoder</param>
155+
/// /// <param name="appendSourceFileOrDescription">A boolean indicating whether to append <see cref="ITestImageProvider.SourceFileOrDescription"/> to the test output file name.</param>
142156
public string SaveTestOutputFile<TPixel>(
143157
Image<TPixel> image,
144158
string extension = null,
145159
IImageEncoder encoder = null,
146160
object testOutputDetails = null,
147-
bool appendPixelTypeToFileName = true)
161+
bool appendPixelTypeToFileName = true,
162+
bool appendSourceFileOrDescription = true)
148163
where TPixel : struct, IPixel<TPixel>
149164
{
150-
string path = this.GetTestOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName);
165+
string path = this.GetTestOutputFileName(
166+
extension,
167+
testOutputDetails,
168+
appendPixelTypeToFileName,
169+
appendSourceFileOrDescription);
170+
151171
encoder = encoder ?? TestEnvironment.GetReferenceEncoder(path);
152172

153173
using (FileStream stream = File.OpenWrite(path))
@@ -161,9 +181,10 @@ public IEnumerable<string> GetTestOutputFileNamesMultiFrame(
161181
int frameCount,
162182
string extension = null,
163183
object testOutputDetails = null,
164-
bool appendPixelTypeToFileName = true)
184+
bool appendPixelTypeToFileName = true,
185+
bool appendSourceFileOrDescription = true)
165186
{
166-
string baseDir = this.GetTestOutputFileName("", testOutputDetails, appendPixelTypeToFileName);
187+
string baseDir = this.GetTestOutputFileName("", testOutputDetails, appendPixelTypeToFileName, appendSourceFileOrDescription);
167188

168189
if (!Directory.Exists(baseDir))
169190
{
@@ -211,10 +232,11 @@ public string[] SaveTestOutputFileMultiFrame<TPixel>(
211232
internal string GetReferenceOutputFileName(
212233
string extension,
213234
object testOutputDetails,
214-
bool appendPixelTypeToFileName)
235+
bool appendPixelTypeToFileName,
236+
bool appendSourceFileOrDescription)
215237
{
216238
return TestEnvironment.GetReferenceOutputFileName(
217-
this.GetTestOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName)
239+
this.GetTestOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName, appendSourceFileOrDescription)
218240
);
219241
}
220242

0 commit comments

Comments
 (0)