Exemplo n.º 1
0
		public image_resample()
		{
			m_gamma_lut = new GammaLookUpTable(2.0);
			m_quad = new MatterHackers.Agg.UI.PolygonEditWidget(4, 5.0);
			m_trans_type = new MatterHackers.Agg.UI.RadioButtonGroup(new Vector2(400, 5.0), new Vector2(30 + 170.0, 95));
			m_gamma = new MatterHackers.Agg.UI.Slider(5.0, 5.0 + 15 * 0, 400 - 5, 10.0 + 15 * 0);
			m_blur = new MatterHackers.Agg.UI.Slider(5.0, 5.0 + 15 * 1, 400 - 5, 10.0 + 15 * 1);
			m_blur.ValueChanged += new EventHandler(NeedRedraw);
			m_gamma.ValueChanged += new EventHandler(NeedRedraw);
			m_old_gamma = 2.0;

			g_rasterizer = new ScanlineRasterizer();
			g_scanline = new scanline_unpacked_8();

			m_trans_type.AddRadioButton("Affine No Resample");
			m_trans_type.AddRadioButton("Affine Resample");
			m_trans_type.AddRadioButton("Perspective No Resample LERP");
			m_trans_type.AddRadioButton("Perspective No Resample Exact");
			m_trans_type.AddRadioButton("Perspective Resample LERP");
			m_trans_type.AddRadioButton("Perspective Resample Exact");
			m_trans_type.SelectedIndex = 4;
			AddChild(m_trans_type);

			m_gamma.SetRange(0.5, 3.0);
			m_gamma.Value = 2.0;
			m_gamma.Text = "Gamma={0:F3}";
			AddChild(m_gamma);

			m_blur.SetRange(0.5, 5.0);
			m_blur.Value = 1.0;
			m_blur.Text = "Blur={0:F3}";
			AddChild(m_blur);
		}
Exemplo n.º 2
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            IImageByte backBuffer = widgetsSubImage;
            
            GammaLookUpTable gamma = new GammaLookUpTable(m_gamma.Value);
            IRecieveBlenderByte NormalBlender = new BlenderBGRA();
            IRecieveBlenderByte GammaBlender = new BlenderGammaBGRA(gamma);
            ImageBuffer rasterNormal = new ImageBuffer();
            rasterNormal.Attach(backBuffer, NormalBlender);
            ImageBuffer rasterGamma = new ImageBuffer();
            rasterGamma.Attach(backBuffer, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

            clippingProxyNormal.clear(m_white_on_black.Checked ? new RGBA_Floats(0, 0, 0) : new RGBA_Floats(1, 1, 1));

            ScanlineRasterizer ras = new ScanlineRasterizer();
            ScanlineCachePacked8 sl = new ScanlineCachePacked8();

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

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

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

            double d = m_offset.Value;

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

            // Drawing as an outline
            if (!m_DrawAsOutlineCheckBox.Checked)
            {
                Stroke p = new Stroke(r);
                p.width(1.0);
                ras.add_path(p);
            }
            else
            {
                ras.add_path(r);
            }

            scanlineRenderer.render_scanlines_aa_solid(clippingProxyGamma, ras, sl, m_white_on_black.Checked ? new RGBA_Bytes(255, 255, 255) : new RGBA_Bytes(0, 0, 0));

            base.OnDraw(graphics2D);
        }
Exemplo n.º 3
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			GammaLookUpTable gamma = new GammaLookUpTable(gammaSlider.Value);
			IRecieveBlenderByte NormalBlender = new BlenderBGR();
			IRecieveBlenderByte GammaBlender = new BlenderGammaBGR(gamma);
			ImageBuffer rasterNormal = new ImageBuffer();
			rasterNormal.Attach(graphics2D.DestImage, NormalBlender);
			ImageBuffer rasterGamma = new ImageBuffer();
			rasterGamma.Attach(graphics2D.DestImage, GammaBlender);
			ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
			ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

			clippingProxyNormal.clear(new RGBA_Floats(1, 1, 1));

			ScanlineRasterizer ras = new ScanlineRasterizer();
			scanline_unpacked_8 sl = new scanline_unpacked_8();

			int size_mul = (int)pixelSizeSlider.Value;

			renderer_enlarged ren_en = new renderer_enlarged(size_mul);

			StyledTypeFace type = new StyledTypeFace(LiberationSansFont.Instance, 12);
			IVertexSource character = type.GetGlyphForCharacter('E');
			character.rewind(0);
			ras.reset();
			ras.add_path(character);
			ren_en.RenderSolid(clippingProxyGamma, ras, sl, RGBA_Bytes.Black);

			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.RenderSolid(clippingProxyGamma, ras, sl, RGBA_Bytes.Black);

			ras.gamma(new gamma_none());

			PathStorage ps = new PathStorage();
			Stroke pg = new Stroke(ps);
			pg.width(2);

			DrawBigA(graphics2D);

			base.OnDraw(graphics2D);
		}
