예제 #1
0
        public static void CreateContext(RasterBuffer renderingBuffer)
        {
            // set the rendering buffer and all the GL default states (this is also where you can new anything you need)
            s_RenderingBuffer = renderingBuffer;
            s_Rasterizer.SetVectorClipBox(M.Zero <T>(), M.Zero <T>(), M.New <T>(s_RenderingBuffer.Width), M.New <T>(s_RenderingBuffer.Height));
            s_PixelFormt = new FormatRGBA(s_RenderingBuffer, new BlenderBGRA());
            s_ClippingPixelFormatProxy = new FormatClippingProxy(s_PixelFormt);
            //s_ClippingPixelFormatProxy = s_PixelFormt;

            m_CurAccumulatedMatrix = MatrixFactory <T> .NewIdentity(VectorDimension.Three); // new Matrix4X4();

            m_ModelviewMatrix = MatrixFactory <T> .NewIdentity(VectorDimension.Three);      // new Matrix4X4();

            m_ProjectionMatrix = MatrixFactory <T> .NewIdentity(VectorDimension.Three);     //new Matrix4X4();

            m_pVertexCache = new VertexCachItem[m_MaxVertexCacheItems];
            for (int i = 0; i < m_MaxVertexCacheItems; i++)
            {
                m_pVertexCache[i] = new VertexCachItem();
            }

            m_LastSetColor  = new RGBA_Doubles(1, 1, 1, 1);
            m_LastSetNormal = MatrixFactory <T> .CreateZeroVector(VectorDimension.Three);          // new Vector3D();

            m_LastSetTextureCoordinate = MatrixFactory <T> .CreateZeroVector(VectorDimension.Two); // new Vector2D();
        }
예제 #2
0
        public override void Render(IVertexSource <T> vertexSource, uint pathIndexToRender, RGBA_Bytes colorBytes)
        {
#if use_timers
            OpenGLRenderTimer.Start();
#endif
            PushOrthoProjection();

            vertexSource.Rewind(pathIndexToRender);

            RGBA_Doubles color = colorBytes.GetAsRGBA_Doubles();

            Gl.glColor4d(color.R, color.G, color.B, color.A);

            IAffineTransformMatrix <T> transform = GetTransform();
            if (!transform.Equals(MatrixFactory <T> .NewIdentity(VectorDimension.Two)))
            {
                vertexSource = new ConvTransform <T>(vertexSource, transform);
            }

            if (m_ForceTexturedEdgeAntiAliasing)
            {
                DrawAAShape(vertexSource);
            }
            else
            {
                SendShapeToTeselator(m_RenderNowTesselator, vertexSource);
            }

            PopOrthoProjection();
#if use_timers
            OpenGLRenderTimer.Stop();
#endif
        }
예제 #3
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));
        }
예제 #4
0
 public lion_application(PixelFormats format, ERenderOrigin RenderOrigin)
     : base(format, RenderOrigin)
 {
     m_AlphaSlider = new UI.SliderWidget <T>(M.New <T>(5), M.New <T>(5), M.New <T>(512 - 5), M.New <T>(12));
     parse_lion();
     AddChild(m_AlphaSlider);
     m_AlphaSlider.SetTransform(MatrixFactory <T> .NewIdentity(VectorDimension.Two));
     m_AlphaSlider.label("Alpha {0:F3}");
     m_AlphaSlider.value(M.New <T>(0.1));
 }
예제 #5
0
        // format - see enum pix_format_e {};
        // flip_y - true if you want to have the Y-axis flipped vertically.
        public PlatformSupportAbstract(PixelFormats format, ERenderOrigin RenderOrigin)
        {
            m_format         = format;
            m_bpp            = GetBitDepthForPixelFormat(format);
            m_RenderOrigin   = RenderOrigin;
            m_initial_width  = 10;
            m_initial_height = 10;
            m_resize_mtx     = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            m_rbuf_img = new List <RasterBuffer>();
        }
