|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using SixLabors.ImageSharp.Drawing.Processing; |
| 6 | +using SixLabors.ImageSharp.Drawing.Processing.Processors.Drawing; |
| 7 | +using SixLabors.ImageSharp.PixelFormats; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace SixLabors.ImageSharp.Drawing.Tests.Processing |
| 11 | +{ |
| 12 | + public class FillPathProcessorTests |
| 13 | + { |
| 14 | + [Fact] |
| 15 | + public void OtherShape() |
| 16 | + { |
| 17 | + var imageSize = new Rectangle(0, 0, 500, 500); |
| 18 | + var path = new EllipsePolygon(1, 1, 23); |
| 19 | + var processor = new FillPathProcessor(new ImageSharp.Drawing.Processing.ShapeGraphicsOptions() |
| 20 | + { |
| 21 | + GraphicsOptions = { |
| 22 | + Antialias = true |
| 23 | + } |
| 24 | + }, Brushes.Solid(Color.Red), path); |
| 25 | + var pixelProcessor = processor.CreatePixelSpecificProcessor<Rgba32>(null, null, imageSize); |
| 26 | + |
| 27 | + Assert.IsType<FillRegionProcessor<Rgba32>>(pixelProcessor); |
| 28 | + } |
| 29 | + |
| 30 | + [Fact] |
| 31 | + public void RectangleFloatAndAntialias() |
| 32 | + { |
| 33 | + var imageSize = new Rectangle(0, 0, 500, 500); |
| 34 | + var floatRect = new RectangleF(10.5f, 10.5f, 400.6f, 400.9f); |
| 35 | + var expectedRect = new Rectangle(10, 10, 400, 400); |
| 36 | + var path = new RectangularPolygon(floatRect); |
| 37 | + var processor = new FillPathProcessor(new ImageSharp.Drawing.Processing.ShapeGraphicsOptions() |
| 38 | + { |
| 39 | + GraphicsOptions = { |
| 40 | + Antialias = true |
| 41 | + } |
| 42 | + }, Brushes.Solid(Color.Red), path); |
| 43 | + var pixelProcessor = processor.CreatePixelSpecificProcessor<Rgba32>(null, null, imageSize); |
| 44 | + |
| 45 | + Assert.IsType<FillRegionProcessor<Rgba32>>(pixelProcessor); |
| 46 | + } |
| 47 | + |
| 48 | + [Fact] |
| 49 | + public void IntRectangle() |
| 50 | + { |
| 51 | + var imageSize = new Rectangle(0, 0, 500, 500); |
| 52 | + var expectedRect = new Rectangle(10, 10, 400, 400); |
| 53 | + var path = new RectangularPolygon(expectedRect); |
| 54 | + var processor = new FillPathProcessor(new ImageSharp.Drawing.Processing.ShapeGraphicsOptions() |
| 55 | + { |
| 56 | + GraphicsOptions = { |
| 57 | + Antialias = true |
| 58 | + } |
| 59 | + }, Brushes.Solid(Color.Red), path); |
| 60 | + var pixelProcessor = processor.CreatePixelSpecificProcessor<Rgba32>(null, null, imageSize); |
| 61 | + |
| 62 | + var fill = Assert.IsType<FillProcessor<Rgba32>>(pixelProcessor); |
| 63 | + Assert.Equal(expectedRect, fill.GetProtectedValue<Rectangle>("SourceRectangle")); |
| 64 | + } |
| 65 | + |
| 66 | + [Fact] |
| 67 | + public void FloatRectAntialiasingOff() |
| 68 | + { |
| 69 | + var imageSize = new Rectangle(0, 0, 500, 500); |
| 70 | + var floatRect = new RectangleF(10.5f, 10.5f, 400.6f, 400.9f); |
| 71 | + var expectedRect = new Rectangle(10, 10, 400, 400); |
| 72 | + var path = new RectangularPolygon(floatRect); |
| 73 | + var processor = new FillPathProcessor(new ImageSharp.Drawing.Processing.ShapeGraphicsOptions() |
| 74 | + { |
| 75 | + GraphicsOptions = { |
| 76 | + Antialias = false |
| 77 | + } |
| 78 | + }, Brushes.Solid(Color.Red), path); |
| 79 | + var pixelProcessor = processor.CreatePixelSpecificProcessor<Rgba32>(null, null, imageSize); |
| 80 | + |
| 81 | + var fill = Assert.IsType<FillProcessor<Rgba32>>(pixelProcessor); |
| 82 | + Assert.Equal(expectedRect, fill.GetProtectedValue<Rectangle>("SourceRectangle")); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + internal static class ReflectionHelpers |
| 87 | + { |
| 88 | + internal static T GetProtectedValue<T>(this object obj, string name) |
| 89 | + { |
| 90 | + return (T)obj.GetType() |
| 91 | + .GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.FlattenHierarchy) |
| 92 | + .Single(x => x.Name == name) |
| 93 | + .GetValue(obj); |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments