image - add iterator interface

This commit is contained in:
artemp 2015-09-16 11:37:03 +01:00
parent 8c8ea74a63
commit d7d3da6935
2 changed files with 22 additions and 0 deletions

View file

@ -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;

View file

@ -226,6 +226,20 @@ inline unsigned char* image<T>::bytes()
return buffer_.data();
}
// iterator interface
template <typename T>
inline typename image<T>::iterator image<T>::begin() { return pData_; }
template <typename T>
inline typename image<T>::iterator image<T>::end() { return pData_ + dimensions_.width() * dimensions_.height(); }
template <typename T>
inline typename image<T>::const_iterator image<T>::begin() const { return pData_; }
template <typename T>
inline typename image<T>::const_iterator image<T>::end() const{ return pData_ + dimensions_.width() * dimensions_.height(); }
template <typename T>
inline typename image<T>::pixel_type const* image<T>::get_row(std::size_t row) const
{