// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests; /// /// Provides instances for parametric unit tests. /// /// The pixel format of the image public abstract partial class TestImageProvider : IXunitSerializable where TPixel : unmanaged, IPixel { private class SolidProvider : BlankProvider { private byte a; private byte b; private byte g; private byte r; public SolidProvider(int width, int height, byte r, byte g, byte b, byte a) : base(width, height) { this.r = r; this.g = g; this.b = b; this.a = a; } /// /// This parameterless constructor is needed for xUnit deserialization /// public SolidProvider() : base() { this.r = 0; this.g = 0; this.b = 0; this.a = 0; } public override string SourceFileOrDescription => TestUtils.AsInvariantString($"Solid{this.Width}x{this.Height}_({this.r},{this.g},{this.b},{this.a})"); public override Image GetImage() { Image image = base.GetImage(); Color color = Color.FromPixel(new Rgba32(this.r, this.g, this.b, this.a)); image.GetRootFramePixelBuffer().FastMemoryGroup.Fill(color.ToPixel()); return image; } public override void Serialize(IXunitSerializationInfo info) { info.AddValue("red", this.r); info.AddValue("green", this.g); info.AddValue("blue", this.b); info.AddValue("alpha", this.a); base.Serialize(info); } public override void Deserialize(IXunitSerializationInfo info) { this.r = info.GetValue("red"); this.g = info.GetValue("green"); this.b = info.GetValue("blue"); this.a = info.GetValue("alpha"); base.Deserialize(info); } } }