Beispiel #1
0
        //----------------------
        /// <summary>
        /// do filter at specific area
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="area"></param>
        public override void DoFilterBlurStack(RectInt area, int r)
        {
            ChildImage img = new ChildImage(this.gx.DestImage, gx.PixelBlender,
                                            area.Left, area.Bottom, area.Right, area.Top);

            filterMan.DoStackBlur(img, r);
        }
Beispiel #2
0
        public void DoFilterBlurRecursive(RectInt area, int r)
        {
            ChildImage img = new ChildImage(this.gx.DestImage, gx.PixelBlender,
                                            area.Left, area.Bottom, area.Right, area.Top);

            filterMan.DoRecursiveBlur(img, r);
        }
Beispiel #3
0
        void generate_alpha_mask(ScanlineRasToDestBitmapRenderer sclineRasToBmp, ScanlinePacked8 sclnPack, ScanlineRasterizer rasterizer, int width, int height)
        {
            alphaBitmap = new ActualImage(width, height, PixelFormat.GrayScale8);

            var bmpReaderWrtier = new MyImageReaderWriter(alphaBitmap);

            alphaMaskImageBuffer = new ChildImage(bmpReaderWrtier, new PixelBlenderGray(1));

            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(ColorRGBA.Black);

            VertexSource.Ellipse ellipseForMask = new PixelFarm.Agg.VertexSource.Ellipse();

            System.Random randGenerator = new Random(1432);


            int i;
            int num = (int)maskAlphaSliderValue;
            for (i = 0; i < num; i++)
            {
                if (i == num - 1)
                {
                    ellipseForMask.Reset(Width / 2, Height / 2, 110, 110, 100);
                    rasterizer.AddPath(ellipseForMask.MakeVertexSnap());
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(0, 0, 0, 255));

                    ellipseForMask.Reset(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100);
                    rasterizer.AddPath(ellipseForMask.MakeVertexSnap());
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(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());
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack,
                                                   ColorRGBA.Make((int)((float)i / (float)num * 255), 0, 0, 255));
                }
            }
        }
Beispiel #4
0
        public void OnDraw(Graphics2D graphics2D)
        {
            var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());

            graphics2D.UseSubPixelRendering = false;

            IPixelBlender NormalBlender = new PixelBlenderBGRA();
            IPixelBlender GammaBlender  = new PixelBlenderGammaBGRA(this.GammaValue);
            var           rasterGamma   = new ChildImage(widgetsSubImage, GammaBlender);


            ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage);
            ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);

            clippingProxyNormal.Clear(ColorRGBA.White);
            var rasterizer = graphics2D.ScanlineRasterizer;

            ScanlineUnpacked8 sl = new ScanlineUnpacked8();

            int size_mul = (int)this.PixelSize;

            CustomScanlineRasToBmp_EnlargedV3 ren_en = new CustomScanlineRasToBmp_EnlargedV3(size_mul, graphics2D.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, ColorRGBA.Black);

            //----------------------------------------
            ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;

            graphics2D.UseSubPixelRendering = true;
            sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black);
            rasterizer.ResetGamma(new GammaNone());
            graphics2D.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()));
            rasterizer.AddPath(StrokeHelp.MakeVxs(ps.Vxs, 2));
            //----------------------------------------

            sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new ColorRGBA(0, 150, 160, 200));
        }
Beispiel #5
0
        public override void Draw(CanvasPainter p)
        {
            //specific for agg

            if (p is PixelFarm.Agg.AggCanvasPainter)
            {
                var        p2 = (PixelFarm.Agg.AggCanvasPainter)p;
                Graphics2D gx = p2.Graphics;
                var        widgetsSubImage = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect());
                gx.UseSubPixelRendering = false;
                IPixelBlender  NormalBlender       = new PixelBlenderBGRA();
                IPixelBlender  GammaBlender        = new PixelBlenderGammaBGRA(this.GammaValue);
                var            rasterGamma         = new ChildImage(widgetsSubImage, GammaBlender);
                ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage);
                ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);
                clippingProxyNormal.Clear(Color.White);
                var rasterizer       = gx.ScanlineRasterizer;
                ScanlineUnpacked8 sl = new ScanlineUnpacked8();
                int size_mul         = (int)this.PixelSize;
                CustomScanlineRasToBmp_EnlargedSubPixelRendering ren_en = new CustomScanlineRasToBmp_EnlargedSubPixelRendering(size_mul, gx.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 = gx.ScanlineRasToDestBitmap;
                gx.UseSubPixelRendering = true;
                sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                rasterizer.ResetGamma(new GammaNone());
                gx.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()));
                var v1 = GetFreeVxs();
                rasterizer.AddPath(stroke.MakeVxs(ps.Vxs, v1));
                ReleaseVxs(ref v1);
                //----------------------------------------

                sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160));
            }
        }
