private void DrawFilledEllipse(Image image, Numerics.Rectangle targetLocation)
        {
            int hh   = Height * Height;
            int ww   = Width * Width;
            int hhww = hh * ww;
            int x0   = Width;
            int dx   = 0;

            for (int x = -Width; x <= Width; ++x)
            {
                Plot(image, (int)Center.X + x, (int)Center.Y, 1, targetLocation);
            }

            for (int y = 1; y <= Height; ++y)
            {
                int x1 = x0 - (dx - 1);
                for (; x1 > 0; x1--)
                {
                    if (x1 * x1 * hh + y * y * ww <= hhww)
                    {
                        break;
                    }
                }
                dx = x0 - x1;
                x0 = x1;

                for (int x = -x0; x <= x0; x++)
                {
                    Plot(image, (int)Center.X + x, (int)Center.Y - y, 1, targetLocation);
                    Plot(image, (int)Center.X + x, (int)Center.Y + y, 1, targetLocation);
                }
            }
        }
 /// <summary>
 /// Plots 4 points along the ellipse.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 /// <param name="targetLocation">The target location.</param>
 private void Plot4EllipsePoints(Image image, int x, int y, Numerics.Rectangle targetLocation)
 {
     Plot(image, (int)(Center.X + x), (int)(Center.Y + y), 1, targetLocation);
     Plot(image, (int)(Center.X - x), (int)(Center.Y + y), 1, targetLocation);
     Plot(image, (int)(Center.X - x), (int)(Center.Y - y), 1, targetLocation);
     Plot(image, (int)(Center.X + x), (int)(Center.Y - y), 1, targetLocation);
 }
        public static RectangleF ToGDIRectangleF(this Numerics.Rectangle rectangle)
        {
            Union u = _union;

            u.Rectangle = rectangle;
            return(u.GdiRectangleF);
        }
 /// <summary>
 /// Applies the specified image.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="targetLocation">The target location.</param>
 /// <returns></returns>
 public override unsafe Image Apply(Image image, Numerics.Rectangle targetLocation = default(Numerics.Rectangle))
 {
     targetLocation = targetLocation == default(Numerics.Rectangle) ? new Numerics.Rectangle(0, 0, image.Width, image.Height) : targetLocation.Clamp(image);
     Bounds         = Bounds.Clamp(targetLocation);
     return(Fill ? DrawFilledRectangle(image, Bounds)
                 : DrawRectangleOutline(image, targetLocation));
 }
 /// <summary>
 /// Draws the rectangle outline.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="targetLocation">The target location.</param>
 /// <returns>The resulting image</returns>
 private Image DrawRectangleOutline(Image image, Numerics.Rectangle targetLocation)
 {
     new Line(Color, Bounds.Left, Bounds.Bottom, Bounds.Right, Bounds.Bottom).Apply(image, targetLocation);
     new Line(Color, Bounds.Left, Bounds.Top, Bounds.Right, Bounds.Top).Apply(image, targetLocation);
     new Line(Color, Bounds.Left, Bounds.Bottom, Bounds.Left, Bounds.Top).Apply(image, targetLocation);
     new Line(Color, Bounds.Right, Bounds.Bottom, Bounds.Right, Bounds.Top).Apply(image, targetLocation);
     return(image);
 }
        /// <summary>
        /// Plots the pixel to the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="brightness">The brightness of the pixel.</param>
        /// <param name="targetLocation">The target location.</param>
        protected void Plot(Image image, int x, int y, float brightness, Numerics.Rectangle targetLocation)
        {
            if (!targetLocation.Contains(x, y))
            {
                return;
            }
            var Offset    = (y * image.Width) + x;
            var TempColor = Color * brightness;

            //float TempAlpha = TempColor.Alpha / 255f;
            image.Pixels[Offset] = TempColor;
        }
 /// <summary>
 /// Applies the specified image.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="targetLocation">The target location.</param>
 /// <returns></returns>
 public override Image Apply(Image image, Numerics.Rectangle targetLocation = default(Numerics.Rectangle))
 {
     targetLocation = targetLocation == default(Numerics.Rectangle) ? new Numerics.Rectangle(0, 0, image.Width, image.Height) : targetLocation.Clamp(image);
     if (Fill)
     {
         DrawFilledEllipse(image, targetLocation);
     }
     else
     {
         DrawEllipse(image, targetLocation);
     }
     return(image);
 }
        private void DrawEllipse(Image image, Numerics.Rectangle targetLocation)
        {
            int TwoASquare   = 2 * Width * Width;
            int TwoBSquare   = 2 * Height * Height;
            int x            = Width;
            int y            = 0;
            var XChange      = Height * Height * (1 - 2 * Width);
            var YChange      = Width * Width;
            var EllipseError = 0;
            var StoppingX    = TwoBSquare * Width;
            var StoppingY    = 0;

            while (StoppingX >= StoppingY)
            {
                Plot4EllipsePoints(image, x, y, targetLocation);
                ++y;
                StoppingY    += TwoASquare;
                EllipseError += YChange;
                YChange      += TwoASquare;
                if (2 * EllipseError + XChange > 0)
                {
                    --x;
                    StoppingX    -= TwoBSquare;
                    EllipseError += XChange;
                    XChange      += TwoBSquare;
                }
            }
            x            = 0;
            y            = Height;
            XChange      = Height * Height;
            YChange      = Width * Width * (1 - 2 * Height);
            EllipseError = 0;
            StoppingX    = 0;
            StoppingY    = TwoASquare * Height;
            while (StoppingX <= StoppingY)
            {
                Plot4EllipsePoints(image, x, y, targetLocation);
                ++x;
                StoppingX    += TwoBSquare;
                EllipseError += XChange;
                XChange      += TwoBSquare;
                if (2 * EllipseError + YChange > 0)
                {
                    --y;
                    StoppingY    -= TwoASquare;
                    EllipseError += YChange;
                    YChange      += TwoASquare;
                }
            }
        }
 /// <summary>
 /// Draws the filled rectangle.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="targetLocation">The target location.</param>
 /// <returns>The resulting image</returns>
 private unsafe Image DrawFilledRectangle(Image image, Numerics.Rectangle targetLocation)
 {
     Parallel.For(targetLocation.Bottom, targetLocation.Top, y =>
     {
         fixed(Color * TargetPointer = &image.Pixels[(y * image.Width) + targetLocation.Left])
         {
             Color *TargetPointer2 = TargetPointer;
             for (int x = targetLocation.Left; x < targetLocation.Right; ++x)
             {
                 *TargetPointer2 = Color;
                 ++TargetPointer2;
             }
         }
     });
     return(image);
 }
