Example #1
0
        unsafe void generate_alpha_mask(int cx, int cy)
        {
            alphaByteArray = new byte[cx * cy];
            {
#if USE_CLIPPING_ALPHA_MASK
                alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 20 * cx + 20, cx - 40, cy - 40, cx, 8, 1);
#else
                alphaMaskImageBuffer.attach(alphaByteArray, (int)cx, (int)cy, cx, 1);
#endif

                ImageBuffer image = new ImageBuffer();
                image.Attach(alphaMaskImageBuffer, new blender_gray(1), 1, 0, 8);
                ImageClippingProxy clippingProxy = new ImageClippingProxy(image);
                ScanlineCachePacked8 sl = new ScanlineCachePacked8();

                clippingProxy.clear(new RGBA_Floats(0));

                VertexSource.Ellipse ellipseForMask = new MatterHackers.Agg.VertexSource.Ellipse();

                System.Random randGenerator = new Random(1432);

                ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
                int i;
                int num = (int)numMasksSlider.Value;
                for (i = 0; i < num; i++)
                {
                    if (i == num - 1)
                    {
                        ellipseForMask.init(Width / 2, Height / 2, 110, 110, 100);
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.render_scanlines_aa_solid(clippingProxy, rasterizer, sl, new RGBA_Bytes(0, 0, 0, 255));

                        ellipseForMask.init(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100);
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.render_scanlines_aa_solid(clippingProxy, rasterizer, sl, new RGBA_Bytes(255, 0, 0, 255));
                    }
                    else
                    {
                        ellipseForMask.init(randGenerator.Next() % cx,
                                 randGenerator.Next() % cy,
                                 randGenerator.Next() % 100 + 20,
                                 randGenerator.Next() % 100 + 20,
                                 100);
                        // set the color to draw into the alpha channel.
                        // there is not very much reason to set the alpha as you will get the amount of 
                        // transparency based on the color you draw.  (you might want some type of different edeg effect but it will be minor).
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.render_scanlines_aa_solid(clippingProxy, rasterizer, sl, new RGBA_Bytes((int)((float)i / (float)num * 255), 0, 0, 255));
                    }

                }
                
                alphaMaskImageBuffer.DettachBuffer();
            }
        }
Example #2
0
        private unsafe void generate_alpha_mask(int cx, int cy)
        {
            alphaByteArray = new byte[cx * cy];
            {
#if USE_CLIPPING_ALPHA_MASK
                alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 20 * cx + 20, cx - 40, cy - 40, cx, 8, 1);
#else
                alphaMaskImageBuffer.attach(alphaByteArray, (int)cx, (int)cy, cx, 1);
#endif

                ImageBuffer image = new ImageBuffer();
                image.Attach(alphaMaskImageBuffer, new blender_gray(1), 1, 0, 8);
                ImageClippingProxy   clippingProxy = new ImageClippingProxy(image);
                ScanlineCachePacked8 sl            = new ScanlineCachePacked8();

                clippingProxy.clear(new ColorF(0));

                VertexSource.Ellipse ellipseForMask = new MatterHackers.Agg.VertexSource.Ellipse();

                System.Random randGenerator = new Random(1432);

                ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
                int i;
                int num = (int)numMasksSlider.Value;
                for (i = 0; i < num; i++)
                {
                    if (i == num - 1)
                    {
                        ellipseForMask.init(Width / 2, Height / 2, 110, 110, 100);
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.RenderSolid(clippingProxy, rasterizer, sl, new Color(0, 0, 0, 255));

                        ellipseForMask.init(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100);
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.RenderSolid(clippingProxy, rasterizer, sl, new Color(255, 0, 0, 255));
                    }
                    else
                    {
                        ellipseForMask.init(randGenerator.Next() % cx,
                                            randGenerator.Next() % cy,
                                            randGenerator.Next() % 100 + 20,
                                            randGenerator.Next() % 100 + 20,
                                            100);
                        // set the color to draw into the alpha channel.
                        // there is not very much reason to set the alpha as you will get the amount of
                        // transparency based on the color you draw.  (you might want some type of different edeg effect but it will be minor).
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.RenderSolid(clippingProxy, rasterizer, sl, new Color((int)((float)i / (float)num * 255), 0, 0, 255));
                    }
                }

                alphaMaskImageBuffer.DettachBuffer();
            }
        }
Example #3
0
        public FloodFillDemo()
        {
            BackgroundColor = RGBA_Bytes.White;
            imageToFillOn = new ImageBuffer(400, 300, 32, new BlenderBGRA());
            Graphics2D imageToFillGraphics = imageToFillOn.NewGraphics2D();
            imageToFillGraphics.Clear(RGBA_Bytes.White);
            imageToFillGraphics.DrawString("Click to fill", 20, 30);
            imageToFillGraphics.Circle(new Vector2(200, 150), 35, RGBA_Bytes.Black);
            imageToFillGraphics.Circle(new Vector2(200, 150), 30, RGBA_Bytes.Green);
            imageToFillGraphics.Rectangle(20, 50, 210, 280, RGBA_Bytes.Black);
            imageToFillGraphics.Rectangle(imageToFillOn.GetBounds(), RGBA_Bytes.Blue);

            Random rand = new Random();
            for (int i = 0; i < 20; i++)
            {
                Ellipse elipse = new Ellipse(rand.Next(imageToFillOn.Width), rand.Next(imageToFillOn.Height), rand.Next(10, 60), rand.Next(10, 60));
                Stroke outline = new Stroke(elipse);
                imageToFillGraphics.Render(outline, RGBA_Bytes.Black);
            }
            

            m_slider1 = new Slider(new Vector2(80, 10), 510);
            m_slider2 = new Slider(new Vector2(80, 10 + 20), 510);

            m_slider1.ValueChanged += new EventHandler(NeedsRedraw);
            m_slider2.ValueChanged += new EventHandler(NeedsRedraw);

            AddChild(m_slider1);
            AddChild(m_slider2);

            m_slider1.Text = "Pixel size={0:F3}";
            m_slider1.SetRange(8, 100);
            m_slider1.NumTicks = 23;
            m_slider1.Value = 32;

            m_slider2.Text = "gamma={0:F3}";
            m_slider2.SetRange(0.0, 3.0);
            m_slider2.Value = 1.0;
        }
