Example #1
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            IImageByte backBuffer = widgetsSubImage;

#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr());
#else
            ImageBuffer pf = new ImageBuffer();
            pf.Attach(backBuffer, new BlenderBGRA());
#endif
            ImageClippingProxy ren_base = new ImageClippingProxy(pf);
            ren_base.clear(new RGBA_Floats(1.0, 1.0, 1.0));

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

            ras.gamma(new gamma_none());
            //m_dilation.Render(ras, sl, ren_base);
            //m_gamma.Render(ras, sl, ren_base);
            //m_alpha.Render(ras, sl, ren_base);
            base.OnDraw(graphics2D);
        }
        public image_filters()
            : base(FlowDirection.BottomToTop)
        {
            m_step   = new Slider(new Vector2(115, 5), new Vector2(285, 6));
            m_radius = new Slider(new Vector2(115, 5 + 15), new Vector2(285, 6));
            filterSelectionButtons = new RadioButtonGroup(new Vector2(0.0, 10.0), new Vector2(110.0, 210.0));
            m_normalize            = new CheckBox(8.0, 215.0, "Normalize Filter");

            m_refresh            = new Button(8.0, 273.0, new ButtonViewText("Refresh", 8, 1, 3));
            m_refresh.Click     += RefreshImage;
            m_run                = new Button(8.0, 253.0, new ButtonViewText("RUN Test!", 8, 1, 3));
            m_run.Click         += RunTest;
            m_single_step        = new Button(8.0, 233.0, new ButtonViewText("Single Step", 8, 1, 3));
            m_single_step.Click += SingleStep;

            m_cur_angle        = (0.0);
            m_cur_filter       = (1);
            m_num_steps        = (0);
            m_num_pix          = (0.0);
            m_time1            = (0);
            m_time2            = (0);
            m_ScanlinePacked   = new ScanlineCachePacked8();
            m_Rasterizer       = new ScanlineRasterizer();
            m_ScanlineUnpacked = new scanline_unpacked_8();
            m_SpanAllocator    = new span_allocator();

            AddChild(m_radius);
            AddChild(m_step);
            AddChild(filterSelectionButtons);
            AddChild(m_run);
            AddChild(m_single_step);
            AddChild(m_normalize);
            AddChild(m_refresh);
            m_normalize.Checked = true;

            m_radius.Text = "Filter Radius={0:F2}";
            m_step.Text   = "Step={0:F2}";
            m_radius.SetRange(2.0, 8.0);
            m_radius.Value = 4.0;
            m_step.SetRange(1.0, 10.0);
            m_step.Value = 5.0;

            filterSelectionButtons.AddRadioButton("simple (NN)");
            filterSelectionButtons.AddRadioButton("bilinear");
            filterSelectionButtons.AddRadioButton("bicubic");
            filterSelectionButtons.AddRadioButton("spline16");
            filterSelectionButtons.AddRadioButton("spline36");
            filterSelectionButtons.AddRadioButton("hanning");
            filterSelectionButtons.AddRadioButton("hamming");
            filterSelectionButtons.AddRadioButton("hermite");
            filterSelectionButtons.AddRadioButton("kaiser");
            filterSelectionButtons.AddRadioButton("quadric");
            filterSelectionButtons.AddRadioButton("catrom");
            filterSelectionButtons.AddRadioButton("gaussian");
            filterSelectionButtons.AddRadioButton("bessel");
            filterSelectionButtons.AddRadioButton("mitchell");
            filterSelectionButtons.AddRadioButton("sinc");
            filterSelectionButtons.AddRadioButton("lanczos");
            filterSelectionButtons.AddRadioButton("blackman");
            filterSelectionButtons.SelectedIndex = 1;

            filterSelectionButtons.background_color(new ColorF(0.0, 0.0, 0.0, 0.1));
        }
