image: add pixel offset query

This commit is contained in:
Danny Robson 2015-07-23 21:18:15 +10:00
parent 0899c16557
commit d5f1506afd
2 changed files with 13 additions and 2 deletions

View File

@ -255,13 +255,22 @@ util::image::buffer<T>::downsample (float factor) const
///////////////////////////////////////////////////////////////////////////////
template <typename T>
size_t
buffer<T>::offset (point<2,size_t> p) const
{
return dot (stride (), p);
}
//-----------------------------------------------------------------------------
template <typename T>
T
buffer<T>::operator[] (point<2,size_t> p) const
{
CHECK_LT (p.x, w);
CHECK_LT (p.y, h);
return begin ()[p.y * s + p.x];
return begin ()[offset (p)];
}
@ -273,7 +282,7 @@ buffer<T>::operator[] (point<2,size_t> p)
CHECK_LT (p.x, w);
CHECK_LT (p.y, h);
return begin ()[p.y * s + p.x];
return begin ()[offset (p)];
}

View File

@ -61,6 +61,8 @@ namespace util { namespace image {
size_t s;
//---------------------------------------------------------------------
size_t offset (point<2,size_t>) const;
T operator[] (point<2,size_t>) const;
T& operator[] (point<2,size_t>);