// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Advanced;
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
where TPixel : struct, 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 = new Rgba32(this.r, this.g, this.b, this.a);
image.GetPixelSpan().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);
}
}
}
}