예제 #6
0
 public override void Render(IVertexSource<T> vertexSource, uint pathIndexToRender, RGBA_Bytes colorBytes)
 {
     m_Rasterizer.Reset();
     IAffineTransformMatrix<T> transform = GetTransform();
     if (!transform.Equals(MatrixFactory<T>.NewIdentity(VectorDimension.Two)))
     {
         vertexSource = new ConvTransform<T>(vertexSource, transform);
     }
     m_Rasterizer.AddPath(vertexSource, pathIndexToRender);
     Renderer<T>.RenderSolid(m_PixelFormat, m_Rasterizer, m_ScanlineCache, colorBytes);
 }
예제 #7
0
        //-------------------------------------------------------------------
        public IAffineTransformMatrix <T> ToAffine()
        {
            //Affine mtx = Affine.NewTranslation(-m_wx1, -m_wy1);
            //mtx *= Affine.NewScaling(m_kx, m_ky);
            //mtx *= Affine.NewTranslation(m_dx1, m_dy1);
            //return mtx;
            IAffineTransformMatrix <T> a = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            a.Translate(MatrixFactory <T> .CreateVector2D(m_wx1.Negative(), m_wy1.Negative()));
            a.Scale(MatrixFactory <T> .CreateVector2D(m_kx, m_ky));
            a.Scale(MatrixFactory <T> .CreateVector2D(m_dx1, m_dy1));
            return(a);
        }
예제 #8
0
        public void TransformTest()
        {
            IAffineTransformMatrix <DoubleComponent> a = MatrixFactory <DoubleComponent> .NewIdentity(VectorDimension.Two);

            a.Translate(MatrixFactory <DoubleComponent> .CreateVector2D(10, 20));

            DoubleComponent x    = 10;
            DoubleComponent y    = 20;
            DoubleComponent newx = 0;
            DoubleComponent newy = 0;

            a.Transform(ref newx, ref newy);
            Assert.AreEqual((double)x, (double)newx, .001);
            Assert.AreEqual((double)y, (double)newy, .001);
        }
예제 #9
0
        public lion_outline_application(PixelFormats format, ERenderOrigin RenderOrigin)
            : base(format, RenderOrigin)
        {
            m_width_slider = new AGG.UI.SliderWidget <T>(5, 5, 150, 12);
            m_scanline     = new AGG.UI.cbox_ctrl <T>(160, 5, "Use Scanline Rasterizer");
            m_scanline.status(true);
            parse_lion();
            AddChild(m_width_slider);
            m_width_slider.SetTransform(MatrixFactory <T> .NewIdentity(VectorDimension.Two));
            m_width_slider.range(0.0, 4.0);
            m_width_slider.value(1.0);
            m_width_slider.label("Width {0:F2}");

            AddChild(m_scanline);
            m_scanline.SetTransform(MatrixFactory <T> .NewIdentity(VectorDimension.Two));
        }
예제 #10
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;
            }
        }
예제 #11
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();
        }
예제 #12
0
        public alpha_mask2_application(PixelFormats format, ERenderOrigin RenderOrigin)
            : base(format, RenderOrigin)
        {
            m_alpha_mask_rbuf = new RasterBuffer();
#if USE_CLIPPING_ALPHA_MASK
            m_alpha_mask = new AlphaMaskByteClipped(m_alpha_mask_rbuf, 1, 0);
#else
            m_alpha_mask = new AlphaMaskByteUnclipped(m_alpha_mask_rbuf, 1, 0);
#endif

            m_num_cb       = new UI.SliderWidget <T>(5, 5, 150, 12);
            m_slider_value = M.Zero <T>();
            parse_lion();
            AddChild(m_num_cb);
            m_num_cb.range(5, 100);
            m_num_cb.value(10);
            m_num_cb.label("N={0:F3}");
            m_num_cb.SetTransform(MatrixFactory <T> .NewIdentity(VectorDimension.Two));
        }
예제 #13
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();
        }
예제 #14
0
        public void WorldTransform(List <IVector <T> > VBuffer, IVector <T> vPos)
        {
            //create the world transformation matrix
            //Matrix4X4 matTransform = new Matrix4X4();

            IAffineTransformMatrix <T> matTransform = MatrixFactory <T> .NewIdentity(VectorDimension.Three);

            //scale
            matTransform.Scale(MatrixFactory <T> .CreateVector2D(m_MineScale, m_MineScale));

            //translate
            matTransform.Translate(MatrixFactory <T> .CreateVector2D(vPos[0], vPos[1]));

            //Transform the ships vertices
            for (int i = 0; i < VBuffer.Count; i++)
            {
                IVector <T> Temp = VBuffer[i];
                Temp       = matTransform.TransformVector(Temp);
                VBuffer[i] = Temp;
            }
        }