Exemplo n.º 4
0
		public void apply_gamma_dir(GammaLookUpTable gamma)
		{
			Red0To255 = gamma.dir((byte)Red0To255);
			Green0To255 = gamma.dir((byte)Green0To255);
			Blue0To255 = gamma.dir((byte)Blue0To255);
		}
Exemplo n.º 5
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			GammaLookUpTable gamma = new GammaLookUpTable(gammaSlider.Value);
			IRecieveBlenderByte NormalBlender = new BlenderBGRA();
			IRecieveBlenderByte GammaBlender = new BlenderGammaBGRA(gamma);
			ImageBuffer rasterGamma = new ImageBuffer();
			rasterGamma.Attach(widgetsSubImage, GammaBlender);
			ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(widgetsSubImage);
			ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

			clippingProxyNormal.clear(new RGBA_Floats(1, 1, 1));

			ScanlineRasterizer rasterizer = new ScanlineRasterizer();
			scanline_unpacked_8 sl = new scanline_unpacked_8();

			int size_mul = (int)pixelSizeSlider.Value;

			renderer_enlarged ren_en = new renderer_enlarged(size_mul);

			rasterizer.reset();
			rasterizer.move_to_d(m_x[0] / size_mul, m_y[0] / size_mul);
			rasterizer.line_to_d(m_x[1] / size_mul, m_y[1] / size_mul);
			rasterizer.line_to_d(m_x[2] / size_mul, m_y[2] / size_mul);
			ren_en.RenderSolid(clippingProxyGamma, rasterizer, sl, RGBA_Bytes.Black);

			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.RenderSolid(clippingProxyGamma, rasterizer, sl, RGBA_Bytes.Black);

			rasterizer.gamma(new gamma_none());

			PathStorage ps = new PathStorage();
			Stroke pg = new Stroke(ps);
			pg.width(2);

			ps.remove_all();
			ps.MoveTo(m_x[0], m_y[0]);
			ps.LineTo(m_x[1], m_y[1]);
			ps.LineTo(m_x[2], m_y[2]);
			ps.LineTo(m_x[0], m_y[0]);
			rasterizer.add_path(pg);
			scanlineRenderer.RenderSolid(clippingProxyNormal, rasterizer, sl, new RGBA_Bytes(0, 150, 160, 200));

			base.OnDraw(graphics2D);
		}
Exemplo n.º 6
0
 public void apply_gamma_dir(GammaLookUpTable gamma)
 {
     Red0To255   = gamma.dir((byte)Red0To255);
     Green0To255 = gamma.dir((byte)Green0To255);
     Blue0To255  = gamma.dir((byte)Blue0To255);
 }
