diff --git a/include/mapnik/image_util.hpp b/include/mapnik/image_util.hpp index f6bb1ca21..a02826f6a 100644 --- a/include/mapnik/image_util.hpp +++ b/include/mapnik/image_util.hpp @@ -266,20 +266,20 @@ extern template MAPNIK_DECL void save_to_file(image_data_rgba8 std::string const&); -extern template MAPNIK_DECL void save_to_file > (image_view const&, +extern template MAPNIK_DECL void save_to_file (image_view_rgba8 const&, std::string const&, std::string const&, rgba_palette const&); -extern template MAPNIK_DECL void save_to_file > (image_view const&, +extern template MAPNIK_DECL void save_to_file (image_view_rgba8 const&, std::string const&, std::string const&); -extern template MAPNIK_DECL void save_to_file > (image_view const&, +extern template MAPNIK_DECL void save_to_file (image_view_rgba8 const&, std::string const&, rgba_palette const&); -extern template MAPNIK_DECL void save_to_file > (image_view const&, +extern template MAPNIK_DECL void save_to_file (image_view_rgba8 const&, std::string const&); extern template MAPNIK_DECL std::string save_to_string(image_data_rgba8 const&, @@ -289,10 +289,10 @@ extern template MAPNIK_DECL std::string save_to_string(image_d std::string const&, rgba_palette const&); -extern template MAPNIK_DECL std::string save_to_string > (image_view const&, +extern template MAPNIK_DECL std::string save_to_string (image_view_rgba8 const&, std::string const&); -extern template MAPNIK_DECL std::string save_to_string > (image_view const&, +extern template MAPNIK_DECL std::string save_to_string (image_view_rgba8 const&, std::string const&, rgba_palette const&); #ifdef _MSC_VER @@ -310,15 +310,15 @@ template MAPNIK_DECL void save_to_stream( std::string const& type ); -template MAPNIK_DECL void save_to_stream > ( - image_view const& image, +template MAPNIK_DECL void save_to_stream ( + image_view_rgba8 const& image, std::ostream & stream, std::string const& type, rgba_palette const& palette ); -template MAPNIK_DECL void save_to_stream > ( - image_view const& image, +template MAPNIK_DECL void save_to_stream ( + image_view_rgba8 const& image, std::ostream & stream, std::string const& type ); diff --git a/include/mapnik/image_util_jpeg.hpp b/include/mapnik/image_util_jpeg.hpp index 091ce2566..5f77f56f0 100644 --- a/include/mapnik/image_util_jpeg.hpp +++ b/include/mapnik/image_util_jpeg.hpp @@ -23,18 +23,15 @@ #ifndef MAPNIK_IMAGE_UTIL_JPEG_HPP #define MAPNIK_IMAGE_UTIL_JPEG_HPP -// mapnik -#include - // stl #include #include namespace mapnik { -struct jpeg_saver : public mapnik::util::static_visitor<> +struct jpeg_saver { - jpeg_saver(std::ostream &, std::string &); + jpeg_saver(std::ostream &, std::string const&); template void operator() (T const&) const; private: diff --git a/include/mapnik/image_util_png.hpp b/include/mapnik/image_util_png.hpp index a48c02bef..06dcde894 100644 --- a/include/mapnik/image_util_png.hpp +++ b/include/mapnik/image_util_png.hpp @@ -23,18 +23,15 @@ #ifndef MAPNIK_IMAGE_UTIL_PNG_HPP #define MAPNIK_IMAGE_UTIL_PNG_HPP -// mapnik -#include - // stl #include #include namespace mapnik { -struct png_saver_pal : public mapnik::util::static_visitor<> +struct png_saver_pal { - png_saver_pal(std::ostream &, std::string &, rgba_palette const&); + png_saver_pal(std::ostream &, std::string const&, rgba_palette const&); template void operator() (T const&) const; private: @@ -43,9 +40,9 @@ struct png_saver_pal : public mapnik::util::static_visitor<> rgba_palette const& pal_; }; -struct png_saver : public mapnik::util::static_visitor<> +struct png_saver { - png_saver(std::ostream &, std::string &); + png_saver(std::ostream &, std::string const&); template void operator() (T const&) const; private: diff --git a/include/mapnik/image_util_tiff.hpp b/include/mapnik/image_util_tiff.hpp index 6a2861b2a..5cacc6781 100644 --- a/include/mapnik/image_util_tiff.hpp +++ b/include/mapnik/image_util_tiff.hpp @@ -23,18 +23,15 @@ #ifndef MAPNIK_IMAGE_UTIL_TIFF_HPP #define MAPNIK_IMAGE_UTIL_TIFF_HPP -// mapnik -#include - // stl #include #include namespace mapnik { -struct tiff_saver : public mapnik::util::static_visitor<> +struct tiff_saver { - tiff_saver(std::ostream &, std::string &); + tiff_saver(std::ostream &, std::string const&); template void operator() (T const&) const; private: diff --git a/include/mapnik/image_util_webp.hpp b/include/mapnik/image_util_webp.hpp index 8ba687082..14a218309 100644 --- a/include/mapnik/image_util_webp.hpp +++ b/include/mapnik/image_util_webp.hpp @@ -23,18 +23,15 @@ #ifndef MAPNIK_IMAGE_UTIL_WEBP_HPP #define MAPNIK_IMAGE_UTIL_WEBP_HPP -// mapnik -#include - // stl #include #include namespace mapnik { -struct webp_saver : public mapnik::util::static_visitor<> +struct webp_saver { - webp_saver(std::ostream &, std::string &); + webp_saver(std::ostream &, std::string const&); template void operator() (T const&) const; private: diff --git a/include/mapnik/png_io.hpp b/include/mapnik/png_io.hpp index 14b9edc44..7034ca293 100644 --- a/include/mapnik/png_io.hpp +++ b/include/mapnik/png_io.hpp @@ -607,7 +607,7 @@ void save_as_png8(T1 & file, mapnik::image_data_gray8::pixel_type * row_out = reduced_image.getRow(y); for (unsigned x = 0; x < width; ++x) { - row_out[x] = tree->quantize(row[x]); + row_out[x] = tree.quantize(row[x]); } } save_as_png(file, palette, reduced_image, width, height, 8, alphaTable, opts); @@ -635,7 +635,7 @@ void save_as_png8(T1 & file, for (unsigned x = 0; x < width; ++x) { - index = tree->quantize(row[x]); + index = tree.quantize(row[x]); if (x%2 == 0) { index = index<<4; diff --git a/src/build.py b/src/build.py index 0f32bce0b..044659f94 100644 --- a/src/build.py +++ b/src/build.py @@ -174,6 +174,10 @@ source = Split( parse_path.cpp image_reader.cpp image_util.cpp + image_util_jpeg.cpp + image_util_png.cpp + image_util_tiff.cpp + image_util_webp.cpp layer.cpp map.cpp load_map.cpp diff --git a/src/image_util.cpp b/src/image_util.cpp index b54e75a8a..22a431b7d 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -110,8 +110,8 @@ void save_to_file(T const& image, else throw ImageWriterException("Could not write file to " + filename ); } -template <> -void save_to_stream(image_data_any const& image, +template +void save_to_stream(T const& image, std::ostream & stream, std::string const& type, rgba_palette const& palette) @@ -122,7 +122,9 @@ void save_to_stream(image_data_any const& image, std::transform(t.begin(), t.end(), t.begin(), ::tolower); if (t == "png" || boost::algorithm::starts_with(t, "png")) { - mapnik::util::apply_visitor(png_saver_pal(stream, t, palette), image); + png_saver_pal visitor(stream, t, palette); + visitor(image); + //mapnik::util::apply_visitor(visitor, image); } else if (boost::algorithm::starts_with(t, "tif")) { @@ -137,7 +139,8 @@ void save_to_stream(image_data_any const& image, else throw ImageWriterException("Could not write to empty stream" ); } -void save_to_stream(image_data_any const& image, +template +void save_to_stream(T const& image, std::ostream & stream, std::string const& type) { @@ -147,19 +150,27 @@ void save_to_stream(image_data_any const& image, std::transform(t.begin(), t.end(), t.begin(), ::tolower); if (t == "png" || boost::algorithm::starts_with(t, "png")) { - util::apply_visitor(png_saver(stream, t), image); + png_saver visitor(stream, t); + visitor(image); + //util::apply_visitor(visitor, image); } else if (boost::algorithm::starts_with(t, "tif")) { - util::apply_visitor(tiff_saver(stream, t), image); + tiff_saver visitor(stream, t); + visitor(image); + //util::apply_visitor(visitor, image); } else if (boost::algorithm::starts_with(t, "jpeg")) { - util::apply_visitor(jpeg_saver(stream, t), image); + jpeg_saver visitor(stream, t); + visitor(image); + //util::apply_visitor(visitor, image); } else if (boost::algorithm::starts_with(t, "webp")) { - util::apply_visitor(webp_saver(stream, t), image); + webp_saver visitor(stream, t); + visitor(image); + //util::apply_visitor(visitor, image); } else throw ImageWriterException("unknown file type: " + type); } diff --git a/src/image_util_jpeg.cpp b/src/image_util_jpeg.cpp index 74a3c5aa5..d44c13974 100644 --- a/src/image_util_jpeg.cpp +++ b/src/image_util_jpeg.cpp @@ -25,8 +25,12 @@ #include #endif +#include #include #include +#include +#include +#include // boost #include @@ -41,13 +45,8 @@ namespace mapnik jpeg_saver::jpeg_saver(std::ostream & stream, std::string const& t): stream_(stream), t_(t) {} -void jpeg_saver::operator() (image_data_null const& image) const -{ - throw ImageWriterException("null images not supported"); -} - template -void jpeg_saver::operator() (T const& image) const +void process_rgba8_jpeg(T const& image, std::string const& t, std::ostream & stream) { #if defined(HAVE_JPEG) int quality = 85; @@ -65,13 +64,29 @@ void jpeg_saver::operator() (T const& image) const #endif } -template void jpeg_saver::operator() (image_data_rgba8 const& image) const; -template void jpeg_saver::operator() (image_data_gray8 const& image) const; -template void jpeg_saver::operator() (image_data_gray16 const& image) const; -template void jpeg_saver::operator() (image_data_gray32f const& image) const; -template void jpeg_saver::operator()> (image_view const& image) const; -template void jpeg_saver::operator()> (image_view const& image) const; -template void jpeg_saver::operator()> (image_view const& image) const; -template void jpeg_saver::operator()> (image_view const& image) const; +template<> +void jpeg_saver::operator() (image_data_rgba8 const& image) const +{ + process_rgba8_jpeg(image, t_, stream_); +} + +template<> +void jpeg_saver::operator() (image_view_rgba8 const& image) const +{ + process_rgba8_jpeg(image, t_, stream_); +} + +template +void jpeg_saver::operator() (T const& image) const +{ + throw ImageWriterException("Mapnik does not support jpeg grayscale images"); +} + +template void jpeg_saver::operator() (image_data_gray8 const& image) const; +template void jpeg_saver::operator() (image_data_gray16 const& image) const; +template void jpeg_saver::operator() (image_data_gray32f const& image) const; +template void jpeg_saver::operator() (image_view_gray8 const& image) const; +template void jpeg_saver::operator() (image_view_gray16 const& image) const; +template void jpeg_saver::operator() (image_view_gray32f const& image) const; } // end ns diff --git a/src/image_util_png.cpp b/src/image_util_png.cpp index cd3527e8a..b4b102798 100644 --- a/src/image_util_png.cpp +++ b/src/image_util_png.cpp @@ -32,8 +32,12 @@ extern "C" #include #endif +#include #include #include +#include +#include +#include // boost #include @@ -179,37 +183,47 @@ png_saver::png_saver(std::ostream & stream, std::string const& t): png_saver_pal::png_saver_pal(std::ostream & stream, std::string const& t, rgba_palette const& pal): stream_(stream), t_(t), pal_(pal) {} -void png_saver::operator() (image_data_null const& image) const +template<> +void png_saver::operator() (image_data_null const& image) const { - throw ImageWriterException("null images not supported"); + throw ImageWriterException("null images not supported for png"); +} + +template<> +void png_saver_pal::operator() (image_data_null const& image) const +{ + throw ImageWriterException("null images not supported for png"); } template -void process_rgb8_png_pal(T const& image) +void process_rgba8_png_pal(T const& image, + std::string const& t, + std::ostream & stream, + rgba_palette const& pal) { #if defined(HAVE_PNG) png_options opts; - handle_png_options(t_, opts); - if (pal_ && pal_->valid()) + handle_png_options(t, opts); + if (pal.valid()) { png_options opts; handle_png_options(t,opts); - save_as_png8_pal(stream, image, pal_, opts); + save_as_png8_pal(stream, image, pal, opts); } else if (opts.paletted) { if (opts.use_hextree) { - save_as_png8_hex(stream_, image, opts); + save_as_png8_hex(stream, image, opts); } else { - save_as_png8_oct(stream_, image, opts); + save_as_png8_oct(stream, image, opts); } } else { - save_as_png(stream_, image, opts); + save_as_png(stream, image, opts); } #else throw ImageWriterException("png output is not enabled in your build of Mapnik"); @@ -217,87 +231,94 @@ void process_rgb8_png_pal(T const& image) } template -void process_rgb8_png(T const& image) +void process_rgba8_png(T const& image, + std::string const& t, + std::ostream & stream) { #if defined(HAVE_PNG) png_options opts; - handle_png_options(t_, opts); + handle_png_options(t, opts); if (opts.paletted) { if (opts.use_hextree) { - save_as_png8_hex(stream_, image, opts); + save_as_png8_hex(stream, image, opts); } else { - save_as_png8_oct(stream_, image, opts); + save_as_png8_oct(stream, image, opts); } } else { - save_as_png(stream_, image, opts); + save_as_png(stream, image, opts); } #else throw ImageWriterException("png output is not enabled in your build of Mapnik"); #endif } -void png_saver_pal::operator() (image_data_rgba8 const& image) const +template<> +void png_saver_pal::operator() (image_data_rgba8 const& image) const { - process_rgb8_png(image); + process_rgba8_png_pal(image, t_, stream_, pal_); } -void png_saver_pal::operator() (image_view const& image) const +template<> +void png_saver_pal::operator() (image_view_rgba8 const& image) const { - process_rgb8_png(image); + process_rgba8_png_pal(image, t_, stream_, pal_); } -void png_saver::operator() (image_data_rgba8 const& image) const +template<> +void png_saver::operator() (image_data_rgba8 const& image) const { - process_rgb8_png(image); + process_rgba8_png(image, t_, stream_); } -void png_saver::operator() (image_view const& image) const +template<> +void png_saver::operator() (image_view_rgba8 const& image) const { - process_rgb8_png(image); + process_rgba8_png(image, t_, stream_); } template void png_saver::operator() (T const& image) const { #if defined(HAVE_PNG) - png_options opts; - handle_png_options(t_, opts); - save_as_png(stream_, image, opts); + throw ImageWriterException("Mapnik does not support grayscale images for png"); + //png_options opts; + //handle_png_options(t_, opts); + //save_as_png(stream_, image, opts); #else throw ImageWriterException("png output is not enabled in your build of Mapnik"); #endif } -template void png_saver::operator() (image_data_gray8 const& image) const; -template void png_saver::operator() (image_data_gray16 const& image) const; -template void png_saver::operator() (image_data_gray32f const& image) const; -template void png_saver::operator()> (image_view const& image) const; -template void png_saver::operator()> (image_view const& image) const; -template void png_saver::operator()> (image_view const& image) const; - template void png_saver_pal::operator() (T const& image) const { #if defined(HAVE_PNG) - png_options opts; - handle_png_options(t_, opts); - save_as_png(stream_, image, opts); + throw ImageWriterException("Mapnik does not support grayscale images for png"); + //png_options opts; + //handle_png_options(t_, opts); + //save_as_png(stream_, image, opts); #else throw ImageWriterException("png output is not enabled in your build of Mapnik"); #endif } -template void png_saver_pal::operator() (image_data_gray8 const& image) const; -template void png_saver_pal::operator() (image_data_gray16 const& image) const; -template void png_saver_pal::operator() (image_data_gray32f const& image) const; -template void png_saver_pal::operator()> (image_view const& image) const; -template void png_saver_pal::operator()> (image_view const& image) const; -template void png_saver_pal::operator()> (image_view const& image) const; +template void png_saver::operator() (image_data_gray8 const& image) const; +template void png_saver::operator() (image_data_gray16 const& image) const; +template void png_saver::operator() (image_data_gray32f const& image) const; +template void png_saver::operator() (image_view_gray8 const& image) const; +template void png_saver::operator() (image_view_gray16 const& image) const; +template void png_saver::operator() (image_view_gray32f const& image) const; +template void png_saver_pal::operator() (image_data_gray8 const& image) const; +template void png_saver_pal::operator() (image_data_gray16 const& image) const; +template void png_saver_pal::operator() (image_data_gray32f const& image) const; +template void png_saver_pal::operator() (image_view_gray8 const& image) const; +template void png_saver_pal::operator() (image_view_gray16 const& image) const; +template void png_saver_pal::operator() (image_view_gray32f const& image) const; } // end ns diff --git a/src/image_util_tiff.cpp b/src/image_util_tiff.cpp index 92bd01a2b..f4a94ffc7 100644 --- a/src/image_util_tiff.cpp +++ b/src/image_util_tiff.cpp @@ -25,8 +25,12 @@ #include #endif +#include #include #include +#include +#include +#include // boost #include @@ -161,8 +165,8 @@ void handle_tiff_options(std::string const& type, tiff_saver::tiff_saver(std::ostream & stream, std::string const& t): stream_(stream), t_(t) {} - -void tiff_saver::operator() (image_data_null const& image) const +template<> +void tiff_saver::operator() (image_data_null const& image) const { throw ImageWriterException("null images not supported"); } @@ -179,13 +183,13 @@ void tiff_saver::operator() (T const& image) const #endif } -template void tiff_saver::operator() (image_data_rgba8 const& image) const; -template void tiff_saver::operator() (image_data_gray8 const& image) const; -template void tiff_saver::operator() (image_data_gray16 const& image) const; -template void tiff_saver::operator() (image_data_gray32f const& image) const; -template void tiff_saver::operator()> (image_view const& image) const; -template void tiff_saver::operator()> (image_view const& image) const; -template void tiff_saver::operator()> (image_view const& image) const; -template void tiff_saver::operator()> (image_view const& image) const; +template void tiff_saver::operator() (image_data_rgba8 const& image) const; +template void tiff_saver::operator() (image_data_gray8 const& image) const; +template void tiff_saver::operator() (image_data_gray16 const& image) const; +template void tiff_saver::operator() (image_data_gray32f const& image) const; +template void tiff_saver::operator() (image_view_rgba8 const& image) const; +template void tiff_saver::operator() (image_view_gray8 const& image) const; +template void tiff_saver::operator() (image_view_gray16 const& image) const; +template void tiff_saver::operator() (image_view_gray32f const& image) const; } // end ns diff --git a/src/image_util_webp.cpp b/src/image_util_webp.cpp index a98168cbf..5d6770947 100644 --- a/src/image_util_webp.cpp +++ b/src/image_util_webp.cpp @@ -25,8 +25,12 @@ #include #endif +#include #include #include +#include +#include +#include // boost #include @@ -330,13 +334,14 @@ void handle_webp_options(std::string const& type, webp_saver::webp_saver(std::ostream & stream, std::string const& t): stream_(stream), t_(t) {} -void webp_saver::operator() (image_data_null const& image) const +template<> +void webp_saver::operator() (image_data_null const& image) const { throw ImageWriterException("null images not supported"); } template -void webp_saver::operator() (T const& image) const +void process_rgba8_webp(T const& image, std::string const& t, std::ostream & stream) { #if defined(HAVE_WEBP) WebPConfig config; @@ -354,6 +359,24 @@ void webp_saver::operator() (T const& image) const #endif } +template <> +void webp_saver::operator() (image_data_rgba8 const& image) const +{ + process_rgba8_webp(image, t_, stream_); +} + +template <> +void webp_saver::operator() (image_view_rgba8 const& image) const +{ + process_rgba8_webp(image, t_, stream_); +} + +template +void webp_saver::operator() (T const& image) const +{ + throw ImageWriterException("Mapnik does not support webp grayscale images"); +} + template void webp_saver::operator() (image_data_rgba8 const& image) const; template void webp_saver::operator() (image_data_gray8 const& image) const; template void webp_saver::operator() (image_data_gray16 const& image) const;