Exemplo n.º 1
0
        void transform_image(double angle)
        {
            double width  = rbuf_img(0).Width;
            double height = rbuf_img(0).Height;

#if SourceDepth24
            FormatRGB pixf     = new FormatRGB(rbuf_img(0), new BlenderBGR());
            FormatRGB pixf_pre = new FormatRGB(rbuf_img(0), new BlenderPreMultBGR());
#else
            pixfmt_alpha_blend_rgba32 pixf     = new pixfmt_alpha_blend_rgba32(rbuf_img(0), new blender_bgra32());
            pixfmt_alpha_blend_rgba32 pixf_pre = new pixfmt_alpha_blend_rgba32(rbuf_img(0), new blender_bgra_pre());
#endif
            FormatClippingProxy rb     = new FormatClippingProxy(pixf);
            FormatClippingProxy rb_pre = new FormatClippingProxy(pixf_pre);

            rb.Clear(new RGBA_Doubles(1.0, 1.0, 1.0));

            IAffineTransformMatrix <T> src_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            src_mtx.Translate(MatrixFactory <T> .CreateVector2D(-width / 2.0, -height / 2.0));
            src_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), angle * Math.PI / 180.0);
            src_mtx.Translate(MatrixFactory <T> .CreateVector2D(width / 2.0, height / 2.0));

            IAffineTransformMatrix <T> img_mtx = MatrixFactory <T> .CreateAffine(src_mtx);

            img_mtx = img_mtx.Inverse;

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

            r *= 0.5;
            r -= 4.0;
            VertexSource.Ellipse <T> ell = new AGG.VertexSource.Ellipse <T>(width / 2.0, height / 2.0, r, r, 200);
            ConvTransform <T>        tr  = new ConvTransform <T>(ell, src_mtx);

            m_num_pix += r * r * Math.PI;

            SpanInterpolatorLinear <T> interpolator = new SpanInterpolatorLinear <T>(img_mtx);

            ImageFilterLookUpTable <T> filter = new ImageFilterLookUpTable <T>();
            bool norm = m_normalize.status();

#if SourceDepth24
            FormatRGB pixf_img = new FormatRGB(rbuf_img(1), new BlenderBGR());
#else
            pixfmt_alpha_blend_rgba32 pixf_img = new pixfmt_alpha_blend_rgba32(rbuf_img(1), new blender_bgra32());
#endif
            RasterBufferAccessorClip source = new RasterBufferAccessorClip(pixf_img, RGBA_Doubles.RgbaPre(0, 0, 0, 0));

            switch (m_filters.cur_item())
            {
            case 0:
            {
#if SourceDepth24
                SpanImageFilterRgbNN <T> sg = new SpanImageFilterRgbNN <T>(source, interpolator);
#else
                span_image_filter_rgba_nn sg = new span_image_filter_rgba_nn(source, interpolator);
#endif
                m_Rasterizer.AddPath(tr);
                Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg);
            }
            break;

            case 1:
            {
#if SourceDepth24
                //span_image_filter_rgb_bilinear_clip sg = new span_image_filter_rgb_bilinear_clip(pixf_img, rgba.rgba_pre(0, 0.4, 0, 0.5), interpolator);
                SpanImageFilterRgbBilinear <T> sg = new SpanImageFilterRgbBilinear <T>(source, interpolator);
#else
                //span_image_filter_rgba_bilinear_clip sg = new span_image_filter_rgba_bilinear_clip(pixf_img, rgba.rgba_pre(0, 0, 0, 0), interpolator);
                span_image_filter_rgba_bilinear sg = new span_image_filter_rgba_bilinear(source, interpolator);
#endif
                m_Rasterizer.AddPath(tr);
                Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg);
            }
            break;

            case 5:
            case 6:
            case 7:
            {
                switch (m_filters.cur_item())
                {
                case 5: filter.Calculate(new ImageFilterHanning <T>(), norm); break;

                case 6: filter.Calculate(new ImageFilterHamming <T>(), norm); break;

                case 7: filter.Calculate(new ImageFilterHermite <T>(), norm); break;
                }

                SpanImageFilterRgb2x2 <T> sg = new SpanImageFilterRgb2x2 <T>(source, interpolator, filter);
                m_Rasterizer.AddPath(tr);
                Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg);
            }
            break;

            case 2:
            case 3:
            case 4:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            {
                switch (m_filters.cur_item())
                {
                case 2: filter.Calculate(new ImageFilterBicubic <T>(), norm); break;

                case 3: filter.Calculate(new ImageFilterSpline16 <T>(), norm); break;

                case 4: filter.Calculate(new ImageFilterSpline36 <T>(), norm); break;

                case 8: filter.Calculate(new ImageFilterKaiser <T>(), norm); break;

                case 9: filter.Calculate(new ImageFilterQuadric <T>(), norm); break;

                case 10: filter.Calculate(new ImageFilterCatrom <T>(), norm); break;

                case 11: filter.Calculate(new ImageFilterGaussian <T>(), norm); break;

                case 12: filter.Calculate(new ImageFilterBessel <T>(), norm); break;

                case 13: filter.Calculate(new ImageFilterMitchell <T>(), norm); break;

                case 14: filter.Calculate(new ImageFilterSinc <T>(m_radius.value()), norm); break;

                case 15: filter.Calculate(new ImageFilterLanczos <T>(m_radius.value()), norm); break;

                case 16:
                    filter.Calculate(new ImageFilterBlackman <T>(m_radius.value()), norm);
                    break;
                }

#if SourceDepth24
                SpanImageFilterRgb <T> sg = new SpanImageFilterRgb <T>(source, interpolator, filter);
#else
                span_image_filter_rgb sg = new span_image_filter_rgba(source, interpolator, filter);
#endif
                m_Rasterizer.AddPath(tr);
                Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg);
            }
            break;
            }
        }