Example #4
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

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

            ImageClippingProxy clippingProxy = new ImageClippingProxy(widgetsSubImage);

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

            m_profile.text_size(8.0);

            // draw a background to show how the alpha is working
            int RectWidth = 32;
            int xoffset   = 238;
            int yoffset   = 171;
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * RectWidth + xoffset, j * RectWidth + yoffset,
                                                                                     (i + 1) * RectWidth + xoffset, (j + 1) * RectWidth + yoffset, 2);
                        rect.normalize_radius();

                        ras.add_path(rect);
                        scanlineRenderer.render_scanlines_aa_solid(clippingProxy, ras, sl, new RGBA_Bytes(.9, .9, .9));
                    }
                }
            }

            double ini_scale = 1.0;

            Transform.Affine mtx1 = Affine.NewIdentity();
            mtx1 *= Affine.NewScaling(ini_scale, ini_scale);
            mtx1 *= Affine.NewTranslation(center_x, center_y);

            VertexSource.Ellipse e1 = new MatterHackers.Agg.VertexSource.Ellipse();
            e1.init(0.0, 0.0, 110.0, 110.0, 64);

            Transform.Affine mtx_g1 = Affine.NewIdentity();
            mtx_g1 *= Affine.NewScaling(ini_scale, ini_scale);
            mtx_g1 *= Affine.NewScaling(m_SaveData.m_scale, m_SaveData.m_scale);
            mtx_g1 *= Affine.NewScaling(m_scale_x, m_scale_y);
            mtx_g1 *= Affine.NewRotation(m_SaveData.m_angle);
            mtx_g1 *= Affine.NewTranslation(m_SaveData.m_center_x, m_SaveData.m_center_y);
            mtx_g1.invert();


            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],
                                                  m_spline_g.spline()[i],
                                                  m_spline_b.spline()[i],
                                                  m_spline_a.spline()[i]);
            }

            VertexSourceApplyTransform t1 = new VertexSourceApplyTransform(e1, mtx1);

            IGradient innerGradient = null;

            switch (m_GradTypeRBox.SelectedIndex)
            {
            case 0:
                innerGradient = new gradient_radial();
                break;

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

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

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

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

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

            IGradient outerGradient = null;

            switch (m_GradWrapRBox.SelectedIndex)
            {
            case 0:
                outerGradient = new gradient_reflect_adaptor(innerGradient);
                break;

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

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

            span_allocator           span_alloc = new span_allocator();
            color_function_profile   colors     = new color_function_profile(color_profile, m_profile.gamma());
            span_interpolator_linear inter      = new span_interpolator_linear(mtx_g1);
            span_gradient            span_gen   = new span_gradient(inter, outerGradient, colors, 0, 150);

            ras.add_path(t1);
            scanlineRenderer.GenerateAndRender(ras, sl, clippingProxy, span_alloc, span_gen);
            base.OnDraw(graphics2D);
        }
Example #5
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);
        }
Example #6
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

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

			ImageClippingProxy clippingProxy = new ImageClippingProxy(widgetsSubImage);
			clippingProxy.clear(new RGBA_Floats(0, 0, 0));

			m_profile.text_size(8.0);

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

						ras.add_path(rect);
						scanlineRenderer.RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(.9, .9, .9));
					}
				}
			}

			double ini_scale = 1.0;

			Transform.Affine mtx1 = Affine.NewIdentity();
			mtx1 *= Affine.NewScaling(ini_scale, ini_scale);
			mtx1 *= Affine.NewTranslation(center_x, center_y);

			VertexSource.Ellipse e1 = new MatterHackers.Agg.VertexSource.Ellipse();
			e1.init(0.0, 0.0, 110.0, 110.0, 64);

			Transform.Affine mtx_g1 = Affine.NewIdentity();
			mtx_g1 *= Affine.NewScaling(ini_scale, ini_scale);
			mtx_g1 *= Affine.NewScaling(m_SaveData.m_scale, m_SaveData.m_scale);
			mtx_g1 *= Affine.NewScaling(m_scale_x, m_scale_y);
			mtx_g1 *= Affine.NewRotation(m_SaveData.m_angle);
			mtx_g1 *= Affine.NewTranslation(m_SaveData.m_center_x, m_SaveData.m_center_y);
			mtx_g1.invert();

			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],
														m_spline_g.spline()[i],
														m_spline_b.spline()[i],
														m_spline_a.spline()[i]);
			}

			VertexSourceApplyTransform t1 = new VertexSourceApplyTransform(e1, mtx1);

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

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

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

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

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

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

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

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

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

			span_allocator span_alloc = new span_allocator();
			color_function_profile colors = new color_function_profile(color_profile, m_profile.gamma());
			span_interpolator_linear inter = new span_interpolator_linear(mtx_g1);
			span_gradient span_gen = new span_gradient(inter, outerGradient, colors, 0, 150);

			ras.add_path(t1);
			scanlineRenderer.GenerateAndRender(ras, sl, clippingProxy, span_alloc, span_gen);
			base.OnDraw(graphics2D);
		}
Example #7
0
		public void Circle(double x, double y, double radius, RGBA_Bytes color)
		{
			Ellipse elipse = new Ellipse(x, y, radius, radius);
			Render(elipse, color);
		}
Example #8
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			if (orignialSize.x == 0)
			{
				orignialSize.x = WindowSize.x;
				orignialSize.y = WindowSize.y;
			}

			ImageBuffer destImageWithPreMultBlender = new ImageBuffer();
			switch (widgetsSubImage.BitDepth)
			{
				case 24:
					destImageWithPreMultBlender.Attach(widgetsSubImage, new BlenderPreMultBGR());
					break;

				case 32:
					destImageWithPreMultBlender.Attach(widgetsSubImage, new BlenderPreMultBGRA());
					break;

				default:
					throw new Exception("Unknown bit depth");
			}

			ImageClippingProxy clippingProxy_pre = new ImageClippingProxy(destImageWithPreMultBlender);

			clippingProxy_pre.clear(new RGBA_Floats(1.0, 1.0, 1.0));

			Affine src_mtx = Affine.NewIdentity();
			src_mtx *= Affine.NewTranslation(-orignialSize.x / 2 - 10, -orignialSize.y / 2 - 20 - 10);
			src_mtx *= Affine.NewRotation(drawAngle.Value * Math.PI / 180.0);
			src_mtx *= Affine.NewScaling(drawScale.Value);
			src_mtx *= Affine.NewTranslation(orignialSize.x / 2, orignialSize.y / 2 + 20);

			Affine img_mtx = Affine.NewIdentity();
			img_mtx *= Affine.NewTranslation(-orignialSize.x / 2 + 10, -orignialSize.y / 2 + 20 + 10);
			img_mtx *= Affine.NewRotation(drawAngle.Value * Math.PI / 180.0);
			img_mtx *= Affine.NewScaling(drawScale.Value);
			img_mtx *= Affine.NewTranslation(orignialSize.x / 2, orignialSize.y / 2 + 20);
			img_mtx.invert();

			MatterHackers.Agg.span_allocator sa = new span_allocator();

			span_interpolator_linear interpolator = new span_interpolator_linear(img_mtx);

			span_image_filter sg;
			switch (sourceImage.BitDepth)
			{
				case 24:
					{
						ImageBufferAccessorClip source = new ImageBufferAccessorClip(sourceImage, RGBA_Floats.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes());
						sg = new span_image_filter_rgb_bilinear_clip(source, RGBA_Floats.rgba_pre(0, 0.4, 0, 0.5), interpolator);
					}
					break;

				case 32:
					{
						ImageBufferAccessorClip source = new ImageBufferAccessorClip(sourceImage, RGBA_Floats.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes());
						sg = new span_image_filter_rgba_bilinear_clip(source, RGBA_Floats.rgba_pre(0, 0.4, 0, 0.5), interpolator);
					}
					break;

				default:
					throw new Exception("Bad sourc depth");
			}

			ScanlineRasterizer ras = new ScanlineRasterizer();
			ras.SetVectorClipBox(0, 0, Width, Height);
			ScanlineCachePacked8 sl = new ScanlineCachePacked8();
			//scanline_unpacked_8 sl = new scanline_unpacked_8();

			double r = orignialSize.x;
			if (orignialSize.y - 60 < r)
			{
				r = orignialSize.y - 60;
			}

			VertexSource.Ellipse ell = new VertexSource.Ellipse(orignialSize.x / 2.0 + 10,
				orignialSize.y / 2.0 + 20 + 10,
				r / 2.0 + 16.0,
				r / 2.0 + 16.0, 200);

			VertexSourceApplyTransform tr = new VertexSourceApplyTransform(ell, src_mtx);

			ras.add_path(tr);
			//clippingProxy_pre.SetClippingBox(30, 0, (int)width(), (int)height());
			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg);

			base.OnDraw(graphics2D);
		}
