public AggTextSpanPrinter(GLPainter canvasPainter, int w, int h)
        {
            //this class print long text into agg canvas
            //then copy pixel buffer from aff canvas to gl-bmp
            //then draw the  gl-bmp into target gl canvas


            //TODO: review here
            this.canvasPainter = canvasPainter;
            this._glsx         = canvasPainter.Canvas;
            bmpWidth           = w;
            bmpHeight          = h;

            _actualImage            = new ActualImage(bmpWidth, bmpHeight);
            _aggsx                  = new AggRenderSurface(_actualImage);
            _aggPainter             = new AggPainter(_aggsx);
            _aggPainter.FillColor   = Color.Black;
            _aggPainter.StrokeColor = Color.Black;

            //set default1
            _aggPainter.CurrentFont = canvasPainter.CurrentFont;
            var openFontStore = new Typography.TextServices.OpenFontStore();

            _vxsTextPrinter         = new VxsTextPrinter(_aggPainter, openFontStore);
            _aggPainter.TextPrinter = _vxsTextPrinter;
        }
Exemplo n.º 2
0
 public CustomScanlineRasToBmp_EnlargedV2(double size, ActualImage destImage)
 {
     this.ScanlineRenderMode = Agg.ScanlineRenderMode.Custom;
     m_size   = size;
     m_square = new Square(size);
     gfx      = new AggRenderSurface(destImage);
 }
Exemplo n.º 3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (DesignMode)
            {
                return;
            }
            //
            _basicOptions = basicFontOptionsUserControl1.Options;
            _basicOptions.TypefaceChanged += (s, e2) =>
            {
                if (_devVxsTextPrinter != null)
                {
                    _devVxsTextPrinter.Typeface = e2.SelectedTypeface;
                }
            };
            _basicOptions.UpdateRenderOutput += (s, e2) =>
            {
                UpdateRenderOutput();
            };
            //
            //----------
            _renderOptions = glyphRenderOptionsUserControl1.Options;
            _renderOptions.UpdateRenderOutput += (s, e2) =>
            {
                UpdateRenderOutput();
            };

            //share text printer to our sample textbox
            //but you can create another text printer that specific to text textbox control

            destImg = new MemBitmap(800, 600);
            aggsx   = new AggRenderSurface();
            aggsx.AttachDstBitmap(destImg);

            painter = new AggPainter(aggsx);

            winBmp = new Bitmap(destImg.Width, destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            g      = this.sampleTextBox1.CreateGraphics();

            painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14);

            _openFontTextService = new PixelFarm.Drawing.OpenFontTextService();
            //....
            _devVxsTextPrinter                   = new PixelFarm.Drawing.VxsTextPrinter(painter, _openFontTextService);
            _devVxsTextPrinter.ScriptLang        = _basicOptions.ScriptLang;
            _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont;
            _devVxsTextPrinter.FontSizeInPoints  = 10;

            _controllerForPixelFarm.BindHostGraphics(g);
            _controllerForPixelFarm.TextPrinter = _devVxsTextPrinter;

            this.sampleTextBox1.SetController(_controllerForPixelFarm);
            _readyToRender = true;
            _basicOptions.UpdateRenderOutput += (s, e2) => UpdateRenderOutput();
            //....
            //----------
            //txtInputChar.TextChanged += (s, e2) => UpdateRenderOutput();
            //----------
        }
Exemplo n.º 4
0
 public CustomRas_EnlargeV2(double size, MemBitmap dstBmp)
 {
     this.ScanlineRenderMode = ScanlineRenderMode.Custom;
     _size   = size;
     _square = new Square(size);
     _gfx    = new AggRenderSurface();
     _gfx.AttachDstBitmap(dstBmp);
 }
Exemplo n.º 5
0
 public CustomScanlineRasToBmp_EnlargedSubPixelRendering(double size, ActualImage destImage)
 {
     this.ScanlineRenderMode = Agg.ScanlineRenderMode.Custom;
     m_size   = size;
     m_square = new Square(size);
     gfx      = new AggRenderSurface(destImage);
     lcdLut   = new Sample_AADemoTest3.AggLcdDistributionLookupTable(primary, 2.0 / 9, 1.0 / 9);
 }
Exemplo n.º 6
0
 public MiniAggCanvasRenderElement(RootGraphic rootgfx, int width, int height)
     : base(rootgfx, width, height)
 {
     this.actualImage = new ActualImage(width, height, PixelFarm.Agg.PixelFormat.ARGB32);
     this._aggsx      = new AggRenderSurface(actualImage);
     this.painter     = new AggPainter((AggRenderSurface)_aggsx);
     needUpdate       = true;
     this.BackColor   = Color.White;
 }
Exemplo n.º 7
0
 public CustomScanlineRasToBmp_EnlargedSubPixelRendering(double size, MemBitmap destImage)
 {
     this.ScanlineRenderMode = ScanlineRenderMode.Custom;
     _size   = size;
     _square = new Square(size);
     _gfx    = new AggRenderSurface();
     _gfx.AttachDstBitmap(destImage);
     _lcdLut = new Sample_AADemoTest3.AggLcdDistributionLookupTable(_primary, 2.0 / 9, 1.0 / 9);
 }
Exemplo n.º 8
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));
            }
        }
Exemplo n.º 9
0
        private void button4_Click(object sender, EventArgs e)
        {
            //----------------------
            //1. test gdi+ font path
            char  testChar = 'b';
            float fontSize = 20;

            using (Graphics g = this.pictureBox1.CreateGraphics())
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.Clear(System.Drawing.Color.White);
                //convert Agg vxs to bitmap
                int bmpW = 500;
                int bmpH = 500;
                using (Bitmap bufferBmp = new Bitmap(bmpW, bmpH))
                {
                    ActualImage      actualImage = new ActualImage(bmpW, bmpH);
                    AggRenderSurface gfx         = new AggRenderSurface(actualImage);
                    var vxs = new PixelFarm.Drawing.VertexStore();
                    //vxs.AddMoveTo(0, 0);
                    ////vxs.AddP3c(100, 0);
                    ////vxs.AddP3c(100,150);
                    ////vxs.AddLineTo(0,0);
                    //vxs.AddLineTo(0, 0);
                    //vxs.AddP3c(100, 0);
                    ////vxs.AddLineTo(100, 0);
                    ////vxs.AddLineTo(100, 150);
                    //vxs.AddP3c(100, 150);
                    //vxs.AddLineTo(0, 150);
                    //vxs.AddCloseFigure();

                    //PixelFarm.Agg.VertexSource.CurveFlattener cflat = new PixelFarm.Agg.VertexSource.CurveFlattener();
                    //vxs = cflat.MakeVxs(vxs);

                    gfx.Render(vxs, PixelFarm.Drawing.Color.Black);
                    //test subpixel rendering


                    vxs = vxs.TranslateToNewVxs(15, 0, new PixelFarm.Drawing.VertexStore());
                    gfx.UseSubPixelRendering = true;
                    gfx.Render(vxs, PixelFarm.Drawing.Color.Black);
                    PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(
                        actualImage, //src from actual img buffer
                        bufferBmp    //dest to buffer bmp
                        );
                    //-----------------------------------------
                    bufferBmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                    g.DrawImage(bufferBmp, new System.Drawing.Point(0, 30));
                }
            }
        }
Exemplo n.º 10
0
        public void BindHostGraphics(Graphics hostControlGraphics)
        {
            g = hostControlGraphics;
            //
            destImg = new ActualImage(400, 300, PixelFormat.ARGB32);
            aggsx   = new AggRenderSurface(destImg); //no platform
            p       = new AggPainter(aggsx);
            winBmp  = new Bitmap(400, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            _printer    = new VxsTextPrinter(p, null);
            _visualLine = new VisualLine();
            _visualLine.BindLine(_line);
            _visualLine.Y = 100;
        }
Exemplo n.º 11
0
        public override void Paint(PaintVisitor p)
        {
            if (Vxs != null)
            {
                //1.
                //convert vxs to bitmap
                //then render with bitmap cache**
                //or
                //2. convert vxs to path data

                if (backimg == null)
                {
                    var svgPart = new SvgPart(SvgRenderVxKind.Path);
                    svgPart.FillColor = fillColor;

                    svgPart.SetVxsAsOriginal(Vxs);
                    var svgVx = new SvgRenderVx(new SvgPart[] { svgPart });

                    if (svgVx != null && !svgVx.HasBitmapSnapshot)
                    {
                        var bounds = svgVx.GetBounds();
                        //create
                        backimg = new ActualBitmap((int)bounds.Width, (int)bounds.Height);
                        AggRenderSurface renderSurface = new AggRenderSurface(backimg);
                        AggPainter       painter       = new AggPainter(renderSurface);
                        svgVx.Render(painter);
                        svgVx.SetBitmapSnapshot(backimg);
                        //***
                    }
                }


                if (backimg != null)
                {
                    p.InnerCanvas.DrawImage(backimg, new RectangleF(0, 0, backimg.Width, backimg.Height));
                    return;
                }
            }

            if (fillColor.A > 0)
            {
                p.FillPath(this.myCachedPath, this.fillColor);
            }
            if (this.strokeColor.A > 0)
            {
                p.DrawPath(this.myCachedPath, this.strokeColor, this.ActualStrokeWidth);
            }
        }
        protected override void OnReadyForInitGLShaderProgram()
        {
            lionShape = new SpriteShape();
            lionShape.ParseLion();
            RectD lionBounds = lionShape.Bounds;

            //-------------
            aggImage   = new ActualImage((int)lionBounds.Width, (int)lionBounds.Height, PixelFarm.Agg.PixelFormat.ARGB32);
            _aggsx     = new AggRenderSurface(aggImage);
            aggPainter = new AggPainter(_aggsx);


            DrawLion(aggPainter, lionShape, lionShape.Vxs);
            //convert affImage to texture
            glBmp = DemoHelper.LoadTexture(aggImage);
        }
Exemplo n.º 13
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
        }
        protected override void OnReadyForInitGLShaderProgram()
        {
            var _svgRenderVx = PixelFarm.Agg.SvgRenderVxLoader.CreateSvgRenderVxFromFile("Samples/lion.svg");

            lionShape = new SpriteShape(_svgRenderVx);

            RectD lionBounds = lionShape.Bounds;

            //-------------
            aggImage   = new ActualImage((int)lionBounds.Width, (int)lionBounds.Height);
            _aggsx     = new AggRenderSurface(aggImage);
            aggPainter = new AggPainter(_aggsx);


            DrawLion(aggPainter, lionShape);
            //convert affImage to texture
            glBmp = DemoHelper.LoadTexture(aggImage);
        }
Exemplo n.º 15
0
        void RunSampleA(PixelFarm.Drawing.Painter p)
        {
            //1. create simple vertical line to test agg's lcd rendernig technique
            //create gray-scale actual image
            ActualImage      glyphImg = new ActualImage(100, 100, PixelFormat.ARGB32);
            AggRenderSurface glyph2d  = new AggRenderSurface(glyphImg);
            AggPainter       painter  = new AggPainter(glyph2d);

            painter.StrokeColor = PixelFarm.Drawing.Color.Black;
            painter.StrokeWidth = 2.0f * 3;
            int x = 10, y = 10;

            painter.DrawLine(x * 3, 0, y * 3, 20); //scale horizontal 3 times,
            int lineLen = 4;


            //painter.Line(x * 3, 0, y * 3, 20); //scale horizontal 3 times,
            //painter.Line(2, 0, 2, 15);
            //painter.Line(2, 0, 20, 20);
            //painter.Line(2, 0, 30, 15);
            //painter.Line(2, 0, 30, 5);
            //clear surface bg
            p.Clear(PixelFarm.Drawing.Color.White);
            //draw img into that bg
            //---------------
            //convert glyphImg from RGBA to grey Scale buffer
            //---------------
            //lcd process ...
            byte[] glyphGreyScale = CreateGreyScaleBuffer(glyphImg);
            //---------------

            //swap gray scale
            int newGreyImgStride;

            byte[] expanedGreyScaleBuffer = CreateNewExpandedLcdGrayScale(glyphGreyScale, glyphImg.Width, glyphImg.Height, out newGreyImgStride);

            //blend lcd
            var aggPainer = (PixelFarm.Agg.AggPainter)p;

            Blend(aggPainer.RenderSurface.DestActualImage, expanedGreyScaleBuffer, newGreyImgStride, glyphImg.Height);
            //---------------
            p.DrawImage(glyphImg, 0, 50);
        }
Exemplo n.º 16
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);
            }
        }
Exemplo n.º 17
0
            public CpuBlitAggCanvasRenderElement(RootGraphic rootgfx, int w, int h)
                : base(rootgfx, w, h)
            {
                //TODO: check if we can access raw rootGraphics buffer or not
                //1. gdi+ create backbuffer
                _nativeWin32DC = new Win32.NativeWin32MemoryDC(w, h);
                //2. create actual bitmap that share bitmap data from native _nativeWin32Dc
                _memBmp = new MemBitmap(w, h, _nativeWin32DC.PPVBits);
                //----------------------------------------------------------------
                //3. create render surface from bitmap => provide basic bitmap fill operations
                AggRenderSurface aggsx = new AggRenderSurface();

                aggsx.AttachDstBitmap(_memBmp);
                //4. painter wraps the render surface  => provide advance operations
                AggPainter aggPainter = new AggPainter(aggsx);

                aggPainter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14);
                _painter = aggPainter;
                //----------------------------------------------------------------
            }
