public void RenderScanline(
            IImageReaderWriter dest,
            ScanlineRasterizer sclineRas,
            Scanline scline,
            Color color)
        {
#if DEBUG
            int dbugMinScanlineCount = 0;
#endif

            //1. ensure single line buffer width
            _grayScaleLine.EnsureLineStride(dest.Width + 4);
            //2. setup vars
            byte[] dest_buffer = dest.GetBuffer();
            int    dest_w      = dest.Width;
            int    dest_h      = dest.Height;
            int    dest_stride = dest.Stride;
            int    src_w       = dest_w;
            int    src_stride  = dest_stride;
            //*** set color before call Blend()
            this._color = color;

            byte color_alpha = color.alpha;
            //---------------------------
            //3. loop, render single scanline with subpixel rendering

            byte[] lineBuff = _grayScaleLine.GetInternalBuffer();

            while (sclineRas.SweepScanline(scline))
            {
                //3.1. clear
                _grayScaleLine.Clear();
                //3.2. write grayscale span to temp buffer
                //3.3 convert to subpixel value and write to dest buffer
                //render solid single scanline
                int    num_spans = scline.SpanCount;
                byte[] covers    = scline.GetCovers();
                //render each span in the scanline
                for (int i = 1; i <= num_spans; ++i)
                {
                    ScanlineSpan span = scline.GetSpan(i);
                    if (span.len > 0)
                    {
                        //positive len
                        _grayScaleLine.SubPixBlendSolidHSpan(span.x, span.len, color_alpha, covers, span.cover_index);
                    }
                    else
                    {
                        //fill the line, same coverage area
                        int x  = span.x;
                        int x2 = (x - span.len - 1);
                        _grayScaleLine.SubPixBlendHL(x, x2, color_alpha, covers[span.cover_index]);
                    }
                }
                BlendScanline(dest_buffer, dest_stride, scline.Y, src_w, src_stride, lineBuff);
#if DEBUG
                dbugMinScanlineCount++;
#endif
            }
        }
Example #2
0
 public AggCanvasPainter(ImageGraphics2D graphic2d)
 {
     this.gx             = graphic2d;
     this.sclineRas      = gx.ScanlineRasterizer;
     this.stroke         = new Stroke(1);//default
     this.scline         = graphic2d.ScanlinePacked8;
     this.sclineRasToBmp = graphic2d.ScanlineRasToDestBitmap;
 }
 public AggCanvasPainter(ImageGraphics2D graphic2d)
 {
     this.gx = graphic2d;
     this.sclineRas = gx.ScanlineRasterizer;
     this.stroke = new Stroke(1);//default
     this.scline = graphic2d.ScanlinePacked8;
     this.sclineRasToBmp = graphic2d.ScanlineRasToDestBitmap;
 }
        public void RenderWithColor(IImageReaderWriter dest,
                                    ScanlineRasterizer sclineRas,
                                    Scanline scline,
                                    Color color)
        {
            if (!sclineRas.RewindScanlines())
            {
                return;
            }                                             //early exit
            //-----------------------------------------------
            scline.ResetSpans(sclineRas.MinX, sclineRas.MaxX);
            switch (this.ScanlineRenderMode)
            {
            default:
            {
                while (sclineRas.SweepScanline(scline))
                {
                    //render solid single scanline
                    int    y         = scline.Y;
                    int    num_spans = scline.SpanCount;
                    byte[] covers    = scline.GetCovers();
                    //render each span in the scanline
                    for (int i = 1; i <= num_spans; ++i)
                    {
                        ScanlineSpan span = scline.GetSpan(i);
                        if (span.len > 0)
                        {
                            //positive len
                            dest.BlendSolidHSpan(span.x, y, span.len, color, covers, span.cover_index);
                        }
                        else
                        {
                            //fill the line, same coverage area
                            int x  = span.x;
                            int x2 = (x - span.len - 1);
                            dest.BlendHL(x, y, x2, color, covers[span.cover_index]);
                        }
                    }
                }
            }
            break;

            case Agg.ScanlineRenderMode.SubPixelRendering:
            {
                scSubPixRas.RenderScanline(dest, sclineRas, scline, color);
            }
            break;

            case Agg.ScanlineRenderMode.Custom:
            {
                while (sclineRas.SweepScanline(scline))
                {
                    CustomRenderSingleScanLine(dest, scline, color);
                }
            }
            break;
            }
        }
