image: add indexing operator for ints and points

This commit is contained in:
Danny Robson 2015-06-03 23:17:37 +10:00
parent c826822a43
commit fc279753eb
2 changed files with 43 additions and 0 deletions

View File

@ -268,8 +268,44 @@ util::image::buffer<T>::downsample (float factor) const
} }
///////////////////////////////////////////////////////////////////////////////
template <typename T>
T
buffer<T>::operator[] (point<2,size_t> p) const
{
return begin ()[p.y * s + p.x];
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T> template <typename T>
T&
buffer<T>::operator[] (point<2,size_t> p)
{
return begin ()[p.y * s + p.x];
}
//-----------------------------------------------------------------------------
template <typename T>
T
buffer<T>::operator[] (size_t idx) const
{
return begin ()[idx];
}
//-----------------------------------------------------------------------------
template <typename T>
T&
buffer<T>::operator[] (size_t idx)
{
return begin ()[idx];
}
///////////////////////////////////////////////////////////////////////////////
template <typename T>
T* T*
buffer<T>::data (void) buffer<T>::data (void)
{ {

View File

@ -18,6 +18,7 @@
#define __UTIL_IMAGE_HPP #define __UTIL_IMAGE_HPP
#include "extent.hpp" #include "extent.hpp"
#include "point.hpp"
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
@ -53,6 +54,12 @@ namespace util {
size_t h; size_t h;
size_t s; size_t s;
T operator[] (point<2,size_t>) const;
T& operator[] (point<2,size_t>);
T operator[] (size_t) const;
T& operator[] (size_t);
T* begin (void); T* begin (void);
T* end (void); T* end (void);
T* data (void); T* data (void);