mirror of https://github.com/SixLabors/ImageSharp
8 changed files with 149 additions and 1 deletions
@ -0,0 +1,37 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.Reflection; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests |
|||
{ |
|||
public class WithBasicTestPatternImagesAttribute : ImageDataAttributeBase |
|||
{ |
|||
public WithBasicTestPatternImagesAttribute(int width, int height, PixelTypes pixelTypes, params object[] additionalParameters) |
|||
: this(null, width, height, pixelTypes, additionalParameters) |
|||
{ |
|||
} |
|||
|
|||
public WithBasicTestPatternImagesAttribute(string memberData, int width, int height, PixelTypes pixelTypes, params object[] additionalParameters) |
|||
: base(memberData, pixelTypes, additionalParameters) |
|||
{ |
|||
this.Width = width; |
|||
this.Height = height; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the width
|
|||
/// </summary>
|
|||
public int Width { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the height
|
|||
/// </summary>
|
|||
public int Height { get; } |
|||
|
|||
protected override string GetFactoryMethodName(MethodInfo testMethod) => "BasicTestPattern"; |
|||
|
|||
protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) => new object[] { this.Width, this.Height }; |
|||
} |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
// 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<TPixel> |
|||
{ |
|||
private class BasicTestPatternProvider : BlankProvider |
|||
{ |
|||
public BasicTestPatternProvider(int width, int height) |
|||
: base(width, height) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// This parameterless constructor is needed for xUnit deserialization
|
|||
/// </summary>
|
|||
public BasicTestPatternProvider() |
|||
{ |
|||
} |
|||
|
|||
public override string SourceFileOrDescription => TestUtils.AsInvariantString($"BasicTestPattern{this.Width}x{this.Height}"); |
|||
|
|||
public override Image<TPixel> GetImage() |
|||
{ |
|||
var result = new Image<TPixel>(this.Width, this.Height); |
|||
|
|||
TPixel topLeftColor = NamedColors<TPixel>.Red; |
|||
TPixel topRightColor = NamedColors<TPixel>.Green; |
|||
TPixel bottomLeftColor = NamedColors<TPixel>.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<TPixel> 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<TPixel> row = result.GetPixelRowSpan(y); |
|||
|
|||
row.Slice(0, midX).Fill(bottomLeftColor); |
|||
row.Slice(midX, this.Width-midX).Fill(bottomRightColor); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue