author | Francesco Abbate <francesco.bbt@gmail.com> | 2012年07月10日 16:57:05 +0200 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2012年07月10日 16:57:05 +0200 |
commit | d36ada7c9b87ce0f2f7e98fe5b1a756f875ec2c1 (patch) | |
tree | 38dd7a92a5dd25f047c7f0773be335ac419d9704 /agg-plot/canvas.h | |
parent | 7615c4d622a7cc07216b72e0e95abc9911afe936 (diff) | |
download | gsl-shell-d36ada7c9b87ce0f2f7e98fe5b1a756f875ec2c1.tar.gz |
-rw-r--r-- | agg-plot/canvas.h | 194 |
diff --git a/agg-plot/canvas.h b/agg-plot/canvas.h index 536efe38..cc27f722 100644 --- a/agg-plot/canvas.h +++ b/agg-plot/canvas.h @@ -17,91 +17,144 @@ #include "agg_conv_stroke.h" template <class Pixel> -class canvas_gen : private Pixel { - - enum { subpixel_scale = 3 }; - - typedef agg::renderer_base<typename Pixel::pixfmt_type> renderer_base; - typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid; - - renderer_base rb; - renderer_solid rs; - - agg::renderer_base<typename Pixel::pixfmt_lcd_type> rb_subpixel; - agg::renderer_scanline_aa_solid<agg::renderer_base<typename Pixel::pixfmt_lcd_type> > rs_subpixel; - - agg::rasterizer_scanline_aa<> ras; - agg::scanline_u8 sl; - - agg::rgba bg_color; - - double m_width; - double m_height; - +class renderer_gray_aa +{ public: - canvas_gen(agg::rendering_buffer& ren_buf, double width, double height, - agg::rgba bgcol): - Pixel(ren_buf), rb(Pixel::pixfmt), rs(rb), - rb_subpixel(Pixel::pixfmt_lcd), rs_subpixel(rb_subpixel), - ras(), sl(), bg_color(bgcol), - m_width(width), m_height(height) - { - }; - - double width() const { return m_width; }; - double height() const { return m_height; }; + renderer_gray_aa(agg::rendering_buffer& ren_buf, agg::rgba bg_color): + m_pixbuf(ren_buf), m_ren_base(m_pixbuf), m_ren_solid(m_ren_base), + m_bgcol(bg_color) + { } + + typedef Pixel pixfmt_type; + + agg::renderer_base<Pixel>& renderer_base() { return m_ren_base; } + + double width() const { return m_pixbuf.width(); }; + double height() const { return m_pixbuf.height(); }; + + template <class Rasterizer, class VertexSource> + static void add_path(Rasterizer& ras, VertexSource& vs) + { + ras.add_path(vs); + } + + void color(agg::rgba8 c) { m_ren_solid.color(c); } + + void clear(agg::rgba c) { m_ren_base.clear(c); } + + void clear_box(const agg::rect_base<int>& r) + { + unsigned len = r.x2 - r.x1; + for (int y = r.y1; y < r.y2; y++) + m_ren_base.copy_hline (r.x1, y, len, m_bgcol); + } + + void clip_box(const agg::rect_base<int>& clip) + { + m_ren_base.clip_box_naked(clip.x1, clip.y1, clip.x2, clip.y2); + } + + void reset_clipping() { m_ren_base.reset_clipping(true); } + + template <class Rasterizer, class Scanline> + void render_scanlines(Rasterizer& ras, Scanline& sl) + { + agg::render_scanlines(ras, sl, m_ren_solid); + } +private: + Pixel m_pixbuf; + agg::renderer_base<Pixel> m_ren_base; + agg::renderer_scanline_aa_solid<agg::renderer_base<Pixel> > m_ren_solid; + agg::rgba m_bgcol; +}; - void clear() { rb.clear(bg_color); }; +class renderer_subpixel_aa +{ + enum { subpixel_scale = 3 }; +public: + renderer_subpixel_aa(agg::rendering_buffer& ren_buf, agg::rgba bg_color): + m_pixbuf(ren_buf), m_ren_base(m_pixbuf), m_ren_solid(m_ren_base), + m_bgcol(bg_color) + { } + + typedef pixel_gamma_lcd pixfmt_type; + + agg::renderer_base<pixfmt_type>& renderer_base() { return m_ren_base; } + + double width() const { return m_pixbuf.width() / subpixel_scale; }; + double height() const { return m_pixbuf.height(); }; + + void clear(agg::rgba c) { m_ren_base.clear(c); } + + void clear_box(const agg::rect_base<int>& r) + { + unsigned len = subpixel_scale * (r.x2 - r.x1); + for (int y = r.y1; y < r.y2; y++) + m_ren_base.copy_hline (subpixel_scale * r.x1, y, len, m_bgcol); + } + + void clip_box(const agg::rect_base<int>& clip) + { + int x1 = subpixel_scale * clip.x1, x2 = subpixel_scale * clip.x2; + m_ren_base.clip_box_naked(x1, clip.y1, x2, clip.y2); + } + + void reset_clipping() { m_ren_base.reset_clipping(true); } + + template <class Rasterizer, class VertexSource> + static void add_path(Rasterizer& ras, VertexSource& vs) + { + agg::trans_affine_scaling subpixel_mtx(double(subpixel_scale), 1.0); + agg::conv_transform<VertexSource> scaled_vs(vs, subpixel_mtx); + ras.add_path(scaled_vs); + } + + void color(agg::rgba8 c) { m_ren_solid.color(c); } + + template <class Rasterizer, class Scanline> + void render_scanlines(Rasterizer& ras, Scanline& sl) + { + agg::render_scanlines(ras, sl, m_ren_solid); + } + +private: + pixfmt_type m_pixbuf; + agg::renderer_base<pixfmt_type> m_ren_base; + agg::renderer_scanline_aa_solid<agg::renderer_base<pixfmt_type> > m_ren_solid; + agg::rgba m_bgcol; +}; - void clear_box(const agg::rect_base<int>& r) - { - for (int y = r.y1; y < r.y2; y++) - this->rb.copy_hline (r.x1, y, r.x2, bg_color); - }; +template <class Renderer> +class canvas_gen : public Renderer { - void clip_box(const agg::rect_base<int>& clip) - { - this->rb.clip_box_naked(clip.x1, clip.y1, clip.x2, clip.y2); - }; + typedef typename Renderer::pixfmt_type pixfmt_type; - void reset_clipping() { this->rb.reset_clipping(true); }; + enum { line_width = 120 }; - template <class VertexSource> - void draw_solid(VertexSource& vs, agg::rgba8 c) - { - this->ras.add_path(vs); - this->rs.color(c); - agg::render_scanlines(this->ras, this->sl, this->rs); - } + agg::rasterizer_scanline_aa<> ras; + agg::scanline_u8 sl; - template <class VertexSource> - void draw_solid_subpixel(VertexSource& vs, agg::rgba8 c) - { - agg::trans_affine_scaling subpixel_mtx(double(subpixel_scale), 1.0); - agg::conv_transform<VertexSource> trans(vs, subpixel_mtx); - this->ras.add_path(trans); - this->rs_subpixel.color(c); - agg::render_scanlines(this->ras, this->sl, this->rs_subpixel); - } +public: + canvas_gen(agg::rendering_buffer& ren_buf, double width, double height, + agg::rgba bgcol): + Renderer(ren_buf, bgcol), ras(), sl() + { } void draw(sg_object& vs, agg::rgba8 c) { - if (vs.use_subpixel()) - draw_solid_subpixel(vs, c); - else - draw_solid(vs, c); + this->add_path(this->ras, vs); + this->color(c); + this->render_scanlines(this->ras, this->sl); } void draw_outline(sg_object& vs, agg::rgba8 c) { agg::conv_stroke<sg_object> line(vs); - line.width(Pixel::line_width / 100.0); + line.width(line_width / 100.0); line.line_cap(agg::round_cap); - - if (vs.use_subpixel()) - draw_solid_subpixel(line, c); - else - draw_solid(line, c); + this->add_path(this->ras, line); + this->color(c); + this->render_scanlines(this->ras, this->sl); } }; @@ -115,6 +168,7 @@ struct virtual_canvas { virtual ~virtual_canvas() { } }; -typedef canvas_gen<pixel_type> canvas; +//typedef canvas_gen<renderer_gray_aa<pixel_type> > canvas; +typedef canvas_gen<renderer_subpixel_aa> canvas; #endif |