Exemplo n.º 18
0
        void SoftAggControl_Load(object sender, EventArgs e)
        {
            if (_useGdiPlusOutput)
            {
                // This example assumes the existence of a form called Form1.
                // Gets a reference to the current BufferedGraphicsContext
                //BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
                //_myBuffGfx = currentContext.Allocate(this.CreateGraphics(),
                //   this.DisplayRectangle);

                // Creates a BufferedGraphics instance associated with Form1, and with
                // dimensions the same size as the drawing surface of Form1.
                thisGfx       = this.CreateGraphics(); //for render to output
                bufferBmpRect = this.DisplayRectangle;
                //bufferBmp = new Bitmap(bufferBmpRect.Width, bufferBmpRect.Height);


                sx = new PixelFarm.Drawing.WinGdi.GdiPlusRenderSurface(0, 0, bufferBmpRect.Width, bufferBmpRect.Height);
                var gdiPlusCanvasPainter = new PixelFarm.Drawing.WinGdi.GdiPlusPainter(sx);

                gdiPlusCanvasPainter.SmoothingMode = _gdiAntiAlias ? PixelFarm.Drawing.SmoothingMode.AntiAlias : PixelFarm.Drawing.SmoothingMode.HighSpeed;
                painter             = gdiPlusCanvasPainter;
                painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14);
            }
            else
            {
                AggRenderSurface aggsx      = CreateAggRenderSurface(myWidth, myHeight, 32);
                AggPainter       aggPainter = new AggPainter(aggsx);
                //set text printer for agg canvas painter
                aggPainter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14);

                //TODO: review text printer here again***
                VxsTextPrinter textPrinter = new VxsTextPrinter(aggPainter, YourImplementation.BootStrapWinGdi.GetFontLoader());
                aggPainter.TextPrinter = textPrinter;
                painter = aggPainter;
            }
            painter.Clear(PixelFarm.Drawing.Color.White);
        }
Exemplo n.º 19
0
        public FloodFillDemo()
        {
            //
            BackgroundColor = Color.White;
            imageToFillOn   = new ActualImage(400, 300, PixelFormat.ARGB32);
            AggRenderSurface aggsx = new AggRenderSurface(imageToFillOn);
            AggPainter       p     = new AggPainter(aggsx);

            p.Clear(Color.White);

            p.FillColor = Color.Black;
            p.FillEllipse(20, 20, 30, 30);


            for (int i = 0; i < 20; i++)
            {
                p.StrokeColor = Color.Black;
                p.DrawEllipse(i * 10, i * 10, 20, 20);
            }
            //
            this.PixelSize = 32;
            this.Gamma     = 1;
        }
Exemplo n.º 20
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;
                }
            }
        }
Exemplo n.º 21
0
        void RunSampleB(PixelFarm.Drawing.Painter p)
        {
            //version 2:
            //1. create simple vertical line to test agg's lcd rendernig technique
            //create gray-scale actual image
            ActualImage      glyphImg = new ActualImage(100, 100, PixelFormat.ARGB32);
            AggRenderSurface glyph2d  = new AggRenderSurface(glyphImg);
            AggPainter       painter  = new AggPainter(glyph2d);

            //
            painter.StrokeColor = PixelFarm.Drawing.Color.Black;
            painter.StrokeWidth = 2.0f;
            painter.DrawLine(2, 0, 3, 15);//not need to scale3
            //
            //clear surface bg
            p.Clear(PixelFarm.Drawing.Color.White);
            //--------------------------
            var aggPainer = (PixelFarm.Agg.AggPainter)p;

            BlendWithLcdTechnique(aggPainer.RenderSurface.DestActualImage, glyphImg, PixelFarm.Drawing.Color.Black);
            //---------------
            p.DrawImage(glyphImg, 0, 50);
            //---------------
        }
