mirror of https://github.com/SixLabors/ImageSharp
4 changed files with 57 additions and 54 deletions
@ -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}"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -1 +1 @@ |
|||
Subproject commit dc5afda9a4ad69dc3526d49ceb1d27610064f2af |
|||
Subproject commit 5036d47ec2393d90efb6f3864d828e2e4381947f |
|||
Loading…
Reference in new issue