Esempio n. 1
0
        void generate_alpha_mask(ScanlineRasToDestBitmapRenderer sclineRasToBmp, ScanlinePacked8 sclnPack, ScanlineRasterizer rasterizer, int width, int height)
        {
            alphaBitmap = new ActualImage(width, height, PixelFormat.GrayScale8);

            var bmpReaderWrtier = new MyImageReaderWriter(alphaBitmap);

            alphaMaskImageBuffer = new ChildImage(bmpReaderWrtier, new PixelBlenderGray(1));

            alphaMask = new AlphaMaskByteClipped(alphaMaskImageBuffer, 1, 0);

#if USE_CLIPPING_ALPHA_MASK
            //alphaMaskImageBuffer.AttachBuffer(alphaBitmap.GetBuffer(), 20 * width + 20, width - 40, height - 40, width, 8, 1);
#else
            alphaMaskImageBuffer.attach(alphaByteArray, (int)cx, (int)cy, cx, 1);
#endif

            var image = new ChildImage(alphaMaskImageBuffer, new PixelBlenderGray(1), 1, 0, 8);

            ClipProxyImage clippingProxy = new ClipProxyImage(image);


            clippingProxy.Clear(ColorRGBA.Black);

            VertexSource.Ellipse ellipseForMask = new PixelFarm.Agg.VertexSource.Ellipse();

            System.Random randGenerator = new Random(1432);


            int i;
            int num = (int)maskAlphaSliderValue;
            for (i = 0; i < num; i++)
            {
                if (i == num - 1)
                {
                    ellipseForMask.Reset(Width / 2, Height / 2, 110, 110, 100);
                    rasterizer.AddPath(ellipseForMask.MakeVertexSnap());
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(0, 0, 0, 255));

                    ellipseForMask.Reset(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100);
                    rasterizer.AddPath(ellipseForMask.MakeVertexSnap());
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(255, 0, 0, 255));
                }
                else
                {
                    ellipseForMask.Reset(randGenerator.Next() % width,
                                         randGenerator.Next() % height,
                                         randGenerator.Next() % 100 + 20,
                                         randGenerator.Next() % 100 + 20,
                                         100);
                    // set the color to draw into the alpha channel.
                    // there is not very much reason to set the alpha as you will get the amount of
                    // transparency based on the color you draw.  (you might want some type of different edeg effect but it will be minor).
                    rasterizer.AddPath(ellipseForMask.MakeVxs());
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack,
                                                   ColorRGBA.Make((int)((float)i / (float)num * 255), 0, 0, 255));
                }
            }
        }
Esempio n. 2
0
        public override void Draw(Painter p)
        {
            //specific for agg

            if (p is PixelFarm.Agg.AggPainter)
            {
                var p2 = (PixelFarm.Agg.AggPainter)p;
                AggRenderSurface   aggsx      = p2.RenderSurface;
                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;


                var widgetsSubImage = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect());
                aggsx.UseSubPixelRendering = false;
                PixelBlenderBGRA normalBlender = new PixelBlenderBGRA();
                PixelBlenderBGRA gammaBlender  = new PixelBlenderBGRA(); //TODO: revisit, and fix this again
                gammaBlender.GammaValue  = this.GammaValue;
                gammaBlender.EnableGamma = true;
                var            rasterGamma         = new SubImageRW(widgetsSubImage, gammaBlender);
                ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage);
                ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);
                clippingProxyNormal.Clear(Color.White);

                ScanlineUnpacked8 sl = new ScanlineUnpacked8();
                int size_mul         = (int)this.PixelSize;
                CustomScanlineRasToBmp_EnlargedSubPixelRendering ren_en = new CustomScanlineRasToBmp_EnlargedSubPixelRendering(size_mul, aggsx.DestActualImage);
                rasterizer.Reset();
                rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul);
                rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul);
                rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul);
                ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                //----------------------------------------
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = aggsx.ScanlineRasToDestBitmap;
                aggsx.UseSubPixelRendering = false;
                sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                rasterizer.ResetGamma(new GammaNone());
                aggsx.UseSubPixelRendering = false;
                //----------------------------------------
                PathWriter ps = new PathWriter();
                ps.Clear();
                ps.MoveTo(m_x[0], m_y[0]);
                ps.LineTo(m_x[1], m_y[1]);
                ps.LineTo(m_x[2], m_y[2]);
                ps.LineTo(m_x[0], m_y[0]);
                //----------------------------------------
                //Stroke stroke = new Stroke(ps);
                //stroke.Width = 2;
                //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs()));

                VectorToolBox.GetFreeVxs(out var v1);
                rasterizer.AddPath(stroke.MakeVxs(ps.Vxs, v1));
                VectorToolBox.ReleaseVxs(ref v1);
                //----------------------------------------

                sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160));
            }
        }
Esempio n. 3
0
        public void OnDraw(Graphics2D graphics2D)
        {
            var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());

            graphics2D.UseSubPixelRendering = false;

            IPixelBlender NormalBlender = new PixelBlenderBGRA();
            IPixelBlender GammaBlender  = new PixelBlenderGammaBGRA(this.GammaValue);
            var           rasterGamma   = new ChildImage(widgetsSubImage, GammaBlender);


            ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage);
            ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);

            clippingProxyNormal.Clear(ColorRGBA.White);
            var rasterizer = graphics2D.ScanlineRasterizer;

            ScanlineUnpacked8 sl = new ScanlineUnpacked8();

            int size_mul = (int)this.PixelSize;

            CustomScanlineRasToBmp_EnlargedV3 ren_en = new CustomScanlineRasToBmp_EnlargedV3(size_mul, graphics2D.DestActualImage);

            rasterizer.Reset();
            rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul);
            rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul);
            rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul);
            ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black);

            //----------------------------------------
            ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;

            graphics2D.UseSubPixelRendering = true;
            sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black);
            rasterizer.ResetGamma(new GammaNone());
            graphics2D.UseSubPixelRendering = false;
            //----------------------------------------
            PathWriter ps = new PathWriter();

            ps.Clear();
            ps.MoveTo(m_x[0], m_y[0]);
            ps.LineTo(m_x[1], m_y[1]);
            ps.LineTo(m_x[2], m_y[2]);
            ps.LineTo(m_x[0], m_y[0]);
            //----------------------------------------
            //Stroke stroke = new Stroke(ps);
            //stroke.Width = 2;
            //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs()));
            rasterizer.AddPath(StrokeHelp.MakeVxs(ps.Vxs, 2));
            //----------------------------------------

            sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new ColorRGBA(0, 150, 160, 200));
        }