Example #3
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

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

			if (m_gamma.Value != m_old_gamma)
			{
				m_gamma_lut.SetGamma(m_gamma.Value);
				ImageIO.LoadImageData("spheres.bmp", m_SourceImage);
				//m_SourceImage.apply_gamma_dir(m_gamma_lut);
				m_old_gamma = m_gamma.Value;
			}

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

				case 32:
					pixf.Attach(widgetsSubImage, new BlenderBGRA());
					break;

				default:
					throw new NotImplementedException();
			}

			ImageClippingProxy clippingProxy = new ImageClippingProxy(pixf);

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

			if (m_trans_type.SelectedIndex < 2)
			{
				// For the affine parallelogram transformations we
				// calculate the 4-th (implicit) point of the parallelogram
				m_quad.SetXN(3, m_quad.GetXN(0) + (m_quad.GetXN(2) - m_quad.GetXN(1)));
				m_quad.SetYN(3, m_quad.GetYN(0) + (m_quad.GetYN(2) - m_quad.GetYN(1)));
			}

			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			// draw a background to show how the alpha is working
			int RectWidth = 70;
			int xoffset = 50;
			int yoffset = 50;
			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();

						g_rasterizer.add_path(rect);
						scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(.2, .2, .2));
					}
				}
			}

			//--------------------------
			// Render the "quad" tool and controls
			g_rasterizer.add_path(m_quad);
			scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0.3, 0.5, 0.1));

			// Prepare the polygon to rasterize. Here we need to fill
			// the destination (transformed) polygon.
			g_rasterizer.SetVectorClipBox(0, 0, Width, Height);
			g_rasterizer.reset();
			int b = 0;
			g_rasterizer.move_to_d(m_quad.GetXN(0) - b, m_quad.GetYN(0) - b);
			g_rasterizer.line_to_d(m_quad.GetXN(1) + b, m_quad.GetYN(1) - b);
			g_rasterizer.line_to_d(m_quad.GetXN(2) + b, m_quad.GetYN(2) + b);
			g_rasterizer.line_to_d(m_quad.GetXN(3) - b, m_quad.GetYN(3) + b);

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

			ImageBufferAccessorClamp source = new ImageBufferAccessorClamp(m_SourceImage);

			stopwatch.Restart();

			switch (m_trans_type.SelectedIndex)
			{
				case 0:
					{
						/*
								agg::trans_affine tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);

								typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type;
								interpolator_type interpolator(tr);

								typedef image_filter_2x2_type<source_type,
															  interpolator_type> span_gen_type;
								span_gen_type sg(source, interpolator, filter);
								agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
						 */
						break;
					}

				case 1:
					{
						/*
								agg::trans_affine tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);

								typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type;
								typedef image_resample_affine_type<source_type> span_gen_type;

								interpolator_type interpolator(tr);
								span_gen_type sg(source, interpolator, filter);
								sg.blur(m_blur.Value);
								agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
						 */
						break;
					}

				case 2:
					{
						/*
								agg::trans_perspective tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
								if(tr.is_valid())
								{
									typedef agg::span_interpolator_linear_subdiv<agg::trans_perspective> interpolator_type;
									interpolator_type interpolator(tr);

									typedef image_filter_2x2_type<source_type,
																  interpolator_type> span_gen_type;
									span_gen_type sg(source, interpolator, filter);
									agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
								}
						 */
						break;
					}

				case 3:
					{
						/*
								agg::trans_perspective tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
								if(tr.is_valid())
								{
									typedef agg::span_interpolator_trans<agg::trans_perspective> interpolator_type;
									interpolator_type interpolator(tr);

									typedef image_filter_2x2_type<source_type,
																  interpolator_type> span_gen_type;
									span_gen_type sg(source, interpolator, filter);
									agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
								}
						 */
						break;
					}

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

						span_interpolator_persp_lerp interpolator = new span_interpolator_persp_lerp(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
						span_subdiv_adaptor subdiv_adaptor = new span_subdiv_adaptor(interpolator);

						span_image_resample sg = null;
						if (interpolator.is_valid())
						{
							switch (source.SourceImage.BitDepth)
							{
								case 24:
									sg = new span_image_resample_rgb(source, subdiv_adaptor, filter);
									break;

								case 32:
									sg = new span_image_resample_rgba(source, subdiv_adaptor, filter);
									break;
							}

							sg.blur(m_blur.Value);
							scanlineRenderer.GenerateAndRender(g_rasterizer, g_scanline, clippingProxy, sa, sg);
						}
						break;
					}

				case 5:
					{
						/*
								typedef agg::span_interpolator_persp_exact<> interpolator_type;
								typedef agg::span_subdiv_adaptor<interpolator_type> subdiv_adaptor_type;

								interpolator_type interpolator(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
								subdiv_adaptor_type subdiv_adaptor(interpolator);

								if(interpolator.is_valid())
								{
									typedef image_resample_type<source_type,
																subdiv_adaptor_type> span_gen_type;
									span_gen_type sg(source, subdiv_adaptor, filter);
									sg.blur(m_blur.Value);
									agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
								}
						 */
						break;
					}
			}

			double tm = stopwatch.ElapsedMilliseconds;
			//pixf.apply_gamma_inv(m_gamma_lut);

			gsv_text t = new gsv_text();
			t.SetFontSize(10.0);

			Stroke pt = new Stroke(t);
			pt.width(1.5);

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

			g_rasterizer.add_path(pt);
			scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0, 0));

			//--------------------------
			//m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy);
			//m_gamma.Render(g_rasterizer, g_scanline, clippingProxy);
			//m_blur.Render(g_rasterizer, g_scanline, clippingProxy);
			base.OnDraw(graphics2D);
		}
		internal void render_gouraud(IImageByte backBuffer, IScanlineCache sl, IRasterizer ras, RenderPoint[] points)
		{
			ImageBuffer image = new ImageBuffer();
			image.Attach(backBuffer, new BlenderZBuffer());

			ImageClippingProxy ren_base = new ImageClippingProxy(image);

			MatterHackers.Agg.span_allocator span_alloc = new span_allocator();
			span_gouraud_rgba span_gen = new span_gouraud_rgba();

			span_gen.colors(points[0].color, points[1].color, points[2].color);
			span_gen.triangle(points[0].position.x, points[0].position.y, points[1].position.x, points[1].position.y, points[2].position.x, points[2].position.y);
			ras.add_path(span_gen);
			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);
		}
