public void DoesNotDependOnSinglePixelType <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { provider.VerifyOperation( TolerantComparer, image => { var unicolorLinearGradientBrush = new LinearGradientBrush( new Point(0, 0), new Point(image.Width, 0), GradientRepetitionMode.None, new ColorStop(0, Color.Blue), new ColorStop(1, Color.Yellow)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, appendSourceFileOrDescription: false); }
public void DoesNotDependOnSinglePixelType <TPixel>(TestImageProvider <TPixel> provider) where TPixel : struct, IPixel <TPixel> { provider.VerifyOperation( TolerantComparer, image => { var unicolorLinearGradientBrush = new LinearGradientBrush <TPixel>( new SixLabors.Primitives.Point(0, 0), new SixLabors.Primitives.Point(image.Width, 0), GradientRepetitionMode.None, new ColorStop <TPixel>(0, NamedColors <TPixel> .Blue), new ColorStop <TPixel>(1, NamedColors <TPixel> .Yellow)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, appendSourceFileOrDescription: false); }
public void MultiplePointGradients <TPixel>( TestImageProvider <TPixel> provider, int startX, int startY, int endX, int endY, float[] stopPositions, int[] stopColorCodes) where TPixel : struct, IPixel <TPixel> { TPixel[] colors = { NamedColors <TPixel> .Black, NamedColors <TPixel> .Blue, NamedColors <TPixel> .Red, NamedColors <TPixel> .White, NamedColors <TPixel> .Lime }; var coloringVariant = new StringBuilder(); var colorStops = new ColorStop <TPixel> [stopPositions.Length]; for (int i = 0; i < stopPositions.Length; i++) { TPixel color = colors[stopColorCodes[i % colors.Length]]; float position = stopPositions[i]; colorStops[i] = new ColorStop <TPixel>(position, color); Rgba32 rgba = default; color.ToRgba32(ref rgba); coloringVariant.AppendFormat(CultureInfo.InvariantCulture, "{0}@{1};", rgba.ToHex(), position); } FormattableString variant = $"({startX},{startY})_TO_({endX},{endY})__[{coloringVariant}]"; provider.VerifyOperation( image => { var unicolorLinearGradientBrush = new LinearGradientBrush <TPixel>( new SixLabors.Primitives.Point(startX, startY), new SixLabors.Primitives.Point(endX, endY), GradientRepetitionMode.None, colorStops); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, variant, false, false); }
public void FontShapesAreRenderedCorrectly_LargeText <TPixel>( TestImageProvider <TPixel> provider) where TPixel : struct, IPixel <TPixel> { Font font = CreateFont("OpenSans-Regular.ttf", 36); var sb = new StringBuilder(); string str = Repeat(" ", 78) + "THISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDS"; sb.Append(str); string newLines = Repeat(Environment.NewLine, 80); sb.Append(newLines); for (int i = 0; i < 10; i++) { sb.AppendLine(str); } var textOptions = new TextGraphicsOptions { Antialias = true, ApplyKerning = true, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, }; Color color = Color.Black; // Based on the reported 0.0270% difference with AccuracyMultiple = 8 // We should avoid quality regressions leading to higher difference! var comparer = ImageComparer.TolerantPercentage(0.03f); provider.VerifyOperation( comparer, img => { img.Mutate(c => c.DrawText(textOptions, sb.ToString(), font, color, new PointF(10, 5))); }, false, false); }
public void ArbitraryGradients <TPixel>( TestImageProvider <TPixel> provider, int startX, int startY, int endX, int endY, float[] stopPositions, int[] stopColorCodes) where TPixel : unmanaged, IPixel <TPixel> { Color[] colors = { Color.Navy, Color.LightGreen, Color.Yellow, Color.Red }; var coloringVariant = new StringBuilder(); var colorStops = new ColorStop[stopPositions.Length]; for (int i = 0; i < stopPositions.Length; i++) { Color color = colors[stopColorCodes[i % colors.Length]]; float position = stopPositions[i]; colorStops[i] = new ColorStop(position, color); Rgba32 rgba = color; coloringVariant.AppendFormat(CultureInfo.InvariantCulture, "{0}@{1};", rgba.ToHex(), position); } FormattableString variant = $"({startX},{startY})_TO_({endX},{endY})__[{coloringVariant}]"; provider.VerifyOperation( image => { var unicolorLinearGradientBrush = new LinearGradientBrush( new Point(startX, startY), new Point(endX, endY), GradientRepetitionMode.None, colorStops); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, variant, false, false); }
public void FillComplex <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> => provider.VerifyOperation( new TolerantImageComparer(0.2f), image => { var star = new Star(50, 50, 5, 20, 45); PointF[] points = star.Points.ToArray(); Color[] colors = { Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple, Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple }; var brush = new PathGradientBrush(points, colors, Color.White); image.Mutate(x => x.Fill(brush)); }, appendSourceFileOrDescription: false, appendPixelTypeToFileName: false);
public void HorizontalReturnsUnicolorColumns <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> => provider.VerifyOperation( TolerantComparer, image => { Color red = Color.Red; Color yellow = Color.Yellow; var unicolorLinearGradientBrush = new LinearGradientBrush( new Point(0, 0), new Point(image.Width, 0), GradientRepetitionMode.None, new ColorStop(0, red), new ColorStop(1, yellow)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, false, false);
public void RotatedEllipsesWithDifferentRatio <TPixel>( TestImageProvider <TPixel> provider, float ratio, float rotationInDegree) where TPixel : unmanaged, IPixel <TPixel> { FormattableString variant = $"{ratio:F2}_AT_{rotationInDegree:00}deg"; provider.VerifyOperation( TolerantComparer, image => { Color yellow = Color.Yellow; Color red = Color.Red; Color black = Color.Black; var center = new Point(image.Width / 2, image.Height / 2); double rotation = Math.PI * rotationInDegree / 180.0; double cos = Math.Cos(rotation); double sin = Math.Sin(rotation); int offsetY = image.Height / 6; int axisX = center.X + (int)-(offsetY * sin); int axisY = center.Y + (int)(offsetY * cos); var unicolorLinearGradientBrush = new EllipticGradientBrush( center, new Point(axisX, axisY), ratio, GradientRepetitionMode.None, new ColorStop(0, yellow), new ColorStop(1, red), new ColorStop(1, black)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, variant, false, false); }
public void FontShapesAreRenderedCorrectlyWithAPenPatterned <TPixel>( TestImageProvider <TPixel> provider, int fontSize, int x, int y, string fontName, string text) where TPixel : struct, IPixel <TPixel> { Font font = CreateFont(fontName, fontSize); TPixel color = NamedColors <TPixel> .Black; provider.VerifyOperation( OutlinedTextDrawingComparer, img => { img.Mutate(c => c.DrawText(text, new Font(font, fontSize), null, Pens.DashDot(color, 3), new PointF(x, y))); }, $"pen_{fontName}-{fontSize}-{ToTestOutputDisplayText(text)}-({x},{y})", appendPixelTypeToFileName: false, appendSourceFileOrDescription: true); }
public void HorizontalReturnsUnicolorColumns <TPixel>(TestImageProvider <TPixel> provider) where TPixel : struct, IPixel <TPixel> { provider.VerifyOperation( TolerantComparer, image => { TPixel red = NamedColors <TPixel> .Red; TPixel yellow = NamedColors <TPixel> .Yellow; var unicolorLinearGradientBrush = new LinearGradientBrush <TPixel>( new SixLabors.Primitives.Point(0, 0), new SixLabors.Primitives.Point(image.Width, 0), GradientRepetitionMode.None, new ColorStop <TPixel>(0, red), new ColorStop <TPixel>(1, yellow)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, false, false); }
public void FillTriangleWithGreyscale <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> => provider.VerifyOperation( ImageComparer.TolerantPercentage(0.02f), image => { PointF[] points = { new PointF(10, 0), new PointF(20, 20), new PointF(0, 20) }; var c1 = default(Rgba32); var c2 = default(Rgba32); var c3 = default(Rgba32); new HalfSingle(-1).ToRgba32(ref c1); new HalfSingle(0).ToRgba32(ref c2); new HalfSingle(1).ToRgba32(ref c3); Color[] colors = { new Color(c1), new Color(c2), new Color(c3) }; var brush = new PathGradientBrush(points, colors); image.Mutate(x => x.Fill(brush)); image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); });
public void FillTriangleWithDifferentColors <TPixel>(TestImageProvider <TPixel> provider) where TPixel : struct, IPixel <TPixel> { provider.VerifyOperation( TolerantComparer, image => { ILineSegment[] path = { new LinearLineSegment(new PointF(5, 0), new PointF(10, 10)), new LinearLineSegment(new PointF(10, 10), new PointF(0, 10)), new LinearLineSegment(new PointF(0, 10), new PointF(5, 0)) }; Color[] colors = { Color.Red, Color.Green, Color.Blue }; var brush = new PathGradientBrush(path, colors); image.Mutate(x => x.Fill(brush)); image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); }); }
public void FontShapesAreRenderedCorrectly <TPixel>( TestImageProvider <TPixel> provider, int fontSize, int x, int y, string fontName, string text) where TPixel : struct, IPixel <TPixel> { Font font = CreateFont(fontName, fontSize); Color color = Color.Black; provider.VerifyOperation( TextDrawingComparer, img => { img.Mutate(c => c.DrawText(text, new Font(font, fontSize), color, new PointF(x, y))); }, $"{fontName}-{fontSize}-{ToTestOutputDisplayText(text)}-({x},{y})", appendPixelTypeToFileName: false, appendSourceFileOrDescription: true); }
public void FontShapesAreRenderedCorrectly_LargeText <TPixel>( TestImageProvider <TPixel> provider) where TPixel : struct, IPixel <TPixel> { Font font = CreateFont("OpenSans-Regular.ttf", 36); var sb = new StringBuilder(); string str = Repeat(" ", 78) + "THISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDS"; sb.Append(str); string newLines = Repeat(Environment.NewLine, 80); sb.Append(newLines); for (int i = 0; i < 10; i++) { sb.AppendLine(str); } var textOptions = new TextGraphicsOptions { Antialias = true, ApplyKerning = true, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, }; TPixel color = NamedColors <TPixel> .Black; provider.VerifyOperation( TextDrawingComparer, img => { img.Mutate(c => c.DrawText(textOptions, sb.ToString(), font, color, new PointF(10, 5))); }, false, false); }
public void VerticalBrushReturnsUnicolorRows <TPixel>( TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { provider.VerifyOperation( image => { Color red = Color.Red; Color yellow = Color.Yellow; var unicolorLinearGradientBrush = new LinearGradientBrush( new Point(0, 0), new Point(0, image.Height), GradientRepetitionMode.None, new ColorStop(0, red), new ColorStop(1, yellow)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); VerifyAllRowsAreUnicolor(image); }, false, false);
public void ShouldRotateTheColorsWhenThereAreMorePoints <TPixel>(TestImageProvider <TPixel> provider) where TPixel : struct, IPixel <TPixel> { provider.VerifyOperation( TolerantComparer, image => { ILineSegment[] path = { new LinearLineSegment(new PointF(0, 0), new PointF(10, 0)), new LinearLineSegment(new PointF(10, 0), new PointF(10, 10)), new LinearLineSegment(new PointF(10, 10), new PointF(0, 10)), new LinearLineSegment(new PointF(0, 10), new PointF(0, 0)) }; Color[] colors = { Color.Red, Color.Yellow }; var brush = new PathGradientBrush(path, colors); image.Mutate(x => x.Fill(brush)); image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); }); }
public void WithDifferentCentersReturnsImage <TPixel>( TestImageProvider <TPixel> provider, int centerX, int centerY) where TPixel : struct, IPixel <TPixel> { provider.VerifyOperation( TolerantComparer, image => { var brush = new RadialGradientBrush <TPixel>( new SixLabors.Primitives.Point(centerX, centerY), image.Width / 2f, GradientRepetitionMode.None, new ColorStop <TPixel>(0, NamedColors <TPixel> .Red), new ColorStop <TPixel>(1, NamedColors <TPixel> .Yellow)); image.Mutate(x => x.Fill(brush)); }, $"center({centerX},{centerY})", false, false); }
public void WithDifferentCentersReturnsImage <TPixel>( TestImageProvider <TPixel> provider, int centerX, int centerY) where TPixel : unmanaged, IPixel <TPixel> { provider.VerifyOperation( TolerantComparer, image => { var brush = new RadialGradientBrush( new Point(centerX, centerY), image.Width / 2f, GradientRepetitionMode.None, new ColorStop(0, Color.Red), new ColorStop(1, Color.Yellow)); image.Mutate(x => x.Fill(brush)); }, $"center({centerX},{centerY})", false, false); }
public void VerticalBrushReturnsUnicolorRows <TPixel>( TestImageProvider <TPixel> provider) where TPixel : struct, IPixel <TPixel> { provider.VerifyOperation( image => { TPixel red = NamedColors <TPixel> .Red; TPixel yellow = NamedColors <TPixel> .Yellow; var unicolorLinearGradientBrush = new LinearGradientBrush <TPixel>( new SixLabors.Primitives.Point(0, 0), new SixLabors.Primitives.Point(0, image.Height), GradientRepetitionMode.None, new ColorStop <TPixel>(0, red), new ColorStop <TPixel>(1, yellow)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); VerifyAllRowsAreUnicolor(image); }, false, false); void VerifyAllRowsAreUnicolor(Image <TPixel> image) { for (int y = 0; y < image.Height; y++) { Span <TPixel> row = image.GetPixelRowSpan(y); TPixel firstColorOfRow = row[0]; foreach (TPixel p in row) { Assert.Equal(firstColorOfRow, p); } } } }
public void FontShapesAreRenderedCorrectly <TPixel>( TestImageProvider <TPixel> provider, int fontSize, int x, int y, string fontName, string text) where TPixel : struct, IPixel <TPixel> { Font font = CreateFont(fontName, fontSize); string fnDisplayText = text.Replace("\n", ""); fnDisplayText = fnDisplayText.Substring(0, Math.Min(fnDisplayText.Length, 4)); TPixel color = NamedColors <TPixel> .Black; provider.VerifyOperation( img => { img.Mutate(c => c.DrawText(text, new Font(font, fontSize), color, new PointF(x, y))); }, $"{fontName}-{fontSize}-{fnDisplayText}-({x},{y})", appendPixelTypeToFileName: false, appendSourceFileOrDescription: true); }
public void GradientsWithTransparencyOnExistingBackground <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { provider.VerifyOperation( image => { image.Mutate(i => i.Fill(Color.Red)); image.Mutate(ApplyGloss); }); void ApplyGloss(IImageProcessingContext ctx) { Size size = ctx.GetCurrentSize(); IPathCollection glossPath = BuildGloss(size.Width, size.Height); var graphicsOptions = new GraphicsOptions { Antialias = true, ColorBlendingMode = PixelColorBlendingMode.Normal, AlphaCompositionMode = PixelAlphaCompositionMode.SrcAtop }; var linearGradientBrush = new LinearGradientBrush(new Point(0, 0), new Point(0, size.Height / 2), GradientRepetitionMode.Repeat, new ColorStop(0, Color.White.WithAlpha(0.5f)), new ColorStop(1, Color.White.WithAlpha(0.25f))); ctx.SetGraphicsOptions(graphicsOptions).Fill(linearGradientBrush, glossPath); } IPathCollection BuildGloss(int imageWidth, int imageHeight) { var pathBuilder = new PathBuilder(); pathBuilder.AddLine(new PointF(0, 0), new PointF(imageWidth, 0)); pathBuilder.AddLine(new PointF(imageWidth, 0), new PointF(imageWidth, imageHeight * 0.4f)); pathBuilder.AddBezier(new PointF(imageWidth, imageHeight * 0.4f), new PointF(imageWidth / 2, imageHeight * 0.6f), new PointF(0, imageHeight * 0.4f)); pathBuilder.CloseFigure(); return(new PathCollection(pathBuilder.Build())); } }