예제 #15
0
        public void InvertTest()
        {
            //Affine a = Affine.NewIdentity();
            IAffineTransformMatrix <DoubleComponent> a =
                MatrixFactory <DoubleComponent> .NewIdentity(VectorDimension.Two);

            a.Translate(
                MatrixFactory <DoubleComponent> .CreateVector2D(
                    M.New <DoubleComponent>(10),
                    M.New <DoubleComponent>(10)));

            IAffineTransformMatrix <DoubleComponent> b = MatrixFactory <DoubleComponent> .CreateAffine(a);

            b = b.Inverse;



            DoubleComponent x    = 100;
            DoubleComponent y    = 100;
            DoubleComponent newx = x;
            DoubleComponent newy = y;

            IVector <DoubleComponent> v1 =
                MatrixFactory <DoubleComponent> .CreateVector2D(
                    M.New <DoubleComponent>(100),
                    M.New <DoubleComponent>(100));

            IVector <DoubleComponent> v2 = a.TransformVector(v1);
            IVector <DoubleComponent> v3 = b.TransformVector(v2);


            //a.Transform(ref newx, ref newy);
            //b.Transform(ref newx, ref newy);
            Assert.AreEqual((double)v1[0], (double)v3[0], .001);
            Assert.AreEqual((double)v1[1], (double)v3[1], .001);
        }
예제 #16
0
 public RendererBase()
 {
     TextPath     = new GsvText <T>();
     StrockedText = new ConvStroke <T>(TextPath);
     m_AffineTransformStack.Push(MatrixFactory <T> .NewIdentity(VectorDimension.Two));
 }
