Ejemplo n.º 1
0
        public static void Draw(this Engine.Effects.Particles.ForceParticle fp, Engine.Surface.Canvas c, Engine.Color.Cell color)
        {
            // TODO a strange case where position is way out of bounds which causes LinearInterpolation to build a list that
            // has so many items that it reaches "out of bounds (int)"
            // this problem may have disappeared since I changed to Engine.Calc.Vector
            if (double.IsNaN(fp.Position.X) || double.IsNaN(fp.Position.Y))
            {
                return;
            }

            // draw a line between last position and current position
            List <MousePoint> points = Engine.Calc.Math.LinearInterpolate(new MousePoint(fp.PreviousPoint.X, fp.PreviousPoint.Y),
                                                                          new MousePoint((int)fp.Position.X, (int)fp.Position.Y));

            foreach (MousePoint p in points)
            {
                int x = p.X;
                int y = p.Y;

                if (c.IsOutOfBounds(x, y))
                {
                    return;
                }

                Engine.Color.Cell bg = c.GetPixel(x, y, Surface.PixelRetrievalOptions.ReturnEdgePixel);

                c.SetPixel(Engine.Calc.Color.FastAlphaBlend(color, bg), x, y, Surface.PixelSetOptions.Ignore);
            }
        }
Ejemplo n.º 2
0
        public override void Process()
        {
            t_imageProcessed = Engine.Surface.Ops.Copy(t_imageSource);
            t_imagePerlin    = new Engine.Surface.Canvas(t_imageSource.Width, t_imageSource.Height);

            t_workflow.ThreadingQueue.RunAndForget(new Action(ThreadedProcess));
        }
Ejemplo n.º 3
0
        public void HandleDoubleClick(object sender, Engine.Utilities.Selection.SelectionEventArgs e)
        {
            if (t_hasErrors)
            {
                return;
            }

            if (String.IsNullOrEmpty(Folder))
            {
                // TODO : validation code and message back to UI
                return;
            }

            Engine.Rectangle      r = new Rectangle(e.Rectangle.Location.X, e.Rectangle.Location.Y, e.Rectangle.Width, e.Rectangle.Height);
            Engine.Surface.Canvas c = Engine.Surface.Ops.CopyFromImage(this.t_imageSource, r);

            string fileName = BuildFileName();

            // check file exists, if so, repeat and increase sequence until file does not exist
            while (Engine.Utilities.SFO.FileExists(fileName))
            {
                fileName = BuildFileName();
            }

            Engine.Surface.Ops.Save(c, fileName, Surface.ImageFileFormats.PNG);
        }
Ejemplo n.º 4
0
        private void CreatePlaneImage(Engine.Color.Cell c)
        {
            Engine.Surface.ColorPickerPlane cpp = new Engine.Surface.ColorPickerPlane((int)this.Width, (int)this.Height);
            cpp.SetColors(new Engine.Color.Cell(255, 255, 255, 255), c, new Engine.Color.Cell(0, 0, 0, 255), new Engine.Color.Cell(0, 0, 0, 255));

            t_currentPlaneImage = cpp.Canvas;
        }
Ejemplo n.º 5
0
        public static Bitmap ToBitmap(Engine.Surface.Canvas canvas)
        {
            Bitmap bmp = new Bitmap(canvas.Width, canvas.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            try
            {
                System.Drawing.Rectangle          rect    = new System.Drawing.Rectangle(0, 0, canvas.Width, canvas.Height);
                System.Drawing.Imaging.BitmapData bmpData =
                    bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
                                 bmp.PixelFormat);

                // Get the address of the first line.
                IntPtr ptr = bmpData.Scan0;

                // Copy the BGRA values into the array.
                System.Runtime.InteropServices.Marshal.Copy(canvas.Array, 0, ptr, canvas.Array.Length);

                // Unlock the bits. VERY IMPORTANT
                bmp.UnlockBits(bmpData);
            }
            catch (AccessViolationException e)
            {
                MessageBox.Show(e.Message + "\\nAn empty image is provided instead.");
            }
            finally
            {
                ;
            }

            return(bmp);
        }
        public ColorPlaneSelectionGlass(Engine.Surface.Canvas colorPlane)
        {
            InitializeComponent();

            t_colorPlane = colorPlane;

            t_cursorLocation = new Point(0, 0);

            t_cursor                     = new Ellipse();
            t_cursor.Stroke              = System.Windows.Media.Brushes.Gray;
            t_cursor.Fill                = System.Windows.Media.Brushes.Transparent;
            t_cursor.Width               = 10;
            t_cursor.Height              = 10;
            t_cursor.StrokeThickness     = 2;
            t_cursor.HorizontalAlignment = HorizontalAlignment.Left;
            t_cursor.VerticalAlignment   = VerticalAlignment.Top;
            Thickness t = new Thickness();

            t.Left          = 0;
            t.Top           = 0;
            t_cursor.Margin = t;

            t_cursor.MouseDown += T_cursor_MouseDown;
            t_cursor.MouseMove += T_cursor_MouseMove;
            t_cursor.MouseUp   += T_cursor_MouseUp;

            this.Glass.Children.Add(t_cursor);
        }