Esempio n. 4
0
        public override void Draw(CanvasPainter p)
        {
            //specific for agg

            if (p is PixelFarm.Agg.AggCanvasPainter)
            {
                var        p2 = (PixelFarm.Agg.AggCanvasPainter)p;
                Graphics2D gx = p2.Graphics;
                var        widgetsSubImage = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect());
                gx.UseSubPixelRendering = false;
                IPixelBlender  NormalBlender       = new PixelBlenderBGRA();
                IPixelBlender  GammaBlender        = new PixelBlenderGammaBGRA(this.GammaValue);
                var            rasterGamma         = new ChildImage(widgetsSubImage, GammaBlender);
                ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage);
                ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);
                clippingProxyNormal.Clear(Color.White);
                var rasterizer       = gx.ScanlineRasterizer;
                ScanlineUnpacked8 sl = new ScanlineUnpacked8();
                int size_mul         = (int)this.PixelSize;
                CustomScanlineRasToBmp_EnlargedSubPixelRendering ren_en = new CustomScanlineRasToBmp_EnlargedSubPixelRendering(size_mul, gx.DestActualImage);
                rasterizer.Reset();
                rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul);
                rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul);
                rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul);
                ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                //----------------------------------------
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap;
                gx.UseSubPixelRendering = true;
                sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                rasterizer.ResetGamma(new GammaNone());
                gx.UseSubPixelRendering = false;
                //----------------------------------------
                PathWriter ps = new PathWriter();
                ps.Clear();
                ps.MoveTo(m_x[0], m_y[0]);
                ps.LineTo(m_x[1], m_y[1]);
                ps.LineTo(m_x[2], m_y[2]);
                ps.LineTo(m_x[0], m_y[0]);
                //----------------------------------------
                //Stroke stroke = new Stroke(ps);
                //stroke.Width = 2;
                //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs()));
                var v1 = GetFreeVxs();
                rasterizer.AddPath(stroke.MakeVxs(ps.Vxs, v1));
                ReleaseVxs(ref v1);
                //----------------------------------------

                sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160));
            }
        }
Esempio n. 5
0
        public void OnDraw(Graphics2D graphics2D)
        {
            var childImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());

            //IRecieveBlenderByte rasterBlender = new BlenderBGRA();
            var rasterGamma = new ChildImage(childImage, new PixelBlenderGammaBGRA(this.GammaValue));

            ClipProxyImage clippingProxyNormal = new ClipProxyImage(childImage);
            ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);

            clippingProxyNormal.Clear(ColorRGBA.White);

            var rasterizer = graphics2D.ScanlineRasterizer;
            var sl         = new ScanlineUnpacked8();


            int size_mul = this.PixelSize;

            CustomScanlineRasToBmp_EnlargedV2 sclineToBmpEn2 = new CustomScanlineRasToBmp_EnlargedV2(size_mul, graphics2D.DestActualImage);

            rasterizer.Reset();
            rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul);
            rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul);
            rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul);

            sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black);


            ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;

            sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black);

            //-----------------------------------------------------------------------------------------------------------
            rasterizer.ResetGamma(new GammaNone());

            PathWriter ps = new PathWriter();

            ps.Clear();
            ps.MoveTo(m_x[0], m_y[0]);
            ps.LineTo(m_x[1], m_y[1]);
            ps.LineTo(m_x[2], m_y[2]);
            ps.LineTo(m_x[0], m_y[0]);

            rasterizer.AddPath((new Stroke(2)).MakeVxs(ps.Vxs));
            sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new ColorRGBA(0, 150, 160, 200));
        }
Esempio n. 6
0
        public override void Draw(Painter p)
        {
            //this specific for agg
#if DEBUG
            //low-level scanline rasterizer example
            if (p is AggPainter)
            {
                AggPainter       p2    = (AggPainter)p;
                AggRenderSurface aggsx = p2.RenderSurface;
                PixelProcessing.SubBitmapBlender subImg = PixelProcessing.BitmapBlenderExtension.CreateSubBitmapBlender(aggsx.DestBitmapBlender, aggsx.GetClippingRect());

                //TODO: review here again
                PixelBlenderBGRA blenderWithGamma = new PixelProcessing.PixelBlenderBGRA();

                SubBitmapBlender rasterGamma         = new SubBitmapBlender(subImg, blenderWithGamma);
                ClipProxyImage   clippingProxyNormal = new ClipProxyImage(subImg);
                ClipProxyImage   clippingProxyGamma  = new ClipProxyImage(rasterGamma);
                clippingProxyNormal.Clear(Color.White);
                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;
                var sl             = new ScanlineUnpacked8();
                int size_mul       = this.PixelSize;
                var sclineToBmpEn2 = new CustomRas_EnlargeV2(size_mul, aggsx.DestBitmap);
                rasterizer.Reset();
                rasterizer.dbugDevMoveTo(_x[0] / size_mul, _y[0] / size_mul);
                rasterizer.dbugDevLineTo(_x[1] / size_mul, _y[1] / size_mul);
                rasterizer.dbugDevLineTo(_x[2] / size_mul, _y[2] / size_mul);
                sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                DestBitmapRasterizer bmpRas = aggsx.BitmapRasterizer;
                bmpRas.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                //-----------------------------------------------------------------------------------------------------------
                rasterizer.ResetGamma(new GammaNone());

                using (Tools.BorrowVxs(out var v1, out var v2))
                    using (Tools.BorrowPathWriter(v1, out PathWriter ps))
                    {
                        ps.Clear();
                        ps.MoveTo(_x[0], _y[0]);
                        ps.LineTo(_x[1], _y[1]);
                        ps.LineTo(_x[2], _y[2]);
                        ps.LineTo(_x[0], _y[0]);
                        rasterizer.AddPath((new Stroke(2)).MakeVxs(v1, v2));
                        bmpRas.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160));
                    }
            }
#endif
        }