Example #9
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 ColorF(0, 0, 0) : new ColorF(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 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));

            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 Color(255, 255, 255) : new Color(0, 0, 0));

            base.OnDraw(graphics2D);
        }
		private bool SetImageFast()
		{
			if (this.ItemWrapper == null)
			{
				this.thumbnailImage = new ImageBuffer(this.noThumbnailImage);
				this.Invalidate();
				return true;
			}

			if (this.ItemWrapper.FileLocation == QueueData.SdCardFileName)
			{
				switch (this.Size)
				{
					case ImageSizes.Size115x115:
						{
							this.thumbnailImage = StaticData.Instance.LoadIcon(Path.ChangeExtension("icon_sd_card_115x115", partExtension)).InvertLightness();
						}
						break;

					case ImageSizes.Size50x50:
						{
							this.thumbnailImage = StaticData.Instance.LoadIcon(Path.ChangeExtension("icon_sd_card_50x50", partExtension)).InvertLightness();
						}
						break;

					default:
						throw new NotImplementedException();
				}
				this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
				Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
				Ellipse outline = new Ellipse(new Vector2(Width / 2.0, Height / 2.0), Width / 2 - Width / 12);
				graphics.Render(new Stroke(outline, Width / 12), RGBA_Bytes.White);

				UiThread.RunOnIdle(this.EnsureImageUpdated);
				return true;
			}
			else if (Path.GetExtension(this.ItemWrapper.FileLocation).ToUpper() == ".GCODE")
			{
				CreateImage(this, Width, Height);
				this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
				Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
				Vector2 center = new Vector2(Width / 2.0, Height / 2.0);
				Ellipse outline = new Ellipse(center, Width / 2 - Width / 12);
				graphics.Render(new Stroke(outline, Width / 12), RGBA_Bytes.White);
				graphics.DrawString("GCode", center.x, center.y, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);

				UiThread.RunOnIdle(this.EnsureImageUpdated);
				return true;
			}
			else if (!File.Exists(this.ItemWrapper.FileLocation))
			{
				CreateImage(this, Width, Height);
				this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
				Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
				Vector2 center = new Vector2(Width / 2.0, Height / 2.0);
				graphics.DrawString("Missing", center.x, center.y, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);

				UiThread.RunOnIdle(this.EnsureImageUpdated);
				return true;
			}
			else if (MeshIsTooBigToLoad(this.ItemWrapper.FileLocation))
			{
				CreateImage(this, Width, Height);
				this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
				Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
				Vector2 center = new Vector2(Width / 2.0, Height / 2.0);
				double yOffset = 8 * Width / 50 * GuiWidget.DeviceScale * 2;
				graphics.DrawString("Reduce\nPolygons\nto\nRender", center.x, center.y + yOffset, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);

				UiThread.RunOnIdle(this.EnsureImageUpdated);
				return true;
			}

			string stlHashCode = this.ItemWrapper.FileHashCode.ToString();

			if (stlHashCode != "0")
			{
				ImageBuffer bigRender = LoadImageFromDisk(this, stlHashCode);
				if (bigRender == null)
				{
					this.thumbnailImage = new ImageBuffer(buildingThumbnailImage);
					return false;
				}

				bigRender.SetRecieveBlender(new BlenderPreMultBGRA());

				this.thumbnailImage = ImageBuffer.CreateScaledImage(bigRender, (int)Width, (int)Height);

				UiThread.RunOnIdle(this.EnsureImageUpdated);

				return true;
			}

			return false;
		}
		public void DrawTrackballRadius(Graphics2D graphics2D)
		{
			var center = TrackBallController.ScreenCenter;
			var radius = TrackBallController.TrackBallRadius;
			var elipse = new Ellipse(center, radius, radius);
			var outline = new Stroke(elipse, 3);
			graphics2D.Render(outline, RotationHelperCircleColor);

			if (insideArrows.Count == 0)
			{
				MakeArrowIcons();
			}

			if (TrackBallController.LastMoveInsideRadius)
			{
				foreach (IVertexSource arrow in insideArrows)
				{
					graphics2D.Render(arrow, RotationHelperCircleColor);
				}
			}
			else
			{
				foreach (IVertexSource arrow in outsideArrows)
				{
					graphics2D.Render(arrow, RotationHelperCircleColor);
				}
			}
		}
Example #12
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			IImageByte backBuffer = widgetsSubImage;

			if (!didInit)
			{
				didInit = true;
				OnInitialize();
			}
			ImageBuffer image;
			if (backBuffer.BitDepth == 32)
			{
				image = new ImageBuffer();
				image.Attach(backBuffer, new BlenderBGRA());
			}
			else
			{
				if (backBuffer.BitDepth != 24)
				{
					throw new System.NotSupportedException();
				}
				image = new ImageBuffer();
				image.Attach(backBuffer, new BlenderBGR());
			}
			ImageClippingProxy clippingProxy = new ImageClippingProxy(image);
			clippingProxy.clear(new RGBA_Floats(1, 1, 1));

			g_rasterizer.SetVectorClipBox(0, 0, Width, Height);

			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			if (transformationTypeRadioButton.SelectedIndex == 0)
			{
				Bilinear tr = new Bilinear(lionShape.Bounds.Left, lionShape.Bounds.Bottom, lionShape.Bounds.Right, lionShape.Bounds.Top, quadPolygonControl.polygon());
				if (tr.is_valid())
				{
					//--------------------------
					// Render transformed lion
					//
					VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, tr);

					scanlineRenderer.RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths);
					//--------------------------

					//--------------------------
					// Render transformed ellipse
					//
					VertexSource.Ellipse ell = new MatterHackers.Agg.VertexSource.Ellipse((lionShape.Bounds.Left + lionShape.Bounds.Right) * 0.5, (lionShape.Bounds.Bottom + lionShape.Bounds.Top) * 0.5,
									 (lionShape.Bounds.Right - lionShape.Bounds.Left) * 0.5, (lionShape.Bounds.Top - lionShape.Bounds.Bottom) * 0.5,
									 200);
					Stroke ell_stroke = new Stroke(ell);
					ell_stroke.width(3.0);
					VertexSourceApplyTransform trans_ell = new VertexSourceApplyTransform(ell, tr);

					VertexSourceApplyTransform trans_ell_stroke = new VertexSourceApplyTransform(ell_stroke, tr);

					g_rasterizer.add_path(trans_ell);
					scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3));

					g_rasterizer.add_path(trans_ell_stroke);
					scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0));
				}
			}
			else
			{
				Perspective tr = new Perspective(lionShape.Bounds.Left, lionShape.Bounds.Bottom, lionShape.Bounds.Right, lionShape.Bounds.Top, quadPolygonControl.polygon());
				if (tr.is_valid())
				{
					// Render transformed lion
					VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, tr);

					scanlineRenderer.RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths);

					// Render transformed ellipse
					VertexSource.Ellipse FilledEllipse = new MatterHackers.Agg.VertexSource.Ellipse((lionShape.Bounds.Left + lionShape.Bounds.Right) * 0.5, (lionShape.Bounds.Bottom + lionShape.Bounds.Top) * 0.5,
									 (lionShape.Bounds.Right - lionShape.Bounds.Left) * 0.5, (lionShape.Bounds.Top - lionShape.Bounds.Bottom) * 0.5,
									 200);

					Stroke EllipseOutline = new Stroke(FilledEllipse);
					EllipseOutline.width(3.0);
					VertexSourceApplyTransform TransformedFilledEllipse = new VertexSourceApplyTransform(FilledEllipse, tr);

					VertexSourceApplyTransform TransformedEllipesOutline = new VertexSourceApplyTransform(EllipseOutline, tr);

					g_rasterizer.add_path(TransformedFilledEllipse);
					scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3));

					g_rasterizer.add_path(TransformedEllipesOutline);
					scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0));
				}
			}

			//--------------------------
			// Render the "quad" tool and controls
			g_rasterizer.add_path(quadPolygonControl);
			scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0.3, 0.5, 0.6));
			//m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy);
			base.OnDraw(graphics2D);
		}
