Ejemplo n.º 1
0
        private void undoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DynamicShadingCPU temp = ds;

            ds     = dsPrev;
            dsPrev = temp;

            beginRenderToolStripMenuItem_Click(sender, e);
        }
        /// <summary>Clones this object</summary>
        public DynamicShadingCPU Clone()
        {
            List <int> newEdges = new List <int>();

            foreach (int k in this._edges)
            {
                newEdges.Add(k);
            }
            DynamicShadingCPU ans = new DynamicShadingCPU(newEdges, ImageWidth, ImageHeight);

            foreach (ColorStroke cs in this._strokes)
            {
                ans._strokes.Add(cs.Clone());
            }

            return(ans);
        }
Ejemplo n.º 3
0
        private void frmDynShading_Load(object sender, EventArgs e)
        {
            string[] sLic = lblLicData.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            SoftwareKey.lblNotRegisteredTxt = sLic[1];
            SoftwareKey.lblFindLicenseTxt   = sLic[0];

            //check license
            //SoftwareKey.CheckLicense("", false);

            int      n    = 300;
            Bitmap   bmp0 = new Bitmap(n, n);
            Graphics g    = Graphics.FromImage(bmp0);

            g.FillRectangle(Brushes.White, 0, 0, n, n);
            ds = new DynamicShadingCPU(new List <int>(), n, n);

            picShadeImg.Image = bmp0;
            frmpalette.Show();
        }
Ejemplo n.º 4
0
        private void stepbystepRenderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            swRender.Reset();

            lblStatus.Text = "Start rendering at" + DateTime.Now.ToString();
            Application.DoEvents();

            //if (!bgWorker.IsBusy) bgWorker.RunWorkerAsync();

            //bgWorker_DoWork(sender, new DoWorkEventArgs(0));

            //else lblStatus.Text = "Already rendering";

            swRender.Start();

            //compute distance maps if necessary
            for (int j = 0; j < ds._strokes.Count; j++)
            {
                lblStatus.Text = "Stroke " + (1 + j).ToString() + " of " + ds._strokes.Count.ToString();
                Application.DoEvents();

                DynamicShadingCPU.ColorStroke cs = ds._strokes[j];
                if (cs.DistanceMap == null)
                {
                    cs.DistanceMap = DynamicShadingCPU.GetPixelDistances(cs.StrokeCoords, ds._edges, ds.ImageWidth, ds.ImageHeight, ds.MAXITER);
                }

                picShadeImg.Image = ds.ComposeImage();
                picShadeImg.Invalidate();
            }


            bmpComposed = ds.ComposeImage();

            swRender.Stop();
            rendered = true;

            picShadeImg.Image = bmpComposed;
            picShadeImg.Invalidate();
            lblStatus.Text = "Done rendering " + swRender.Elapsed.ToString();
        }
Ejemplo n.º 5
0
        private void doOpenFile(bool tryReadStrokes, bool removeColors)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Images|*.jpg;*.bmp;*.png;*.jpeg";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Bitmap bmpSrc = new Bitmap(ofd.FileName);
                curFile = ofd.FileName;

                //DynamicShadingCPU.EqualizeHistogram(bmpSrc);

                #region base64 example
                //MemoryStream stream = new MemoryStream();
                //bmpSrc.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                //byte[] imageBytes = stream.ToArray();

                //// Convert byte[] to Base64 String
                //string base64String = Convert.ToBase64String(imageBytes);

                //byte[] b2 = Convert.FromBase64String(base64String);
                //MemoryStream ms2 = new MemoryStream(b2);
                //bmpSrc = new Bitmap(ms2);
                #endregion

                if (removeColors)
                {
                    DynamicShadingCPU.RemoveColors(bmpSrc, 33);
                }

                List <DynamicShadingCPU.ColorStroke> strokes = null;
                if (tryReadStrokes)
                {
                    strokes = DynamicShadingCPU.GetColorStrokes(bmpSrc, 33);
                }

                float      thresh = DynamicShadingCPU.getOtsuThreshold(bmpSrc);
                List <int> edges  = DynamicShadingCPU.RetrieveImageEdges(bmpSrc, thresh);

                lblStatus.Text = "Otsu threshold: " + thresh.ToString();

                picShadeImg.Image = DynamicShadingCPU.RetrieveImageFromEdges(edges, bmpSrc.Width, bmpSrc.Height);

                ds = new DynamicShadingCPU(edges, bmpSrc.Width, bmpSrc.Height);

                if (File.Exists(ofd.FileName + ".json"))
                {
                    ds = DynamicShadingCPU.FromJson(ofd.FileName + ".json");
                }
                else if (File.Exists(ofd.FileName + ".strokes"))
                {
                    ds.LoadStrokes(ofd.FileName + ".strokes");
                }
                else if (tryReadStrokes)
                {
                    ds._strokes = strokes;
                }

                picShadeImg.Invalidate();
            }
        }
Ejemplo n.º 6
0
 private void revertToOriginalToolStripMenuItem_Click(object sender, EventArgs e)
 {
     picShadeImg.Image = DynamicShadingCPU.RetrieveImageFromEdges(ds._edges, ds.ImageWidth, ds.ImageHeight);
     picShadeImg.Invalidate();
 }