Exemplo n.º 22
0
        //template<class Scanline, class Ras>
        public void RenderGourand(Painter p)
        {
            float alpha = this.AlphaValue;
            float brc   = 1;

#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr());
#else
#endif
            ////var destImage = gx.DestImage;
            ////span_allocator span_alloc = new span_allocator();

            //specific for agg
            AggPainter painter = p as AggPainter;
            if (painter == null)
            {
                return;
            }

            //
            AggRenderSurface   aggRdsf        = painter.RenderSurface;
            SpanGenGouraudRGBA gouraudSpanGen = new SpanGenGouraudRGBA();
            aggRdsf.ScanlineRasterizer.ResetGamma(new GammaLinear(0.0f, this.LinearGamma));
            double d = this.DilationValue;
            // Six triangles

            double xc = (m_x[0] + m_x[1] + m_x[2]) / 3.0;
            double yc = (m_y[0] + m_y[1] + m_y[2]) / 3.0;
            double x1 = (m_x[1] + m_x[0]) / 2 - (xc - (m_x[1] + m_x[0]) / 2);
            double y1 = (m_y[1] + m_y[0]) / 2 - (yc - (m_y[1] + m_y[0]) / 2);
            double x2 = (m_x[2] + m_x[1]) / 2 - (xc - (m_x[2] + m_x[1]) / 2);
            double y2 = (m_y[2] + m_y[1]) / 2 - (yc - (m_y[2] + m_y[1]) / 2);
            double x3 = (m_x[0] + m_x[2]) / 2 - (xc - (m_x[0] + m_x[2]) / 2);
            double y3 = (m_y[0] + m_y[2]) / 2 - (yc - (m_y[0] + m_y[2]) / 2);
            gouraudSpanGen.SetColor(ColorEx.Make(1, 0, 0, alpha),
                                    ColorEx.Make(0, 1, 0, alpha),
                                    ColorEx.Make(brc, brc, brc, alpha));
            gouraudSpanGen.SetTriangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d);

            var tmpVxs = _tmpVxs;
            painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen);
            tmpVxs.Clear();
            gouraudSpanGen.SetColor(ColorEx.Make(0, 1, 0, alpha),
                                    ColorEx.Make(0, 0, 1, alpha),
                                    ColorEx.Make(brc, brc, brc, alpha));
            gouraudSpanGen.SetTriangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d);
            painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen);
            tmpVxs.Clear();
            gouraudSpanGen.SetColor(ColorEx.Make(0, 0, 1, alpha),
                                    ColorEx.Make(1, 0, 0, alpha),
                                    ColorEx.Make(brc, brc, brc, alpha));
            gouraudSpanGen.SetTriangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d);
            painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen);
            tmpVxs.Clear();
            brc = 1 - brc;
            gouraudSpanGen.SetColor(ColorEx.Make(1, 0, 0, alpha),
                                    ColorEx.Make(0, 1, 0, alpha),
                                    ColorEx.Make(brc, brc, brc, alpha));
            gouraudSpanGen.SetTriangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d);
            painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen);
            tmpVxs.Clear();
            gouraudSpanGen.SetColor(ColorEx.Make(0, 1, 0, alpha),
                                    ColorEx.Make(0, 0, 1, alpha),
                                    ColorEx.Make(brc, brc, brc, alpha));
            gouraudSpanGen.SetTriangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d);
            painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen);
            tmpVxs.Clear();
            gouraudSpanGen.SetColor(ColorEx.Make(0, 0, 1, alpha),
                                    ColorEx.Make(1, 0, 0, alpha),
                                    ColorEx.Make(brc, brc, brc, alpha));
            gouraudSpanGen.SetTriangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d);
            painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen);
            tmpVxs.Clear();
        }
Exemplo n.º 23
0
        public override void Draw(Painter p)
        {
            if (p is GdiPlusPainter)
            {
                DrawWithWinGdi((GdiPlusPainter)p);
                return;
            }
            AggPainter       p2      = (AggPainter)p;
            AggRenderSurface aggRdsf = p2.RenderSurface;
            var widgetsSubImage      = aggRdsf.DestImage;
            var scline = aggRdsf.ScanlinePacked8;
            int width  = (int)widgetsSubImage.Width;
            int height = (int)widgetsSubImage.Height;

            //change value ***
            if (isMaskSliderValueChanged)
            {
                generate_alpha_mask(aggRdsf.ScanlineRasToDestBitmap, aggRdsf.ScanlinePacked8, aggRdsf.ScanlineRasterizer, width, height);
                this.isMaskSliderValueChanged = false;
            }
            var rasterizer = aggRdsf.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 = aggRdsf.ScanlineRasToDestBitmap;
            // draw a background to show how the mask is working better
            int rect_w = 30;

            VectorToolBox.GetFreeVxs(out var v1);
            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, ColorEx.Make(.9f, .9f, .9f));
                    }
                }
            }
            VectorToolBox.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();
            //lionShape.ApplyTransform(transform);

            throw new NotImplementedException();

            //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);
        }
