예제 #1
0
        private void _InternalRender(IVertexSource vertexSource, RGBA_Bytes color)
        {
            if (_clipBuffer != null)
            {
                // DEBUG_saveImageBuffer(_clipBuffer);
                // DEBUG_saveImageBuffer(this.imb);

                IAlphaMask         alphaMask              = new AlphaMaskByteClipped(_clipBuffer, 1, 0);
                AlphaMaskAdaptor   imageAlphaMaskAdaptor  = new AlphaMaskAdaptor(aggGc.DestImage, alphaMask);
                ImageClippingProxy alphaMaskClippingProxy = new ImageClippingProxy(imageAlphaMaskAdaptor);

                var scanlineRenderer = new ScanlineRenderer();
                var rasterizer       = new ScanlineRasterizer();
                var scanlineCache    = new ScanlineCachePacked8();


                VertexSourceApplyTransform trans = new VertexSourceApplyTransform(vertexSource, aggGc.GetTransform());
                rasterizer.add_path(trans);

                scanlineRenderer.render_scanlines_aa_solid(alphaMaskClippingProxy, rasterizer, scanlineCache, color);
                aggGc.DestImage.MarkImageChanged();
            }
            else
            {
                aggGc.Render(vertexSource, color);
            }
        }
예제 #2
0
파일: Main.cs 프로젝트: brezza92/PixelFarm
    public static void Main()
    {
        //TEST
        //this is low-level scanline rasterizer
        //1. create vertex store
        VertexStore vxs = new VertexStore();

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

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

        sclineRas.AddPath(vxs);

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

        //4. create 32bit rgba bitmap blender

        MyBitmapBlender myBitmapBlender = new MyBitmapBlender();

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

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

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

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


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

                unsafe
                {
                    MemMx.memcpy((byte *)bmpdata.Scan0, (byte *)mem_ptr, membitmap.Width * membitmap.Height * 4);
                }
                bmp.UnlockBits(bmpdata);
                bmp.Save("test01.png");
            }
        }
    }
예제 #3
0
			internal InternalImageGraphics2D(ImageBuffer owner)
				: base()
			{
				ScanlineRasterizer rasterizer = new ScanlineRasterizer();
				ImageClippingProxy imageClippingProxy = new ImageClippingProxy(owner);

				Initialize(imageClippingProxy, rasterizer);
				ScanlineCache = new ScanlineCachePacked8();
			}
예제 #4
0
            internal InternalImageGraphics2D(ImageBuffer owner)
                : base()
            {
                ScanlineRasterizer rasterizer         = new ScanlineRasterizer();
                ImageClippingProxy imageClippingProxy = new ImageClippingProxy(owner);

                Initialize(imageClippingProxy, rasterizer);
                ScanlineCache = new ScanlineCachePacked8();
            }
예제 #5
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));
            }
        }
예제 #6
0
파일: Square.cs 프로젝트: BiDuc/PixelFarm
 public void Draw(
     DestBitmapRasterizer bmpRast,
     ScanlineRasterizer ras,
     Scanline sl,
     PixelProcessing.IBitmapBlender destImage, Color color,
     double x, double y)
 {
     ras.Reset();
     ras.MoveTo(x * _size, y * _size);
     ras.LineTo(x * _size + _size, y * _size);
     ras.LineTo(x * _size + _size, y * _size + _size);
     ras.LineTo(x * _size, y * _size + _size);
     bmpRast.RenderWithColor(destImage, ras, sl, color);
 }
예제 #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);
 }
예제 #8
0
        public AggRenderSurface()
        {
            //1. attach dst bmp before use this
            //2. you can detach this surface and attach to another bmp surface

            _pixelBlenderBGRA  = new PixelBlenderBGRA();
            _destBitmapBlender = new MyBitmapBlender();

            _bmpRasterizer = new DestBitmapRasterizer();
            _sclinePack8   = new ScanlinePacked8();
            _sclineRas     = new ScanlineRasterizer();

            _currentImgSpanGen     = _imgSpanGenBilinearClip;
            CurrentTransformMatrix = Affine.IdentityMatrix;
        }
 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]);
     }
 }
예제 #10
0
 public static void RenderSolidAllPaths(this ScanlineRasToDestBitmapRenderer sclineRasToBmp,
                                        IImageReaderWriter destImage,
                                        ScanlineRasterizer sclineRas,
                                        Scanline scline,
                                        VertexStore vxs,
                                        Drawing.Color[] colors,
                                        int[] path_id,
                                        int num_paths)
 {
     for (int i = 0; i < num_paths; ++i)
     {
         sclineRas.Reset();
         sclineRas.AddPath(new VertexStoreSnap(vxs, path_id[i]));
         sclineRasToBmp.RenderWithColor(destImage, sclineRas, scline, colors[i]);
     }
 }
