Пример #1
0
        public override void OnDraw()
        {
#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr());
#else
            FormatRGBA pf = new FormatRGBA(rbuf_window(), new BlenderBGRA());
#endif
            FormatClippingProxy ren_base = new FormatClippingProxy(pf);
            ren_base.Clear(new RGBA_Doubles(1.0, 1.0, 1.0));

            ScanlineUnpacked8        sl  = new ScanlineUnpacked8();
            RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>();
#if true
            render_gouraud(sl, ras);
#else
            agg.span_allocator span_alloc = new span_allocator();
            span_gouraud_rgba  span_gen   = new span_gouraud_rgba(new rgba8(255, 0, 0, 255), new rgba8(0, 255, 0, 255), new rgba8(0, 0, 255, 255), 320, 220, 100, 100, 200, 100, 0);
            span_gouraud       test_sg    = new span_gouraud(new rgba8(0, 0, 0, 255), new rgba8(0, 0, 0, 255), new rgba8(0, 0, 0, 255), 320, 220, 100, 100, 200, 100, 0);
            ras.add_path(test_sg);
            renderer_scanlines.render_scanlines_aa(ras, sl, ren_base, span_alloc, span_gen);
            //renderer_scanlines.render_scanlines_aa_solid(ras, sl, ren_base, new rgba8(0, 0, 0, 255));
#endif


            ras.Gamma(new GammaNone());
            m_dilation.SetTransform(trans_affine_resizing());
            //m_dilation.Render(ras, sl, ren_base);
            m_gamma.SetTransform(trans_affine_resizing());
            //m_gamma.Render(ras, sl, ren_base);
            m_alpha.SetTransform(trans_affine_resizing());
            //m_alpha.Render(ras, sl, ren_base);
            base.OnDraw();
        }
Пример #2
0
        public override void OnDraw()
        {
#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr());
#else
            FormatRGBA pf = new FormatRGBA(rbuf_window(), new BlenderBGRA());
#endif
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pf);
            clippingProxy.Clear(new RGBA_Doubles(0, 0, 0));

            RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>();
            ScanlineUnpacked8        sl  = new ScanlineUnpacked8();
            ScanlineBin sl_bin           = new ScanlineBin();

            RasterizerCompoundAA <T> rasc  = new RasterizerCompoundAA <T>();
            SpanAllocator            alloc = new SpanAllocator();

            uint           i;
            styles_gouraud styles = new styles_gouraud(m_mesh, m_gamma);
            start_timer();
            rasc.Reset();
            //rasc.clip_box(40, 40, width() - 40, height() - 40);
            for (i = 0; i < m_mesh.num_edges(); i++)
            {
                mesh_edge  e  = m_mesh.edge(i);
                mesh_point p1 = m_mesh.vertex(e.p1);
                mesh_point p2 = m_mesh.vertex(e.p2);
                rasc.Styles(e.tl, e.tr);
                rasc.MoveToDbl(p1.x, p1.y);
                rasc.LineToDbl(p2.x, p2.y);
            }

            Renderer <T> .RenderCompound(rasc, sl, sl_bin, clippingProxy, alloc, styles);

            double tm = elapsed_time();

            GsvText <T> t = new GsvText <T>();
            t.SetFontSize(10.0);

            ConvStroke <T> pt = new ConvStroke <T>(t);
            pt.Width    = M.New <T>(1.5);
            pt.LineCap  = LineCap.Round;
            pt.LineJoin = LineJoin.RoundJoin;

            string buf = string.Format("{0:F2} ms, {1} triangles, {2:F0} tri/sec",
                                       tm,
                                       m_mesh.num_triangles(),
                                       m_mesh.num_triangles() / tm * 1000.0);
            t.StartPoint(10.0, 10.0);
            t.Text = buf;

            ras.AddPath(pt);
            Renderer <T> .RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(1, 1, 1).GetAsRGBA_Bytes());


            if (m_gamma.Gamma() != 1.0)
            {
                pf.ApplyGammaInv(m_gamma);
            }
        }
Пример #3
0
 public override void Clear(IColorType color)
 {
     FormatClippingProxy clipper = (FormatClippingProxy)m_PixelFormat;
     if (clipper != null)
     {
         clipper.Clear(color);
     }
 }
Пример #4
0
        unsafe void generate_alpha_mask(int cx, int cy)
        {
            m_alpha_buf = new byte[cx * cy];
            fixed(byte *pAlphaBuffer = m_alpha_buf)
            {
#if USE_CLIPPING_ALPHA_MASK
                m_alpha_mask_rbuf.attach(pAlphaBuffer + 20 * cx + 20, (uint)cx - 40, (uint)cy - 40, cx, 1);
#else
                m_alpha_mask_rbuf.attach(pAlphaBuffer, (uint)cx, (uint)cy, cx, 1);
#endif

                FormatGray          pixf          = new FormatGray(m_alpha_mask_rbuf, new BlenderGray(), 1, 0);
                FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);
                ScanlinePacked8     sl            = new ScanlinePacked8();

                clippingProxy.Clear(new RGBA_Doubles(0));

                VertexSource.Ellipse <T> ell = new AGG.VertexSource.Ellipse <T>();

                System.Random randGenerator = new Random(1432);

                int i;
                int num = (int)m_num_cb.value().ToInt();
                for (i = 0; i < num; i++)
                {
                    if (i == num - 1)
                    {
                        ell.Init(width().Divide(2), height().Divide(2), M.New <T>(110), M.New <T>(110), 100);
                        g_rasterizer.AddPath(ell);
                        Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, sl, new RGBA_Bytes(0, 0, 0, 255));

                        ell.Init(ell.X, ell.Y, ell.RX.Subtract(10), ell.RY.Subtract(10), 100);
                        g_rasterizer.AddPath(ell);
                        Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, sl, new RGBA_Bytes(255, 0, 0, 255));
                    }
                    else
                    {
                        ell.Init(randGenerator.Next() % cx,
                                 randGenerator.Next() % cy,
                                 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).
                        g_rasterizer.AddPath(ell);
                        Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, sl, new RGBA_Bytes((uint)((float)i / (float)num * 255), 0, 0, 255));
                    }
                }

                m_alpha_mask_rbuf.dettachBuffer();
            }
        }
Пример #5
0
        public override void OnDraw()
        {
            int width  = (int)rbuf_window().Width;
            int height = (int)rbuf_window().Height;


            IPixelFormat        pixf          = new FormatRGB(rbuf_window(), new BlenderBGR());
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);

            clippingProxy.Clear(new RGBA_Doubles(1, 1, 1));

            IAffineTransformMatrix <T> mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            mtx.Translate(MatrixFactory <T> .CreateVector2D(g_base_dx.Negative(), g_base_dy.Negative()));
            mtx.Scale(g_scale);
            mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), g_angle.Add(Math.PI).ToDouble());
            mtx.Shear(MatrixFactory <T> .CreateVector2D(g_skew_x.Divide(1000.0), g_skew_y.Divide(1000.0)));
            mtx.Translate(MatrixFactory <T> .CreateVector2D(width / 2, height / 2));

            if (m_scanline.status())
            {
                g_rasterizer.SetVectorClipBox(0, 0, width, height);

                ConvStroke <T> stroke = new ConvStroke <T>(g_path);
                stroke.Width    = m_width_slider.value();
                stroke.LineJoin = LineJoin.RoundJoin;
                ConvTransform <T> trans = new ConvTransform <T>(stroke, mtx);
                Renderer <T> .RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths);
            }
            else
            {
                /*
                 * double w = m_width_slider.Value() * mtx.scale();
                 *
                 * line_profile_aa profile = new line_profile_aa(w, new gamma_none());
                 * renderer_outline_aa ren = new renderer_outline_aa(rb, profile);
                 * rasterizer_outline_aa ras = new rasterizer_outline_aa(ren);
                 *
                 * conv_transform trans = new conv_transform(g_path, mtx);
                 *
                 * ras.render_all_paths(trans, g_colors, g_path_idx, g_npaths);
                 */
            }

            base.OnDraw();
        }
Пример #6
0
        public override void OnDraw()
        {
#if SourceDepth24
            FormatRGB pixf = new FormatRGB(rbuf_window(), new BlenderBGR());
#else
            pixfmt_alpha_blend_rgba32 pixf      = new pixfmt_alpha_blend_rgba32(rbuf_window(), new blender_bgra32());
            pixfmt_alpha_blend_rgba32 pixfImage = new pixfmt_alpha_blend_rgba32(rbuf_img(0), new blender_bgra32());
#endif
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);

            clippingProxy.Clear(new RGBA_Doubles(1.0, 1.0, 1.0));
            clippingProxy.CopyFrom(rbuf_img(0), new RectInt(0, 0, (int)Width.ToInt(), (int)Height.ToInt()), 110, 35);

            string      buf = string.Format("NSteps={0:F0}", m_num_steps);
            GsvText <T> t   = new GsvText <T>();
            t.StartPoint(10.0, 295.0);
            t.SetFontSize(10.0);
            t.Text = buf;

            ConvStroke <T> pt = new ConvStroke <T>(t);
            pt.Width = M.New <T>(1.5);

            m_Rasterizer.AddPath(pt);
            Renderer <T> .RenderSolid(clippingProxy, m_Rasterizer, m_ScanlinePacked, new RGBA_Bytes(0, 0, 0));

            if (m_time1 != m_time2 && m_num_pix > 0.0)
            {
                buf = string.Format("{0:F2} Kpix/sec", m_num_pix / (m_time2 - m_time1));
                t.StartPoint(10.0, 310.0);
                t.Text = buf;
                m_Rasterizer.AddPath(pt);
                Renderer <T> .RenderSolid(clippingProxy, m_Rasterizer, m_ScanlinePacked, new RGBA_Bytes(0, 0, 0));
            }

            if (m_filters.cur_item() >= 14)
            {
                m_radius.Visible = true;
            }
            else
            {
                m_radius.Visible = true;
            }

            base.OnDraw();
        }
Пример #7
0
        public static void glClear(int mask)
        {
            if ((mask & GL_COLOR_BUFFER_BIT) != 0)
            {
                FormatRGBA pf = new FormatRGBA(s_RenderingBuffer, new BlenderBGRA());

                FormatClippingProxy renderBase = new FormatClippingProxy(pf);

                RasterizerScanlineAA <T> rasterizer = new RasterizerScanlineAA <T>();
                ScanlinePacked8          scanline   = new ScanlinePacked8();

                renderBase.Clear(s_ClearColor);
            }

            if ((mask & GL_DEPTH_BUFFER_BIT) != 0)
            {
            }
        }
Пример #8
0
        public override void OnDraw()
        {
            FormatRGB pf = new FormatRGB(rbuf_window(), new BlenderBGR());

            FormatGray pfr = new FormatGray(rbuf_window(), new BlenderGray(), 3, 2);
            FormatGray pfg = new FormatGray(rbuf_window(), new BlenderGray(), 3, 1);
            FormatGray pfb = new FormatGray(rbuf_window(), new BlenderGray(), 3, 0);

            FormatClippingProxy clippingProxy      = new FormatClippingProxy(pf);
            FormatClippingProxy clippingProxyRed   = new FormatClippingProxy(pfr);
            FormatClippingProxy clippingProxyGreen = new FormatClippingProxy(pfg);
            FormatClippingProxy clippingProxyBlue  = new FormatClippingProxy(pfb);

            RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>();
            ScanlinePacked8          sl  = new ScanlinePacked8();

            clippingProxy.Clear(m_UseBlackBackground.status() ? new RGBA_Doubles(0, 0, 0) : new RGBA_Doubles(1, 1, 1));

            RGBA_Bytes FillColor = m_UseBlackBackground.status() ? new RGBA_Bytes(255, 255, 255, (uint)(m_alpha.value().ToInt())) : new RGBA_Bytes(0, 0, 0, (uint)(m_alpha.value().ToInt()));

            VertexSource.Ellipse <T> er = new AGG.VertexSource.Ellipse <T>(width().Divide(2).Subtract(0.87 * 50), height().Divide(2).Subtract(0.5 * 50), M.New <T>(100), M.New <T>(100), 100);
            ras.AddPath(er);
            Renderer <T> .RenderSolid(clippingProxyRed, ras, sl, FillColor);

            VertexSource.Ellipse <T> eg = new AGG.VertexSource.Ellipse <T>(width().Divide(2).Add(0.87 * 50), height().Divide(2).Subtract(0.5 * 50), M.New <T>(100), M.New <T>(100), 100);
            ras.AddPath(eg);
            Renderer <T> .RenderSolid(clippingProxyGreen, ras, sl, FillColor);

            //renderer_scanlines.render_scanlines_aa_solid(ras, sl, rbg, new gray8(0, unsigned(m_alpha.Value())));

            VertexSource.Ellipse <T> eb = new AGG.VertexSource.Ellipse <T>(width().Divide(2), height().Divide(2).Add(50), M.New <T>(100), M.New <T>(100), 100);
            ras.AddPath(eb);
            Renderer <T> .RenderSolid(clippingProxyBlue, ras, sl, FillColor);

            //renderer_scanlines.render_scanlines_aa_solid(ras, sl, rbb, new gray8(0, unsigned(m_alpha.Value())));

            //m_alpha.Render(ras, sl, clippingProxy);
            //m_UseBlackBackground.Render(ras, sl, clippingProxy);
            base.OnDraw();
        }
Пример #9
0
        public override void OnDraw()
        {
            if (m_gamma.value().NotEqual(m_old_gamma))
            {
                m_gamma_lut.Gamma(m_gamma.value().ToDouble());
                load_img(0, "spheres");
                FormatRGB pixf_change_gamma = new FormatRGB(rbuf_img(0), new BlenderBGR());
                //pixf_change_gamma.apply_gamma_dir(m_gamma_lut);
                m_old_gamma = m_gamma.value();
            }

#if SourceDepth24
            pixfmt_alpha_blend_rgb pixf     = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr());
            pixfmt_alpha_blend_rgb pixf_pre = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr_pre());
#else
            FormatRGBA pixf     = new FormatRGBA(rbuf_window(), new BlenderBGRA());
            FormatRGBA pixf_pre = new FormatRGBA(rbuf_window(), new BlenderPreMultBGRA());
#endif
            FormatClippingProxy clippingProxy     = new FormatClippingProxy(pixf);
            FormatClippingProxy clippingProxy_pre = new FormatClippingProxy(pixf_pre);

            clippingProxy.Clear(new RGBA_Doubles(1, 1, 1));

            if (m_trans_type.cur_item() < 2)
            {
                // For the IAffineTransformMatrix<T> parallelogram transformations we
                // calculate the 4-th (implicit) point of the parallelogram
                m_quad.SetXN(3, m_quad.xn(0).Add(m_quad.xn(2).Subtract(m_quad.xn(1))));
                m_quad.SetYN(3, m_quad.yn(0).Add(m_quad.yn(2).Subtract(m_quad.yn(1))));
            }

            //--------------------------
            // Render the "quad" tool and controls
            g_rasterizer.AddPath(m_quad);
            Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0.3, 0.5, 0.1));

            // Prepare the polygon to rasterize. Here we need to fill
            // the destination (transformed) polygon.
            g_rasterizer.SetVectorClipBox(0, 0, width().ToDouble(), height().ToDouble());
            g_rasterizer.Reset();
            int b = 0;
            g_rasterizer.MoveToDbl(m_quad.xn(0).Subtract(b), m_quad.yn(0).Subtract(b));
            g_rasterizer.LineToDbl(m_quad.xn(1).Add(b), m_quad.yn(1).Subtract(b));
            g_rasterizer.LineToDbl(m_quad.xn(2).Add(b), m_quad.yn(2).Add(b));
            g_rasterizer.LineToDbl(m_quad.xn(3).Subtract(b), m_quad.yn(3).Add(b));

            //typedef agg::span_allocator<color_type> span_alloc_type;
            SpanAllocator              sa            = new SpanAllocator();
            ImageFilterBilinear <T>    filter_kernel = new ImageFilterBilinear <T>();
            ImageFilterLookUpTable <T> filter        = new ImageFilterLookUpTable <T>(filter_kernel, true);

#if SourceDepth24
            pixfmt_alpha_blend_rgb pixf_img = new pixfmt_alpha_blend_rgb(rbuf_img(0), new blender_bgr());
#else
            FormatRGBA pixf_img = new FormatRGBA(rbuf_img(0), new BlenderBGRA());
#endif
            RasterBufferAccessorClamp source = new RasterBufferAccessorClamp(pixf_img);

            start_timer();

            switch (m_trans_type.cur_item())
            {
            case 0:
            {
                /*
                 *      agg::trans_affine tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                 *
                 *      typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type;
                 *      interpolator_type interpolator(tr);
                 *
                 *      typedef image_filter_2x2_type<source_type,
                 *                                    interpolator_type> span_gen_type;
                 *      span_gen_type sg(source, interpolator, filter);
                 *      agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
                 */
                break;
            }

            case 1:
            {
                /*
                 *      agg::trans_affine tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                 *
                 *      typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type;
                 *      typedef image_resample_affine_type<source_type> span_gen_type;
                 *
                 *      interpolator_type interpolator(tr);
                 *      span_gen_type sg(source, interpolator, filter);
                 *      sg.blur(m_blur.Value());
                 *      agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
                 */
                break;
            }

            case 2:
            {
                /*
                 *      agg::trans_perspective tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                 *      if(tr.is_valid())
                 *      {
                 *          typedef agg::span_interpolator_linear_subdiv<agg::trans_perspective> interpolator_type;
                 *          interpolator_type interpolator(tr);
                 *
                 *          typedef image_filter_2x2_type<source_type,
                 *                                        interpolator_type> span_gen_type;
                 *          span_gen_type sg(source, interpolator, filter);
                 *          agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
                 *      }
                 */
                break;
            }

            case 3:
            {
                /*
                 *      agg::trans_perspective tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                 *      if(tr.is_valid())
                 *      {
                 *          typedef agg::span_interpolator_trans<agg::trans_perspective> interpolator_type;
                 *          interpolator_type interpolator(tr);
                 *
                 *          typedef image_filter_2x2_type<source_type,
                 *                                        interpolator_type> span_gen_type;
                 *          span_gen_type sg(source, interpolator, filter);
                 *          agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
                 *      }
                 */
                break;
            }

            case 4:
            {
                //typedef agg::span_interpolator_persp_lerp<> interpolator_type;
                //typedef agg::span_subdiv_adaptor<interpolator_type> subdiv_adaptor_type;

                SpanInterpolatorPerspLerp <T> interpolator   = new SpanInterpolatorPerspLerp <T>(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                SpanSubDivAdaptor <T>         subdiv_adaptor = new SpanSubDivAdaptor <T>(interpolator);

                if (interpolator.IsValid())
                {
#if SourceDepth24
                    span_image_resample_rgb sg = new span_image_resample_rgb(source, subdiv_adaptor, filter);
#else
                    span_image_resample_rgba <T> sg = new span_image_resample_rgba <T>(source, subdiv_adaptor, filter);
#endif
                    sg.Blur = m_blur.value().ToDouble();
                    Renderer <T> .GenerateAndRender(g_rasterizer, g_scanline, clippingProxy_pre, sa, sg);
                }
                break;
            }

            case 5:
            {
                /*
                 *      typedef agg::span_interpolator_persp_exact<> interpolator_type;
                 *      typedef agg::span_subdiv_adaptor<interpolator_type> subdiv_adaptor_type;
                 *
                 *      interpolator_type interpolator(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                 *      subdiv_adaptor_type subdiv_adaptor(interpolator);
                 *
                 *      if(interpolator.is_valid())
                 *      {
                 *          typedef image_resample_type<source_type,
                 *                                      subdiv_adaptor_type> span_gen_type;
                 *          span_gen_type sg(source, subdiv_adaptor, filter);
                 *          sg.blur(m_blur.Value());
                 *          agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
                 *      }
                 */
                break;
            }
            }

            double tm = elapsed_time();
            //pixf.apply_gamma_inv(m_gamma_lut);

            GsvText <T> t = new GsvText <T>();
            t.SetFontSize(10.0);

            ConvStroke <T> pt = new ConvStroke <T>(t);
            pt.Width = M.New <T>(1.5);

            string buf = string.Format("{0:F2} ms", tm);
            t.StartPoint(10.0, 70.0);
            t.Text = buf;

            g_rasterizer.AddPath(pt);
            Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0, 0));

            //--------------------------
            //m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy);
            //m_gamma.Render(g_rasterizer, g_scanline, clippingProxy);
            //m_blur.Render(g_rasterizer, g_scanline, clippingProxy);
            base.OnDraw();
        }