Esempio n. 7
0
        public override void Draw(Painter p)
        {
            //this specific for agg
            if (p is AggPainter)
            {
                AggPainter       p2     = (AggPainter)p;
                AggRenderSurface aggsx  = p2.RenderSurface;
                SubImageRW       subImg = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect());

                //TODO: review here again
                PixelBlenderBGRA blenderWithGamma = new PixelBlenderBGRA();

                SubImageRW     rasterGamma         = new SubImageRW(subImg, blenderWithGamma);
                ClipProxyImage clippingProxyNormal = new ClipProxyImage(subImg);
                ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);
                clippingProxyNormal.Clear(Color.White);
                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;
                var sl             = new ScanlineUnpacked8();
                int size_mul       = this.PixelSize;
                var sclineToBmpEn2 = new CustomScanlineRasToBmp_EnlargedV2(size_mul, aggsx.DestActualImage);
                rasterizer.Reset();
                rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul);
                rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul);
                rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul);
                sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = aggsx.ScanlineRasToDestBitmap;
                sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                //-----------------------------------------------------------------------------------------------------------
                rasterizer.ResetGamma(new GammaNone());
                PathWriter ps = new PathWriter();
                ps.Clear();
                ps.MoveTo(m_x[0], m_y[0]);
                ps.LineTo(m_x[1], m_y[1]);
                ps.LineTo(m_x[2], m_y[2]);
                ps.LineTo(m_x[0], m_y[0]);

                VectorToolBox.GetFreeVxs(out var v1);
                rasterizer.AddPath((new Stroke(2)).MakeVxs(ps.Vxs, v1));
                sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160));
                VectorToolBox.ReleaseVxs(ref v1);
            }
        }
Esempio n. 8
0
 public override void Draw(CanvasPainter p)
 {
     //this specific for agg
     if (p is PixelFarm.Agg.AggCanvasPainter)
     {
         PixelFarm.Agg.AggCanvasPainter p2 = (PixelFarm.Agg.AggCanvasPainter)p;
         Graphics2D gx         = p2.Graphics;
         var        childImage = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect());
         //IRecieveBlenderByte rasterBlender = new BlenderBGRA();
         var            rasterGamma         = new ChildImage(childImage, new PixelBlenderGammaBGRA(this.GammaValue));
         ClipProxyImage clippingProxyNormal = new ClipProxyImage(childImage);
         ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);
         clippingProxyNormal.Clear(Color.White);
         var rasterizer     = gx.ScanlineRasterizer;
         var sl             = new ScanlineUnpacked8();
         int size_mul       = this.PixelSize;
         var sclineToBmpEn2 = new CustomScanlineRasToBmp_EnlargedV2(size_mul, gx.DestActualImage);
         rasterizer.Reset();
         rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul);
         rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul);
         rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul);
         sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
         ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap;
         sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
         //-----------------------------------------------------------------------------------------------------------
         rasterizer.ResetGamma(new GammaNone());
         PathWriter ps = new PathWriter();
         ps.Clear();
         ps.MoveTo(m_x[0], m_y[0]);
         ps.LineTo(m_x[1], m_y[1]);
         ps.LineTo(m_x[2], m_y[2]);
         ps.LineTo(m_x[0], m_y[0]);
         var v1 = GetFreeVxs();
         rasterizer.AddPath((new Stroke(2)).MakeVxs(ps.Vxs, v1));
         sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160));
         ReleaseVxs(ref v1);
     }
 }
Esempio n. 9
0
        void DrawAsScanline(ClipProxyImage imageClippingProxy,
                            AggRenderSurface aggsx,
                            ScanlineRasterizer rasterizer,
                            ScanlineRasToDestBitmapRenderer sclineRasToBmp)
        {
            SvgRenderVx renderVx  = lionShape.GetRenderVx();
            int         num_paths = renderVx.SvgVxCount;

            for (int i = 0; i < num_paths; ++i)
            {
                rasterizer.Reset();
                SvgPart svgPart = renderVx.GetInnerVx(i);

                switch (svgPart.Kind)
                {
                case SvgRenderVxKind.Path:
                {
                    rasterizer.AddPath(new PixelFarm.Drawing.VertexStoreSnap(svgPart.GetVxs(), 0));
                    sclineRasToBmp.RenderWithColor(imageClippingProxy, rasterizer, aggsx.ScanlinePacked8, new Drawing.Color(255, 0, 0));
                }
                break;
                }
            }
        }