예제 #11
0
 public AggPainter(AggRenderSurface aggsx)
 {
     //painter paint to target surface
     this._aggsx         = aggsx;
     this.sclineRas      = _aggsx.ScanlineRasterizer;
     this.stroke         = new Stroke(1);//default
     this.scline         = aggsx.ScanlinePacked8;
     this._bmpRasterizer = aggsx.BitmapRasterizer;
     _orientation        = DrawBoardOrientation.LeftBottom;
     //from membuffer
     _bxt = new BitmapBuffer(aggsx.Width,
                             aggsx.Height,
                             PixelFarm.CpuBlit.ActualBitmap.GetBuffer(aggsx.DestActualImage));
     _vectorTool      = new VectorTool();
     _useDefaultBrush = true;
 }
예제 #12
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
        }
예제 #13
0
        public void Draw(
            DestBitmapRasterizer bmpRast,
            ScanlineRasterizer ras,
            Scanline sl,
            PixelProcessing.IBitmapBlender destImage, Color color,
            double x, double y)
        {
#if DEBUG
            //low-level scanline rasterizer example
            ras.Reset();
            ras.dbugDevMoveTo(x * _size, y * _size);
            ras.dbugDevLineTo(x * _size + _size, y * _size);
            ras.dbugDevLineTo(x * _size + _size, y * _size + _size);
            ras.dbugDevLineTo(x * _size, y * _size + _size);
            bmpRast.RenderWithColor(destImage, ras, sl, color);
#endif
        }
예제 #14
0
 public AggRenderSurface(MemBitmap dstBmp)
 {
     //create from actual image
     _destBmp           = dstBmp;
     _pixelBlenderBGRA  = new PixelBlenderBGRA();
     _destBitmapBlender = new MyBitmapBlender(dstBmp, _pixelBlenderBGRA);
     //
     _bmpRasterizer = new DestBitmapRasterizer();
     _sclinePack8   = new ScanlinePacked8();
     _sclineRas     = new ScanlineRasterizer();
     //
     _sclineRas.SetClipBox(
         new RectInt(0, 0,
                     _destWidth  = dstBmp.Width,  //**
                     _destHeight = dstBmp.Height) //**
         );
     CurrentTransformMatrix = Affine.IdentityMatrix;
 }
예제 #15
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);
            }
        }
예제 #16
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;
                }
            }
        }
예제 #17
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
        }
예제 #18
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);
        }
 public void SetClippingRect(RectInt rect)
 {
     ScanlineRasterizer.SetClipBox(rect);
 }
예제 #20
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            //specific for agg
            if (!(p is AggPainter))
            {
                return;
            }


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

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

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

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


                DestBitmapRasterizer bmpRas = asx.BitmapRasterizer;

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

                        ////

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

                        //

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

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

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

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

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

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

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

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

            //                VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
            //                ras.add_path(eb);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor);
            //#endif
            //            }
        }