Exemplo n.º 2
0
        public override void OnDraw()
        {
            //typedef agg::renderer_base<pixfmt>     renderer_base;
            //typedef agg::renderer_base<pixfmt_pre> renderer_base_pre;

#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.0, 1.0, 1.0));

            IAffineTransformMatrix <T> src_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            src_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Negative().Divide(2).Subtract(10), initial_height().Negative().Divide(2).Subtract(30)));
            src_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_angle.value().Multiply(Math.PI / 180.0).ToDouble());
            src_mtx.Scale(m_scale.value());
            src_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Divide(2), initial_height().Divide(2).Add(20)));
            src_mtx.Multiply(trans_affine_resizing());

            IAffineTransformMatrix <T> img_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            img_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Negative().Divide(2).Add(10), initial_height().Negative().Divide(2).Add(30)));
            img_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_angle.value().Multiply(Math.PI / 180.0).ToDouble());
            img_mtx.Scale(m_scale.value());
            img_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Divide(2), initial_height().Divide(2).Add(20)));
            img_mtx.Multiply(trans_affine_resizing());
            img_mtx = img_mtx.Inverse;

            AGG.SpanAllocator sa = new SpanAllocator();

            SpanInterpolatorLinear <T> interpolator = new SpanInterpolatorLinear <T>(img_mtx);

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

#if SourceDepth24
            span_image_filter_rgb_bilinear_clip sg;
            sg = new span_image_filter_rgb_bilinear_clip(img_pixf, rgba.rgba_pre(0, 0.4, 0, 0.5), interpolator);
#else
            SpanImageFilterRgbaBilinearClip <T> sg;
            RasterBufferAccessorClip            source = new RasterBufferAccessorClip(img_pixf, RGBA_Doubles.RgbaPre(0, 0, 0, 0));
            sg = new SpanImageFilterRgbaBilinearClip <T>(source, RGBA_Doubles.RgbaPre(0, 0.4, 0, 0.5), interpolator);
#endif

            RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>();
            ras.SetVectorClipBox(M.Zero <T>(), M.Zero <T>(), width(), height());
            //agg.scanline_packed_8 sl = new scanline_packed_8();
            ScanlineUnpacked8 sl = new ScanlineUnpacked8();

            T r = initial_width();
            if (initial_height().Subtract(60).LessThan(r))
            {
                r = initial_height().Subtract(60);
            }

            Ellipse <T> ell = new Ellipse <T>(initial_width().Divide(2.0).Add(10),
                                              initial_height().Divide(2.0).Add(30),
                                              r.Divide(2.0).Add(16.0),
                                              r.Divide(2.0).Add(16.0), 200);

            ConvTransform <T> tr = new ConvTransform <T>(ell, src_mtx);

            ras.AddPath(tr);
#if use_timers
            for (uint j = 0; j < 10; j++)
            {
                Renderer.GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg);
            }
            AllTimer.Start();
            image1_100_Times.Start();
            for (uint i = 0; i < 500; i++)
            {
#endif
            //clippingProxy_pre.SetClippingBox(30, 0, (int)width(), (int)height());
            //clippingProxy.SetClippingBox(30, 0, (int)width(), (int)height());
            Renderer <T> .GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg);

#if use_timers
        }

        image1_100_Times.Stop();
#endif

            //m_angle.SetTransform(trans_affine_resizing());
            //m_scale.SetTransform(trans_affine_resizing());
#if use_timers
            AllTimer.Stop();
            CExecutionTimer.Instance.AppendResultsToFile("TimingTest.txt", AllTimer.GetTotalSeconds());
            CExecutionTimer.Instance.Reset();
#endif
            base.OnDraw();
        }