Exemplo n.º 24
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
        }
Exemplo n.º 25
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();
                }
            }
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
0
        void UpdateRenderOutput()
        {
            if (!_readyToRender)
            {
                return;
            }
            //
            if (g == null)
            {
                destImg = new ActualImage(800, 600, PixelFormat.ARGB32);
                _aggsx  = new AggRenderSurface(destImg); //no platform
                painter = new AggPainter(_aggsx);
                winBmp  = new Bitmap(destImg.Width, destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                g       = this.CreateGraphics();

                painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14);

                _devVxsTextPrinter = new VxsTextPrinter(painter, _basicOptions.OpenFontStore);
                _devVxsTextPrinter.TargetCanvasPainter = painter;
                _devVxsTextPrinter.ScriptLang          = _basicOptions.ScriptLang;
                _devVxsTextPrinter.PositionTechnique   = Typography.TextLayout.PositionTechnique.OpenFont;
                //_devGdiTextPrinter.TargetGraphics = g;
            }

            if (string.IsNullOrEmpty(this.txtInputChar.Text))
            {
                return;
            }

            //test option use be used with lcd subpixel rendering.
            //this demonstrate how we shift a pixel for subpixel rendering tech
            _devVxsTextPrinter.UseWithLcdSubPixelRenderingTechnique = _contourAnalysisOpts.SetupPrinterLayoutForLcdSubPix;



            //1. read typeface from font file
            TypographyTest.RenderChoice renderChoice = _basicOptions.RenderChoice;
            switch (renderChoice)
            {
            case TypographyTest.RenderChoice.RenderWithGdiPlusPath:
                //not render in this example
                //see more at ...
                break;

            case TypographyTest.RenderChoice.RenderWithTextPrinterAndMiniAgg:
            {
                //clear previous draw
                painter.Clear(PixelFarm.Drawing.Color.White);
                painter.UseSubPixelLcdEffect = _contourAnalysisOpts.LcdTechnique;
                painter.FillColor            = PixelFarm.Drawing.Color.Black;

                selectedTextPrinter                   = _devVxsTextPrinter;
                selectedTextPrinter.Typeface          = _basicOptions.Typeface;
                selectedTextPrinter.FontSizeInPoints  = _basicOptions.FontSizeInPoints;
                selectedTextPrinter.ScriptLang        = _basicOptions.ScriptLang;
                selectedTextPrinter.PositionTechnique = _basicOptions.PositionTech;

                selectedTextPrinter.HintTechnique  = _glyphRenderOptions.HintTechnique;
                selectedTextPrinter.EnableLigature = _glyphRenderOptions.EnableLigature;


                glyphTextureBitmapGenUserControl1.SelectedTypeface = _basicOptions.Typeface;
                glyphTextureBitmapGenUserControl1.FontSizeInPoints = _basicOptions.FontSizeInPoints;
                glyphTextureBitmapGenUserControl1.SelectedScriptLangs.Clear();
                glyphTextureBitmapGenUserControl1.SelectedScriptLangs.Add(_basicOptions.ScriptLang);

                //test print 3 lines
#if DEBUG
                GlyphDynamicOutline.dbugTestNewGridFitting    = _contourAnalysisOpts.EnableGridFit;
                GlyphDynamicOutline.dbugActualPosToConsole    = _contourAnalysisOpts.WriteFitOutputToConsole;
                GlyphDynamicOutline.dbugUseHorizontalFitValue = _contourAnalysisOpts.UseHorizontalFitAlignment;
#endif

                char[] printTextBuffer = this.txtInputChar.Text.ToCharArray();
                float  x_pos = 0, y_pos = 200;
                float  lineSpacingPx = selectedTextPrinter.FontLineSpacingPx;
                for (int i = 0; i < 1; ++i)
                {
                    selectedTextPrinter.DrawString(printTextBuffer, x_pos, y_pos);
                    y_pos -= lineSpacingPx;
                }


                //copy from Agg's memory buffer to gdi
                PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(destImg, winBmp);
                g.Clear(System.Drawing.Color.White);
                g.DrawImage(winBmp, new System.Drawing.Point(10, 0));
            }
            break;

            //==============================================
            //render 1 glyph for debug and test
            case TypographyTest.RenderChoice.RenderWithMsdfGen:
            case TypographyTest.RenderChoice.RenderWithSdfGen:
            {
                char     testChar = this.txtInputChar.Text[0];
                Typeface typeFace = _basicOptions.Typeface;
                RenderWithMsdfImg(typeFace, testChar, _basicOptions.FontSizeInPoints);
            }
            break;

            case TypographyTest.RenderChoice.RenderWithMiniAgg_SingleGlyph:
            {
                selectedTextPrinter = _devVxsTextPrinter;
                //for test only 1 char
                RenderSingleCharWithMiniAgg(
                    _basicOptions.Typeface,
                    this.txtInputChar.Text[0],
                    _basicOptions.FontSizeInPoints);
            }
            break;

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 28
0
        //template<class Scanline, class Ras>
        public void RenderGourand(Painter p)
        {
            float alpha = this.AlphaValue;
            float brc   = 1;

#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr());
#else
#endif
            ////var destImage = gx.DestImage;
            ////span_allocator span_alloc = new span_allocator();

            //specific for agg
            AggPainter painter = p as AggPainter;
            if (painter == null)
            {
                return;
            }

            //
            AggRenderSurface      aggsx          = painter.RenderSurface;
            RGBAGouraudSpanGen    gouraudSpanGen = new RGBAGouraudSpanGen();
            GouraudVerticeBuilder grBuilder      = new GouraudVerticeBuilder();

            aggsx.ScanlineRasterizer.ResetGamma(new GammaLinear(0.0f, this.LinearGamma));

            grBuilder.DilationValue = (float)this.DilationValue;
            // Six triangles

            double xc = (_x[0] + _x[1] + _x[2]) / 3.0;
            double yc = (_y[0] + _y[1] + _y[2]) / 3.0;
            double x1 = (_x[1] + _x[0]) / 2 - (xc - (_x[1] + _x[0]) / 2);
            double y1 = (_y[1] + _y[0]) / 2 - (yc - (_y[1] + _y[0]) / 2);
            double x2 = (_x[2] + _x[1]) / 2 - (xc - (_x[2] + _x[1]) / 2);
            double y2 = (_y[2] + _y[1]) / 2 - (yc - (_y[2] + _y[1]) / 2);
            double x3 = (_x[0] + _x[2]) / 2 - (xc - (_x[0] + _x[2]) / 2);
            double y3 = (_y[0] + _y[2]) / 2 - (yc - (_y[0] + _y[2]) / 2);
            grBuilder.SetColor(ColorEx.Make(1, 0, 0, alpha),
                               ColorEx.Make(0, 1, 0, alpha),
                               ColorEx.Make(brc, brc, brc, alpha));
            grBuilder.SetTriangle(_x[0], _y[0], _x[1], _y[1], xc, yc);

            GouraudVerticeBuilder.CoordAndColor c0, c1, c2;
            grBuilder.GetArrangedVertices(out c0, out c1, out c2);
            gouraudSpanGen.SetColorAndCoords(c0, c1, c2);

            using (Tools.BorrowVxs(out var v1))
            {
                painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen);
                v1.Clear();

                //
                grBuilder.SetColor(
                    ColorEx.Make(0, 1, 0, alpha),
                    ColorEx.Make(0, 0, 1, alpha),
                    ColorEx.Make(brc, brc, brc, alpha));
                grBuilder.SetTriangle(_x[1], _y[1], _x[2], _y[2], xc, yc);
                grBuilder.GetArrangedVertices(out c0, out c1, out c2);
                gouraudSpanGen.SetColorAndCoords(c0, c1, c2);

                painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen);
                v1.Clear();

                //
                grBuilder.SetColor(ColorEx.Make(0, 0, 1, alpha),
                                   ColorEx.Make(1, 0, 0, alpha),
                                   ColorEx.Make(brc, brc, brc, alpha));
                grBuilder.SetTriangle(_x[2], _y[2], _x[0], _y[0], xc, yc);
                grBuilder.GetArrangedVertices(out c0, out c1, out c2);
                gouraudSpanGen.SetColorAndCoords(c0, c1, c2);
                painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen);
                v1.Clear();
                //
                brc = 1 - brc;
                grBuilder.SetColor(ColorEx.Make(1, 0, 0, alpha),
                                   ColorEx.Make(0, 1, 0, alpha),
                                   ColorEx.Make(brc, brc, brc, alpha));
                grBuilder.SetTriangle(_x[0], _y[0], _x[1], _y[1], x1, y1);
                grBuilder.GetArrangedVertices(out c0, out c1, out c2);
                gouraudSpanGen.SetColorAndCoords(c0, c1, c2);
                painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen);
                v1.Clear();

                grBuilder.SetColor(ColorEx.Make(0, 1, 0, alpha),
                                   ColorEx.Make(0, 0, 1, alpha),
                                   ColorEx.Make(brc, brc, brc, alpha));
                grBuilder.SetTriangle(_x[1], _y[1], _x[2], _y[2], x2, y2);
                grBuilder.GetArrangedVertices(out c0, out c1, out c2);
                gouraudSpanGen.SetColorAndCoords(c0, c1, c2);
                painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen);
                v1.Clear();
                //
                grBuilder.SetColor(ColorEx.Make(0, 0, 1, alpha),
                                   ColorEx.Make(1, 0, 0, alpha),
                                   ColorEx.Make(brc, brc, brc, alpha));
                grBuilder.SetTriangle(_x[2], _y[2], _x[0], _y[0], x3, y3);
                grBuilder.GetArrangedVertices(out c0, out c1, out c2);
                gouraudSpanGen.SetColorAndCoords(c0, c1, c2);
                painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen);
                v1.Clear();
            }
        }
