diff --git a/agg/SConscript b/agg/SConscript index 94280424d..109130eab 100644 --- a/agg/SConscript +++ b/agg/SConscript @@ -25,5 +25,5 @@ agg_root = env['AGG_ROOT'] agg_headers = agg_root + '/include' agg_src_dir = agg_root + '/src/' agg_src = glob.glob(agg_src_dir + '*.cpp') -agg_lib = env.SharedLibrary('libagg',agg_src,LIBS=[],CPPPATH=agg_headers) +agg_lib = env.StaticLibrary('libagg',agg_src,LIBS=[],CPPPATH=agg_headers) env.Install(prefix+'/lib',agg_lib) diff --git a/include/graphics.hpp b/include/graphics.hpp index 3eb5c371f..212cb8d85 100644 --- a/include/graphics.hpp +++ b/include/graphics.hpp @@ -24,7 +24,7 @@ #include #include #include -#include "style.hpp" +#include "color.hpp" #include "gamma.hpp" #include "image_data.hpp" diff --git a/include/image_symbolizer.hpp b/include/image_symbolizer.hpp index 29526de96..6e3293629 100644 --- a/include/image_symbolizer.hpp +++ b/include/image_symbolizer.hpp @@ -22,7 +22,6 @@ #define IMAGE_SYMBOLIZER_HPP #include "symbolizer.hpp" -#include "image_data.hpp" #include namespace mapnik @@ -30,42 +29,15 @@ namespace mapnik struct image_symbolizer : public symbolizer, private boost::noncopyable { - private: - ImageData32 symbol_; - public: + image_symbolizer(std::string const& file, std::string const& type, - unsigned width,unsigned height) - : symbolizer(), - symbol_(width,height) - { - try - { - std::auto_ptr reader(get_image_reader(type,file)); - reader->read(0,0,symbol_); - } - catch (...) - { - std::cerr<<"exception caught..."< namespace mapnik -{ - class pattern_source : private boost::noncopyable - { - public: - pattern_source(ImageData32 const& pattern) - : pattern_(pattern) {} - - unsigned int width() const - { - return pattern_.width(); - } - unsigned int height() const - { - return pattern_.height(); - } - agg::rgba8 pixel(int x, int y) const - { - unsigned c = pattern_(x,y); - return agg::rgba8(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff,(c >> 24) & 0xff); - } - private: - ImageData32 const& pattern_; - }; - +{ struct line_pattern_symbolizer : public symbolizer, private boost::noncopyable { + line_pattern_symbolizer(std::string const& file, + std::string const& type, + unsigned width,unsigned height); + void render(geometry_type& geom,Image32& image) const; + private: ImageData32 pattern_; - public: - line_pattern_symbolizer(std::string const& file, - std::string const& type, - unsigned width,unsigned height) - : symbolizer(), - pattern_(width,height) - { - try - { - std::auto_ptr reader(get_image_reader(type,file)); - reader->read(0,0,pattern_); - } - catch (...) - { - std::cerr<<"exception caught..."< pattern_type; - typedef agg::renderer_base renderer_base; - typedef agg::renderer_outline_image renderer_type; - typedef agg::rasterizer_outline_aa rasterizer_type; - unsigned int width=image.width(); - unsigned int height=image.height(); - agg::row_ptr_cache buf(image.raw_data(), width, height,width*4); - agg::pixfmt_rgba32 pixf(buf); - renderer_base ren_base(pixf); - agg::pattern_filter_bilinear_rgba8 filter; - pattern_source source(pattern_); - pattern_type pattern (filter,source); - renderer_type ren(ren_base, pattern); - ren.clip_box(0,0,width,height); - rasterizer_type ras(ren); - ras.add_path(geom); - } }; } diff --git a/include/line_symbolizer.hpp b/include/line_symbolizer.hpp index 1571c7ca7..de8cf8cd5 100644 --- a/include/line_symbolizer.hpp +++ b/include/line_symbolizer.hpp @@ -21,27 +21,6 @@ #ifndef LINE_SYMBOLIZER_HPP #define LINE_SYMBOLIZER_HPP -#include "agg_basics.h" -#include "agg_rendering_buffer.h" -#include "agg_rasterizer_scanline_aa.h" -#include "agg_conv_stroke.h" -#include "agg_conv_dash.h" -#include "agg_conv_contour.h" -#include "agg_vcgen_stroke.h" -#include "agg_conv_adaptor_vcgen.h" -#include "agg_conv_smooth_poly1.h" -#include "agg_conv_marker.h" -#include "agg_arrowhead.h" -#include "agg_vcgen_markers_term.h" -#include "agg_scanline_p.h" -#include "agg_scanline_u.h" -#include "agg_renderer_scanline.h" -#include "agg_pixfmt_rgba.h" -#include "agg_path_storage.h" -#include "agg_renderer_outline_aa.h" -#include "agg_rasterizer_outline_aa.h" -#include "agg_rasterizer_outline.h" -#include "agg_renderer_outline_image.h" #include "symbolizer.hpp" #include "stroke.hpp" @@ -53,124 +32,11 @@ namespace mapnik struct line_symbolizer : public symbolizer, private boost::noncopyable { + line_symbolizer(stroke const& stroke); + line_symbolizer(const Color& pen,float width=1.0); + void render(geometry_type& geom, Image32& image) const; private: stroke stroke_; - public: - - line_symbolizer(stroke const& stroke) - : symbolizer(), - stroke_(stroke) {} - - line_symbolizer(const Color& pen,float width=1.0) - : symbolizer(), - stroke_(pen,width) {} - - void render(geometry_type& geom, Image32& image) const - { - typedef agg::renderer_base ren_base; - agg::row_ptr_cache buf(image.raw_data(),image.width(),image.height(), - image.width()*4); - agg::pixfmt_rgba32 pixf(buf); - ren_base renb(pixf); - - Color const& col = stroke_.get_color(); - unsigned r=col.red(); - unsigned g=col.green(); - unsigned b=col.blue(); - - if (0)//stroke_.get_width() <= 1.0) - { - typedef agg::renderer_outline_aa renderer_oaa; - typedef agg::rasterizer_outline_aa rasterizer_outline_aa; - agg::line_profile_aa prof; - prof.width(stroke_.get_width()); - renderer_oaa ren_oaa(renb, prof); - rasterizer_outline_aa ras_oaa(ren_oaa); - - ren_oaa.color(agg::rgba8(r, g, b, int(255*stroke_.get_opacity()))); - ren_oaa.clip_box(0,0,image.width(),image.height()); - ras_oaa.add_path(geom); - - } - else - { - typedef agg::renderer_scanline_aa_solid renderer; - renderer ren(renb); - agg::rasterizer_scanline_aa<> ras; - agg::scanline_u8 sl; - - if (stroke_.has_dash()) - { - - agg::conv_dash > dash(geom); - dash_array const& d = stroke_.get_dash_array(); - dash_array::const_iterator itr = d.begin(); - dash_array::const_iterator end = d.end(); - while (itr != end) - { - dash.add_dash(itr->first, itr->second); - ++itr; - } - agg::conv_stroke > > stroke(dash); - - line_join_e join=stroke_.get_line_join(); - if ( join == MITER_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == MITER_REVERT_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == ROUND_JOIN) - stroke.generator().line_join(agg::round_join); - else - stroke.generator().line_join(agg::bevel_join); - - line_cap_e cap=stroke_.get_line_cap(); - if (cap == BUTT_CAP) - stroke.generator().line_cap(agg::butt_cap); - else if (cap == SQUARE_CAP) - stroke.generator().line_cap(agg::square_cap); - else - stroke.generator().line_cap(agg::round_cap); - - stroke.generator().miter_limit(4.0); - stroke.generator().width(stroke_.get_width()); - - ras.clip_box(0,0,image.width(),image.height()); - ras.add_path(stroke); - ren.color(agg::rgba8(r, g, b, int(255*stroke_.get_opacity()))); - agg::render_scanlines(ras, sl, ren); - } - else - { - agg::conv_stroke > stroke(geom); - - line_join_e join=stroke_.get_line_join(); - if ( join == MITER_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == MITER_REVERT_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == ROUND_JOIN) - stroke.generator().line_join(agg::round_join); - else - stroke.generator().line_join(agg::bevel_join); - - line_cap_e cap=stroke_.get_line_cap(); - if (cap == BUTT_CAP) - stroke.generator().line_cap(agg::butt_cap); - else if (cap == SQUARE_CAP) - stroke.generator().line_cap(agg::square_cap); - else - stroke.generator().line_cap(agg::round_cap); - - stroke.generator().miter_limit(4.0); - stroke.generator().width(stroke_.get_width()); - - ras.clip_box(0,0,image.width(),image.height()); - ras.add_path(stroke); - ren.color(agg::rgba8(r, g, b, int(255*stroke_.get_opacity()))); - agg::render_scanlines(ras, sl, ren); - } - } - } }; } diff --git a/include/mapnik.hpp b/include/mapnik.hpp index 16de08532..c46c922a0 100644 --- a/include/mapnik.hpp +++ b/include/mapnik.hpp @@ -34,9 +34,7 @@ #include "comparison.hpp" #include "regex_filter.hpp" #include "utils.hpp" -#include "style.hpp" #include "symbolizer.hpp" -#include "style_cache.hpp" #include "geometry.hpp" #include "geom_util.hpp" #include "raster.hpp" @@ -48,8 +46,9 @@ #include "image_reader.hpp" #include "line_symbolizer.hpp" #include "polygon_symbolizer.hpp" +#include "polygon_pattern_symbolizer.hpp" #include "line_pattern_symbolizer.hpp" -//#include "image_symbolizer.hpp" +#include "image_symbolizer.hpp" #include "image_util.hpp" #include "datasource.hpp" #include "layer.hpp" @@ -57,6 +56,7 @@ #include "wkb.hpp" #include "map.hpp" #include "feature_type_style.hpp" +#include "named_style_cache.hpp" #include "feature_factory.hpp" #include "math_expr.hpp" #include "value.hpp" diff --git a/include/style_cache.hpp b/include/named_style_cache.hpp similarity index 98% rename from include/style_cache.hpp rename to include/named_style_cache.hpp index 425fda8f8..d290bc093 100644 --- a/include/style_cache.hpp +++ b/include/named_style_cache.hpp @@ -22,7 +22,6 @@ #define STYLE_CACHE_HPP #include "utils.hpp" -#include "style.hpp" #include #include "feature_type_style.hpp" diff --git a/src/style.cpp b/include/polygon_pattern_symbolizer.hpp similarity index 60% rename from src/style.cpp rename to include/polygon_pattern_symbolizer.hpp index 55cbbaa50..cd22e23e2 100644 --- a/src/style.cpp +++ b/include/polygon_pattern_symbolizer.hpp @@ -16,11 +16,28 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -//$Id: style.cpp 17 2005-03-08 23:58:43Z pavlenko $ +//$Id$ -#include "style.hpp" +#ifndef POLYGON_PATTERN_SYMBOLIZER_HPP +#define POLYGON_PATTERN_SYMBOLIZER_HPP -namespace mapnik +#include "symbolizer.hpp" +#include + +namespace mapnik { - boost::shared_ptr Style::zero_symbol_ = boost::shared_ptr(); + struct polygon_pattern_symbolizer : public symbolizer, + private boost::noncopyable + { + + polygon_pattern_symbolizer(std::string const& file, + std::string const& type, + unsigned width,unsigned height); + + void render(geometry_type& geom,Image32& image) const; + private: + ImageData32 pattern_; + }; } + +#endif //POLYGON_PATTERN_SYMBOLIZER_HPP diff --git a/include/polygon_symbolizer.hpp b/include/polygon_symbolizer.hpp index f90c74ec2..252917f02 100644 --- a/include/polygon_symbolizer.hpp +++ b/include/polygon_symbolizer.hpp @@ -22,132 +22,18 @@ #define POLYGON_SYMBOLIZER_HPP #include "symbolizer.hpp" -#include "image_reader.hpp" -#include "agg_basics.h" -#include "agg_rendering_buffer.h" -#include "agg_rasterizer_scanline_aa.h" -#include "agg_scanline_p.h" -#include "agg_scanline_u.h" -#include "agg_renderer_scanline.h" -#include "agg_pixfmt_rgba.h" -#include "agg_path_storage.h" -#include "agg_span_allocator.h" -#include "agg_span_pattern_rgba.h" -#include "agg_image_accessors.h" +#include namespace mapnik { - struct polygon_symbolizer : public symbolizer + struct polygon_symbolizer : public symbolizer, + private boost::noncopyable { + polygon_symbolizer(const Color& fill); + void render(geometry_type& geom,Image32& image) const; private: Color fill_; - public: - polygon_symbolizer(const Color& fill) - : symbolizer(), - fill_(fill) {} - - virtual ~polygon_symbolizer() {} - - void render(geometry_type& geom,Image32& image) const - { - typedef agg::renderer_base ren_base; - typedef agg::renderer_scanline_aa_solid renderer; - agg::row_ptr_cache buf(image.raw_data(),image.width(),image.height(), - image.width()*4); - agg::pixfmt_rgba32 pixf(buf); - ren_base renb(pixf); - - unsigned r=fill_.red(); - unsigned g=fill_.green(); - unsigned b=fill_.blue(); - unsigned a=fill_.alpha(); - renderer ren(renb); - - agg::rasterizer_scanline_aa<> ras; - agg::scanline_u8 sl; - ras.clip_box(0,0,image.width(),image.height()); - ras.add_path(geom); - ren.color(agg::rgba8(r, g, b, a)); - agg::render_scanlines(ras, sl, ren); - } - - private: - polygon_symbolizer(const polygon_symbolizer&); - polygon_symbolizer& operator=(const polygon_symbolizer&); - }; - - struct pattern_symbolizer : public symbolizer - { - private: - ImageData32 pattern_; - public: - pattern_symbolizer(std::string const& file, - std::string const& type, - unsigned width,unsigned height) - : symbolizer(), - pattern_(width,height) - { - try - { - std::auto_ptr reader(get_image_reader(type,file)); - reader->read(0,0,pattern_); - } - catch (...) - { - std::cerr<<"exception caught..."< ren_base; - agg::row_ptr_cache buf(image.raw_data(),image.width(),image.height(), - image.width()*4); - agg::pixfmt_rgba32 pixf(buf); - ren_base renb(pixf); - - unsigned w=pattern_.width(); - unsigned h=pattern_.height(); - agg::row_ptr_cache pattern_rbuf((agg::int8u*)pattern_.getBytes(),w,h,w*4); - - typedef agg::wrap_mode_repeat wrap_x_type; - typedef agg::wrap_mode_repeat wrap_y_type; - typedef agg::image_accessor_wrap img_source_type; - - typedef agg::span_pattern_rgba span_gen_type; - - typedef agg::renderer_scanline_aa, - span_gen_type> renderer_type; - - double x0,y0; - geom.vertex(&x0,&y0); - geom.rewind(0); - - unsigned offset_x = unsigned(image.width() - x0); - unsigned offset_y = unsigned(image.height() - y0); - - agg::span_allocator sa; - img_source_type img_src(pattern_rbuf); - span_gen_type sg(img_src, offset_x, offset_y); - renderer_type rp(renb,sa, sg); - - agg::rasterizer_scanline_aa<> ras; - agg::scanline_u8 sl; - ras.clip_box(0,0,image.width(),image.height()); - ras.add_path(geom); - agg::render_scanlines(ras, sl, rp); - } - - private: - pattern_symbolizer(const pattern_symbolizer&); - pattern_symbolizer& operator=(const pattern_symbolizer&); - }; - + }; } #endif // POLYGON_SYMBOLIZER_HPP diff --git a/include/render.hpp b/include/render.hpp index cc7e0cd7c..a4c025ac9 100644 --- a/include/render.hpp +++ b/include/render.hpp @@ -22,7 +22,6 @@ #define RENDER_HPP #include -#include "style.hpp" #include "envelope.hpp" #include "graphics.hpp" #include "datasource.hpp" diff --git a/include/style_factory.hpp b/include/style_factory.hpp index 8022b18fb..39ca720db 100644 --- a/include/style_factory.hpp +++ b/include/style_factory.hpp @@ -21,7 +21,7 @@ #ifndef STYLE_FACTORY_HPP #define STYLE_FACTORY_HPP -#include "style.hpp" +//#include "style.hpp" namespace mapnik { diff --git a/include/text.hpp b/include/text.hpp index 6fc32e7d3..bfb50e53b 100644 --- a/include/text.hpp +++ b/include/text.hpp @@ -27,7 +27,6 @@ #include FT_FREETYPE_H #include #include -#include "style.hpp" #include "graphics.hpp" namespace mapnik diff --git a/python/SConscript b/python/SConscript index 2bd846a43..ec67c55eb 100644 --- a/python/SConscript +++ b/python/SConscript @@ -45,9 +45,9 @@ lib_boost_python = env.SharedLibrary('libboost-python',boost_python_src,LIBS=[], env.Install(prefix + '/lib',lib_boost_python) -agg_root = env['AGG_ROOT'] -agg_headers = agg_root +'/include' -freetype2_root = env['FREETYPE2_ROOT'] +#agg_root = env['AGG_ROOT'] +#agg_headers = agg_root +'/include' +#freetype2_root = env['FREETYPE2_ROOT'] def createPythonExtBuilder(env): @@ -91,7 +91,7 @@ mapnik_python_src=Split( """ ) -headers =[ '#include',boost_root,freetype2_root,agg_headers,python_headers] +headers =[ '#include',boost_root,python_headers] libraries=['mapnik','boost-python'] libpaths = [prefix+"/lib"] diff --git a/python/mapnik_python.cpp b/python/mapnik_python.cpp index e222ed3e3..c7afa1d35 100644 --- a/python/mapnik_python.cpp +++ b/python/mapnik_python.cpp @@ -23,7 +23,6 @@ #include #include "mapnik.hpp" -#include "image_symbolizer.hpp" using namespace mapnik; @@ -68,6 +67,11 @@ boost::shared_ptr create_line_symbolizer2(stroke const& strk) return boost::shared_ptr(new line_symbolizer(strk)); } +boost::shared_ptr create_line_symbolizer3(std::string const& file,unsigned w,unsigned h) +{ + return boost::shared_ptr(new line_pattern_symbolizer(file,"png",w,h)); +} + boost::shared_ptr create_polygon_symbolizer(const Color& fill) { return boost::shared_ptr(new polygon_symbolizer(fill)); @@ -75,7 +79,7 @@ boost::shared_ptr create_polygon_symbolizer(const Color& fill) boost::shared_ptr create_polygon_symbolizer2(std::string const& file,unsigned w,unsigned h) { - return boost::shared_ptr(new pattern_symbolizer(file,"png",w,h)); + return boost::shared_ptr(new polygon_pattern_symbolizer(file,"png",w,h)); } BOOST_PYTHON_MODULE(_mapnik) @@ -117,6 +121,7 @@ BOOST_PYTHON_MODULE(_mapnik) def("point_symbolizer",&create_point_symbolizer); def("line_symbolizer",&create_line_symbolizer); def("line_symbolizer",&create_line_symbolizer2); + def("line_symbolizer",&create_line_symbolizer3); def("polygon_symbolizer",&create_polygon_symbolizer); def("polygon_symbolizer",&create_polygon_symbolizer2); register_ptr_to_python >(); diff --git a/src/SConscript b/src/SConscript index 4c4b9625b..8ff374627 100644 --- a/src/SConscript +++ b/src/SConscript @@ -49,11 +49,16 @@ source = Split( plugin.cpp png_reader.cpp render.cpp - style_cache.cpp - style.cpp + named_style_cache.cpp text.cpp tiff_reader.cpp - wkb.cpp""" + wkb.cpp + line_symbolizer.cpp + line_pattern_symbolizer.cpp + polygon_symbolizer.cpp + polygon_pattern_symbolizer.cpp + image_symbolizer.cpp + """ ) lib_mapnik = env.SharedLibrary('libmapnik',source,CPPPATH=headers,LIBS=libraries,LIBPATH=libpaths,LINKFLAGS=linkflags) diff --git a/src/image_symbolizer.cpp b/src/image_symbolizer.cpp new file mode 100644 index 000000000..7ff9e694b --- /dev/null +++ b/src/image_symbolizer.cpp @@ -0,0 +1,59 @@ +/* This file is part of Mapnik (c++ mapping toolkit) + * Copyright (C) 2005 Artem Pavlenko + * + * Mapnik is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +//$Id$ + +#include "image_symbolizer.hpp" +#include "image_data.hpp" +#include "image_reader.hpp" + +namespace mapnik +{ + image_symbolizer::image_symbolizer(std::string const& file, + std::string const& type, + unsigned width,unsigned height) + : symbolizer(), + symbol_(width,height) + { + try + { + std::auto_ptr reader(get_image_reader(type,file)); + reader->read(0,0,symbol_); + } + catch (...) + { + std::cerr<<"exception caught..." << std::endl; + } + } + + void image_symbolizer::render(geometry_type& geom,Image32& image) const + { + int w=symbol_.width(); + int h=symbol_.height(); + double x,y; + unsigned size = geom.num_points(); + for (unsigned pos = 0; pos < size ;++pos) + { + geom.vertex(&x,&y); + int px=int(x - 0.5 * w); + int py=int(y - 0.5 * h); + image.set_rectangle_alpha(px,py,symbol_); + } + } +} + diff --git a/src/line_pattern_symbolizer.cpp b/src/line_pattern_symbolizer.cpp new file mode 100644 index 000000000..9f3c70bb3 --- /dev/null +++ b/src/line_pattern_symbolizer.cpp @@ -0,0 +1,101 @@ +/* This file is part of Mapnik (c++ mapping toolkit) + * Copyright (C) 2005 Artem Pavlenko + * + * Mapnik is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +//$Id$ + +#include "line_pattern_symbolizer.hpp" +#include "image_reader.hpp" +#include "agg_basics.h" +#include "agg_rendering_buffer.h" +#include "agg_rasterizer_scanline_aa.h" +#include "agg_rasterizer_outline_aa.h" +#include "agg_scanline_p.h" +#include "agg_scanline_u.h" +#include "agg_renderer_scanline.h" +#include "agg_pixfmt_rgba.h" +#include "agg_path_storage.h" +#include "agg_span_allocator.h" +#include "agg_span_pattern_rgba.h" +#include "agg_image_accessors.h" +#include "agg_pattern_filters_rgba.h" +#include "agg_renderer_outline_image.h" + +namespace mapnik +{ + class pattern_source : private boost::noncopyable + { + public: + pattern_source(ImageData32 const& pattern) + : pattern_(pattern) {} + + unsigned int width() const + { + return pattern_.width(); + } + unsigned int height() const + { + return pattern_.height(); + } + agg::rgba8 pixel(int x, int y) const + { + unsigned c = pattern_(x,y); + return agg::rgba8(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff,(c >> 24) & 0xff); + } + private: + ImageData32 const& pattern_; + }; + + line_pattern_symbolizer::line_pattern_symbolizer(std::string const& file, + std::string const& type, + unsigned width,unsigned height) + : symbolizer(), + pattern_(width,height) + { + try + { + std::auto_ptr reader(get_image_reader(type,file)); + reader->read(0,0,pattern_); + } + catch (...) + { + std::cerr<<"exception caught..."< pattern_type; + typedef agg::renderer_base renderer_base; + typedef agg::renderer_outline_image renderer_type; + typedef agg::rasterizer_outline_aa rasterizer_type; + + unsigned int width=image.width(); + unsigned int height=image.height(); + agg::row_ptr_cache buf(image.raw_data(), width, height,width*4); + agg::pixfmt_rgba32 pixf(buf); + renderer_base ren_base(pixf); + agg::pattern_filter_bilinear_rgba8 filter; + pattern_source source(pattern_); + pattern_type pattern (filter,source); + renderer_type ren(ren_base, pattern); + ren.clip_box(0,0,width,height); + rasterizer_type ras(ren); + ras.add_path(geom); + } +} diff --git a/src/line_symbolizer.cpp b/src/line_symbolizer.cpp new file mode 100644 index 000000000..beb745ce8 --- /dev/null +++ b/src/line_symbolizer.cpp @@ -0,0 +1,161 @@ +/* This file is part of Mapnik (c++ mapping toolkit) + * Copyright (C) 2005 Artem Pavlenko + * + * Mapnik is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +//$Id$ + +#include "line_symbolizer.hpp" + +#include "agg_basics.h" +#include "agg_rendering_buffer.h" +#include "agg_rasterizer_scanline_aa.h" +#include "agg_conv_stroke.h" +#include "agg_conv_dash.h" +#include "agg_conv_contour.h" +#include "agg_vcgen_stroke.h" +#include "agg_conv_adaptor_vcgen.h" +#include "agg_conv_smooth_poly1.h" +#include "agg_conv_marker.h" +#include "agg_arrowhead.h" +#include "agg_vcgen_markers_term.h" +#include "agg_scanline_p.h" +#include "agg_scanline_u.h" +#include "agg_renderer_scanline.h" +#include "agg_pixfmt_rgba.h" +#include "agg_path_storage.h" +#include "agg_renderer_outline_aa.h" +#include "agg_rasterizer_outline_aa.h" +#include "agg_rasterizer_outline.h" +#include "agg_renderer_outline_image.h" + +namespace mapnik +{ + line_symbolizer::line_symbolizer(stroke const& stroke) + : symbolizer(), + stroke_(stroke) {} + + line_symbolizer::line_symbolizer(const Color& pen,float width) + : symbolizer(), + stroke_(pen,width) {} + + void line_symbolizer::render(geometry_type& geom, Image32& image) const + { + typedef agg::renderer_base ren_base; + agg::row_ptr_cache buf(image.raw_data(),image.width(),image.height(), + image.width()*4); + agg::pixfmt_rgba32 pixf(buf); + ren_base renb(pixf); + + Color const& col = stroke_.get_color(); + unsigned r=col.red(); + unsigned g=col.green(); + unsigned b=col.blue(); + + if (0)//stroke_.get_width() <= 1.0) + { + typedef agg::renderer_outline_aa renderer_oaa; + typedef agg::rasterizer_outline_aa rasterizer_outline_aa; + agg::line_profile_aa prof; + prof.width(stroke_.get_width()); + renderer_oaa ren_oaa(renb, prof); + rasterizer_outline_aa ras_oaa(ren_oaa); + + ren_oaa.color(agg::rgba8(r, g, b, int(255*stroke_.get_opacity()))); + ren_oaa.clip_box(0,0,image.width(),image.height()); + ras_oaa.add_path(geom); + + } + else + { + typedef agg::renderer_scanline_aa_solid renderer; + renderer ren(renb); + agg::rasterizer_scanline_aa<> ras; + agg::scanline_u8 sl; + + if (stroke_.has_dash()) + { + + agg::conv_dash > dash(geom); + dash_array const& d = stroke_.get_dash_array(); + dash_array::const_iterator itr = d.begin(); + dash_array::const_iterator end = d.end(); + while (itr != end) + { + dash.add_dash(itr->first, itr->second); + ++itr; + } + agg::conv_stroke > > stroke(dash); + + line_join_e join=stroke_.get_line_join(); + if ( join == MITER_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == MITER_REVERT_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == ROUND_JOIN) + stroke.generator().line_join(agg::round_join); + else + stroke.generator().line_join(agg::bevel_join); + + line_cap_e cap=stroke_.get_line_cap(); + if (cap == BUTT_CAP) + stroke.generator().line_cap(agg::butt_cap); + else if (cap == SQUARE_CAP) + stroke.generator().line_cap(agg::square_cap); + else + stroke.generator().line_cap(agg::round_cap); + + stroke.generator().miter_limit(4.0); + stroke.generator().width(stroke_.get_width()); + + ras.clip_box(0,0,image.width(),image.height()); + ras.add_path(stroke); + ren.color(agg::rgba8(r, g, b, int(255*stroke_.get_opacity()))); + agg::render_scanlines(ras, sl, ren); + } + else + { + agg::conv_stroke > stroke(geom); + + line_join_e join=stroke_.get_line_join(); + if ( join == MITER_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == MITER_REVERT_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == ROUND_JOIN) + stroke.generator().line_join(agg::round_join); + else + stroke.generator().line_join(agg::bevel_join); + + line_cap_e cap=stroke_.get_line_cap(); + if (cap == BUTT_CAP) + stroke.generator().line_cap(agg::butt_cap); + else if (cap == SQUARE_CAP) + stroke.generator().line_cap(agg::square_cap); + else + stroke.generator().line_cap(agg::round_cap); + + stroke.generator().miter_limit(4.0); + stroke.generator().width(stroke_.get_width()); + + ras.clip_box(0,0,image.width(),image.height()); + ras.add_path(stroke); + ren.color(agg::rgba8(r, g, b, int(255*stroke_.get_opacity()))); + agg::render_scanlines(ras, sl, ren); + } + } + } +} diff --git a/src/mapnik.cpp b/src/mapnik.cpp index ead495613..014aab7c4 100644 --- a/src/mapnik.cpp +++ b/src/mapnik.cpp @@ -59,3 +59,5 @@ namespace mapnik ia >> m; } } + + diff --git a/src/style_cache.cpp b/src/named_style_cache.cpp similarity index 96% rename from src/style_cache.cpp rename to src/named_style_cache.cpp index 0d853f078..7e1e46da6 100644 --- a/src/style_cache.cpp +++ b/src/named_style_cache.cpp @@ -18,8 +18,7 @@ //$Id: style_cache.cpp 37 2005-04-07 17:09:38Z pavlenko $ -#include "style_cache.hpp" -#include "line_symbolizer.hpp" +#include "named_style_cache.hpp" #include namespace mapnik diff --git a/src/polygon_pattern_symbolizer.cpp b/src/polygon_pattern_symbolizer.cpp new file mode 100644 index 000000000..3cd8a725b --- /dev/null +++ b/src/polygon_pattern_symbolizer.cpp @@ -0,0 +1,97 @@ +/* This file is part of Mapnik (c++ mapping toolkit) + * Copyright (C) 2005 Artem Pavlenko + * + * Mapnik is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +//$Id$ + +#include "polygon_pattern_symbolizer.hpp" + +#include "image_reader.hpp" +#include "agg_basics.h" +#include "agg_rendering_buffer.h" +#include "agg_rasterizer_scanline_aa.h" +#include "agg_scanline_p.h" +#include "agg_scanline_u.h" +#include "agg_renderer_scanline.h" +#include "agg_pixfmt_rgba.h" +#include "agg_path_storage.h" +#include "agg_span_allocator.h" +#include "agg_span_pattern_rgba.h" +#include "agg_image_accessors.h" + +namespace mapnik +{ + polygon_pattern_symbolizer::polygon_pattern_symbolizer(std::string const& file, + std::string const& type, + unsigned width,unsigned height) + : symbolizer(), + pattern_(width,height) + { + try + { + std::auto_ptr reader(get_image_reader(type,file)); + reader->read(0,0,pattern_); + } + catch (...) + { + std::cerr<<"exception caught..."< ren_base; + agg::row_ptr_cache buf(image.raw_data(),image.width(),image.height(), + image.width()*4); + agg::pixfmt_rgba32 pixf(buf); + ren_base renb(pixf); + + unsigned w=pattern_.width(); + unsigned h=pattern_.height(); + agg::row_ptr_cache pattern_rbuf((agg::int8u*)pattern_.getBytes(),w,h,w*4); + + typedef agg::wrap_mode_repeat wrap_x_type; + typedef agg::wrap_mode_repeat wrap_y_type; + typedef agg::image_accessor_wrap img_source_type; + + typedef agg::span_pattern_rgba span_gen_type; + + typedef agg::renderer_scanline_aa, + span_gen_type> renderer_type; + + double x0,y0; + geom.vertex(&x0,&y0); + geom.rewind(0); + + unsigned offset_x = unsigned(image.width() - x0); + unsigned offset_y = unsigned(image.height() - y0); + + agg::span_allocator sa; + img_source_type img_src(pattern_rbuf); + span_gen_type sg(img_src, offset_x, offset_y); + renderer_type rp(renb,sa, sg); + + agg::rasterizer_scanline_aa<> ras; + agg::scanline_u8 sl; + ras.clip_box(0,0,image.width(),image.height()); + ras.add_path(geom); + agg::render_scanlines(ras, sl, rp); + } +} diff --git a/src/polygon_symbolizer.cpp b/src/polygon_symbolizer.cpp new file mode 100644 index 000000000..97afdef47 --- /dev/null +++ b/src/polygon_symbolizer.cpp @@ -0,0 +1,63 @@ +/* This file is part of Mapnik (c++ mapping toolkit) + * Copyright (C) 2005 Artem Pavlenko + * + * Mapnik is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +//$Id$ + +#include "polygon_symbolizer.hpp" + +#include "agg_basics.h" +#include "agg_rendering_buffer.h" +#include "agg_rasterizer_scanline_aa.h" +#include "agg_scanline_p.h" +#include "agg_scanline_u.h" +#include "agg_renderer_scanline.h" +#include "agg_pixfmt_rgba.h" +#include "agg_path_storage.h" +#include "agg_span_allocator.h" +#include "agg_span_pattern_rgba.h" +#include "agg_image_accessors.h" + +namespace mapnik +{ + polygon_symbolizer::polygon_symbolizer(const Color& fill) + : symbolizer(), + fill_(fill) {} + + void polygon_symbolizer::render(geometry_type& geom,Image32& image) const + { + typedef agg::renderer_base ren_base; + typedef agg::renderer_scanline_aa_solid renderer; + agg::row_ptr_cache buf(image.raw_data(),image.width(),image.height(), + image.width()*4); + agg::pixfmt_rgba32 pixf(buf); + ren_base renb(pixf); + + unsigned r=fill_.red(); + unsigned g=fill_.green(); + unsigned b=fill_.blue(); + unsigned a=fill_.alpha(); + renderer ren(renb); + + agg::rasterizer_scanline_aa<> ras; + agg::scanline_u8 sl; + ras.clip_box(0,0,image.width(),image.height()); + ras.add_path(geom); + ren.color(agg::rgba8(r, g, b, a)); + agg::render_scanlines(ras, sl, ren); + } +} diff --git a/src/render.cpp b/src/render.cpp index c7903ba01..f1710a345 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -21,7 +21,7 @@ #include "render.hpp" #include "image_util.hpp" #include "utils.hpp" -#include "style_cache.hpp" +#include "named_style_cache.hpp" #include "symbolizer.hpp" #include "query.hpp" #include "feature_layer_desc.hpp"