author | Francesco Abbate <francesco.bbt@gmail.com> | 2010年08月22日 22:43:37 +0200 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2010年08月22日 22:43:37 +0200 |
commit | 513a0fe79bb643ba53c64bee18f77f8127d348dd (patch) | |
tree | 00fa9dc46a2033acaa03ec81dac79b01be9639f4 /agg-plot/canvas.h | |
parent | bef124c9c9e081062a457f6d0b2ab1eda6283a3e (diff) | |
download | gsl-shell-513a0fe79bb643ba53c64bee18f77f8127d348dd.tar.gz |
-rw-r--r-- | agg-plot/canvas.h | 82 |
diff --git a/agg-plot/canvas.h b/agg-plot/canvas.h index f5304bec..c7ca3e6b 100644 --- a/agg-plot/canvas.h +++ b/agg-plot/canvas.h @@ -5,6 +5,7 @@ #include <stdlib.h> #include <limits.h> +#include "agg_basics.h" #include "agg_rendering_buffer.h" #include "agg_rasterizer_scanline_aa.h" #include "agg_pixfmt_rgb.h" @@ -14,28 +15,39 @@ #include "agg_rasterizer_outline_aa.h" #include "agg_renderer_outline_aa.h" -#ifdef ENABLE_GAMMA_CORR #include "agg_gamma_lut.h" -#endif -#include "utils.h" - -class canvas { -#ifdef ENABLE_GAMMA_CORR +class pixel_gamma_corr { typedef agg::gamma_lut<agg::int8u, agg::int16u, 8, 12> gamma_type; typedef agg::pixfmt_bgr24_gamma<gamma_type> pixel_fmt; -#else - typedef agg::pixfmt_bgr24 pixel_fmt; -#endif - typedef agg::renderer_base<pixel_fmt> renderer_base; + + gamma_type m_gamma; + +public: + typedef pixel_fmt fmt; + + pixel_gamma_corr(agg::rendering_buffer& ren_buf): + m_gamma(2.2), pixfmt(ren_buf, m_gamma) + { }; + + pixel_fmt pixfmt; +}; + +struct pixel_simple { + agg::pixfmt_bgr24 pixfmt; + + typedef agg::pixfmt_bgr24 fmt; + + pixel_simple(agg::rendering_buffer& ren_buf): pixfmt(ren_buf) { }; +}; + +template <class pixel, int linewidth> +class canvas_gen : private pixel { + typedef agg::renderer_base<typename pixel::fmt> renderer_base; typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid; typedef agg::renderer_outline_aa<renderer_base> renderer_oaa; typedef agg::rasterizer_outline_aa<renderer_oaa> rasterizer_outline_aa; -#ifdef ENABLE_GAMMA_CORR - gamma_type m_gamma; -#endif - pixel_fmt pixf; renderer_base rb; renderer_solid rs; @@ -52,49 +64,47 @@ class canvas { double m_height; public: - canvas(agg::rendering_buffer& ren_buf, double width, double height, - agg::rgba bgcol): -#ifdef ENABLE_GAMMA_CORR - m_gamma(2.2), pixf(ren_buf, m_gamma), rb(pixf), rs(rb), -#else - pixf(ren_buf), rb(pixf), rs(rb), -#endif - prof(), ren_oaa(rb, prof), ras_oaa(ren_oaa), + canvas_gen(agg::rendering_buffer& ren_buf, double width, double height, + agg::rgba bgcol): + pixel(ren_buf), rb(pixel::pixfmt), rs(rb), prof(), + ren_oaa(rb, prof), ras_oaa(ren_oaa), ras(), sl(), bg_color(bgcol), m_width(width), m_height(height) { -#ifdef ENABLE_GAMMA_CORR - prof.width(1.5); -#else - prof.width(1.0); -#endif + prof.width(linewidth / 10.0L); }; - double width() const { return m_width; }; + double width() const { return m_width; }; double height() const { return m_height; }; void clear() { rb.clear(bg_color); }; - void clear_box(int x1, int y1, int width, int height) + void clear_box(const agg::rect_base<int>& r) { - for (int y = y1; y < y1 + height; y++) - rb.copy_hline (x1, y, x1 + width, bg_color); + for (int y = r.y1; y < r.y2; y++) + this->rb.copy_hline (r.x1, y, r.x2, bg_color); }; template<class VertexSource> void draw(VertexSource& vs, agg::rgba8 c) { - ras.add_path(vs); - rs.color(c); - agg::render_scanlines(ras, sl, rs); + this->ras.add_path(vs); + this->rs.color(c); + agg::render_scanlines(this->ras, this->sl, this->rs); }; template<class VertexSource> void draw_outline(VertexSource& vs, agg::rgba8 c) { - ren_oaa.color(c); - ras_oaa.add_path(vs); + this->ren_oaa.color(c); + this->ras_oaa.add_path(vs); }; }; +#ifdef ENABLE_GAMMA_CORR +typedef canvas_gen<pixel_gamma_corr, 15> canvas; +#else +typedef canvas_gen<pixel_simple, 10> canvas; +#endif + #endif |