From 6df688160c56a9f612e81e4ac08a5e89c7a3d630 Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Wed, 7 Jan 2015 18:16:38 -0500 Subject: [PATCH] More stuff to break it all --- include/mapnik/graphics.hpp | 4 ++ include/mapnik/image_data_any.hpp | 21 ++++++--- include/mapnik/image_view.hpp | 8 ++-- src/image_util.cpp | 32 -------------- src/image_util_png.cpp | 71 +++++++++++++++++++++++++++++-- 5 files changed, 92 insertions(+), 44 deletions(-) diff --git a/include/mapnik/graphics.hpp b/include/mapnik/graphics.hpp index 0e753fb44..3a2ce4db5 100644 --- a/include/mapnik/graphics.hpp +++ b/include/mapnik/graphics.hpp @@ -112,6 +112,10 @@ public: { return data_.getBytes(); } + inline const unsigned char* getBytes() const + { + return data_.getBytes(); + } inline unsigned char* raw_data() { diff --git a/include/mapnik/image_data_any.hpp b/include/mapnik/image_data_any.hpp index c9b2d0b2e..e97d8d849 100644 --- a/include/mapnik/image_data_any.hpp +++ b/include/mapnik/image_data_any.hpp @@ -24,6 +24,8 @@ #define MAPNIK_IMAGE_DATA_ANY_HPP #include +#include +#include #include namespace mapnik { @@ -36,18 +38,27 @@ struct image_data_null std::size_t height() const { return 0; } }; -using image_data_base = util::variant; +using image_data_base = util::variant, + image_view, + image_view, + image_view>; namespace detail { -struct get_bytes_visitor : util::static_visitor +/*struct get_bytes_visitor : util::static_visitor { template unsigned char* operator()(T & data) { return data.getBytes(); } -}; +};*/ struct get_bytes_visitor_const : util::static_visitor { @@ -91,10 +102,10 @@ struct image_data_any : image_data_base return util::apply_visitor(detail::get_bytes_visitor_const(),*this); } - unsigned char* getBytes() + /*unsigned char* getBytes() { return util::apply_visitor(detail::get_bytes_visitor(),*this); - } + }*/ std::size_t width() const { diff --git a/include/mapnik/image_view.hpp b/include/mapnik/image_view.hpp index 4b648aab5..146271ade 100644 --- a/include/mapnik/image_view.hpp +++ b/include/mapnik/image_view.hpp @@ -109,18 +109,18 @@ public: { return data_.getBytes(); } - inline T& data() + /*inline T& data() { return data_; - } + }*/ inline T const& data() const { return data_; } - inline pixel_type* getData() + /*inline pixel_type* getData() { return data_.getData(); - } + }*/ inline const pixel_type* getData() const { return data_.getData(); diff --git a/src/image_util.cpp b/src/image_util.cpp index 55e7cdf3f..2d0e68747 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -528,23 +528,6 @@ void handle_webp_options(std::string const& type, } #endif -template -void save_to_stream(image_view const& image, - std::ostream & stream, - std::string const& type, - rgba_palette_ptr const& palette) -{ - save_to_stream(image.data(), stream, type, palette); -} - -void save_to_stream(image_32 const& image, - std::ostream & stream, - std::string const& type, - rgba_palette_ptr const& palette) -{ - save_to_stream(image.data(), stream, type, palette); -} - void save_to_stream(image_data_any const& image, std::ostream & stream, std::string const& type, @@ -571,21 +554,6 @@ void save_to_stream(image_data_any const& image, else throw ImageWriterException("Could not write to empty stream" ); } -template -void save_to_stream(image_view const& image, - std::ostream & stream, - std::string const& type) -{ - save_to_stream(image.data(), stream, type); -} - -void save_to_stream(image_32 const& image, - std::ostream & stream, - std::string const& type) -{ - save_to_stream(image.data(), stream, type); -} - void save_to_stream(image_data_any const& image, std::ostream & stream, std::string const& type) diff --git a/src/image_util_png.cpp b/src/image_util_png.cpp index 344a8a151..31cccec57 100644 --- a/src/image_util_png.cpp +++ b/src/image_util_png.cpp @@ -176,7 +176,7 @@ void handle_png_options(std::string const& type, png_saver::png_saver(std::ostream & stream, std::string const& t, rgba_palette_ptr const& pal): _stream(stream), _t(t), _pal(pal) {} -void png_saver::operator() (mapnik::image_data_rgba8 const& image) const +void png_saver::operator() (image_data_rgba8 const& image) const { #if defined(HAVE_PNG) png_options opts; @@ -207,7 +207,38 @@ void png_saver::operator() (mapnik::image_data_rgba8 const& image) const #endif } -void png_saver::operator() (mapnik::image_data_gray8 const& image) const +void png_saver::operator() (image_view const& image) const +{ +#if defined(HAVE_PNG) + png_options opts; + handle_png_options(_t, opts); + if (_pal && _pal->valid()) + { + png_options opts; + handle_png_options(t,opts); + save_as_png8_pal(stream, image, _pal, opts); + } + else if (opts.paletted) + { + if (opts.use_hextree) + { + save_as_png8_hex(_stream, image, opts); + } + else + { + save_as_png8_oct(_stream, image, opts); + } + } + else + { + save_as_png(_stream, image, opts); + } +#else + throw ImageWriterException("png output is not enabled in your build of Mapnik"); +#endif +} + +void png_saver::operator() (image_data_gray8 const& image) const { #if defined(HAVE_PNG) png_options opts; @@ -218,7 +249,29 @@ void png_saver::operator() (mapnik::image_data_gray8 const& image) const #endif } -void png_saver::operator() (mapnik::image_data_gray16 const& image) const +void png_saver::operator() (image_view const& image) const +{ +#if defined(HAVE_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 +} + +void png_saver::operator() (image_data_gray16 const& image) const +{ +#if defined(HAVE_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 +} + +void png_saver::operator() (image_view const& image) const { #if defined(HAVE_PNG) png_options opts; @@ -239,3 +292,15 @@ void png_saver::operator() (mapnik::image_data_gray32f const& image) const throw ImageWriterException("png output is not enabled in your build of Mapnik"); #endif } +void png_saver::operator() (mapnik::image_data_gray32f const& image) const +{ +#if defined(HAVE_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 +} + +} // end ns