Esempio n. 10
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            //specific for agg
            if (!(p is AggPainter))
            {
                return;
            }


            AggPainter       p2  = (AggPainter)p;
            AggRenderSurface asx = p2.RenderSurface;

            if (asx.DestBitmapBlender != null)
            {
                IBitmapBlender backBuffer = asx.DestBitmapBlender;

                //use different pixel blender
                var redImageBuffer   = new SubBitmapBlender(backBuffer, new PixelBlenderGrey());
                var greenImageBuffer = new SubBitmapBlender(backBuffer, new PixelBlenderGrey());
                var blueImageBuffer  = new SubBitmapBlender(backBuffer, new PixelBlenderGrey());

                ClipProxyImage clippingProxy      = new ClipProxyImage(backBuffer);
                ClipProxyImage clippingProxyRed   = new ClipProxyImage(redImageBuffer);
                ClipProxyImage clippingProxyGreen = new ClipProxyImage(greenImageBuffer);
                ClipProxyImage clippingProxyBlue  = new ClipProxyImage(blueImageBuffer);
                //
                ScanlineRasterizer sclineRas  = asx.ScanlineRasterizer;
                ScanlinePacked8    scline     = asx.ScanlinePacked8;
                Drawing.Color      clearColor = this.UseBlackBlackground ? Drawing.Color.FromArgb(0, 0, 0) : Drawing.Color.FromArgb(255, 255, 255);
                clippingProxy.Clear(clearColor);
                Drawing.Color fillColor = this.UseBlackBlackground ?
                                          new Drawing.Color((byte)(this.AlphaValue), 255, 255, 255) :
                                          new Drawing.Color((byte)(this.AlphaValue), 0, 0, 0);


                DestBitmapRasterizer bmpRas = asx.BitmapRasterizer;

                using (VectorToolBox.Borrow(out Ellipse ellipse))
                    using (VxsTemp.Borrow(out var v1))
                    {
                        ellipse.Set(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                        sclineRas.AddPath(ellipse.MakeVxs(v1));
                        v1.Clear();//**
                        bmpRas.RenderWithColor(clippingProxyRed, sclineRas, scline, fillColor);

                        ////

                        ellipse.Set(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                        sclineRas.AddPath(ellipse.MakeVxs(v1));
                        v1.Clear();//***
                        bmpRas.RenderWithColor(clippingProxyGreen, sclineRas, scline, fillColor);

                        //

                        ellipse.Set(Width / 2, Height / 2 + 50, 100, 100, 100);
                        sclineRas.AddPath(ellipse.MakeVxs(v1));
                        v1.Clear(); //***
                        bmpRas.RenderWithColor(clippingProxyBlue, sclineRas, scline, fillColor);
                    }
            }
            //            else if (graphics2D.DestImageFloat != null)
            //            {
            //#if false
            //                IImageFloat backBuffer = graphics2D.DestImageFloat;

            //                int distBetween = backBuffer.GetFloatsBetweenPixelsInclusive();
            //                ImageBufferFloat redImageBuffer = new ImageBufferFloat();
            //                redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8);
            //                ImageBufferFloat greenImageBuffer = new ImageBufferFloat();
            //                greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8);
            //                ImageBufferFloat blueImageBuffer = new ImageBufferFloat();
            //                blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8);

            //                ImageClippingProxy clippingProxy = new ImageClippingProxy(backBuffer);
            //                ImageClippingProxy clippingProxyRed = new ImageClippingProxy(redImageBuffer);
            //                ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer);
            //                ImageClippingProxy clippingProxyBlue = new ImageClippingProxy(blueImageBuffer);

            //                ScanlineRasterizer ras = new ScanlineRasterizer();
            //                ScanlineCachePacked8 sl = new ScanlineCachePacked8();

            //                RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255);
            //                clippingProxy.clear(clearColor);
            //                alphaSlider.View.BackGroundColor = clearColor;

            //                RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value));

            //                VertexSource.Ellipse er = new AGG.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
            //                ras.add_path(er);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyRed, ras, sl, FillColor);

            //                VertexSource.Ellipse eg = new AGG.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
            //                ras.add_path(eg);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyGreen, ras, sl, FillColor);

            //                VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
            //                ras.add_path(eb);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor);
            //#endif
            //            }
        }
Esempio n. 11
0
        public override void Render(PixelFarm.Drawing.Painter p)
        {
            int strokeWidth = 1;
            int width       = p.Width;
            int height      = p.Height;

            Affine affTx = Affine.NewMatix(
                AffinePlan.Translate(-_spriteShape.Center.x, -_spriteShape.Center.y),
                AffinePlan.Scale(_spriteScale, _spriteScale),
                AffinePlan.Rotate(_angle + Math.PI),
                AffinePlan.Skew(_skewX / 1000.0, _skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            var p1 = p as AggPainter;

            if (p1 == null)
            {
                //TODO: review here
                _spriteShape.Paint(p, affTx);
                //int j = lionShape.NumPaths;
                //int[] pathList = lionShape.PathIndexList;
                //Drawing.Color[] colors = lionShape.Colors;
                ////graphics2D.UseSubPixelRendering = true;
                //var vxs = GetFreeVxs();
                //affTx.TransformToVxs(lionShape.Vxs, vxs);
                //p.StrokeWidth = 1;
                //for (int i = 0; i < j; ++i)
                //{
                //    p.StrokeColor = colors[i];
                //    p.Draw(new PixelFarm.Drawing.VertexStoreSnap(vxs, pathList[i]));

                //}
                ////not agg
                //Release(ref vxs);
                //return; //**
            }


            if (UseBitmapExt)
            {
                p.RenderQuality = Drawing.RenderQuality.Fast;
                p.Clear(Drawing.Color.White);
                p.StrokeWidth = 1;

                //-------------------------
                _spriteShape.DrawOutline(p);
            }
            else
            {
                p.RenderQuality = Drawing.RenderQuality.HighQuality;
            }


            //-----------------------
            AggRenderSurface aggsx = p1.RenderSurface;
            //-----------------------
            //TODO: make this reusable ...
            //
            SubBitmapBlender widgetsSubImage    = BitmapBlenderExtension.CreateSubBitmapBlender(aggsx.DestBitmapBlender, aggsx.GetClippingRect());
            SubBitmapBlender clippedSubImage    = new SubBitmapBlender(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage   imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(PixelFarm.Drawing.Color.White);

            AggPainter aggPainter = (AggPainter)p;

            if (RenderAsScanline)
            {
                //a low-level example, expose scanline rasterizer

                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);

                //lionShape.ApplyTransform(affTx);
                //---------------------

                using (VgPaintArgsPool.Borrow(aggPainter, out VgPaintArgs paintArgs))
                {
                    paintArgs._currentTx        = affTx;
                    paintArgs.PaintVisitHandler = (vxs, painterA) =>
                    {
                        //use external painter handler
                        //draw only outline with its fill-color.
                        rasterizer.Reset();
                        rasterizer.AddPath(vxs);
                        aggsx.BitmapRasterizer.RenderWithColor(
                            imageClippingProxy, rasterizer,
                            aggsx.ScanlinePacked8,
                            aggPainter.FillColor); //draw line with external drawing handler
                    };

                    _spriteShape.Paint(paintArgs);
                }

                //----------------------------
                //lionShape.ResetTransform();
            }
            else
            {
                if (UseBuiltInAggOutlineAATech)
                {
                    aggPainter.StrokeWidth       = 1;
                    aggPainter.LineRenderingTech = AggPainter.LineRenderingTechnique.OutlineAARenderer;

                    //------
                    using (VgPaintArgsPool.Borrow(aggPainter, out VgPaintArgs paintArgs))
                    {
                        paintArgs._currentTx        = affTx;
                        paintArgs.PaintVisitHandler = (vxs, painterA) =>
                        {
                            //use external painter handler
                            //draw only outline with its fill-color.
                            Drawing.Painter m_painter       = paintArgs.P;
                            Drawing.Color   prevStrokeColor = m_painter.StrokeColor;
                            m_painter.StrokeColor = m_painter.FillColor;
                            m_painter.Draw(vxs);
                            m_painter.StrokeColor = prevStrokeColor;
                        };
                        _spriteShape.Paint(paintArgs);
                    }
                }
                else
                {
                    //low-level implementation
                    aggPainter.StrokeWidth = 1;

                    //-------------------------
                    //Draw with LineProfile:
                    //LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), new GammaNone()); //with gamma

                    LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), null);
                    OutlineRenderer      outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile);
                    outlineRenderer.SetClipBox(0, 0, this.Width, this.Height);

                    OutlineAARasterizer rasterizer = new OutlineAARasterizer(outlineRenderer);
                    rasterizer.LineJoin = (RenderAccurateJoins ?
                                           OutlineAARasterizer.OutlineJoin.AccurateJoin
                        : OutlineAARasterizer.OutlineJoin.Round);
                    rasterizer.RoundCap = true;

                    //lionShape.ApplyTransform(affTx);
                    //----------------------------
                    using (VgPaintArgsPool.Borrow(aggPainter, out VgPaintArgs paintArgs))
                    {
                        paintArgs._currentTx        = affTx;
                        paintArgs.PaintVisitHandler = (vxs, painterA) =>
                        {
                            //use external painter handler
                            //draw only outline with its fill-color.
                            rasterizer.RenderVertexSnap(
                                vxs,
                                painterA.P.FillColor);
                        };

                        _spriteShape.Paint(paintArgs);
                    }

                    //----------------------------
                    //lionShape.ResetTransform();
                }
            }
        }