Exemplo n.º 7
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            GammaLookUpTable    gamma               = new GammaLookUpTable(m_gamma.Value);
            IRecieveBlenderByte NormalBlender       = new BlenderBGRA();
            IRecieveBlenderByte GammaBlender        = new BlenderGammaBGRA(gamma);
            ImageBuffer         rasterNormal        = new ImageBuffer(NewGraphics2D().DestImage, NormalBlender);
            ImageBuffer         rasterGamma         = new ImageBuffer(NewGraphics2D().DestImage, GammaBlender);
            ImageClippingProxy  clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy  clippingProxyGamma  = new ImageClippingProxy(rasterGamma);

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

            ScanlineRasterizer   ras = new ScanlineRasterizer();
            ScanlineCachePacked8 sl  = new ScanlineCachePacked8();

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

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

            // Render two "control" circles
            e.init(m_x[0], m_y[0], 3, 3, 16);
            ras.add_path(e);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.RenderSolid(clippingProxyNormal, ras, sl, new Color(127, 127, 127));
            e.init(m_x[1], m_y[1], 3, 3, 16);
            ras.add_path(e);
            scanlineRenderer.RenderSolid(clippingProxyNormal, ras, sl, new Color(127, 127, 127));

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

            // Drawing as an outline
            Stroke p = new Stroke(r);

            p.width(1.0);
            ras.add_path(p);

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

            /*
             *              int i;
             *
             *              // radial line test
             *              //-------------------------
             *              dashed_line<rasterizer_type,
             *                                      renderer_scanline_type,
             *                                      scanline_type> dash(ras, ren_sl, sl);
             *
             *              double cx = width() / 2.0;
             *              double cy = height() / 2.0;
             *
             *              ren_sl.color(agg::rgba(1.0, 1.0, 1.0, 0.2));
             *              for(i = 180; i > 0; i--)
             *              {
             *                      double n = 2.0 * agg::pi * i / 180.0;
             *                      dash.draw(cx + min(cx, cy) * sin(n), cy + min(cx, cy) * cos(n),
             *                                        cx, cy,
             *                                        1.0, (i < 90) ? i : 0.0);
             *              }
             *
             *              typedef agg::gradient_x gradient_func_type;
             *              typedef agg::span_interpolator_linear<> interpolator_type;
             *              typedef agg::span_allocator<color_type> span_allocator_type;
             *              typedef agg::pod_auto_array<color_type, 256> color_array_type;
             *              typedef agg::span_gradient<color_type,
             *                                                                 interpolator_type,
             *                                                                 gradient_func_type,
             *                                                                 color_array_type> span_gradient_type;
             *
             *              typedef agg::renderer_scanline_aa<renderer_base_type,
             *                                                                                span_allocator_type,
             *                                                                                span_gradient_type> renderer_gradient_type;
             *
             *              gradient_func_type  gradient_func;                   // The gradient function
             *              agg::trans_affine   gradient_mtx;                    // Affine transformer
             *              interpolator_type   span_interpolator(gradient_mtx); // Span interpolator
             *              span_allocator_type span_allocator;                  // Span Allocator
             *              color_array_type    gradient_colors;                 // The gradient colors
             *              span_gradient_type  span_gradient(span_interpolator,
             *                                                                                gradient_func,
             *                                                                                gradient_colors,
             *                                                                                0, 100);
             *
             *              renderer_gradient_type ren_gradient(ren_base, span_allocator, span_gradient);
             *
             *              dashed_line<rasterizer_type,
             *                                      renderer_gradient_type,
             *                                      scanline_type> dash_gradient(ras, ren_gradient, sl);
             *
             *              double x1, y1, x2, y2;
             *
             *              for(i = 1; i <= 20; i++)
             *              {
             *                      ren_sl.color(agg::rgba(1,1,1));
             *
             *                      // integral point sizes 1..20
             *                      //----------------
             *                      agg::ellipse ell;
             *
             *                      ell.init(20 + i * (i + 1) + 0.5,
             *                                       20.5,
             *                                       i / 2.0,
             *                                       i / 2.0,
             *                                       8 + i);
             *                      ras.reset();
             *                      ras.add_path(ell);
             *                      agg::render_scanlines(ras, sl, ren_sl);
             *
             *                      // fractional point sizes 0..2
             *                      //----------------
             *                      ell.init(18 + i * 4 + 0.5, 33 + 0.5,
             *                                       i/20.0, i/20.0,
             *                                       8);
             *                      ras.reset();
             *                      ras.add_path(ell);
             *                      agg::render_scanlines(ras, sl, ren_sl);
             *
             *                      // fractional point positioning
             *                      //---------------
             *                      ell.init(18 + i * 4 + (i-1) / 10.0 + 0.5,
             *                                       27 + (i - 1) / 10.0 + 0.5,
             *                                       0.5, 0.5, 8);
             *                      ras.reset();
             *                      ras.add_path(ell);
             *                      agg::render_scanlines(ras, sl, ren_sl);
             *
             *                      // integral line widths 1..20
             *                      //----------------
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(1,1,1),
             *                                                       agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));
             *
             *                      x1 = 20 + i* (i + 1);
             *                      y1 = 40.5;
             *                      x2 = 20 + i * (i + 1) + (i - 1) * 4;
             *                      y2 = 100.5;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, i, 0);
             *
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(1,0,0),
             *                                                       agg::rgba(0,0,1));
             *
             *                      // fractional line lengths H (red/blue)
             *                      //----------------
             *                      x1 = 17.5 + i * 4;
             *                      y1 = 107;
             *                      x2 = 17.5 + i * 4 + i/6.66666667;
             *                      y2 = 107;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);
             *
             *                      // fractional line lengths V (red/blue)
             *                      //---------------
             *                      x1 = 18 + i * 4;
             *                      y1 = 112.5;
             *                      x2 = 18 + i * 4;
             *                      y2 = 112.5 + i / 6.66666667;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);
             *
             *                      // fractional line positioning (red)
             *                      //---------------
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(1,0,0),
             *                                                       agg::rgba(1,1,1));
             *                      x1 = 21.5;
             *                      y1 = 120 + (i - 1) * 3.1;
             *                      x2 = 52.5;
             *                      y2 = 120 + (i - 1) * 3.1;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);
             *
             *                      // fractional line width 2..0 (green)
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(0,1,0),
             *                                                       agg::rgba(1,1,1));
             *                      x1 = 52.5;
             *                      y1 = 118 + i * 3;
             *                      x2 = 83.5;
             *                      y2 = 118 + i * 3;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 0);
             *
             *                      // stippled fractional width 2..0 (blue)
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(0,0,1),
             *                                                       agg::rgba(1,1,1));
             *                      x1 = 83.5;
             *                      y1 = 119 + i * 3;
             *                      x2 = 114.5;
             *                      y2 = 119 + i * 3;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 3.0);
             *
             *                      ren_sl.color(agg::rgba(1,1,1));
             *                      if(i <= 10)
             *                      {
             *                              // integral line width, horz aligned (mipmap test)
             *                              //-------------------
             *                              dash.draw(125.5, 119.5 + (i + 2) * (i / 2.0),
             *                                                135.5, 119.5 + (i + 2) * (i / 2.0),
             *                                                i, 0.0);
             *                      }
             *
             *                      // fractional line width 0..2, 1 px H
             *                      //-----------------
             *                      dash.draw(17.5 + i * 4, 192, 18.5 + i * 4, 192, i / 10.0, 0);
             *
             *                      // fractional line positioning, 1 px H
             *                      //-----------------
             *                      dash.draw(17.5 + i * 4 + (i - 1) / 10.0, 186,
             *                                        18.5 + i * 4 + (i - 1) / 10.0, 186,
             *                                        1.0, 0);
             *              }
             *
             *              // Triangles
             *              //---------------
             *              for (int i = 1; i <= 13; i++)
             *              {
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(1,1,1),
             *                                                       agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));
             *                      calc_linear_gradient_transform(width()  - 150,
             *                                                                                 height() - 20 - i * (i + 1.5),
             *                                                                                 width()  - 20,
             *                                                                                 height() - 20 - i * (i + 1),
             *                                                                                 gradient_mtx);
             *                      ras.reset();
             *                      ras.move_to_d(width() - 150, height() - 20 - i * (i + 1.5));
             *                      ras.line_to_d(width() - 20,  height() - 20 - i * (i + 1));
             *                      ras.line_to_d(width() - 20,  height() - 20 - i * (i + 2));
             *                      agg::render_scanlines(ras, sl, ren_gradient);
             *              }
             */

            base.OnDraw(graphics2D);
        }
