Browse Source

ensure we fill pixels even if start is smaller then minX

fixes #237
af/merge-core
Scott Williams 9 years ago
parent
commit
15dffecfc1
  1. 10
      src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
  2. 28
      tests/ImageSharp.Tests/Drawing/DrawPathTests.cs

10
src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs

@ -154,13 +154,11 @@ namespace ImageSharp.Drawing.Processors
int nextX = startX + 1; int nextX = startX + 1;
endX = Math.Min(endX, scanline.Length); // reduce to end to the right edge endX = Math.Min(endX, scanline.Length); // reduce to end to the right edge
if (nextX >= 0) nextX = Math.Max(nextX, 0);
for (int x = nextX; x < endX; x++)
{ {
for (int x = nextX; x < endX; x++) scanline[x] += subpixelFraction;
{ scanlineDirty = true;
scanline[x] += subpixelFraction;
scanlineDirty = true;
}
} }
} }
} }

28
tests/ImageSharp.Tests/Drawing/DrawPathTests.cs

@ -13,6 +13,7 @@ namespace ImageSharp.Tests.Drawing
using ImageSharp.PixelFormats; using ImageSharp.PixelFormats;
using Xunit; using Xunit;
using ImageSharp.Drawing.Pens;
public class DrawPathTests : FileTestBase public class DrawPathTests : FileTestBase
{ {
@ -98,5 +99,32 @@ namespace ImageSharp.Tests.Drawing
} }
} }
[Fact]
public void PathExtendingOffEdgeOfImageShouldNotBeCropped()
{
string path = this.CreateOutputDirectory("Drawing", "Path");
using (var image = new Image<Rgba32>(256, 256))
{
image.Fill(Rgba32.Black);
var pen = Pens.Solid(Rgba32.White, 5f);
for (int i = 0; i < 300; i += 20)
{
image.DrawLines(pen, new Vector2[] { new Vector2(100, 2), new Vector2(-10, i) });
}
using (FileStream output = File.OpenWrite($"{path}/ClippedLines.png"))
{
image
.Save(output);
}
using (PixelAccessor<Rgba32> sourcePixels = image.Lock())
{
Assert.Equal(Rgba32.White, sourcePixels[0, 90]);
}
}
}
} }
} }
Loading…
Cancel
Save