예제 #17
0
        public blur_application(PixelFormats format, ERenderOrigin RenderOrigin)
            : base(format, RenderOrigin)
        {
            m_rbuf2         = new RasterBuffer();
            m_shape_bounds  = new RectDouble <T>();
            m_method        = new rbox_ctrl <T>(10.0, 10.0, 130.0, 70.0);
            m_radius        = new SliderWidget <T>(130 + 10.0, 10.0 + 4.0, 130 + 300.0, 10.0 + 8.0 + 4.0);
            m_shadow_ctrl   = new polygon_ctrl <T>(4);
            m_channel_r     = new cbox_ctrl <T>(10.0, 80.0, "Red");
            m_channel_g     = new cbox_ctrl <T>(10.0, 95.0, "Green");
            m_channel_b     = new cbox_ctrl <T>(10.0, 110.0, "Blue");
            m_FlattenCurves = new cbox_ctrl <T>(10, 315, "Convert And Flatten Curves");
            m_FlattenCurves.status(true);

            AddChild(m_method);
            m_method.text_size(8);
            m_method.add_item("Stack Blur");
            m_method.add_item("Recursive Blur");
            m_method.add_item("Channels");
            m_method.cur_item(1);

            AddChild(m_radius);
            m_radius.range(0.0, 40.0);
            m_radius.value(15.0);
            m_radius.label("Blur Radius={0:F2}");

            AddChild(m_shadow_ctrl);

            AddChild(m_channel_r);
            AddChild(m_channel_g);
            AddChild(m_channel_b);
            AddChild(m_FlattenCurves);
            m_channel_g.status(true);

            m_sl    = new ScanlinePacked8();
            m_path  = new PathStorage <T>();
            m_shape = new ConvCurve <T>(m_path);

            m_path.RemoveAll();
            m_path.MoveTo(28.47, 6.45);
            m_path.Curve3(21.58, 1.12, 19.82, 0.29);
            m_path.Curve3(17.19, -0.93, 14.21, -0.93);
            m_path.Curve3(9.57, -0.93, 6.57, 2.25);
            m_path.Curve3(3.56, 5.42, 3.56, 10.60);
            m_path.Curve3(3.56, 13.87, 5.03, 16.26);
            m_path.Curve3(7.03, 19.58, 11.99, 22.51);
            m_path.Curve3(16.94, 25.44, 28.47, 29.64);
            m_path.LineTo(28.47, 31.40);
            m_path.Curve3(28.47, 38.09, 26.34, 40.58);
            m_path.Curve3(24.22, 43.07, 20.17, 43.07);
            m_path.Curve3(17.09, 43.07, 15.28, 41.41);
            m_path.Curve3(13.43, 39.75, 13.43, 37.60);
            m_path.LineTo(13.53, 34.77);
            m_path.Curve3(13.53, 32.52, 12.38, 31.30);
            m_path.Curve3(11.23, 30.08, 9.38, 30.08);
            m_path.Curve3(7.57, 30.08, 6.42, 31.35);
            m_path.Curve3(5.27, 32.62, 5.27, 34.81);
            m_path.Curve3(5.27, 39.01, 9.57, 42.53);
            m_path.Curve3(13.87, 46.04, 21.63, 46.04);
            m_path.Curve3(27.59, 46.04, 31.40, 44.04);
            m_path.Curve3(34.28, 42.53, 35.64, 39.31);
            m_path.Curve3(36.52, 37.21, 36.52, 30.71);
            m_path.LineTo(36.52, 15.53);
            m_path.Curve3(36.52, 9.13, 36.77, 7.69);
            m_path.Curve3(37.01, 6.25, 37.57, 5.76);
            m_path.Curve3(38.13, 5.27, 38.87, 5.27);
            m_path.Curve3(39.65, 5.27, 40.23, 5.62);
            m_path.Curve3(41.26, 6.25, 44.19, 9.18);
            m_path.LineTo(44.19, 6.45);
            m_path.Curve3(38.72, -0.88, 33.74, -0.88);
            m_path.Curve3(31.35, -0.88, 29.93, 0.78);
            m_path.Curve3(28.52, 2.44, 28.47, 6.45);
            m_path.ClosePolygon();

            m_path.MoveTo(28.47, 9.62);
            m_path.LineTo(28.47, 26.66);
            m_path.Curve3(21.09, 23.73, 18.95, 22.51);
            m_path.Curve3(15.09, 20.36, 13.43, 18.02);
            m_path.Curve3(11.77, 15.67, 11.77, 12.89);
            m_path.Curve3(11.77, 9.38, 13.87, 7.06);
            m_path.Curve3(15.97, 4.74, 18.70, 4.74);
            m_path.Curve3(22.41, 4.74, 28.47, 9.62);
            m_path.ClosePolygon();

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

            shape_mtx.Scale(M.New <T>(4.0));
            shape_mtx.Translate(MatrixFactory <T> .CreateVector2D(150, 100));
            m_path.Transform(shape_mtx);

            BoundingRect <T> .BoundingRectSingle(m_shape, 0, ref m_shape_bounds);

            m_shadow_ctrl.SetXN(0, m_shape_bounds.x1);
            m_shadow_ctrl.SetYN(0, m_shape_bounds.y1);
            m_shadow_ctrl.SetXN(1, m_shape_bounds.x2);
            m_shadow_ctrl.SetYN(1, m_shape_bounds.y1);
            m_shadow_ctrl.SetXN(2, m_shape_bounds.x2);
            m_shadow_ctrl.SetYN(2, m_shape_bounds.y2);
            m_shadow_ctrl.SetXN(3, m_shape_bounds.x1);
            m_shadow_ctrl.SetYN(3, m_shape_bounds.y2);
            m_shadow_ctrl.line_color(new RGBA_Doubles(0, 0.3, 0.5, 0.3));
        }
예제 #18
0
        //--------------------------------------------------------------------
        public SpanInterpolatorPerspLerp()
        {
            m_trans_dir = MatrixFactory <T> .NewIdentity(VectorDimension.Two); // new Transform.Perspective();

            m_trans_inv = MatrixFactory <T> .NewIdentity(VectorDimension.Two); //new Transform.Perspective();
        }
예제 #19
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();
        }
예제 #20
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();
        }
예제 #21
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;
            }
        }
예제 #22
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();
        }