Exemplo n.º 8
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            IImageByte backBuffer = widgetsSubImage;

            GammaLookUpTable    gamma         = new GammaLookUpTable(m_gamma.Value);
            IRecieveBlenderByte NormalBlender = new BlenderBGRA();
            IRecieveBlenderByte GammaBlender  = new BlenderGammaBGRA(gamma);
            ImageBuffer         rasterNormal  = new ImageBuffer();

            rasterNormal.Attach(backBuffer, NormalBlender);
            ImageBuffer rasterGamma = new ImageBuffer();

            rasterGamma.Attach(backBuffer, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy clippingProxyGamma  = new ImageClippingProxy(rasterGamma);

            clippingProxyNormal.clear(m_white_on_black.Checked ? new RGBA_Floats(0, 0, 0) : new RGBA_Floats(1, 1, 1));

            ScanlineRasterizer   ras = new ScanlineRasterizer();
            ScanlineCachePacked8 sl  = new ScanlineCachePacked8();

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

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

            // Render two "control" circles
            e.init(m_x[0], m_y[0], 3, 3, 16);
            ras.add_path(e);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));
            e.init(m_x[1], m_y[1], 3, 3, 16);
            ras.add_path(e);
            scanlineRenderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));

            double d = m_offset.Value;

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

            // Drawing as an outline
            if (!m_DrawAsOutlineCheckBox.Checked)
            {
                Stroke p = new Stroke(r);
                p.width(1.0);
                ras.add_path(p);
            }
            else
            {
                ras.add_path(r);
            }

            scanlineRenderer.RenderSolid(clippingProxyGamma, ras, sl, m_white_on_black.Checked ? new RGBA_Bytes(255, 255, 255) : new RGBA_Bytes(0, 0, 0));

            base.OnDraw(graphics2D);
        }
