Exemplo n.º 1
0
        public override void Draw(Painter p)
        {
            //create painter
            p.SetClipBox(0, 0, Width, Height);
            p.Clear(Drawing.Color.White);
            _testSprite.Render(p);
            _testSprite.GetElementBounds(out float b_left, out float b_top, out float b_right, out float b_bottom);

            //-----------------------------------------------------------------------------


            if (FilterMethod == FilterMethod.None)
            {
                return;
            }

            RectInt boundRect = new RectInt((int)b_left, (int)b_bottom, (int)b_right, (int)b_top);
            int     m_radius  = this.BlurRadius;

            //expand bound rect
            boundRect.Left   -= m_radius;
            boundRect.Bottom -= m_radius;
            boundRect.Right  += m_radius;
            boundRect.Top    += m_radius;
            // Create a new pixel renderer and attach it to the main one as a child image.
            // It returns true if the attachment succeeded. It fails if the rectangle
            // (bbox) is fully clipped.
            //------------------
            //create filter specfication
            //it will be resolve later by the platform similar to request font
            //------------------
            if (boundRect.Clip(new RectInt(0, 0, p.Width - 1, p.Height - 1)))
            {
                //check if intersect
                var prevClip = p.ClipBox;
                p.ClipBox = boundRect;
                // Blur it

                IImageFilter selectedFilter = null;
                switch (FilterMethod)
                {
                case FilterMethod.Sharpen:

                    selectedFilter = _fxSharpen;

                    break;

                case FilterMethod.StackBlur:

                    //------------------
                    // Faster, but bore specific.
                    // Works only for 8 bits per channel and only with radii <= 254.
                    //------------------
                    selectedFilter = _fxBlurStack;
                    break;

                case FilterMethod.Emboss:
                    selectedFilter = _fxEmboss;
                    break;

                case FilterMethod.EdgeDetection:
                    selectedFilter = _fxEdgeDetection;
                    break;

                case FilterMethod.OilPaint:
                    selectedFilter = _oilPaintFilter;
                    break;

                case FilterMethod.PencilSketch:
                    selectedFilter = _pencilSketch;
                    break;

                case FilterMethod.AutoLevel:
                    selectedFilter = _autoLevel;
                    break;

                default:
                {           // True Gaussian Blur, 3-5 times slower than Stack Blur,
                            // but still constant time of radius. Very sensitive
                            // to precision, doubles are must here.
                            //------------------
                }
                break;
                }

                if (selectedFilter != null)
                {
                    _sw.Reset();
                    _sw.Start();

                    p.ApplyFilter(selectedFilter);

                    _sw.Stop();


                    System.Diagnostics.Debug.WriteLine(_sw.ElapsedMilliseconds);
                }

                //store back
                p.ClipBox = prevClip;
            }


            p.FillColor = Drawing.Color.FromArgb(0.8f, 0.6f, 0.9f, 0.7f);
            // Render the shape itself
            ////------------------
            //if (FlattenCurveChecked)
            //{
            //    //m_ras.AddPath(m_path_2);
            //    p.Fill(m_path_2);
            //}
            //else
            //{
            //    //m_ras.AddPath(m_pathVxs);
            //    p.Fill(m_pathVxs);
            //}

            p.FillColor = Drawing.Color.Black;
            //p.DrawString(string.Format("{0:F2} ms", tm), 140, 30);
            //-------------------------------------------------------------
            //control
            //m_shadow_ctrl.OnDraw(p);
        }
Exemplo n.º 2
0
        public override void Draw(Painter p)
        {
            //create painter
            p.SetClipBox(0, 0, Width, Height);
            p.Clear(Drawing.Color.White);
            //-----------------------------------------------------------------------
            //green glyph
            RectD r             = m_shape_bounds;
            var   txPerspective = new Perspective(
                r.Left, r.Bottom, r.Right, r.Top,
                m_shadow_ctrl.GetInnerCoords());
            VertexStore s2 = this.m_pathVxs2;

            //if (FlattenCurveChecked)
            //{
            //    //s2 = shadow_persp.TransformToVxs(m_path_2);
            //    s2 = shadow_persp.TransformToVxs(m_pathVxs2);
            //}
            //else
            //{
            //    s2 = shadow_persp.TransformToVxs(m_pathVxs);
            //}
            p.FillColor = ColorEx.Make(0.2f, 0.3f, 0f);
            p.Fill(s2);
            //---------------------------------------------------------------------------------------------------------
            //shadow
            //---------------------------------------------------------------------------------------------------------
            // Calculate the bounding box and extend it by the blur radius

            RectInt boundRect = BoundingRectInt.GetBoundingRect(s2);
            int     m_radius  = this.BlurRadius;

            //expand bound rect
            boundRect.Left   -= m_radius;
            boundRect.Bottom -= m_radius;
            boundRect.Right  += m_radius;
            boundRect.Top    += m_radius;
            if (BlurMethod == BlurMethod.RecursiveBlur)
            {
                // The recursive blur method represents the true Gaussian Blur,
                // with theoretically infinite kernel. The restricted window size
                // results in extra influence of edge pixels. It's impossible to
                // solve correctly, but extending the right and top areas to another
                // radius value produces fair result.
                //------------------
                boundRect.Right += m_radius;
                boundRect.Top   += m_radius;
            }

            stopwatch.Stop();
            stopwatch.Reset();
            stopwatch.Start();

            if (BlurMethod != BlurMethod.ChannelBlur)
            {
                // Create a new pixel renderer and attach it to the main one as a child image.
                // It returns true if the attachment succeeded. It fails if the rectangle
                // (bbox) is fully clipped.
                //------------------



                //------------------
                //create filter specfication
                //it will be resolve later by the platform similar to request font
                //------------------


                if (boundRect.Clip(new RectInt(0, 0, p.Width - 1, p.Height - 1)))
                {
                    //check if intersect
                    var prevClip = p.ClipBox;
                    p.ClipBox = boundRect;
                    // Blur it
                    switch (BlurMethod)
                    {
                    case BlurMethod.StackBlur:
                    {
                        //------------------
                        // Faster, but bore specific.
                        // Works only for 8 bits per channel and only with radii <= 254.
                        //------------------
                        //p.DoFilterBlurStack(boundRect, m_radius);
                        p.ApplyFilter(imgFilterBlurStack);
                    }
                    break;

                    default:
                    {           // True Gaussian Blur, 3-5 times slower than Stack Blur,
                                // but still constant time of radius. Very sensitive
                                // to precision, doubles are must here.
                                //------------------
                        p.ApplyFilter(imgFilterGaussianBlur);
                    }
                    break;
                    }
                    //store back
                    p.ClipBox = prevClip;
                }
            }

            double tm = stopwatch.ElapsedMilliseconds;

            p.FillColor = Drawing.Color.FromArgb(0.8f, 0.6f, 0.9f, 0.7f);
            // Render the shape itself
            ////------------------
            //if (FlattenCurveChecked)
            //{
            //    //m_ras.AddPath(m_path_2);
            //    p.Fill(m_path_2);
            //}
            //else
            //{
            //    //m_ras.AddPath(m_pathVxs);
            //    p.Fill(m_pathVxs);
            //}

            p.FillColor = Drawing.Color.Black;
            //p.DrawString(string.Format("{0:F2} ms", tm), 140, 30);
            //-------------------------------------------------------------
            //control
            //m_shadow_ctrl.OnDraw(p);
        }