Browse Source

FillRegion_WorksOnWrappedMemoryImage

af/merge-core
Anton Firszov 8 years ago
parent
commit
3ed641f660
  1. 4
      src/ImageSharp/ImageFrameCollection.cs
  2. 8
      src/ImageSharp/ImageFrame{TPixel}.cs
  3. 8
      src/ImageSharp/Image{TPixel}.cs
  4. 3
      tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs
  5. 17
      tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs
  6. 1
      tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs
  7. 4
      tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

4
src/ImageSharp/ImageFrameCollection.cs

@ -30,14 +30,14 @@ namespace SixLabors.ImageSharp
this.frames.Add(new ImageFrame<TPixel>(parent.GetConfiguration(), width, height, backgroundColor)); this.frames.Add(new ImageFrame<TPixel>(parent.GetConfiguration(), width, height, backgroundColor));
} }
internal ImageFrameCollection(Image<TPixel> parent, int width, int height, Memory<TPixel> consumedBuffer) internal ImageFrameCollection(Image<TPixel> parent, int width, int height, Memory<TPixel> consumedMemory)
{ {
Guard.NotNull(parent, nameof(parent)); Guard.NotNull(parent, nameof(parent));
this.parent = parent; this.parent = parent;
// Frames are already cloned within the caller // Frames are already cloned within the caller
this.frames.Add(new ImageFrame<TPixel>(parent.GetConfiguration(), width, height, consumedBuffer)); this.frames.Add(new ImageFrame<TPixel>(parent.GetConfiguration(), width, height, consumedMemory));
} }
internal ImageFrameCollection(Image<TPixel> parent, IEnumerable<ImageFrame<TPixel>> frames) internal ImageFrameCollection(Image<TPixel> parent, IEnumerable<ImageFrame<TPixel>> frames)

8
src/ImageSharp/ImageFrame{TPixel}.cs

@ -95,8 +95,8 @@ namespace SixLabors.ImageSharp
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class wrapping an existing buffer. /// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class wrapping an existing buffer.
/// </summary> /// </summary>
internal ImageFrame(Configuration configuration, int width, int height, Memory<TPixel> consumedBuffer) internal ImageFrame(Configuration configuration, int width, int height, Memory<TPixel> consumedMemory)
: this(configuration, width, height, consumedBuffer, new ImageFrameMetaData()) : this(configuration, width, height, consumedMemory, new ImageFrameMetaData())
{ {
} }
@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp
Configuration configuration, Configuration configuration,
int width, int width,
int height, int height,
Memory<TPixel> consumedBuffer, Memory<TPixel> consumedMemory,
ImageFrameMetaData metaData) ImageFrameMetaData metaData)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp
this.configuration = configuration; this.configuration = configuration;
this.MemoryAllocator = configuration.MemoryAllocator; this.MemoryAllocator = configuration.MemoryAllocator;
this.PixelBuffer = new Buffer2D<TPixel>(consumedBuffer, width, height); this.PixelBuffer = new Buffer2D<TPixel>(consumedMemory, width, height);
this.MetaData = metaData; this.MetaData = metaData;
} }

8
src/ImageSharp/Image{TPixel}.cs

@ -86,8 +86,8 @@ namespace SixLabors.ImageSharp
/// Initializes a new instance of the <see cref="Image{TPixel}"/> class /// Initializes a new instance of the <see cref="Image{TPixel}"/> class
/// consuming an external buffer instance. /// consuming an external buffer instance.
/// </summary> /// </summary>
internal Image(Configuration configuration, Memory<TPixel> consumedBuffer, int width, int height) internal Image(Configuration configuration, Memory<TPixel> consumedMemory, int width, int height)
: this(configuration, consumedBuffer, width, height, new ImageMetaData()) : this(configuration, consumedMemory, width, height, new ImageMetaData())
{ {
} }
@ -95,12 +95,12 @@ namespace SixLabors.ImageSharp
/// Initializes a new instance of the <see cref="Image{TPixel}"/> class /// Initializes a new instance of the <see cref="Image{TPixel}"/> class
/// consuming an external buffer instance. /// consuming an external buffer instance.
/// </summary> /// </summary>
internal Image(Configuration configuration, Memory<TPixel> consumedBuffer, int width, int height, ImageMetaData metadata) internal Image(Configuration configuration, Memory<TPixel> consumedMemory, int width, int height, ImageMetaData metadata)
{ {
this.configuration = configuration; this.configuration = configuration;
this.PixelType = new PixelTypeInfo(Unsafe.SizeOf<TPixel>() * 8); this.PixelType = new PixelTypeInfo(Unsafe.SizeOf<TPixel>() * 8);
this.MetaData = metadata; this.MetaData = metadata;
this.frames = new ImageFrameCollection<TPixel>(this, width, height, consumedBuffer); this.frames = new ImageFrameCollection<TPixel>(this, width, height, consumedMemory);
} }
/// <summary> /// <summary>