Пример #10
0
        public override void OnDraw()
        {
            IPixelFormat pixf;

            if (this.bpp() == 32)
            {
                pixf = new FormatRGBA(rbuf_window(), new BlenderBGRA());
                //pixf = new pixfmt_alpha_blend_rgba32(rbuf_window(), new blender_rgba32());
            }
            else
            {
                if (bpp() != 24)
                {
                    throw new System.NotSupportedException();
                }
                pixf = new FormatRGB(rbuf_window(), new BlenderBGR());
            }
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);

            clippingProxy.Clear(new RGBA_Doubles(1, 1, 1));

            g_rasterizer.SetVectorClipBox(M.Zero <T>(), M.Zero <T>(), width(), height());

            if (m_trans_type.cur_item() == 0)
            {
                Bilinear <T> tr = new Bilinear <T>(g_x1, g_y1, g_x2, g_y2, m_quad.polygon());
                if (tr.IsValid())
                {
                    //--------------------------
                    // Render transformed lion
                    //
                    ConvTransform <T> trans = new ConvTransform <T>(g_path, tr);

                    Renderer <T> .RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths);

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



                    //--------------------------
                    // Render transformed ellipse
                    //
                    VertexSource.Ellipse <T> ell = new AGG.VertexSource.Ellipse <T>(g_x1.Add(g_x2).Multiply(0.5), g_y1.Add(g_y2).Multiply(0.5),
                                                                                    g_x2.Subtract(g_x1).Multiply(0.5), g_y2.Subtract(g_y1).Multiply(0.5),
                                                                                    200);
                    ConvStroke <T> ell_stroke = new ConvStroke <T>(ell);
                    ell_stroke.Width = M.New <T>(3.0);
                    ConvTransform <T> trans_ell = new ConvTransform <T>(ell, tr);

                    ConvTransform <T> trans_ell_stroke = new ConvTransform <T>(ell_stroke, tr);

                    g_rasterizer.AddPath(trans_ell);
                    Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3));

                    g_rasterizer.AddPath(trans_ell_stroke);
                    Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0));
                }
            }
            else
            {
                Perspective <T> tr = new Perspective <T>(g_x1, g_y1, g_x2, g_y2, m_quad.polygon());
                if (tr.IsValid())
                {
                    // Render transformed lion
                    ConvTransform <T> trans = new ConvTransform <T>(g_path, tr);

                    Renderer <T> .RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths);

                    // Render transformed ellipse
                    VertexSource.Ellipse <T> FilledEllipse = new AGG.VertexSource.Ellipse <T>(g_x1.Add(g_x2).Multiply(0.5), g_y1.Add(g_y2).Multiply(0.5),
                                                                                              g_x2.Subtract(g_x1).Multiply(0.5), g_y2.Subtract(g_y1).Multiply(0.5),
                                                                                              200);

                    ConvStroke <T> EllipseOutline = new ConvStroke <T>(FilledEllipse);
                    EllipseOutline.Width = M.New <T>(3.0);
                    ConvTransform <T> TransformedFilledEllipse = new ConvTransform <T>(FilledEllipse, tr);

                    ConvTransform <T> TransformedEllipesOutline = new ConvTransform <T>(EllipseOutline, tr);

                    g_rasterizer.AddPath(TransformedFilledEllipse);
                    Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3));

                    g_rasterizer.AddPath(TransformedEllipesOutline);
                    Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0));
                }
            }

            //--------------------------
            // Render the "quad" tool and controls
            g_rasterizer.AddPath(m_quad);
            Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0.3, 0.5, 0.6));

            //m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy);
            base.OnDraw();
        }
Пример #11
0
        void transform_image(double angle)
        {
            double width  = rbuf_img(0).Width;
            double height = rbuf_img(0).Height;

#if SourceDepth24
            FormatRGB pixf     = new FormatRGB(rbuf_img(0), new BlenderBGR());
            FormatRGB pixf_pre = new FormatRGB(rbuf_img(0), new BlenderPreMultBGR());
#else
            pixfmt_alpha_blend_rgba32 pixf     = new pixfmt_alpha_blend_rgba32(rbuf_img(0), new blender_bgra32());
            pixfmt_alpha_blend_rgba32 pixf_pre = new pixfmt_alpha_blend_rgba32(rbuf_img(0), new blender_bgra_pre());
#endif
            FormatClippingProxy rb     = new FormatClippingProxy(pixf);
            FormatClippingProxy rb_pre = new FormatClippingProxy(pixf_pre);

            rb.Clear(new RGBA_Doubles(1.0, 1.0, 1.0));

            IAffineTransformMatrix <T> src_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            src_mtx.Translate(MatrixFactory <T> .CreateVector2D(-width / 2.0, -height / 2.0));
            src_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), angle * Math.PI / 180.0);
            src_mtx.Translate(MatrixFactory <T> .CreateVector2D(width / 2.0, height / 2.0));

            IAffineTransformMatrix <T> img_mtx = MatrixFactory <T> .CreateAffine(src_mtx);

            img_mtx = img_mtx.Inverse;

            double r = width;
            if (height < r)
            {
                r = height;
            }

            r *= 0.5;
            r -= 4.0;
            VertexSource.Ellipse <T> ell = new AGG.VertexSource.Ellipse <T>(width / 2.0, height / 2.0, r, r, 200);
            ConvTransform <T>        tr  = new ConvTransform <T>(ell, src_mtx);

            m_num_pix += r * r * Math.PI;

            SpanInterpolatorLinear <T> interpolator = new SpanInterpolatorLinear <T>(img_mtx);

            ImageFilterLookUpTable <T> filter = new ImageFilterLookUpTable <T>();
            bool norm = m_normalize.status();