Example #13
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (graphics2D.DestImage != null)
            {
                ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

                IImageByte backBuffer = widgetsSubImage;

                int         distBetween    = backBuffer.GetBytesBetweenPixelsInclusive();
                ImageBuffer redImageBuffer = new ImageBuffer();
                redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8);
                ImageBuffer greenImageBuffer = new ImageBuffer();
                greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8);
                ImageBuffer blueImageBuffer = new ImageBuffer();
                blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8);

                ImageClippingProxy clippingProxy      = new ImageClippingProxy(backBuffer);
                ImageClippingProxy clippingProxyRed   = new ImageClippingProxy(redImageBuffer);
                ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer);
                ImageClippingProxy clippingProxyBlue  = new ImageClippingProxy(blueImageBuffer);

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

                RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255);
                clippingProxy.clear(clearColor);
                alphaSlider.View.BackgroundColor = clearColor;

                RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value));

                VertexSource.Ellipse er = new MatterHackers.Agg.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                ras.add_path(er);
                ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
                scanlineRenderer.render_scanlines_aa_solid(clippingProxyRed, ras, sl, FillColor);

                VertexSource.Ellipse eg = new MatterHackers.Agg.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                ras.add_path(eg);
                scanlineRenderer.render_scanlines_aa_solid(clippingProxyGreen, ras, sl, FillColor);

                VertexSource.Ellipse eb = new MatterHackers.Agg.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
                ras.add_path(eb);
                scanlineRenderer.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor);
            }
            else if (graphics2D.DestImageFloat != null)
            {
#if false
                IImageFloat backBuffer = graphics2D.DestImageFloat;

                int distBetween = backBuffer.GetFloatsBetweenPixelsInclusive();
                ImageBufferFloat redImageBuffer = new ImageBufferFloat();
                redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8);
                ImageBufferFloat greenImageBuffer = new ImageBufferFloat();
                greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8);
                ImageBufferFloat blueImageBuffer = new ImageBufferFloat();
                blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8);

                ImageClippingProxy clippingProxy      = new ImageClippingProxy(backBuffer);
                ImageClippingProxy clippingProxyRed   = new ImageClippingProxy(redImageBuffer);
                ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer);
                ImageClippingProxy clippingProxyBlue  = new ImageClippingProxy(blueImageBuffer);

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

                RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255);
                clippingProxy.clear(clearColor);
                alphaSlider.View.BackGroundColor = clearColor;

                RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value));

                VertexSource.Ellipse er = new AGG.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                ras.add_path(er);
                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyRed, ras, sl, FillColor);

                VertexSource.Ellipse eg = new AGG.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                ras.add_path(eg);
                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyGreen, ras, sl, FillColor);

                VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
                ras.add_path(eb);
                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor);