Exemplo n.º 29
0
        public GlyphImage CreateGlyphImage(GlyphPathBuilder builder, float pxscale)
        {
            //1. create

            var txToVxs = new GlyphTranslatorToVxs();

            builder.ReadShapes(txToVxs);
            //
            //create new one
            var glyphVxs = new VertexStore();

            txToVxs.WriteOutput(glyphVxs, pxscale);
            //find bound
            //--------------------------------------------
            //GlyphImage glyphImg = new GlyphImage()
            RectD bounds = new RectD();

            BoundingRect.GetBoundingRect(new VertexStoreSnap(glyphVxs), ref bounds);

            ////--------------------------------------------
            int w = (int)System.Math.Ceiling(bounds.Width);
            int h = (int)System.Math.Ceiling(bounds.Height);

            if (w < 5)
            {
                w = 5;
            }
            if (h < 5)
            {
                h = 5;
            }
            ////translate to positive quadrant
            double dx = (bounds.Left < 0) ? -bounds.Left : 0;
            double dy = (bounds.Bottom < 0) ? -bounds.Bottom : 0;

            //we need some borders
            int horizontal_margin = 1; //'margin' 1px
            int vertical_margin   = 1; //margin 1 px

            dx += horizontal_margin;   //+ left margin
            dy += vertical_margin;     //+ top margin
                                       //--------------------------------------------
                                       //create glyph img


            w = (int)Math.Ceiling(dx + w + horizontal_margin); //+right margin
            h = (int)Math.Ceiling(dy + h + vertical_margin);   //+bottom margin

            ActualImage      img     = new ActualImage(w, h, PixelFormat.ARGB32);
            AggRenderSurface aggsx   = new AggRenderSurface(img);
            AggPainter       painter = new AggPainter(aggsx);

            if (TextureKind == TextureKind.StencilLcdEffect)
            {
                VertexStore vxs2 = new VertexStore();
                glyphVxs.TranslateToNewVxs(dx + 0.33f, dy, vxs2); //offset to proper x of subpixel rendering  ***
                glyphVxs = vxs2;
                //
                painter.UseSubPixelLcdEffect = true;

                //we use white glyph on black bg for this texture
                painter.Clear(Color.Black);
                painter.FillColor = Color.White;
                painter.Fill(glyphVxs);

                //apply sharpen filter
                //painter.DoFilter(new RectInt(0, h, w, 0), 2);
                //painter.DoFilter(new RectInt(0, h, w, 0), 2); //?
            }
            else
            {
                VertexStore vxs2 = new VertexStore();
                glyphVxs.TranslateToNewVxs(dx, dy, vxs2);
                glyphVxs = vxs2;

                painter.UseSubPixelLcdEffect = false;

                if (TextureKind == TextureKind.StencilGreyScale)
                {
                    painter.Clear(Color.Empty);
                    painter.FillColor = Color.Black;
                }
                else
                {
                    painter.Clear(BackGroundColor);
                    painter.FillColor = this.GlyphColor;
                }
                painter.Fill(glyphVxs);
            }
            //
            var glyphImage = new GlyphImage(w, h);

            glyphImage.TextureOffsetX = dx;
            glyphImage.TextureOffsetY = dy;
            glyphImage.SetImageBuffer(ActualImageExtensions.CopyImgBuffer(img, w), false);
            //copy data from agg canvas to glyph image
            return(glyphImage);
        }