diff --git a/image.cpp b/image.cpp index 981de0fa..4ae8ff99 100644 --- a/image.cpp +++ b/image.cpp @@ -255,13 +255,22 @@ util::image::buffer::downsample (float factor) const /////////////////////////////////////////////////////////////////////////////// template +size_t +buffer::offset (point<2,size_t> p) const +{ + return dot (stride (), p); +} + + +//----------------------------------------------------------------------------- +template T buffer::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::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)]; } diff --git a/image.hpp b/image.hpp index b63cafea..676b4c7f 100644 --- a/image.hpp +++ b/image.hpp @@ -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>);