예제 #1
0
        public Bitmap(int width, int height, PixelFormat format)
        {
            IRecieveBlenderByte byteBlender;
            int bpp;

            switch (format)
            {
            case PixelFormat.Format32bppArgb:
                bpp         = 32;
                byteBlender = new BlenderBGRA();
                break;

            case PixelFormat.Format32bppRgb:
                bpp         = 32;
                byteBlender = new BlenderBGR();
                break;

            case PixelFormat.Format24bppRgb:
                bpp         = 24;
                byteBlender = new BlenderBGR();
                break;

            default:
                throw new NotImplementedException(String.Format("UG.Bitmap unsupported format {0}", format));
            }
            this.buffer = new ImageBuffer(width, height, bpp, byteBlender);
        }
예제 #2
0
        /// <summary>
        /// Download an image from the web into the specified ImageBuffer
        /// </summary>
        /// <param name="uri"></param>
        public void DownloadToImageAsync(ImageBuffer imageToLoadInto, string uriToLoad, bool scaleToImageX, IRecieveBlenderByte scalingBlender = null)
        {
            if (scalingBlender == null)
            {
                scalingBlender = new BlenderBGRA();
            }

            WebClient client = new WebClient();

            client.DownloadDataCompleted += (object sender, DownloadDataCompletedEventArgs e) =>
            {
                try                 // if we get a bad result we can get a target invocation exception. In that case just don't show anything
                {
                    // scale the loaded image to the size of the target image
                    byte[]      raw           = e.Result;
                    Stream      stream        = new MemoryStream(raw);
                    ImageBuffer unScaledImage = new ImageBuffer(10, 10);
                    if (scaleToImageX)
                    {
                        StaticData.Instance.LoadImageData(stream, unScaledImage);
                        // If the source image (the one we downloaded) is more than twice as big as our dest image.
                        while (unScaledImage.Width > imageToLoadInto.Width * 2)
                        {
                            // The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results.
                            // So we scale as many times as we need to to get the Image to be the right size.
                            // If this were going to be a non-uniform scale we could do the x and y separately to get better results.
                            ImageBuffer halfImage = new ImageBuffer(unScaledImage.Width / 2, unScaledImage.Height / 2, 32, scalingBlender);
                            halfImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, halfImage.Width / (double)unScaledImage.Width, halfImage.Height / (double)unScaledImage.Height);
                            unScaledImage = halfImage;
                        }

                        double finalScale = imageToLoadInto.Width / (double)unScaledImage.Width;
                        imageToLoadInto.Allocate(imageToLoadInto.Width, (int)(unScaledImage.Height * finalScale), imageToLoadInto.Width * (imageToLoadInto.BitDepth / 8), imageToLoadInto.BitDepth);
                        imageToLoadInto.NewGraphics2D().Render(unScaledImage, 0, 0, 0, finalScale, finalScale);
                    }
                    else
                    {
                        StaticData.Instance.LoadImageData(stream, imageToLoadInto);
                    }
                    imageToLoadInto.MarkImageChanged();
                }
                catch
                {
                }
            };

            try
            {
                client.DownloadDataAsync(new Uri(uriToLoad));
            }
            catch
            {
            }
        }
예제 #3
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            GammaLookUpTable    gamma         = new GammaLookUpTable(gammaSlider.Value);
            IRecieveBlenderByte NormalBlender = new BlenderBGRA();
            IRecieveBlenderByte GammaBlender  = new BlenderGammaBGRA(gamma);
            ImageBuffer         rasterGamma   = new ImageBuffer();

            rasterGamma.Attach(widgetsSubImage, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(widgetsSubImage);
            ImageClippingProxy clippingProxyGamma  = new ImageClippingProxy(rasterGamma);

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

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

            int size_mul = (int)pixelSizeSlider.Value;

            renderer_enlarged ren_en = new renderer_enlarged(size_mul);

            rasterizer.reset();
            rasterizer.move_to_d(m_x[0] / size_mul, m_y[0] / size_mul);
            rasterizer.line_to_d(m_x[1] / size_mul, m_y[1] / size_mul);
            rasterizer.line_to_d(m_x[2] / size_mul, m_y[2] / size_mul);
            ren_en.RenderSolid(clippingProxyGamma, rasterizer, sl, Color.Black);

            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.RenderSolid(clippingProxyGamma, rasterizer, sl, Color.Black);

            rasterizer.gamma(new gamma_none());

            VertexStorage ps = new VertexStorage();
            Stroke        pg = new Stroke(ps);

            pg.Width = 2;

            ps.remove_all();
            ps.MoveTo(m_x[0], m_y[0]);
            ps.LineTo(m_x[1], m_y[1]);
            ps.LineTo(m_x[2], m_y[2]);
            ps.LineTo(m_x[0], m_y[0]);
            rasterizer.add_path(pg);
            scanlineRenderer.RenderSolid(clippingProxyNormal, rasterizer, sl, new Color(0, 150, 160, 200));

            base.OnDraw(graphics2D);
        }
