Implement is_solid
using stdlib <algorithm> `find_if
This commit is contained in:
parent
5629a6fb6f
commit
adced85761
1 changed files with 25 additions and 7 deletions
|
@ -52,6 +52,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <execution>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik
|
||||||
{
|
{
|
||||||
|
@ -420,19 +421,18 @@ struct is_solid_visitor
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool operator() (T const & data) const
|
bool operator() (image_view<T> const& view) const
|
||||||
{
|
{
|
||||||
using pixel_type = typename T::pixel_type;
|
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];
|
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);
|
pixel_type const * row = view.get_row(y);
|
||||||
for (std::size_t x = 0; x < data.width(); ++x)
|
for (std::size_t x = 0; x < view.width(); ++x)
|
||||||
{
|
{
|
||||||
if (first_pixel != row[x])
|
if (first_pixel != row[x])
|
||||||
{
|
{
|
||||||
|
@ -443,6 +443,24 @@ struct is_solid_visitor
|
||||||
}
|
}
|
||||||
return true;
|
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
|
} // end detail ns
|
||||||
|
|
Loading…
Reference in a new issue