#if SourceDepth24
            FormatRGB pixf_img = new FormatRGB(rbuf_img(1), new BlenderBGR());
#else
            pixfmt_alpha_blend_rgba32 pixf_img = new pixfmt_alpha_blend_rgba32(rbuf_img(1), new blender_bgra32());
#endif
            RasterBufferAccessorClip source = new RasterBufferAccessorClip(pixf_img, RGBA_Doubles.RgbaPre(0, 0, 0, 0));

            switch (m_filters.cur_item())
            {
            case 0:
            {
#if SourceDepth24
                SpanImageFilterRgbNN <T> sg = new SpanImageFilterRgbNN <T>(source, interpolator);
#else
                span_image_filter_rgba_nn sg = new span_image_filter_rgba_nn(source, interpolator);
#endif
                m_Rasterizer.AddPath(tr);
                Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg);
            }
            break;

            case 1:
            {
#if SourceDepth24
                //span_image_filter_rgb_bilinear_clip sg = new span_image_filter_rgb_bilinear_clip(pixf_img, rgba.rgba_pre(0, 0.4, 0, 0.5), interpolator);
                SpanImageFilterRgbBilinear <T> sg = new SpanImageFilterRgbBilinear <T>(source, interpolator);
#else
                //span_image_filter_rgba_bilinear_clip sg = new span_image_filter_rgba_bilinear_clip(pixf_img, rgba.rgba_pre(0, 0, 0, 0), interpolator);
                span_image_filter_rgba_bilinear sg = new span_image_filter_rgba_bilinear(source, interpolator);
#endif
                m_Rasterizer.AddPath(tr);
                Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg);
            }
            break;

            case 5:
            case 6:
            case 7:
            {
                switch (m_filters.cur_item())
                {
                case 5: filter.Calculate(new ImageFilterHanning <T>(), norm); break;

                case 6: filter.Calculate(new ImageFilterHamming <T>(), norm); break;

                case 7: filter.Calculate(new ImageFilterHermite <T>(), norm); break;
                }

                SpanImageFilterRgb2x2 <T> sg = new SpanImageFilterRgb2x2 <T>(source, interpolator, filter);
                m_Rasterizer.AddPath(tr);
                Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg);
            }
            break;

            case 2:
            case 3:
            case 4:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            {
                switch (m_filters.cur_item())
                {
                case 2: filter.Calculate(new ImageFilterBicubic <T>(), norm); break;

                case 3: filter.Calculate(new ImageFilterSpline16 <T>(), norm); break;

                case 4: filter.Calculate(new ImageFilterSpline36 <T>(), norm); break;

                case 8: filter.Calculate(new ImageFilterKaiser <T>(), norm); break;

                case 9: filter.Calculate(new ImageFilterQuadric <T>(), norm); break;

                case 10: filter.Calculate(new ImageFilterCatrom <T>(), norm); break;

                case 11: filter.Calculate(new ImageFilterGaussian <T>(), norm); break;

                case 12: filter.Calculate(new ImageFilterBessel <T>(), norm); break;

                case 13: filter.Calculate(new ImageFilterMitchell <T>(), norm); break;

                case 14: filter.Calculate(new ImageFilterSinc <T>(m_radius.value()), norm); break;

                case 15: filter.Calculate(new ImageFilterLanczos <T>(m_radius.value()), norm); break;

                case 16:
                    filter.Calculate(new ImageFilterBlackman <T>(m_radius.value()), norm);
                    break;
                }

#if SourceDepth24
                SpanImageFilterRgb <T> sg = new SpanImageFilterRgb <T>(source, interpolator, filter);
#else
                span_image_filter_rgb sg = new span_image_filter_rgba(source, interpolator, filter);
#endif
                m_Rasterizer.AddPath(tr);
                Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg);
            }
            break;
            }
        }
