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 | |
parent | 7615c4d622a7cc07216b72e0e95abc9911afe936 (diff) | |
download | gsl-shell-d36ada7c9b87ce0f2f7e98fe5b1a756f875ec2c1.tar.gz |
-rw-r--r-- | agg-plot/agg_pixfmt_rgb24_lcd.h | 12 | ||||
-rw-r--r-- | agg-plot/canvas.h | 194 | ||||
-rw-r--r-- | agg-plot/pixel_fmt.h | 48 | ||||
-rw-r--r-- | agg-plot/sg_object.h | 3 | ||||
-rw-r--r-- | agg-plot/text.h | 2 |
diff --git a/agg-plot/agg_pixfmt_rgb24_lcd.h b/agg-plot/agg_pixfmt_rgb24_lcd.h index 16553fe6..d6e3c3ab 100644 --- a/agg-plot/agg_pixfmt_rgb24_lcd.h +++ b/agg-plot/agg_pixfmt_rgb24_lcd.h @@ -174,6 +174,18 @@ namespace agg const color_type& c, int8u cover)
{ }
+ void copy_hline(int x, int y, unsigned len, const color_type& c)
+ {
+ int xr = x / 3;
+ int8u* p = m_rbuf->row_ptr(x, y, len) + xr;
+ for (int ilen = len; ilen > 0; p += 3, ilen -= 3)
+ {
+ p[0] = c.r;
+ p[1] = c.g;
+ p[2] = c.b;
+ }
+ }
+
//--------------------------------------------------------------------
void blend_solid_hspan(int x, int y,
unsigned len,
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 diff --git a/agg-plot/pixel_fmt.h b/agg-plot/pixel_fmt.h index 635eb566..30b17d5d 100644 --- a/agg-plot/pixel_fmt.h +++ b/agg-plot/pixel_fmt.h @@ -5,39 +5,27 @@ #include "agg_pixfmt_rgb.h" -class pixel_gamma_corr { - typedef gslshell::gamma_type gamma_type; +typedef gslshell::gamma_type gamma_type; - gamma_type& m_gamma; - agg::lcd_distribution_lut& m_lut; -public: - typedef agg::pixfmt_rgb24_gamma<gamma_type> pixfmt_type; - typedef agg::pixfmt_rgb24_lcd_gamma<gamma_type> pixfmt_lcd_type; - - pixfmt_type pixfmt; - pixfmt_lcd_type pixfmt_lcd; - - pixel_gamma_corr(agg::rendering_buffer& ren_buf): - m_gamma(gslshell::gamma), m_lut(gslshell::subpixel_lut), - pixfmt(ren_buf, m_gamma), pixfmt_lcd(ren_buf, m_lut, m_gamma) - { }; - - enum { line_width = 120 }; +struct pixel_gamma : public agg::pixfmt_rgb24_gamma<gamma_type> +{ + pixel_gamma(agg::rendering_buffer& ren_buf): + agg::pixfmt_rgb24_gamma<gamma_type>(ren_buf, gslshell::gamma) + { } }; -class pixel_simple { - agg::lcd_distribution_lut& m_lut; - -public: - typedef agg::pixfmt_rgb24 pixfmt_type; - typedef agg::pixfmt_rgb24_lcd pixfmt_lcd_type; - - pixfmt_type pixfmt; - pixfmt_lcd_type pixfmt_lcd; +struct pixel_gamma_lcd : public agg::pixfmt_rgb24_lcd_gamma<gamma_type> +{ + pixel_gamma_lcd(agg::rendering_buffer& ren_buf): + agg::pixfmt_rgb24_lcd_gamma<gamma_type>(ren_buf, gslshell::subpixel_lut, gslshell::gamma) + { } +}; - pixel_simple(agg::rendering_buffer& ren_buf): - m_lut(gslshell::subpixel_lut), pixfmt(ren_buf), pixfmt_lcd(ren_buf, m_lut) - { }; +struct pixel_simple : public agg::pixfmt_rgb24 +{ + pixel_simple(agg::rendering_buffer& ren_buf): + agg::pixfmt_rgb24(ren_buf) + { } enum { line_width = 100 }; }; @@ -45,7 +33,7 @@ public: #ifdef DISABLE_GAMMA_CORR typedef pixel_simple pixel_type; #else -typedef pixel_gamma_corr pixel_type; +typedef pixel_gamma pixel_type; #endif #endif diff --git a/agg-plot/sg_object.h b/agg-plot/sg_object.h index e863e828..4b3b4b8d 100644 --- a/agg-plot/sg_object.h +++ b/agg-plot/sg_object.h @@ -45,7 +45,6 @@ struct sg_object : public vertex_source { virtual void apply_transform(const agg::trans_affine& m, double as) = 0; virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) = 0; - virtual bool use_subpixel() { return false; } virtual bool affine_compose(agg::trans_affine& m) { return false; } @@ -204,8 +203,6 @@ public: virtual bool affine_compose(agg::trans_affine& m) { return this->m_source->affine_compose(m); } - virtual bool use_subpixel() { return m_source->use_subpixel(); } - private: sg_object* m_source; }; diff --git a/agg-plot/text.h b/agg-plot/text.h index 7eada4a7..1186284e 100644 --- a/agg-plot/text.h +++ b/agg-plot/text.h @@ -72,8 +72,6 @@ class text : public sg_object virtual void bounding_box(double *x1, double *y1, double *x2, double *y2); virtual str write_svg(int id, agg::rgba8 c, double h); - - virtual bool use_subpixel() { return true; } }; } |