|
1 | 1 | // Copyright (c) Six Labors.
|
2 | 2 | // Licensed under the Six Labors Split License.
|
3 | 3 |
|
4 |
| -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders; |
5 |
| - |
6 | 4 | using SixLabors.ImageSharp.PixelFormats;
|
7 | 5 | using SixLabors.ImageSharp.Processing;
|
| 6 | +using SixLabors.ImageSharp.Tests.TestUtilities; |
8 | 7 |
|
9 |
| -using Xunit; |
| 8 | +namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders; |
10 | 9 |
|
11 | 10 | public class PorterDuffCompositorTests
|
12 | 11 | {
|
13 | 12 | // TODO: Add other modes to compare.
|
14 | 13 | public static readonly TheoryData<PixelAlphaCompositionMode> CompositingOperators =
|
15 |
| - new TheoryData<PixelAlphaCompositionMode> |
16 |
| - { |
17 |
| - PixelAlphaCompositionMode.Src, |
18 |
| - PixelAlphaCompositionMode.SrcAtop, |
19 |
| - PixelAlphaCompositionMode.SrcOver, |
20 |
| - PixelAlphaCompositionMode.SrcIn, |
21 |
| - PixelAlphaCompositionMode.SrcOut, |
22 |
| - PixelAlphaCompositionMode.Dest, |
23 |
| - PixelAlphaCompositionMode.DestAtop, |
24 |
| - PixelAlphaCompositionMode.DestOver, |
25 |
| - PixelAlphaCompositionMode.DestIn, |
26 |
| - PixelAlphaCompositionMode.DestOut, |
27 |
| - PixelAlphaCompositionMode.Clear, |
28 |
| - PixelAlphaCompositionMode.Xor |
29 |
| - }; |
| 14 | + new() |
| 15 | + { |
| 16 | + PixelAlphaCompositionMode.Src, |
| 17 | + PixelAlphaCompositionMode.SrcAtop, |
| 18 | + PixelAlphaCompositionMode.SrcOver, |
| 19 | + PixelAlphaCompositionMode.SrcIn, |
| 20 | + PixelAlphaCompositionMode.SrcOut, |
| 21 | + PixelAlphaCompositionMode.Dest, |
| 22 | + PixelAlphaCompositionMode.DestAtop, |
| 23 | + PixelAlphaCompositionMode.DestOver, |
| 24 | + PixelAlphaCompositionMode.DestIn, |
| 25 | + PixelAlphaCompositionMode.DestOut, |
| 26 | + PixelAlphaCompositionMode.Clear, |
| 27 | + PixelAlphaCompositionMode.Xor |
| 28 | + }; |
30 | 29 |
|
31 | 30 | [Theory]
|
32 | 31 | [WithFile(TestImages.Png.PDDest, nameof(CompositingOperators), PixelTypes.Rgba32)]
|
33 | 32 | public void PorterDuffOutputIsCorrect(TestImageProvider<Rgba32> provider, PixelAlphaCompositionMode mode)
|
34 | 33 | {
|
35 |
| - var srcFile = TestFile.Create(TestImages.Png.PDSrc); |
36 |
| - using (Image<Rgba32> src = srcFile.CreateRgba32Image()) |
37 |
| - using (Image<Rgba32> dest = provider.GetImage()) |
| 34 | + static void RunTest(string providerDump, string alphaMode) |
38 | 35 | {
|
39 |
| - var options = new GraphicsOptions |
| 36 | + TestImageProvider<Rgba32> provider |
| 37 | + = BasicSerializer.Deserialize<TestImageProvider<Rgba32>>(providerDump); |
| 38 | + |
| 39 | + TestFile srcFile = TestFile.Create(TestImages.Png.PDSrc); |
| 40 | + using Image<Rgba32> src = srcFile.CreateRgba32Image(); |
| 41 | + using Image<Rgba32> dest = provider.GetImage(); |
| 42 | + GraphicsOptions options = new() |
40 | 43 | {
|
41 | 44 | Antialias = false,
|
42 |
| - AlphaCompositionMode = mode |
| 45 | + AlphaCompositionMode = Enum.Parse<PixelAlphaCompositionMode>(alphaMode) |
43 | 46 | };
|
44 | 47 |
|
45 |
| - using (Image<Rgba32> res = dest.Clone(x => x.DrawImage(src, options))) |
46 |
| - { |
47 |
| - string combinedMode = mode.ToString(); |
48 |
| - |
49 |
| - if (combinedMode != "Src" && combinedMode.StartsWith("Src")) |
50 |
| - { |
51 |
| - combinedMode = combinedMode.Substring(3); |
52 |
| - } |
| 48 | + using Image<Rgba32> res = dest.Clone(x => x.DrawImage(src, options)); |
| 49 | + string combinedMode = alphaMode; |
53 | 50 |
|
54 |
| - res.DebugSave(provider, combinedMode); |
55 |
| - res.CompareToReferenceOutput(provider, combinedMode); |
| 51 | + if (combinedMode != "Src" && combinedMode.StartsWith("Src", StringComparison.OrdinalIgnoreCase)) |
| 52 | + { |
| 53 | + combinedMode = combinedMode[3..]; |
56 | 54 | }
|
| 55 | + |
| 56 | + res.DebugSave(provider, combinedMode); |
| 57 | + res.CompareToReferenceOutput(provider, combinedMode); |
57 | 58 | }
|
| 59 | + |
| 60 | + FeatureTestRunner.RunWithHwIntrinsicsFeature( |
| 61 | + RunTest, |
| 62 | + HwIntrinsics.AllowAll | HwIntrinsics.DisableAVX, |
| 63 | + provider, |
| 64 | + mode.ToString()); |
58 | 65 | }
|
59 | 66 | }
|
0 commit comments