예제 #4
0
        private static void LoadImageInto(ImageBuffer imageToLoadInto, bool scaleToImageX, IRecieveBlenderByte scalingBlender, Stream stream)
        {
            if (scalingBlender == null)
            {
                scalingBlender = new BlenderBGRA();
            }

            ImageBuffer unScaledImage = new ImageBuffer(10, 10);

            if (scaleToImageX)
            {
                lock (locker)
                {
                    // scale the loaded image to the size of the target image
                    StaticData.Instance.LoadImageData(stream, unScaledImage);
                }

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

                double finalScale = imageToLoadInto.Width / (double)unScaledImage.Width;
                imageToLoadInto.Allocate(imageToLoadInto.Width, (int)(unScaledImage.Height * finalScale), imageToLoadInto.Width * (imageToLoadInto.BitDepth / 8), imageToLoadInto.BitDepth);
                imageToLoadInto.NewGraphics2D().Render(unScaledImage, 0, 0, 0, finalScale, finalScale);
            }
            else
            {
                StaticData.Instance.LoadImageData(stream, imageToLoadInto);
            }

            imageToLoadInto.MarkImageChanged();
        }
예제 #5
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            IImageByte backBuffer = widgetsSubImage;

            GammaLookUpTable    gamma         = new GammaLookUpTable(m_gamma.Value);
            IRecieveBlenderByte NormalBlender = new BlenderBGRA();
            IRecieveBlenderByte GammaBlender  = new BlenderGammaBGRA(gamma);
            ImageBuffer         rasterNormal  = new ImageBuffer();

            rasterNormal.Attach(backBuffer, NormalBlender);
            ImageBuffer rasterGamma = new ImageBuffer();

            rasterGamma.Attach(backBuffer, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy clippingProxyGamma  = new ImageClippingProxy(rasterGamma);

            clippingProxyNormal.clear(m_white_on_black.Checked ? new ColorF(0, 0, 0) : new ColorF(1, 1, 1));

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

            VertexSource.Ellipse e = new VertexSource.Ellipse();

            // TODO: If you drag the control circles below the bottom of the window we get an exception.  This does not happen in AGG.
            // It needs to be debugged.  Turning on clipping fixes it.  But standard agg works without clipping.  Could be a bigger problem than this.
            //ras.clip_box(0, 0, width(), height());

            // Render two "control" circles
            e.init(m_x[0], m_y[0], 3, 3, 16);
            ras.add_path(e);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.RenderSolid(clippingProxyNormal, ras, sl, new Color(127, 127, 127));
            e.init(m_x[1], m_y[1], 3, 3, 16);
            ras.add_path(e);
            scanlineRenderer.RenderSolid(clippingProxyNormal, ras, sl, new Color(127, 127, 127));

            double d = m_offset.Value;

            // Creating a rounded rectangle
            VertexSource.RoundedRect r = new VertexSource.RoundedRect(m_x[0] + d, m_y[0] + d, m_x[1] + d, m_y[1] + d, m_radius.Value);
            r.normalize_radius();

            // Drawing as an outline
            if (!m_DrawAsOutlineCheckBox.Checked)
            {
                Stroke p = new Stroke(r);
                p.width(1.0);
                ras.add_path(p);
            }
            else
            {
                ras.add_path(r);
            }

            scanlineRenderer.RenderSolid(clippingProxyGamma, ras, sl, m_white_on_black.Checked ? new Color(255, 255, 255) : new Color(0, 0, 0));

            base.OnDraw(graphics2D);
        }