Beispiel #6
0
        public void OnDraw(Graphics2D graphics2D)
        {
            var childImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());

            //IRecieveBlenderByte rasterBlender = new BlenderBGRA();
            var rasterGamma = new ChildImage(childImage, new PixelBlenderGammaBGRA(this.GammaValue));

            ClipProxyImage clippingProxyNormal = new ClipProxyImage(childImage);
            ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);

            clippingProxyNormal.Clear(ColorRGBA.White);

            var rasterizer = graphics2D.ScanlineRasterizer;
            var sl         = new ScanlineUnpacked8();


            int size_mul = this.PixelSize;

            CustomScanlineRasToBmp_EnlargedV2 sclineToBmpEn2 = new CustomScanlineRasToBmp_EnlargedV2(size_mul, graphics2D.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, ColorRGBA.Black);


            ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;

            sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.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]);

            rasterizer.AddPath((new Stroke(2)).MakeVxs(ps.Vxs));
            sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new ColorRGBA(0, 150, 160, 200));
        }
Beispiel #7
0
 public override void Draw(CanvasPainter p)
 {
     //this specific for agg
     if (p is PixelFarm.Agg.AggCanvasPainter)
     {
         PixelFarm.Agg.AggCanvasPainter p2 = (PixelFarm.Agg.AggCanvasPainter)p;
         Graphics2D gx         = p2.Graphics;
         var        childImage = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect());
         //IRecieveBlenderByte rasterBlender = new BlenderBGRA();
         var            rasterGamma         = new ChildImage(childImage, new PixelBlenderGammaBGRA(this.GammaValue));
         ClipProxyImage clippingProxyNormal = new ClipProxyImage(childImage);
         ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);
         clippingProxyNormal.Clear(Color.White);
         var rasterizer     = gx.ScanlineRasterizer;
         var sl             = new ScanlineUnpacked8();
         int size_mul       = this.PixelSize;
         var sclineToBmpEn2 = new CustomScanlineRasToBmp_EnlargedV2(size_mul, gx.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 = gx.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]);
         var v1 = GetFreeVxs();
         rasterizer.AddPath((new Stroke(2)).MakeVxs(ps.Vxs, v1));
         sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160));
         ReleaseVxs(ref v1);
     }
 }
        // Create
        //--------------------------------------------------------------------
        public void Create(IImageReaderWriter src)
        {
            // we are going to create a dialated image for filtering
            // we add m_dilation pixels to every side of the image and then copy the image in the x
            // dirrection into each end so that we can sample into this image to get filtering on x repeating
            // if the original image look like this
            //
            // 123456
            //
            // the new image would look like this
            //
            // 0000000000
            // 0000000000
            // 5612345612
            // 0000000000
            // 0000000000

            m_height          = (int)AggBasics.uceil(src.Height);
            m_width           = (int)AggBasics.uceil(src.Width);
            m_width_hr        = (int)AggBasics.uround(src.Width * LineAA.SUBPIXEL_SCALE);
            m_half_height_hr  = (int)AggBasics.uround(src.Height * LineAA.SUBPIXEL_SCALE / 2);
            m_offset_y_hr     = m_dilation_hr + m_half_height_hr - LineAA.SUBPIXEL_SCALE / 2;
            m_half_height_hr += LineAA.SUBPIXEL_SCALE / 2;

            int bufferWidth    = m_width + m_dilation * 2;
            int bufferHeight   = m_height + m_dilation * 2;
            int bytesPerPixel  = src.BitDepth / 8;
            int newSizeInBytes = bufferWidth * bufferHeight * bytesPerPixel;

            if (m_DataSizeInBytes < newSizeInBytes)
            {
                m_DataSizeInBytes = newSizeInBytes;
                m_data            = new byte[m_DataSizeInBytes];
            }


            m_buf = new ChildImage(m_data, 0, bufferWidth, bufferHeight, bufferWidth * bytesPerPixel, src.BitDepth, bytesPerPixel);

            byte[] destBuffer = m_buf.GetBuffer();
            byte[] srcBuffer  = src.GetBuffer();

            // copy the image into the middle of the dest
            for (int y = 0; y < m_height; y++)
            {
                for (int x = 0; x < m_width; x++)
                {
                    int sourceOffset = src.GetBufferOffsetXY(x, y);
                    int destOffset   = m_buf.GetBufferOffsetXY(m_dilation, y + m_dilation);
                    for (int channel = 0; channel < bytesPerPixel; channel++)
                    {
                        destBuffer[destOffset++] = srcBuffer[sourceOffset++];
                    }
                }
            }

            // copy the first two pixels form the end into the begining and from the begining into the end
            for (int y = 0; y < m_height; y++)
            {
                int s1Offset = src.GetBufferOffsetXY(0, y);
                int d1Offset = m_buf.GetBufferOffsetXY(m_dilation + m_width, y);

                int s2Offset = src.GetBufferOffsetXY(m_width - m_dilation, y);
                int d2Offset = m_buf.GetBufferOffsetXY(0, y);

                for (int x = 0; x < m_dilation; x++)
                {
                    for (int channel = 0; channel < bytesPerPixel; channel++)
                    {
                        destBuffer[d1Offset++] = srcBuffer[s1Offset++];
                        destBuffer[d2Offset++] = srcBuffer[s2Offset++];
                    }
                }
            }
        }
