Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
		}