Added is_solid to image_utils. It is currently built to support the eventual use of image_view_any and image_data_any, but for a limited time supports the passing of image_view_rgba8 and image_data_rgba8.
Ref #2633
This commit is contained in:
parent
7d2db67cf3
commit
7ce7416999
4 changed files with 64 additions and 38 deletions
|
@ -121,24 +121,7 @@ bool painted(mapnik::image_32 const& im)
|
|||
|
||||
bool is_solid(mapnik::image_32 const& im)
|
||||
{
|
||||
if (im.width() > 0 && im.height() > 0)
|
||||
{
|
||||
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;
|
||||
return mapnik::is_solid(im.data());
|
||||
}
|
||||
|
||||
unsigned get_pixel(mapnik::image_32 const& im, int x, int y)
|
||||
|
|
|
@ -89,23 +89,7 @@ PyObject* view_tostring3(image_view_rgba8 const & view, std::string const& forma
|
|||
|
||||
bool is_solid(image_view_rgba8 const& view)
|
||||
{
|
||||
if (view.width() > 0 && view.height() > 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_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;
|
||||
mapnik::is_solid(view);
|
||||
}
|
||||
|
||||
void save_view1(image_view_rgba8 const& view,
|
||||
|
|
|
@ -119,9 +119,7 @@ template <typename T>
|
|||
MAPNIK_DECL void set_premultiplied_alpha(T & image, bool status);
|
||||
|
||||
template <typename T>
|
||||
void save_as_png(T const& image,
|
||||
std::string const& filename,
|
||||
rgba_palette const& palette);
|
||||
MAPNIK_DECL bool is_solid (T const& image);
|
||||
|
||||
inline bool is_png(std::string const& filename)
|
||||
{
|
||||
|
|
|
@ -325,6 +325,67 @@ void save_to_file(T const& image, std::string const& filename, rgba_palette cons
|
|||
else throw ImageWriterException("Could not write file to " + filename );
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
} // end detail ns
|
||||
|
||||
template <typename T>
|
||||
bool is_solid(T const& image)
|
||||
{
|
||||
return util::apply_visitor(detail::is_solid_visitor(), image);
|
||||
}
|
||||
|
||||
// Temporary until image_data_rgba8 is removed from passing
|
||||
template <>
|
||||
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 <>
|
||||
bool is_solid<image_view_rgba8>(image_view_rgba8 const& image)
|
||||
{
|
||||
detail::is_solid_visitor visitor;
|
||||
return visitor(image);
|
||||
}
|
||||
|
||||
// image_data_rgba8
|
||||
template void save_to_file<image_data_rgba8>(image_data_rgba8 const&,
|
||||
std::string const&,
|
||||
|
|
Loading…
Add table
Reference in a new issue