예제 #1
0
        void generate_alpha_mask(ScanlineRasToDestBitmapRenderer sclineRasToBmp, ScanlinePacked8 sclnPack, ScanlineRasterizer rasterizer, int width, int height)
        {
            //create 1  8-bits chanel (grayscale8) bmp
            alphaBitmap = new ActualImage(width, height, PixelFormat.GrayScale8);
            var bmpReaderWrtier = new MyImageReaderWriter();

            bmpReaderWrtier.ReloadImage(alphaBitmap);
            alphaMaskImageBuffer = new SubImageRW(bmpReaderWrtier, new PixelBlenderGray(1));
            //create mask from alpahMaskImageBuffer
            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 SubImageRW(alphaMaskImageBuffer, new PixelBlenderGray(1), 1, 0, 8);
            ClipProxyImage clippingProxy = new ClipProxyImage(image);
            clippingProxy.Clear(Drawing.Color.Black);
            VertexSource.Ellipse ellipseForMask = new PixelFarm.Agg.VertexSource.Ellipse();
            System.Random        randGenerator  = new Random(1432);
            int i;
            int num = (int)maskAlphaSliderValue;

            VectorToolBox.GetFreeVxs(out var v1);
            for (i = 0; i < num; i++)
            {
                if (i == num - 1)
                {
                    //for the last one
                    ellipseForMask.Reset(Width / 2, Height / 2, 110, 110, 100);
                    rasterizer.AddPath(ellipseForMask.MakeVertexSnap(v1));
                    v1.Clear();
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new Color(255, 0, 0, 0));
                    ellipseForMask.Reset(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100);
                    rasterizer.AddPath(ellipseForMask.MakeVertexSnap(v1));
                    v1.Clear();
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new Color(255, 255, 0, 0));
                }
                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(v1));
                    v1.Clear();
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack,
                                                   ColorEx.Make((int)((float)i / (float)num * 255), 0, 0, 255));
                }
            }
            VectorToolBox.ReleaseVxs(ref v1);
        }
예제 #2
0
        /// <summary>
        /// fill vertex store, we do NOT store snap
        /// </summary>
        /// <param name="vxs"></param>
        /// <param name="c"></param>
        public override void Fill(VertexStoreSnap snap)
        {
            //BitmapExt
            if (this._renderQuality == RenderQualtity.Fast)
            {
                FillWithBxt(snap);
                return;
            }

            //Agg
            sclineRas.AddPath(snap);
            _bmpRasterizer.RenderWithColor(this._aggsx.DestImage, sclineRas, scline, fillColor);
        }
예제 #3
0
파일: Main.cs 프로젝트: brezza92/PixelFarm
    public static void Main()
    {
        //TEST
        //this is low-level scanline rasterizer
        //1. create vertex store
        VertexStore vxs = new VertexStore();

        vxs.AddMoveTo(10, 10);
        vxs.AddLineTo(50, 10);
        vxs.AddLineTo(50, 50);
        vxs.AddLineTo(10, 50);
        vxs.AddCloseFigure();

        //2. create scanline rasterizer
        ScanlineRasterizer sclineRas = new ScanlineRasterizer();

        sclineRas.AddPath(vxs);

        //3. create destination bitmap
        DestBitmapRasterizer destBmpRasterizer = new DestBitmapRasterizer();

        //4. create 32bit rgba bitmap blender

        MyBitmapBlender myBitmapBlender = new MyBitmapBlender();

        //5. create output bitmap
        using (MemBitmap membitmap = new MemBitmap(800, 600))
        {
            //6. attach target bitmap to bitmap blender
            myBitmapBlender.Attach(membitmap);

            //7. rasterizer sends the vector content inside sclineRas
            //   to the bitmap blender and

            destBmpRasterizer.RenderWithColor(myBitmapBlender, //blender+ output
                                              sclineRas,       //with vectors input inside
                                              new ScanlinePacked8(),
                                              Color.Red);

            //8. the content inside membitmap is just color image buffer
            //   you can copy it to other image object (eg SkImage, Gdi+ image etc)


            //... example ...
            using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(membitmap.Width, membitmap.Height))
            {
                IntPtr mem_ptr = membitmap.GetRawBufferHead();
                System.Drawing.Imaging.BitmapData bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                unsafe
                {
                    MemMx.memcpy((byte *)bmpdata.Scan0, (byte *)mem_ptr, membitmap.Width * membitmap.Height * 4);
                }
                bmp.UnlockBits(bmpdata);
                bmp.Save("test01.png");
            }
        }
    }
예제 #4
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));
            }
        }
예제 #5
0
 public static void RenderSolidAllPaths(this ScanlineRasToDestBitmapRenderer sclineRasToBmp,
                                        IImageReaderWriter destImage,
                                        ScanlineRasterizer sclineRas,
                                        Scanline scline,
                                        VertexStore vxs,
                                        Drawing.Color[] colors,
                                        int[] path_id,
                                        int num_paths)
 {
     for (int i = 0; i < num_paths; ++i)
     {
         sclineRas.Reset();
         sclineRas.AddPath(new VertexStoreSnap(vxs, path_id[i]));
         sclineRasToBmp.RenderWithColor(destImage, sclineRas, scline, colors[i]);
     }
 }
 public static void RenderSolidAllPaths(this ScanlineRasToDestBitmapRenderer sclineRasToBmp,
      IImageReaderWriter destImage,
       ScanlineRasterizer sclineRas,
       Scanline scline,
       VertexStore vxs,
       Drawing.Color[] colors,
       int[] path_id,
       int num_paths)
 {
     for (int i = 0; i < num_paths; ++i)
     {
         sclineRas.Reset();
         sclineRas.AddPath(new VertexStoreSnap(vxs, path_id[i]));
         sclineRasToBmp.RenderWithColor(destImage, sclineRas, scline, colors[i]);
     }
 }
예제 #7
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
        }
예제 #8
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);
            }
        }
예제 #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;
                }
            }
        }
예제 #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
            //            }
        }
예제 #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();
                }
            }
        }
예제 #12
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
        }