3
tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs

@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Tests.Advanced
Memory<TPixel> externalMemory = managerOfExeternalMemory.Memory; Memory<TPixel> externalMemory = managerOfExeternalMemory.Memory;
using (Image<TPixel> image1 = Image.WrapMemory(externalMemory, image0.Width, image0.Height)) using (var image1 = Image.WrapMemory(externalMemory, image0.Width, image0.Height))
{ {
Memory<TPixel> internalMemory = image1.GetPixelMemory(); Memory<TPixel> internalMemory = image1.GetPixelMemory();
Assert.Equal(targetBuffer.Length, internalMemory.Length); Assert.Equal(targetBuffer.Length, internalMemory.Length);
@ -72,7 +72,6 @@ namespace SixLabors.ImageSharp.Tests.Advanced
image0.ComparePixelBufferTo(externalMemory.Span); image0.ComparePixelBufferTo(externalMemory.Span);
} }
} }
} }
[Theory] [Theory]

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

@ -81,6 +81,23 @@ namespace SixLabors.ImageSharp.Tests.Drawing
provider.RunValidatingProcessorTest(c => c.Fill(color, region), testDetails, ImageComparer.Exact); provider.RunValidatingProcessorTest(c => c.Fill(color, region), testDetails, ImageComparer.Exact);
} }
[Theory]
[WithSolidFilledImages(16, 16, "Red", PixelTypes.Rgba32, 5, 7, 3, 8)]
[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)
where TPixel : struct, IPixel<TPixel>
{
FormattableString testDetails = $"(x{x0},y{y0},w{w},h{h})";
var region = new RectangleF(x0, y0, w, h);
TPixel color = TestUtils.GetPixelOfNamedColor<TPixel>("Blue");
provider.RunValidatingProcessorTestOnWrappedMemoryImage(
c => c.Fill(color, region),
testDetails,
ImageComparer.Exact,
useReferenceOutputFrom: nameof(this.FillRegion));
}
public static readonly TheoryData<bool, string, float, PixelBlenderMode, float> BlendData = public static readonly TheoryData<bool, string, float, PixelBlenderMode, float> BlendData =
new TheoryData<bool, string, float, PixelBlenderMode, float>() new TheoryData<bool, string, float, PixelBlenderMode, float>()
{ {

1
tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs

@ -38,6 +38,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
} }
} }
[Theory] [Theory]
[WithBlankImages(500, 500, PixelTypes.Rgba32)] [WithBlankImages(500, 500, PixelTypes.Rgba32)]
public void OverlayByFilledPolygonOpacity<TPixel>(TestImageProvider<TPixel> provider) public void OverlayByFilledPolygonOpacity<TPixel>(TestImageProvider<TPixel> provider)

4
tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

@ -228,6 +228,8 @@ namespace SixLabors.ImageSharp.Tests
// TODO: Investigate the cause of pixel inaccuracies under Linux // TODO: Investigate the cause of pixel inaccuracies under Linux
if (TestEnvironment.IsWindows) if (TestEnvironment.IsWindows)
{ {
string testNameBackup = provider.Utility.TestName;
if (useReferenceOutputFrom != null) if (useReferenceOutputFrom != null)
{ {
provider.Utility.TestName = useReferenceOutputFrom; provider.Utility.TestName = useReferenceOutputFrom;
@ -239,6 +241,8 @@ namespace SixLabors.ImageSharp.Tests
testOutputDetails, testOutputDetails,
appendPixelTypeToFileName: appendPixelTypeToFileName, appendPixelTypeToFileName: appendPixelTypeToFileName,
appendSourceFileOrDescription: appendSourceFileOrDescription); appendSourceFileOrDescription: appendSourceFileOrDescription);
provider.Utility.TestName = testNameBackup;
} }
} }
} }

Loading…
Cancel
Save