예제 #6
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            GammaLookUpTable    gamma               = new GammaLookUpTable(m_gamma.Value);
            IRecieveBlenderByte NormalBlender       = new BlenderBGRA();
            IRecieveBlenderByte GammaBlender        = new BlenderGammaBGRA(gamma);
            ImageBuffer         rasterNormal        = new ImageBuffer(NewGraphics2D().DestImage, NormalBlender);
            ImageBuffer         rasterGamma         = new ImageBuffer(NewGraphics2D().DestImage, GammaBlender);
            ImageClippingProxy  clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy  clippingProxyGamma  = new ImageClippingProxy(rasterGamma);

            clippingProxyNormal.clear(new ColorF(0, 0, 0));

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

            VertexSource.Ellipse e = new VertexSource.Ellipse();

            // TODO: If you drag the control circles below the bottom of the window we get an exception.  This does not happen in AGG.
            // It needs to be debugged.  Turning on clipping fixes it.  But standard agg works without clipping.  Could be a bigger problem than this.
            //ras.clip_box(0, 0, width(), height());

            // Render two "control" circles
            e.init(m_x[0], m_y[0], 3, 3, 16);
            ras.add_path(e);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.RenderSolid(clippingProxyNormal, ras, sl, new Color(127, 127, 127));
            e.init(m_x[1], m_y[1], 3, 3, 16);
            ras.add_path(e);
            scanlineRenderer.RenderSolid(clippingProxyNormal, ras, sl, new Color(127, 127, 127));

            // Creating a rounded rectangle
            VertexSource.RoundedRect r = new VertexSource.RoundedRect(m_x[0], m_y[0], m_x[1], m_y[1], 10);
            r.normalize_radius();

            // Drawing as an outline
            Stroke p = new Stroke(r);

            p.width(1.0);
            ras.add_path(p);

            //Renderer.RenderSolid(clippingProxyGamma, ras, sl, new RGBA_Bytes(0, 0, 0));
            scanlineRenderer.RenderSolid(clippingProxyGamma, ras, sl, new Color(255, 1, 1));

            /*
             *              int i;
             *
             *              // radial line test
             *              //-------------------------
             *              dashed_line<rasterizer_type,
             *                                      renderer_scanline_type,
             *                                      scanline_type> dash(ras, ren_sl, sl);
             *
             *              double cx = width() / 2.0;
             *              double cy = height() / 2.0;
             *
             *              ren_sl.color(agg::rgba(1.0, 1.0, 1.0, 0.2));
             *              for(i = 180; i > 0; i--)
             *              {
             *                      double n = 2.0 * agg::pi * i / 180.0;
             *                      dash.draw(cx + min(cx, cy) * sin(n), cy + min(cx, cy) * cos(n),
             *                                        cx, cy,
             *                                        1.0, (i < 90) ? i : 0.0);
             *              }
             *
             *              typedef agg::gradient_x gradient_func_type;
             *              typedef agg::span_interpolator_linear<> interpolator_type;
             *              typedef agg::span_allocator<color_type> span_allocator_type;
             *              typedef agg::pod_auto_array<color_type, 256> color_array_type;
             *              typedef agg::span_gradient<color_type,
             *                                                                 interpolator_type,
             *                                                                 gradient_func_type,
             *                                                                 color_array_type> span_gradient_type;
             *
             *              typedef agg::renderer_scanline_aa<renderer_base_type,
             *                                                                                span_allocator_type,
             *                                                                                span_gradient_type> renderer_gradient_type;
             *
             *              gradient_func_type  gradient_func;                   // The gradient function
             *              agg::trans_affine   gradient_mtx;                    // Affine transformer
             *              interpolator_type   span_interpolator(gradient_mtx); // Span interpolator
             *              span_allocator_type span_allocator;                  // Span Allocator
             *              color_array_type    gradient_colors;                 // The gradient colors
             *              span_gradient_type  span_gradient(span_interpolator,
             *                                                                                gradient_func,
             *                                                                                gradient_colors,
             *                                                                                0, 100);
             *
             *              renderer_gradient_type ren_gradient(ren_base, span_allocator, span_gradient);
             *
             *              dashed_line<rasterizer_type,
             *                                      renderer_gradient_type,
             *                                      scanline_type> dash_gradient(ras, ren_gradient, sl);
             *
             *              double x1, y1, x2, y2;
             *
             *              for(i = 1; i <= 20; i++)
             *              {
             *                      ren_sl.color(agg::rgba(1,1,1));
             *
             *                      // integral point sizes 1..20
             *                      //----------------
             *                      agg::ellipse ell;
             *
             *                      ell.init(20 + i * (i + 1) + 0.5,
             *                                       20.5,
             *                                       i / 2.0,
             *                                       i / 2.0,
             *                                       8 + i);
             *                      ras.reset();
             *                      ras.add_path(ell);
             *                      agg::render_scanlines(ras, sl, ren_sl);
             *
             *                      // fractional point sizes 0..2
             *                      //----------------
             *                      ell.init(18 + i * 4 + 0.5, 33 + 0.5,
             *                                       i/20.0, i/20.0,
             *                                       8);
             *                      ras.reset();
             *                      ras.add_path(ell);
             *                      agg::render_scanlines(ras, sl, ren_sl);
             *
             *                      // fractional point positioning
             *                      //---------------
             *                      ell.init(18 + i * 4 + (i-1) / 10.0 + 0.5,
             *                                       27 + (i - 1) / 10.0 + 0.5,
             *                                       0.5, 0.5, 8);
             *                      ras.reset();
             *                      ras.add_path(ell);
             *                      agg::render_scanlines(ras, sl, ren_sl);
             *
             *                      // integral line widths 1..20
             *                      //----------------
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(1,1,1),
             *                                                       agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));
             *
             *                      x1 = 20 + i* (i + 1);
             *                      y1 = 40.5;
             *                      x2 = 20 + i * (i + 1) + (i - 1) * 4;
             *                      y2 = 100.5;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, i, 0);
             *
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(1,0,0),
             *                                                       agg::rgba(0,0,1));
             *
             *                      // fractional line lengths H (red/blue)
             *                      //----------------
             *                      x1 = 17.5 + i * 4;
             *                      y1 = 107;
             *                      x2 = 17.5 + i * 4 + i/6.66666667;
             *                      y2 = 107;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);
             *
             *                      // fractional line lengths V (red/blue)
             *                      //---------------
             *                      x1 = 18 + i * 4;
             *                      y1 = 112.5;
             *                      x2 = 18 + i * 4;
             *                      y2 = 112.5 + i / 6.66666667;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);
             *
             *                      // fractional line positioning (red)
             *                      //---------------
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(1,0,0),
             *                                                       agg::rgba(1,1,1));
             *                      x1 = 21.5;
             *                      y1 = 120 + (i - 1) * 3.1;
             *                      x2 = 52.5;
             *                      y2 = 120 + (i - 1) * 3.1;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);
             *
             *                      // fractional line width 2..0 (green)
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(0,1,0),
             *                                                       agg::rgba(1,1,1));
             *                      x1 = 52.5;
             *                      y1 = 118 + i * 3;
             *                      x2 = 83.5;
             *                      y2 = 118 + i * 3;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 0);
             *
             *                      // stippled fractional width 2..0 (blue)
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(0,0,1),
             *                                                       agg::rgba(1,1,1));
             *                      x1 = 83.5;
             *                      y1 = 119 + i * 3;
             *                      x2 = 114.5;
             *                      y2 = 119 + i * 3;
             *                      calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
             *                      dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 3.0);
             *
             *                      ren_sl.color(agg::rgba(1,1,1));
             *                      if(i <= 10)
             *                      {
             *                              // integral line width, horz aligned (mipmap test)
             *                              //-------------------
             *                              dash.draw(125.5, 119.5 + (i + 2) * (i / 2.0),
             *                                                135.5, 119.5 + (i + 2) * (i / 2.0),
             *                                                i, 0.0);
             *                      }
             *
             *                      // fractional line width 0..2, 1 px H
             *                      //-----------------
             *                      dash.draw(17.5 + i * 4, 192, 18.5 + i * 4, 192, i / 10.0, 0);
             *
             *                      // fractional line positioning, 1 px H
             *                      //-----------------
             *                      dash.draw(17.5 + i * 4 + (i - 1) / 10.0, 186,
             *                                        18.5 + i * 4 + (i - 1) / 10.0, 186,
             *                                        1.0, 0);
             *              }
             *
             *              // Triangles
             *              //---------------
             *              for (int i = 1; i <= 13; i++)
             *              {
             *                      fill_color_array(gradient_colors,
             *                                                       agg::rgba(1,1,1),
             *                                                       agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));
             *                      calc_linear_gradient_transform(width()  - 150,
             *                                                                                 height() - 20 - i * (i + 1.5),
             *                                                                                 width()  - 20,
             *                                                                                 height() - 20 - i * (i + 1),
             *                                                                                 gradient_mtx);
             *                      ras.reset();
             *                      ras.move_to_d(width() - 150, height() - 20 - i * (i + 1.5));
             *                      ras.line_to_d(width() - 20,  height() - 20 - i * (i + 1));
             *                      ras.line_to_d(width() - 20,  height() - 20 - i * (i + 2));
             *                      agg::render_scanlines(ras, sl, ren_gradient);
             *              }
             */

            base.OnDraw(graphics2D);
        }