Esempio n. 12
0
        public override void Draw(CanvasPainter p)
        {
            //specific for agg
            if (!(p is AggCanvasPainter))
            {
                return;
            }


            AggCanvasPainter p2         = (AggCanvasPainter)p;
            Graphics2D       graphics2D = p2.Graphics;

            if (graphics2D.DestImage != null)
            {
                IImageReaderWriter backBuffer          = graphics2D.DestImage;
                IPixelBlender      currentPixelBlender = graphics2D.PixelBlender;
                int distBetween = backBuffer.BytesBetweenPixelsInclusive;
                //use different pixel blender
                var                redImageBuffer     = new ChildImage(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.R, 8);
                var                greenImageBuffer   = new ChildImage(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.G, 8);
                var                blueImageBuffer    = new ChildImage(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.B, 8);
                ClipProxyImage     clippingProxy      = new ClipProxyImage(backBuffer);
                ClipProxyImage     clippingProxyRed   = new ClipProxyImage(redImageBuffer);
                ClipProxyImage     clippingProxyGreen = new ClipProxyImage(greenImageBuffer);
                ClipProxyImage     clippingProxyBlue  = new ClipProxyImage(blueImageBuffer);
                ScanlineRasterizer sclineRas          = graphics2D.ScanlineRasterizer;
                ScanlinePacked8    scline             = graphics2D.ScanlinePacked8;
                ColorRGBA          clearColor         = this.UseBlackBlackground ? new ColorRGBA(0, 0, 0) : new ColorRGBA(255, 255, 255);
                clippingProxy.Clear(clearColor);
                ColorRGBA fillColor = this.UseBlackBlackground ?
                                      new ColorRGBA(255, 255, 255, (byte)(this.AlphaValue)) :
                                      new ColorRGBA(0, 0, 0, (byte)(this.AlphaValue));
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;
                VertexSource.Ellipse            er             = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                sclineRas.AddPath(er.MakeVertexSnap());
                sclineRasToBmp.RenderWithColor(clippingProxyRed, sclineRas, scline, fillColor);
                VertexSource.Ellipse eg = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                sclineRas.AddPath(eg.MakeVertexSnap());
                sclineRasToBmp.RenderWithColor(clippingProxyGreen, sclineRas, scline, fillColor);
                VertexSource.Ellipse eb = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
                sclineRas.AddPath(eb.MakeVertexSnap());
                sclineRasToBmp.RenderWithColor(clippingProxyBlue, sclineRas, scline, fillColor);
            }
            //            else if (graphics2D.DestImageFloat != null)
            //            {
            //#if false
            //                IImageFloat backBuffer = graphics2D.DestImageFloat;

            //                int distBetween = backBuffer.GetFloatsBetweenPixelsInclusive();
            //                ImageBufferFloat redImageBuffer = new ImageBufferFloat();
            //                redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8);
            //                ImageBufferFloat greenImageBuffer = new ImageBufferFloat();
            //                greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8);
            //                ImageBufferFloat blueImageBuffer = new ImageBufferFloat();
            //                blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8);

            //                ImageClippingProxy clippingProxy = new ImageClippingProxy(backBuffer);
            //                ImageClippingProxy clippingProxyRed = new ImageClippingProxy(redImageBuffer);
            //                ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer);
            //                ImageClippingProxy clippingProxyBlue = new ImageClippingProxy(blueImageBuffer);

            //                ScanlineRasterizer ras = new ScanlineRasterizer();
            //                ScanlineCachePacked8 sl = new ScanlineCachePacked8();

            //                RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255);
            //                clippingProxy.clear(clearColor);
            //                alphaSlider.View.BackGroundColor = clearColor;

            //                RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value));

            //                VertexSource.Ellipse er = new AGG.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
            //                ras.add_path(er);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyRed, ras, sl, FillColor);

            //                VertexSource.Ellipse eg = new AGG.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
            //                ras.add_path(eg);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyGreen, ras, sl, FillColor);

            //                VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
            //                ras.add_path(eb);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor);
            //#endif
            //            }
        }
Esempio n. 13
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            int strokeWidth = 1;
            int width       = p.Width;
            int height      = p.Height;

            Affine affTx = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(spriteScale, spriteScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            var p1 = p as AggPainter;

            if (p1 == null)
            {
                //TODO: review here

                lionShape.Paint(p, affTx);
                //int j = lionShape.NumPaths;
                //int[] pathList = lionShape.PathIndexList;
                //Drawing.Color[] colors = lionShape.Colors;
                ////graphics2D.UseSubPixelRendering = true;
                //var vxs = GetFreeVxs();
                //affTx.TransformToVxs(lionShape.Vxs, vxs);
                //p.StrokeWidth = 1;
                //for (int i = 0; i < j; ++i)
                //{
                //    p.StrokeColor = colors[i];
                //    p.Draw(new PixelFarm.Drawing.VertexStoreSnap(vxs, pathList[i]));

                //}
                ////not agg
                //Release(ref vxs);
                //return; //**
            }


            if (UseBitmapExt)
            {
                p.RenderQuality = Drawing.RenderQualtity.Fast;
                p.Clear(Drawing.Color.White);
                p.StrokeWidth = 1;

                //-------------------------
                lionShape.DrawOutline(p);
            }
            else
            {
                p.RenderQuality = Drawing.RenderQualtity.HighQuality;
            }



            //-----------------------
            AggRenderSurface aggsx = p1.RenderSurface;
            //var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());
            //int width = widgetsSubImage.Width;
            //int height = widgetsSubImage.Height;

            SubImageRW     widgetsSubImage    = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect());
            SubImageRW     clippedSubImage    = new SubImageRW(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(PixelFarm.Drawing.Color.White);


            if (RenderAsScanline)
            {
                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);
                //Stroke stroke = new Stroke(strokeWidth);
                //stroke.LineJoin = LineJoin.Round;
                lionShape.ApplyTransform(affTx);


                DrawAsScanline(imageClippingProxy, aggsx, rasterizer, aggsx.ScanlineRasToDestBitmap);



                lionShape.ResetTransform();
            }
            else
            {
                //LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), new GammaNone());
                LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), null);
                OutlineRenderer      outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile);
                OutlineAARasterizer  rasterizer      = new OutlineAARasterizer(outlineRenderer);
                rasterizer.LineJoin = (RenderAccurateJoins ?
                                       OutlineAARasterizer.OutlineJoin.AccurateJoin
                    : OutlineAARasterizer.OutlineJoin.Round);
                rasterizer.RoundCap = true;

                SvgRenderVx renderVx = lionShape.GetRenderVx();

                lionShape.ApplyTransform(affTx);

                DrawWithLineProfile(rasterizer);

                lionShape.ResetTransform();
            }
            base.Draw(p);
        }