Beispiel #9
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
            //            }
        }
Beispiel #10
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            //render
            var            widgetsSubImage    = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());
            int            width              = widgetsSubImage.Width;
            int            height             = widgetsSubImage.Height;
            int            strokeWidth        = 1;
            var            clippedSubImage    = new ChildImage(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(ColorRGBA.White);
            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));

            //transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y);
            //transform *= Affine.NewScaling(spriteScale, spriteScale);
            //transform *= Affine.NewRotation(angle + Math.PI);
            //transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0);
            //transform *= Affine.NewTranslation(width / 2, height / 2);


            if (RenderAsScanline)
            {
                var rasterizer = graphics2D.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);
                Stroke stroke = new Stroke(strokeWidth);
                stroke.LineJoin = LineJoin.Round;
                var vxs = affTx.TransformToVxs(lionShape.Path.Vxs);
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;
                sclineRasToBmp.RenderSolidAllPaths(
                    imageClippingProxy,
                    rasterizer,
                    graphics2D.ScanlinePacked8,
                    vxs,
                    lionShape.Colors,
                    lionShape.PathIndexList,
                    lionShape.NumPaths);
            }
            else
            {
                double w = strokeWidth * affTx.GetScale();
                LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(w, new GammaNone());
                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;
                //VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);
                var vxs = affTx.TransformToVxs(lionShape.Path.Vxs);// trans.DoTransformToNewVxStorage();
                int j   = lionShape.NumPaths;
                for (int i = 0; i < j; ++i)
                {
                    rasterizer.RenderVertexSnap(
                        new VertexStoreSnap(vxs,
                                            lionShape.PathIndexList[i]),
                        lionShape.Colors[i]);
                }
            }

            base.OnDraw(graphics2D);
        }