Example #5
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 #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 GenerateAndRender(IRasterizer rasterizer, IScanlineCache scanlineCache, IImageFloat destImage, span_allocator spanAllocator, ISpanGeneratorFloat spanGenerator)
		{
			if (rasterizer.rewind_scanlines())
			{
				scanlineCache.reset(rasterizer.min_x(), rasterizer.max_x());
				spanGenerator.prepare();
				while (rasterizer.sweep_scanline(scanlineCache))
				{
					GenerateAndRenderSingleScanline(scanlineCache, destImage, spanAllocator, spanGenerator);
				}
			}
		}
Example #8
0
 public void GenerateAndRender(IRasterizer rasterizer, IScanlineCache scanlineCache, IImageFloat destImage, span_allocator spanAllocator, ISpanGeneratorFloat spanGenerator)
 {
     if (rasterizer.rewind_scanlines())
     {
         scanlineCache.reset(rasterizer.min_x(), rasterizer.max_x());
         spanGenerator.prepare();
         while (rasterizer.sweep_scanline(scanlineCache))
         {
             GenerateAndRenderSingleScanline(scanlineCache, destImage, spanAllocator, spanGenerator);
         }
     }
 }
Example #9
0
        public void RenderCompound(rasterizer_compound_aa ras, IScanlineCache sl_aa, IScanlineCache sl_bin, IImageByte imageFormat, span_allocator alloc, IStyleHandler sh)
        {
#if false
            unsafe
            {
                if (ras.rewind_scanlines())
                {
                    int min_x = ras.min_x();
                    int len   = ras.max_x() - min_x + 2;
                    sl_aa.reset(min_x, ras.max_x());
                    sl_bin.reset(min_x, ras.max_x());

                    //typedef typename BaseRenderer::color_type color_type;
                    ArrayPOD <RGBA_Bytes> color_span = alloc.allocate((int)len * 2);
                    byte[] ManagedCoversArray        = sl_aa.GetCovers();
                    fixed(byte *pCovers = ManagedCoversArray)
                    {
                        fixed(RGBA_Bytes *pColorSpan = color_span.Array)
                        {
                            int mix_bufferOffset = len;
                            int num_spans;

                            int  num_styles;
                            int  style;
                            bool solid;

                            while ((num_styles = ras.sweep_styles()) > 0)
                            {
                                if (num_styles == 1)
                                {
                                    // Optimization for a single style. Happens often
                                    //-------------------------
                                    if (ras.sweep_scanline(sl_aa, 0))
                                    {
                                        style = ras.style(0);
                                        if (sh.is_solid(style))
                                        {
                                            // Just solid fill
                                            //-----------------------
                                            RenderSolidSingleScanLine(imageFormat, sl_aa, sh.color(style));
                                        }
                                        else
                                        {
                                            // Arbitrary span generator
                                            //-----------------------
                                            ScanlineSpan span_aa = sl_aa.Begin();
                                            num_spans = sl_aa.num_spans();
                                            for (; ;)
                                            {
                                                len = span_aa.len;
                                                sh.generate_span(pColorSpan,
                                                                 span_aa.x,
                                                                 sl_aa.y(),
                                                                 (int)len,
                                                                 style);

                                                imageFormat.blend_color_hspan(span_aa.x,
                                                                              sl_aa.y(),
                                                                              (int)span_aa.len,
                                                                              pColorSpan,
                                                                              &pCovers[span_aa.cover_index], 0);
                                                if (--num_spans == 0)
                                                {
                                                    break;
                                                }
                                                span_aa = sl_aa.GetNextScanlineSpan();
                                            }
                                        }
                                    }
                                }
                                else // there are multiple styles
                                {
                                    if (ras.sweep_scanline(sl_bin, -1))
                                    {
                                        // Clear the spans of the mix_buffer
                                        //--------------------
                                        ScanlineSpan span_bin = sl_bin.Begin();
                                        num_spans = sl_bin.num_spans();
                                        for (; ;)
                                        {
                                            agg_basics.MemClear((byte *)&pColorSpan[mix_bufferOffset + span_bin.x - min_x],
                                                                span_bin.len * sizeof(RGBA_Bytes));

                                            if (--num_spans == 0)
                                            {
                                                break;
                                            }
                                            span_bin = sl_bin.GetNextScanlineSpan();
                                        }

                                        for (int i = 0; i < num_styles; i++)
                                        {
                                            style = ras.style(i);
                                            solid = sh.is_solid(style);

                                            if (ras.sweep_scanline(sl_aa, (int)i))
                                            {
                                                //IColorType* colors;
                                                //IColorType* cspan;
                                                //typename ScanlineAA::cover_type* covers;
                                                ScanlineSpan span_aa = sl_aa.Begin();
                                                num_spans = sl_aa.num_spans();
                                                if (solid)
                                                {
                                                    // Just solid fill
                                                    //-----------------------
                                                    for (; ;)
                                                    {
                                                        RGBA_Bytes c = sh.color(style);
                                                        len = span_aa.len;
                                                        RGBA_Bytes *colors = &pColorSpan[mix_bufferOffset + span_aa.x - min_x];
                                                        byte *      covers = &pCovers[span_aa.cover_index];
                                                        do
                                                        {
                                                            if (*covers == cover_full)
                                                            {
                                                                *colors = c;
                                                            }
                                                            else
                                                            {
                                                                colors->add(c, *covers);
                                                            }
                                                            ++colors;
                                                            ++covers;
                                                        }while (--len != 0);
                                                        if (--num_spans == 0)
                                                        {
                                                            break;
                                                        }
                                                        span_aa = sl_aa.GetNextScanlineSpan();
                                                    }
                                                }
                                                else
                                                {
                                                    // Arbitrary span generator
                                                    //-----------------------
                                                    for (; ;)
                                                    {
                                                        len = span_aa.len;
                                                        RGBA_Bytes *colors = &pColorSpan[mix_bufferOffset + span_aa.x - min_x];
                                                        RGBA_Bytes *cspan  = pColorSpan;
                                                        sh.generate_span(cspan,
                                                                         span_aa.x,
                                                                         sl_aa.y(),
                                                                         (int)len,
                                                                         style);
                                                        byte *covers = &pCovers[span_aa.cover_index];
                                                        do
                                                        {
                                                            if (*covers == cover_full)
                                                            {
                                                                *colors = *cspan;
                                                            }
                                                            else
                                                            {
                                                                colors->add(*cspan, *covers);
                                                            }
                                                            ++cspan;
                                                            ++colors;
                                                            ++covers;
                                                        }while (--len != 0);
                                                        if (--num_spans == 0)
                                                        {
                                                            break;
                                                        }
                                                        span_aa = sl_aa.GetNextScanlineSpan();
                                                    }
                                                }
                                            }
                                        }

                                        // Emit the blended result as a color hspan
                                        //-------------------------
                                        span_bin  = sl_bin.Begin();
                                        num_spans = sl_bin.num_spans();
                                        for (; ;)
                                        {
                                            imageFormat.blend_color_hspan(span_bin.x,
                                                                          sl_bin.y(),
                                                                          (int)span_bin.len,
                                                                          &pColorSpan[mix_bufferOffset + span_bin.x - min_x],
                                                                          null,
                                                                          cover_full);
                                            if (--num_spans == 0)
                                            {
                                                break;
                                            }
                                            span_bin = sl_bin.GetNextScanlineSpan();
                                        }
                                    } // if(ras.sweep_scanline(sl_bin, -1))
                                }     // if(num_styles == 1) ... else
                            }         // while((num_styles = ras.sweep_styles()) > 0)
                        }
                    }
                } // if(ras.rewind_scanlines())
            }
#endif
        }