Esempio n. 14
0
        public override void Draw(Painter p)
        {
            //specific for agg
#if DEBUG
            //low-level scanline rasterizer example
            if (p is PixelFarm.CpuBlit.AggPainter p2)
            {
                AggRenderSurface   aggsx      = p2.RenderSurface;
                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;


                var widgetsSubImage = PixelProcessing.BitmapBlenderExtension.CreateSubBitmapBlender(aggsx.DestBitmapBlender, aggsx.GetClippingRect());
                aggsx.UseSubPixelLcdEffect = false;
                PixelProcessing.PixelBlenderBGRA normalBlender = new PixelProcessing.PixelBlenderBGRA();
                PixelProcessing.PixelBlenderBGRA gammaBlender  = new PixelProcessing.PixelBlenderBGRA(); //TODO: revisit, and fix this again
                gammaBlender.GammaValue  = this.GammaValue;
                gammaBlender.EnableGamma = true;
                var            rasterGamma         = new PixelProcessing.SubBitmapBlender(widgetsSubImage, gammaBlender);
                ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage);
                ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);
                clippingProxyNormal.Clear(Color.White);

                ScanlineUnpacked8 sl = new ScanlineUnpacked8();
                int size_mul         = (int)this.PixelSize;
                CustomScanlineRasToBmp_EnlargedSubPixelRendering ren_en = new CustomScanlineRasToBmp_EnlargedSubPixelRendering(size_mul, aggsx.DestBitmap);
                rasterizer.Reset();
                rasterizer.dbugDevMoveTo(_x[0] / size_mul, _y[0] / size_mul);
                rasterizer.dbugDevLineTo(_x[1] / size_mul, _y[1] / size_mul);
                rasterizer.dbugDevLineTo(_x[2] / size_mul, _y[2] / size_mul);
                ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                //----------------------------------------
                DestBitmapRasterizer sclineRasToBmp = aggsx.BitmapRasterizer;
                aggsx.UseSubPixelLcdEffect = false;
                sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                rasterizer.ResetGamma(new GammaNone());
                aggsx.UseSubPixelLcdEffect = false;
                //----------------------------------------

                using (Tools.BorrowVxs(out var v1, out var v2))
                    using (Tools.BorrowPathWriter(v1, out PathWriter ps))
                    {
                        ps.Clear();

                        ps.MoveTo(_x[0], _y[0]);
                        ps.LineTo(_x[1], _y[1]);
                        ps.LineTo(_x[2], _y[2]);
                        ps.LineTo(_x[0], _y[0]);

                        rasterizer.AddPath(_stroke.MakeVxs(v1, v2));
                    }


                //----------------------------------------
                //Stroke stroke = new Stroke(ps);
                //stroke.Width = 2;
                //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs()));

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

                sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160));
            }
#endif
        }
Esempio n. 15
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            //render
            var            widgetsSubImage    = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());
            int            width              = widgetsSubImage.Width;
            int            height             = widgetsSubImage.Height;
            int            strokeWidth        = 1;
            var            clippedSubImage    = new ChildImage(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(ColorRGBA.White);
            Affine affTx = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(spriteScale, spriteScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            //transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y);
            //transform *= Affine.NewScaling(spriteScale, spriteScale);
            //transform *= Affine.NewRotation(angle + Math.PI);
            //transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0);
            //transform *= Affine.NewTranslation(width / 2, height / 2);


            if (RenderAsScanline)
            {
                var rasterizer = graphics2D.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);
                Stroke stroke = new Stroke(strokeWidth);
                stroke.LineJoin = LineJoin.Round;
                var vxs = affTx.TransformToVxs(lionShape.Path.Vxs);
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;
                sclineRasToBmp.RenderSolidAllPaths(
                    imageClippingProxy,
                    rasterizer,
                    graphics2D.ScanlinePacked8,
                    vxs,
                    lionShape.Colors,
                    lionShape.PathIndexList,
                    lionShape.NumPaths);
            }
            else
            {
                double w = strokeWidth * affTx.GetScale();
                LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(w, new GammaNone());
                OutlineRenderer      outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile);
                OutlineAARasterizer  rasterizer      = new OutlineAARasterizer(outlineRenderer);
                rasterizer.LineJoin = (RenderAccurateJoins ?
                                       OutlineAARasterizer.OutlineJoin.AccurateJoin
                    : OutlineAARasterizer.OutlineJoin.Round);
                rasterizer.RoundCap = true;
                //VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);
                var vxs = affTx.TransformToVxs(lionShape.Path.Vxs);// trans.DoTransformToNewVxStorage();
                int j   = lionShape.NumPaths;
                for (int i = 0; i < j; ++i)
                {
                    rasterizer.RenderVertexSnap(
                        new VertexStoreSnap(vxs,
                                            lionShape.PathIndexList[i]),
                        lionShape.Colors[i]);
                }
            }

            base.OnDraw(graphics2D);
        }
