Browse Source

DrawImageProcessor + formatting

pull/710/head
Anton Firszov 8 years ago
parent
commit
f0cda4387b
  1. 20
      src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs
  2. 253
      tests/ImageSharp.Tests/Drawing/FillPatternTests.cs
  3. 42
      tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs

20
src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs

@ -6,6 +6,7 @@ using System.Buffers;
using System.Threading.Tasks; using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.ParallelUtils;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Memory; using SixLabors.Memory;
using SixLabors.Primitives; using SixLabors.Primitives;
@ -80,15 +81,20 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
MemoryAllocator memoryAllocator = this.Image.GetConfiguration().MemoryAllocator; MemoryAllocator memoryAllocator = this.Image.GetConfiguration().MemoryAllocator;
ParallelFor.WithConfiguration( var workingRect = Rectangle.FromLTRB(minX, minY, maxX, maxY);
minY,
maxY, ParallelHelper.IterateRows(
workingRect,
configuration, configuration,
y => rows =>
{ {
Span<TPixelDst> background = source.GetPixelRowSpan(y).Slice(minX, width); for (int y = rows.Min; y < rows.Max; y++)
Span<TPixelSrc> foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width); {
blender.Blend<TPixelSrc>(memoryAllocator, background, background, foreground, this.Opacity); Span<TPixelDst> background = source.GetPixelRowSpan(y).Slice(minX, width);
Span<TPixelSrc> foreground =
targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width);
blender.Blend<TPixelSrc>(memoryAllocator, background, background, foreground, this.Opacity);
}
}); });
} }
} }

253
tests/ImageSharp.Tests/Drawing/FillPatternTests.cs

