From adced85761de2036a30be08c4a97aa3ceb305528 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Thu, 10 Sep 2020 15:57:19 +0100 Subject: [PATCH] Implement `is_solid` using stdlib `find_if --- src/image_util.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/image_util.cpp b/src/image_util.cpp index d562cdd57..a825c9e91 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -52,6 +52,7 @@ #include #include #include +#include namespace mapnik { @@ -420,19 +421,18 @@ struct is_solid_visitor { return true; } - template - bool operator() (T const & data) const + bool operator() (image_view 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 + 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