Exemplo n.º 1
0
 public bool SetClippingBox(int x1, int y1, int x2, int y2)
 {
     RectInt cb = new RectInt(x1, y1, x2, y2);
     cb.Normalize();
     if (cb.Clip(new RectInt(0, 0, (int)Width - 1, (int)Height - 1)))
     {
         m_ClippingRect = cb;
         return true;
     }
     m_ClippingRect.Left = 1;
     m_ClippingRect.Bottom = 1;
     m_ClippingRect.Right = 0;
     m_ClippingRect.Top = 0;
     return false;
 }
Exemplo n.º 2
0
 //--------------------------------------------------------------------
 //public IPixelFormat ren() { return m_ren; }
   
 //--------------------------------------------------------------------
 public bool SetClippingBox(int x1, int y1, int x2, int y2)
 {
     RectInt cb = new RectInt(x1, y1, x2, y2);
     cb.Normalize();
     if (cb.Clip(new RectInt(0, 0, (int)Width - 1, (int)Height - 1)))
     {
         m_clip_box = cb;
         return true;
     }
     m_clip_box.X1 = 1;
     m_clip_box.Y1 = 1;
     m_clip_box.X2 = 0;
     m_clip_box.Y2 = 0;
     return false;
 }
Exemplo n.º 3
0
        public bool SetClippingBox(int x1, int y1, int x2, int y2)
        {
            RectInt cb = new RectInt(x1, y1, x2, y2);

            cb.Normalize();
            if (cb.Clip(new RectInt(0, 0, (int)Width - 1, (int)Height - 1)))
            {
                m_ClippingRect = cb;
                return(true);
            }
            m_ClippingRect.Left   = 1;
            m_ClippingRect.Bottom = 1;
            m_ClippingRect.Right  = 0;
            m_ClippingRect.Top    = 0;
            return(false);
        }
Exemplo n.º 4
0
        //--------------------------------------------------------------------
        //public IPixelFormat ren() { return m_ren; }

        //--------------------------------------------------------------------
        public bool SetClippingBox(int x1, int y1, int x2, int y2)
        {
            RectInt cb = new RectInt(x1, y1, x2, y2);

            cb.Normalize();
            if (cb.Clip(new RectInt(0, 0, (int)Width - 1, (int)Height - 1)))
            {
                m_clip_box = cb;
                return(true);
            }
            m_clip_box.X1 = 1;
            m_clip_box.Y1 = 1;
            m_clip_box.X2 = 0;
            m_clip_box.Y2 = 0;
            return(false);
        }
Exemplo n.º 5
0
        bool Attach(IImageReaderWriter sourceImage, int x1, int y1, int x2, int y2)
        {
            m_ByteBuffer = null;
            if (x1 > x2 || y1 > y2)
            {
                throw new Exception("You need to have your x1 and y1 be the lower left corner of your sub image.");
            }
            RectInt boundsRect = new RectInt(x1, y1, x2, y2);

            if (boundsRect.Clip(new RectInt(0, 0, (int)sourceImage.Width - 1, (int)sourceImage.Height - 1)))
            {
                SetDimmensionAndFormat(boundsRect.Width, boundsRect.Height, sourceImage.Stride, sourceImage.BitDepth, sourceImage.BytesBetweenPixelsInclusive);
                int    bufferOffset = sourceImage.GetBufferOffsetXY(boundsRect.Left, boundsRect.Bottom);
                byte[] buffer       = sourceImage.GetBuffer();
                SetBuffer(buffer, bufferOffset);
                return(true);
            }

            return(false);
        }
Exemplo n.º 6
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.º 7
0
 public bool Attach(IPixelFormat pixf, int x1, int y1, int x2, int y2)
 {
     RectInt r = new RectInt(x1, y1, x2, y2);
     if (r.Clip(new RectInt(0, 0, (int)pixf.Width - 1, (int)pixf.Height - 1)))
     {
         int stride = pixf.Stride;
         unsafe
         {
             m_rbuf.attach(pixf.PixPtr(r.X1, stride < 0 ? r.Y2 : r.Y1),
                 (uint)(r.X2 - r.X1) + 1,
                 (uint)(r.Y2 - r.Y1) + 1,
                 stride, 3);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 8
0
        public override void Draw(CanvasPainter p)
        {
            //create painter
            p.SetClipBox(0, 0, Width, Height);
            p.Clear(Drawing.Color.White);
            //-----------------------------------------------------------------------
            //green glyph
            Perspective shadow_persp = new Perspective(
                m_shape_bounds,
                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 = PixelFarm.Drawing.Color.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.
                //------------------

                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.DoFilterBlurStack(new RectInt(0, 0, Width, Height), m_radius);
                    }
                    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.DoFilterBlurRecursive(boundRect, m_radius);
                    }
                    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);
        }
Exemplo n.º 9
0
        bool Attach(IImageReaderWriter sourceImage, int x1, int y1, int x2, int y2)
        {
            m_ByteBuffer = null;
            if (x1 > x2 || y1 > y2)
            {
                throw new Exception("You need to have your x1 and y1 be the lower left corner of your sub image.");
            }
            RectInt boundsRect = new RectInt(x1, y1, x2, y2);
            if (boundsRect.Clip(new RectInt(0, 0, (int)sourceImage.Width - 1, (int)sourceImage.Height - 1)))
            {
                SetDimmensionAndFormat(boundsRect.Width, boundsRect.Height, sourceImage.Stride, sourceImage.BitDepth, sourceImage.BytesBetweenPixelsInclusive);
                int bufferOffset = sourceImage.GetBufferOffsetXY(boundsRect.Left, boundsRect.Bottom);
                byte[] buffer = sourceImage.GetBuffer();
                SetBuffer(buffer, bufferOffset);
                return true;
            }

            return false;
        }