예제 #21
0
        public void DrawTo(Graphics2D graphics2D, Mesh meshToDraw, RGBA_Bytes partColorIn, double minZ, double maxZ)
        {
            RGBA_Floats partColor = partColorIn.GetAsRGBA_Floats();

            graphics2D.Rasterizer.gamma(new gamma_power(.3));
            RenderPoint[] points = new RenderPoint[3] {
                new RenderPoint(), new RenderPoint(), new RenderPoint()
            };

            foreach (Face face in meshToDraw.Faces)
            {
                int     i      = 0;
                Vector3 normal = Vector3.TransformVector(face.normal, trackballTumbleWidget.ModelviewMatrix).GetNormal();
                if (normal.z > 0)
                {
                    foreach (FaceEdge faceEdge in face.FaceEdges())
                    {
                        points[i].position = trackballTumbleWidget.GetScreenPosition(faceEdge.firstVertex.Position);

                        Vector3 transformedPosition = Vector3.TransformPosition(faceEdge.firstVertex.Position, trackballTumbleWidget.ModelviewMatrix);
                        points[i].z = transformedPosition.z;
                        i++;
                    }

                    RGBA_Floats polyDrawColor = new RGBA_Floats();
                    double      L             = Vector3.Dot(lightNormal, normal);
                    if (L > 0.0f)
                    {
                        polyDrawColor = partColor * lightIllumination * L;
                    }

                    polyDrawColor = RGBA_Floats.ComponentMax(polyDrawColor, partColor * ambiantIllumination);
                    for (i = 0; i < 3; i++)
                    {
                        double ratio      = (points[i].z - minZ) / (maxZ - minZ);
                        int    ratioInt16 = (int)(ratio * 65536);
                        points[i].color = new RGBA_Bytes(polyDrawColor.Red0To255, ratioInt16 >> 8, ratioInt16 & 0xFF);
                    }


#if true
                    scanline_unpacked_8 sl  = new scanline_unpacked_8();
                    ScanlineRasterizer  ras = new ScanlineRasterizer();
                    render_gouraud(graphics2D.DestImage, sl, ras, points);
#else
                    IRecieveBlenderByte oldBlender = graphics2D.DestImage.GetRecieveBlender();
                    graphics2D.DestImage.SetRecieveBlender(new BlenderZBuffer());
                    graphics2D.Render(polygonProjected, renderColor);
                    graphics2D.DestImage.SetRecieveBlender(oldBlender);
#endif

                    byte[] buffer = graphics2D.DestImage.GetBuffer();
                    int    pixels = graphics2D.DestImage.Width * graphics2D.DestImage.Height;
                    for (int pixelIndex = 0; pixelIndex < pixels; pixelIndex++)
                    {
                        buffer[pixelIndex * 4 + ImageBuffer.OrderR] = buffer[pixelIndex * 4 + ImageBuffer.OrderR];
                        buffer[pixelIndex * 4 + ImageBuffer.OrderG] = buffer[pixelIndex * 4 + ImageBuffer.OrderR];
                        buffer[pixelIndex * 4 + ImageBuffer.OrderB] = buffer[pixelIndex * 4 + ImageBuffer.OrderR];
                    }
                }
            }
        }
 public RectInt GetClippingRect()
 {
     return(ScanlineRasterizer.GetVectorClipBox());
 }
예제 #23
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();
                }
            }
        }
