コード例 #1
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);
        }
コード例 #2
0
        /// <summary>
        /// we do NOT store vxs/vxsSnap
        /// </summary>
        /// <param name="vxsSnap"></param>
        /// <param name="color"></param>
        public void Render(VertexStoreSnap vxsSnap, Drawing.Color color)
        {
            //reset rasterizer before render each vertextSnap
            //-----------------------------
            sclineRas.Reset();
            Affine transform = this.CurrentTransformMatrix;

            if (!transform.IsIdentity())
            {
                VectorToolBox.GetFreeVxs(out var v1);
                transform.TransformToVxs(vxsSnap, v1);
                sclineRas.AddPath(v1);
                VectorToolBox.ReleaseVxs(ref v1);
                //-------------------------
                //since sclineRas do NOT store vxs
                //then we can reuse the vxs***
                //-------------------------
            }
            else
            {
                sclineRas.AddPath(vxsSnap);
            }
            _bmpRasterizer.RenderWithColor(destImageReaderWriter, sclineRas, sclinePack8, color);
            unchecked { destImageChanged++; };
            //-----------------------------
        }
コード例 #3
0
ファイル: AADemo_Test2.cs プロジェクト: brezza92/PixelFarm
        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
        }
コード例 #4
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");
            }
        }
    }
コード例 #5
0
ファイル: Square.cs プロジェクト: BiDuc/PixelFarm
 public void Draw(
     DestBitmapRasterizer bmpRast,
     ScanlineRasterizer ras,
     Scanline sl,
     PixelProcessing.IBitmapBlender destImage, Color color,
     double x, double y)
 {
     ras.Reset();
     ras.MoveTo(x * _size, y * _size);
     ras.LineTo(x * _size + _size, y * _size);
     ras.LineTo(x * _size + _size, y * _size + _size);
     ras.LineTo(x * _size, y * _size + _size);
     bmpRast.RenderWithColor(destImage, ras, sl, color);
 }
コード例 #6
0
        public void Draw(
            DestBitmapRasterizer bmpRast,
            ScanlineRasterizer ras,
            Scanline sl,
            PixelProcessing.IBitmapBlender destImage, Color color,
            double x, double y)
        {
#if DEBUG
            //low-level scanline rasterizer example
            ras.Reset();
            ras.dbugDevMoveTo(x * _size, y * _size);
            ras.dbugDevLineTo(x * _size + _size, y * _size);
            ras.dbugDevLineTo(x * _size + _size, y * _size + _size);
            ras.dbugDevLineTo(x * _size, y * _size + _size);
            bmpRast.RenderWithColor(destImage, ras, sl, color);
#endif
        }
コード例 #7
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
            //            }
        }
コード例 #8
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
        }