#endif
            }

            base.OnDraw(graphics2D);
        }
        void createThumbnailWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            PartThumbnailWidget thumbnailWidget = e.Argument as PartThumbnailWidget;
            if (thumbnailWidget != null)
            {
                if (thumbnailWidget.printItem == null)
                {
                    thumbnailWidget.thumbnailImage = new ImageBuffer(thumbnailWidget.noThumbnailImage);
                    thumbnailWidget.Invalidate();
                    return;
                }

                if (thumbnailWidget.PrintItem.FileLocation == QueueData.SdCardFileName)
                {
                    switch (thumbnailWidget.Size)
                    {
                        case ImageSizes.Size115x115:
                            {
                                ImageIO.LoadImageData(this.GetImageLocation("icon_sd_card_115x115.png"), thumbnailWidget.thumbnailImage);
                            }
                            break;

                        case ImageSizes.Size50x50:
                            {
                                ImageIO.LoadImageData(this.GetImageLocation("icon_sd_card_50x50.png"), thumbnailWidget.thumbnailImage);
                            }
                            break;

                        default:
                            throw new NotImplementedException();
                    }
                    thumbnailWidget.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                    Graphics2D graphics = thumbnailWidget.thumbnailImage.NewGraphics2D();
                    Ellipse outline = new Ellipse(new Vector2(Width / 2.0, Height / 2.0), Width/2 + Width/12);
                    graphics.Render(new Stroke(outline, 4), RGBA_Bytes.White);

                    UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated);
                    return;
                }
                
                string stlHashCode = thumbnailWidget.PrintItem.StlFileHashCode.ToString();

                Point2D bigRenderSize = new Point2D(460, 460);
                ImageBuffer bigRender = LoadImageFromDisk(thumbnailWidget, stlHashCode, bigRenderSize);
                if (bigRender == null)
                {
                    Mesh loadedMesh = StlProcessing.Load(thumbnailWidget.PrintItem.FileLocation);

                    thumbnailWidget.thumbnailImage = new ImageBuffer(thumbnailWidget.buildingThumbnailImage);
                    thumbnailWidget.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                    bigRender = BuildImageFromSTL(loadedMesh, stlHashCode, bigRenderSize);
                    if (bigRender == null)
                    {
                        bigRender = new ImageBuffer(thumbnailWidget.noThumbnailImage);
                    }
                }

                switch (thumbnailWidget.Size)
                {
                    case ImageSizes.Size50x50:
                        {
                            ImageBuffer halfWay1 = new ImageBuffer(200, 200, 32, new BlenderBGRA());
                            halfWay1.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                            halfWay1.NewGraphics2D().Render(bigRender, 0, 0, 0, (double)halfWay1.Width / bigRender.Width, (double)halfWay1.Height / bigRender.Height);

                            ImageBuffer halfWay2 = new ImageBuffer(100, 100, 32, new BlenderBGRA());
                            halfWay2.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                            halfWay2.NewGraphics2D().Render(halfWay1, 0, 0, 0, (double)halfWay2.Width / halfWay1.Width, (double)halfWay2.Height / halfWay1.Height);

                            thumbnailWidget.thumbnailImage = new ImageBuffer((int)Width, (int)Height, 32, new BlenderBGRA());
                            thumbnailWidget.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                            thumbnailWidget.thumbnailImage.NewGraphics2D().Render(halfWay2, 0, 0, 0, (double)thumbnailWidget.thumbnailImage.Width / halfWay2.Width, (double)thumbnailWidget.thumbnailImage.Height / halfWay2.Height);
                        }
                        break;

                    case ImageSizes.Size115x115:
                        {
                            ImageBuffer halfWay1 = new ImageBuffer(230, 230, 32, new BlenderBGRA());
                            halfWay1.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                            halfWay1.NewGraphics2D().Render(bigRender, 0, 0, 0, (double)halfWay1.Width / bigRender.Width, (double)halfWay1.Height / bigRender.Height);

                            thumbnailWidget.thumbnailImage = new ImageBuffer((int)Width, (int)Height, 32, new BlenderBGRA());
                            thumbnailWidget.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                            thumbnailWidget.thumbnailImage.NewGraphics2D().Render(halfWay1, 0, 0, 0, (double)thumbnailWidget.thumbnailImage.Width / halfWay1.Width, (double)thumbnailWidget.thumbnailImage.Height / halfWay1.Height);
                        }
                        break;

                    default:
                        throw new NotImplementedException();
                }

                UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated);
            }
        }
		private bool SetImageFast()
		{
			if (this.ItemWrapper == null)
			{
				this.thumbnailImage = new ImageBuffer(this.noThumbnailImage);
				this.Invalidate();
				return true;
			}

			if (this.ItemWrapper.FileLocation == QueueData.SdCardFileName)
			{
				switch (this.Size)
				{
					case ImageSizes.Size115x115:
						{
							StaticData.Instance.LoadIcon(Path.ChangeExtension("icon_sd_card_115x115", partExtension), this.thumbnailImage);
						}
						break;

					case ImageSizes.Size50x50:
						{
							StaticData.Instance.LoadIcon(Path.ChangeExtension("icon_sd_card_50x50", partExtension), this.thumbnailImage);
						}
						break;

					default:
						throw new NotImplementedException();
				}
				this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
				Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
				Ellipse outline = new Ellipse(new Vector2(Width / 2.0, Height / 2.0), Width / 2 - Width / 12);
				graphics.Render(new Stroke(outline, Width / 12), RGBA_Bytes.White);

				UiThread.RunOnIdle(this.EnsureImageUpdated);
				return true;
			}
			else if (Path.GetExtension(this.ItemWrapper.FileLocation).ToUpper() == ".GCODE")
			{
				CreateImage(this, Width, Height);
				this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
				Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
				Vector2 center = new Vector2(Width / 2.0, Height / 2.0);
				Ellipse outline = new Ellipse(center, Width / 2 - Width / 12);
				graphics.Render(new Stroke(outline, Width / 12), RGBA_Bytes.White);
				graphics.DrawString("GCode", center.x, center.y, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);

				UiThread.RunOnIdle(this.EnsureImageUpdated);
				return true;
			}
			else if (!File.Exists(this.ItemWrapper.FileLocation))
			{
				CreateImage(this, Width, Height);
				this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
				Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
				Vector2 center = new Vector2(Width / 2.0, Height / 2.0);
				graphics.DrawString("Missing", center.x, center.y, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);

				UiThread.RunOnIdle(this.EnsureImageUpdated);
				return true;
			}
			else if (MeshIsTooBigToLoad(this.ItemWrapper.FileLocation))
			{
				CreateImage(this, Width, Height);
				this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
				Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
				Vector2 center = new Vector2(Width / 2.0, Height / 2.0);
				double yOffset = 8 * Width / 50 * TextWidget.GlobalPointSizeScaleRatio * 1.5;
				graphics.DrawString("Too Big\nto\nRender", center.x, center.y + yOffset, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);

				UiThread.RunOnIdle(this.EnsureImageUpdated);
				return true;
			}

			string stlHashCode = this.ItemWrapper.FileHashCode.ToString();

			if (stlHashCode != "0")
			{
				ImageBuffer bigRender = LoadImageFromDisk(this, stlHashCode);
				if (bigRender == null)
				{
					this.thumbnailImage = new ImageBuffer(buildingThumbnailImage);
					return false;
				}

				ImageBuffer unScaledImage = new ImageBuffer(bigRender.Width, bigRender.Height, 32, new BlenderBGRA());
				unScaledImage.NewGraphics2D().Render(bigRender, 0, 0);
				// If the source image (the one we downloaded) is more than twice as big as our dest image.
				while (unScaledImage.Width > Width * 2)
				{
					// The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results.
					// So we scale as many times as we need to to get the Image to be the right size.
					// If this were going to be a non-uniform scale we could do the x and y separatly to get better results.
					ImageBuffer halfImage = new ImageBuffer(unScaledImage.Width / 2, unScaledImage.Height / 2, 32, new BlenderBGRA());
					halfImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, halfImage.Width / (double)unScaledImage.Width, halfImage.Height / (double)unScaledImage.Height);
					unScaledImage = halfImage;
				}

				this.thumbnailImage = new ImageBuffer((int)Width, (int)Height, 32, new BlenderBGRA());
				this.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
				this.thumbnailImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, (double)this.thumbnailImage.Width / unScaledImage.Width, (double)this.thumbnailImage.Height / unScaledImage.Height);

				UiThread.RunOnIdle(this.EnsureImageUpdated);

				return true;
			}

			return false;
		}
Example #16
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);
        }
Example #17
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);
        }
