Esempio n. 1
0
        public override void OnInitialize()
        {
            T dx = width().Divide(2.0).Subtract(m_quad.xn(1).Subtract(m_quad.xn(0)).Divide(2.0));
            T dy = height().Divide(2.0).Subtract(m_quad.yn(2).Subtract(m_quad.yn(0)).Divide(2.0));

            m_quad.AddXN(0, dx);
            m_quad.AddYN(0, dy);
            m_quad.AddXN(1, dx);
            m_quad.AddYN(1, dy);
            m_quad.AddXN(2, dx);
            m_quad.AddYN(2, dy);
            m_quad.AddXN(3, dx);
            m_quad.AddYN(3, dy);

            base.OnInitialize();
        }
Esempio n. 2
0
        public override void OnDraw()
        {
            if (m_gamma.value().NotEqual(m_old_gamma))
            {
                m_gamma_lut.Gamma(m_gamma.value().ToDouble());
                load_img(0, "spheres");
                FormatRGB pixf_change_gamma = new FormatRGB(rbuf_img(0), new BlenderBGR());
                //pixf_change_gamma.apply_gamma_dir(m_gamma_lut);
                m_old_gamma = m_gamma.value();
            }

#if SourceDepth24
            pixfmt_alpha_blend_rgb pixf     = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr());
            pixfmt_alpha_blend_rgb pixf_pre = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr_pre());
#else
            FormatRGBA pixf     = new FormatRGBA(rbuf_window(), new BlenderBGRA());
            FormatRGBA pixf_pre = new FormatRGBA(rbuf_window(), new BlenderPreMultBGRA());
#endif
            FormatClippingProxy clippingProxy     = new FormatClippingProxy(pixf);
            FormatClippingProxy clippingProxy_pre = new FormatClippingProxy(pixf_pre);

            clippingProxy.Clear(new RGBA_Doubles(1, 1, 1));

            if (m_trans_type.cur_item() < 2)
            {
                // For the IAffineTransformMatrix<T> parallelogram transformations we
                // calculate the 4-th (implicit) point of the parallelogram
                m_quad.SetXN(3, m_quad.xn(0).Add(m_quad.xn(2).Subtract(m_quad.xn(1))));
                m_quad.SetYN(3, m_quad.yn(0).Add(m_quad.yn(2).Subtract(m_quad.yn(1))));
            }

            //--------------------------
            // Render the "quad" tool and controls
            g_rasterizer.AddPath(m_quad);
            Renderer <T> .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().ToDouble(), height().ToDouble());
            g_rasterizer.Reset();
            int b = 0;
            g_rasterizer.MoveToDbl(m_quad.xn(0).Subtract(b), m_quad.yn(0).Subtract(b));
            g_rasterizer.LineToDbl(m_quad.xn(1).Add(b), m_quad.yn(1).Subtract(b));
            g_rasterizer.LineToDbl(m_quad.xn(2).Add(b), m_quad.yn(2).Add(b));
            g_rasterizer.LineToDbl(m_quad.xn(3).Subtract(b), m_quad.yn(3).Add(b));

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

#if SourceDepth24
            pixfmt_alpha_blend_rgb pixf_img = new pixfmt_alpha_blend_rgb(rbuf_img(0), new blender_bgr());
#else
            FormatRGBA pixf_img = new FormatRGBA(rbuf_img(0), new BlenderBGRA());
#endif
            RasterBufferAccessorClamp source = new RasterBufferAccessorClamp(pixf_img);

            start_timer();

            switch (m_trans_type.cur_item())
            {
            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;

                SpanInterpolatorPerspLerp <T> interpolator   = new SpanInterpolatorPerspLerp <T>(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                SpanSubDivAdaptor <T>         subdiv_adaptor = new SpanSubDivAdaptor <T>(interpolator);

                if (interpolator.IsValid())
                {
#if SourceDepth24
                    span_image_resample_rgb sg = new span_image_resample_rgb(source, subdiv_adaptor, filter);
#else
                    span_image_resample_rgba <T> sg = new span_image_resample_rgba <T>(source, subdiv_adaptor, filter);
#endif
                    sg.Blur = m_blur.value().ToDouble();
                    Renderer <T> .GenerateAndRender(g_rasterizer, g_scanline, clippingProxy_pre, 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 = elapsed_time();
            //pixf.apply_gamma_inv(m_gamma_lut);

            GsvText <T> t = new GsvText <T>();
            t.SetFontSize(10.0);

            ConvStroke <T> pt = new ConvStroke <T>(t);
            pt.Width = M.New <T>(1.5);

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

            g_rasterizer.AddPath(pt);
            Renderer <T> .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();
        }