Ejemplo n.º 7
0
        public override void Initialize(Engine.Workflow w)
        {
            base.Initialize(w);

            t_imagePerlin = Engine.Effects.Code.Noise.NoiseFactory_Static.CreatePerlinNoisePlane(t_imageSource, t_frequency, t_seed, t_octaves);

            CreateFlowField();
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <param name="forceRefresh">Forces the UI to refresh the visual</param>
        private void ChangeImage(Engine.Surface.Canvas image, bool forceRefresh)
        {
            OnDrawingBoardActionRequested(WorkflowDrawingBoardRequestType.ViewPortSize);

            if (forceRefresh)
            {
                OnDrawingBoardActionRequested(WorkflowDrawingBoardRequestType.Invalidate);
            }
        }
Ejemplo n.º 9
0
        private void ThreadedProcess()
        {
            t_imagePerlin = Engine.Effects.Code.Noise.NoiseFactory_Static.CreatePerlinNoisePlane(t_imageSource, t_frequency, t_seed, t_octaves);
            CreateFlowField();

            t_workflow.AllowInvalidate = true;
            Flow();

            base.PostProcess();
        }
Ejemplo n.º 10
0
        private void ThreadedProcess()
        {
            t_imagePerlin = Engine.Effects.Code.Noise.NoiseFactory_Static.CreatePerlinNoisePlane(t_imageSource, t_frequency, t_seed, t_octaves);
            CreateFlowField();

            // call this as late as possible, just before actual effect processing
            t_workflow.AllowInvalidate = true;
            Flow();

            base.PostProcess();
        }
Ejemplo n.º 11
0
 void IAttribute.SetValue(object val)
 {
     if (val.GetType() == typeof(Engine.Surface.Canvas))
     {
         t_image = (Engine.Surface.Canvas)val;
     }
     else
     {
         throw new InvalidCastException();
     }
 }
Ejemplo n.º 12
0
        public PressureGrid(Engine.Surface.Canvas c, int gridCellWidth, int gridCellHeight, bool invertLuminance)
        {
            t_imageSource = c;

            t_gridCellWidth  = gridCellWidth;
            t_gridCellHeight = gridCellHeight;

            t_flowField = new Effects.Particles.FlowField(t_imageSource, invertLuminance);

            SetGrid();
        }
Ejemplo n.º 13
0
        public static void DrawLine(Engine.Surface.Canvas canvas, Point start, Point end, Engine.Color.Cell color)
        {
            Engine.MousePoint pStart = new MousePoint(start.X, start.Y, MouseActionType.Undefined);
            Engine.MousePoint pEnd   = new MousePoint(end.X, end.Y, MouseActionType.Undefined);
            List <MousePoint> lst    = Engine.Calc.Math.LinearInterpolate(pStart, pEnd);

            foreach (MousePoint p in lst)
            {
                canvas.SetPixel(color, p.X, p.Y, Surface.PixelSetOptions.Ignore);
            }
        }
Ejemplo n.º 14
0
        public static void Save(Engine.Surface.Canvas canvas, string fileName, Engine.Surface.ImageFileFormats format)
        {
            if (format == ImageFileFormats.Undefined)
            {
                throw new ArgumentOutOfRangeException(String.Format("In Engine.Surface.Ops.Save(), the '{0}' is not supported.", format.ToString()));
            }

            using (MagickImage image = new MagickImage(Engine.Surface.Ops.ToBitmap(canvas)))
            {
                image.Format = MagickFormat.Png;
                image.Write(fileName);
            }
        }
Ejemplo n.º 15
0
        public static Engine.Surface.Canvas Blur(Engine.Surface.Canvas c, double radius, double sigma)
        {
            Bitmap bmp = Engine.Surface.Ops.ToBitmap(c);

            using (ImageMagick.MagickImage image = new ImageMagick.MagickImage(bmp))
            {
                image.Blur(radius, sigma);

                bmp = image.ToBitmap();
            }

            return(Engine.Surface.Ops.ToCanvas(bmp));
        }
Ejemplo n.º 16
0
 public void FillFluid(Engine.Surface.Canvas c)
 {
     for (int y = 0; y < c.Height; y++)
     {
         for (int x = 0; x < c.Width; x++)
         {
             Engine.Color.Cell pix = c.GetPixel(x, y, Surface.PixelRetrievalOptions.ReturnEdgePixel);
             double            lum = (double)Engine.Calc.Color.Luminance(pix);
             int offset            = CellOffset(x, y, c.Width);
             mp_p0[offset]  = lum; // lum /255;
             mp_xv0[offset] = lum;
             mp_yv0[offset] = lum;
         }
     }
 }
Ejemplo n.º 17
0
 private static void thread_CopyFromImage(Engine.Surface.Canvas source, Engine.Surface.Canvas dest, int originX, int originY, int destX, int destY, int width, int height)
 {
     for (int y = destY; y < height; y++)
     {
         int offset         = source.GetOffset(originX, originY + y);
         int offsetNewImage = dest.GetOffset(destX, y);
         for (int x = destX; x < width; x++)
         {
             Engine.Color.Cell c = new Color.Cell(source.Array, offset);
             c.WriteBytes(dest.Array, offsetNewImage);
             offset         += Engine.BytesPerPixel.BGRA;
             offsetNewImage += Engine.BytesPerPixel.BGRA;
         }
     }
 }
Ejemplo n.º 18
0
        public static Engine.Surface.Canvas ToCanvas(Bitmap b)
        {
            byte[] imageData;

            using (MagickImage image = new MagickImage(b))
            {
                imageData = image.ToByteArray(MagickFormat.Bgra);

                /*imageData = new int[bytes.Length / sizeof(int)];
                 * Buffer.BlockCopy(bytes, 0, imageData, 0, bytes.Length);*/
            }

            Engine.Surface.Canvas canvas = new Engine.Surface.Canvas(imageData, b.Width, b.Height);

            return(canvas);
        }
Ejemplo n.º 19
0
        private System.Windows.Media.Imaging.BitmapSource MakeImage(Engine.Surface.Canvas c)
        {
            // TODO just get the updated portion of the image to be displayed here
            BitmapSource bmpSource = BitmapSource.Create(c.Width,
                                                         c.Height,
                                                         96,
                                                         96,
                                                         PixelFormats.Bgra32,
                                                         null,
                                                         c.Array,
                                                         c.Stride);

            // TODO see also https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.imaging.writeablebitmap?view=netframework-4.7.2
            // where there is an example to use System.Windows.Media.Imaging.WriteableBitmap, one that is an array of int
            // that can be manipulated. web link also saved in bmp_creator/improving surface code

            return(bmpSource);
        }
Ejemplo n.º 20
0
        public static unsafe Engine.Surface.Canvas Copy(Engine.Surface.Canvas source)
        {
            Engine.Surface.Canvas copy = new Canvas(source.Width, source.Height);

            fixed(byte *pSource = source.Array, pCopy = copy.Array)
            {
                byte *ps = pSource;
                byte *pc = pCopy;

                for (int i = 0; i < source.Array.Length; i++)
                {
                    *pc = *ps;
                    pc++;
                    ps++;
                }
            }

            return(copy);
        }
Ejemplo n.º 21
0
        public Engine.Surface.Canvas GetVectorFieldSketch()
        {
            t_vectorFieldSketch = new Surface.Canvas(Width, Height, Engine.Colors.White);

            for (int x = 0; x < t_cells.GetLength(0); x++)
            {
                for (int y = 0; y < t_cells.GetLength(1); y++)
                {
                    PressureGridCell   gc     = t_cells[x, y];
                    Engine.Point       pStart = new Point((x * gc.Width) - (gc.Width / 2), (y * gc.Height) - (gc.Height / 2));
                    Engine.Calc.Vector shortV = new Calc.Vector(0, 0);
                    shortV += gc.Pressure;
                    shortV.SetMagnitude(gc.Width / 2);
                    Engine.Point pEnd = new Point(pStart.X + (int)shortV.X, pStart.Y + (int)shortV.Y);
                    Engine.Tools.Drawing.DrawLine(t_vectorFieldSketch, pStart, pEnd, Engine.Colors.Black);
                }
            }

            return(t_vectorFieldSketch);
        }
Ejemplo n.º 22
0
        private void CreateFaderImage()
        {
            t_faderImage = new Engine.Surface.Canvas((int)this.Width - 10, (int)this.Height - 10); //, new Engine.Color.Cell(100, 100, 100, 255));

            t_range = Engine.Calc.Color.GenerateLinearGradient(new Engine.Color.Models.HSV(0, 1.0, 1.0), new Engine.Color.Models.HSV(1.0, 1.0, 1.0), t_faderImage.Height);

            int offset = 0;

            for (int y = 0; y < t_faderImage.Height; y++)
            {
                System.Drawing.Color c    = t_range[y].ToRGB().ToArgb();
                Engine.Color.Cell    cell = new Engine.Color.Cell(c);

                for (int x = 0; x < t_faderImage.Width; x++)
                {
                    cell.WriteBytes(t_faderImage.Array, offset);
                    offset += Engine.BytesPerPixel.BGRA;
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Draws a filled circle at the specified coordinates using the specified color.
        /// </summary>
        /// <param name="canvas">the target image onto which to draw a circle</param>
        /// <param name="position">where on the target image the center of the cicle is to be located.</param>
        /// <param name="size">the diameter of the circle to draw</param>
        /// <param name="color">the color of the circle line</param>
        /// <remarks>Implements the Bresenham's circle argorithm, most of the code found at : https://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm#C.23 </remarks>
        public static void DrawCircle(Engine.Surface.Canvas canvas, Engine.Calc.Vector position, int size, Engine.Color.Cell color)
        {
            int centerX = (int)System.Math.Round(position.X);
            int centerY = (int)System.Math.Round(position.Y);

            int radius = (int)System.Math.Round((double)size / 2);

            int d = (5 - radius * 4) / 4;
            int x = 0;
            int y = radius;

            do
            {
                // ensure index is in range before setting (depends on your image implementation)
                // in this case we check if the pixel location is within the bounds of the image before setting the pixel

                canvas.SetPixel(color, centerX + x, centerY + y, Surface.PixelSetOptions.Ignore);
                canvas.SetPixel(color, centerX + x, centerY - y, Surface.PixelSetOptions.Ignore);
                canvas.SetPixel(color, centerX - x, centerY + y, Surface.PixelSetOptions.Ignore);
                canvas.SetPixel(color, centerX - x, centerY - y, Surface.PixelSetOptions.Ignore);
                canvas.SetPixel(color, centerX + y, centerY + x, Surface.PixelSetOptions.Ignore);
                canvas.SetPixel(color, centerX + y, centerY - x, Surface.PixelSetOptions.Ignore);
                canvas.SetPixel(color, centerX - y, centerY + x, Surface.PixelSetOptions.Ignore);
                canvas.SetPixel(color, centerX - y, centerY - x, Surface.PixelSetOptions.Ignore);

                if (d < 0)
                {
                    d += 2 * x + 1;
                }
                else
                {
                    d += 2 * (x - y) + 1;
                    y--;
                }
                x++;
            } while (x <= y);
        }
Ejemplo n.º 24
0
 public ImageAttribute(Engine.Surface.Canvas img)
 {
     t_image = img;
 }
Ejemplo n.º 25
0
 public ColorPickerPlane(int width, int height)
 {
     t_plane = new Engine.Surface.Canvas(width, height);
 }
Ejemplo n.º 26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="c">The main image of the current worflow process to be displayed on the PaintualCanvas within
 /// the DrawingBoard (UI)</param>
 public void SetCanvas(Engine.Surface.Canvas c)
 {
     t_canvas = c;
     CoordinatesManager.SetImageSize(c.Width, c.Height);
 }
Ejemplo n.º 27
0
        public void SetColors(Engine.Color.Cell upperLeft, Engine.Color.Cell upperRight, Engine.Color.Cell lowerLeft, Engine.Color.Cell lowerRight)
        {
            int[,] plane = Engine.Calc.Color.GenerateQuadGradient(upperLeft, upperRight, lowerLeft, lowerRight, Width, Height);

            t_plane = Engine.Surface.Ops.ToCanvas(plane, Width, Height);
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Called by EffectBase when updating Canvas (t_imageSource in GraphicActivity) with the modified t_imageProcessed
 /// </summary>
 /// <param name="c"></param>
 /// <param name="forceRefresh"></param>
 internal void UpdateImage(Engine.Surface.Canvas c, bool forceRefresh)
 {
     SetCanvas(c);
     ChangeImage(c, forceRefresh);
 }
Ejemplo n.º 29
0
        private BitmapSource ConvertPlaneImage(Engine.Surface.Canvas canvas)
        {
            BitmapSource bmpSource = BitmapSource.Create(canvas.Width, canvas.Height, 96, 96, PixelFormats.Bgra32, null, canvas.Array, canvas.Stride);

            return(bmpSource);
        }
Ejemplo n.º 30
0
 public void Draw(Engine.Surface.Canvas c)
 {
     Engine.Color.Cell source = c.GetPixel((int)t_position.X, (int)t_position.Y, Surface.PixelRetrievalOptions.ReturnEdgePixel);
     Engine.Color.Cell dest   = Engine.Calc.Color.FastAlphaBlend(t_cell, source);
     c.SetPixel(dest, (int)t_position.X, (int)t_position.Y, Surface.PixelSetOptions.Ignore);
 }