예제 #24
0
        void SubPixRender(IImageReaderWriter destImage, Scanline scanline, Color color)
        {
            int y         = scanline.Y;
            int num_spans = scanline.SpanCount;

            byte[]             covers = scanline.GetCovers();
            ScanlineRasterizer ras    = gfx.ScanlineRasterizer;
            var rasToBmp = gfx.ScanlineRasToDestBitmap;
            //------------------------------------------
            Color bgColor = Color.White;
            float cb_R    = bgColor.R / 255f;
            float cb_G    = bgColor.G / 255f;
            float cb_B    = bgColor.B / 255f;
            float cf_R    = color.R / 255f;
            float cf_G    = color.G / 255f;
            float cf_B    = color.B / 255f;

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

            for (int i = 0; i <= num_spans; ++i)
            {
                //render span by span
                ScanlineSpan span       = scanline.GetSpan(i);
                int          x          = span.x;
                int          num_pix    = span.len;
                int          coverIndex = span.cover_index;
                //test subpixel rendering concept
                //----------------------------------------------------

                int prev_cover = 0;
                while (num_pix > 0)
                {
                    byte coverageValue = covers[coverIndex++];
                    if (coverageValue >= 255)
                    {
                        //100% cover
                        int a = (coverageValue * color.Alpha0To255) >> 8;
                        m_square.Draw(rasToBmp,
                                      ras, m_sl, destImage,
                                      Color.FromArgb(a, Color.FromArgb(color.red, color.green, color.blue)),
                                      x, y);
                        prev_cover = 255;//full
                    }
                    else
                    {
                        //check direction :
                        bool isUpHill = (coverageValue % 2) > 0;
                        //--------------------------------------------------------------------
                        //TODO: review here
                        //in somecase, demo3, isUpHill2 != isUpHill
                        //but we skip it, because we don't want context color around the point
                        //so when we use in fragment shader we can pick up a single color
                        //and determine what color it should be
                        bool isUpHill2 = coverageValue > prev_cover;
                        if (isUpHill != isUpHill2)
                        {
                        }
                        //--------------------------------------------------------------------
                        prev_cover = coverageValue;
                        byte  c_r, c_g, c_b;
                        float subpix_percent = ((float)(coverageValue) / 256f);
                        if (coverageValue < cover_1_3)
                        {
                            //assume LCD color arrangement is RGB
                            if (isUpHill)
                            {
                                c_r = bgColor.R;
                                c_g = bgColor.G;
                                c_b = (byte)(mix(cb_B, cf_B, subpix_percent) * 255);
                            }
                            else
                            {
                                c_r = (byte)(mix(cb_R, cf_R, subpix_percent) * 255);
                                c_g = bgColor.G;
                                c_b = bgColor.B;
                            }


                            int a = (coverageValue * color.Alpha0To255) >> 8;
                            m_square.Draw(rasToBmp,
                                          ras, m_sl, destImage,
                                          Color.FromArgb(a, Color.FromArgb(c_r, c_g, c_b)),
                                          x, y);
                        }
                        else if (coverageValue < cover_2_3)
                        {
                            if (isUpHill)
                            {
                                c_r = bgColor.R;
                                c_g = (byte)(mix(cb_G, cf_G, subpix_percent) * 255);
                                c_b = (byte)(mix(cb_B, cf_B, 1) * 255);
                            }
                            else
                            {
                                c_r = (byte)(mix(cb_R, cf_R, 1) * 255);
                                c_g = (byte)(mix(cb_G, cf_G, subpix_percent) * 255);
                                c_b = bgColor.B;
                            }



                            int a = (coverageValue * color.Alpha0To255) >> 8;
                            m_square.Draw(rasToBmp,
                                          ras, m_sl, destImage,
                                          Color.FromArgb(a, Color.FromArgb(c_r, c_g, c_b)),
                                          x, y);
                        }
                        else
                        {
                            //cover > 2/3 but not full
                            if (isUpHill)
                            {
                                c_r = (byte)(mix(cb_R, cf_R, subpix_percent) * 255);
                                c_g = (byte)(mix(cb_G, cf_G, 1) * 255);
                                c_b = (byte)(mix(cb_B, cf_B, 1) * 255);
                            }
                            else
                            {
                                c_r = (byte)(mix(cb_R, cf_R, 1) * 255);
                                c_g = (byte)(mix(cb_G, cf_G, 1) * 255);
                                c_b = (byte)(mix(cb_B, cf_B, subpix_percent) * 255);
                            }


                            int a = (coverageValue * color.Alpha0To255) >> 8;
                            m_square.Draw(rasToBmp,
                                          ras, m_sl, destImage,
                                          Color.FromArgb(a, Color.FromArgb(c_r, c_g, c_b)),
                                          x, y);
                        }
                    }


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

            bmpReaderWrtier.ReloadImage(alphaBitmap);
            alphaMaskImageBuffer = new ChildImage(bmpReaderWrtier, new PixelBlenderGray(1));
            //create mask from alpahMaskImageBuffer
            alphaMask = new AlphaMaskByteClipped(alphaMaskImageBuffer, 1, 0);
#if USE_CLIPPING_ALPHA_MASK
            //alphaMaskImageBuffer.AttachBuffer(alphaBitmap.GetBuffer(), 20 * width + 20, width - 40, height - 40, width, 8, 1);
#else
            alphaMaskImageBuffer.attach(alphaByteArray, (int)cx, (int)cy, cx, 1);
#endif

            var            image         = new ChildImage(alphaMaskImageBuffer, new PixelBlenderGray(1), 1, 0, 8);
            ClipProxyImage clippingProxy = new ClipProxyImage(image);
            clippingProxy.Clear(Drawing.Color.Black);
            VertexSource.Ellipse ellipseForMask = new PixelFarm.Agg.VertexSource.Ellipse();
            System.Random        randGenerator  = new Random(1432);
            int i;
            int num = (int)maskAlphaSliderValue;

            var v1 = GetFreeVxs();
            for (i = 0; i < num; i++)
            {
                if (i == num - 1)
                {
                    //for the last one
                    ellipseForMask.Reset(Width / 2, Height / 2, 110, 110, 100);
                    rasterizer.AddPath(ellipseForMask.MakeVertexSnap(v1));
                    v1.Clear();
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, Drawing.Color.Make(0, 0, 0, 255));
                    ellipseForMask.Reset(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100);
                    rasterizer.AddPath(ellipseForMask.MakeVertexSnap(v1));
                    v1.Clear();
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, Drawing.Color.Make(255, 0, 0, 255));
                }
                else
                {
                    ellipseForMask.Reset(randGenerator.Next() % width,
                                         randGenerator.Next() % height,
                                         randGenerator.Next() % 100 + 20,
                                         randGenerator.Next() % 100 + 20,
                                         100);
                    // set the color to draw into the alpha channel.
                    // there is not very much reason to set the alpha as you will get the amount of
                    // transparency based on the color you draw.  (you might want some type of different edeg effect but it will be minor).
                    rasterizer.AddPath(ellipseForMask.MakeVxs(v1));
                    v1.Clear();
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack,
                                                   Drawing.Color.Make((int)((float)i / (float)num * 255), 0, 0, 255));
                }
            }
            ReleaseVxs(ref v1);
        }