Exemplo n.º 9
0
 public BlenderGammaBGR(GammaLookUpTable g)
 {
     m_gamma = g;
 }
Exemplo n.º 10
0
 public void gamma(GammaLookUpTable g)
 {
     m_gamma = g; 
 }
Exemplo n.º 11
0
 public BlenderGammaBGR()
 {
     m_gamma = new GammaLookUpTable();
 }
Exemplo n.º 12
0
 public void apply_gamma_inv(GammaLookUpTable g)
 {
     throw new System.NotImplementedException();
     //for_each_pixel(apply_gamma_inv_rgba<color_type, order_type, GammaLut>(g));
 }
Exemplo n.º 13
0
        public ImageBuffer(IImage image, IBlender blender, GammaLookUpTable gammaTable)
        {
            unsafe
            {
                AttachBuffer(image.GetBuffer(), image.Width(), image.Height(), image.StrideInBytes(), image.BitDepth, image.GetDistanceBetweenPixelsInclusive());
            }

            SetBlender(blender);
        }
Exemplo n.º 14
0
			public styles_gouraud(mesh_ctrl mesh, GammaLookUpTable gamma)
			{
				int i;
				for (i = 0; i < mesh.num_triangles(); i++)
				{
					mesh_triangle t = mesh.triangle(i);
					mesh_point p1 = mesh.vertex(t.p1);
					mesh_point p2 = mesh.vertex(t.p2);
					mesh_point p3 = mesh.vertex(t.p3);

					RGBA_Bytes c1 = p1.color;
					RGBA_Bytes c2 = p2.color;
					RGBA_Bytes c3 = p3.color;
					c1.apply_gamma_dir(gamma);
					c2.apply_gamma_dir(gamma);
					c3.apply_gamma_dir(gamma);
					span_gouraud_rgba gouraud = new span_gouraud_rgba(c1, c2, c3,
										 p1.x, p1.y,
										 p2.x, p2.y,
										 p3.x, p3.y);
					gouraud.prepare();
					m_triangles.Add(gouraud);
				}
			}
Exemplo n.º 15
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            GammaLookUpTable gamma = new GammaLookUpTable(m_gamma.Value);
            IRecieveBlenderByte NormalBlender = new BlenderBGRA();
            IRecieveBlenderByte GammaBlender = new BlenderGammaBGRA(gamma);
            ImageBuffer rasterNormal = new ImageBuffer(NewGraphics2D().DestImage, NormalBlender);
            ImageBuffer rasterGamma = new ImageBuffer(NewGraphics2D().DestImage, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

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

            ScanlineRasterizer ras = new ScanlineRasterizer();
            ScanlineCachePacked8 sl = new ScanlineCachePacked8();

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

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

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

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

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

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








            /*            
                    int i;

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

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

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


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

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

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

                    renderer_gradient_type ren_gradient(ren_base, span_allocator, span_gradient);

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

                    double x1, y1, x2, y2;

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

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

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


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


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

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


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

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


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

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


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

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


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

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

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


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










            base.OnDraw(graphics2D);
        }