Example #5
0
        //-------------
        public CanvasPainter(Graphics2D graphic2d)
        {
            this.gx        = graphic2d;
            this.sclineRas = gx.ScanlineRasterizer;
            this.stroke    = new Stroke(1);//default

            this.scline         = graphic2d.ScanlinePacked8;
            this.sclineRasToBmp = graphic2d.ScanlineRasToDestBitmap;
            this.textPrinter    = new TextPrinter();
        }
        public void RenderWithSpan(IImageReaderWriter dest,
                                   ScanlineRasterizer sclineRas,
                                   Scanline scline,
                                   ISpanGenerator spanGenerator)
        {
            if (!sclineRas.RewindScanlines())
            {
                return;
            }                                             //early exit
            //-----------------------------------------------

            scline.ResetSpans(sclineRas.MinX, sclineRas.MaxX);

            spanGenerator.Prepare();


            if (dest.Stride / 4 > (tempSpanColors.AllocatedSize))
            {
                //if not enough -> alloc more
                tempSpanColors.Clear(dest.Stride / 4);
            }

            ColorRGBA[] colorArray = tempSpanColors.Array;

            while (sclineRas.SweepScanline(scline))
            {
                //render single scanline
                int    y         = scline.Y;
                int    num_spans = scline.SpanCount;
                byte[] covers    = scline.GetCovers();

                for (int i = 1; i <= num_spans; ++i)
                {
                    ScanlineSpan span             = scline.GetSpan(i);
                    int          x                = span.x;
                    int          span_len         = span.len;
                    bool         firstCoverForAll = false;

                    if (span_len < 0)
                    {
                        span_len         = -span_len;
                        firstCoverForAll = true;
                    } //make absolute value

                    //1. generate colors -> store in colorArray
                    spanGenerator.GenerateColors(colorArray, 0, x, y, span_len);

                    //2. blend color in colorArray to destination image
                    dest.BlendColorHSpan(x, y, span_len,
                                         colorArray, 0,
                                         covers, span.cover_index,
                                         firstCoverForAll);
                }
            }
        }
Example #7
0
 public void Draw(
     ScanlineRasToDestBitmapRenderer sclineRasToBmp,
     ScanlineRasterizer ras,
     Scanline sl,
     IImageReaderWriter destImage, ColorRGBA color,
     double x, double y)
 {
     ras.Reset();
     ras.MoveTo(x * m_size, y * m_size);
     ras.LineTo(x * m_size + m_size, y * m_size);
     ras.LineTo(x * m_size + m_size, y * m_size + m_size);
     ras.LineTo(x * m_size, y * m_size + m_size);
     sclineRasToBmp.RenderWithColor(destImage, ras, sl, color);
 }
Example #8
0
        public AggPainter(AggRenderSurface aggsx)
        {
            this._aggsx         = aggsx;
            this.sclineRas      = _aggsx.ScanlineRasterizer;
            this.stroke         = new Stroke(1);//default
            this.scline         = aggsx.ScanlinePacked8;
            this.sclineRasToBmp = aggsx.ScanlineRasToDestBitmap;
            _orientation        = DrawBoardOrientation.LeftBottom;

            //from membuffer
            _bxt = new BitmapBuffer(aggsx.Width,
                                    aggsx.Height,
                                    PixelFarm.Agg.ActualImage.GetBuffer(aggsx.DestActualImage));
        }
 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]);
     }
 }
Example #10
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            //specific for agg
            if (!(p is AggPainter))
            {
                return;
            }


            throw new NotSupportedException();

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

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

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

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

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

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

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

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

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

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

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

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

            //                VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
            //                ras.add_path(eb);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor);
            //#endif
            //            }
        }