예제 #7
0
        public override void OnDraw(RendererBase renderer)
        {
            GammaLookUpTable gamma = new GammaLookUpTable(m_gamma.value());
            IBlender NormalBlender = new BlenderBGRA();
            IBlender GammaBlender = new BlenderGammaBGRA(gamma);
            ImageBuffer rasterNormal = new ImageBuffer(NewRenderer().DestImage, NormalBlender);
            ImageBuffer rasterGamma = new ImageBuffer(NewRenderer().DestImage, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

            clippingProxyNormal.clear(new RGBA_Doubles(0,0,0));

            rasterizer_scanline_aa ras = new rasterizer_scanline_aa();
            scanline_packed_8 sl = new scanline_packed_8();

            VertexSource.Ellipse e = new VertexSource.Ellipse();

            // TODO: If you drag the control circles below the bottom of the window we get an exception.  This does not happen in AGG.
            // It needs to be debugged.  Turning on clipping fixes it.  But standard agg works without clipping.  Could be a bigger problem than this.
            //ras.clip_box(0, 0, width(), height());

            // Render two "control" circles
            e.init(m_x[0], m_y[0], 3, 3, 16);
            ras.add_path(e);
            Renderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));
            e.init(m_x[1], m_y[1], 3, 3, 16);
            ras.add_path(e);
            Renderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));

            // Creating a rounded rectangle
            VertexSource.RoundedRect r = new VertexSource.RoundedRect(m_x[0], m_y[0], m_x[1], m_y[1], 10);
            r.normalize_radius();

            // Drawing as an outline
                conv_stroke p = new conv_stroke(r);
                p.width(1.0);
                ras.add_path(p);

                //Renderer.RenderSolid(clippingProxyGamma, ras, sl, new RGBA_Bytes(0, 0, 0));
            Renderer.RenderSolid(clippingProxyGamma, ras, sl, new RGBA_Bytes(255, 1, 1));








            /*            
                    int i;

                    // radial line test
                    //-------------------------
                    dashed_line<rasterizer_type, 
                                renderer_scanline_type, 
                                scanline_type> dash(ras, ren_sl, sl);

                    double cx = width() / 2.0;
                    double cy = height() / 2.0;

                    ren_sl.color(agg::rgba(1.0, 1.0, 1.0, 0.2));
                    for(i = 180; i > 0; i--) 
                    {
                        double n = 2.0 * agg::pi * i / 180.0;
                        dash.draw(cx + min(cx, cy) * sin(n), cy + min(cx, cy) * cos(n),
                                  cx, cy, 
                                  1.0, (i < 90) ? i : 0.0);
                    }


                    typedef agg::gradient_x gradient_func_type;
                    typedef agg::span_interpolator_linear<> interpolator_type;
                    typedef agg::span_allocator<color_type> span_allocator_type;
                    typedef agg::pod_auto_array<color_type, 256> color_array_type;
                    typedef agg::span_gradient<color_type, 
                                               interpolator_type, 
                                               gradient_func_type, 
                                               color_array_type> span_gradient_type;

                    typedef agg::renderer_scanline_aa<renderer_base_type, 
                                                      span_allocator_type,
                                                      span_gradient_type> renderer_gradient_type;

                    gradient_func_type  gradient_func;                   // The gradient function
                    agg::trans_affine   gradient_mtx;                    // Affine transformer
                    interpolator_type   span_interpolator(gradient_mtx); // Span interpolator
                    span_allocator_type span_allocator;                  // Span Allocator
                    color_array_type    gradient_colors;                 // The gradient colors
                    span_gradient_type  span_gradient(span_interpolator, 
                                                      gradient_func, 
                                                      gradient_colors, 
                                                      0, 100);

                    renderer_gradient_type ren_gradient(ren_base, span_allocator, span_gradient);

                    dashed_line<rasterizer_type, 
                                renderer_gradient_type, 
                                scanline_type> dash_gradient(ras, ren_gradient, sl);

                    double x1, y1, x2, y2;

                    for(i = 1; i <= 20; i++)
                    {
                        ren_sl.color(agg::rgba(1,1,1));

                        // integral point sizes 1..20
                        //----------------
                        agg::ellipse ell;
            
                        ell.init(20 + i * (i + 1) + 0.5, 
                                 20.5, 
                                 i / 2.0, 
                                 i / 2.0, 
                                 8 + i);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);
            

                        // fractional point sizes 0..2
                        //----------------
                        ell.init(18 + i * 4 + 0.5, 33 + 0.5, 
                                 i/20.0, i/20.0, 
                                 8);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);


                        // fractional point positioning
                        //---------------
                        ell.init(18 + i * 4 + (i-1) / 10.0 + 0.5, 
                                 27 + (i - 1) / 10.0 + 0.5, 
                                 0.5, 0.5, 8);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);


                        // integral line widths 1..20
                        //----------------
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,1,1), 
                                         agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));

                        x1 = 20 + i* (i + 1);
                        y1 = 40.5;
                        x2 = 20 + i * (i + 1) + (i - 1) * 4;
                        y2 = 100.5;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, i, 0);


                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,0,0), 
                                         agg::rgba(0,0,1));

                        // fractional line lengths H (red/blue)
                        //----------------
                        x1 = 17.5 + i * 4;
                        y1 = 107;
                        x2 = 17.5 + i * 4 + i/6.66666667;
                        y2 = 107;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);


                        // fractional line lengths V (red/blue)
                        //---------------
                        x1 = 18 + i * 4;
                        y1 = 112.5;
                        x2 = 18 + i * 4;
                        y2 = 112.5 + i / 6.66666667;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);

                        // fractional line positioning (red)
                        //---------------
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,0,0), 
                                         agg::rgba(1,1,1));
                        x1 = 21.5;
                        y1 = 120 + (i - 1) * 3.1;
                        x2 = 52.5;
                        y2 = 120 + (i - 1) * 3.1;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);


                        // fractional line width 2..0 (green)
                        fill_color_array(gradient_colors, 
                                         agg::rgba(0,1,0), 
                                         agg::rgba(1,1,1));
                        x1 = 52.5;
                        y1 = 118 + i * 3;
                        x2 = 83.5;
                        y2 = 118 + i * 3;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 0);

                        // stippled fractional width 2..0 (blue)
                        fill_color_array(gradient_colors, 
                                         agg::rgba(0,0,1), 
                                         agg::rgba(1,1,1));
                        x1 = 83.5;
                        y1 = 119 + i * 3;
                        x2 = 114.5;
                        y2 = 119 + i * 3;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 3.0);


                        ren_sl.color(agg::rgba(1,1,1));
                        if(i <= 10)
                        {
                            // integral line width, horz aligned (mipmap test)
                            //-------------------
                            dash.draw(125.5, 119.5 + (i + 2) * (i / 2.0),
                                      135.5, 119.5 + (i + 2) * (i / 2.0),
                                      i, 0.0);
                        }

                        // fractional line width 0..2, 1 px H
                        //-----------------
                        dash.draw(17.5 + i * 4, 192, 18.5 + i * 4, 192, i / 10.0, 0);

                        // fractional line positioning, 1 px H
                        //-----------------
                        dash.draw(17.5 + i * 4 + (i - 1) / 10.0, 186, 
                                  18.5 + i * 4 + (i - 1) / 10.0, 186,
                                  1.0, 0);
                    }


                    // Triangles
                    //---------------
                    for (int i = 1; i <= 13; i++) 
                    {
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,1,1), 
                                         agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));
                        calc_linear_gradient_transform(width()  - 150, 
                                                       height() - 20 - i * (i + 1.5),
                                                       width()  - 20,  
                                                       height() - 20 - i * (i + 1),
                                                       gradient_mtx);
                        ras.reset();
                        ras.move_to_d(width() - 150, height() - 20 - i * (i + 1.5));
                        ras.line_to_d(width() - 20,  height() - 20 - i * (i + 1));
                        ras.line_to_d(width() - 20,  height() - 20 - i * (i + 2));
                        agg::render_scanlines(ras, sl, ren_gradient);
                    }
             */










            base.OnDraw(renderer);
        }
