Implement is_solid using stdlib <algorithm> `find_if

This commit is contained in:
Artem Pavlenko 2020-09-10 15:57:19 +01:00
parent 5629a6fb6f
commit adced85761

View file

@ -52,6 +52,7 @@
#include <fstream>
#include <sstream>
#include <algorithm>
#include <execution>
namespace mapnik
{
@ -420,19 +421,18 @@ struct is_solid_visitor
{
return true;
}
template <typename T>
bool operator() (T const & data) const
bool operator() (image_view<T> const& view) const
{
using pixel_type = typename T::pixel_type;
if (data.width() > 0 && data.height() > 0)
if (view.width() > 0 && view.height() > 0)
{
pixel_type const* first_row = data.get_row(0);
pixel_type const* first_row = view.get_row(0);
pixel_type const first_pixel = first_row[0];
for (std::size_t y = 0; y < data.height(); ++y)
for (std::size_t y = 0; y < view.height(); ++y)
{
pixel_type const * row = data.get_row(y);
for (std::size_t x = 0; x < data.width(); ++x)
pixel_type const * row = view.get_row(y);
for (std::size_t x = 0; x < view.width(); ++x)
{
if (first_pixel != row[x])
{
@ -443,6 +443,24 @@ struct is_solid_visitor
}
return true;
}
template <typename T>
bool operator() (T const& image) const
{
using pixel_type = typename T::pixel_type;
if (image.size() > 0)
{
pixel_type const first_p = *image.begin();
auto itr = std::find_if(/*std::execution::par_unseq,*/ // still missing on ubuntu with
// clang++10/libc++ (!)
image.begin(), image.end(),
[first_p](pixel_type const p) {
return first_p != p;
});
return (itr == image.end());
}
return true;
}
};
} // end detail ns