Beispiel #10
0
        /// <summary>
        ///     Updates the view bounds.
        /// </summary>
        private void UpdateViewBounds()
        {
            Vector2 tl = Vector2.Zero;
            Vector2 br = new Vector2(_renderControl.Width, _renderControl.Height);

            tl = Vector2.Transform(tl, InverseViewMatrix);
            br = Vector2.Transform(br, InverseViewMatrix);

            _bounds = Numerics.Rectangle.ContainingPoints(tl, br);
            if (!_layoutSuspended)
                ViewBoundsChanged?.Invoke(this, EventArgs.Empty);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Rectangle"/> class.
 /// </summary>
 /// <param name="color">The color.</param>
 /// <param name="fill">if set to <c>true</c> [fill].</param>
 /// <param name="bounds">The bounds.</param>
 public Rectangle(Color color, bool fill, Numerics.Rectangle bounds)
     : base(color)
 {
     Bounds = bounds;
     Fill   = fill;
 }
Beispiel #12
0
 public static RawRectangleF ToRawRectangleF(this Numerics.Rectangle rect)
 {
     return(new RawRectangleF(rect.Left, rect.Top, rect.Right, rect.Bottom));
 }
Beispiel #13
0
        /// <summary>
        /// Applies the filter to the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="targetLocation">The target location.</param>
        /// <returns>The image</returns>
        public unsafe Image Apply(Image image, Numerics.Rectangle targetLocation = default(Numerics.Rectangle))
        {
            targetLocation = targetLocation == default(Numerics.Rectangle) ? new Numerics.Rectangle(0, 0, image.Width, image.Height) : targetLocation.Clamp(image);
            var PointSize2 = PointSize * 2;
            var Copy       = new Color[image.Pixels.Length];

            Array.Copy(image.Pixels, Copy, Copy.Length);
            var EllipseDrawer = new Ellipse(Color.AliceBlue, true, PointSize, PointSize, new Vector2(0, 0));

            for (int y = targetLocation.Bottom; y < targetLocation.Top; y += PointSize2)
            {
                var MinY = (y - PointSize).Clamp(targetLocation.Bottom, targetLocation.Top - 1);
                var MaxY = (y + PointSize).Clamp(targetLocation.Bottom, targetLocation.Top - 1);
                fixed(Color *TargetPointer = &Copy[(y * image.Width) + targetLocation.Left])
                {
                    Color *TargetPointer2 = TargetPointer;

                    for (int x = targetLocation.Left; x < targetLocation.Right; x += PointSize2)
                    {
                        uint RValue       = 0;
                        uint GValue       = 0;
                        uint BValue       = 0;
                        var  MinX         = (x - PointSize).Clamp(targetLocation.Left, targetLocation.Right - 1);
                        var  MaxX         = (x + PointSize).Clamp(targetLocation.Left, targetLocation.Right - 1);
                        int  NumberPixels = 0;
                        for (int x2 = MinX; x2 < MaxX; ++x2)
                        {
                            for (int y2 = MinY; y2 < MaxY; ++y2)
                            {
                                var Offset = ((y * image.Width) + x);
                                RValue += Copy[Offset].Red;
                                GValue += Copy[Offset].Green;
                                BValue += Copy[Offset].Blue;
                                ++NumberPixels;
                            }
                        }
                        RValue /= (uint)NumberPixels;
                        GValue /= (uint)NumberPixels;
                        BValue /= (uint)NumberPixels;
                        EllipseDrawer.Center = new Vector2(x, y);
                        EllipseDrawer.Color  = new Color((byte)RValue, (byte)GValue, (byte)BValue);
                        EllipseDrawer.Apply(image, targetLocation);
                    }
                }
            }
            for (int y = targetLocation.Bottom + PointSize; y < targetLocation.Top; y += PointSize2)
            {
                var MinY = (y - PointSize).Clamp(targetLocation.Bottom, targetLocation.Top - 1);
                var MaxY = (y + PointSize).Clamp(targetLocation.Bottom, targetLocation.Top - 1);
                fixed(Color *TargetPointer = &Copy[(y *image.Width) + targetLocation.Left])
                {
                    Color *TargetPointer2 = TargetPointer;

                    for (int x = targetLocation.Left + PointSize; x < targetLocation.Right; x += PointSize2)
                    {
                        uint RValue       = 0;
                        uint GValue       = 0;
                        uint BValue       = 0;
                        var  MinX         = (x - PointSize).Clamp(targetLocation.Left, targetLocation.Right - 1);
                        var  MaxX         = (x + PointSize).Clamp(targetLocation.Left, targetLocation.Right - 1);
                        int  NumberPixels = 0;
                        for (int x2 = MinX; x2 < MaxX; ++x2)
                        {
                            for (int y2 = MinY; y2 < MaxY; ++y2)
                            {
                                var Offset = ((y * image.Width) + x);
                                RValue += Copy[Offset].Red;
                                GValue += Copy[Offset].Green;
                                BValue += Copy[Offset].Blue;
                                ++NumberPixels;
                            }
                        }
                        RValue /= (uint)NumberPixels;
                        GValue /= (uint)NumberPixels;
                        BValue /= (uint)NumberPixels;
                        EllipseDrawer.Center = new Vector2(x, y);
                        EllipseDrawer.Color  = new Color((byte)RValue, (byte)GValue, (byte)BValue);
                        EllipseDrawer.Apply(image, targetLocation);
                    }
                }
            }
            for (int y = targetLocation.Bottom; y < targetLocation.Top; y += PointSize2)
            {
                var TempY = y + new Random(y).Next(-PointSize, PointSize);
                var MinY  = (TempY - PointSize).Clamp(targetLocation.Bottom, targetLocation.Top - 1);
                var MaxY  = (TempY + PointSize).Clamp(targetLocation.Bottom, targetLocation.Top - 1);
                fixed(Color *TargetPointer = &Copy[(y *image.Width) + targetLocation.Left])
                {
                    Color *TargetPointer2 = TargetPointer;

                    for (int x = targetLocation.Left + PointSize; x < targetLocation.Right; x += PointSize2)
                    {
                        uint RValue       = 0;
                        uint GValue       = 0;
                        uint BValue       = 0;
                        var  TempX        = x + new Random(x).Next(-PointSize, PointSize);
                        var  MinX         = (TempX - PointSize).Clamp(targetLocation.Left, targetLocation.Right - 1);
                        var  MaxX         = (TempX + PointSize).Clamp(targetLocation.Left, targetLocation.Right - 1);
                        int  NumberPixels = 0;
                        for (int x2 = MinX; x2 < MaxX; ++x2)
                        {
                            for (int y2 = MinY; y2 < MaxY; ++y2)
                            {
                                var Offset = ((y * image.Width) + x);
                                RValue += Copy[Offset].Red;
                                GValue += Copy[Offset].Green;
                                BValue += Copy[Offset].Blue;
                                ++NumberPixels;
                            }
                        }
                        RValue /= (uint)NumberPixels;
                        GValue /= (uint)NumberPixels;
                        BValue /= (uint)NumberPixels;
                        EllipseDrawer.Center = new Vector2(TempX, TempY);
                        EllipseDrawer.Color  = new Color((byte)RValue, (byte)GValue, (byte)BValue);
                        EllipseDrawer.Apply(image, targetLocation);
                    }
                }
            }
            return(image);
        }
Beispiel #14
0
        /// <summary>
        /// Applies the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="targetLocation">The target location.</param>
        /// <returns></returns>
        public override Image Apply(Image image, Numerics.Rectangle targetLocation = default(Numerics.Rectangle))
        {
            targetLocation = targetLocation == default(Numerics.Rectangle) ? new Numerics.Rectangle(0, 0, image.Width, image.Height) : targetLocation.Clamp(image);
            var IsSteep = Math.Abs(Y2 - Y1) > Math.Abs(X2 - X1);

            if (IsSteep)
            {
                var Temp = X1;
                X1   = Y1;
                Y1   = Temp;
                Temp = X2;
                X2   = Y2;
                Y2   = Temp;
            }
            if (X1 > X2)
            {
                var Temp = X1;
                X1   = X2;
                X2   = Temp;
                Temp = Y1;
                Y1   = Y2;
                Y2   = Temp;
            }
            var   ChangeX  = X2 - X1;
            var   ChangeY  = Y2 - Y1;
            float Gradiant = ChangeY / (float)ChangeX;
            var   XEnd     = Round(X1);
            var   YEnd     = Y1 + Gradiant * (XEnd - X1);
            var   XGap     = RFPart(X1 + 0.5);
            var   XPixel1  = (int)XEnd;
            var   YPixel1  = (int)YEnd;

            if (IsSteep)
            {
                Plot(image, YPixel1, XPixel1, (float)(RFPart(YEnd) * XGap), targetLocation);
                Plot(image, YPixel1 + 1, XPixel1, (float)(FractionalPart(YEnd) * XGap), targetLocation);
            }
            else
            {
                Plot(image, XPixel1, YPixel1, (float)(RFPart(YEnd) * XGap), targetLocation);
                Plot(image, XPixel1, YPixel1 + 1, (float)(FractionalPart(YEnd) * XGap), targetLocation);
            }
            var Intery = YEnd + Gradiant;

            XEnd = Round(X2);
            YEnd = Y2 + Gradiant * (XEnd - X2);
            XGap = FractionalPart(X2 + 0.5);
            var XPixel2 = (int)XEnd;
            var YPixel2 = (int)YEnd;

            if (IsSteep)
            {
                Plot(image, YPixel2, XPixel2, (float)(RFPart(YEnd) * XGap), targetLocation);
                Plot(image, YPixel2 + 1, XPixel2, (float)(FractionalPart(YEnd) * XGap), targetLocation);
            }
            else
            {
                Plot(image, XPixel2, YPixel2, (float)(RFPart(YEnd) * XGap), targetLocation);
                Plot(image, XPixel2, YPixel2 + 1, (float)(FractionalPart(YEnd) * XGap), targetLocation);
            }
            if (IsSteep)
            {
                for (int x = XPixel1 + 1; x < XPixel2; ++x)
                {
                    Plot(image, (int)Intery, x, (float)RFPart(Intery), targetLocation);
                    Plot(image, (int)Intery + 1, x, (float)FractionalPart(Intery), targetLocation);
                    Intery = Intery + Gradiant;
                }
            }
            else
            {
                for (int x = XPixel1 + 1; x < XPixel2; ++x)
                {
                    Plot(image, x, (int)Intery, (float)RFPart(Intery), targetLocation);
                    Plot(image, x, (int)Intery + 1, (float)FractionalPart(Intery), targetLocation);
                    Intery = Intery + Gradiant;
                }
            }
            return(image);
        }
 /// <summary>
 /// Applies the shape to the specified image.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="targetLocation">The target location.</param>
 /// <returns>The resulting image</returns>
 public abstract Image Apply(Image image, Numerics.Rectangle targetLocation = default(Numerics.Rectangle));