Example #10
0
		//template<class Scanline, class Ras>
		public void render_gouraud(IImageByte backBuffer, IScanlineCache sl, IRasterizer ras)
		{
			double alpha = m_alpha.Value;
			double brc = 1;
#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr());
#else
			ImageBuffer image = new ImageBuffer();
			image.Attach(backBuffer, new BlenderBGRA());
#endif
			ImageClippingProxy ren_base = new ImageClippingProxy(image);

			MatterHackers.Agg.span_allocator span_alloc = new span_allocator();
			span_gouraud_rgba span_gen = new span_gouraud_rgba();

			ras.gamma(new gamma_linear(0.0, m_gamma.Value));

			double d = m_dilation.Value;

			// Six triangles
			double xc = (m_x[0] + m_x[1] + m_x[2]) / 3.0;
			double yc = (m_y[0] + m_y[1] + m_y[2]) / 3.0;

			double x1 = (m_x[1] + m_x[0]) / 2 - (xc - (m_x[1] + m_x[0]) / 2);
			double y1 = (m_y[1] + m_y[0]) / 2 - (yc - (m_y[1] + m_y[0]) / 2);

			double x2 = (m_x[2] + m_x[1]) / 2 - (xc - (m_x[2] + m_x[1]) / 2);
			double y2 = (m_y[2] + m_y[1]) / 2 - (yc - (m_y[2] + m_y[1]) / 2);

			double x3 = (m_x[0] + m_x[2]) / 2 - (xc - (m_x[0] + m_x[2]) / 2);
			double y3 = (m_y[0] + m_y[2]) / 2 - (yc - (m_y[0] + m_y[2]) / 2);

			span_gen.colors(new RGBA_Floats(1, 0, 0, alpha),
							new RGBA_Floats(0, 1, 0, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d);
			ras.add_path(span_gen);
			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

			span_gen.colors(new RGBA_Floats(0, 1, 0, alpha),
							new RGBA_Floats(0, 0, 1, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d);
			ras.add_path(span_gen);
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

			span_gen.colors(new RGBA_Floats(0, 0, 1, alpha),
							new RGBA_Floats(1, 0, 0, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d);
			ras.add_path(span_gen);
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

			brc = 1 - brc;
			span_gen.colors(new RGBA_Floats(1, 0, 0, alpha),
							new RGBA_Floats(0, 1, 0, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d);
			ras.add_path(span_gen);
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

			span_gen.colors(new RGBA_Floats(0, 1, 0, alpha),
							new RGBA_Floats(0, 0, 1, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d);
			ras.add_path(span_gen);
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

			span_gen.colors(new RGBA_Floats(0, 0, 1, alpha),
							new RGBA_Floats(1, 0, 0, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d);
			ras.add_path(span_gen);
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);
		}
Example #11
0
        private void GenerateAndRenderSingleScanline(IScanlineCache scanLineCache, IImageFloat destImageFloat, span_allocator alloc, ISpanGeneratorFloat span_gen)
        {
            int          y            = scanLineCache.y();
            int          num_spans    = scanLineCache.num_spans();
            ScanlineSpan scanlineSpan = scanLineCache.begin();

            byte[] ManagedCoversArray = scanLineCache.GetCovers();
            for (; ;)
            {
                int x   = scanlineSpan.x;
                int len = scanlineSpan.len;
                if (len < 0)
                {
                    len = -len;
                }

                if (tempSpanColorsFloats.Capacity() < len)
                {
                    tempSpanColorsFloats.Capacity(len);
                }

                span_gen.generate(tempSpanColorsFloats.Array, 0, x, y, len);
                bool useFirstCoverForAll = scanlineSpan.len < 0;
                destImageFloat.blend_color_hspan(x, y, len, tempSpanColorsFloats.Array, 0, ManagedCoversArray, scanlineSpan.cover_index, useFirstCoverForAll);

                if (--num_spans == 0)
                {
                    break;
                }
                scanlineSpan = scanLineCache.GetNextScanlineSpan();
            }
        }
Example #12
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			IImageByte backBuffer = widgetsSubImage;
#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr());
#else
			ImageBuffer pf = new ImageBuffer();
			pf.Attach(backBuffer, new BlenderBGRA());
#endif
			ImageClippingProxy ren_base = new ImageClippingProxy(pf);
			ren_base.clear(new RGBA_Floats(1.0, 1.0, 1.0));

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

			ras.gamma(new gamma_none());
			//m_dilation.Render(ras, sl, ren_base);
			//m_gamma.Render(ras, sl, ren_base);
			//m_alpha.Render(ras, sl, ren_base);
			base.OnDraw(graphics2D);
		}
Example #13
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			IImageByte backBuffer = widgetsSubImage;

			IImageByte destImage = backBuffer;
			ImageClippingProxy clippingProxy = new ImageClippingProxy(destImage);
			clippingProxy.clear(new RGBA_Floats(0, 0, 0));

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

			rasterizer_compound_aa rasc = new rasterizer_compound_aa();
			span_allocator alloc = new span_allocator();

			int i;
			styles_gouraud styles = new styles_gouraud(m_mesh, m_gamma);
			stopwatch.Restart();
			rasc.reset();
			//rasc.clip_box(40, 40, width() - 40, height() - 40);
			for (i = 0; i < m_mesh.num_edges(); i++)
			{
				mesh_edge e = m_mesh.edge(i);
				mesh_point p1 = m_mesh.vertex(e.p1);
				mesh_point p2 = m_mesh.vertex(e.p2);
				rasc.styles(e.tl, e.tr);
				rasc.move_to_d(p1.x, p1.y);
				rasc.line_to_d(p2.x, p2.y);
			}

			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.RenderCompound(rasc, sl, sl_bin, clippingProxy, alloc, styles);
			double tm = stopwatch.ElapsedMilliseconds;

			gsv_text t = new gsv_text();
			t.SetFontSize(10.0);

			Stroke pt = new Stroke(t);
			pt.width(1.5);
			pt.line_cap(LineCap.Round);
			pt.line_join(LineJoin.Round);

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

			ras.add_path(pt);
			scanlineRenderer.RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(255, 255, 255));

			if (m_gamma.GetGamma() != 1.0)
			{
				((ImageBuffer)destImage).apply_gamma_inv(m_gamma);
			}

			base.OnDraw(graphics2D);
		}
Example #14
0
		public void RenderCompound(rasterizer_compound_aa ras, IScanlineCache sl_aa, IScanlineCache sl_bin, IImageByte imageFormat, span_allocator alloc, IStyleHandler sh)
		{
#if false
            unsafe
            {
                if (ras.rewind_scanlines())
                {
                    int min_x = ras.min_x();
                    int len = ras.max_x() - min_x + 2;
                    sl_aa.reset(min_x, ras.max_x());
                    sl_bin.reset(min_x, ras.max_x());

                    //typedef typename BaseRenderer::color_type color_type;
                    ArrayPOD<RGBA_Bytes> color_span = alloc.allocate((int)len * 2);
                    byte[] ManagedCoversArray = sl_aa.GetCovers();
                    fixed (byte* pCovers = ManagedCoversArray)
                    {
                        fixed (RGBA_Bytes* pColorSpan = color_span.Array)
                        {
                            int mix_bufferOffset = len;
                            int num_spans;

                            int num_styles;
                            int style;
                            bool solid;
                            while ((num_styles = ras.sweep_styles()) > 0)
                            {
                                if (num_styles == 1)
                                {
                                    // Optimization for a single style. Happens often
                                    //-------------------------
                                    if (ras.sweep_scanline(sl_aa, 0))
                                    {
                                        style = ras.style(0);
                                        if (sh.is_solid(style))
                                        {
                                            // Just solid fill
                                            //-----------------------
                                            RenderSolidSingleScanLine(imageFormat, sl_aa, sh.color(style));
                                        }
                                        else
                                        {
                                            // Arbitrary span generator
                                            //-----------------------
                                            ScanlineSpan span_aa = sl_aa.Begin();
                                            num_spans = sl_aa.num_spans();
                                            for (; ; )
                                            {
                                                len = span_aa.len;
                                                sh.generate_span(pColorSpan,
                                                                 span_aa.x,
                                                                 sl_aa.y(),
                                                                 (int)len,
                                                                 style);

                                                imageFormat.blend_color_hspan(span_aa.x,
                                                                      sl_aa.y(),
                                                                      (int)span_aa.len,
                                                                      pColorSpan,
                                                                      &pCovers[span_aa.cover_index], 0);
                                                if (--num_spans == 0) break;
                                                span_aa = sl_aa.GetNextScanlineSpan();
                                            }
                                        }
                                    }
                                }
                                else // there are multiple styles
                                {
                                    if (ras.sweep_scanline(sl_bin, -1))
                                    {
                                        // Clear the spans of the mix_buffer
                                        //--------------------
                                        ScanlineSpan span_bin = sl_bin.Begin();
                                        num_spans = sl_bin.num_spans();
                                        for (; ; )
                                        {
                                            agg_basics.MemClear((byte*)&pColorSpan[mix_bufferOffset + span_bin.x - min_x],
                                                   span_bin.len * sizeof(RGBA_Bytes));

                                            if (--num_spans == 0) break;
                                            span_bin = sl_bin.GetNextScanlineSpan();
                                        }

                                        for (int i = 0; i < num_styles; i++)
                                        {
                                            style = ras.style(i);
                                            solid = sh.is_solid(style);

                                            if (ras.sweep_scanline(sl_aa, (int)i))
                                            {
                                                //IColorType* colors;
                                                //IColorType* cspan;
                                                //typename ScanlineAA::cover_type* covers;
                                                ScanlineSpan span_aa = sl_aa.Begin();
                                                num_spans = sl_aa.num_spans();
                                                if (solid)
                                                {
                                                    // Just solid fill
                                                    //-----------------------
                                                    for (; ; )
                                                    {
                                                        RGBA_Bytes c = sh.color(style);
                                                        len = span_aa.len;
                                                        RGBA_Bytes* colors = &pColorSpan[mix_bufferOffset + span_aa.x - min_x];
                                                        byte* covers = &pCovers[span_aa.cover_index];
                                                        do
                                                        {
                                                            if (*covers == cover_full)
                                                            {
                                                                *colors = c;
                                                            }
                                                            else
                                                            {
                                                                colors->add(c, *covers);
                                                            }
                                                            ++colors;
                                                            ++covers;
                                                        }
                                                        while (--len != 0);
                                                        if (--num_spans == 0) break;
                                                        span_aa = sl_aa.GetNextScanlineSpan();
                                                    }
                                                }
                                                else
                                                {
                                                    // Arbitrary span generator
                                                    //-----------------------
                                                    for (; ; )
                                                    {
                                                        len = span_aa.len;
                                                        RGBA_Bytes* colors = &pColorSpan[mix_bufferOffset + span_aa.x - min_x];
                                                        RGBA_Bytes* cspan = pColorSpan;
                                                        sh.generate_span(cspan,
                                                                         span_aa.x,
                                                                         sl_aa.y(),
                                                                         (int)len,
                                                                         style);
                                                        byte* covers = &pCovers[span_aa.cover_index];
                                                        do
                                                        {
                                                            if (*covers == cover_full)
                                                            {
                                                                *colors = *cspan;
                                                            }
                                                            else
                                                            {
                                                                colors->add(*cspan, *covers);
                                                            }
                                                            ++cspan;
                                                            ++colors;
                                                            ++covers;
                                                        }
                                                        while (--len != 0);
                                                        if (--num_spans == 0) break;
                                                        span_aa = sl_aa.GetNextScanlineSpan();
                                                    }
                                                }
                                            }
                                        }

                                        // Emit the blended result as a color hspan
                                        //-------------------------
                                        span_bin = sl_bin.Begin();
                                        num_spans = sl_bin.num_spans();
                                        for (; ; )
                                        {
                                            imageFormat.blend_color_hspan(span_bin.x,
                                                                  sl_bin.y(),
                                                                  (int)span_bin.len,
                                                                  &pColorSpan[mix_bufferOffset + span_bin.x - min_x],
                                                                  null,
                                                                  cover_full);
                                            if (--num_spans == 0) break;
                                            span_bin = sl_bin.GetNextScanlineSpan();
                                        }
                                    } // if(ras.sweep_scanline(sl_bin, -1))
                                } // if(num_styles == 1) ... else
                            } // while((num_styles = ras.sweep_styles()) > 0)
                        }
                    }
                } // if(ras.rewind_scanlines())
            }
#endif
		}
Example #15
0
        //template<class Scanline, class Ras>
        public void render_gouraud(IImageByte backBuffer, IScanlineCache sl, IRasterizer ras)
        {
            double alpha = m_alpha.Value;
            double brc   = 1;

#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr());
#else
            ImageBuffer image = new ImageBuffer();
            image.Attach(backBuffer, new BlenderBGRA());
#endif
            ImageClippingProxy ren_base = new ImageClippingProxy(image);

            MatterHackers.Agg.span_allocator span_alloc = new span_allocator();
            span_gouraud_rgba span_gen = new span_gouraud_rgba();

            ras.gamma(new gamma_linear(0.0, m_gamma.Value));

            double d = m_dilation.Value;

            // Six triangles
            double xc = (m_x[0] + m_x[1] + m_x[2]) / 3.0;
            double yc = (m_y[0] + m_y[1] + m_y[2]) / 3.0;

            double x1 = (m_x[1] + m_x[0]) / 2 - (xc - (m_x[1] + m_x[0]) / 2);
            double y1 = (m_y[1] + m_y[0]) / 2 - (yc - (m_y[1] + m_y[0]) / 2);

            double x2 = (m_x[2] + m_x[1]) / 2 - (xc - (m_x[2] + m_x[1]) / 2);
            double y2 = (m_y[2] + m_y[1]) / 2 - (yc - (m_y[2] + m_y[1]) / 2);

            double x3 = (m_x[0] + m_x[2]) / 2 - (xc - (m_x[0] + m_x[2]) / 2);
            double y3 = (m_y[0] + m_y[2]) / 2 - (yc - (m_y[0] + m_y[2]) / 2);

            span_gen.colors(new RGBA_Floats(1, 0, 0, alpha),
                            new RGBA_Floats(0, 1, 0, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d);
            ras.add_path(span_gen);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

            span_gen.colors(new RGBA_Floats(0, 1, 0, alpha),
                            new RGBA_Floats(0, 0, 1, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d);
            ras.add_path(span_gen);
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

            span_gen.colors(new RGBA_Floats(0, 0, 1, alpha),
                            new RGBA_Floats(1, 0, 0, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d);
            ras.add_path(span_gen);
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

            brc = 1 - brc;
            span_gen.colors(new RGBA_Floats(1, 0, 0, alpha),
                            new RGBA_Floats(0, 1, 0, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d);
            ras.add_path(span_gen);
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

            span_gen.colors(new RGBA_Floats(0, 1, 0, alpha),
                            new RGBA_Floats(0, 0, 1, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d);
            ras.add_path(span_gen);
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

            span_gen.colors(new RGBA_Floats(0, 0, 1, alpha),
                            new RGBA_Floats(1, 0, 0, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d);
            ras.add_path(span_gen);
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);
        }
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            IImageByte backBuffer = widgetsSubImage;

            IImageByte         destImage     = backBuffer;
            ImageClippingProxy clippingProxy = new ImageClippingProxy(destImage);

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

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

            rasterizer_compound_aa rasc  = new rasterizer_compound_aa();
            span_allocator         alloc = new span_allocator();

            int            i;
            styles_gouraud styles = new styles_gouraud(m_mesh, m_gamma);

            stopwatch.Restart();
            rasc.reset();
            //rasc.clip_box(40, 40, width() - 40, height() - 40);
            for (i = 0; i < m_mesh.num_edges(); i++)
            {
                mesh_edge  e  = m_mesh.edge(i);
                mesh_point p1 = m_mesh.vertex(e.p1);
                mesh_point p2 = m_mesh.vertex(e.p2);
                rasc.styles(e.tl, e.tr);
                rasc.move_to_d(p1.x, p1.y);
                rasc.line_to_d(p2.x, p2.y);
            }

            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.RenderCompound(rasc, sl, sl_bin, clippingProxy, alloc, styles);
            double tm = stopwatch.ElapsedMilliseconds;

            gsv_text t = new gsv_text();

            t.SetFontSize(10.0);

            Stroke pt = new Stroke(t);

            pt.width(1.5);
            pt.line_cap(LineCap.Round);
            pt.line_join(LineJoin.Round);

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

            t.start_point(10.0, 10.0);
            t.text(buf);

            ras.add_path(pt);
            scanlineRenderer.RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(255, 255, 255));

            if (m_gamma.GetGamma() != 1.0)
            {
                ((ImageBuffer)destImage).apply_gamma_inv(m_gamma);
            }

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

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

            if (m_gamma.Value != m_old_gamma)
            {
                m_gamma_lut.SetGamma(m_gamma.Value);
                ImageIO.LoadImageData("spheres.bmp", m_SourceImage);
                //m_SourceImage.apply_gamma_dir(m_gamma_lut);
                m_old_gamma = m_gamma.Value;
            }

            ImageBuffer pixf = new ImageBuffer();

            switch (widgetsSubImage.BitDepth)
            {
            case 24:
                pixf.Attach(widgetsSubImage, new BlenderBGR());
                break;

            case 32:
                pixf.Attach(widgetsSubImage, new BlenderBGRA());
                break;

            default:
                throw new NotImplementedException();
            }

            ImageClippingProxy clippingProxy = new ImageClippingProxy(pixf);

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

            if (m_trans_type.SelectedIndex < 2)
            {
                // For the affine parallelogram transformations we
                // calculate the 4-th (implicit) point of the parallelogram
                m_quad.SetXN(3, m_quad.GetXN(0) + (m_quad.GetXN(2) - m_quad.GetXN(1)));
                m_quad.SetYN(3, m_quad.GetYN(0) + (m_quad.GetYN(2) - m_quad.GetYN(1)));
            }

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

            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();

                        g_rasterizer.add_path(rect);
                        scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(.2, .2, .2));
                    }
                }
            }

            //--------------------------
            // Render the "quad" tool and controls
            g_rasterizer.add_path(m_quad);
            scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0, 0.3, 0.5, 0.1));

            // Prepare the polygon to rasterize. Here we need to fill
            // the destination (transformed) polygon.
            g_rasterizer.SetVectorClipBox(0, 0, Width, Height);
            g_rasterizer.reset();
            int b = 0;

            g_rasterizer.move_to_d(m_quad.GetXN(0) - b, m_quad.GetYN(0) - b);
            g_rasterizer.line_to_d(m_quad.GetXN(1) + b, m_quad.GetYN(1) - b);
            g_rasterizer.line_to_d(m_quad.GetXN(2) + b, m_quad.GetYN(2) + b);
            g_rasterizer.line_to_d(m_quad.GetXN(3) - b, m_quad.GetYN(3) + b);

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

            ImageBufferAccessorClamp source = new ImageBufferAccessorClamp(m_SourceImage);

            stopwatch.Restart();

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

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

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

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

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

                span_interpolator_persp_lerp interpolator   = new span_interpolator_persp_lerp(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                span_subdiv_adaptor          subdiv_adaptor = new span_subdiv_adaptor(interpolator);

                span_image_resample sg = null;
                if (interpolator.is_valid())
                {
                    switch (source.SourceImage.BitDepth)
                    {
                    case 24:
                        sg = new span_image_resample_rgb(source, subdiv_adaptor, filter);
                        break;

                    case 32:
                        sg = new span_image_resample_rgba(source, subdiv_adaptor, filter);
                        break;
                    }

                    sg.blur(m_blur.Value);
                    scanlineRenderer.GenerateAndRender(g_rasterizer, g_scanline, clippingProxy, sa, sg);
                }
                break;
            }

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

            double tm = stopwatch.ElapsedMilliseconds;
            //pixf.apply_gamma_inv(m_gamma_lut);

            gsv_text t = new gsv_text();

            t.SetFontSize(10.0);

            Stroke pt = new Stroke(t);

            pt.Width = 1.5;

            string buf = string.Format("{0:F2} ms", tm);

            t.start_point(10.0, 70.0);
            t.text(buf);

            g_rasterizer.add_path(pt);
            scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0, 0, 0));

            //--------------------------
            //m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy);
            //m_gamma.Render(g_rasterizer, g_scanline, clippingProxy);
            //m_blur.Render(g_rasterizer, g_scanline, clippingProxy);
            base.OnDraw(graphics2D);
        }
Example #20
0
		private void GenerateAndRenderSingleScanline(IScanlineCache scanLineCache, IImageFloat destImageFloat, span_allocator alloc, ISpanGeneratorFloat span_gen)
		{
			int y = scanLineCache.y();
			int num_spans = scanLineCache.num_spans();
			ScanlineSpan scanlineSpan = scanLineCache.begin();

			byte[] ManagedCoversArray = scanLineCache.GetCovers();
			for (; ; )
			{
				int x = scanlineSpan.x;
				int len = scanlineSpan.len;
				if (len < 0) len = -len;

				if (tempSpanColorsFloats.Capacity() < len)
				{
					tempSpanColorsFloats.Capacity(len);
				}

				span_gen.generate(tempSpanColorsFloats.Array, 0, x, y, len);
				bool useFirstCoverForAll = scanlineSpan.len < 0;
				destImageFloat.blend_color_hspan(x, y, len, tempSpanColorsFloats.Array, 0, ManagedCoversArray, scanlineSpan.cover_index, useFirstCoverForAll);

				if (--num_spans == 0) break;
				scanlineSpan = scanLineCache.GetNextScanlineSpan();
			}
		}