Example #11
0
        public override void Draw(CanvasPainter p)
        {
            //specific for agg
            if (!(p is AggCanvasPainter))
            {
                return;
            }


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

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

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

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

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

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

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

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

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

            //                VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
            //                ras.add_path(eb);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor);
            //#endif
            //            }
        }
        public void RenderWithSpan(IImageReaderWriter dest,
                ScanlineRasterizer sclineRas,
                Scanline scline,
                ISpanGenerator spanGenerator)
        {
            if (!sclineRas.RewindScanlines()) { return; } //early exit
            //-----------------------------------------------

            scline.ResetSpans(sclineRas.MinX, sclineRas.MaxX);
            spanGenerator.Prepare();
            if (dest.Stride / 4 > (tempSpanColors.AllocatedSize))
            {
                //if not enough -> alloc more
                tempSpanColors.Clear(dest.Stride / 4);
            }

            Color[] colorArray = tempSpanColors.Array;
            while (sclineRas.SweepScanline(scline))
            {
                //render single scanline 
                int y = scline.Y;
                int num_spans = scline.SpanCount;
                byte[] covers = scline.GetCovers();
                for (int i = 1; i <= num_spans; ++i)
                {
                    ScanlineSpan span = scline.GetSpan(i);
                    int x = span.x;
                    int span_len = span.len;
                    bool firstCoverForAll = false;
                    if (span_len < 0)
                    {
                        span_len = -span_len;
                        firstCoverForAll = true;
                    } //make absolute value

                    //1. generate colors -> store in colorArray
                    spanGenerator.GenerateColors(colorArray, 0, x, y, span_len);
                    //2. blend color in colorArray to destination image
                    dest.BlendColorHSpan(x, y, span_len,
                        colorArray, 0,
                        covers, span.cover_index,
                        firstCoverForAll);
                }
            }
        }
        public void RenderWithColor(IImageReaderWriter dest,
                ScanlineRasterizer sclineRas,
                Scanline scline,
                Color color)
        {
            if (!sclineRas.RewindScanlines()) { return; } //early exit
            //----------------------------------------------- 
            scline.ResetSpans(sclineRas.MinX, sclineRas.MaxX);
            switch (this.ScanlineRenderMode)
            {
                default:
                    {
                        //prev mode  
                        //this mode 
                        while (sclineRas.SweepScanline(scline))
                        {
                            //render solid single scanline
                            int y = scline.Y;
                            int num_spans = scline.SpanCount;
                            byte[] covers = scline.GetCovers();
                            //render each span in the scanline
                            for (int i = 1; i <= num_spans; ++i)
                            {
                                ScanlineSpan span = scline.GetSpan(i);
                                if (span.len > 0)
                                {
                                    //positive len 
                                    dest.BlendSolidHSpan(span.x, y, span.len, color, covers, span.cover_index);
                                }
                                else
                                {
                                    //fill the line, same coverage area
                                    int x = span.x;
                                    int x2 = (x - span.len - 1);
                                    dest.BlendHL(x, y, x2, color, covers[span.cover_index]);
                                }
                            }
                        }
                    }
                    break;
                case Agg.ScanlineRenderMode.SubPixelRendering:
                    {
#if DEBUG
                        int dbugMinScanlineCount = 0;
#endif

                        while (sclineRas.SweepScanline(scline))
                        {
                            SubPixRender(dest, scline, color);
#if DEBUG
                            dbugMinScanlineCount++;
#endif
                        }
                    }
                    break;
                case Agg.ScanlineRenderMode.Custom:
                    {
                        while (sclineRas.SweepScanline(scline))
                        {
                            CustomRenderSingleScanLine(dest, scline, color);
                        }
                    }
                    break;
            }
        }
Example #14
0
 public override RectInt GetClippingRect()
 {
     return(ScanlineRasterizer.GetVectorClipBox());
 }
Example #15
0
 public override void SetClippingRect(RectInt rect)
 {
     ScanlineRasterizer.SetClipBox(rect);
 }