예제 #26
0
        void SubPixRender(IImageReaderWriter destImage, Scanline scanline, ColorRGBA color)
        {
            int y         = scanline.Y;
            int num_spans = scanline.SpanCount;

            byte[]             covers = scanline.GetCovers();
            ScanlineRasterizer ras    = gfx.ScanlineRasterizer;
            var       rasToBmp        = gfx.ScanlineRasToDestBitmap;
            ColorRGBA prevColor       = ColorRGBA.White;

            for (int i = 0; i <= num_spans; ++i)
            {
                //render span by span
                ScanlineSpan span       = scanline.GetSpan(i);
                int          x          = span.x;
                int          num_pix    = span.len;
                int          coverIndex = span.cover_index;
                //test subpixel rendering concept
                //----------------------------------------------------

                int prev_cover = 0;
                while (num_pix > 0)
                {
                    int coverageValue = covers[coverIndex++];
                    if (coverageValue >= 255)
                    {
                        //100% cover
                        ColorRGBA newc = new ColorRGBA(color.red, color.green, color.blue);
                        prevColor = newc;
                        int a = (coverageValue * color.Alpha0To255) >> 8;
                        m_square.Draw(rasToBmp,
                                      ras, m_sl, destImage,
                                      new ColorRGBA(newc, a),
                                      x, y);
                        prev_cover = 255;//full
                    }
                    else
                    {
                        //check direction :
                        bool isLeftToRight = coverageValue >= prev_cover;
                        prev_cover = coverageValue;
                        byte  c_r, c_g, c_b;
                        float subpix_percent = ((float)(coverageValue) / 256f);
                        if (coverageValue < cover_1_3)
                        {
                            if (isLeftToRight)
                            {
                                c_r = 255;
                                c_g = 255;
                                c_b = (byte)(255 - (255f * (subpix_percent)));
                            }
                            else
                            {
                                c_r = (byte)(255 - (255f * (subpix_percent)));
                                c_g = 255;
                                c_b = 255;
                            }

                            ColorRGBA newc = prevColor = new ColorRGBA(c_r, c_g, c_b);
                            int       a    = (coverageValue * color.Alpha0To255) >> 8;
                            m_square.Draw(rasToBmp,
                                          ras, m_sl, destImage,
                                          new ColorRGBA(newc, a),
                                          x, y);
                        }
                        else if (coverageValue < cover_2_3)
                        {
                            if (isLeftToRight)
                            {
                                c_r = prevColor.blue;
                                c_g = (byte)(255 - (255f * (subpix_percent)));
                                c_b = color.blue;// (byte)(255 - (255f * (subpix_percent)));// color.blue;
                            }
                            else
                            {
                                c_r = color.blue;// (byte)(255 - (255f * (subpix_percent))); //color.blue;
                                c_g = (byte)(255 - (255f * (subpix_percent)));
                                c_b = 255;
                            }


                            ColorRGBA newc = prevColor = new ColorRGBA(c_r, c_g, c_b);
                            int       a    = (coverageValue * color.Alpha0To255) >> 8;
                            m_square.Draw(rasToBmp,
                                          ras, m_sl, destImage,
                                          new ColorRGBA(newc, a),
                                          x, y);
                        }
                        else
                        {
                            //cover > 2/3 but not full
                            if (isLeftToRight)
                            {
                                c_r = (byte)(255 - (255f * (subpix_percent)));
                                c_g = color.green;
                                c_b = color.blue;
                            }
                            else
                            {
                                c_r = prevColor.green;
                                c_g = prevColor.blue;
                                c_b = (byte)(255 - (255f * (subpix_percent)));
                            }

                            ColorRGBA newc = prevColor = new ColorRGBA(c_r, c_g, c_b);
                            int       a    = (coverageValue * color.Alpha0To255) >> 8;
                            m_square.Draw(rasToBmp,
                                          ras, m_sl, destImage,
                                          new ColorRGBA(newc, a),
                                          x, y);
                        }
                    }



                    ++x;
                    --num_pix;
                }
            }
        }