Esempio n. 16
0
        public override void Draw(CanvasPainter p)
        {
            if (p is GdiPlusCanvasPainter)
            {
                DrawWithWinGdi((GdiPlusCanvasPainter)p);
                return;
            }
            AggCanvasPainter p2 = (AggCanvasPainter)p;
            Graphics2D       gx = p2.Graphics;
            var widgetsSubImage = gx.DestImage;
            var scline          = gx.ScanlinePacked8;
            int width           = (int)widgetsSubImage.Width;
            int height          = (int)widgetsSubImage.Height;

            //change value ***
            if (isMaskSliderValueChanged)
            {
                generate_alpha_mask(gx.ScanlineRasToDestBitmap, gx.ScanlinePacked8, gx.ScanlineRasterizer, width, height);
                this.isMaskSliderValueChanged = false;
            }
            var rasterizer = gx.ScanlineRasterizer;

            rasterizer.SetClipBox(0, 0, width, height);
            //alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 0, width, height, width, 8, 1);

            PixelFarm.Agg.Imaging.AlphaMaskAdaptor imageAlphaMaskAdaptor = new PixelFarm.Agg.Imaging.AlphaMaskAdaptor(widgetsSubImage, alphaMask);
            ClipProxyImage alphaMaskClippingProxy = new ClipProxyImage(imageAlphaMaskAdaptor);
            ClipProxyImage clippingProxy          = new ClipProxyImage(widgetsSubImage);
            ////Affine transform = Affine.NewIdentity();
            ////transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y);
            ////transform *= Affine.NewScaling(lionScale, lionScale);
            ////transform *= Affine.NewRotation(angle + Math.PI);
            ////transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0);
            ////transform *= Affine.NewTranslation(Width / 2, Height / 2);
            Affine transform = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(lionScale, lionScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            clippingProxy.Clear(Drawing.Color.White);
            ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap;
            // draw a background to show how the mask is working better
            int rect_w = 30;
            var v1     = GetFreeVxs();

            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 40; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * rect_w, j * rect_w, (i + 1) * rect_w, (j + 1) * rect_w, 0);
                        rect.NormalizeRadius();
                        // Drawing as an outline
                        rasterizer.AddPath(rect.MakeVxs(v1));
                        v1.Clear();
                        sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, scline, Drawing.Color.Make(.9f, .9f, .9f));
                    }
                }
            }
            ReleaseVxs(ref v1);
            ////int x, y;
            //// Render the lion
            ////VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);

            ////var vxlist = new System.Collections.Generic.List<VertexData>();
            ////trans.DoTransform(vxlist);

            var tmpVxs1 = new VertexStore();

            transform.TransformToVxs(lionShape.Path.Vxs, tmpVxs1);

            sclineRasToBmp.RenderSolidAllPaths(alphaMaskClippingProxy,
                                               rasterizer,
                                               scline,
                                               tmpVxs1,
                                               lionShape.Colors,
                                               lionShape.PathIndexList,
                                               lionShape.NumPaths);
            ///*
            //// Render random Bresenham lines and markers
            //agg::renderer_markers<amask_ren_type> m(r);
            //for(i = 0; i < 50; i++)
            //{
            //    m.line_color(agg::rgba8(randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            (randGenerator.Next() & 0x7F) + 0x7F));
            //    m.fill_color(agg::rgba8(randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            (randGenerator.Next() & 0x7F) + 0x7F));

            //    m.line(m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height),
            //           m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height));

            //    m.marker(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 10 + 5,
            //             agg::marker_e(randGenerator.Next() % agg::end_of_markers));
            //}


            //// Render random anti-aliased lines
            //double w = 5.0;
            //agg::line_profile_aa profile;
            //profile.width(w);

            //typedef agg::renderer_outline_aa<amask_ren_type> renderer_type;
            //renderer_type ren(r, profile);

            //typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
            //rasterizer_type ras(ren);
            //ras.round_cap(true);

            //for(i = 0; i < 50; i++)
            //{
            //    ren.Color = agg::rgba8(randGenerator.Next() & 0x7F,
            //                         randGenerator.Next() & 0x7F,
            //                         randGenerator.Next() & 0x7F,
            //                         //255));
            //                         (randGenerator.Next() & 0x7F) + 0x7F);
            //    ras.move_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
            //    ras.line_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
            //    ras.render(false);
            //}


            //// Render random circles with gradient
            //typedef agg::gradient_linear_color<color_type> grad_color;
            //typedef agg::gradient_circle grad_func;
            //typedef agg::span_interpolator_linear<> interpolator_type;
            //typedef agg::span_gradient<color_type,
            //                          interpolator_type,
            //                          grad_func,
            //                          grad_color> span_grad_type;

            //agg::trans_affine grm;
            //grad_func grf;
            //grad_color grc(agg::rgba8(0,0,0), agg::rgba8(0,0,0));
            //agg::ellipse ell;
            //agg::span_allocator<color_type> sa;
            //interpolator_type inter(grm);
            //span_grad_type sg(inter, grf, grc, 0, 10);
            //agg::renderer_scanline_aa<amask_ren_type,
            //                          agg::span_allocator<color_type>,
            //                          span_grad_type> rg(r, sa, sg);
            //for(i = 0; i < 50; i++)
            //{
            //    x = randGenerator.Next() % width;
            //    y = randGenerator.Next() % height;
            //    double r = randGenerator.Next() % 10 + 5;
            //    grm.reset();
            //    grm *= agg::trans_affine_scaling(r / 10.0);
            //    grm *= agg::trans_affine_translation(x, y);
            //    grm.invert();
            //    grc.colors(agg::rgba8(255, 255, 255, 0),
            //               agg::rgba8(randGenerator.Next() & 0x7F,
            //                          randGenerator.Next() & 0x7F,
            //                          randGenerator.Next() & 0x7F,
            //                          255));
            //    sg.color_function(grc);
            //    ell.init(x, y, r, r, 32);
            //    g_rasterizer.add_path(ell);
            //    agg::render_scanlines(g_rasterizer, g_scanline, rg);
            //}
            // */
            ////m_num_cb.Render(g_rasterizer, g_scanline, clippingProxy);
        }
