Browse Source

RecolorImageTests

af/merge-core
Anton Firszov 7 years ago
parent
commit
5c28322825
  1. 10
      tests/ImageSharp.Tests/Drawing/DrawBezierTests.cs
  2. 48
      tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs
  3. 51
      tests/ImageSharp.Tests/Drawing/RecolorImageTests.cs
  4. 2
      tests/Images/External

10
tests/ImageSharp.Tests/Drawing/BeziersTests.cs → tests/ImageSharp.Tests/Drawing/DrawBezierTests.cs

@ -11,13 +11,13 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing
{
public class Beziers : FileTestBase
public class DrawBezierTests
{
[Fact]
public void ImageShouldBeOverlayedByBezierLine()
{
string path = TestEnvironment.CreateOutputDirectory("Drawing", "BezierLine");
using (var image = new Image<Rgba32>(500, 500))
string path = TestEnvironment.CreateOutputDirectory("Drawing", "DrawBezierTests");
using (var image = new Image<Rgba32>(350, 450))
{
image.Mutate(x => x.BackgroundColor(Color.Blue));
image.Mutate(
@ -51,11 +51,11 @@ namespace SixLabors.ImageSharp.Tests.Drawing
[Fact]
public void ImageShouldBeOverlayedBezierLineWithOpacity()
{
string path = TestEnvironment.CreateOutputDirectory("Drawing", "BezierLine");
string path = TestEnvironment.CreateOutputDirectory("Drawing", "DrawBezierTests");
var color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
using (var image = new Image<Rgba32>(500, 500))
using (var image = new Image<Rgba32>(350, 450))
{
image.Mutate(x => x.BackgroundColor(Color.Blue));
image.Mutate(

48
tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs

@ -1,48 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using Xunit;
namespace SixLabors.ImageSharp.Tests
{
public class RecolorImageTest : FileTestBase
{
[Fact]
public void ImageShouldRecolorYellowToHotPink()
{
string path = TestEnvironment.CreateOutputDirectory("Drawing", "RecolorImage");
var brush = new RecolorBrush<Rgba32>(Rgba32.Yellow, Rgba32.HotPink, 0.2f);
foreach (TestFile file in Files)
{
using (Image<Rgba32> image = file.CreateRgba32Image())
{
image.Mutate(x => x.Fill(brush));
image.Save($"{path}/{file.FileName}");
}
}
}
[Fact]
public void ImageShouldRecolorYellowToHotPinkInARectangle()
{
string path = TestEnvironment.CreateOutputDirectory("Drawing", "RecolorImage");
var brush = new RecolorBrush<Rgba32>(Rgba32.Yellow, Rgba32.HotPink, 0.2f);
foreach (TestFile file in Files)
{
using (Image<Rgba32> image = file.CreateRgba32Image())
{
int imageHeight = image.Height;
image.Mutate(x => x.Fill(brush, new Rectangle(0, imageHeight / 2 - imageHeight / 4, image.Width, imageHeight / 2)));
image.Save($"{path}/Shaped_{file.FileName}");
}
}
}
}
}

51
tests/ImageSharp.Tests/Drawing/RecolorImageTests.cs

@ -0,0 +1,51 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using Xunit;
namespace SixLabors.ImageSharp.Tests
{
[GroupOutput("Drawing")]
public class RecolorImageTests
{
[Theory]
[WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Rgba32, "Yellow", "Pink", 0.2f)]
[WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Bgra32, "Yellow", "Pink", 0.5f)]
[WithTestPatternImages(100, 100, PixelTypes.Rgba32, "Red", "Blue", 0.2f)]
[WithTestPatternImages(100, 100, PixelTypes.Rgba32, "Red", "Blue", 0.6f)]
public void Recolor<TPixel>(TestImageProvider<TPixel> provider, string sourceColorName, string targetColorName, float threshold)
where TPixel : struct, IPixel<TPixel>
{
Color sourceColor = TestUtils.GetColorByName(sourceColorName);
Color targetColor = TestUtils.GetColorByName(targetColorName);
var brush = new RecolorBrush<TPixel>(sourceColor.ToPixel<TPixel>(), targetColor.ToPixel<TPixel>(), threshold);
FormattableString testInfo = $"{sourceColorName}-{targetColorName}-{threshold}";
provider.RunValidatingProcessorTest(x => x.Fill(brush), testInfo);
}
[Theory]
[WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Bgra32, "Yellow", "Pink", 0.5f)]
[WithTestPatternImages(100, 100, PixelTypes.Rgba32, "Red", "Blue", 0.2f)]
public void Recolor_InBox<TPixel>(TestImageProvider<TPixel> provider, string sourceColorName, string targetColorName, float threshold)
where TPixel : struct, IPixel<TPixel>
{
Color sourceColor = TestUtils.GetColorByName(sourceColorName);
Color targetColor = TestUtils.GetColorByName(targetColorName);
var brush = new RecolorBrush<TPixel>(sourceColor.ToPixel<TPixel>(), targetColor.ToPixel<TPixel>(), threshold);
FormattableString testInfo = $"{sourceColorName}-{targetColorName}-{threshold}";
provider.RunValidatingProcessorTest(x =>
{
Size size = x.GetCurrentSize();
var rectangle = new Rectangle(0, size.Height / 2 - size.Height / 4, size.Width, size.Height / 2);
x.Fill(brush, rectangle);
}, testInfo);
}
}
}

2
tests/Images/External

@ -1 +1 @@
Subproject commit dc5afda9a4ad69dc3526d49ceb1d27610064f2af
Subproject commit 5036d47ec2393d90efb6f3864d828e2e4381947f
Loading…
Cancel
Save