More stuff to break it all

This commit is contained in:
Blake Thompson 2015-01-07 18:16:38 -05:00
parent a3f6a989de
commit 6df688160c
5 changed files with 92 additions and 44 deletions

View file

@ -112,6 +112,10 @@ public:
{
return data_.getBytes();
}
inline const unsigned char* getBytes() const
{
return data_.getBytes();
}
inline unsigned char* raw_data()
{

View file

@ -24,6 +24,8 @@
#define MAPNIK_IMAGE_DATA_ANY_HPP
#include <mapnik/image_data.hpp>
#include <mapnik/image_view.hpp>
#include <mapnik/graphics.hpp>
#include <mapnik/util/variant.hpp>
namespace mapnik {
@ -36,18 +38,27 @@ struct image_data_null
std::size_t height() const { return 0; }
};
using image_data_base = util::variant<image_data_null, image_data_rgba8, image_data_gray8, image_data_gray16, image_data_gray32f>;
using image_data_base = util::variant<image_data_null,
image_data_rgba8,
image_data_gray8,
image_data_gray16,
image_data_gray32f,
image_32,
image_view<image_data_rgba8>,
image_view<image_data_gray8>,
image_view<image_data_gray16>,
image_view<image_data_gray32f>>;
namespace detail {
struct get_bytes_visitor : util::static_visitor<unsigned char*>
/*struct get_bytes_visitor : util::static_visitor<unsigned char*>
{
template <typename T>
unsigned char* operator()(T & data)
{
return data.getBytes();
}
};
};*/
struct get_bytes_visitor_const : util::static_visitor<unsigned char const*>
{
@ -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
{

View file

@ -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();

View file

@ -528,23 +528,6 @@ void handle_webp_options(std::string const& type,
}
#endif
template <typename T>
void save_to_stream(image_view<T> 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 <typename T>
void save_to_stream(image_view<T> 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)

View file

@ -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<image_data_rgba8> 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<image_data_gray8> 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<image_data_gray16> 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