// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.Numerics; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Tests { public abstract partial class TestImageProvider { private class BasicTestPatternProvider : BlankProvider { public BasicTestPatternProvider(int width, int height) : base(width, height) { } /// /// This parameterless constructor is needed for xUnit deserialization /// public BasicTestPatternProvider() { } public override string SourceFileOrDescription => TestUtils.AsInvariantString($"BasicTestPattern{this.Width}x{this.Height}"); public override Image GetImage() { var result = new Image(this.Configuration, this.Width, this.Height); TPixel topLeftColor = NamedColors.Red; TPixel topRightColor = NamedColors.Green; TPixel bottomLeftColor = NamedColors.Blue; // Transparent purple: TPixel bottomRightColor = default; bottomRightColor.FromVector4(new Vector4(1f, 0f, 1f, 0.5f)); int midY = this.Height / 2; int midX = this.Width / 2; for (int y = 0; y < midY; y++) { Span row = result.GetPixelRowSpan(y); row.Slice(0, midX).Fill(topLeftColor); row.Slice(midX, this.Width-midX).Fill(topRightColor); } for (int y = midY; y < this.Height; y++) { Span row = result.GetPixelRowSpan(y); row.Slice(0, midX).Fill(bottomLeftColor); row.Slice(midX, this.Width-midX).Fill(bottomRightColor); } return result; } } } }