Esempio n. 1
0
        static System.Drawing.Bitmap CreateBackgroundBmp(int w, int h)
        {
            //----------------------------------------------------
            //1. create background bitmap
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(w, h);
            //2. create graphics from bmp
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            // draw a background to show how the mask is working better
            g.Clear(System.Drawing.Color.White);
            int rect_w = 30;

            var v1 = new VertexStore();//todo; use pool

            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 40; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * rect_w, j * rect_w, (i + 1) * rect_w, (j + 1) * rect_w, 0);
                        rect.NormalizeRadius();
                        // Drawing as an outline
                        VxsHelper.FillVxsSnap(g, new VertexStoreSnap(rect.MakeVxs(v1)), Drawing.Color.Make(.9f, .9f, .9f));
                        v1.Clear();
                    }
                }
            }

            //----------------------------------------------------
            return(bmp);
        }
Esempio n. 2
0
        public override void Draw(CanvasPainter p)
        {
            if (p is GdiPlusCanvasPainter)
            {
                DrawWithWinGdi((GdiPlusCanvasPainter)p);
                return;
            }
            AggCanvasPainter p2 = (AggCanvasPainter)p;
            Graphics2D       gx = p2.Graphics;
            var widgetsSubImage = gx.DestImage;
            var scline          = gx.ScanlinePacked8;
            int width           = (int)widgetsSubImage.Width;
            int height          = (int)widgetsSubImage.Height;

            //change value ***
            if (isMaskSliderValueChanged)
            {
                generate_alpha_mask(gx.ScanlineRasToDestBitmap, gx.ScanlinePacked8, gx.ScanlineRasterizer, width, height);
                this.isMaskSliderValueChanged = false;
            }
            var rasterizer = gx.ScanlineRasterizer;

            rasterizer.SetClipBox(0, 0, width, height);
            //alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 0, width, height, width, 8, 1);

            PixelFarm.Agg.Imaging.AlphaMaskAdaptor imageAlphaMaskAdaptor = new PixelFarm.Agg.Imaging.AlphaMaskAdaptor(widgetsSubImage, alphaMask);
            ClipProxyImage alphaMaskClippingProxy = new ClipProxyImage(imageAlphaMaskAdaptor);
            ClipProxyImage clippingProxy          = new ClipProxyImage(widgetsSubImage);
            ////Affine transform = Affine.NewIdentity();
            ////transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y);
            ////transform *= Affine.NewScaling(lionScale, lionScale);
            ////transform *= Affine.NewRotation(angle + Math.PI);
            ////transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0);
            ////transform *= Affine.NewTranslation(Width / 2, Height / 2);
            Affine transform = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(lionScale, lionScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            clippingProxy.Clear(Drawing.Color.White);
            ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap;
            // draw a background to show how the mask is working better
            int rect_w = 30;
            var v1     = GetFreeVxs();

            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 40; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * rect_w, j * rect_w, (i + 1) * rect_w, (j + 1) * rect_w, 0);
                        rect.NormalizeRadius();
                        // Drawing as an outline
                        rasterizer.AddPath(rect.MakeVxs(v1));
                        v1.Clear();
                        sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, scline, Drawing.Color.Make(.9f, .9f, .9f));
                    }
                }
            }
            ReleaseVxs(ref v1);
            ////int x, y;
            //// Render the lion
            ////VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);

            ////var vxlist = new System.Collections.Generic.List<VertexData>();
            ////trans.DoTransform(vxlist);

            var tmpVxs1 = new VertexStore();

            transform.TransformToVxs(lionShape.Path.Vxs, tmpVxs1);

            sclineRasToBmp.RenderSolidAllPaths(alphaMaskClippingProxy,
                                               rasterizer,
                                               scline,
                                               tmpVxs1,
                                               lionShape.Colors,
                                               lionShape.PathIndexList,
                                               lionShape.NumPaths);
            ///*
            //// Render random Bresenham lines and markers
            //agg::renderer_markers<amask_ren_type> m(r);
            //for(i = 0; i < 50; i++)
            //{
            //    m.line_color(agg::rgba8(randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            (randGenerator.Next() & 0x7F) + 0x7F));
            //    m.fill_color(agg::rgba8(randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            (randGenerator.Next() & 0x7F) + 0x7F));

            //    m.line(m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height),
            //           m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height));

            //    m.marker(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 10 + 5,
            //             agg::marker_e(randGenerator.Next() % agg::end_of_markers));
            //}


            //// Render random anti-aliased lines
            //double w = 5.0;
            //agg::line_profile_aa profile;
            //profile.width(w);

            //typedef agg::renderer_outline_aa<amask_ren_type> renderer_type;
            //renderer_type ren(r, profile);

            //typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
            //rasterizer_type ras(ren);
            //ras.round_cap(true);

            //for(i = 0; i < 50; i++)
            //{
            //    ren.Color = agg::rgba8(randGenerator.Next() & 0x7F,
            //                         randGenerator.Next() & 0x7F,
            //                         randGenerator.Next() & 0x7F,
            //                         //255));
            //                         (randGenerator.Next() & 0x7F) + 0x7F);
            //    ras.move_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
            //    ras.line_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
            //    ras.render(false);
            //}


            //// Render random circles with gradient
            //typedef agg::gradient_linear_color<color_type> grad_color;
            //typedef agg::gradient_circle grad_func;
            //typedef agg::span_interpolator_linear<> interpolator_type;
            //typedef agg::span_gradient<color_type,
            //                          interpolator_type,
            //                          grad_func,
            //                          grad_color> span_grad_type;

            //agg::trans_affine grm;
            //grad_func grf;
            //grad_color grc(agg::rgba8(0,0,0), agg::rgba8(0,0,0));
            //agg::ellipse ell;
            //agg::span_allocator<color_type> sa;
            //interpolator_type inter(grm);
            //span_grad_type sg(inter, grf, grc, 0, 10);
            //agg::renderer_scanline_aa<amask_ren_type,
            //                          agg::span_allocator<color_type>,
            //                          span_grad_type> rg(r, sa, sg);
            //for(i = 0; i < 50; i++)
            //{
            //    x = randGenerator.Next() % width;
            //    y = randGenerator.Next() % height;
            //    double r = randGenerator.Next() % 10 + 5;
            //    grm.reset();
            //    grm *= agg::trans_affine_scaling(r / 10.0);
            //    grm *= agg::trans_affine_translation(x, y);
            //    grm.invert();
            //    grc.colors(agg::rgba8(255, 255, 255, 0),
            //               agg::rgba8(randGenerator.Next() & 0x7F,
            //                          randGenerator.Next() & 0x7F,
            //                          randGenerator.Next() & 0x7F,
            //                          255));
            //    sg.color_function(grc);
            //    ell.init(x, y, r, r, 32);
            //    g_rasterizer.add_path(ell);
            //    agg::render_scanlines(g_rasterizer, g_scanline, rg);
            //}
            // */
            ////m_num_cb.Render(g_rasterizer, g_scanline, clippingProxy);
        }
