diff --git a/bindings/python/mapnik_image_view.cpp b/bindings/python/mapnik_image_view.cpp index e08129f7f..8894a96eb 100644 --- a/bindings/python/mapnik_image_view.cpp +++ b/bindings/python/mapnik_image_view.cpp @@ -39,21 +39,19 @@ #include #include #include -#include #include -using mapnik::image_data_rgba8; -using mapnik::image_view; +using mapnik::image_view_rgba8; using mapnik::save_to_file; // output 'raw' pixels -PyObject* view_tostring1(image_view const& view) +PyObject* view_tostring1(image_view_rgba8 const& view) { std::ostringstream ss(std::ios::out|std::ios::binary); for (unsigned i=0;i(view.getRow(i)), - view.width() * sizeof(image_view::pixel_type)); + view.width() * sizeof(image_view_rgba8::pixel_type)); } return #if PY_VERSION_HEX >= 0x03000000 @@ -65,7 +63,7 @@ PyObject* view_tostring1(image_view const& view) } // encode (png,jpeg) -PyObject* view_tostring2(image_view const & view, std::string const& format) +PyObject* view_tostring2(image_view_rgba8 const & view, std::string const& format) { std::string s = save_to_string(view, format); return @@ -77,7 +75,7 @@ PyObject* view_tostring2(image_view const & view, std::string (s.data(),s.size()); } -PyObject* view_tostring3(image_view const & view, std::string const& format, mapnik::rgba_palette const& pal) +PyObject* view_tostring3(image_view_rgba8 const & view, std::string const& format, mapnik::rgba_palette const& pal) { std::string s = save_to_string(view, format, pal); return @@ -89,15 +87,15 @@ PyObject* view_tostring3(image_view const & view, std::string (s.data(),s.size()); } -bool is_solid(image_view const& view) +bool is_solid(image_view_rgba8 const& view) { if (view.width() > 0 && view.height() > 0) { - mapnik::image_view::pixel_type const* first_row = view.getRow(0); - mapnik::image_view::pixel_type const first_pixel = first_row[0]; + mapnik::image_view_rgba8::pixel_type const* first_row = view.getRow(0); + mapnik::image_view_rgba8::pixel_type const first_pixel = first_row[0]; for (unsigned y = 0; y < view.height(); ++y) { - mapnik::image_view::pixel_type const * row = view.getRow(y); + mapnik::image_view_rgba8::pixel_type const * row = view.getRow(y); for (unsigned x = 0; x < view.width(); ++x) { if (first_pixel != row[x]) @@ -110,20 +108,20 @@ bool is_solid(image_view const& view) return true; } -void save_view1(image_view const& view, +void save_view1(image_view_rgba8 const& view, std::string const& filename) { save_to_file(view,filename); } -void save_view2(image_view const& view, +void save_view2(image_view_rgba8 const& view, std::string const& filename, std::string const& type) { save_to_file(view,filename,type); } -void save_view3(image_view const& view, +void save_view3(image_view_rgba8 const& view, std::string const& filename, std::string const& type, mapnik::rgba_palette const& pal) @@ -135,9 +133,9 @@ void save_view3(image_view const& view, void export_image_view() { using namespace boost::python; - class_ >("ImageView","A view into an image.",no_init) - .def("width",&image_view::width) - .def("height",&image_view::height) + class_("ImageView","A view into an image.",no_init) + .def("width",&image_view_rgba8::width) + .def("height",&image_view_rgba8::height) .def("is_solid",&is_solid) .def("tostring",&view_tostring1) .def("tostring",&view_tostring2) diff --git a/bindings/python/mapnik_python.cpp b/bindings/python/mapnik_python.cpp index 73fba74f6..649d20126 100644 --- a/bindings/python/mapnik_python.cpp +++ b/bindings/python/mapnik_python.cpp @@ -137,6 +137,7 @@ void clear_cache() } #if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO) +#include #include #include #include diff --git a/demo/c++/rundemo.cpp b/demo/c++/rundemo.cpp index bb354fdeb..8f568affb 100644 --- a/demo/c++/rundemo.cpp +++ b/demo/c++/rundemo.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #if defined(HAVE_CAIRO) #include diff --git a/include/mapnik/cairo_io.hpp b/include/mapnik/cairo_io.hpp new file mode 100644 index 000000000..c808b9970 --- /dev/null +++ b/include/mapnik/cairo_io.hpp @@ -0,0 +1,49 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2014 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#ifndef MAPNIK_CAIRO_IO_HPP +#define MAPNIK_CAIRO_IO_HPP + +// mapnik +#include +#include + +// stl +#include + +namespace mapnik { + +#if defined(HAVE_CAIRO) +MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map, + std::string const& filename, + double scale_factor=1.0, + double scale_denominator=0.0); +MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map, + std::string const& filename, + std::string const& type, + double scale_factor=1.0, + double scale_denominator=0.0); +#endif + +} // end ns + +#endif // MAPNIK_CAIRO_IO_HPP diff --git a/include/mapnik/graphics.hpp b/include/mapnik/graphics.hpp index 5e84af2a7..c1fe52414 100644 --- a/include/mapnik/graphics.hpp +++ b/include/mapnik/graphics.hpp @@ -119,9 +119,9 @@ public: return data_.getBytes(); } - inline image_view get_view(unsigned x,unsigned y, unsigned w,unsigned h) + inline image_view_rgba8 get_view(unsigned x,unsigned y, unsigned w,unsigned h) { - return image_view(x,y,w,h,data_); + return image_view_rgba8(x,y,w,h,data_); } private: diff --git a/include/mapnik/image_util.hpp b/include/mapnik/image_util.hpp index b84326f6a..8501d578d 100644 --- a/include/mapnik/image_util.hpp +++ b/include/mapnik/image_util.hpp @@ -62,18 +62,6 @@ public: } }; -#if defined(HAVE_CAIRO) -MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map, - std::string const& filename, - double scale_factor=1.0, - double scale_denominator=0.0); -MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map, - std::string const& filename, - std::string const& type, - double scale_factor=1.0, - double scale_denominator=0.0); -#endif - template MAPNIK_DECL void save_to_file(T const& image, std::string const& filename, diff --git a/include/mapnik/miniz_png.hpp b/include/mapnik/miniz_png.hpp index bc9221f36..5c6fed248 100644 --- a/include/mapnik/miniz_png.hpp +++ b/include/mapnik/miniz_png.hpp @@ -84,11 +84,11 @@ private: }; extern template MAPNIK_DECL void PNGWriter::writeIDAT(image_data_gray8 const& image); -extern template MAPNIK_DECL void PNGWriter::writeIDAT >(image_view const& image); +extern template MAPNIK_DECL void PNGWriter::writeIDAT(image_view_gray8 const& image); extern template MAPNIK_DECL void PNGWriter::writeIDAT(image_data_rgba8 const& image); -extern template MAPNIK_DECL void PNGWriter::writeIDAT >(image_view const& image); +extern template MAPNIK_DECL void PNGWriter::writeIDAT(image_view_rgba8 const& image); extern template MAPNIK_DECL void PNGWriter::writeIDATStripAlpha(image_data_rgba8 const& image); -extern template MAPNIK_DECL void PNGWriter::writeIDATStripAlpha >(image_view const& image); +extern template MAPNIK_DECL void PNGWriter::writeIDATStripAlpha(image_view_rgba8 const& image); }} diff --git a/localize.sh b/localize.sh index 4f227e73c..1e79ded61 100755 --- a/localize.sh +++ b/localize.sh @@ -6,8 +6,8 @@ if [ ${UNAME} = 'Darwin' ]; then else export LD_LIBRARY_PATH="${CURRENT_DIR}/src/":${LD_LIBRARY_PATH} fi -export PYTHONPATH="${CURRENT_DIR}/bindings/python/":$PYTHONPATH +export PYTHONPATH="${CURRENT_DIR}/bindings/python/" #:$PYTHONPATH export MAPNIK_FONT_DIRECTORY="${CURRENT_DIR}/fonts/dejavu-fonts-ttf-2.34/ttf/" export MAPNIK_INPUT_PLUGINS_DIRECTORY="${CURRENT_DIR}/plugins/input/" export PATH="${CURRENT_DIR}/utils/mapnik-config":${PATH} -export PATH="${CURRENT_DIR}/utils/nik2img":${PATH} \ No newline at end of file +export PATH="${CURRENT_DIR}/utils/nik2img":${PATH} diff --git a/src/build.py b/src/build.py index 044659f94..737d1b7b5 100644 --- a/src/build.py +++ b/src/build.py @@ -173,6 +173,7 @@ source = Split( graphics.cpp parse_path.cpp image_reader.cpp + cairo_io.cpp image_util.cpp image_util_jpeg.cpp image_util_png.cpp diff --git a/src/cairo_io.cpp b/src/cairo_io.cpp new file mode 100644 index 000000000..0eefa2e89 --- /dev/null +++ b/src/cairo_io.cpp @@ -0,0 +1,131 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2014 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +// mapnik +#include +#include +#include + +#ifdef HAVE_CAIRO +#include +#include +#ifdef CAIRO_HAS_PDF_SURFACE +#include +#endif +#ifdef CAIRO_HAS_PS_SURFACE +#include +#endif +#ifdef CAIRO_HAS_SVG_SURFACE +#include +#endif +#endif + +// stl +#include +#include +#include +#include + +namespace mapnik { + +#if defined(HAVE_CAIRO) +void save_to_cairo_file(mapnik::Map const& map, std::string const& filename, double scale_factor, double scale_denominator) +{ + boost::optional type = type_from_filename(filename); + if (type) + { + save_to_cairo_file(map,filename,*type,scale_factor,scale_denominator); + } + else throw ImageWriterException("Could not write file to " + filename ); +} + +void save_to_cairo_file(mapnik::Map const& map, + std::string const& filename, + std::string const& type, + double scale_factor, + double scale_denominator) +{ + std::ofstream file (filename.c_str(), std::ios::out|std::ios::trunc|std::ios::binary); + if (file) + { + cairo_surface_ptr surface; + unsigned width = map.width(); + unsigned height = map.height(); + if (type == "pdf") + { +#ifdef CAIRO_HAS_PDF_SURFACE + surface = cairo_surface_ptr(cairo_pdf_surface_create(filename.c_str(),width,height),cairo_surface_closer()); +#else + throw ImageWriterException("PDFSurface not supported in the cairo backend"); +#endif + } +#ifdef CAIRO_HAS_SVG_SURFACE + else if (type == "svg") + { + surface = cairo_surface_ptr(cairo_svg_surface_create(filename.c_str(),width,height),cairo_surface_closer()); + } +#endif +#ifdef CAIRO_HAS_PS_SURFACE + else if (type == "ps") + { + surface = cairo_surface_ptr(cairo_ps_surface_create(filename.c_str(),width,height),cairo_surface_closer()); + } +#endif +#ifdef CAIRO_HAS_IMAGE_SURFACE + else if (type == "ARGB32") + { + surface = cairo_surface_ptr(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,width,height),cairo_surface_closer()); + } + else if (type == "RGB24") + { + surface = cairo_surface_ptr(cairo_image_surface_create(CAIRO_FORMAT_RGB24,width,height),cairo_surface_closer()); + } +#endif + else + { + throw ImageWriterException("unknown file type: " + type); + } + + //cairo_t * ctx = cairo_create(surface); + + // TODO - expose as user option + /* + if (type == "ARGB32" || type == "RGB24") + { + context->set_antialias(Cairo::ANTIALIAS_NONE); + } + */ + + mapnik::cairo_renderer ren(map, create_context(surface), scale_factor); + ren.apply(scale_denominator); + + if (type == "ARGB32" || type == "RGB24") + { + cairo_surface_write_to_png(&*surface, filename.c_str()); + } + cairo_surface_finish(&*surface); + } +} + +#endif + +} // end ns diff --git a/src/image_util.cpp b/src/image_util.cpp index c6f532c88..8f6c00e13 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -34,20 +34,6 @@ #include #include -#ifdef HAVE_CAIRO -#include -#include -#ifdef CAIRO_HAS_PDF_SURFACE -#include -#endif -#ifdef CAIRO_HAS_PS_SURFACE -#include -#endif -#ifdef CAIRO_HAS_SVG_SURFACE -#include -#endif -#endif - // boost #include @@ -61,7 +47,6 @@ namespace mapnik { - template std::string save_to_string(T const& image, std::string const& type, @@ -197,88 +182,6 @@ void save_to_file(T const& image, std::string const& filename, rgba_palette cons else throw ImageWriterException("Could not write file to " + filename ); } -#if defined(HAVE_CAIRO) -// TODO - move to separate cairo_io.hpp -void save_to_cairo_file(mapnik::Map const& map, std::string const& filename, double scale_factor, double scale_denominator) -{ - boost::optional type = type_from_filename(filename); - if (type) - { - save_to_cairo_file(map,filename,*type,scale_factor,scale_denominator); - } - else throw ImageWriterException("Could not write file to " + filename ); -} - -void save_to_cairo_file(mapnik::Map const& map, - std::string const& filename, - std::string const& type, - double scale_factor, - double scale_denominator) -{ - std::ofstream file (filename.c_str(), std::ios::out|std::ios::trunc|std::ios::binary); - if (file) - { - cairo_surface_ptr surface; - unsigned width = map.width(); - unsigned height = map.height(); - if (type == "pdf") - { -#ifdef CAIRO_HAS_PDF_SURFACE - surface = cairo_surface_ptr(cairo_pdf_surface_create(filename.c_str(),width,height),cairo_surface_closer()); -#else - throw ImageWriterException("PDFSurface not supported in the cairo backend"); -#endif - } -#ifdef CAIRO_HAS_SVG_SURFACE - else if (type == "svg") - { - surface = cairo_surface_ptr(cairo_svg_surface_create(filename.c_str(),width,height),cairo_surface_closer()); - } -#endif -#ifdef CAIRO_HAS_PS_SURFACE - else if (type == "ps") - { - surface = cairo_surface_ptr(cairo_ps_surface_create(filename.c_str(),width,height),cairo_surface_closer()); - } -#endif -#ifdef CAIRO_HAS_IMAGE_SURFACE - else if (type == "ARGB32") - { - surface = cairo_surface_ptr(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,width,height),cairo_surface_closer()); - } - else if (type == "RGB24") - { - surface = cairo_surface_ptr(cairo_image_surface_create(CAIRO_FORMAT_RGB24,width,height),cairo_surface_closer()); - } -#endif - else - { - throw ImageWriterException("unknown file type: " + type); - } - - //cairo_t * ctx = cairo_create(surface); - - // TODO - expose as user option - /* - if (type == "ARGB32" || type == "RGB24") - { - context->set_antialias(Cairo::ANTIALIAS_NONE); - } - */ - - mapnik::cairo_renderer ren(map, create_context(surface), scale_factor); - ren.apply(scale_denominator); - - if (type == "ARGB32" || type == "RGB24") - { - cairo_surface_write_to_png(&*surface, filename.c_str()); - } - cairo_surface_finish(&*surface); - } -} - -#endif - template void save_to_file(image_data_rgba8 const&, std::string const&, std::string const&); @@ -302,26 +205,26 @@ template std::string save_to_string(image_data_rgba8 const&, std::string const&, rgba_palette const& palette); -template void save_to_file > (image_view const&, +template void save_to_file (image_view_rgba8 const&, std::string const&, std::string const&); -template void save_to_file > (image_view const&, +template void save_to_file (image_view_rgba8 const&, std::string const&, std::string const&, rgba_palette const& palette); -template void save_to_file > (image_view const&, +template void save_to_file (image_view_rgba8 const&, std::string const&); -template void save_to_file > (image_view const&, +template void save_to_file (image_view_rgba8 const&, std::string const&, rgba_palette const& palette); -template std::string save_to_string > (image_view const&, +template std::string save_to_string (image_view_rgba8 const&, std::string const&); -template std::string save_to_string > (image_view const&, +template std::string save_to_string (image_view_rgba8 const&, std::string const&, rgba_palette const& palette); diff --git a/src/image_util_webp.cpp b/src/image_util_webp.cpp index 5d6770947..62c9ca2ed 100644 --- a/src/image_util_webp.cpp +++ b/src/image_util_webp.cpp @@ -381,9 +381,9 @@ template void webp_saver::operator() (image_data_rgba8 const& template void webp_saver::operator() (image_data_gray8 const& image) const; template void webp_saver::operator() (image_data_gray16 const& image) const; template void webp_saver::operator() (image_data_gray32f const& image) const; -template void webp_saver::operator()> (image_view const& image) const; -template void webp_saver::operator()> (image_view const& image) const; -template void webp_saver::operator()> (image_view const& image) const; -template void webp_saver::operator()> (image_view const& image) const; +template void webp_saver::operator() (image_view_rgba8 const& image) const; +template void webp_saver::operator() (image_view_gray8 const& image) const; +template void webp_saver::operator() (image_view_gray16 const& image) const; +template void webp_saver::operator() (image_view_gray32f const& image) const; } // end ns diff --git a/src/miniz_png.cpp b/src/miniz_png.cpp index d968d1dae..485337992 100644 --- a/src/miniz_png.cpp +++ b/src/miniz_png.cpp @@ -362,10 +362,10 @@ const mz_uint8 PNGWriter::IEND_tpl[] = { }; template void PNGWriter::writeIDAT(image_data_gray8 const& image); -template void PNGWriter::writeIDAT >(image_view const& image); +template void PNGWriter::writeIDAT(image_view_gray8 const& image); template void PNGWriter::writeIDAT(image_data_rgba8 const& image); -template void PNGWriter::writeIDAT >(image_view const& image); +template void PNGWriter::writeIDAT(image_view_rgba8 const& image); template void PNGWriter::writeIDATStripAlpha(image_data_rgba8 const& image); -template void PNGWriter::writeIDATStripAlpha >(image_view const& image); +template void PNGWriter::writeIDATStripAlpha(image_view_rgba8 const& image); }}