Merge pull request #2637 from mapnik/feature/is_solid_move

is_solid to image_util
This commit is contained in:
Blake Thompson 2015-01-15 11:17:11 -06:00
commit 58f5812425
6 changed files with 75 additions and 82 deletions

View file

@ -121,24 +121,7 @@ bool painted(mapnik::image_32 const& im)
bool is_solid(mapnik::image_32 const& im) bool is_solid(mapnik::image_32 const& im)
{ {
if (im.width() > 0 && im.height() > 0) return mapnik::is_solid(im.data());
{
mapnik::image_data_rgba8 const & data = im.data();
mapnik::image_data_rgba8::pixel_type const* first_row = data.getRow(0);
mapnik::image_data_rgba8::pixel_type const first_pixel = first_row[0];
for (unsigned y = 0; y < im.height(); ++y)
{
mapnik::image_data_rgba8::pixel_type const * row = data.getRow(y);
for (unsigned x = 0; x < im.width(); ++x)
{
if (first_pixel != row[x])
{
return false;
}
}
}
}
return true;
} }
unsigned get_pixel(mapnik::image_32 const& im, int x, int y) unsigned get_pixel(mapnik::image_32 const& im, int x, int y)

View file

@ -89,23 +89,7 @@ PyObject* view_tostring3(image_view_rgba8 const & view, std::string const& forma
bool is_solid(image_view_rgba8 const& view) bool is_solid(image_view_rgba8 const& view)
{ {
if (view.width() > 0 && view.height() > 0) return mapnik::is_solid(view);
{
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_rgba8::pixel_type const * row = view.getRow(y);
for (unsigned x = 0; x < view.width(); ++x)
{
if (first_pixel != row[x])
{
return false;
}
}
}
}
return true;
} }
void save_view1(image_view_rgba8 const& view, void save_view1(image_view_rgba8 const& view,

View file

@ -24,6 +24,7 @@
#define MAPNIK_IMAGE_HPP #define MAPNIK_IMAGE_HPP
#include <mapnik/image_data_any.hpp> #include <mapnik/image_data_any.hpp>
#include <mapnik/config.hpp>
namespace mapnik { namespace mapnik {

View file

@ -27,6 +27,7 @@
#include <mapnik/config.hpp> #include <mapnik/config.hpp>
#include <mapnik/image_data.hpp> #include <mapnik/image_data.hpp>
#include <mapnik/image_view.hpp> #include <mapnik/image_view.hpp>
#include <mapnik/util/variant.hpp>
// boost // boost
#pragma GCC diagnostic push #pragma GCC diagnostic push
@ -119,9 +120,7 @@ template <typename T>
MAPNIK_DECL void set_premultiplied_alpha(T & image, bool status); MAPNIK_DECL void set_premultiplied_alpha(T & image, bool status);
template <typename T> template <typename T>
void save_as_png(T const& image, MAPNIK_DECL bool is_solid (T const& image);
std::string const& filename,
rgba_palette const& palette);
inline bool is_png(std::string const& filename) inline bool is_png(std::string const& filename)
{ {

View file

@ -52,54 +52,10 @@ image image::read_from_file(std::string const& filename)
return image(); return image();
} }
} }
/*
namespace detail {
struct save_to_file_visitor
{
save_to_file_visitor(std::string const& filename, std::string const& format)
: filename_(filename),
format_(format) {}
void operator() (image_data_rgba8 const& data) const
{
save_to_file(data,filename_, format_);
}
void operator() (image_data_gray16 const& data) const
{
if (format_ == "tiff") // only TIFF supported
{
std::ofstream file (filename_.c_str(), std::ios::out| std::ios::trunc|std::ios::binary);
if (file)
{
tiff_config config;
save_as_tiff(file, data, config);
}
else throw ImageWriterException("Could not write file to " + filename_ );
}
else
{
throw std::runtime_error("Error: saving gray16 image as " + format_ + " is not supported");
}
}
template <typename T>
void operator() (T const& data) const
{
throw std::runtime_error("Error: saving " + std::string(typeid(data).name()) + " as " + format_ + " is not supported");
}
std::string const& filename_;
std::string const& format_;
};
}*/
void image::save_to_file(std::string const& filename, std::string const& format) void image::save_to_file(std::string const& filename, std::string const& format)
{ {
mapnik::save_to_file(data_, filename, format); mapnik::save_to_file(data_, filename, format);
//util::apply_visitor(detail::save_to_file_visitor(filename, format), data_);
} }
} }

View file

@ -28,6 +28,7 @@
#include <mapnik/image_util_webp.hpp> #include <mapnik/image_util_webp.hpp>
#include <mapnik/image_data.hpp> #include <mapnik/image_data.hpp>
#include <mapnik/image_data_any.hpp> #include <mapnik/image_data_any.hpp>
#include <mapnik/image_view_any.hpp>
#include <mapnik/memory.hpp> #include <mapnik/memory.hpp>
#include <mapnik/image_view.hpp> #include <mapnik/image_view.hpp>
#include <mapnik/palette.hpp> #include <mapnik/palette.hpp>
@ -397,6 +398,75 @@ template std::string save_to_string<image_data_any>(image_data_any const&,
std::string const&, std::string const&,
rgba_palette const& palette); rgba_palette const& palette);
namespace detail {
struct is_solid_visitor
{
template <typename T>
bool operator() (T const & data)
{
using pixel_type = typename T::pixel_type;
if (data.width() > 0 && data.height() > 0)
{
pixel_type const* first_row = data.getRow(0);
pixel_type const first_pixel = first_row[0];
for (unsigned y = 0; y < data.height(); ++y)
{
pixel_type const * row = data.getRow(y);
for (unsigned x = 0; x < data.width(); ++x)
{
if (first_pixel != row[x])
{
return false;
}
}
}
}
return true;
}
};
template bool is_solid_visitor::operator()<image_data_rgba8> (image_data_rgba8 const& data);
template bool is_solid_visitor::operator()<image_data_gray8> (image_data_gray8 const& data);
template bool is_solid_visitor::operator()<image_data_gray16> (image_data_gray16 const& data);
template bool is_solid_visitor::operator()<image_data_gray32f> (image_data_gray32f const& data);
template bool is_solid_visitor::operator()<image_view_rgba8> (image_view_rgba8 const& data);
template bool is_solid_visitor::operator()<image_view_gray8> (image_view_gray8 const& data);
template bool is_solid_visitor::operator()<image_view_gray16> (image_view_gray16 const& data);
template bool is_solid_visitor::operator()<image_view_gray32f> (image_view_gray32f const& data);
template<>
bool is_solid_visitor::operator()<image_data_null> (image_data_null const&)
{
return true;
}
} // end detail ns
template <typename T>
MAPNIK_DECL bool is_solid(T const& image)
{
return util::apply_visitor(detail::is_solid_visitor(), image);
}
template bool is_solid<image_data_any> (image_data_any const&);
template bool is_solid<image_view_any> (image_view_any const&);
// Temporary until image_data_rgba8 is removed from passing
template <>
MAPNIK_DECL bool is_solid<image_data_rgba8>(image_data_rgba8 const& image)
{
detail::is_solid_visitor visitor;
return visitor(image);
}
// Temporary until image_view_rgba8 is removed from passing
template <>
MAPNIK_DECL bool is_solid<image_view_rgba8>(image_view_rgba8 const& image)
{
detail::is_solid_visitor visitor;
return visitor(image);
}
namespace detail { namespace detail {