Пример #12
0
        public override void OnDraw()
        {
            //typedef agg::renderer_base<agg::pixfmt_bgr24> ren_base;

            FormatRGB           pixf          = new FormatRGB(rbuf_window(), new BlenderBGR());
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);

            clippingProxy.Clear(new RGBA_Doubles(1, 1, 1));
            m_ras.SetVectorClipBox(0, 0, width().ToDouble(), height().ToDouble());

            IAffineTransformMatrix <T> move = MatrixFactory <T> .NewTranslation(10, 10);

            Perspective <T> shadow_persp = new Perspective <T>(m_shape_bounds.x1, m_shape_bounds.y1,
                                                               m_shape_bounds.x2, m_shape_bounds.y2,
                                                               m_shadow_ctrl.polygon());

            IVertexSource <T> shadow_trans;

            if (m_FlattenCurves.status())
            {
                shadow_trans = new ConvTransform <T>(m_shape, shadow_persp);
            }
            else
            {
                shadow_trans = new ConvTransform <T>(m_path, shadow_persp);
                // this will make it very smooth after the Transform
                //shadow_trans = new conv_curve(shadow_trans);
            }


            // Render shadow
            m_ras.AddPath(shadow_trans);
            Renderer <T> .RenderSolid(clippingProxy, m_ras, m_sl, new RGBA_Doubles(0.2, 0.3, 0).GetAsRGBA_Bytes());

            // Calculate the bounding box and extend it by the blur radius
            RectDouble <T> bbox = new RectDouble <T>();

            BoundingRect <T> .BoundingRectSingle(shadow_trans, 0, ref bbox);

            bbox.x1.SubtractEquals(m_radius.value());
            bbox.y1.SubtractEquals(m_radius.value());
            bbox.x2.AddEquals(m_radius.value());
            bbox.y2.AddEquals(m_radius.value());

            if (m_method.cur_item() == 1)
            {
                // The recursive blur method represents the true Gaussian Blur,
                // with theoretically infinite kernel. The restricted window size
                // results in extra influence of edge pixels. It's impossible to
                // solve correctly, but extending the right and top areas to another
                // radius Value produces fair result.
                //------------------
                bbox.x2.AddEquals(m_radius.value());
                bbox.y2.AddEquals(m_radius.value());
            }

            start_timer();

            if (m_method.cur_item() != 2)
            {
                // Create a new pixel renderer and Attach it to the main one as a child image.
                // It returns true if the attachment succeeded. It fails if the rectangle
                // (bbox) is fully clipped.
                //------------------
                FormatRGB pixf2 = new FormatRGB(m_rbuf2, new BlenderBGR());
                if (pixf2.Attach(pixf, (int)bbox.x1.ToInt(), (int)bbox.y1.ToInt(), (int)bbox.x2.ToInt(), (int)bbox.y2.ToInt()))
                {
                    // Blur it
                    if (m_method.cur_item() == 0)
                    {
                        // More general method, but 30-40% slower.
                        //------------------
                        //m_stack_blur.blur(pixf2, agg::uround(m_radius.Value()));

                        // Faster, but bore specific.
                        // Works only for 8 bits per channel and only with radii <= 254.
                        //------------------
                        //                         agg::stack_blur_rgb24(pixf2, agg::uround(m_radius.Value()),
                        //                                                      agg::uround(m_radius.Value()));
                    }
                    else
                    {
                        // True Gaussian Blur, 3-5 times slower than Stack Blur,
                        // but still constant time of radius. Very sensitive
                        // to precision, doubles are must here.
                        //------------------
                        m_recursive_blur.Blur(pixf2, m_radius.value().ToDouble());
                    }
                }
            }
            else
            {
                /*
                 * // Blur separate channels
                 * //------------------
                 * if(m_channel_r.status())
                 * {
                 *  typedef agg::pixfmt_alpha_blend_gray<
                 *      agg::blender_gray8,
                 *      agg::rendering_buffer,
                 *      3, 2> pixfmt_gray8r;
                 *
                 *  pixfmt_gray8r pixf2r(m_rbuf2);
                 *  if(pixf2r.Attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *  {
                 *      agg::stack_blur_gray8(pixf2r, agg::uround(m_radius.Value()),
                 *                                    agg::uround(m_radius.Value()));
                 *  }
                 * }
                 *
                 * if(m_channel_g.status())
                 * {
                 *  typedef agg::pixfmt_alpha_blend_gray<
                 *      agg::blender_gray8,
                 *      agg::rendering_buffer,
                 *      3, 1> pixfmt_gray8g;
                 *
                 *  pixfmt_gray8g pixf2g(m_rbuf2);
                 *  if(pixf2g.Attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *  {
                 *      agg::stack_blur_gray8(pixf2g, agg::uround(m_radius.Value()),
                 *                                    agg::uround(m_radius.Value()));
                 *  }
                 * }
                 *
                 * if(m_channel_b.status())
                 * {
                 *  typedef agg::pixfmt_alpha_blend_gray<
                 *      agg::blender_gray8,
                 *      agg::rendering_buffer,
                 *      3, 0> pixfmt_gray8b;
                 *
                 *  pixfmt_gray8b pixf2b(m_rbuf2);
                 *  if(pixf2b.Attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *  {
                 *      agg::stack_blur_gray8(pixf2b, agg::uround(m_radius.Value()),
                 *                                    agg::uround(m_radius.Value()));
                 *  }
                 * }
                 */
            }

            double tm = elapsed_time();

            //m_shadow_ctrl.Render(m_ras, m_sl, clippingProxy);

            // Render the shape itself
            //------------------
            if (m_FlattenCurves.status())
            {
                m_ras.AddPath(m_shape);
            }
            else
            {
                m_ras.AddPath(m_path);
            }

            Renderer <T> .RenderSolid(clippingProxy, m_ras, m_sl, new RGBA_Doubles(0.6, 0.9, 0.7, 0.8).GetAsRGBA_Bytes());

            GsvText <T> t = new GsvText <T>();

            t.SetFontSize(10.0);

            ConvStroke <T> st = new ConvStroke <T>(t);

            st.Width = M.New <T>(1.5);

            string buf;

            buf = string.Format("{0:F2} ms", tm);
            t.StartPoint(140.0, 30.0);
            t.Text = buf;

            m_ras.AddPath(st);
            Renderer <T> .RenderSolid(clippingProxy, m_ras, m_sl, new RGBA_Doubles(0, 0, 0).GetAsRGBA_Bytes());


            //m_method.Render(m_ras, m_sl, clippingProxy);
            //m_radius.Render(m_ras, m_sl, clippingProxy);
            //m_channel_r.Render(m_ras, m_sl, clippingProxy);
            //m_channel_g.Render(m_ras, m_sl, clippingProxy);
            //m_channel_b.Render(m_ras, m_sl, clippingProxy);
            //m_FlattenCurves.Render(m_ras, m_sl, clippingProxy);
            base.OnDraw();
        }