Example #18
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            IImageByte backBuffer = widgetsSubImage;

            if (!didInit)
            {
                didInit = true;
                OnInitialize();
            }
            ImageBuffer image;

            if (backBuffer.BitDepth == 32)
            {
                image = new ImageBuffer();
                image.Attach(backBuffer, new BlenderBGRA());
            }
            else
            {
                if (backBuffer.BitDepth != 24)
                {
                    throw new System.NotSupportedException();
                }
                image = new ImageBuffer();
                image.Attach(backBuffer, new BlenderBGR());
            }
            ImageClippingProxy clippingProxy = new ImageClippingProxy(image);

            clippingProxy.clear(new ColorF(1, 1, 1));

            g_rasterizer.SetVectorClipBox(0, 0, Width, Height);

            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            if (transformationTypeRadioButton.SelectedIndex == 0)
            {
                Bilinear tr = new Bilinear(lionShape.Bounds.Left, lionShape.Bounds.Bottom, lionShape.Bounds.Right, lionShape.Bounds.Top, quadPolygonControl.polygon());
                if (tr.is_valid())
                {
                    //--------------------------
                    // Render transformed lion
                    //
                    foreach (var shape in lionShape.Shapes)
                    {
                        g_rasterizer.add_path(new VertexSourceApplyTransform(shape.VertexStorage, tr));
                        scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, shape.Color);
                    }
                    //--------------------------

                    //--------------------------
                    // Render transformed ellipse
                    //
                    VertexSource.Ellipse ell = new MatterHackers.Agg.VertexSource.Ellipse((lionShape.Bounds.Left + lionShape.Bounds.Right) * 0.5, (lionShape.Bounds.Bottom + lionShape.Bounds.Top) * 0.5,
                                                                                          (lionShape.Bounds.Right - lionShape.Bounds.Left) * 0.5, (lionShape.Bounds.Top - lionShape.Bounds.Bottom) * 0.5,
                                                                                          200);
                    Stroke ell_stroke = new Stroke(ell);
                    ell_stroke.width(3.0);
                    VertexSourceApplyTransform trans_ell = new VertexSourceApplyTransform(ell, tr);

                    VertexSourceApplyTransform trans_ell_stroke = new VertexSourceApplyTransform(ell_stroke, tr);

                    g_rasterizer.add_path(trans_ell);
                    scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0.5, 0.3, 0.0, 0.3));

                    g_rasterizer.add_path(trans_ell_stroke);
                    scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0.0, 0.3, 0.2, 1.0));
                }
            }
            else
            {
                Perspective tr = new Perspective(lionShape.Bounds.Left, lionShape.Bounds.Bottom, lionShape.Bounds.Right, lionShape.Bounds.Top, quadPolygonControl.polygon());
                if (tr.is_valid())
                {
                    // Render transformed lion
                    foreach (var shape in lionShape.Shapes)
                    {
                        VertexSourceApplyTransform trans = new VertexSourceApplyTransform(shape.VertexStorage, tr);
                        g_rasterizer.reset();
                        g_rasterizer.add_path(trans);
                        scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, shape.Color);
                    }

                    // Render transformed ellipse
                    VertexSource.Ellipse FilledEllipse = new MatterHackers.Agg.VertexSource.Ellipse((lionShape.Bounds.Left + lionShape.Bounds.Right) * 0.5, (lionShape.Bounds.Bottom + lionShape.Bounds.Top) * 0.5,
                                                                                                    (lionShape.Bounds.Right - lionShape.Bounds.Left) * 0.5, (lionShape.Bounds.Top - lionShape.Bounds.Bottom) * 0.5,
                                                                                                    200);

                    Stroke EllipseOutline = new Stroke(FilledEllipse);
                    EllipseOutline.width(3.0);
                    VertexSourceApplyTransform TransformedFilledEllipse = new VertexSourceApplyTransform(FilledEllipse, tr);

                    VertexSourceApplyTransform TransformedEllipesOutline = new VertexSourceApplyTransform(EllipseOutline, tr);

                    g_rasterizer.add_path(TransformedFilledEllipse);
                    scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0.5, 0.3, 0.0, 0.3));

                    g_rasterizer.add_path(TransformedEllipesOutline);
                    scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0.0, 0.3, 0.2, 1.0));
                }
            }

            //--------------------------
            // Render the "quad" tool and controls
            g_rasterizer.add_path(quadPolygonControl);
            scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0, 0.3, 0.5, 0.6));
            //m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy);
            base.OnDraw(graphics2D);
        }
Example #19
0
		private void CreateCircularBedGridImage(int linesInX, int linesInY)
		{
			Vector2 bedImageCentimeters = new Vector2(linesInX, linesInY);
			BedImage = new ImageBuffer(1024, 1024, 32, new BlenderBGRA());
			Graphics2D graphics2D = BedImage.NewGraphics2D();
			graphics2D.Clear(bedBaseColor);
			{
				double lineDist = BedImage.Width / (double)linesInX;

				int count = 1;
				int pointSize = 16;
				graphics2D.DrawString(count.ToString(), 4, 4, pointSize, color: bedMarkingsColor);
				double currentRadius = lineDist;
				Vector2 bedCenter = new Vector2(BedImage.Width / 2, BedImage.Height / 2);
				for (double linePos = lineDist + BedImage.Width / 2; linePos < BedImage.Width; linePos += lineDist)
				{
					int linePosInt = (int)linePos;
					graphics2D.DrawString(count.ToString(), linePos + 2, BedImage.Height / 2, pointSize, color: bedMarkingsColor);

					Ellipse circle = new Ellipse(bedCenter, currentRadius);
					Stroke outline = new Stroke(circle);
					graphics2D.Render(outline, bedMarkingsColor);
					currentRadius += lineDist;
					count++;
				}

				graphics2D.Line(0, BedImage.Height / 2, BedImage.Width, BedImage.Height / 2, bedMarkingsColor);
				graphics2D.Line(BedImage.Width / 2, 0, BedImage.Width / 2, BedImage.Height, bedMarkingsColor);
			}
		}
		private void DrawCircle(Vector2 imagePosition, RGBA_Bytes color)
		{
			Ellipse circle = new Ellipse(imagePosition, 14);
			graphics.Render(circle, color);
			graphics.Render(new Stroke(circle), RGBA_Bytes.Black);
		}
Example #21
0
        public override void Render(Graphics2D graphics2D, Affine transform, double layerScale, RenderType renderType)
        {
            if ((renderType & RenderType.Retractions) == RenderType.Retractions)
            {
                Vector2 position = new Vector2(this.position.x, this.position.y);
                transform.transform(ref position);
                double radius = Radius(layerScale);
                Ellipse extrusion = new Ellipse(position, radius);

                if (extrusionAmount > 0)
                {
                    // unretraction
                    graphics2D.Render(extrusion, new RGBA_Bytes(RGBA_Bytes.Blue, 200));
                }
                else
                {
                    // retraction
                    graphics2D.Render(extrusion, new RGBA_Bytes(RGBA_Bytes.Red, 200));
                }
            }
        }
        private void transform_image(double angle)
        {
            double width  = m_TempDestImage.Width;
            double height = m_TempDestImage.Height;

#if SourceDepthFloat
            ImageClippingProxyFloat clippedDest = new ImageClippingProxyFloat(m_TempDestImage);
#else
            ImageClippingProxy clippedDest = new ImageClippingProxy(m_TempDestImage);
#endif

            clippedDest.clear(new ColorF(1.0, 1.0, 1.0));

            Affine src_mtx = Affine.NewIdentity();
            src_mtx *= Affine.NewTranslation(-width / 2.0, -height / 2.0);
            src_mtx *= Affine.NewRotation(angle * Math.PI / 180.0);
            src_mtx *= Affine.NewTranslation(width / 2.0, height / 2.0);

            Affine img_mtx = new Affine(src_mtx);
            img_mtx.invert();

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

            r *= 0.5;
            r -= 4.0;
            VertexSource.Ellipse       ell = new MatterHackers.Agg.VertexSource.Ellipse(width / 2.0, height / 2.0, r, r, 200);
            VertexSourceApplyTransform tr  = new VertexSourceApplyTransform(ell, src_mtx);

            m_num_pix += r * r * Math.PI;

#if SourceDepthFloat
            span_interpolator_linear_float interpolator = new span_interpolator_linear_float(img_mtx);
#else
            span_interpolator_linear interpolator = new span_interpolator_linear(img_mtx);
#endif

            ImageFilterLookUpTable filter = new ImageFilterLookUpTable();
            bool norm = m_normalize.Checked;

#if SourceDepthFloat
            ImageBufferAccessorClipFloat source = new ImageBufferAccessorClipFloat(m_RotatedImage, RGBA_Floats.rgba_pre(0, 0, 0, 0).ToColorF());
#else
            ImageBufferAccessorClip source = new ImageBufferAccessorClip(m_RotatedImage, ColorF.rgba_pre(0, 0, 0, 0).ToColor());
#endif
            IImageFilterFunction filterFunction   = null;
            ScanlineRenderer     scanlineRenderer = new ScanlineRenderer();

            switch (filterSelectionButtons.SelectedIndex)
            {
            case 0:
            {
#if SourceDepthFloat
                span_image_filter_float spanGenerator;
#else
                span_image_filter spanGenerator;
#endif

                switch (source.SourceImage.BitDepth)
                {
                case 24:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgb_nn(source, interpolator);
#endif
                    break;

                case 32:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgba_nn(source, interpolator);
#endif
                    break;

                default:
                    throw new NotImplementedException("only support 24 and 32 bit");
                }

                m_Rasterizer.add_path(tr);
                scanlineRenderer.GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, clippedDest, m_SpanAllocator, spanGenerator);
            }
            break;

            case 1:
            {
#if SourceDepthFloat
                span_image_filter_float spanGenerator;
#else
                span_image_filter spanGenerator;
#endif
                switch (source.SourceImage.BitDepth)
                {
                case 24:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgb_bilinear(source, interpolator);
#endif
                    break;

                case 32:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgba_bilinear(source, interpolator);
#endif
                    break;

#if SourceDepthFloat
                case 128:
                    spanGenerator = new span_image_filter_rgba_bilinear_float(source, interpolator);
                    break;
#endif

                default:
                    throw new NotImplementedException("only support 24 and 32 bit");
                }
                m_Rasterizer.add_path(tr);
                scanlineRenderer.GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, clippedDest, m_SpanAllocator, spanGenerator);
            }
            break;

            case 5:
            case 6:
            case 7:
            {
                switch (filterSelectionButtons.SelectedIndex)
                {
                case 5: filter.calculate(new image_filter_hanning(), norm); break;

                case 6: filter.calculate(new image_filter_hamming(), norm); break;

                case 7: filter.calculate(new image_filter_hermite(), norm); break;
                }

#if SourceDepthFloat
                throw new NotImplementedException();
#else
                span_image_filter_rgb_2x2 spanGenerator = new span_image_filter_rgb_2x2(source, interpolator, filter);
#endif
                m_Rasterizer.add_path(tr);
#if SourceDepthFloat
                throw new NotImplementedException();
#else
                scanlineRenderer.GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, clippedDest, m_SpanAllocator, spanGenerator);