예제 #8
0
        public override void OnDraw()
        {
            GammaLut            gamma         = new GammaLut(m_gamma.value().ToDouble());
            IBlender            NormalBlender = new BlenderBGRA();
            IBlender            GammaBlender  = new BlenderGammaBGRA(gamma);
            FormatRGBA          pixf          = new FormatRGBA(rbuf_window(), NormalBlender);
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);

            clippingProxy.Clear(m_white_on_black.status() ? new RGBA_Doubles(0, 0, 0) : new RGBA_Doubles(1, 1, 1));

            RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>();
            ScanlinePacked8          sl  = new ScanlinePacked8();

            Ellipse <T> e = new Ellipse <T>();

            // TODO: If you drag the control circles below the bottom of the window we get an exception.  This does not happen in AGG.
            // It needs to be debugged.  Turning on clipping fixes it.  But standard agg works without clipping.  Could be a bigger problem than this.
            //ras.clip_box(0, 0, width(), height());

            // Render two "control" circles
            e.Init(m_x[0], m_y[0], M.New <T>(3), M.New <T>(3), 16);
            ras.AddPath(e);
            Renderer <T> .RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(127, 127, 127));

            e.Init(m_x[1], m_y[1], M.New <T>(3), M.New <T>(3), 16);
            ras.AddPath(e);
            Renderer <T> .RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(127, 127, 127));

            T d = m_offset.value();

            // Creating a rounded rectangle
            RoundedRect <T> r = new RoundedRect <T>(m_x[0].Add(d), m_y[0].Add(d), m_x[1].Add(d), m_y[1].Add(d), m_radius.value());

            r.NormalizeRadius();

            // Drawing as an outline
            if (!m_DrawAsOutlineCheckBox.status())
            {
                ConvStroke <T> p = new ConvStroke <T>(r);
                p.Width = M.One <T>();
                ras.AddPath(p);
            }
            else
            {
                ras.AddPath(r);
            }

            pixf.Blender = GammaBlender;
            Renderer <T> .RenderSolid(clippingProxy, ras, sl, m_white_on_black.status()?new RGBA_Bytes(1, 1, 1) : new RGBA_Bytes(0, 0, 0));

            // this was in the original demo, but it does nothing because we changed the blender not the gamma function.
            //ras.gamma(new gamma_none());
            // so let's change the blender instead
            pixf.Blender = NormalBlender;

            // Render the controls
            //m_radius.Render(ras, sl, clippingProxy);
            //m_gamma.Render(ras, sl, clippingProxy);
            //m_offset.Render(ras, sl, clippingProxy);
            //m_white_on_black.Render(ras, sl, clippingProxy);
            //m_DrawAsOutlineCheckBox.Render(ras, sl, clippingProxy);
            base.OnDraw();
        }