Пример #1
0
        public static IAffineTransformMatrix <T> NewRotation(VectorDimension dimension, double r)
        {
            IAffineTransformMatrix <T> a = MatrixFactory <T> .NewIdentity(dimension);

            a.RotateAlong(MatrixFactory <T> .CreateZeroVector(dimension), r);
            return(a);
        }
Пример #2
0
        public override void OnKeyDown(AGG.UI.KeyEventArgs keyEvent)
        {
            if (keyEvent.KeyCode == Keys.Space)
            {
                T cx = m_quad.xn(0).Add(m_quad.xn(1)).Add(m_quad.xn(2)).Add(m_quad.xn(3)).Divide(4);
                T cy = m_quad.yn(0).Add(m_quad.yn(1)).Add(m_quad.yn(2)).Add(m_quad.yn(3)).Divide(4);
                IAffineTransformMatrix <T> tr = MatrixFactory <T> .NewTranslation(cx.Negative(), cy.Negative());

                tr.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), (Math.PI / 2.0));
                tr.Translate(MatrixFactory <T> .CreateVector2D(cx, cy));
                T xn0 = m_quad.xn(0); T yn0 = m_quad.yn(0);
                T xn1 = m_quad.xn(1); T yn1 = m_quad.yn(1);
                T xn2 = m_quad.xn(2); T yn2 = m_quad.yn(2);
                T xn3 = m_quad.xn(3); T yn3 = m_quad.yn(3);
                tr.Transform(ref xn0, ref yn0);
                tr.Transform(ref xn1, ref yn1);
                tr.Transform(ref xn2, ref yn2);
                tr.Transform(ref xn3, ref yn3);
                m_quad.SetXN(0, xn0); m_quad.SetYN(0, yn0);
                m_quad.SetXN(1, xn1); m_quad.SetYN(1, yn1);
                m_quad.SetXN(2, xn2); m_quad.SetYN(2, yn2);
                m_quad.SetXN(3, xn3); m_quad.SetYN(3, yn3);
                force_redraw();
            }

            base.OnKeyDown(keyEvent);
        }
Пример #3
0
        public static IAffineTransformMatrix <T> NewRotation(IVector <T> axis, double r)
        {
            IAffineTransformMatrix <T> a = MatrixFactory <T> .NewIdentity(axis.RowCount);

            a.RotateAlong(axis, r);
            return(a);
        }
Пример #4
0
        protected override void DoDraw(RendererBase <T> destRenderer)
        {
            IAffineTransformMatrix <T> Final = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            Final.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_Rotation.ToDouble());
            Final.Translate(m_Position);
            ConvTransform <T> TransformedShip = new ConvTransform <T>(m_PlayerToDraw, Final);

            destRenderer.Render(TransformedShip, new RGBA_Bytes(.9, .4, .2, 1));
        }
Пример #5
0
        public static void glRotatef(double AngleDegrees, T AxisX, T AxisY, T AxisZ)
        {
            //if (s_BeginMode != 0) throw new System.FormatException("You cannot call this inside a Begin - End section.");
            //Vector3D Axis = new Vector3D(AxisX, AxisY, AxisZ);
            //Matrix4X4 Matrix = new Matrix4X4();
            //double AngleRadians = Helper.DegToRad(AngleDegrees);
            //Matrix.Rotate(Axis, AngleRadians);

            //glMultMatrixf(Matrix.GetElements());
            m_CurEditingMatrix.RotateAlong(MatrixFactory <T> .CreateVector3D(AxisX, AxisY, AxisZ), Helper.DegToRad(AngleDegrees));
        }
Пример #6
0
        void DrawAATest()
        {
            PathStorage <T> PolgonToDraw = new PathStorage <T>();
            T    Angle        = M.Zero <T>();
            bool DrawTrinagle = true;

            if (DrawTrinagle)
            {
                PolgonToDraw.MoveTo(Angle.Cos(), Angle.Sin());
                Angle.AddEquals(120.0 / 180.0 * Math.PI);
                PolgonToDraw.LineTo(Angle.Cos(), Angle.Sin());
                Angle.AddEquals(120.0 / 180.0 * Math.PI);
                PolgonToDraw.LineTo(Angle.Cos(), Angle.Sin());
                Angle.AddEquals(120.0 / 180.0 * Math.PI);
                //Triangle.line_to(Math.Cos(Angle), Math.Sin(Angle));
                PolgonToDraw.ClosePolygon();
            }
            else
            {
                PolgonToDraw.MoveTo(M.Zero <T>(), M.Zero <T>());
                PolgonToDraw.LineTo(M.One <T>(), M.Zero <T>());
                PolgonToDraw.LineTo(M.One <T>(), M.One <T>());
                PolgonToDraw.LineTo(M.Zero <T>(), M.One <T>());
                PolgonToDraw.ClosePolygon();
            }

            IAffineTransformMatrix <T> tran = MatrixFactory <T> .NewScaling(VectorDimension.Two, M.New <T>(80));

            tran.RotateAlong(MatrixFactory <T> .CreateVector2D(M.Zero <T>(), M.Zero <T>()), Math.PI / 8);
            tran.Translate(MatrixFactory <T> .CreateVector2D(M.New <T>(500), M.New <T>(100)));

            ConvTransform <T> TransformedPolygon = new ConvTransform <T>(PolgonToDraw, tran);

            ((RendererOpenGL <T>)GetRenderer()).m_ForceTexturedEdgeAntiAliasing = true;
            GetRenderer().Render(TransformedPolygon, new RGBA_Bytes(0, 0, 0));

            Ellipse <T> testEllipse = new Ellipse <T>(M.New <T>(300), M.New <T>(250), M.New <T>(60), M.New <T>(60));

            GetRenderer().Render(testEllipse, new RGBA_Bytes(205, 23, 12, 120));
            ((RendererOpenGL <T>)GetRenderer()).m_ForceTexturedEdgeAntiAliasing = false;

            //conv_stroke OutLine = new conv_stroke(TransformedPolygon);
            //OutLine.width(2);
            //conv_transform TransformedOutLine = new conv_transform(OutLine, Affine.NewTranslation(100, 0));
            //GetRenderer().Render(TransformedOutLine, new RGBA_Bytes(0, 0, 0));

            //conv_transform TransformedOutLine2 = new conv_transform(OutLine, Affine.NewScaling(6) * Affine.NewTranslation(200, 0));
            //conv_stroke OutLineOutLine = new conv_stroke(TransformedOutLine2);
            //GetRenderer().Render(OutLineOutLine, new RGBA_Bytes(0, 0, 0));
        }