#endif
            }
            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 (filterSelectionButtons.SelectedIndex)
                {
                case 2: filter.calculate(new image_filter_bicubic(), norm); break;

                case 3: filter.calculate(new image_filter_spline16(), norm); break;

                case 4: filter.calculate(new image_filter_spline36(), norm); break;

                case 8: filter.calculate(new image_filter_kaiser(), norm); break;

                case 9: filter.calculate(new image_filter_quadric(), norm); break;

                case 10: filter.calculate(new image_filter_catrom(), norm); break;

                case 11: filter.calculate(new image_filter_gaussian(), norm); break;

                case 12: filter.calculate(new image_filter_bessel(), norm); break;

                case 13: filter.calculate(new image_filter_mitchell(), norm); break;

                case 14: filter.calculate(new image_filter_sinc(m_radius.Value), norm); break;

                case 15: filter.calculate(new image_filter_lanczos(m_radius.Value), norm); break;

                case 16:
                    filterFunction = new image_filter_blackman(m_radius.Value);
                    //filterFunction = new image_filter_bilinear();
                    filter.calculate(filterFunction, norm);
                    break;
                }

#if SourceDepthFloat
                span_image_filter_float spanGenerator;
#else
                span_image_filter spanGenerator;
#endif
                switch (source.SourceImage.BitDepth)
                {
                case 24:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgb(source, interpolator, filter);
#endif
                    break;

                case 32:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgba(source, interpolator, filter);
#endif
                    break;

#if SourceDepthFloat
                case 128:
                    spanGenerator = new span_image_filter_rgba_float(source, interpolator, filterFunction);
                    break;
#endif

                default:
                    throw new NotImplementedException("only support 24 and 32 bit");
                }

                m_Rasterizer.add_path(tr);
                scanlineRenderer.GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, clippedDest, m_SpanAllocator, spanGenerator);
            }
            break;
            }
        }
Example #23
0
 //圆形
 public static CCSprite CreateEllipse(
     double width, double height,
     CCColor4B fill, CCColor4B stroke,
     double strokeThickness = 1
     )
 {
     ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA());
     Graphics2D g = buffer.NewGraphics2D();
     MatterHackers.Agg.VertexSource.Ellipse path;
     if (stroke.A > 0) //有border
     {
         //border是以线的中间对齐,所以转换成int,如果是1个像素,正好变成零
         int halfThickness = (int)(strokeThickness / 2);
         path = new MatterHackers.Agg.VertexSource.Ellipse(width / 2, height / 2, width / 2 - halfThickness, height / 2 - halfThickness);
     }
     else
     {
         path = new MatterHackers.Agg.VertexSource.Ellipse(width / 2, height / 2, width / 2, height / 2);
     }
     if (fill.A > 0) g.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A));
     if (stroke.A > 0) g.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));
     Texture2D xnaTexture = XnaTexture((int)width, (int)height);
     xnaTexture.SetData<byte>(buffer.GetBuffer());
     CCTexture2D ccTexture = new CCTexture2D();
     ccTexture.InitWithTexture(xnaTexture);
     return new CCSprite(ccTexture);
 }
Example #24
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            if (orignialSize.x == 0)
            {
                orignialSize.x = WindowSize.x;
                orignialSize.y = WindowSize.y;
            }

            ImageBuffer destImageWithPreMultBlender = new ImageBuffer();

            switch (widgetsSubImage.BitDepth)
            {
            case 24:
                destImageWithPreMultBlender.Attach(widgetsSubImage, new BlenderPreMultBGR());
                break;

            case 32:
                destImageWithPreMultBlender.Attach(widgetsSubImage, new BlenderPreMultBGRA());
                break;

            default:
                throw new Exception("Unknown bit depth");
            }

            ImageClippingProxy clippingProxy_pre = new ImageClippingProxy(destImageWithPreMultBlender);

            clippingProxy_pre.clear(new RGBA_Floats(1.0, 1.0, 1.0));

            Affine src_mtx = Affine.NewIdentity();

            src_mtx *= Affine.NewTranslation(-orignialSize.x / 2 - 10, -orignialSize.y / 2 - 20 - 10);
            src_mtx *= Affine.NewRotation(drawAngle.Value * Math.PI / 180.0);
            src_mtx *= Affine.NewScaling(drawScale.Value);
            src_mtx *= Affine.NewTranslation(orignialSize.x / 2, orignialSize.y / 2 + 20);

            Affine img_mtx = Affine.NewIdentity();

            img_mtx *= Affine.NewTranslation(-orignialSize.x / 2 + 10, -orignialSize.y / 2 + 20 + 10);
            img_mtx *= Affine.NewRotation(drawAngle.Value * Math.PI / 180.0);
            img_mtx *= Affine.NewScaling(drawScale.Value);
            img_mtx *= Affine.NewTranslation(orignialSize.x / 2, orignialSize.y / 2 + 20);
            img_mtx.invert();

            MatterHackers.Agg.span_allocator sa = new span_allocator();

            span_interpolator_linear interpolator = new span_interpolator_linear(img_mtx);

            span_image_filter sg;

            switch (sourceImage.BitDepth)
            {
            case 24:
            {
                ImageBufferAccessorClip source = new ImageBufferAccessorClip(sourceImage, RGBA_Floats.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes());
                sg = new span_image_filter_rgb_bilinear_clip(source, RGBA_Floats.rgba_pre(0, 0.4, 0, 0.5), interpolator);
            }
            break;

            case 32:
            {
                ImageBufferAccessorClip source = new ImageBufferAccessorClip(sourceImage, RGBA_Floats.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes());
                sg = new span_image_filter_rgba_bilinear_clip(source, RGBA_Floats.rgba_pre(0, 0.4, 0, 0.5), interpolator);
            }
            break;

            default:
                throw new Exception("Bad sourc depth");
            }

            ScanlineRasterizer ras = new ScanlineRasterizer();

            ras.SetVectorClipBox(0, 0, Width, Height);
            ScanlineCachePacked8 sl = new ScanlineCachePacked8();
            //scanline_unpacked_8 sl = new scanline_unpacked_8();

            double r = orignialSize.x;

            if (orignialSize.y - 60 < r)
            {
                r = orignialSize.y - 60;
            }

            VertexSource.Ellipse ell = new VertexSource.Ellipse(orignialSize.x / 2.0 + 10,
                                                                orignialSize.y / 2.0 + 20 + 10,
                                                                r / 2.0 + 16.0,
                                                                r / 2.0 + 16.0, 200);

            VertexSourceApplyTransform tr = new VertexSourceApplyTransform(ell, src_mtx);

            ras.add_path(tr);
            //clippingProxy_pre.SetClippingBox(30, 0, (int)width(), (int)height());
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg);

            if (false)             // this is test code to check different quality settings for scalling
            {
                Vector2 screenCenter = new Vector2(Width / 2, Height / 2);
                Vector2 deltaToMouse = mousePosition - screenCenter;
                double  angleToMouse = Math.Atan2(deltaToMouse.y, deltaToMouse.x);
                double  diagonalSize = Math.Sqrt(sourceImage.Width * sourceImage.Width + sourceImage.Height * sourceImage.Height);
                double  distToMouse  = deltaToMouse.Length;
                double  scalling     = distToMouse / diagonalSize;
                graphics2D.Render(sourceImage, Width / 2, Height / 2, angleToMouse - MathHelper.Tau / 8, scalling, scalling);
            }

            base.OnDraw(graphics2D);
        }