Пример #13
0
        public override void OnDraw()
        {
            int width  = (int)rbuf_window().Width;
            int height = (int)rbuf_window().Height;

            if (m_num_cb.value().NotEqual(m_slider_value))
            {
                generate_alpha_mask(width, height);
                m_slider_value = m_num_cb.value();
            }

            g_rasterizer.SetVectorClipBox(0, 0, width, height);

            IPixelFormat pf = new FormatRGB(rbuf_window(), new BlenderBGR());

            unsafe
            {
                fixed(byte *pAlphaBuffer = m_alpha_buf)
                {
                    m_alpha_mask_rbuf.attach(pAlphaBuffer, (uint)width, (uint)height, width, 1);

                    AGG.PixelFormat.AlphaMaskAdaptor pixFormatAlphaMaskAdaptor = new AGG.PixelFormat.AlphaMaskAdaptor(pf, m_alpha_mask);
                    FormatClippingProxy alphaMaskClippingProxy = new FormatClippingProxy(pixFormatAlphaMaskAdaptor);
                    FormatClippingProxy clippingProxy          = new FormatClippingProxy(pf);

                    IAffineTransformMatrix <T> mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

                    mtx.Translate(MatrixFactory <T> .CreateVector2D(g_base_dx.Negative(), g_base_dy.Negative()));
                    mtx.Scale(g_scale);
                    mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), g_angle.Add(Math.PI).ToDouble());
                    mtx.Shear(MatrixFactory <T> .CreateVector2D(g_skew_x.Divide(1000.0), g_skew_y.Divide(1000.0)));
                    mtx.Translate(MatrixFactory <T> .CreateVector2D(width / 2, height / 2));

                    clippingProxy.Clear(new RGBA_Doubles(1, 1, 1));

                    // draw a background to show how the mask is working better
                    int RectWidth = 30;

                    for (int i = 0; i < 40; i++)
                    {
                        for (int j = 0; j < 40; j++)
                        {
                            if ((i + j) % 2 != 0)
                            {
                                VertexSource.RoundedRect <T> rect = new VertexSource.RoundedRect <T>(i * RectWidth, j * RectWidth, (i + 1) * RectWidth, (j + 1) * RectWidth, 0);
                                rect.NormalizeRadius();

                                // Drawing as an outline
                                g_rasterizer.AddPath(rect);
                                Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(.9, .9, .9));
                            }
                        }
                    }

                    //int x, y;

                    // Render the lion
                    ConvTransform <T> trans = new ConvTransform <T>(g_path, mtx);

                    Renderer <T> .RenderSolidAllPaths(alphaMaskClippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths);

                    /*
                     * // 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);
                }

                m_alpha_mask_rbuf.dettachBuffer();
            }
            base.OnDraw();
        }
Пример #14
0
        public override void OnDraw()
        {
            RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>();
            ScanlineUnpacked8        sl  = new ScanlineUnpacked8();

#if SourceDepth24
            FormatRGB pixf = new FormatRGB(rbuf_window(), new BlenderBGR());
#else
            FormatRGBA pixf = new FormatRGBA(rbuf_window(), new blender_bgra32());
#endif
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);
            clippingProxy.Clear(new RGBA_Doubles(0, 0, 0));

            m_profile.text_size(8.0);

            //m_profile.Render(ras, sl, clippingProxy);
            //m_spline_r.Render(ras, sl, clippingProxy);
            //m_spline_g.Render(ras, sl, clippingProxy);
            //m_spline_b.Render(ras, sl, clippingProxy);
            //m_spline_a.Render(ras, sl, clippingProxy);
            //m_GradTypeRBox.Render(ras, sl, clippingProxy);
            //m_GradWrapRBox.Render(ras, sl, clippingProxy);

            // draw a background to show how the alpha is working
            int RectWidth = 32;
            int xoffset   = 238;
            int yoffset   = 171;
            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect <T> rect = new VertexSource.RoundedRect <T>(i * RectWidth + xoffset, j * RectWidth + yoffset,
                                                                                             (i + 1) * RectWidth + xoffset, (j + 1) * RectWidth + yoffset, 2);
                        rect.NormalizeRadius();

                        // Drawing as an outline
                        ras.AddPath(rect);
                        Renderer <T> .RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(.9, .9, .9));
                    }
                }
            }

            double ini_scale = 1.0;

            IAffineTransformMatrix <T> mtx1 = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            mtx1.Scale(MatrixFactory <T> .CreateVector2D(ini_scale, ini_scale));
            mtx1.Translate(MatrixFactory <T> .CreateVector2D(center_x, center_y));
            mtx1.Add(trans_affine_resizing());

            VertexSource.Ellipse <T> e1 = new AGG.VertexSource.Ellipse <T>();
            e1.Init(0.0, 0.0, 110.0, 110.0, 64);

            IAffineTransformMatrix <T> mtx_g1 = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(ini_scale, ini_scale));
            mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(m_SaveData.m_scale, m_SaveData.m_scale));
            mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(m_scale_x, m_scale_y));
            mtx_g1.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_SaveData.m_angle.ToDouble());
            mtx_g1.Translate(MatrixFactory <T> .CreateVector2D(m_SaveData.m_center_x, m_SaveData.m_center_y));
            mtx_g1.Add(trans_affine_resizing());
            mtx_g1 = mtx_g1.Inverse;


            RGBA_Bytes[] color_profile = new RGBA_Bytes[256]; // color_type is defined in pixel_formats.h
            for (int i = 0; i < 256; i++)
            {
                color_profile[i] = new RGBA_Bytes(m_spline_r.spline()[i].ToInt(),
                                                  m_spline_g.spline()[i].ToInt(),
                                                  m_spline_b.spline()[i].ToInt(),
                                                  m_spline_a.spline()[i].ToInt());
            }

            ConvTransform <T> t1 = new ConvTransform <T>(e1, mtx1);

            IGradient innerGradient = null;
            switch (m_GradTypeRBox.cur_item())
            {
            case 0:
                innerGradient = new GradientRadial();
                break;

            case 1:
                innerGradient = new GradientDiamond();
                break;

            case 2:
                innerGradient = new GradientX();
                break;

            case 3:
                innerGradient = new GradientXY();
                break;

            case 4:
                innerGradient = new GradientSqrtXY();
                break;

            case 5:
                innerGradient = new GradientConic();
                break;
            }

            IGradient outerGradient = null;
            switch (m_GradWrapRBox.cur_item())
            {
            case 0:
                outerGradient = new GradientReflectAdaptor(innerGradient);
                break;

            case 1:
                outerGradient = new GradientRepeatAdaptor(innerGradient);
                break;

            case 2:
                outerGradient = new GradientClampAdaptor(innerGradient);
                break;
            }

            SpanAllocator              span_alloc = new SpanAllocator();
            ColorFunctionProfile       colors     = new ColorFunctionProfile(color_profile, m_profile.gamma());
            SpanInterpolatorLinear <T> inter      = new SpanInterpolatorLinear <T>(mtx_g1);
            SpanGradient <T>           span_gen   = new SpanGradient <T>(inter, outerGradient, colors, 0, 150);

            ras.AddPath(t1);
            Renderer <T> .GenerateAndRender(ras, sl, clippingProxy, span_alloc, span_gen);

            base.OnDraw();
        }
Пример #15
0
        public override void OnDraw()
        {
            //typedef agg::renderer_base<pixfmt>     renderer_base;
            //typedef agg::renderer_base<pixfmt_pre> renderer_base_pre;

#if SourceDepth24
            pixfmt_alpha_blend_rgb pixf     = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr());
            pixfmt_alpha_blend_rgb pixf_pre = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr_pre());
#else
            FormatRGBA pixf     = new FormatRGBA(rbuf_window(), new BlenderBGRA());
            FormatRGBA pixf_pre = new FormatRGBA(rbuf_window(), new BlenderPreMultBGRA());
#endif
            FormatClippingProxy clippingProxy     = new FormatClippingProxy(pixf);
            FormatClippingProxy clippingProxy_pre = new FormatClippingProxy(pixf_pre);

            clippingProxy.Clear(new RGBA_Doubles(1.0, 1.0, 1.0));

            IAffineTransformMatrix <T> src_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            src_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Negative().Divide(2).Subtract(10), initial_height().Negative().Divide(2).Subtract(30)));
            src_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_angle.value().Multiply(Math.PI / 180.0).ToDouble());
            src_mtx.Scale(m_scale.value());
            src_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Divide(2), initial_height().Divide(2).Add(20)));
            src_mtx.Multiply(trans_affine_resizing());

            IAffineTransformMatrix <T> img_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            img_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Negative().Divide(2).Add(10), initial_height().Negative().Divide(2).Add(30)));
            img_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_angle.value().Multiply(Math.PI / 180.0).ToDouble());
            img_mtx.Scale(m_scale.value());
            img_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Divide(2), initial_height().Divide(2).Add(20)));
            img_mtx.Multiply(trans_affine_resizing());
            img_mtx = img_mtx.Inverse;

            AGG.SpanAllocator sa = new SpanAllocator();

            SpanInterpolatorLinear <T> interpolator = new SpanInterpolatorLinear <T>(img_mtx);

#if SourceDepth24
            pixfmt_alpha_blend_rgb img_pixf = new pixfmt_alpha_blend_rgb(rbuf_img(0), new blender_bgr());
#else
            FormatRGBA img_pixf = new FormatRGBA(rbuf_img(0), new BlenderBGRA());
#endif

#if SourceDepth24
            span_image_filter_rgb_bilinear_clip sg;
            sg = new span_image_filter_rgb_bilinear_clip(img_pixf, rgba.rgba_pre(0, 0.4, 0, 0.5), interpolator);
#else
            SpanImageFilterRgbaBilinearClip <T> sg;
            RasterBufferAccessorClip            source = new RasterBufferAccessorClip(img_pixf, RGBA_Doubles.RgbaPre(0, 0, 0, 0));
            sg = new SpanImageFilterRgbaBilinearClip <T>(source, RGBA_Doubles.RgbaPre(0, 0.4, 0, 0.5), interpolator);
#endif

            RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>();
            ras.SetVectorClipBox(M.Zero <T>(), M.Zero <T>(), width(), height());
            //agg.scanline_packed_8 sl = new scanline_packed_8();
            ScanlineUnpacked8 sl = new ScanlineUnpacked8();

            T r = initial_width();
            if (initial_height().Subtract(60).LessThan(r))
            {
                r = initial_height().Subtract(60);
            }

            Ellipse <T> ell = new Ellipse <T>(initial_width().Divide(2.0).Add(10),
                                              initial_height().Divide(2.0).Add(30),
                                              r.Divide(2.0).Add(16.0),
                                              r.Divide(2.0).Add(16.0), 200);

            ConvTransform <T> tr = new ConvTransform <T>(ell, src_mtx);

            ras.AddPath(tr);
#if use_timers
            for (uint j = 0; j < 10; j++)
            {
                Renderer.GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg);
            }
            AllTimer.Start();
            image1_100_Times.Start();
            for (uint i = 0; i < 500; i++)
            {
#endif
            //clippingProxy_pre.SetClippingBox(30, 0, (int)width(), (int)height());
            //clippingProxy.SetClippingBox(30, 0, (int)width(), (int)height());
            Renderer <T> .GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg);

#if use_timers
        }

        image1_100_Times.Stop();
#endif

            //m_angle.SetTransform(trans_affine_resizing());
            //m_scale.SetTransform(trans_affine_resizing());
#if use_timers
            AllTimer.Stop();
            CExecutionTimer.Instance.AppendResultsToFile("TimingTest.txt", AllTimer.GetTotalSeconds());
            CExecutionTimer.Instance.Reset();
#endif
            base.OnDraw();
        }
Пример #16
0
        public override void OnDraw()
        {
            GammaLut            gamma         = new GammaLut(m_gamma.value().ToDouble());
            IBlender            NormalBlender = new BlenderBGRA();
            IBlender            GammaBlender  = new BlenderGammaBGRA(gamma);
            FormatRGBA          pixf          = new FormatRGBA(rbuf_window(), NormalBlender);
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);

            clippingProxy.Clear(m_white_on_black.status() ? new RGBA_Doubles(0, 0, 0) : new RGBA_Doubles(1, 1, 1));

            RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>();
            ScanlinePacked8          sl  = new ScanlinePacked8();

            Ellipse <T> e = new Ellipse <T>();

            // 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], M.New <T>(3), M.New <T>(3), 16);
            ras.AddPath(e);
            Renderer <T> .RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(127, 127, 127));

            e.Init(m_x[1], m_y[1], M.New <T>(3), M.New <T>(3), 16);
            ras.AddPath(e);
            Renderer <T> .RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(127, 127, 127));

            T d = m_offset.value();

            // Creating a rounded rectangle
            RoundedRect <T> r = new RoundedRect <T>(m_x[0].Add(d), m_y[0].Add(d), m_x[1].Add(d), m_y[1].Add(d), m_radius.value());

            r.NormalizeRadius();

            // Drawing as an outline
            if (!m_DrawAsOutlineCheckBox.status())
            {
                ConvStroke <T> p = new ConvStroke <T>(r);
                p.Width = M.One <T>();
                ras.AddPath(p);
            }
            else
            {
                ras.AddPath(r);
            }

            pixf.Blender = GammaBlender;
            Renderer <T> .RenderSolid(clippingProxy, ras, sl, m_white_on_black.status()?new RGBA_Bytes(1, 1, 1) : new RGBA_Bytes(0, 0, 0));

            // this was in the original demo, but it does nothing because we changed the blender not the gamma function.
            //ras.gamma(new gamma_none());
            // so let's change the blender instead
            pixf.Blender = NormalBlender;

            // Render the controls
            //m_radius.Render(ras, sl, clippingProxy);
            //m_gamma.Render(ras, sl, clippingProxy);
            //m_offset.Render(ras, sl, clippingProxy);
            //m_white_on_black.Render(ras, sl, clippingProxy);
            //m_DrawAsOutlineCheckBox.Render(ras, sl, clippingProxy);
            base.OnDraw();
        }