// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Drawing; using SixLabors.ImageSharp.Processing.Overlays; using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests { using SixLabors.ImageSharp.Processing; /// /// 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; } public SolidProvider() : base() { this.r = 0; this.g = 0; this.b = 0; this.a = 0; } public override string SourceFileOrDescription => $"Solid{this.Width}x{this.Height}_({this.r},{this.g},{this.b},{this.a})"; public override Image GetImage() { Image image = base.GetImage(); TPixel color = default(TPixel); color.PackFromRgba32(new Rgba32(this.r, this.g, this.b, this.a)); image.Mutate(x => x.Fill(color)); 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); } } } }