Browse Source

FillRegion_WorksOnWrappedMemoryImage

pull/660/head
Anton Firszov 8 years ago
parent
commit
61eedd77e1
  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));
}
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));
this.parent = parent;
// 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)

8
src/ImageSharp/ImageFrame{TPixel}.cs

@ -95,8 +95,8 @@ namespace SixLabors.ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class wrapping an existing buffer.
/// </summary>
internal ImageFrame(Configuration configuration, int width, int height, Memory<TPixel> consumedBuffer)
: this(configuration, width, height, consumedBuffer, new ImageFrameMetaData())
internal ImageFrame(Configuration configuration, int width, int height, Memory<TPixel> consumedMemory)
: this(configuration, width, height, consumedMemory, new ImageFrameMetaData())
{
}
@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp
Configuration configuration,
int width,
int height,
Memory<TPixel> consumedBuffer,
Memory<TPixel> consumedMemory,
ImageFrameMetaData metaData)
{
Guard.NotNull(configuration, nameof(configuration));
@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp
this.configuration = configuration;
this.MemoryAllocator = configuration.MemoryAllocator;
this.PixelBuffer = new Buffer2D<TPixel>(consumedBuffer, width, height);
this.PixelBuffer = new Buffer2D<TPixel>(consumedMemory, width, height);
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
/// consuming an external buffer instance.
/// </summary>
internal Image(Configuration configuration, Memory<TPixel> consumedBuffer, int width, int height)
: this(configuration, consumedBuffer, width, height, new ImageMetaData())
internal Image(Configuration configuration, Memory<TPixel> consumedMemory, int width, int height)
: 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
/// consuming an external buffer instance.
/// </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.PixelType = new PixelTypeInfo(Unsafe.SizeOf<TPixel>() * 8);
this.MetaData = metadata;
this.frames = new ImageFrameCollection<TPixel>(this, width, height, consumedBuffer);
this.frames = new ImageFrameCollection<TPixel>(this, width, height, consumedMemory);
}
/// <summary>

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

@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Tests.Advanced
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();
Assert.Equal(targetBuffer.Length, internalMemory.Length);
@ -72,7 +72,6 @@ namespace SixLabors.ImageSharp.Tests.Advanced
image0.ComparePixelBufferTo(externalMemory.Span);
}
}
}
[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);
}
[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 =
new TheoryData<bool, string, float, PixelBlenderMode, float>()
{

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

@ -38,6 +38,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
}
}
[Theory]
[WithBlankImages(500, 500, PixelTypes.Rgba32)]
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
if (TestEnvironment.IsWindows)
{
string testNameBackup = provider.Utility.TestName;
if (useReferenceOutputFrom != null)
{
provider.Utility.TestName = useReferenceOutputFrom;
@ -239,6 +241,8 @@ namespace SixLabors.ImageSharp.Tests
testOutputDetails,
appendPixelTypeToFileName: appendPixelTypeToFileName,
appendSourceFileOrDescription: appendSourceFileOrDescription);
provider.Utility.TestName = testNameBackup;
}
}
}

Loading…
Cancel
Save