From d7d3da6935b0f36a4477d7d9e49a28ca6d5962eb Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 16 Sep 2015 11:37:03 +0100 Subject: [PATCH] image - add iterator interface --- include/mapnik/image.hpp | 8 ++++++++ include/mapnik/image_impl.hpp | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/mapnik/image.hpp b/include/mapnik/image.hpp index 7165e0c61..9ebdfc3b2 100644 --- a/include/mapnik/image.hpp +++ b/include/mapnik/image.hpp @@ -72,6 +72,8 @@ class image public: using pixel = T; using pixel_type = typename T::type; + using iterator = pixel_type*; + using const_iterator = pixel_type const*; static constexpr image_dtype dtype = T::id; static constexpr std::size_t pixel_size = sizeof(pixel_type); private: @@ -110,6 +112,12 @@ public: void set(pixel_type const& t); pixel_type const* data() const; pixel_type* data(); + // simple iterator inteface + const_iterator begin() const; + const_iterator end() const; + iterator begin(); + iterator end(); + // unsigned char const* bytes() const; unsigned char* bytes(); pixel_type const* get_row(std::size_t row) const; diff --git a/include/mapnik/image_impl.hpp b/include/mapnik/image_impl.hpp index 2be52933f..b1fbfa966 100644 --- a/include/mapnik/image_impl.hpp +++ b/include/mapnik/image_impl.hpp @@ -226,6 +226,20 @@ inline unsigned char* image::bytes() return buffer_.data(); } +// iterator interface +template +inline typename image::iterator image::begin() { return pData_; } + +template +inline typename image::iterator image::end() { return pData_ + dimensions_.width() * dimensions_.height(); } + +template +inline typename image::const_iterator image::begin() const { return pData_; } + +template +inline typename image::const_iterator image::end() const{ return pData_ + dimensions_.width() * dimensions_.height(); } + + template inline typename image::pixel_type const* image::get_row(std::size_t row) const {