Esempio n. 3
0
        public override void OnDraw(RendererBase renderer)
        {
            GammaLookUpTable gamma = new GammaLookUpTable(m_gamma.value());
            IBlender NormalBlender = new BlenderBGRA();
            IBlender GammaBlender = new BlenderGammaBGRA(gamma);
            ImageBuffer rasterNormal = new ImageBuffer(NewRenderer().DestImage, NormalBlender);
            ImageBuffer rasterGamma = new ImageBuffer(NewRenderer().DestImage, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

            clippingProxyNormal.clear(new RGBA_Doubles(0,0,0));

            rasterizer_scanline_aa ras = new rasterizer_scanline_aa();
            scanline_packed_8 sl = new scanline_packed_8();

            VertexSource.Ellipse e = new VertexSource.Ellipse();

            // TODO: If you drag the control circles below the bottom of the window we get an exception.  This does not happen in AGG.
            // It needs to be debugged.  Turning on clipping fixes it.  But standard agg works without clipping.  Could be a bigger problem than this.
            //ras.clip_box(0, 0, width(), height());

            // Render two "control" circles
            e.init(m_x[0], m_y[0], 3, 3, 16);
            ras.add_path(e);
            Renderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));
            e.init(m_x[1], m_y[1], 3, 3, 16);
            ras.add_path(e);
            Renderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));

            // Creating a rounded rectangle
            VertexSource.RoundedRect r = new VertexSource.RoundedRect(m_x[0], m_y[0], m_x[1], m_y[1], 10);
            r.normalize_radius();

            // Drawing as an outline
                conv_stroke p = new conv_stroke(r);
                p.width(1.0);
                ras.add_path(p);

                //Renderer.RenderSolid(clippingProxyGamma, ras, sl, new RGBA_Bytes(0, 0, 0));
            Renderer.RenderSolid(clippingProxyGamma, ras, sl, new RGBA_Bytes(255, 1, 1));








            /*            
                    int i;

                    // radial line test
                    //-------------------------
                    dashed_line<rasterizer_type, 
                                renderer_scanline_type, 
                                scanline_type> dash(ras, ren_sl, sl);

                    double cx = width() / 2.0;
                    double cy = height() / 2.0;

                    ren_sl.color(agg::rgba(1.0, 1.0, 1.0, 0.2));
                    for(i = 180; i > 0; i--) 
                    {
                        double n = 2.0 * agg::pi * i / 180.0;
                        dash.draw(cx + min(cx, cy) * sin(n), cy + min(cx, cy) * cos(n),
                                  cx, cy, 
                                  1.0, (i < 90) ? i : 0.0);
                    }


                    typedef agg::gradient_x gradient_func_type;
                    typedef agg::span_interpolator_linear<> interpolator_type;
                    typedef agg::span_allocator<color_type> span_allocator_type;
                    typedef agg::pod_auto_array<color_type, 256> color_array_type;
                    typedef agg::span_gradient<color_type, 
                                               interpolator_type, 
                                               gradient_func_type, 
                                               color_array_type> span_gradient_type;

                    typedef agg::renderer_scanline_aa<renderer_base_type, 
                                                      span_allocator_type,
                                                      span_gradient_type> renderer_gradient_type;

                    gradient_func_type  gradient_func;                   // The gradient function
                    agg::trans_affine   gradient_mtx;                    // Affine transformer
                    interpolator_type   span_interpolator(gradient_mtx); // Span interpolator
                    span_allocator_type span_allocator;                  // Span Allocator
                    color_array_type    gradient_colors;                 // The gradient colors
                    span_gradient_type  span_gradient(span_interpolator, 
                                                      gradient_func, 
                                                      gradient_colors, 
                                                      0, 100);

                    renderer_gradient_type ren_gradient(ren_base, span_allocator, span_gradient);

                    dashed_line<rasterizer_type, 
                                renderer_gradient_type, 
                                scanline_type> dash_gradient(ras, ren_gradient, sl);

                    double x1, y1, x2, y2;

                    for(i = 1; i <= 20; i++)
                    {
                        ren_sl.color(agg::rgba(1,1,1));

                        // integral point sizes 1..20
                        //----------------
                        agg::ellipse ell;
            
                        ell.init(20 + i * (i + 1) + 0.5, 
                                 20.5, 
                                 i / 2.0, 
                                 i / 2.0, 
                                 8 + i);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);
            

                        // fractional point sizes 0..2
                        //----------------
                        ell.init(18 + i * 4 + 0.5, 33 + 0.5, 
                                 i/20.0, i/20.0, 
                                 8);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);


                        // fractional point positioning
                        //---------------
                        ell.init(18 + i * 4 + (i-1) / 10.0 + 0.5, 
                                 27 + (i - 1) / 10.0 + 0.5, 
                                 0.5, 0.5, 8);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);


                        // integral line widths 1..20
                        //----------------
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,1,1), 
                                         agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));

                        x1 = 20 + i* (i + 1);
                        y1 = 40.5;
                        x2 = 20 + i * (i + 1) + (i - 1) * 4;
                        y2 = 100.5;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, i, 0);


                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,0,0), 
                                         agg::rgba(0,0,1));

                        // fractional line lengths H (red/blue)
                        //----------------
                        x1 = 17.5 + i * 4;
                        y1 = 107;
                        x2 = 17.5 + i * 4 + i/6.66666667;
                        y2 = 107;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);


                        // fractional line lengths V (red/blue)
                        //---------------
                        x1 = 18 + i * 4;
                        y1 = 112.5;
                        x2 = 18 + i * 4;
                        y2 = 112.5 + i / 6.66666667;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);

                        // fractional line positioning (red)
                        //---------------
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,0,0), 
                                         agg::rgba(1,1,1));
                        x1 = 21.5;
                        y1 = 120 + (i - 1) * 3.1;
                        x2 = 52.5;
                        y2 = 120 + (i - 1) * 3.1;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);


                        // fractional line width 2..0 (green)
                        fill_color_array(gradient_colors, 
                                         agg::rgba(0,1,0), 
                                         agg::rgba(1,1,1));
                        x1 = 52.5;
                        y1 = 118 + i * 3;
                        x2 = 83.5;
                        y2 = 118 + i * 3;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 0);

                        // stippled fractional width 2..0 (blue)
                        fill_color_array(gradient_colors, 
                                         agg::rgba(0,0,1), 
                                         agg::rgba(1,1,1));
                        x1 = 83.5;
                        y1 = 119 + i * 3;
                        x2 = 114.5;
                        y2 = 119 + i * 3;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 3.0);


                        ren_sl.color(agg::rgba(1,1,1));
                        if(i <= 10)
                        {
                            // integral line width, horz aligned (mipmap test)
                            //-------------------
                            dash.draw(125.5, 119.5 + (i + 2) * (i / 2.0),
                                      135.5, 119.5 + (i + 2) * (i / 2.0),
                                      i, 0.0);
                        }

                        // fractional line width 0..2, 1 px H
                        //-----------------
                        dash.draw(17.5 + i * 4, 192, 18.5 + i * 4, 192, i / 10.0, 0);

                        // fractional line positioning, 1 px H
                        //-----------------
                        dash.draw(17.5 + i * 4 + (i - 1) / 10.0, 186, 
                                  18.5 + i * 4 + (i - 1) / 10.0, 186,
                                  1.0, 0);
                    }


                    // Triangles
                    //---------------
                    for (int i = 1; i <= 13; i++) 
                    {
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,1,1), 
                                         agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));
                        calc_linear_gradient_transform(width()  - 150, 
                                                       height() - 20 - i * (i + 1.5),
                                                       width()  - 20,  
                                                       height() - 20 - i * (i + 1),
                                                       gradient_mtx);
                        ras.reset();
                        ras.move_to_d(width() - 150, height() - 20 - i * (i + 1.5));
                        ras.line_to_d(width() - 20,  height() - 20 - i * (i + 1));
                        ras.line_to_d(width() - 20,  height() - 20 - i * (i + 2));
                        agg::render_scanlines(ras, sl, ren_gradient);
                    }
             */










            base.OnDraw(renderer);
        }