Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6741c28
temporarily disable target frameworks
antonfirsov May 11, 2019
7e8357c
validating tests for: DrawPath, FillComplexPolygon
antonfirsov May 11, 2019
cf8005d
validation in DrawImageTest
antonfirsov May 11, 2019
5ab0ad2
RecolorImageTests
antonfirsov May 11, 2019
52fbbda
FillPolygonTests
antonfirsov May 12, 2019
680156a
DrawPolygonTests, DrawLinesTests
antonfirsov May 12, 2019
473fd02
DrawBeziersTests, DrawComplexPolygonTests
antonfirsov May 12, 2019
fd6b229
Merge branch 'af/general-color-type' into af/refactor-drawing
antonfirsov May 12, 2019
a910005
fix merge issues
antonfirsov May 12, 2019
21f221e
DrawImageTests: add tolerance to make all test configurations happy
antonfirsov May 12, 2019
2bff823
started the refactor
antonfirsov May 12, 2019
73f9116
Pen, Brush & Processors refactored
antonfirsov May 12, 2019
b902e6c
ImageSharp.Drawing compiles
antonfirsov May 12, 2019
8271ef1
everything builds
antonfirsov May 12, 2019
f0b70b6
tests are passing
antonfirsov May 12, 2019
0eff9bc
Merge branch 'af/general-color-type' into af/refactor-drawing
antonfirsov May 12, 2019
f7df30f
move drawing extensions to a (non-namespace-provider) subfolder
antonfirsov May 12, 2019
c07bd2f
rename files
antonfirsov May 12, 2019
efaa3c0
ImageBrush can apply a source image of a different pixel type than th…
antonfirsov May 12, 2019
0bd86dd
non-generic DrawImageProcessor
antonfirsov May 12, 2019
3b7a741
DrawImageOfDifferentPixelType test cases
antonfirsov May 13, 2019
b7dadca
clean-up drawing processors
antonfirsov May 13, 2019
d2ea005
fix remaining stylecop issues
antonfirsov May 13, 2019
c2e955c
Rgba32.Definitions: use Color instead of NamedColors<T>
antonfirsov May 13, 2019
51e23eb
Remove NamedColors<T> usages
antonfirsov May 13, 2019
17f2311
drop unnecessary generic IImageProcessorContext<TPixel> usages
antonfirsov May 16, 2019
7e57fce
drop almost all usages of FileTestBase
antonfirsov May 16, 2019
3af895b
fix tests
antonfirsov May 16, 2019
a36aa55
re-enable target frameworks
antonfirsov May 16, 2019
0395300
Merge remote-tracking branch 'origin/master' into af/refactor-drawing
antonfirsov May 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
validation in DrawImageTest
  • Loading branch information
antonfirsov committed May 11, 2019
commit cf8005deb2ba98063af51414009f7e4aca2edc32
198 changes: 0 additions & 198 deletions tests/ImageSharp.Tests/Drawing/DrawImageTest.cs

This file was deleted.

174 changes: 174 additions & 0 deletions tests/ImageSharp.Tests/Drawing/DrawImageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;

using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.Primitives;
using SixLabors.Shapes;

using Xunit;

namespace SixLabors.ImageSharp.Tests.Drawing
{
[GroupOutput("Drawing")]
public class DrawImageTests
{
public static readonly TheoryData<PixelColorBlendingMode> BlendingModes = new TheoryData<PixelColorBlendingMode>
{
PixelColorBlendingMode.Normal,
PixelColorBlendingMode.Multiply,
PixelColorBlendingMode.Add,
PixelColorBlendingMode.Subtract,
PixelColorBlendingMode.Screen,
PixelColorBlendingMode.Darken,
PixelColorBlendingMode.Lighten,
PixelColorBlendingMode.Overlay,
PixelColorBlendingMode.HardLight,
};

[Theory]
[WithFile( TestImages.Png.Rainbow,nameof(BlendingModes), PixelTypes.Rgba32)]
public void ImageBlendingMatchesSvgSpecExamples<TPixel>(TestImageProvider<TPixel> provider, PixelColorBlendingMode mode)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> background = provider.GetImage())
using (var source = Image.Load<TPixel>(TestFile.Create(TestImages.Png.Ducky).Bytes))
{
background.Mutate(x => x.DrawImage(source, mode, 1F));
background.DebugSave(
provider,
new { mode = mode },
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);

var comparer = ImageComparer.TolerantPercentage(0.01F);
background.CompareToReferenceOutput(comparer,
provider,
new { mode = mode },
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
}
}

[Theory]
[WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Rgba32, TestImages.Png.Splash, PixelColorBlendingMode.Normal, 1f)]
[WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Bgr24, TestImages.Png.Bike, PixelColorBlendingMode.Normal, 1f)]
[WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Rgba32, TestImages.Png.Splash, PixelColorBlendingMode.Normal, 0.75f)]
[WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Rgba32, TestImages.Png.Splash, PixelColorBlendingMode.Normal, 0.25f)]