Example #25
0
        //圆形
        public UIGraphic AddEllipse(double x, double y, double width, double height, CCColor4B fill, CCColor4B stroke, double strokeThickness = 1)
        {
            IVertexSource path;
            if (stroke.A > 0) //有border
            {
                //border是以线的中间对齐,所以转换成int,如果是1个像素变成1
                int halfThickness = (int)((strokeThickness + 1) / 2);
                path = new MatterHackers.Agg.VertexSource.Ellipse(width / 2, height / 2, width / 2 - halfThickness, height / 2 - halfThickness);
            }
            else
            {
                path = new MatterHackers.Agg.VertexSource.Ellipse(width / 2, height / 2, width / 2, height / 2);
            }

            if (x != 0 || y != 0)
                path = new VertexSourceApplyTransform(path, Affine.NewTranslation(x, y));
            if (fill.A > 0) this.graphics2D.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A));
            if (stroke.A > 0) this.graphics2D.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));
            return this;
        }
Example #26
0
		public static void Main(string[] args)
		{
			// first we will show how to use the simple drawing functions in graphics 2D
			{
				ImageBuffer simpleImage = new ImageBuffer(640, 480, 32, new BlenderBGRA());
				Graphics2D simpleImageGraphics2D = simpleImage.NewGraphics2D();
				// clear the image to white
				simpleImageGraphics2D.Clear(RGBA_Bytes.White);
				// draw a circle
				simpleImageGraphics2D.Circle(50, 50, 30, RGBA_Bytes.Blue);
				// draw a line
				simpleImageGraphics2D.Line(10, 100, 520, 50, new RGBA_Bytes(20, 200, 200));
				// draw a filled box
				simpleImageGraphics2D.FillRectangle(60, 260, 200, 280, RGBA_Bytes.Yellow);
				// and an outline around it
				simpleImageGraphics2D.Rectangle(60, 260, 200, 280, RGBA_Bytes.Magenta);
				// draw some text
				simpleImageGraphics2D.DrawString("A Simple Example", 300, 400, 20);

				// and save this image out
				ImageTgaIO.Save(simpleImage, "SimpleDrawAndSave.tga");
			}

			// now we will we will show how to use the render function to draw more complex things
			{
				ImageBuffer lessSimpleImage = new ImageBuffer(640, 480, 32, new BlenderBGRA());
				Graphics2D lessSimpleImageGraphics2D = lessSimpleImage.NewGraphics2D();
				// clear the image to white
				lessSimpleImageGraphics2D.Clear(RGBA_Bytes.White);
				// draw a circle
				Ellipse ellipseTest = new Ellipse(0, 0, 100, 50);
				for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5)
				{
					VertexSourceApplyTransform rotatedTransform = new VertexSourceApplyTransform(ellipseTest, Affine.NewRotation(MathHelper.DegreesToRadians(angleDegrees)));
					VertexSourceApplyTransform rotatedAndTranslatedTransform = new VertexSourceApplyTransform(rotatedTransform, Affine.NewTranslation(lessSimpleImage.Width / 2, 150));
					lessSimpleImageGraphics2D.Render(rotatedAndTranslatedTransform, RGBA_Bytes.Yellow);
					Stroke ellipseOutline = new Stroke(rotatedAndTranslatedTransform, 3);
					lessSimpleImageGraphics2D.Render(ellipseOutline, RGBA_Bytes.Blue);
				}

				// and a little polygon
				PathStorage littlePoly = new PathStorage();
				littlePoly.MoveTo(50, 50);
				littlePoly.LineTo(150, 50);
				littlePoly.LineTo(200, 200);
				littlePoly.LineTo(50, 150);
				littlePoly.LineTo(50, 50);
				lessSimpleImageGraphics2D.Render(littlePoly, RGBA_Bytes.Cyan);

				// draw some text
				TypeFacePrinter textPrinter = new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center);
				IVertexSource translatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewTranslation(new Vector2(lessSimpleImage.Width / 2, lessSimpleImage.Height / 4 * 3)));
				lessSimpleImageGraphics2D.Render(translatedText, RGBA_Bytes.Red);
				Stroke strokedText = new Stroke(translatedText);
				lessSimpleImageGraphics2D.Render(strokedText, RGBA_Bytes.Black);

				IVertexSource rotatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewRotation(MathHelper.DegreesToRadians(90)));
				IVertexSource rotatedTranslatedText = new VertexSourceApplyTransform(rotatedText, Affine.NewTranslation(new Vector2(40, lessSimpleImage.Height / 2)));
				lessSimpleImageGraphics2D.Render(rotatedTranslatedText, RGBA_Bytes.Black);

				// and save this image out
				ImageTgaIO.Save(lessSimpleImage, "LessSimpleDrawAndSave.tga");
			}
		}
		public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions)
			{
				double radius = Radius(renderInfo.LayerScale);
				Vector2 position = new Vector2(this.position.x, this.position.y);
				renderInfo.Transform.transform(ref position);

				RGBA_Bytes retractionColor = new RGBA_Bytes(RGBA_Bytes.Red, 200);
				if (extrusionAmount > 0)
				{
					// unretraction
					retractionColor = new RGBA_Bytes(RGBA_Bytes.Blue, 200);
				}

				// render the part using opengl
				Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
				if (graphics2DGl != null)
				{
					graphics2DGl.DrawAACircle(position, radius, retractionColor);
				}
				else
				{
					Ellipse extrusion = new Ellipse(position, radius);
					graphics2D.Render(extrusion, retractionColor);
				}
			}
		}