Esempio n. 17
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            //specific for agg
            if (!(p is AggPainter))
            {
                return;
            }


            throw new NotSupportedException();

            AggPainter       p2      = (AggPainter)p;
            AggRenderSurface aggRdsf = p2.RenderSurface;

            if (aggRdsf.DestImage != null)
            {
                IImageReaderWriter backBuffer          = aggRdsf.DestImage;
                IPixelBlender      currentPixelBlender = aggRdsf.PixelBlender;
                int distBetween = backBuffer.BytesBetweenPixelsInclusive;
                //use different pixel blender
                var                redImageBuffer     = new SubImageRW(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.R, 8);
                var                greenImageBuffer   = new SubImageRW(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.G, 8);
                var                blueImageBuffer    = new SubImageRW(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.B, 8);
                ClipProxyImage     clippingProxy      = new ClipProxyImage(backBuffer);
                ClipProxyImage     clippingProxyRed   = new ClipProxyImage(redImageBuffer);
                ClipProxyImage     clippingProxyGreen = new ClipProxyImage(greenImageBuffer);
                ClipProxyImage     clippingProxyBlue  = new ClipProxyImage(blueImageBuffer);
                ScanlineRasterizer sclineRas          = aggRdsf.ScanlineRasterizer;
                ScanlinePacked8    scline             = aggRdsf.ScanlinePacked8;
                Drawing.Color      clearColor         = this.UseBlackBlackground ? Drawing.Color.FromArgb(0, 0, 0) : Drawing.Color.FromArgb(255, 255, 255);
                clippingProxy.Clear(clearColor);
                Drawing.Color fillColor = this.UseBlackBlackground ?
                                          new Drawing.Color((byte)(this.AlphaValue), 255, 255, 255) :
                                          new Drawing.Color((byte)(this.AlphaValue), 0, 0, 0);
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = aggRdsf.ScanlineRasToDestBitmap;
                VertexSource.Ellipse            er             = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                //
                VectorToolBox.GetFreeVxs(out var v1);
                sclineRas.AddPath(er.MakeVxs(v1));
                v1.Clear();
                sclineRasToBmp.RenderWithColor(clippingProxyRed, sclineRas, scline, fillColor);
                VertexSource.Ellipse eg = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                sclineRas.AddPath(eg.MakeVertexSnap(v1));
                v1.Clear();

                sclineRasToBmp.RenderWithColor(clippingProxyGreen, sclineRas, scline, fillColor);
                VertexSource.Ellipse eb = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);

                sclineRas.AddPath(eb.MakeVertexSnap(v1));
                v1.Clear();
                sclineRasToBmp.RenderWithColor(clippingProxyBlue, sclineRas, scline, fillColor);

                VectorToolBox.ReleaseVxs(ref v1);
            }
            //            else if (graphics2D.DestImageFloat != null)
            //            {
            //#if false
            //                IImageFloat backBuffer = graphics2D.DestImageFloat;

            //                int distBetween = backBuffer.GetFloatsBetweenPixelsInclusive();
            //                ImageBufferFloat redImageBuffer = new ImageBufferFloat();
            //                redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8);
            //                ImageBufferFloat greenImageBuffer = new ImageBufferFloat();
            //                greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8);
            //                ImageBufferFloat blueImageBuffer = new ImageBufferFloat();
            //                blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8);

            //                ImageClippingProxy clippingProxy = new ImageClippingProxy(backBuffer);
            //                ImageClippingProxy clippingProxyRed = new ImageClippingProxy(redImageBuffer);
            //                ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer);
            //                ImageClippingProxy clippingProxyBlue = new ImageClippingProxy(blueImageBuffer);

            //                ScanlineRasterizer ras = new ScanlineRasterizer();
            //                ScanlineCachePacked8 sl = new ScanlineCachePacked8();

            //                RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255);
            //                clippingProxy.clear(clearColor);
            //                alphaSlider.View.BackGroundColor = clearColor;

            //                RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value));

            //                VertexSource.Ellipse er = new AGG.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
            //                ras.add_path(er);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyRed, ras, sl, FillColor);

            //                VertexSource.Ellipse eg = new AGG.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
            //                ras.add_path(eg);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyGreen, ras, sl, FillColor);

            //                VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
            //                ras.add_path(eb);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor);
            //#endif
            //            }
        }
Esempio n. 18
0
        public override void Draw(CanvasPainter p)
        {
            int strokeWidth = 1;
            int width       = p.Width;
            int height      = p.Height;

            Affine affTx = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(spriteScale, spriteScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            var p1 = p as AggCanvasPainter;

            if (p1 == null)
            {
                int             j        = lionShape.NumPaths;
                int[]           pathList = lionShape.PathIndexList;
                Drawing.Color[] colors   = lionShape.Colors;
                //graphics2D.UseSubPixelRendering = true;
                var vxs = GetFreeVxs();
                affTx.TransformToVxs(lionShape.Path.Vxs, vxs);
                p.StrokeWidth = 1;
                for (int i = 0; i < j; ++i)
                {
                    p.StrokeColor = colors[i];
                    p.Draw(new VertexStoreSnap(vxs, pathList[i]));
                }
                //not agg
                Release(ref vxs);
                return; //**
            }

            Graphics2D graphics2D = p1.Graphics;
            //var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());
            //int width = widgetsSubImage.Width;
            //int height = widgetsSubImage.Height;
            var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());

            var            clippedSubImage    = new ChildImage(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(PixelFarm.Drawing.Color.White);


            if (RenderAsScanline)
            {
                var rasterizer = graphics2D.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);
                Stroke stroke = new Stroke(strokeWidth);
                stroke.LineJoin = LineJoin.Round;
                var vxs = GetFreeVxs();
                affTx.TransformToVxs(lionShape.Path.Vxs, vxs);
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;
                sclineRasToBmp.RenderSolidAllPaths(
                    imageClippingProxy,
                    rasterizer,
                    graphics2D.ScanlinePacked8,
                    vxs,
                    lionShape.Colors,
                    lionShape.PathIndexList,
                    lionShape.NumPaths);
                Release(ref vxs);
            }
            else
            {
                double w = strokeWidth * affTx.GetScale();
                LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(w, new GammaNone());
                OutlineRenderer      outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile);
                OutlineAARasterizer  rasterizer      = new OutlineAARasterizer(outlineRenderer);
                rasterizer.LineJoin = (RenderAccurateJoins ?
                                       OutlineAARasterizer.OutlineJoin.AccurateJoin
                    : OutlineAARasterizer.OutlineJoin.Round);
                rasterizer.RoundCap = true;
                //VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);
                var vxs = GetFreeVxs();
                affTx.TransformToVxs(lionShape.Path.Vxs, vxs);// trans.DoTransformToNewVxStorage();
                int j = lionShape.NumPaths;
                for (int i = 0; i < j; ++i)
                {
                    rasterizer.RenderVertexSnap(
                        new VertexStoreSnap(vxs,
                                            lionShape.PathIndexList[i]),
                        lionShape.Colors[i]);
                }
                Release(ref vxs);
            }
            base.Draw(p);
        }