[WithTestPatternImages(400, 400, PixelTypes.Rgba32, TestImages.Png.Splash, PixelColorBlendingMode.Multiply, 0.5f)]
[WithTestPatternImages(400, 400, PixelTypes.Rgba32, TestImages.Png.Splash, PixelColorBlendingMode.Add, 0.5f)]
[WithTestPatternImages(400, 400, PixelTypes.Rgba32, TestImages.Png.Splash, PixelColorBlendingMode.Subtract, 0.5f)]

[WithFile(TestImages.Png.Rgb48Bpp, PixelTypes.Rgba64, TestImages.Png.Splash, PixelColorBlendingMode.Normal, 1f)]
[WithFile(TestImages.Png.Rgb48Bpp, PixelTypes.Rgba64, TestImages.Png.Splash, PixelColorBlendingMode.Normal, 0.25f)]
public void WorksWithDifferentConfigurations<TPixel>(
TestImageProvider<TPixel> provider,
string brushImage,
PixelColorBlendingMode mode,
float opacity)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
using (var blend = Image.Load<TPixel>(TestFile.Create(brushImage).Bytes))
{
Size size = new Size(image.Width * 3 / 4, image.Height *3/ 4);
Point position = new Point(image.Width / 8, image.Height / 8);
blend.Mutate(x => x.Resize(size.Width, size.Height, KnownResamplers.Bicubic));
image.Mutate(x => x.DrawImage(blend, position, mode, opacity));
FormattableString testInfo = $"{System.IO.Path.GetFileNameWithoutExtension(brushImage)}-{mode}-{opacity}";

PngEncoder encoder = new PngEncoder();

if (provider.PixelType == PixelTypes.Rgba64)
{
encoder.BitDepth = PngBitDepth.Bit16;
}

image.DebugSave(provider, testInfo, encoder: encoder);
image.CompareToReferenceOutput(provider, testInfo);
}
}


[Theory]
[WithSolidFilledImages(100, 100, "White", PixelTypes.Rgba32, 0, 0)]
[WithSolidFilledImages(100, 100, "White", PixelTypes.Rgba32, 25, 25)]
[WithSolidFilledImages(100, 100, "White", PixelTypes.Rgba32, 75, 50)]
[WithSolidFilledImages(100, 100, "White", PixelTypes.Rgba32, -25, -30)]
public void WorksWithDifferentLocations(TestImageProvider<Rgba32> provider, int x, int y)
{
using (Image<Rgba32> background = provider.GetImage())
using (var overlay = new Image<Rgba32>(50, 50))
{
overlay.Mutate(c => c.Fill(Rgba32.Black));

background.Mutate(c => c.DrawImage(overlay, new Point(x, y), PixelColorBlendingMode.Normal, 1F));

background.DebugSave(
provider,
testOutputDetails: $"{x}_{y}",
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);

background.CompareToReferenceOutput(
provider,
testOutputDetails: $"{x}_{y}",
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
}
}

[Theory]
[WithFile(TestImages.Png.Splash, PixelTypes.Rgba32)]
public void DrawTransformed<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
using (var blend = Image.Load<TPixel>(TestFile.Create(TestImages.Bmp.Car).Bytes))
{
AffineTransformBuilder builder = new AffineTransformBuilder()
.AppendRotationDegrees(45F)
.AppendScale(new SizeF(.25F, .25F))
.AppendTranslation(new PointF(10, 10));

// Apply a background color so we can see the translation.
blend.Mutate(x => x.Transform(builder));
blend.Mutate(x => x.BackgroundColor(Color.HotPink));

// Lets center the matrix so we can tell whether any cut-off issues we may have belong to the drawing processor
var position = new Point((image.Width - blend.Width) / 2, (image.Height - blend.Height) / 2);
image.Mutate(x => x.DrawImage(blend, position, .75F));

image.DebugSave(provider, appendSourceFileOrDescription: false, appendPixelTypeToFileName: false);
image.CompareToReferenceOutput(provider, appendSourceFileOrDescription: false, appendPixelTypeToFileName: false);
}
}

[Theory]
[WithSolidFilledImages(100, 100, 255, 255, 255, PixelTypes.Rgba32, -30, -30)]
[WithSolidFilledImages(100, 100, 255, 255, 255, PixelTypes.Rgba32, 130, -30)]
[WithSolidFilledImages(100, 100, 255, 255, 255, PixelTypes.Rgba32, 130, 130)]
[WithSolidFilledImages(100, 100, 255, 255, 255, PixelTypes.Rgba32, -30, 130)]
public void NonOverlappingImageThrows(TestImageProvider<Rgba32> provider, int x, int y)
{
using (Image<Rgba32> background = provider.GetImage())
using (var overlay = new Image<Rgba32>(Configuration.Default, 10, 10, Rgba32.Black))
{
ImageProcessingException ex = Assert.Throws<ImageProcessingException>(Test);

Assert.Contains("does not overlap", ex.ToString());

void Test()
{
background.Mutate(context => context.DrawImage(overlay, new Point(x, y), GraphicsOptions.Default));
}
}
}
}
}
Loading