@ -54,172 +54,225 @@ namespace SixLabors.ImageSharp.Tests.Drawing
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithPercent10() public void ImageShouldBeFloodFilledWithPercent10()
{ {
this.Test("Percent10", Rgba32.Blue, Brushes.Percent10(Rgba32.HotPink, Rgba32.LimeGreen), this.Test(
"Percent10",
Rgba32.Blue,
Brushes.Percent10(Rgba32.HotPink, Rgba32.LimeGreen),
new[,] new[,]
{ {
{ Rgba32.HotPink , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, { Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink , Rgba32.LimeGreen}, { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen} { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen }
}); });
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithPercent10Transparent() public void ImageShouldBeFloodFilledWithPercent10Transparent()
{ {
Test("Percent10_Transparent", Rgba32.Blue, Brushes.Percent10(Rgba32.HotPink), this.Test(
new Rgba32[,] { "Percent10_Transparent",
{ Rgba32.HotPink , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, Rgba32.Blue,
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, Brushes.Percent10(Rgba32.HotPink),
{ Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink , Rgba32.Blue}, new Rgba32[,]
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue} {
}); { Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue }
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithPercent20() public void ImageShouldBeFloodFilledWithPercent20()
{ {
Test("Percent20", Rgba32.Blue, Brushes.Percent20(Rgba32.HotPink, Rgba32.LimeGreen), this.Test(
new Rgba32[,] { "Percent20",
{ Rgba32.HotPink , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, Rgba32.Blue,
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink , Rgba32.LimeGreen}, Brushes.Percent20(Rgba32.HotPink, Rgba32.LimeGreen),
{ Rgba32.HotPink , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, new Rgba32[,]
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink , Rgba32.LimeGreen} {
}); { Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen },
{ Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen }
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithPercent20_transparent() public void ImageShouldBeFloodFilledWithPercent20_transparent()
{ {
Test("Percent20_Transparent", Rgba32.Blue, Brushes.Percent20(Rgba32.HotPink), this.Test(
new Rgba32[,] { "Percent20_Transparent",
{ Rgba32.HotPink , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, Rgba32.Blue,
{ Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink , Rgba32.Blue}, Brushes.Percent20(Rgba32.HotPink),
{ Rgba32.HotPink , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, new Rgba32[,]
{ Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink , Rgba32.Blue} {
}); { Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue },
{ Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue }
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithHorizontal() public void ImageShouldBeFloodFilledWithHorizontal()
{ {
Test("Horizontal", Rgba32.Blue, Brushes.Horizontal(Rgba32.HotPink, Rgba32.LimeGreen), this.Test(
new Rgba32[,] { "Horizontal",
{ Rgba32.LimeGreen , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, Rgba32.Blue,
{ Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink , Rgba32.HotPink}, Brushes.Horizontal(Rgba32.HotPink, Rgba32.LimeGreen),
{ Rgba32.LimeGreen , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, new Rgba32[,]
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen , Rgba32.LimeGreen} {
}); { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen }
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithHorizontal_transparent() public void ImageShouldBeFloodFilledWithHorizontal_transparent()
{ {
Test("Horizontal_Transparent", Rgba32.Blue, Brushes.Horizontal(Rgba32.HotPink), this.Test(
new Rgba32[,] { "Horizontal_Transparent",
{ Rgba32.Blue , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, Rgba32.Blue,
{ Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink , Rgba32.HotPink}, Brushes.Horizontal(Rgba32.HotPink),
{ Rgba32.Blue , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, new Rgba32[,]
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue , Rgba32.Blue} {
}); { Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue }
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithMin() public void ImageShouldBeFloodFilledWithMin()
{ {
Test("Min", Rgba32.Blue, Brushes.Min(Rgba32.HotPink, Rgba32.LimeGreen), this.Test(
new Rgba32[,] { "Min",
{ Rgba32.LimeGreen , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, Rgba32.Blue,
{ Rgba32.LimeGreen , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, Brushes.Min(Rgba32.HotPink, Rgba32.LimeGreen),
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen , Rgba32.LimeGreen}, new Rgba32[,]
{ Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink , Rgba32.HotPink} {
}); { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink }
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithMin_transparent() public void ImageShouldBeFloodFilledWithMin_transparent()
{ {
Test("Min_Transparent", Rgba32.Blue, Brushes.Min(Rgba32.HotPink), this.Test(
new Rgba32[,] { "Min_Transparent",
{ Rgba32.Blue , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, Rgba32.Blue,
{ Rgba32.Blue , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, Brushes.Min(Rgba32.HotPink),
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue , Rgba32.Blue}, new Rgba32[,]
{ Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink , Rgba32.HotPink}, {
}); { Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink },
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithVertical() public void ImageShouldBeFloodFilledWithVertical()
{ {
Test("Vertical", Rgba32.Blue, Brushes.Vertical(Rgba32.HotPink, Rgba32.LimeGreen), this.Test(
new Rgba32[,] { "Vertical",
{ Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen}, Rgba32.Blue,
{ Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen}, Brushes.Vertical(Rgba32.HotPink, Rgba32.LimeGreen),
{ Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen}, new Rgba32[,]
{ Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen} {
}); { Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen }
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithVertical_transparent() public void ImageShouldBeFloodFilledWithVertical_transparent()
{ {
Test("Vertical_Transparent", Rgba32.Blue, Brushes.Vertical(Rgba32.HotPink), this.Test(
new Rgba32[,] { "Vertical_Transparent",
{ Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue}, Rgba32.Blue,
{ Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue}, Brushes.Vertical(Rgba32.HotPink),
{ Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue}, new Rgba32[,]
{ Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue} {
}); { Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue }
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithForwardDiagonal() public void ImageShouldBeFloodFilledWithForwardDiagonal()
{ {
Test("ForwardDiagonal", Rgba32.Blue, Brushes.ForwardDiagonal(Rgba32.HotPink, Rgba32.LimeGreen), this.Test(
new Rgba32[,] { "ForwardDiagonal",
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink}, Rgba32.Blue,
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen}, Brushes.ForwardDiagonal(Rgba32.HotPink, Rgba32.LimeGreen),
{ Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen}, new Rgba32[,]
{ Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen} {
}); { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen }
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithForwardDiagonal_transparent() public void ImageShouldBeFloodFilledWithForwardDiagonal_transparent()
{ {
Test("ForwardDiagonal_Transparent", Rgba32.Blue, Brushes.ForwardDiagonal(Rgba32.HotPink), this.Test(
new Rgba32[,] { "ForwardDiagonal_Transparent",
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink}, Rgba32.Blue,
{ Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue}, Brushes.ForwardDiagonal(Rgba32.HotPink),
{ Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue}, new Rgba32[,]
{ Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue} {
}); { Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue }
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithBackwardDiagonal() public void ImageShouldBeFloodFilledWithBackwardDiagonal()
{ {
Test("BackwardDiagonal", Rgba32.Blue, Brushes.BackwardDiagonal(Rgba32.HotPink, Rgba32.LimeGreen), this.Test(
new Rgba32[,] { "BackwardDiagonal",
{ Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, Rgba32.Blue,
{ Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen}, Brushes.BackwardDiagonal(Rgba32.HotPink, Rgba32.LimeGreen),
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen}, new Rgba32[,]
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink} {
}); { Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen },
{ Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink }
});
} }
[Fact] [Fact]
public void ImageShouldBeFloodFilledWithBackwardDiagonal_transparent() public void ImageShouldBeFloodFilledWithBackwardDiagonal_transparent()
{ {
Test("BackwardDiagonal_Transparent", Rgba32.Blue, Brushes.BackwardDiagonal(Rgba32.HotPink), this.Test(
new Rgba32[,] { "BackwardDiagonal_Transparent",
{ Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, Rgba32.Blue,
{ Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue}, Brushes.BackwardDiagonal(Rgba32.HotPink),
{ Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue}, new Rgba32[,]
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink} {
}); { Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue },
{ Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink }
});
} }
} }
} }

42
tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs

@ -1,20 +1,21 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.Primitives;
using SixLabors.Shapes; using SixLabors.Shapes;
using Xunit; using Xunit;
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Drawing namespace SixLabors.ImageSharp.Tests.Drawing
{ {
using System;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.Primitives;
[GroupOutput("Drawing")] [GroupOutput("Drawing")]
public class FillSolidBrushTests public class FillSolidBrushTests
{ {
@ -55,7 +56,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing
[Theory] [Theory]
[WithSolidFilledImages(16, 16, "Red", PixelTypes.Rgba32, "Blue")] [WithSolidFilledImages(16, 16, "Red", PixelTypes.Rgba32, "Blue")]
[WithSolidFilledImages(16, 16, "Yellow", PixelTypes.Rgba32, "Khaki")] [WithSolidFilledImages(16, 16, "Yellow", PixelTypes.Rgba32, "Khaki")]
public void WhenColorIsOpaque_OverridePreviousColor<TPixel>(TestImageProvider<TPixel> provider, string newColorName) public void WhenColorIsOpaque_OverridePreviousColor<TPixel>(
TestImageProvider<TPixel> provider,
string newColorName)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage()) using (Image<TPixel> image = provider.GetImage())
@ -63,7 +66,11 @@ namespace SixLabors.ImageSharp.Tests.Drawing
TPixel color = TestUtils.GetPixelOfNamedColor<TPixel>(newColorName); TPixel color = TestUtils.GetPixelOfNamedColor<TPixel>(newColorName);
image.Mutate(c => c.Fill(color)); image.Mutate(c => c.Fill(color));
image.DebugSave(provider, newColorName, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); image.DebugSave(
provider,
newColorName,
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
image.ComparePixelBufferTo(color); image.ComparePixelBufferTo(color);
} }
} }
@ -84,7 +91,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing
[Theory] [Theory]
[WithSolidFilledImages(16, 16, "Red", PixelTypes.Rgba32, 5, 7, 3, 8)] [WithSolidFilledImages(16, 16, "Red", PixelTypes.Rgba32, 5, 7, 3, 8)]
[WithSolidFilledImages(16, 16, "Red", PixelTypes.Rgba32, 8, 5, 6, 4)] [WithSolidFilledImages(16, 16, "Red", PixelTypes.Rgba32, 8, 5, 6, 4)]
public void FillRegion_WorksOnWrappedMemoryImage<TPixel>(TestImageProvider<TPixel> provider, int x0, int y0, int w, int h) public void FillRegion_WorksOnWrappedMemoryImage<TPixel>(
TestImageProvider<TPixel> provider,
int x0,
int y0,
int w,
int h)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
FormattableString testDetails = $"(x{x0},y{y0},w{w},h{h})"; FormattableString testDetails = $"(x{x0},y{y0},w{w},h{h})";
@ -105,27 +117,22 @@ namespace SixLabors.ImageSharp.Tests.Drawing
{ false, "Blue", 1.0f, PixelColorBlendingMode.Normal, 0.5f }, { false, "Blue", 1.0f, PixelColorBlendingMode.Normal, 0.5f },
{ false, "Green", 0.5f, PixelColorBlendingMode.Normal, 0.3f }, { false, "Green", 0.5f, PixelColorBlendingMode.Normal, 0.3f },
{ false, "HotPink", 0.8f, PixelColorBlendingMode.Normal, 0.8f }, { false, "HotPink", 0.8f, PixelColorBlendingMode.Normal, 0.8f },
{ false, "Blue", 0.5f, PixelColorBlendingMode.Multiply, 1.0f }, { false, "Blue", 0.5f, PixelColorBlendingMode.Multiply, 1.0f },
{ false, "Blue", 1.0f, PixelColorBlendingMode.Multiply, 0.5f }, { false, "Blue", 1.0f, PixelColorBlendingMode.Multiply, 0.5f },
{ false, "Green", 0.5f, PixelColorBlendingMode.Multiply, 0.3f }, { false, "Green", 0.5f, PixelColorBlendingMode.Multiply, 0.3f },
{ false, "HotPink", 0.8f, PixelColorBlendingMode.Multiply, 0.8f }, { false, "HotPink", 0.8f, PixelColorBlendingMode.Multiply, 0.8f },
{ false, "Blue", 0.5f, PixelColorBlendingMode.Add, 1.0f }, { false, "Blue", 0.5f, PixelColorBlendingMode.Add, 1.0f },
{ false, "Blue", 1.0f, PixelColorBlendingMode.Add, 0.5f }, { false, "Blue", 1.0f, PixelColorBlendingMode.Add, 0.5f },
{ false, "Green", 0.5f, PixelColorBlendingMode.Add, 0.3f }, { false, "Green", 0.5f, PixelColorBlendingMode.Add, 0.3f },
{ false, "HotPink", 0.8f, PixelColorBlendingMode.Add, 0.8f }, { false, "HotPink", 0.8f, PixelColorBlendingMode.Add, 0.8f },
{ true, "Blue", 0.5f, PixelColorBlendingMode.Normal, 1.0f }, { true, "Blue", 0.5f, PixelColorBlendingMode.Normal, 1.0f },
{ true, "Blue", 1.0f, PixelColorBlendingMode.Normal, 0.5f }, { true, "Blue", 1.0f, PixelColorBlendingMode.Normal, 0.5f },
{ true, "Green", 0.5f, PixelColorBlendingMode.Normal, 0.3f }, { true, "Green", 0.5f, PixelColorBlendingMode.Normal, 0.3f },
{ true, "HotPink", 0.8f, PixelColorBlendingMode.Normal, 0.8f }, { true, "HotPink", 0.8f, PixelColorBlendingMode.Normal, 0.8f },
{ true, "Blue", 0.5f, PixelColorBlendingMode.Multiply, 1.0f }, { true, "Blue", 0.5f, PixelColorBlendingMode.Multiply, 1.0f },
{ true, "Blue", 1.0f, PixelColorBlendingMode.Multiply, 0.5f }, { true, "Blue", 1.0f, PixelColorBlendingMode.Multiply, 0.5f },
{ true, "Green", 0.5f, PixelColorBlendingMode.Multiply, 0.3f }, { true, "Green", 0.5f, PixelColorBlendingMode.Multiply, 0.3f },
{ true, "HotPink", 0.8f, PixelColorBlendingMode.Multiply, 0.8f }, { true, "HotPink", 0.8f, PixelColorBlendingMode.Multiply, 0.8f },
{ true, "Blue", 0.5f, PixelColorBlendingMode.Add, 1.0f }, { true, "Blue", 0.5f, PixelColorBlendingMode.Add, 1.0f },
{ true, "Blue", 1.0f, PixelColorBlendingMode.Add, 0.5f }, { true, "Blue", 1.0f, PixelColorBlendingMode.Add, 0.5f },
{ true, "Green", 0.5f, PixelColorBlendingMode.Add, 0.3f }, { true, "Green", 0.5f, PixelColorBlendingMode.Add, 0.3f },
@ -155,8 +162,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
var options = new GraphicsOptions(false) var options = new GraphicsOptions(false)
{ {
ColorBlendingMode = blenderMode, ColorBlendingMode = blenderMode, BlendPercentage = blendPercentage
BlendPercentage = blendPercentage
}; };
if (triggerFillRegion) if (triggerFillRegion)
@ -185,7 +191,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing
appendPixelTypeToFileName: false, appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false); appendSourceFileOrDescription: false);
PixelBlender<TPixel> blender = PixelOperations<TPixel>.Instance.GetPixelBlender(blenderMode, PixelAlphaCompositionMode.SrcOver); PixelBlender<TPixel> blender = PixelOperations<TPixel>.Instance.GetPixelBlender(
blenderMode,
PixelAlphaCompositionMode.SrcOver);
TPixel expectedPixel = blender.Blend(bgColor, fillColor, blendPercentage); TPixel expectedPixel = blender.Blend(bgColor, fillColor, blendPercentage);
image.ComparePixelBufferTo(expectedPixel); image.ComparePixelBufferTo(expectedPixel);

Loading…
Cancel
Save