Beispiel #11
0
        public void OnDraw(Graphics2D gx)
        {
            CanvasPainter painter = new CanvasPainter(gx);

            IImageReaderWriter backBuffer = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect());

            if (!didInit)
            {
                didInit = true;
                OnInitialize();
            }

            ChildImage image;

            if (backBuffer.BitDepth == 32)
            {
                image = new ChildImage(backBuffer, new PixelBlenderBGRA());
            }
            else
            {
                if (backBuffer.BitDepth != 24)
                {
                    throw new System.NotSupportedException();
                }
                image = new ChildImage(backBuffer, new PixelBlenderBGR());
            }

            painter.Clear(ColorRGBA.White);


            //ClipProxyImage dest = new ClipProxyImage(image);
            //gx.Clear(ColorRGBA.White);
            //gx.SetClippingRect(new RectInt(0, 0, Width, Height));
            //ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap;

            if (this.PerspectiveTransformType == Sample_Perspective.PerspectiveTransformType.Bilinear)
            {
                var      bound      = lionShape.Bounds;
                Bilinear txBilinear = Bilinear.RectToQuad(bound.Left,
                                                          bound.Bottom,
                                                          bound.Right,
                                                          bound.Top,
                                                          quadPolygonControl.GetInnerCoords());

                if (txBilinear.IsValid)
                {
                    painter.PaintSeries(txBilinear.TransformToVxs(lionShape.Path.Vxs),
                                        lionShape.Colors,
                                        lionShape.PathIndexList,
                                        lionShape.NumPaths);

                    RectD lionBound = lionShape.Bounds;

                    Ellipse ell = new Ellipse((lionBound.Left + lionBound.Right) * 0.5,
                                              (lionBound.Bottom + lionBound.Top) * 0.5,
                                              (lionBound.Right - lionBound.Left) * 0.5,
                                              (lionBound.Top - lionBound.Bottom) * 0.5,
                                              200);

                    VertexStore trans_ell = txBilinear.TransformToVxs(ell.MakeVxs());
                    painter.FillColor = ColorRGBA.Make(0.5f, 0.3f, 0.0f, 0.3f);
                    painter.Fill(trans_ell);

                    //-------------------------------------------------------------
                    //outline
                    double prevStrokeWidth = painter.StrokeWidth;
                    painter.StrokeWidth = 3;
                    painter.StrokeColor = ColorRGBA.Make(0.0f, 0.3f, 0.2f, 1.0f);
                    painter.Draw(trans_ell);
                    painter.StrokeWidth = prevStrokeWidth;
                }
            }
            else
            {
                var txPerspective = new Perspective(
                    lionShape.Bounds,
                    quadPolygonControl.GetInnerCoords());

                if (txPerspective.IsValid)
                {
                    painter.PaintSeries(txPerspective.TransformToVxs(lionShape.Path.Vxs),
                                        lionShape.Colors,
                                        lionShape.PathIndexList,
                                        lionShape.NumPaths);
                    //--------------------------------------------------------------------------------------
                    //filled Ellipse
                    //1. create original fill ellipse
                    RectD lionBound     = lionShape.Bounds;
                    var   filledEllipse = new Ellipse((lionBound.Left + lionBound.Right) * 0.5,
                                                      (lionBound.Bottom + lionBound.Top) * 0.5,
                                                      (lionBound.Right - lionBound.Left) * 0.5,
                                                      (lionBound.Top - lionBound.Bottom) * 0.5,
                                                      200);

                    VertexStore transformedEll = txPerspective.TransformToVxs(filledEllipse.MakeVxs());
                    painter.FillColor = ColorRGBA.Make(0.5f, 0.3f, 0.0f, 0.3f);
                    painter.Fill(transformedEll);
                    //--------------------------------------------------------
                    var prevStrokeW = painter.StrokeWidth;
                    painter.StrokeWidth = 3;
                    painter.StrokeColor = ColorRGBA.Make(0.0f, 0.3f, 0.2f, 1.0f);
                    painter.Draw(transformedEll);
                    painter.StrokeWidth = prevStrokeW;
                }
            }

            //--------------------------
            // Render the "quad" tool and controls
            painter.FillColor = ColorRGBA.Make(0f, 0.3f, 0.5f, 0.6f);
            painter.Fill(quadPolygonControl.MakeVxs());
        }
Beispiel #12
0
        public override void Draw(CanvasPainter 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 AggCanvasPainter;

            if (p1 == null)
            {
                int             j        = lionShape.NumPaths;
                int[]           pathList = lionShape.PathIndexList;
                Drawing.Color[] colors   = lionShape.Colors;
                //graphics2D.UseSubPixelRendering = true;
                var vxs = GetFreeVxs();
                affTx.TransformToVxs(lionShape.Path.Vxs, vxs);
                p.StrokeWidth = 1;
                for (int i = 0; i < j; ++i)
                {
                    p.StrokeColor = colors[i];
                    p.Draw(new VertexStoreSnap(vxs, pathList[i]));
                }
                //not agg
                Release(ref vxs);
                return; //**
            }

            Graphics2D graphics2D = p1.Graphics;
            //var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());
            //int width = widgetsSubImage.Width;
            //int height = widgetsSubImage.Height;
            var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());

            var            clippedSubImage    = new ChildImage(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(PixelFarm.Drawing.Color.White);


            if (RenderAsScanline)
            {
                var rasterizer = graphics2D.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);
                Stroke stroke = new Stroke(strokeWidth);
                stroke.LineJoin = LineJoin.Round;
                var vxs = GetFreeVxs();
                affTx.TransformToVxs(lionShape.Path.Vxs, vxs);
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;
                sclineRasToBmp.RenderSolidAllPaths(
                    imageClippingProxy,
                    rasterizer,
                    graphics2D.ScanlinePacked8,
                    vxs,
                    lionShape.Colors,
                    lionShape.PathIndexList,
                    lionShape.NumPaths);
                Release(ref vxs);
            }
            else
            {
                double w = strokeWidth * affTx.GetScale();
                LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(w, new GammaNone());
                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;
                //VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);
                var vxs = GetFreeVxs();
                affTx.TransformToVxs(lionShape.Path.Vxs, vxs);// trans.DoTransformToNewVxStorage();
                int j = lionShape.NumPaths;
                for (int i = 0; i < j; ++i)
                {
                    rasterizer.RenderVertexSnap(
                        new VertexStoreSnap(vxs,
                                            lionShape.PathIndexList[i]),
                        lionShape.Colors[i]);
                }
                Release(ref vxs);
            }
            base.Draw(p);
        }