/// <inheritdoc cref="IBrush"/> /// <param name="repetitionMode">Defines how the colors are repeated beyond the interval [0..1]</param> /// <param name="colorStops">The gradient colors.</param> protected GradientBrushBase( GradientRepetitionMode repetitionMode, params ColorStop[] colorStops) { this.RepetitionMode = repetitionMode; this.ColorStops = colorStops; }
/// <summary> /// Initializes a new instance of the <see cref="RadialGradientBrushApplicator" /> class. /// </summary> /// <param name="target">The target image</param> /// <param name="options">The options</param> /// <param name="center">Center of the ellipse</param> /// <param name="referenceAxisEnd">Point on one angular points of the ellipse.</param> /// <param name="axisRatio"> /// Ratio of the axis length's. Used to determine the length of the second axis, /// the first is defined by <see cref="center"/> and <see cref="referenceAxisEnd"/>.</param> /// <param name="colorStops">Definition of colors</param> /// <param name="repetitionMode">Defines how the gradient colors are repeated.</param> public RadialGradientBrushApplicator( ImageFrame <TPixel> target, GraphicsOptions options, Point center, Point referenceAxisEnd, float axisRatio, ColorStop <TPixel>[] colorStops, GradientRepetitionMode repetitionMode) : base(target, options, colorStops, repetitionMode) { this.center = center; this.referenceAxisEnd = referenceAxisEnd; this.axisRatio = axisRatio; this.rotation = this.AngleBetween( this.center, new PointF(this.center.X + 1, this.center.Y), this.referenceAxisEnd); this.referenceRadius = this.DistanceBetween(this.center, this.referenceAxisEnd); this.secondRadius = this.referenceRadius * this.axisRatio; this.referenceRadiusSquared = this.referenceRadius * this.referenceRadius; this.secondRadiusSquared = this.secondRadius * this.secondRadius; this.sinRotation = (float)Math.Sin(this.rotation); this.cosRotation = (float)Math.Cos(this.rotation); }
/// <summary> /// Initializes a new instance of the <see cref="LinearGradientBrushApplicator{TPixel}" /> class. /// </summary> /// <param name="configuration">The configuration instance to use when performing operations.</param> /// <param name="options">The graphics options.</param> /// <param name="source">The source image.</param> /// <param name="start">The start point of the gradient.</param> /// <param name="end">The end point of the gradient.</param> /// <param name="colorStops">A tuple list of colors and their respective position between 0 and 1 on the line.</param> /// <param name="repetitionMode">Defines how the gradient colors are repeated.</param> public LinearGradientBrushApplicator( Configuration configuration, GraphicsOptions options, ImageFrame <TPixel> source, PointF start, PointF end, ColorStop[] colorStops, GradientRepetitionMode repetitionMode) : base(configuration, options, source, colorStops, repetitionMode) { this.start = start; this.end = end; // the along vector: this.alongX = this.end.X - this.start.X; this.alongY = this.end.Y - this.start.Y; // the cross vector: this.acrossX = this.alongY; this.acrossY = -this.alongX; // some helpers: this.alongsSquared = (this.alongX * this.alongX) + (this.alongY * this.alongY); this.length = MathF.Sqrt(this.alongsSquared); }
public void HorizontalGradientWithRepMode <TPixel>( TestImageProvider <TPixel> provider, GradientRepetitionMode repetitionMode) 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 / 10, 0), repetitionMode, new ColorStop <TPixel>(0, red), new ColorStop <TPixel>(1, yellow)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, $"{repetitionMode}", false, false); }
public void HorizontalGradientWithRepMode <TPixel>( TestImageProvider <TPixel> provider, GradientRepetitionMode repetitionMode) 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 / 10, 0), repetitionMode, new ColorStop(0, red), new ColorStop(1, yellow)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, $"{repetitionMode}", false, false); }
/// <inheritdoc cref="GradientBrushBase" /> /// <param name="center">The center of the circular gradient and 0 for the color stops.</param> /// <param name="radius">The radius of the circular gradient and 1 for the color stops.</param> /// <param name="repetitionMode">Defines how the colors in the gradient are repeated.</param> /// <param name="colorStops">the color stops as defined in base class.</param> public RadialGradientBrush( PointF center, float radius, GradientRepetitionMode repetitionMode, params ColorStop[] colorStops) : base(repetitionMode, colorStops) { this.center = center; this.radius = radius; }
/// <summary> /// Initializes a new instance of the <see cref="LinearGradientBrush{TPixel}"/> class. /// </summary> /// <param name="p1">Start point</param> /// <param name="p2">End point</param> /// <param name="repetitionMode">defines how colors are repeated.</param> /// <param name="colorStops"><inheritdoc /></param> public LinearGradientBrush( PointF p1, PointF p2, GradientRepetitionMode repetitionMode, params ColorStop<TPixel>[] colorStops) : base(repetitionMode, colorStops) { this.p1 = p1; this.p2 = p2; }
/// <summary> /// Initializes a new instance of the <see cref="GradientBrushApplicatorBase{TPixel}"/> class. /// </summary> /// <param name="target">The target.</param> /// <param name="options">The options.</param> /// <param name="colorStops">An array of color stops sorted by their position.</param> /// <param name="repetitionMode">Defines if and how the gradient should be repeated.</param> protected GradientBrushApplicatorBase( ImageFrame <TPixel> target, GraphicsOptions options, ColorStop[] colorStops, GradientRepetitionMode repetitionMode) : base(target, options) { this.colorStops = colorStops; // TODO: requires colorStops to be sorted by position - should that be checked? this.repetitionMode = repetitionMode; }
/// <summary> /// Initializes a new instance of the <see cref="RadialGradientBrushApplicator{TPixel}" /> class. /// </summary> /// <param name="target">The target image</param> /// <param name="options">The options.</param> /// <param name="center">Center point of the gradient.</param> /// <param name="radius">Radius of the gradient.</param> /// <param name="colorStops">Definition of colors.</param> /// <param name="repetitionMode">How the colors are repeated beyond the first gradient.</param> public RadialGradientBrushApplicator( ImageFrame <TPixel> target, GraphicsOptions options, PointF center, float radius, ColorStop[] colorStops, GradientRepetitionMode repetitionMode) : base(target, options, colorStops, repetitionMode) { this.center = center; this.radius = radius; }
/// <inheritdoc cref="GradientBrushBase{TPixel}" /> /// <param name="center">The center of the elliptical gradient and 0 for the color stops.</param> /// <param name="referenceAxisEnd">The end point of the reference axis of the ellipse.</param> /// <param name="axisRatio"> /// The ratio of the axis widths. /// The second axis' is perpendicular to the reference axis and /// it's length is the reference axis' length multiplied by this factor. /// </param> /// <param name="repetitionMode">Defines how the colors of the gradients are repeated.</param> /// <param name="colorStops">the color stops as defined in base class.</param> public EllipticGradientBrush( Point center, Point referenceAxisEnd, float axisRatio, GradientRepetitionMode repetitionMode, params ColorStop <TPixel>[] colorStops) : base(repetitionMode, colorStops) { this.center = center; this.referenceAxisEnd = referenceAxisEnd; this.axisRatio = axisRatio; }
/// <summary> /// Initializes a new instance of the <see cref="GradientBrushApplicator{TPixel}"/> class. /// </summary> /// <param name="configuration">The configuration instance to use when performing operations.</param> /// <param name="options">The graphics options.</param> /// <param name="target">The target image.</param> /// <param name="colorStops">An array of color stops sorted by their position.</param> /// <param name="repetitionMode">Defines if and how the gradient should be repeated.</param> protected GradientBrushApplicator( Configuration configuration, GraphicsOptions options, ImageFrame <TPixel> target, ColorStop[] colorStops, GradientRepetitionMode repetitionMode) : base(configuration, options, target) { // TODO: requires colorStops to be sorted by position. // Use Array.Sort with a custom comparer. this.colorStops = colorStops; this.repetitionMode = repetitionMode; this.scalineWidth = target.Width; this.allocator = configuration.MemoryAllocator; this.blenderBuffers = new ThreadLocalBlenderBuffers <TPixel>(this.allocator, this.scalineWidth); }
/// <summary> /// Initializes a new instance of the <see cref="LinearGradientBrushApplicator" /> class. /// </summary> /// <param name="source">The source</param> /// <param name="start">start point of the gradient</param> /// <param name="end">end point of the gradient</param> /// <param name="colorStops">tuple list of colors and their respective position between 0 and 1 on the line</param> /// <param name="repetitionMode">defines how the gradient colors are repeated.</param> /// <param name="options">the graphics options</param> public LinearGradientBrushApplicator( ImageFrame <TPixel> source, Point start, Point end, ColorStop <TPixel>[] colorStops, GradientRepetitionMode repetitionMode, GraphicsOptions options) : base(source, options, colorStops, repetitionMode) { this.start = start; this.end = end; // the along vector: this.alongX = this.end.X - this.start.X; this.alongY = this.end.Y - this.start.Y; // the cross vector: this.acrossX = this.alongY; this.acrossY = -this.alongX; // some helpers: this.alongsSquared = (this.alongX * this.alongX) + (this.alongY * this.alongY); this.length = (float)Math.Sqrt(this.alongsSquared); }