Пример #7
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();
        }
Пример #8
0
        //used to Transform the sweepers vertices prior to rendering
        public void WorldTransform(List <IVector <T> > sweeper)
        {
            ////create the world transformation matrix
            //Matrix4X4 matTransform = new Matrix4X4();

            ////scale
            //matTransform.Scale(m_dScale, m_dScale, 1);

            ////rotate
            //matTransform.AddRotate(2, (double)m_dRotation);

            ////and translate
            //matTransform.AddTranslate(m_vPosition.x, m_vPosition.y, 0);

            ////now Transform the ships vertices
            //for (int i = 0; i < sweeper.Count; i++)
            //{
            //    Vector3D Temp = sweeper[i];
            //    matTransform.TransformVector(ref Temp);
            //    sweeper[i] = Temp;
            //}

            //create the world transformation matrix
            IAffineTransformMatrix <T> matTransform = MatrixFactory <T> .NewIdentity(VectorDimension.Three);

            //scale
            matTransform.Scale(MatrixFactory <T> .CreateVector3D(m_dScale, m_dScale, M.One <T>()));

            //rotate
            //matTransform.AddRotate(2, (double)m_dRotation);
            IVector <T> axis = null;/// need to work out which axis this should be

            matTransform.RotateAlong(axis, m_dRotation);


            //and translate
            matTransform.Translate(MatrixFactory <T> .CreateVector3D(m_vPosition[0], m_vPosition[1], M.Zero <T>()));

            //now Transform the ships vertices
            for (int i = 0; i < sweeper.Count; i++)
            {
                IVector <T> Temp = sweeper[i];
                Temp       = matTransform.TransformVector(Temp);
                sweeper[i] = Temp;
            }
        }
Пример #9
0
        public override void OnDraw()
        {
#if use_timers
            AllTimer.Start();
#endif
            int width  = (int)rbuf_window().Width;
            int height = (int)rbuf_window().Height;

            uint i;
            for (i = 0; i < m_NumPaths; i++)
            {
                // g_colors[i].A_Byte = (byte)(m_AlphaSlider.value() * 255);
                g_colors[i] = RGBA_Bytes.ModifyComponent(g_colors[i], Component.A, (byte)(m_AlphaSlider.value().ToDouble() * 255));
            }

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

            transform.Translate(MatrixFactory <T> .CreateVector2D(g_base_dx.Negative(), g_base_dy.Negative()));
            transform.Scale(MatrixFactory <T> .CreateVector2D(g_scale, g_scale));
            transform.RotateAlong(MatrixFactory <T> .CreateVector2D(M.Zero <T>(), M.Zero <T>()), g_angle + Math.PI);
            transform.Shear(MatrixFactory <T> .CreateVector2D(g_skew_x.Divide(1000.0), g_skew_y.Divide(1000.0)));
            transform.Translate(MatrixFactory <T> .CreateVector2D(M.New <T>(width).Divide(2), M.New <T>(height).Divide(2)));

            // This code renders the lion:
            ConvTransform <T> transformedPathStorage = new ConvTransform <T>(g_PathStorage, transform);
#if use_timers
            Lion50Timer.Start();
            for (uint j = 0; j < 200; j++)
#endif
            {
                this.GetRenderer().Render(transformedPathStorage, g_colors, g_path_idx, m_NumPaths);
            }
#if use_timers
            Lion50Timer.Stop();
#endif

#if use_timers
            AllTimer.Stop();
            CExecutionTimer.Instance.AppendResultsToFile("TimingTest.txt", AllTimer.GetTotalSeconds());
            CExecutionTimer.Instance.Reset();
#endif
            base.OnDraw();
        }
Пример #10
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;
            }
        }
Пример #11
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();
        }
Пример #12
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();
        }
Пример #13
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();
        }