From 1cafc03a468ca2c34b89dead9158ab1ac57527fd Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 1 Feb 2012 17:49:28 -0800 Subject: [PATCH] whitespace fixes --- include/mapnik/grid/grid.hpp | 74 +- include/mapnik/grid/grid_pixel.hpp | 232 +++--- include/mapnik/grid/grid_pixfmt.hpp | 1036 ++++++++++++------------- include/mapnik/grid/grid_renderer.hpp | 10 +- include/mapnik/grid/grid_util.hpp | 8 +- include/mapnik/grid/grid_view.hpp | 42 +- 6 files changed, 701 insertions(+), 701 deletions(-) diff --git a/include/mapnik/grid/grid.hpp b/include/mapnik/grid/grid.hpp index 69df36d62..bb8efec49 100644 --- a/include/mapnik/grid/grid.hpp +++ b/include/mapnik/grid/grid.hpp @@ -56,7 +56,7 @@ public: typedef std::map feature_key_type; typedef std::map key_type; typedef std::map feature_type; - + private: unsigned width_; unsigned height_; @@ -68,36 +68,36 @@ private: unsigned int resolution_; std::string id_name_; bool painted_; - + public: hit_grid(int width, int height, std::string const& key, unsigned int resolution) :width_(width), - height_(height), - key_(key), - data_(width,height), - resolution_(resolution), - id_name_("__id__"), - painted_(false) - { - // this only works if each datasource's - // feature count starts at 1 - f_keys_[0] = ""; - } - + height_(height), + key_(key), + data_(width,height), + resolution_(resolution), + id_name_("__id__"), + painted_(false) + { + // this only works if each datasource's + // feature count starts at 1 + f_keys_[0] = ""; + } + hit_grid(const hit_grid& rhs) :width_(rhs.width_), - height_(rhs.height_), - key_(rhs.key_), - data_(rhs.data_), - resolution_(rhs.resolution_), - id_name_("__id__"), - painted_(rhs.painted_) - { - f_keys_[0] = ""; - } - + height_(rhs.height_), + key_(rhs.key_), + data_(rhs.data_), + resolution_(rhs.resolution_), + id_name_("__id__"), + painted_(rhs.painted_) + { + f_keys_[0] = ""; + } + ~hit_grid() {} inline void painted(bool painted) @@ -117,7 +117,7 @@ public: inline void add_feature(mapnik::feature_ptr const& feature) { - + // NOTE: currently lookup keys must be strings, // but this should be revisited boost::optional lookup_value; @@ -136,7 +136,7 @@ public: else { std::clog << "should not get here: key '" << key_ << "' not found in feature properties\n"; - } + } } if (lookup_value) @@ -154,12 +154,12 @@ public: { std::clog << "### Warning: key '" << key_ << "' was blank for " << *feature << "\n"; } - } - + } + inline void add_property_name(std::string const& name) { names_.insert(name); - } + } inline std::set const& property_names() const { @@ -205,12 +205,12 @@ public: { resolution_ = res; } - + inline const data_type& data() const { return data_; } - + inline data_type& data() { return data_; @@ -230,11 +230,11 @@ public: { return data_.getRow(row); } - + inline mapnik::grid_view get_view(unsigned x, unsigned y, unsigned w, unsigned h) { return mapnik::grid_view(x,y,w,h, - data_,key_,id_name_,resolution_,names_,f_keys_,features_); + data_,key_,id_name_,resolution_,names_,f_keys_,features_); } private: @@ -245,7 +245,7 @@ private: } hit_grid& operator=(const hit_grid&); - + public: inline void setPixel(int x,int y,value_type feature_id) { @@ -278,7 +278,7 @@ public: unsigned a = (int)((rgba1 & 0xff) * opacity) & 0xff; // adjust for desired opacity #else unsigned a = (int)(((rgba1 >> 24) & 0xff) * opacity) & 0xff; // adjust for desired opacity -#endif +#endif // if the pixel is more than a tenth // opaque then burn in the feature id if (a >= 25) @@ -287,7 +287,7 @@ public: } } } - + inline void set_rectangle(value_type id,image_data_32 const& data,int x0,int y0) { box2d ext0(0,0,width_,height_); @@ -308,7 +308,7 @@ public: unsigned a = rgba & 0xff; #else unsigned a = (rgba >> 24) & 0xff; -#endif +#endif // if the pixel is more than a tenth // opaque then burn in the feature id if (a >= 25) diff --git a/include/mapnik/grid/grid_pixel.hpp b/include/mapnik/grid/grid_pixel.hpp index a0bbfc59d..451fad349 100644 --- a/include/mapnik/grid/grid_pixel.hpp +++ b/include/mapnik/grid/grid_pixel.hpp @@ -28,142 +28,142 @@ namespace mapnik { - //==================================================================gray16 - struct gray16 +//==================================================================gray16 +struct gray16 +{ + typedef agg::int16u value_type; + typedef agg::int32u calc_type; + typedef agg::int64 long_type; + enum base_scale_e { - typedef agg::int16u value_type; - typedef agg::int32u calc_type; - typedef agg::int64 long_type; - enum base_scale_e + base_shift = 16, + base_scale = 1 << base_shift, + base_mask = base_scale - 1 + }; + typedef gray16 self_type; + + value_type v; + value_type a; + + //-------------------------------------------------------------------- + gray16() {} + + //-------------------------------------------------------------------- + gray16(unsigned v_, unsigned a_=base_mask) : + v(agg::int16u(v_)), a(agg::int16u(a_)) {} + + //-------------------------------------------------------------------- + gray16(const self_type& c, unsigned a_) : + v(c.v), a(value_type(a_)) {} + + //-------------------------------------------------------------------- + void clear() + { + v = a = 0; + } + + //-------------------------------------------------------------------- + const self_type& transparent() + { + a = 0; + return *this; + } + + //-------------------------------------------------------------------- + void opacity(double a_) + { + if(a_ < 0.0) a_ = 0.0; + if(a_ > 1.0) a_ = 1.0; + a = (value_type)agg::uround(a_ * double(base_mask)); + } + + //-------------------------------------------------------------------- + double opacity() const + { + return double(a) / double(base_mask); + } + + + //-------------------------------------------------------------------- + const self_type& premultiply() + { + if(a == base_mask) return *this; + if(a == 0) { - base_shift = 16, - base_scale = 1 << base_shift, - base_mask = base_scale - 1 - }; - typedef gray16 self_type; + v = 0; + return *this; + } + v = value_type((calc_type(v) * a) >> base_shift); + return *this; + } - value_type v; - value_type a; - - //-------------------------------------------------------------------- - gray16() {} - - //-------------------------------------------------------------------- - gray16(unsigned v_, unsigned a_=base_mask) : - v(agg::int16u(v_)), a(agg::int16u(a_)) {} - - //-------------------------------------------------------------------- - gray16(const self_type& c, unsigned a_) : - v(c.v), a(value_type(a_)) {} - - //-------------------------------------------------------------------- - void clear() + //-------------------------------------------------------------------- + const self_type& premultiply(unsigned a_) + { + if(a == base_mask && a_ >= base_mask) return *this; + if(a == 0 || a_ == 0) { v = a = 0; - } - - //-------------------------------------------------------------------- - const self_type& transparent() - { - a = 0; return *this; } + calc_type v_ = (calc_type(v) * a_) / a; + v = value_type((v_ > a_) ? a_ : v_); + a = value_type(a_); + return *this; + } - //-------------------------------------------------------------------- - void opacity(double a_) + //-------------------------------------------------------------------- + const self_type& demultiply() + { + if(a == base_mask) return *this; + if(a == 0) { - if(a_ < 0.0) a_ = 0.0; - if(a_ > 1.0) a_ = 1.0; - a = (value_type)agg::uround(a_ * double(base_mask)); - } - - //-------------------------------------------------------------------- - double opacity() const - { - return double(a) / double(base_mask); - } - - - //-------------------------------------------------------------------- - const self_type& premultiply() - { - if(a == base_mask) return *this; - if(a == 0) - { - v = 0; - return *this; - } - v = value_type((calc_type(v) * a) >> base_shift); + v = 0; return *this; } + calc_type v_ = (calc_type(v) * base_mask) / a; + v = value_type((v_ > base_mask) ? base_mask : v_); + return *this; + } - //-------------------------------------------------------------------- - const self_type& premultiply(unsigned a_) + //-------------------------------------------------------------------- + self_type gradient(self_type c, double k) const + { + self_type ret; + calc_type ik = agg::uround(k * base_scale); + ret.v = value_type(calc_type(v) + (((calc_type(c.v) - v) * ik) >> base_shift)); + ret.a = value_type(calc_type(a) + (((calc_type(c.a) - a) * ik) >> base_shift)); + return ret; + } + + //-------------------------------------------------------------------- + AGG_INLINE void add(const self_type& c, unsigned cover) + { + calc_type cv, ca; + if(cover == agg::cover_mask) { - if(a == base_mask && a_ >= base_mask) return *this; - if(a == 0 || a_ == 0) + if(c.a == base_mask) { - v = a = 0; - return *this; - } - calc_type v_ = (calc_type(v) * a_) / a; - v = value_type((v_ > a_) ? a_ : v_); - a = value_type(a_); - return *this; - } - - //-------------------------------------------------------------------- - const self_type& demultiply() - { - if(a == base_mask) return *this; - if(a == 0) - { - v = 0; - return *this; - } - calc_type v_ = (calc_type(v) * base_mask) / a; - v = value_type((v_ > base_mask) ? base_mask : v_); - return *this; - } - - //-------------------------------------------------------------------- - self_type gradient(self_type c, double k) const - { - self_type ret; - calc_type ik = agg::uround(k * base_scale); - ret.v = value_type(calc_type(v) + (((calc_type(c.v) - v) * ik) >> base_shift)); - ret.a = value_type(calc_type(a) + (((calc_type(c.a) - a) * ik) >> base_shift)); - return ret; - } - - //-------------------------------------------------------------------- - AGG_INLINE void add(const self_type& c, unsigned cover) - { - calc_type cv, ca; - if(cover == agg::cover_mask) - { - if(c.a == base_mask) - { - *this = c; - } - else - { - cv = v + c.v; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv; - ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca; - } + *this = c; } else { - cv = v + ((c.v * cover + agg::cover_mask/2) >> agg::cover_shift); - ca = a + ((c.a * cover + agg::cover_mask/2) >> agg::cover_shift); - v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv; - a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca; + cv = v + c.v; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv; + ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca; } } + else + { + cv = v + ((c.v * cover + agg::cover_mask/2) >> agg::cover_shift); + ca = a + ((c.a * cover + agg::cover_mask/2) >> agg::cover_shift); + v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv; + a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca; + } + } - //-------------------------------------------------------------------- - static self_type no_color() { return self_type(0,0); } - }; + //-------------------------------------------------------------------- + static self_type no_color() { return self_type(0,0); } +}; } diff --git a/include/mapnik/grid/grid_pixfmt.hpp b/include/mapnik/grid/grid_pixfmt.hpp index 7ae058479..53f73a19f 100644 --- a/include/mapnik/grid/grid_pixfmt.hpp +++ b/include/mapnik/grid/grid_pixfmt.hpp @@ -30,610 +30,610 @@ namespace mapnik { - - //============================================================blender_gray - template struct blender_gray - { - typedef ColorT color_type; - typedef typename color_type::value_type value_type; - typedef typename color_type::calc_type calc_type; - enum base_scale_e { base_shift = color_type::base_shift }; - static AGG_INLINE void blend_pix(value_type* p, unsigned cv, - unsigned alpha, unsigned cover=0) - { - *p = (value_type)((((cv - calc_type(*p)) * alpha) + (calc_type(*p) << base_shift)) >> base_shift); - } +//============================================================blender_gray +template struct blender_gray +{ + typedef ColorT color_type; + typedef typename color_type::value_type value_type; + typedef typename color_type::calc_type calc_type; + enum base_scale_e { base_shift = color_type::base_shift }; + + static AGG_INLINE void blend_pix(value_type* p, unsigned cv, + unsigned alpha, unsigned cover=0) + { + *p = (value_type)((((cv - calc_type(*p)) * alpha) + (calc_type(*p) << base_shift)) >> base_shift); + } +}; + + + +//=====================================================apply_gamma_dir_gray +template class apply_gamma_dir_gray +{ +public: + typedef typename ColorT::value_type value_type; + + apply_gamma_dir_gray(const GammaLut& gamma) : m_gamma(gamma) {} + + AGG_INLINE void operator () (value_type* p) + { + *p = m_gamma.dir(*p); + } + +private: + const GammaLut& m_gamma; +}; + + + +//=====================================================apply_gamma_inv_gray +template class apply_gamma_inv_gray +{ +public: + typedef typename ColorT::value_type value_type; + + apply_gamma_inv_gray(const GammaLut& gamma) : m_gamma(gamma) {} + + AGG_INLINE void operator () (value_type* p) + { + *p = m_gamma.inv(*p); + } + +private: + const GammaLut& m_gamma; +}; + + + +//=================================================pixfmt_alpha_blend_gray +template +class pixfmt_alpha_blend_gray +{ +public: + typedef RenBuf rbuf_type; + typedef typename rbuf_type::row_data row_data; + typedef Blender blender_type; + typedef typename blender_type::color_type color_type; + typedef int order_type; // A fake one + typedef typename color_type::value_type value_type; + typedef typename color_type::calc_type calc_type; + enum base_scale_e + { + base_shift = color_type::base_shift, + base_scale = color_type::base_scale, + base_mask = color_type::base_mask, + pix_width = sizeof(value_type), + pix_step = Step, + pix_offset = Offset }; - - - //=====================================================apply_gamma_dir_gray - template class apply_gamma_dir_gray +private: + //-------------------------------------------------------------------- + static AGG_INLINE void copy_or_blend_pix(value_type* p, + const color_type& c, + unsigned cover) { - public: - typedef typename ColorT::value_type value_type; - - apply_gamma_dir_gray(const GammaLut& gamma) : m_gamma(gamma) {} - - AGG_INLINE void operator () (value_type* p) + if (c.a) { - *p = m_gamma.dir(*p); - } - - private: - const GammaLut& m_gamma; - }; - - - - //=====================================================apply_gamma_inv_gray - template class apply_gamma_inv_gray - { - public: - typedef typename ColorT::value_type value_type; - - apply_gamma_inv_gray(const GammaLut& gamma) : m_gamma(gamma) {} - - AGG_INLINE void operator () (value_type* p) - { - *p = m_gamma.inv(*p); - } - - private: - const GammaLut& m_gamma; - }; - - - - //=================================================pixfmt_alpha_blend_gray - template - class pixfmt_alpha_blend_gray - { - public: - typedef RenBuf rbuf_type; - typedef typename rbuf_type::row_data row_data; - typedef Blender blender_type; - typedef typename blender_type::color_type color_type; - typedef int order_type; // A fake one - typedef typename color_type::value_type value_type; - typedef typename color_type::calc_type calc_type; - enum base_scale_e - { - base_shift = color_type::base_shift, - base_scale = color_type::base_scale, - base_mask = color_type::base_mask, - pix_width = sizeof(value_type), - pix_step = Step, - pix_offset = Offset - }; - - private: - //-------------------------------------------------------------------- - static AGG_INLINE void copy_or_blend_pix(value_type* p, - const color_type& c, - unsigned cover) - { - if (c.a) + calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8; + if(alpha == base_mask) { - calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8; - if(alpha == base_mask) - { - *p = c.v; - } - else - { - Blender::blend_pix(p, c.v, alpha, cover); - } - } - } - - - static AGG_INLINE void copy_or_blend_pix(value_type* p, - const color_type& c) - { - if (c.a) - { - if(c.a == base_mask) - { - *p = c.v; - } - else - { - Blender::blend_pix(p, c.v, c.a); - } - } - } - - - public: - //-------------------------------------------------------------------- - explicit pixfmt_alpha_blend_gray(rbuf_type& rb) : - m_rbuf(&rb) - {} - void attach(rbuf_type& rb) { m_rbuf = &rb; } - //-------------------------------------------------------------------- - - template - bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2) - { - agg::rect_i r(x1, y1, x2, y2); - if(r.clip(agg::rect_i(0, 0, pixf.width()-1, pixf.height()-1))) - { - int stride = pixf.stride(); - m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1), - (r.x2 - r.x1) + 1, - (r.y2 - r.y1) + 1, - stride); - return true; - } - return false; - } - - //-------------------------------------------------------------------- - AGG_INLINE unsigned width() const { return m_rbuf->width(); } - AGG_INLINE unsigned height() const { return m_rbuf->height(); } - AGG_INLINE int stride() const { return m_rbuf->stride(); } - - //-------------------------------------------------------------------- - agg::int8u* row_ptr(int y) { return m_rbuf->row_ptr(y); } - const agg::int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); } - row_data row(int y) const { return m_rbuf->row(y); } - - const agg::int8u* pix_ptr(int x, int y) const - { - return m_rbuf->row_ptr(y) + x * Step + Offset; - } - - agg::int8u* pix_ptr(int x, int y) - { - return m_rbuf->row_ptr(y) + x * Step + Offset; - } - - //-------------------------------------------------------------------- - AGG_INLINE static void make_pix(agg::int8u* p, const color_type& c) - { - *(value_type*)p = c.v; - } - - //-------------------------------------------------------------------- - AGG_INLINE color_type pixel(int x, int y) const - { - value_type* p = (value_type*)m_rbuf->row_ptr(y) + x * Step + Offset; - return color_type(*p); - } - - //-------------------------------------------------------------------- - AGG_INLINE void copy_pixel(int x, int y, const color_type& c) - { - *((value_type*)m_rbuf->row_ptr(x, y, 1) + x * Step + Offset) = c.v; - } - - //-------------------------------------------------------------------- - AGG_INLINE void blend_pixel(int x, int y, const color_type& c, agg::int8u cover) - { - copy_or_blend_pix((value_type*) - m_rbuf->row_ptr(x, y, 1) + x * Step + Offset, - c, - cover); - } - - - //-------------------------------------------------------------------- - AGG_INLINE void copy_hline(int x, int y, - unsigned len, - const color_type& c) - { - value_type* p = (value_type*) - m_rbuf->row_ptr(x, y, len) + x * Step + Offset; - - do - { - *p = c.v; - p += Step; - } - while(--len); - } - - - //-------------------------------------------------------------------- - AGG_INLINE void copy_vline(int x, int y, - unsigned len, - const color_type& c) - { - do - { - value_type* p = (value_type*) - m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; - *p = c.v; } - while(--len); - } - - - //-------------------------------------------------------------------- - void blend_hline(int x, int y, - unsigned len, - const color_type& c, - agg::int8u cover) - { - if (c.a) + else { - value_type* p = (value_type*) - m_rbuf->row_ptr(x, y, len) + x * Step + Offset; - - calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8; - if(alpha == base_mask) - { - do - { - *p = c.v; - p += Step; - } - while(--len); - } - else - { - do - { - Blender::blend_pix(p, c.v, alpha, cover); - p += Step; - } - while(--len); - } + Blender::blend_pix(p, c.v, alpha, cover); } } + } - //-------------------------------------------------------------------- - void blend_vline(int x, int y, - unsigned len, - const color_type& c, - agg::int8u cover) + static AGG_INLINE void copy_or_blend_pix(value_type* p, + const color_type& c) + { + if (c.a) { - if (c.a) + if(c.a == base_mask) { - value_type* p; - calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8; - if(alpha == base_mask) - { - do - { - p = (value_type*) - m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; - - *p = c.v; - } - while(--len); - } - else - { - do - { - p = (value_type*) - m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; - - Blender::blend_pix(p, c.v, alpha, cover); - } - while(--len); - } + *p = c.v; + } + else + { + Blender::blend_pix(p, c.v, c.a); } } + } - //-------------------------------------------------------------------- - void blend_solid_hspan(int x, int y, - unsigned len, - const color_type& c, - const agg::int8u* covers) +public: + //-------------------------------------------------------------------- + explicit pixfmt_alpha_blend_gray(rbuf_type& rb) : + m_rbuf(&rb) + {} + void attach(rbuf_type& rb) { m_rbuf = &rb; } + //-------------------------------------------------------------------- + + template + bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2) + { + agg::rect_i r(x1, y1, x2, y2); + if(r.clip(agg::rect_i(0, 0, pixf.width()-1, pixf.height()-1))) { - if (c.a) - { - value_type* p = (value_type*) - m_rbuf->row_ptr(x, y, len) + x * Step + Offset; - - do - { - calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8; - if(alpha == base_mask) - { - *p = c.v; - } - else - { - Blender::blend_pix(p, c.v, alpha, *covers); - } - p += Step; - ++covers; - } - while(--len); - } + int stride = pixf.stride(); + m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1), + (r.x2 - r.x1) + 1, + (r.y2 - r.y1) + 1, + stride); + return true; } + return false; + } + + //-------------------------------------------------------------------- + AGG_INLINE unsigned width() const { return m_rbuf->width(); } + AGG_INLINE unsigned height() const { return m_rbuf->height(); } + AGG_INLINE int stride() const { return m_rbuf->stride(); } + + //-------------------------------------------------------------------- + agg::int8u* row_ptr(int y) { return m_rbuf->row_ptr(y); } + const agg::int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); } + row_data row(int y) const { return m_rbuf->row(y); } + + const agg::int8u* pix_ptr(int x, int y) const + { + return m_rbuf->row_ptr(y) + x * Step + Offset; + } + + agg::int8u* pix_ptr(int x, int y) + { + return m_rbuf->row_ptr(y) + x * Step + Offset; + } + + //-------------------------------------------------------------------- + AGG_INLINE static void make_pix(agg::int8u* p, const color_type& c) + { + *(value_type*)p = c.v; + } + + //-------------------------------------------------------------------- + AGG_INLINE color_type pixel(int x, int y) const + { + value_type* p = (value_type*)m_rbuf->row_ptr(y) + x * Step + Offset; + return color_type(*p); + } + + //-------------------------------------------------------------------- + AGG_INLINE void copy_pixel(int x, int y, const color_type& c) + { + *((value_type*)m_rbuf->row_ptr(x, y, 1) + x * Step + Offset) = c.v; + } + + //-------------------------------------------------------------------- + AGG_INLINE void blend_pixel(int x, int y, const color_type& c, agg::int8u cover) + { + copy_or_blend_pix((value_type*) + m_rbuf->row_ptr(x, y, 1) + x * Step + Offset, + c, + cover); + } - //-------------------------------------------------------------------- - void blend_solid_vspan(int x, int y, - unsigned len, - const color_type& c, - const agg::int8u* covers) + //-------------------------------------------------------------------- + AGG_INLINE void copy_hline(int x, int y, + unsigned len, + const color_type& c) + { + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y, len) + x * Step + Offset; + + do { - if (c.a) - { - do - { - calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8; - - value_type* p = (value_type*) - m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; - - if(alpha == base_mask) - { - *p = c.v; - } - else - { - Blender::blend_pix(p, c.v, alpha, *covers); - } - ++covers; - } - while(--len); - } + *p = c.v; + p += Step; } + while(--len); + } - //-------------------------------------------------------------------- - void copy_color_hspan(int x, int y, - unsigned len, - const color_type* colors) + //-------------------------------------------------------------------- + AGG_INLINE void copy_vline(int x, int y, + unsigned len, + const color_type& c) + { + do + { + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; + + *p = c.v; + } + while(--len); + } + + + //-------------------------------------------------------------------- + void blend_hline(int x, int y, + unsigned len, + const color_type& c, + agg::int8u cover) + { + if (c.a) { value_type* p = (value_type*) m_rbuf->row_ptr(x, y, len) + x * Step + Offset; - do + calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8; + if(alpha == base_mask) { - *p = colors->v; - p += Step; - ++colors; - } - while(--len); - } - - - //-------------------------------------------------------------------- - void copy_color_vspan(int x, int y, - unsigned len, - const color_type* colors) - { - do - { - value_type* p = (value_type*) - m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; - *p = colors->v; - ++colors; - } - while(--len); - } - - - //-------------------------------------------------------------------- - void blend_color_hspan(int x, int y, - unsigned len, - const color_type* colors, - const agg::int8u* covers, - agg::int8u cover) - { - value_type* p = (value_type*) - m_rbuf->row_ptr(x, y, len) + x * Step + Offset; - - if(covers) - { - do + do { - copy_or_blend_pix(p, *colors++, *covers++); + *p = c.v; p += Step; } while(--len); } else { - if(cover == 255) + do { - do - { - if(colors->a == base_mask) - { - *p = colors->v; - } - else - { - copy_or_blend_pix(p, *colors); - } - p += Step; - ++colors; - } - while(--len); - } - else - { - do - { - copy_or_blend_pix(p, *colors++, cover); - p += Step; - } - while(--len); + Blender::blend_pix(p, c.v, alpha, cover); + p += Step; } + while(--len); } } + } - - //-------------------------------------------------------------------- - void blend_color_vspan(int x, int y, - unsigned len, - const color_type* colors, - const agg::int8u* covers, - agg::int8u cover) + //-------------------------------------------------------------------- + void blend_vline(int x, int y, + unsigned len, + const color_type& c, + agg::int8u cover) + { + if (c.a) { value_type* p; - if(covers) + calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8; + if(alpha == base_mask) { - do + do { p = (value_type*) m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; - copy_or_blend_pix(p, *colors++, *covers++); + *p = c.v; } while(--len); } else { - if(cover == 255) + do { - do - { - p = (value_type*) - m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; + p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; - if(colors->a == base_mask) - { - *p = colors->v; - } - else - { - copy_or_blend_pix(p, *colors); - } - ++colors; - } - while(--len); + Blender::blend_pix(p, c.v, alpha, cover); + } + while(--len); + } + } + } + + + //-------------------------------------------------------------------- + void blend_solid_hspan(int x, int y, + unsigned len, + const color_type& c, + const agg::int8u* covers) + { + if (c.a) + { + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y, len) + x * Step + Offset; + + do + { + calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8; + if(alpha == base_mask) + { + *p = c.v; } else { - do - { - p = (value_type*) - m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; - - copy_or_blend_pix(p, *colors++, cover); - } - while(--len); + Blender::blend_pix(p, c.v, alpha, *covers); } + p += Step; + ++covers; } + while(--len); } + } - //-------------------------------------------------------------------- - template void for_each_pixel(Function f) + + //-------------------------------------------------------------------- + void blend_solid_vspan(int x, int y, + unsigned len, + const color_type& c, + const agg::int8u* covers) + { + if (c.a) { - unsigned y; - for(y = 0; y < height(); ++y) + do { - row_data r = m_rbuf->row(y); - if(r.ptr) + calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8; + + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; + + if(alpha == base_mask) { - unsigned len = r.x2 - r.x1 + 1; - - value_type* p = (value_type*) - m_rbuf->row_ptr(r.x1, y, len) + r.x1 * Step + Offset; - - do - { - f(p); - p += Step; - } - while(--len); + *p = c.v; } - } - } - - //-------------------------------------------------------------------- - template void apply_gamma_dir(const GammaLut& g) - { - for_each_pixel(apply_gamma_dir_gray(g)); - } - - //-------------------------------------------------------------------- - template void apply_gamma_inv(const GammaLut& g) - { - for_each_pixel(apply_gamma_inv_gray(g)); - } - - //-------------------------------------------------------------------- - template - void copy_from(const RenBuf2& from, - int xdst, int ydst, - int xsrc, int ysrc, - unsigned len) - { - const agg::int8u* p = from.row_ptr(ysrc); - if(p) - { - memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width, - p + xsrc * pix_width, - len * pix_width); - } - } - - //-------------------------------------------------------------------- - template - void blend_from_color(const SrcPixelFormatRenderer& from, - const color_type& color, - int xdst, int ydst, - int xsrc, int ysrc, - unsigned len, - agg::int8u cover) - { - typedef typename SrcPixelFormatRenderer::value_type src_value_type; - const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc); - if(psrc) - { - value_type* pdst = - (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst; - do + else { - copy_or_blend_pix(pdst, - color, - (*psrc * cover + base_mask) >> base_shift); - ++psrc; - ++pdst; + Blender::blend_pix(p, c.v, alpha, *covers); + } + ++covers; + } + while(--len); + } + } + + + //-------------------------------------------------------------------- + void copy_color_hspan(int x, int y, + unsigned len, + const color_type* colors) + { + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y, len) + x * Step + Offset; + + do + { + *p = colors->v; + p += Step; + ++colors; + } + while(--len); + } + + + //-------------------------------------------------------------------- + void copy_color_vspan(int x, int y, + unsigned len, + const color_type* colors) + { + do + { + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; + *p = colors->v; + ++colors; + } + while(--len); + } + + + //-------------------------------------------------------------------- + void blend_color_hspan(int x, int y, + unsigned len, + const color_type* colors, + const agg::int8u* covers, + agg::int8u cover) + { + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y, len) + x * Step + Offset; + + if(covers) + { + do + { + copy_or_blend_pix(p, *colors++, *covers++); + p += Step; + } + while(--len); + } + else + { + if(cover == 255) + { + do + { + if(colors->a == base_mask) + { + *p = colors->v; + } + else + { + copy_or_blend_pix(p, *colors); + } + p += Step; + ++colors; + } + while(--len); + } + else + { + do + { + copy_or_blend_pix(p, *colors++, cover); + p += Step; } while(--len); } } + } - //-------------------------------------------------------------------- - template - void blend_from_lut(const SrcPixelFormatRenderer& from, - const color_type* color_lut, - int xdst, int ydst, - int xsrc, int ysrc, - unsigned len, - agg::int8u cover) + + + //-------------------------------------------------------------------- + void blend_color_vspan(int x, int y, + unsigned len, + const color_type* colors, + const agg::int8u* covers, + agg::int8u cover) + { + value_type* p; + if(covers) { - typedef typename SrcPixelFormatRenderer::value_type src_value_type; - const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc); - if(psrc) + do { - value_type* pdst = - (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst; - do + p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; + + copy_or_blend_pix(p, *colors++, *covers++); + } + while(--len); + } + else + { + if(cover == 255) + { + do { - copy_or_blend_pix(pdst, color_lut[*psrc], cover); - ++psrc; - ++pdst; + p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; + + if(colors->a == base_mask) + { + *p = colors->v; + } + else + { + copy_or_blend_pix(p, *colors); + } + ++colors; + } + while(--len); + } + else + { + do + { + p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; + + copy_or_blend_pix(p, *colors++, cover); } while(--len); } } + } - private: - rbuf_type* m_rbuf; - }; + //-------------------------------------------------------------------- + template void for_each_pixel(Function f) + { + unsigned y; + for(y = 0; y < height(); ++y) + { + row_data r = m_rbuf->row(y); + if(r.ptr) + { + unsigned len = r.x2 - r.x1 + 1; - typedef blender_gray blender_gray16; + value_type* p = (value_type*) + m_rbuf->row_ptr(r.x1, y, len) + r.x1 * Step + Offset; - typedef pixfmt_alpha_blend_gray pixfmt_gray16; //----pixfmt_gray16 + do + { + f(p); + p += Step; + } + while(--len); + } + } + } + + //-------------------------------------------------------------------- + template void apply_gamma_dir(const GammaLut& g) + { + for_each_pixel(apply_gamma_dir_gray(g)); + } + + //-------------------------------------------------------------------- + template void apply_gamma_inv(const GammaLut& g) + { + for_each_pixel(apply_gamma_inv_gray(g)); + } + + //-------------------------------------------------------------------- + template + void copy_from(const RenBuf2& from, + int xdst, int ydst, + int xsrc, int ysrc, + unsigned len) + { + const agg::int8u* p = from.row_ptr(ysrc); + if(p) + { + memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width, + p + xsrc * pix_width, + len * pix_width); + } + } + + //-------------------------------------------------------------------- + template + void blend_from_color(const SrcPixelFormatRenderer& from, + const color_type& color, + int xdst, int ydst, + int xsrc, int ysrc, + unsigned len, + agg::int8u cover) + { + typedef typename SrcPixelFormatRenderer::value_type src_value_type; + const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc); + if(psrc) + { + value_type* pdst = + (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst; + do + { + copy_or_blend_pix(pdst, + color, + (*psrc * cover + base_mask) >> base_shift); + ++psrc; + ++pdst; + } + while(--len); + } + } + + //-------------------------------------------------------------------- + template + void blend_from_lut(const SrcPixelFormatRenderer& from, + const color_type* color_lut, + int xdst, int ydst, + int xsrc, int ysrc, + unsigned len, + agg::int8u cover) + { + typedef typename SrcPixelFormatRenderer::value_type src_value_type; + const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc); + if(psrc) + { + value_type* pdst = + (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst; + do + { + copy_or_blend_pix(pdst, color_lut[*psrc], cover); + ++psrc; + ++pdst; + } + while(--len); + } + } + +private: + rbuf_type* m_rbuf; +}; + +typedef blender_gray blender_gray16; + +typedef pixfmt_alpha_blend_gray pixfmt_gray16; //----pixfmt_gray16 } #endif diff --git a/include/mapnik/grid/grid_renderer.hpp b/include/mapnik/grid/grid_renderer.hpp index 77e529d6d..3061e2452 100644 --- a/include/mapnik/grid/grid_renderer.hpp +++ b/include/mapnik/grid/grid_renderer.hpp @@ -1,5 +1,5 @@ /***************************************************************************** - * + * * This file is part of Mapnik (c++ mapping toolkit) * * Copyright (C) 2011 Artem Pavlenko @@ -45,20 +45,20 @@ // apps using mapnik do not // need agg headers namespace agg { - struct trans_affine; +struct trans_affine; } namespace mapnik { class marker; - + struct grid_rasterizer; - + template class MAPNIK_DECL grid_renderer : public feature_style_processor >, private boost::noncopyable { - + public: grid_renderer(Map const& m, T & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0); ~grid_renderer(); diff --git a/include/mapnik/grid/grid_util.hpp b/include/mapnik/grid/grid_util.hpp index 2ea1220df..517c4ccc1 100644 --- a/include/mapnik/grid/grid_util.hpp +++ b/include/mapnik/grid/grid_util.hpp @@ -1,5 +1,5 @@ /***************************************************************************** - * + * * This file is part of Mapnik (c++ mapping toolkit) * * Copyright (C) 2011 Artem Pavlenko @@ -33,8 +33,8 @@ namespace mapnik { */ static inline void scale_grid(mapnik::grid::data_type & target, - const mapnik::grid::data_type & source, - double x_off_f, double y_off_f) + const mapnik::grid::data_type & source, + double x_off_f, double y_off_f) { int source_width=source.width(); @@ -93,7 +93,7 @@ static inline void scale_grid(mapnik::grid::data_type & target, mapnik::grid::value_type b = source(xs1,ys); mapnik::grid::value_type c = source(xs,ys1); mapnik::grid::value_type d = source(xs1,ys1); - + if ((a > 0) && (b > 0)) target(x,y) = b; else if ((c > 0) && (d > 0)) diff --git a/include/mapnik/grid/grid_view.hpp b/include/mapnik/grid/grid_view.hpp index 904ab8fcb..41b5de147 100644 --- a/include/mapnik/grid/grid_view.hpp +++ b/include/mapnik/grid/grid_view.hpp @@ -1,5 +1,5 @@ /***************************************************************************** - * + * * This file is part of Mapnik (c++ mapping toolkit) * * Copyright (C) 2011 Artem Pavlenko @@ -44,7 +44,7 @@ namespace mapnik { - + template class hit_grid_view { @@ -56,17 +56,17 @@ public: typedef std::map feature_key_type; typedef std::map key_type; typedef std::map feature_type; - - hit_grid_view(unsigned x, unsigned y, - unsigned width, unsigned height, - T const& data, - std::string const& key, - std::string const& id_name, - unsigned resolution, - std::set const& names, - feature_key_type const& f_keys, - feature_type const& features - ) + + hit_grid_view(unsigned x, unsigned y, + unsigned width, unsigned height, + T const& data, + std::string const& key, + std::string const& id_name, + unsigned resolution, + std::set const& names, + feature_key_type const& f_keys, + feature_type const& features + ) : x_(x), y_(y), width_(width), @@ -78,16 +78,16 @@ public: names_(names), f_keys_(f_keys), features_(features) - + { if (x_ >= data_.width()) x_=data_.width()-1; if (y_ >= data_.height()) x_=data_.height()-1; if (x_ + width_ > data_.width()) width_= data_.width() - x_; if (y_ + height_ > data_.height()) height_= data_.height() - y_; } - + ~hit_grid_view() {} - + hit_grid_view(hit_grid_view const& rhs) : x_(rhs.x_), y_(rhs.y_), @@ -100,8 +100,8 @@ public: names_(rhs.names_), f_keys_(rhs.f_keys_), features_(rhs.features_) - {} - + {} + hit_grid_view & operator=(hit_grid_view const& rhs) { if (&rhs==this) return *this; @@ -117,7 +117,7 @@ public: f_keys_ = rhs.f_keys_; features_ = rhs.features_; } - + inline unsigned x() const { return x_; @@ -127,7 +127,7 @@ public: { return y_; } - + inline unsigned width() const { return width_; @@ -142,7 +142,7 @@ public: { return id_name_; } - + inline const value_type* getRow(unsigned row) const { return data_.getRow(row + y_) + x_;